guppylang-internals 0.22.0__tar.gz → 0.24.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. guppylang_internals-0.24.0/CHANGELOG.md +98 -0
  2. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/PKG-INFO +5 -5
  3. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/README.md +2 -2
  4. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/pyproject.toml +3 -3
  5. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/__init__.py +1 -1
  6. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/cfg/cfg.py +8 -0
  7. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/checker/cfg_checker.py +26 -65
  8. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/checker/core.py +8 -0
  9. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/checker/expr_checker.py +11 -25
  10. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/checker/func_checker.py +170 -21
  11. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/checker/stmt_checker.py +1 -1
  12. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/decorator.py +124 -58
  13. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/definition/const.py +2 -2
  14. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/definition/custom.py +1 -1
  15. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/definition/declaration.py +1 -1
  16. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/definition/extern.py +2 -2
  17. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/definition/function.py +1 -1
  18. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/definition/parameter.py +2 -2
  19. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/definition/pytket_circuits.py +1 -1
  20. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/definition/struct.py +10 -10
  21. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/definition/traced.py +1 -1
  22. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/definition/ty.py +6 -0
  23. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/definition/wasm.py +2 -2
  24. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/engine.py +13 -2
  25. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/nodes.py +0 -23
  26. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler/tket_exts.py +3 -6
  27. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler/wasm.py +37 -26
  28. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tracing/function.py +13 -2
  29. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tracing/unpacking.py +18 -12
  30. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tys/builtin.py +30 -11
  31. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tys/errors.py +6 -0
  32. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tys/parsing.py +111 -125
  33. guppylang_internals-0.22.0/CHANGELOG.md +0 -47
  34. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/.gitignore +0 -0
  35. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/LICENCE +0 -0
  36. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/ast_util.py +0 -0
  37. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/cfg/__init__.py +0 -0
  38. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/cfg/analysis.py +0 -0
  39. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/cfg/bb.py +0 -0
  40. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/cfg/builder.py +0 -0
  41. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/checker/__init__.py +0 -0
  42. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/checker/errors/__init__.py +0 -0
  43. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/checker/errors/comptime_errors.py +0 -0
  44. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/checker/errors/generic.py +0 -0
  45. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/checker/errors/linearity.py +0 -0
  46. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/checker/errors/type_errors.py +0 -0
  47. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/checker/errors/wasm.py +0 -0
  48. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/checker/linearity_checker.py +0 -0
  49. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/compiler/__init__.py +0 -0
  50. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/compiler/cfg_compiler.py +0 -0
  51. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/compiler/core.py +0 -0
  52. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/compiler/expr_compiler.py +0 -0
  53. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/compiler/func_compiler.py +0 -0
  54. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/compiler/hugr_extension.py +0 -0
  55. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/compiler/qtm_platform_extension.py +0 -0
  56. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/compiler/stmt_compiler.py +0 -0
  57. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/definition/__init__.py +0 -0
  58. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/definition/common.py +0 -0
  59. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/definition/overloaded.py +0 -0
  60. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/definition/value.py +0 -0
  61. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/diagnostic.py +0 -0
  62. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/dummy_decorator.py +0 -0
  63. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/error.py +0 -0
  64. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/experimental.py +0 -0
  65. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/ipython_inspect.py +0 -0
  66. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/py.typed +0 -0
  67. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/span.py +0 -0
  68. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/__init__.py +0 -0
  69. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/__init__.py +0 -0
  70. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/checker.py +0 -0
  71. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler/__init__.py +0 -0
  72. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler/arithmetic.py +0 -0
  73. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler/array.py +0 -0
  74. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler/either.py +0 -0
  75. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler/frozenarray.py +0 -0
  76. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler/futures.py +0 -0
  77. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler/list.py +0 -0
  78. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler/mem.py +0 -0
  79. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler/option.py +0 -0
  80. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler/prelude.py +0 -0
  81. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler/qsystem.py +0 -0
  82. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler/quantum.py +0 -0
  83. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler/tket_bool.py +0 -0
  84. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/compiler.py +0 -0
  85. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/debug.py +0 -0
  86. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/std/_internal/util.py +0 -0
  87. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tracing/__init__.py +0 -0
  88. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tracing/builtins_mock.py +0 -0
  89. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tracing/frozenlist.py +0 -0
  90. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tracing/object.py +0 -0
  91. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tracing/state.py +0 -0
  92. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tracing/util.py +0 -0
  93. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tys/__init__.py +0 -0
  94. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tys/arg.py +0 -0
  95. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tys/common.py +0 -0
  96. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tys/const.py +0 -0
  97. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tys/param.py +0 -0
  98. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tys/printing.py +0 -0
  99. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tys/subst.py +0 -0
  100. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tys/ty.py +0 -0
  101. {guppylang_internals-0.22.0 → guppylang_internals-0.24.0}/src/guppylang_internals/tys/var.py +0 -0
@@ -0,0 +1,98 @@
1
+ # Changelog
2
+
3
+ First release of `guppylang_internals` package containing refactored out internal components
4
+ from `guppylang`.
5
+
6
+ ## [0.24.0](https://github.com/CQCL/guppylang/compare/guppylang-internals-v0.23.0...guppylang-internals-v0.24.0) (2025-09-19)
7
+
8
+
9
+ ### ⚠ BREAKING CHANGES
10
+
11
+ * `guppylang_internals.decorator.extend_type` now returns a `GuppyDefinition` by default. To get the previous behaviour of returning the annotated class unchanged, pass `return_class=True`.
12
+ * `TypeDef`s now require a `params` field
13
+ * guppylang_internals.ty.parsing.parse_function_io_types replaced with parse_function_arg_annotation and check_function_arg
14
+ * Significant changes to the WASM decorators, types and operations
15
+ * Deleted `guppylang_internals.nodes.{IterHasNext, IterEnd}`
16
+ * guppylang_internals.tracing.unpacking.update_packed_value now returns a bool signalling whether the operation was successful.
17
+ * `CompilationEngine` now initialises all it's fields
18
+ * Calling `CompilationEngine.reset` no longer nullifies `additional_extensions`
19
+ * `CompilationEngine.register_extension` no longer adds duplicates to the `additional_extensions` list
20
+
21
+ ### Features
22
+
23
+ * Infer type of `self` arguments ([#1192](https://github.com/CQCL/guppylang/issues/1192)) ([51f5a2b](https://github.com/CQCL/guppylang/commit/51f5a2b3a9b06bc4ab054f32a4d07f7395df8ff4))
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * Add init to CompilationEngine; don't trash additional_extensions ([#1256](https://github.com/CQCL/guppylang/issues/1256)) ([e413748](https://github.com/CQCL/guppylang/commit/e413748532db3895cab4925a222177a4fa3fd61b))
29
+ * Allow generic specialization of methods ([#1206](https://github.com/CQCL/guppylang/issues/1206)) ([93936cc](https://github.com/CQCL/guppylang/commit/93936cc275c56dd856d11fabc7aac20176304147)), closes [#1182](https://github.com/CQCL/guppylang/issues/1182)
30
+ * Correctly update borrowed values after calls and catch cases where it's impossible ([#1253](https://github.com/CQCL/guppylang/issues/1253)) ([3ec5462](https://github.com/CQCL/guppylang/commit/3ec54627729b49689da006a743e9e2c359cd3728))
31
+ * Fix `nat` constructor in comptime functions ([#1258](https://github.com/CQCL/guppylang/issues/1258)) ([e257b6f](https://github.com/CQCL/guppylang/commit/e257b6fc2fe3793d6d8f63feca83bf5ed6643673))
32
+ * Fix incorrect leak error for borrowing functions in comptime ([#1252](https://github.com/CQCL/guppylang/issues/1252)) ([855244e](https://github.com/CQCL/guppylang/commit/855244e2d5e3aeb04c2028f9f2310dba0e74210a)), closes [#1249](https://github.com/CQCL/guppylang/issues/1249)
33
+ * wasm module updates based on tested lowering ([#1230](https://github.com/CQCL/guppylang/issues/1230)) ([657cea2](https://github.com/CQCL/guppylang/commit/657cea27af00a9c02e8d1a3190db535bbd1e7981))
34
+
35
+
36
+ ### Miscellaneous Chores
37
+
38
+ * Delete unused old iterator AST nodes ([#1215](https://github.com/CQCL/guppylang/issues/1215)) ([2310897](https://github.com/CQCL/guppylang/commit/231089750e33cf70754e5218feed64053c558c17))
39
+
40
+ ## [0.23.0](https://github.com/CQCL/guppylang/compare/guppylang-internals-v0.22.0...guppylang-internals-v0.23.0) (2025-08-19)
41
+
42
+
43
+ ### ⚠ BREAKING CHANGES
44
+
45
+ * `check_rows_match` no longer takes `globals` Deleted `GlobalShadowError` and `BranchTypeError.GlobalHint`
46
+
47
+ ### Bug Fixes
48
+
49
+ * Fix globals vs locals scoping behaviour to match Python ([#1169](https://github.com/CQCL/guppylang/issues/1169)) ([a6a91ca](https://github.com/CQCL/guppylang/commit/a6a91ca32ad7c67bf1d733eb26c016a2662256ef))
50
+ * Fix scoping issues with comprehensions in comptime expressions ([#1218](https://github.com/CQCL/guppylang/issues/1218)) ([0b990e2](https://github.com/CQCL/guppylang/commit/0b990e2b006c31352675004aec63a857f03a0793))
51
+
52
+
53
+ ### Documentation
54
+
55
+ * use results sequence protocol for simplicity ([#1208](https://github.com/CQCL/guppylang/issues/1208)) ([f9c1aee](https://github.com/CQCL/guppylang/commit/f9c1aee38776c678660ede5495989ac4d75baaeb))
56
+
57
+ ## [0.22.0](https://github.com/CQCL/guppylang/compare/guppylang-internals-v0.21.2...guppylang-internals-v0.22.0) (2025-08-11)
58
+
59
+
60
+ ### ⚠ BREAKING CHANGES
61
+
62
+ * RangeChecker has been deleted.
63
+
64
+ ### Features
65
+
66
+ * Add float parameter inputs to symbolic pytket circuits ([#1105](https://github.com/CQCL/guppylang/issues/1105)) ([34c546c](https://github.com/CQCL/guppylang/commit/34c546c3b5787beb839687fdbf4db8bc94f36c4a)), closes [#1076](https://github.com/CQCL/guppylang/issues/1076)
67
+ * Allow custom start and step in `range` ([#1157](https://github.com/CQCL/guppylang/issues/1157)) ([a1b9333](https://github.com/CQCL/guppylang/commit/a1b9333712c74270d5efaaa72f83d6b09047c068))
68
+ * Improve codegen for array unpacking ([#1106](https://github.com/CQCL/guppylang/issues/1106)) ([f375097](https://github.com/CQCL/guppylang/commit/f3750973a719b03d27668a3ae39f58c8424deffc))
69
+ * Insert drop ops for affine values ([#1090](https://github.com/CQCL/guppylang/issues/1090)) ([083133e](https://github.com/CQCL/guppylang/commit/083133e809873fce265bb78547fc3e519cb66ea1))
70
+
71
+
72
+ ### Bug Fixes
73
+
74
+ * Fix builtins mock escaping the tracing scope ([#1161](https://github.com/CQCL/guppylang/issues/1161)) ([a27a5c1](https://github.com/CQCL/guppylang/commit/a27a5c19560d76e46678f846476ea86e873ac8ac))
75
+
76
+ ## [0.21.1](https://github.com/CQCL/guppylang/compare/guppylang-internals-v0.21.0...guppylang-internals-v0.21.1) (2025-08-05)
77
+
78
+
79
+ ### Bug Fixes
80
+
81
+ * **guppylang-internals:** Fix circular import for custom decorators ([#1146](https://github.com/CQCL/guppylang/issues/1146)) ([d8474d8](https://github.com/CQCL/guppylang/commit/d8474d8af3d394275268cd3d0754ff06ecb9bcc2)), closes [#1145](https://github.com/CQCL/guppylang/issues/1145)
82
+ * Support `None` value ([#1149](https://github.com/CQCL/guppylang/issues/1149)) ([7f606c7](https://github.com/CQCL/guppylang/commit/7f606c778d98312a0d1c4a9c7a27448c24d80585)), closes [#1148](https://github.com/CQCL/guppylang/issues/1148)
83
+
84
+
85
+ ### Documentation
86
+
87
+ * Fix docs build ([#1142](https://github.com/CQCL/guppylang/issues/1142)) ([4dfd575](https://github.com/CQCL/guppylang/commit/4dfd575bcdfdf1e2db4e61f2f406fff27e0c08f7))
88
+
89
+ ## [0.21.0](https://github.com/CQCL/guppylang/compare/guppylang-internals-v0.20.0...guppylang-internals-v0.21.0) (2025-08-04)
90
+
91
+
92
+ ### ⚠ BREAKING CHANGES
93
+
94
+ * All compiler-internal and non-userfacing functionality is moved into a new `guppylang_internals` package
95
+
96
+ ### Code Refactoring
97
+
98
+ * Split up into `guppylang_internals` package ([#1126](https://github.com/CQCL/guppylang/issues/1126)) ([81d50c0](https://github.com/CQCL/guppylang/commit/81d50c0a24f55eca48d62e4b0275ef2126c5e626))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: guppylang-internals
3
- Version: 0.22.0
3
+ Version: 0.24.0
4
4
  Summary: Compiler internals for `guppylang` package.
5
5
  Author-email: Mark Koch <mark.koch@quantinuum.com>, TKET development team <tket-support@quantinuum.com>
6
6
  Maintainer-email: Mark Koch <mark.koch@quantinuum.com>, TKET development team <tket-support@quantinuum.com>
@@ -219,8 +219,8 @@ Classifier: Programming Language :: Python :: 3.13
219
219
  Classifier: Programming Language :: Python :: 3.14
220
220
  Classifier: Topic :: Software Development :: Compilers
221
221
  Requires-Python: <4,>=3.10
222
- Requires-Dist: hugr<0.14,>=0.13.0rc1
223
- Requires-Dist: tket-exts~=0.10.0
222
+ Requires-Dist: hugr~=0.13.1
223
+ Requires-Dist: tket-exts~=0.11.0
224
224
  Requires-Dist: typing-extensions<5,>=4.9.0
225
225
  Provides-Extra: pytket
226
226
  Requires-Dist: pytket>=1.34; extra == 'pytket'
@@ -228,7 +228,7 @@ Description-Content-Type: text/markdown
228
228
 
229
229
  # guppylang-internals
230
230
 
231
- This packages contains the internals of the Guppy compiler.
231
+ This packages contains the internals of the Guppy compiler.
232
232
 
233
233
  See `guppylang` for the package providing the user-facing language frontend.
234
234
 
@@ -250,4 +250,4 @@ See [DEVELOPMENT.md] information on how to develop and contribute to this packag
250
250
 
251
251
  This project is licensed under Apache License, Version 2.0 ([LICENCE][] or http://www.apache.org/licenses/LICENSE-2.0).
252
252
 
253
- [LICENCE]: https://github.com/CQCL/guppylang/blob/main/LICENCE
253
+ [LICENCE]: https://github.com/CQCL/guppylang/blob/main/LICENCE
@@ -1,6 +1,6 @@
1
1
  # guppylang-internals
2
2
 
3
- This packages contains the internals of the Guppy compiler.
3
+ This packages contains the internals of the Guppy compiler.
4
4
 
5
5
  See `guppylang` for the package providing the user-facing language frontend.
6
6
 
@@ -22,4 +22,4 @@ See [DEVELOPMENT.md] information on how to develop and contribute to this packag
22
22
 
23
23
  This project is licensed under Apache License, Version 2.0 ([LICENCE][] or http://www.apache.org/licenses/LICENSE-2.0).
24
24
 
25
- [LICENCE]: https://github.com/CQCL/guppylang/blob/main/LICENCE
25
+ [LICENCE]: https://github.com/CQCL/guppylang/blob/main/LICENCE
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "guppylang-internals"
3
- version = "0.22.0"
3
+ version = "0.24.0"
4
4
  requires-python = ">=3.10,<4"
5
5
  description = "Compiler internals for `guppylang` package."
6
6
  license = { file = "LICENCE" }
@@ -34,8 +34,8 @@ classifiers = [
34
34
 
35
35
  dependencies = [
36
36
  "typing-extensions >=4.9.0,<5",
37
- "tket-exts ~= 0.10.0",
38
- "hugr >= 0.13.0rc1,<0.14",
37
+ "tket-exts ~= 0.11.0",
38
+ "hugr ~= 0.13.1",
39
39
  ]
40
40
 
41
41
  [project.optional-dependencies]
@@ -1,3 +1,3 @@
1
1
  # This is updated by our release-please workflow, triggered by this
2
2
  # annotation: x-release-please-version
3
- __version__ = "0.22.0"
3
+ __version__ = "0.24.0"
@@ -27,6 +27,9 @@ class BaseCFG(Generic[T]):
27
27
  ass_before: Result[DefAssignmentDomain[str]]
28
28
  maybe_ass_before: Result[MaybeAssignmentDomain[str]]
29
29
 
30
+ #: Set of variables defined in this CFG
31
+ assigned_somewhere: set[str]
32
+
30
33
  def __init__(
31
34
  self, bbs: list[T], entry_bb: T | None = None, exit_bb: T | None = None
32
35
  ):
@@ -38,6 +41,7 @@ class BaseCFG(Generic[T]):
38
41
  self.live_before = {}
39
42
  self.ass_before = {}
40
43
  self.maybe_ass_before = {}
44
+ self.assigned_somewhere = set()
41
45
 
42
46
  def ancestors(self, *bbs: T) -> Iterator[T]:
43
47
  """Returns an iterator over all ancestors of the given BBs in BFS order."""
@@ -101,6 +105,10 @@ class CFG(BaseCFG[BB]):
101
105
  inout_vars: list[str],
102
106
  ) -> dict[BB, VariableStats[str]]:
103
107
  stats = {bb: bb.compute_variable_stats() for bb in self.bbs}
108
+ # Locals are variables that are assigned somewhere inside the function
109
+ self.assigned_somewhere = def_ass_before.union(
110
+ maybe_ass_before, (x for bb in self.bbs for x in stats[bb].assigned)
111
+ )
104
112
  # Mark all borrowed variables as implicitly used in the exit BB
105
113
  stats[self.exit_bb].used |= {x: InoutReturnSentinel(var=x) for x in inout_vars}
106
114
  # This also means borrowed variables are always live, so we can use them as the
@@ -8,7 +8,7 @@ import ast
8
8
  import collections
9
9
  from collections.abc import Iterator, Sequence
10
10
  from dataclasses import dataclass, field
11
- from typing import ClassVar, Generic, TypeVar, cast
11
+ from typing import ClassVar, Generic, TypeVar
12
12
 
13
13
  from guppylang_internals.ast_util import line_col
14
14
  from guppylang_internals.cfg.bb import BB
@@ -23,7 +23,6 @@ from guppylang_internals.checker.core import (
23
23
  )
24
24
  from guppylang_internals.checker.expr_checker import ExprSynthesizer, to_bool
25
25
  from guppylang_internals.checker.stmt_checker import StmtChecker
26
- from guppylang_internals.definition.value import ValueDef
27
26
  from guppylang_internals.diagnostic import Error, Note
28
27
  from guppylang_internals.error import GuppyError
29
28
  from guppylang_internals.tys.param import Parameter
@@ -115,7 +114,7 @@ def check_cfg(
115
114
  if bb in compiled:
116
115
  # If the BB was already compiled, we just have to check that the signatures
117
116
  # match.
118
- check_rows_match(input_row, compiled[bb].sig.input_row, bb, globals)
117
+ check_rows_match(input_row, compiled[bb].sig.input_row, bb)
119
118
  else:
120
119
  # Otherwise, check the BB and enqueue its successors
121
120
  checked_bb = check_bb(
@@ -195,21 +194,6 @@ class BranchTypeError(Error):
195
194
  span_label: ClassVar[str] = "This is of type `{ty}`"
196
195
  ty: Type
197
196
 
198
- @dataclass(frozen=True)
199
- class GlobalHint(Note):
200
- message: ClassVar[str] = (
201
- "{ident} may be shadowing a global {defn.description} definition of type "
202
- "`{defn.ty}` on some branches"
203
- )
204
- defn: ValueDef
205
-
206
-
207
- @dataclass(frozen=True)
208
- class GlobalShadowError(Error):
209
- title: ClassVar[str] = "Global variable conditionally shadowed"
210
- span_label: ClassVar[str] = "{ident} may be shadowing a global variable"
211
- ident: str
212
-
213
197
 
214
198
  def check_bb(
215
199
  bb: BB,
@@ -245,23 +229,27 @@ def check_bb(
245
229
 
246
230
  for succ in bb.successors + bb.dummy_successors:
247
231
  for x, use_bb in cfg.live_before[succ].items():
248
- # Check that the variables requested by the successor are defined
249
- if (
250
- x not in ctx.locals
251
- and x not in ctx.globals
252
- and x not in ctx.generic_params
253
- ):
254
- # If the variable is defined on *some* paths, we can give a more
255
- # informative error message
256
- if x in cfg.maybe_ass_before[use_bb]:
257
- err = VarMaybeNotDefinedError(use_bb.vars.used[x], x)
258
- if bad_branch := diagnose_maybe_undefined(use_bb, x, cfg):
259
- branch_expr, truth_value = bad_branch
260
- note = VarMaybeNotDefinedError.BadBranch(
261
- branch_expr, x, truth_value
262
- )
263
- err.add_sub_diagnostic(note)
232
+ # Check that the variables requested by the successor are defined. If `x` is
233
+ # a local variable, then we must be able to find it in the context.
234
+ # Following Python, locals are exactly those variables that are defined
235
+ # somewhere in the function body.
236
+ if x in cfg.assigned_somewhere:
237
+ if x not in ctx.locals:
238
+ # If the variable is defined on *some* paths, we can give a more
239
+ # informative error message
240
+ if x in cfg.maybe_ass_before[use_bb]:
241
+ err: Error = VarMaybeNotDefinedError(use_bb.vars.used[x], x)
242
+ if bad_branch := diagnose_maybe_undefined(use_bb, x, cfg):
243
+ branch_expr, truth_value = bad_branch
244
+ note = VarMaybeNotDefinedError.BadBranch(
245
+ branch_expr, x, truth_value
246
+ )
247
+ err.add_sub_diagnostic(note)
248
+ else:
249
+ err = VarNotDefinedError(use_bb.vars.used[x], x)
264
250
  raise GuppyError(err)
251
+ # If x is not a local, then it must be a global or generic param
252
+ elif x not in ctx.globals and x not in ctx.generic_params:
265
253
  raise GuppyError(VarNotDefinedError(use_bb.vars.used[x], x))
266
254
 
267
255
  # Finally, we need to compute the signature of the basic block
@@ -287,9 +275,7 @@ def check_bb(
287
275
  return checked_bb
288
276
 
289
277
 
290
- def check_rows_match(
291
- row1: Row[Variable], row2: Row[Variable], bb: BB, globals: Globals
292
- ) -> None:
278
+ def check_rows_match(row1: Row[Variable], row2: Row[Variable], bb: BB) -> None:
293
279
  """Checks that the types of two rows match up.
294
280
 
295
281
  Otherwise, an error is thrown, alerting the user that a variable has different
@@ -299,10 +285,7 @@ def check_rows_match(
299
285
  for x in map1.keys() | map2.keys():
300
286
  # If block signature lengths don't match but no undefined error was thrown, some
301
287
  # variables may be shadowing global variables.
302
- v1 = map1.get(x) or cast(ValueDef, globals[x])
303
- assert isinstance(v1, Variable | ValueDef)
304
- v2 = map2.get(x) or cast(ValueDef, globals[x])
305
- assert isinstance(v2, Variable | ValueDef)
288
+ v1, v2 = map1[x], map2[x]
306
289
  if v1.ty != v2.ty:
307
290
  # In the error message, we want to mention the variable that was first
308
291
  # defined at the start.
@@ -320,31 +303,9 @@ def check_rows_match(
320
303
  # We don't add a location to the type hint for the global variable,
321
304
  # since it could lead to cross-file diagnostics (which are not
322
305
  # supported) or refer to long function definitions.
323
- sub1 = (
324
- BranchTypeError.TypeHint(v1.defined_at, v1.ty)
325
- if isinstance(v1, Variable)
326
- else BranchTypeError.GlobalHint(None, v1)
327
- )
328
- sub2 = (
329
- BranchTypeError.TypeHint(v2.defined_at, v2.ty)
330
- if isinstance(v2, Variable)
331
- else BranchTypeError.GlobalHint(None, v2)
332
- )
333
- err.add_sub_diagnostic(sub1)
334
- err.add_sub_diagnostic(sub2)
306
+ err.add_sub_diagnostic(BranchTypeError.TypeHint(v1.defined_at, v1.ty))
307
+ err.add_sub_diagnostic(BranchTypeError.TypeHint(v2.defined_at, v2.ty))
335
308
  raise GuppyError(err)
336
- else:
337
- # TODO: Remove once https://github.com/CQCL/guppylang/issues/827 is done.
338
- # If either is a global variable, don't allow shadowing even if types match.
339
- if not (isinstance(v1, Variable) and isinstance(v2, Variable)):
340
- local_var = v1 if isinstance(v1, Variable) else v2
341
- ident = (
342
- "Expression"
343
- if local_var.name.startswith("%")
344
- else f"Variable `{local_var.name}`"
345
- )
346
- glob_err = GlobalShadowError(local_var.defined_at, ident)
347
- raise GuppyError(glob_err)
348
309
 
349
310
 
350
311
  def diagnose_maybe_undefined(
@@ -54,6 +54,7 @@ from guppylang_internals.tys.ty import (
54
54
 
55
55
  if TYPE_CHECKING:
56
56
  from guppylang_internals.definition.struct import StructField
57
+ from guppylang_internals.tys.parsing import TypeParsingCtx
57
58
 
58
59
 
59
60
  #: A "place" is a description for a storage location of a local value that users
@@ -507,6 +508,13 @@ class Context(NamedTuple):
507
508
  locals: Locals[str, Variable]
508
509
  generic_params: dict[str, Parameter]
509
510
 
511
+ @property
512
+ def parsing_ctx(self) -> "TypeParsingCtx":
513
+ """A type parsing context derived from this checking context."""
514
+ from guppylang_internals.tys.parsing import TypeParsingCtx
515
+
516
+ return TypeParsingCtx(self.globals, self.generic_params)
517
+
510
518
 
511
519
  class DummyEvalDict(dict[str, Any]):
512
520
  """A custom dict that can be passed to `eval` to give better error messages.
@@ -34,6 +34,7 @@ from guppylang_internals.ast_util import (
34
34
  AstNode,
35
35
  AstVisitor,
36
36
  breaks_in_loop,
37
+ get_type,
37
38
  get_type_opt,
38
39
  return_nodes_in_ast,
39
40
  with_loc,
@@ -101,8 +102,6 @@ from guppylang_internals.nodes import (
101
102
  FieldAccessAndDrop,
102
103
  GenericParamValue,
103
104
  GlobalName,
104
- IterEnd,
105
- IterHasNext,
106
105
  IterNext,
107
106
  LocalCall,
108
107
  MakeIter,
@@ -784,14 +783,6 @@ class ExprSynthesizer(AstVisitor[tuple[ast.expr, Type]]):
784
783
  raise GuppyTypeError(err)
785
784
  return expr, ty
786
785
 
787
- def visit_IterHasNext(self, node: IterHasNext) -> tuple[ast.expr, Type]:
788
- node.value, ty = self.synthesize(node.value)
789
- flags = InputFlags.Owned if not ty.copyable else InputFlags.NoFlags
790
- exp_sig = FunctionType([FuncInput(ty, flags)], TupleType([bool_type(), ty]))
791
- return self.synthesize_instance_func(
792
- node.value, [], "__hasnext__", "an iterator", exp_sig, True
793
- )
794
-
795
786
  def visit_IterNext(self, node: IterNext) -> tuple[ast.expr, Type]:
796
787
  node.value, ty = self.synthesize(node.value)
797
788
  flags = InputFlags.Owned if not ty.copyable else InputFlags.NoFlags
@@ -803,14 +794,6 @@ class ExprSynthesizer(AstVisitor[tuple[ast.expr, Type]]):
803
794
  node.value, [], "__next__", "an iterator", exp_sig, True
804
795
  )
805
796
 
806
- def visit_IterEnd(self, node: IterEnd) -> tuple[ast.expr, Type]:
807
- node.value, ty = self.synthesize(node.value)
808
- flags = InputFlags.Owned if not ty.copyable else InputFlags.NoFlags
809
- exp_sig = FunctionType([FuncInput(ty, flags)], NoneType())
810
- return self.synthesize_instance_func(
811
- node.value, [], "__end__", "an iterator", exp_sig, True
812
- )
813
-
814
797
  def visit_ListComp(self, node: ast.ListComp) -> tuple[ast.expr, Type]:
815
798
  raise InternalGuppyError(
816
799
  "BB contains `ListComp`. Should have been removed during CFG"
@@ -946,7 +929,7 @@ def check_type_apply(ty: FunctionType, node: ast.Subscript, ctx: Context) -> Ins
946
929
  raise GuppyError(err)
947
930
 
948
931
  return [
949
- param.check_arg(arg_from_ast(arg_expr, globals, ctx.generic_params), arg_expr)
932
+ param.check_arg(arg_from_ast(arg_expr, ctx.parsing_ctx), arg_expr)
950
933
  for arg_expr, param in zip(arg_exprs, ty.params, strict=True)
951
934
  ]
952
935
 
@@ -1232,7 +1215,14 @@ def instantiate_poly(node: ast.expr, ty: FunctionType, inst: Inst) -> ast.expr:
1232
1215
  """Instantiates quantified type arguments in a function."""
1233
1216
  assert len(ty.params) == len(inst)
1234
1217
  if len(inst) > 0:
1235
- node = with_loc(node, TypeApply(value=with_type(ty, node), inst=inst))
1218
+ # Partial applications need to be instantiated on the inside
1219
+ if isinstance(node, PartialApply):
1220
+ full_ty = get_type(node.func)
1221
+ assert isinstance(full_ty, FunctionType)
1222
+ assert full_ty.params == ty.params
1223
+ node.func = instantiate_poly(node.func, full_ty, inst)
1224
+ else:
1225
+ node = with_loc(node, TypeApply(value=with_type(ty, node), inst=inst))
1236
1226
  return with_type(ty.instantiate(inst), node)
1237
1227
  return with_type(ty, node)
1238
1228
 
@@ -1309,11 +1299,7 @@ def eval_comptime_expr(node: ComptimeExpr, ctx: Context) -> Any:
1309
1299
  raise GuppyError(ComptimeExprNotCPythonError(node))
1310
1300
 
1311
1301
  try:
1312
- python_val = eval( # noqa: S307
1313
- ast.unparse(node.value),
1314
- None,
1315
- DummyEvalDict(ctx, node.value),
1316
- )
1302
+ python_val = eval(ast.unparse(node.value), DummyEvalDict(ctx, node.value)) # noqa: S307
1317
1303
  except DummyEvalDict.GuppyVarUsedError as e:
1318
1304
  raise GuppyError(ComptimeExprNotStaticError(e.node or node, e.var)) from None
1319
1305
  except Exception as e: