guppylang-internals 0.27.0__tar.gz → 0.28.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.
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/CHANGELOG.md +22 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/PKG-INFO +5 -4
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/pyproject.toml +6 -7
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/__init__.py +1 -1
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/ast_util.py +37 -18
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/cfg/analysis.py +6 -6
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/cfg/builder.py +41 -12
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/cfg/cfg.py +1 -1
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/core.py +1 -1
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/errors/comptime_errors.py +0 -12
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/expr_checker.py +27 -17
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/func_checker.py +4 -3
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/stmt_checker.py +1 -1
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/compiler/cfg_compiler.py +1 -1
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/compiler/core.py +17 -4
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/compiler/expr_compiler.py +9 -9
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/decorator.py +2 -2
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/common.py +1 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/custom.py +2 -2
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/declaration.py +3 -3
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/function.py +8 -1
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/metadata.py +1 -1
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/pytket_circuits.py +44 -65
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/value.py +1 -1
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/wasm.py +3 -3
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/diagnostic.py +17 -1
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/engine.py +83 -30
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/error.py +1 -1
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/nodes.py +269 -3
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/span.py +7 -3
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/checker.py +104 -2
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/debug.py +5 -3
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tracing/builtins_mock.py +2 -2
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tracing/object.py +2 -2
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tys/parsing.py +4 -1
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tys/qubit.py +6 -4
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tys/subst.py +2 -2
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tys/ty.py +2 -2
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/wasm_util.py +1 -2
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/.gitignore +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/LICENCE +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/README.md +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/cfg/__init__.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/cfg/bb.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/__init__.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/cfg_checker.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/errors/__init__.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/errors/generic.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/errors/linearity.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/errors/type_errors.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/errors/wasm.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/linearity_checker.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/modifier_checker.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/unitary_checker.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/compiler/__init__.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/compiler/func_compiler.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/compiler/hugr_extension.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/compiler/modifier_compiler.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/compiler/qtm_platform_extension.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/compiler/stmt_compiler.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/__init__.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/const.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/extern.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/overloaded.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/parameter.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/struct.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/traced.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/definition/ty.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/dummy_decorator.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/experimental.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/ipython_inspect.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/py.typed +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/__init__.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/__init__.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/__init__.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/arithmetic.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/array.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/either.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/frozenarray.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/futures.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/list.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/mem.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/option.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/platform.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/prelude.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/qsystem.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/quantum.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/tket_bool.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/tket_exts.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler/wasm.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/compiler.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/std/_internal/util.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tracing/__init__.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tracing/frozenlist.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tracing/function.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tracing/state.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tracing/unpacking.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tracing/util.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tys/__init__.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tys/arg.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tys/builtin.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tys/common.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tys/const.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tys/errors.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tys/param.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tys/printing.py +0 -0
- {guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/tys/var.py +0 -0
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
First release of `guppylang_internals` package containing refactored out internal components
|
|
4
4
|
from `guppylang`.
|
|
5
5
|
|
|
6
|
+
## [0.28.0](https://github.com/Quantinuum/guppylang/compare/guppylang-internals-v0.27.0...guppylang-internals-v0.28.0) (2026-02-04)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### ⚠ BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* Tket is now a non-optional dependency. Most systems already have this installed, rerunning the package manager should fix any issues.
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* Label `FuncDefn`s with qualified names in HUGR ([#1452](https://github.com/Quantinuum/guppylang/issues/1452)) ([a92f274](https://github.com/Quantinuum/guppylang/commit/a92f274a14668b7ac88713a69a6902aca62d4483))
|
|
16
|
+
* Make tket a non-optional dependency ([#1440](https://github.com/Quantinuum/guppylang/issues/1440)) ([4af4360](https://github.com/Quantinuum/guppylang/commit/4af4360495c9d6155e69310d5bfb8f22953fc1ff))
|
|
17
|
+
* use hugr used_extensions in engine.py ([#1451](https://github.com/Quantinuum/guppylang/issues/1451)) ([c16b96b](https://github.com/Quantinuum/guppylang/commit/c16b96bd5dc6ab4df13e3242ffe55279b317dd7e))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* Add a copy before fallable `synthesize_call` call ([#1460](https://github.com/Quantinuum/guppylang/issues/1460)) ([84137c3](https://github.com/Quantinuum/guppylang/commit/84137c39b7e8ca24142ffe73afcce6a1bcceffe2))
|
|
23
|
+
* Raise type inference error when not all function argument types could be resolved. ([#1439](https://github.com/Quantinuum/guppylang/issues/1439)) ([4120d59](https://github.com/Quantinuum/guppylang/commit/4120d590917245258d69ceb07c763c7633c7c5f8)), closes [#1437](https://github.com/Quantinuum/guppylang/issues/1437)
|
|
24
|
+
* Remove leading tab characters from diagnostics during rendering ([#1447](https://github.com/Quantinuum/guppylang/issues/1447)) ([a1cf792](https://github.com/Quantinuum/guppylang/commit/a1cf792deaf90e31721505ac17fd4911737e6c26)), closes [#1101](https://github.com/Quantinuum/guppylang/issues/1101)
|
|
25
|
+
* Support comptime expressions in subscript assignments ([#1433](https://github.com/Quantinuum/guppylang/issues/1433)) ([108c104](https://github.com/Quantinuum/guppylang/commit/108c104d55ecb052d4d7c363062f444efc689724)), closes [#1363](https://github.com/Quantinuum/guppylang/issues/1363)
|
|
26
|
+
* Support more cases of comptime subscripts ([#1436](https://github.com/Quantinuum/guppylang/issues/1436)) ([9aefdcc](https://github.com/Quantinuum/guppylang/commit/9aefdcc50b142acf842cf60314b5bccc49e01614)), closes [#1435](https://github.com/Quantinuum/guppylang/issues/1435)
|
|
27
|
+
|
|
6
28
|
## [0.27.0](https://github.com/Quantinuum/guppylang/compare/guppylang-internals-v0.26.0...guppylang-internals-v0.27.0) (2026-01-08)
|
|
7
29
|
|
|
8
30
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: guppylang-internals
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.28.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,12 +219,13 @@ 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.15.
|
|
222
|
+
Requires-Dist: hugr~=0.15.1
|
|
223
|
+
Requires-Dist: pytket>=1.34
|
|
223
224
|
Requires-Dist: tket-exts~=0.12.0
|
|
225
|
+
Requires-Dist: tket>=0.12.7
|
|
224
226
|
Requires-Dist: typing-extensions<5,>=4.9.0
|
|
225
|
-
Requires-Dist: wasmtime
|
|
227
|
+
Requires-Dist: wasmtime<41.1,>=38.0
|
|
226
228
|
Provides-Extra: pytket
|
|
227
|
-
Requires-Dist: pytket>=1.34; extra == 'pytket'
|
|
228
229
|
Description-Content-Type: text/markdown
|
|
229
230
|
|
|
230
231
|
# guppylang-internals
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "guppylang-internals"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.28.0"
|
|
4
4
|
requires-python = ">=3.10,<4"
|
|
5
5
|
description = "Compiler internals for `guppylang` package."
|
|
6
6
|
license = { file = "LICENCE" }
|
|
@@ -16,13 +16,10 @@ maintainers = [
|
|
|
16
16
|
|
|
17
17
|
classifiers = [
|
|
18
18
|
"Development Status :: 3 - Alpha",
|
|
19
|
-
|
|
20
19
|
"Intended Audience :: Developers",
|
|
21
20
|
"Intended Audience :: Science/Research",
|
|
22
21
|
"Topic :: Software Development :: Compilers",
|
|
23
|
-
|
|
24
22
|
"License :: OSI Approved :: Apache Software License",
|
|
25
|
-
|
|
26
23
|
"Programming Language :: Python :: 3",
|
|
27
24
|
"Programming Language :: Python :: 3.10",
|
|
28
25
|
"Programming Language :: Python :: 3.11",
|
|
@@ -35,12 +32,14 @@ classifiers = [
|
|
|
35
32
|
dependencies = [
|
|
36
33
|
"typing-extensions >=4.9.0,<5",
|
|
37
34
|
"tket-exts ~= 0.12.0",
|
|
38
|
-
"hugr ~= 0.15.
|
|
39
|
-
"wasmtime
|
|
35
|
+
"hugr ~= 0.15.1",
|
|
36
|
+
"wasmtime>=38.0,<41.1",
|
|
37
|
+
"pytket>=1.34",
|
|
38
|
+
"tket >= 0.12.7",
|
|
40
39
|
]
|
|
41
40
|
|
|
42
41
|
[project.optional-dependencies]
|
|
43
|
-
pytket = [
|
|
42
|
+
pytket = []
|
|
44
43
|
|
|
45
44
|
[build-system]
|
|
46
45
|
requires = ["hatchling"]
|
{guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/ast_util.py
RENAMED
|
@@ -97,13 +97,13 @@ def find_nodes(
|
|
|
97
97
|
def name_nodes_in_ast(node: Any) -> list[ast.Name]:
|
|
98
98
|
"""Returns all `Name` nodes occurring in an AST."""
|
|
99
99
|
found = find_nodes(lambda n: isinstance(n, ast.Name), node)
|
|
100
|
-
return cast(list[ast.Name], found)
|
|
100
|
+
return cast("list[ast.Name]", found)
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
def return_nodes_in_ast(node: Any) -> list[ast.Return]:
|
|
104
104
|
"""Returns all `Return` nodes occurring in an AST."""
|
|
105
105
|
found = find_nodes(lambda n: isinstance(n, ast.Return), node, {ast.FunctionDef})
|
|
106
|
-
return cast(list[ast.Return], found)
|
|
106
|
+
return cast("list[ast.Return]", found)
|
|
107
107
|
|
|
108
108
|
|
|
109
109
|
def loop_in_ast(node: Any) -> list[ast.For | ast.While]:
|
|
@@ -111,7 +111,7 @@ def loop_in_ast(node: Any) -> list[ast.For | ast.While]:
|
|
|
111
111
|
found = find_nodes(
|
|
112
112
|
lambda n: isinstance(n, ast.For | ast.While), node, {ast.FunctionDef}
|
|
113
113
|
)
|
|
114
|
-
return cast(list[ast.For | ast.While], found)
|
|
114
|
+
return cast("list[ast.For | ast.While]", found)
|
|
115
115
|
|
|
116
116
|
|
|
117
117
|
def breaks_in_loop(node: Any) -> list[ast.Break]:
|
|
@@ -122,7 +122,7 @@ def breaks_in_loop(node: Any) -> list[ast.Break]:
|
|
|
122
122
|
found = find_nodes(
|
|
123
123
|
lambda n: isinstance(n, ast.Break), node, {ast.For, ast.While, ast.FunctionDef}
|
|
124
124
|
)
|
|
125
|
-
return cast(list[ast.Break], found)
|
|
125
|
+
return cast("list[ast.Break]", found)
|
|
126
126
|
|
|
127
127
|
|
|
128
128
|
def loop_controls_in_loop(node: Any) -> list[ast.Break | ast.Continue]:
|
|
@@ -135,7 +135,7 @@ def loop_controls_in_loop(node: Any) -> list[ast.Break | ast.Continue]:
|
|
|
135
135
|
node,
|
|
136
136
|
{ast.For, ast.While, ast.FunctionDef},
|
|
137
137
|
)
|
|
138
|
-
return cast(list[ast.Break | ast.Continue], found)
|
|
138
|
+
return cast("list[ast.Break | ast.Continue]", found)
|
|
139
139
|
|
|
140
140
|
|
|
141
141
|
class ContextAdjuster(ast.NodeTransformer):
|
|
@@ -147,7 +147,7 @@ class ContextAdjuster(ast.NodeTransformer):
|
|
|
147
147
|
self.ctx = ctx
|
|
148
148
|
|
|
149
149
|
def visit(self, node: ast.AST) -> ast.AST:
|
|
150
|
-
return cast(ast.AST, super().visit(node))
|
|
150
|
+
return cast("ast.AST", super().visit(node))
|
|
151
151
|
|
|
152
152
|
def visit_Name(self, node: ast.Name) -> ast.Name:
|
|
153
153
|
return with_loc(node, ast.Name(id=node.id, ctx=self.ctx))
|
|
@@ -156,29 +156,48 @@ class ContextAdjuster(ast.NodeTransformer):
|
|
|
156
156
|
self,
|
|
157
157
|
node: ast.Starred,
|
|
158
158
|
) -> ast.Starred:
|
|
159
|
-
return with_loc(
|
|
159
|
+
return with_loc(
|
|
160
|
+
node,
|
|
161
|
+
ast.Starred(value=self.visit(node.value), ctx=self.ctx), # type: ignore[arg-type]
|
|
162
|
+
)
|
|
160
163
|
|
|
161
164
|
def visit_Tuple(self, node: ast.Tuple) -> ast.Tuple:
|
|
162
165
|
return with_loc(
|
|
163
|
-
node,
|
|
166
|
+
node,
|
|
167
|
+
ast.Tuple(
|
|
168
|
+
elts=[self.visit(elt) for elt in node.elts], # type: ignore[misc]
|
|
169
|
+
ctx=self.ctx,
|
|
170
|
+
),
|
|
164
171
|
)
|
|
165
172
|
|
|
166
173
|
def visit_List(self, node: ast.List) -> ast.List:
|
|
167
174
|
return with_loc(
|
|
168
|
-
node,
|
|
175
|
+
node,
|
|
176
|
+
ast.List(
|
|
177
|
+
elts=[self.visit(elt) for elt in node.elts], # type: ignore[misc]
|
|
178
|
+
ctx=self.ctx,
|
|
179
|
+
),
|
|
169
180
|
)
|
|
170
181
|
|
|
171
182
|
def visit_Subscript(self, node: ast.Subscript) -> ast.Subscript:
|
|
172
183
|
# Don't adjust the slice!
|
|
173
184
|
return with_loc(
|
|
174
185
|
node,
|
|
175
|
-
ast.Subscript(
|
|
186
|
+
ast.Subscript(
|
|
187
|
+
value=self.visit(node.value), # type: ignore[arg-type]
|
|
188
|
+
slice=node.slice,
|
|
189
|
+
ctx=self.ctx,
|
|
190
|
+
),
|
|
176
191
|
)
|
|
177
192
|
|
|
178
193
|
def visit_Attribute(self, node: ast.Attribute) -> ast.Attribute:
|
|
179
194
|
return with_loc(
|
|
180
195
|
node,
|
|
181
|
-
ast.Attribute(
|
|
196
|
+
ast.Attribute(
|
|
197
|
+
value=self.visit(node.value), # type: ignore[arg-type]
|
|
198
|
+
attr=node.attr,
|
|
199
|
+
ctx=self.ctx,
|
|
200
|
+
),
|
|
182
201
|
)
|
|
183
202
|
|
|
184
203
|
|
|
@@ -240,15 +259,15 @@ def template_replace(
|
|
|
240
259
|
|
|
241
260
|
def line_col(node: ast.AST) -> tuple[int, int]:
|
|
242
261
|
"""Returns the line and column of an ast node."""
|
|
243
|
-
return node.lineno, node.col_offset
|
|
262
|
+
return node.lineno, node.col_offset # type: ignore[attr-defined]
|
|
244
263
|
|
|
245
264
|
|
|
246
265
|
def set_location_from(node: ast.AST, loc: ast.AST) -> None:
|
|
247
266
|
"""Copy source location from one AST node to the other."""
|
|
248
|
-
node.lineno = loc.lineno
|
|
249
|
-
node.col_offset = loc.col_offset
|
|
250
|
-
node.end_lineno = loc.end_lineno
|
|
251
|
-
node.end_col_offset = loc.end_col_offset
|
|
267
|
+
node.lineno = loc.lineno # type: ignore[attr-defined]
|
|
268
|
+
node.col_offset = loc.col_offset # type: ignore[attr-defined]
|
|
269
|
+
node.end_lineno = loc.end_lineno # type: ignore[attr-defined]
|
|
270
|
+
node.end_col_offset = loc.end_col_offset # type: ignore[attr-defined]
|
|
252
271
|
|
|
253
272
|
source, file, line_offset = get_source(loc), get_file(loc), get_line_offset(loc)
|
|
254
273
|
assert source is not None
|
|
@@ -341,11 +360,11 @@ def with_type(ty: "Type", node: A) -> A:
|
|
|
341
360
|
|
|
342
361
|
def get_type_opt(node: AstNode) -> Optional["Type"]:
|
|
343
362
|
"""Tries to retrieve a type annotation from an AST node."""
|
|
344
|
-
from guppylang_internals.tys.ty import
|
|
363
|
+
from guppylang_internals.tys.ty import TypeBase
|
|
345
364
|
|
|
346
365
|
try:
|
|
347
366
|
ty = node.type # type: ignore[union-attr]
|
|
348
|
-
return cast(Type, ty) if isinstance(ty, TypeBase) else None
|
|
367
|
+
return cast("Type", ty) if isinstance(ty, TypeBase) else None
|
|
349
368
|
except AttributeError:
|
|
350
369
|
return None
|
|
351
370
|
|
{guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/cfg/analysis.py
RENAMED
|
@@ -11,7 +11,7 @@ T = TypeVar("T")
|
|
|
11
11
|
Result = dict[BB, T]
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
class Analysis(Generic[T]
|
|
14
|
+
class Analysis(ABC, Generic[T]):
|
|
15
15
|
"""Abstract base class for a program analysis pass over the lattice `T`"""
|
|
16
16
|
|
|
17
17
|
def eq(self, t1: T, t2: T, /) -> bool:
|
|
@@ -39,7 +39,7 @@ class Analysis(Generic[T], ABC):
|
|
|
39
39
|
"""
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
class ForwardAnalysis(
|
|
42
|
+
class ForwardAnalysis(Analysis[T], ABC, Generic[T]):
|
|
43
43
|
"""Abstract base class for a program analysis pass running in forward direction."""
|
|
44
44
|
|
|
45
45
|
@abstractmethod
|
|
@@ -71,7 +71,7 @@ class ForwardAnalysis(Generic[T], Analysis[T], ABC):
|
|
|
71
71
|
return vals_before
|
|
72
72
|
|
|
73
73
|
|
|
74
|
-
class BackwardAnalysis(
|
|
74
|
+
class BackwardAnalysis(Analysis[T], ABC, Generic[T]):
|
|
75
75
|
"""Abstract base class for a program analysis pass running in backward direction."""
|
|
76
76
|
|
|
77
77
|
@abstractmethod
|
|
@@ -105,7 +105,7 @@ class BackwardAnalysis(Generic[T], Analysis[T], ABC):
|
|
|
105
105
|
LivenessDomain = dict[VId, BB]
|
|
106
106
|
|
|
107
107
|
|
|
108
|
-
class LivenessAnalysis(
|
|
108
|
+
class LivenessAnalysis(BackwardAnalysis[LivenessDomain[VId]], Generic[VId]):
|
|
109
109
|
"""Live variable analysis pass.
|
|
110
110
|
|
|
111
111
|
Computes the variables that are live before the execution of each BB. The analysis
|
|
@@ -143,7 +143,7 @@ class LivenessAnalysis(Generic[VId], BackwardAnalysis[LivenessDomain[VId]]):
|
|
|
143
143
|
|
|
144
144
|
def apply_bb(self, live_after: LivenessDomain[VId], bb: BB) -> LivenessDomain[VId]:
|
|
145
145
|
stats = self.stats[bb]
|
|
146
|
-
return
|
|
146
|
+
return dict.fromkeys(stats.used, bb) | {
|
|
147
147
|
x: b for x, b in live_after.items() if x not in stats.assigned
|
|
148
148
|
}
|
|
149
149
|
|
|
@@ -159,7 +159,7 @@ MaybeAssignmentDomain = set[VId]
|
|
|
159
159
|
AssignmentDomain = tuple[DefAssignmentDomain[VId], MaybeAssignmentDomain[VId]]
|
|
160
160
|
|
|
161
161
|
|
|
162
|
-
class AssignmentAnalysis(
|
|
162
|
+
class AssignmentAnalysis(ForwardAnalysis[AssignmentDomain[VId]], Generic[VId]):
|
|
163
163
|
"""Assigned variable analysis pass.
|
|
164
164
|
|
|
165
165
|
Computes the set of variables (i.e. `V`s) that are definitely assigned at the start
|
{guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/cfg/builder.py
RENAMED
|
@@ -154,27 +154,52 @@ class CFGBuilder(AstVisitor[BB | None]):
|
|
|
154
154
|
return bb_opt
|
|
155
155
|
|
|
156
156
|
def _build_node_value(self, node: BBStatement, bb: BB) -> BB:
|
|
157
|
-
"""Utility method for building a
|
|
157
|
+
"""Utility method for building a nodes `value` expression, if available.
|
|
158
158
|
|
|
159
159
|
Builds the expression and mutates `node.value` to point to the built expression.
|
|
160
|
-
Returns the BB in which the expression is available
|
|
160
|
+
Returns the BB in which the expression is available.
|
|
161
161
|
"""
|
|
162
162
|
if (
|
|
163
163
|
not isinstance(node, NestedFunctionDef | ModifiedBlock)
|
|
164
164
|
and node.value is not None
|
|
165
165
|
):
|
|
166
166
|
node.value, bb = ExprBuilder.build(node.value, self.cfg, bb)
|
|
167
|
-
bb
|
|
167
|
+
return bb
|
|
168
|
+
|
|
169
|
+
def _build_node_targets(self, node: BBStatement, bb: BB) -> BB:
|
|
170
|
+
"""Utility method for building a nodes `target` or `targets` expressions,
|
|
171
|
+
depending on the node type.
|
|
172
|
+
|
|
173
|
+
Builds the expressions and mutates the elements of `node.targets` to point to
|
|
174
|
+
the built expressions. Returns the BB in which the expressions are available.
|
|
175
|
+
"""
|
|
176
|
+
if isinstance(node, ast.Assign):
|
|
177
|
+
for i, target in enumerate(node.targets):
|
|
178
|
+
node.targets[i], bb = ExprBuilder.build(target, self.cfg, bb)
|
|
179
|
+
elif isinstance(node, ast.AugAssign | ast.AnnAssign):
|
|
180
|
+
new_target, bb = ExprBuilder.build(node.target, self.cfg, bb)
|
|
181
|
+
if not isinstance(new_target, ast.Name | ast.Attribute | ast.Subscript):
|
|
182
|
+
raise InternalGuppyError("Unexpected type for built expression.")
|
|
183
|
+
node.target = new_target
|
|
168
184
|
return bb
|
|
169
185
|
|
|
170
186
|
def visit_Assign(self, node: ast.Assign, bb: BB, jumps: Jumps) -> BB | None:
|
|
171
|
-
|
|
187
|
+
bb = self._build_node_value(node, bb)
|
|
188
|
+
bb = self._build_node_targets(node, bb)
|
|
189
|
+
bb.statements.append(node)
|
|
190
|
+
return bb
|
|
172
191
|
|
|
173
192
|
def visit_AugAssign(self, node: ast.AugAssign, bb: BB, jumps: Jumps) -> BB | None:
|
|
174
|
-
|
|
193
|
+
bb = self._build_node_value(node, bb)
|
|
194
|
+
bb = self._build_node_targets(node, bb)
|
|
195
|
+
bb.statements.append(node)
|
|
196
|
+
return bb
|
|
175
197
|
|
|
176
198
|
def visit_AnnAssign(self, node: ast.AnnAssign, bb: BB, jumps: Jumps) -> BB | None:
|
|
177
|
-
|
|
199
|
+
bb = self._build_node_value(node, bb)
|
|
200
|
+
bb = self._build_node_targets(node, bb)
|
|
201
|
+
bb.statements.append(node)
|
|
202
|
+
return bb
|
|
178
203
|
|
|
179
204
|
def visit_Expr(self, node: ast.Expr, bb: BB, jumps: Jumps) -> BB | None:
|
|
180
205
|
# This is an expression statement where the value is discarded
|
|
@@ -262,6 +287,7 @@ class CFGBuilder(AstVisitor[BB | None]):
|
|
|
262
287
|
|
|
263
288
|
def visit_Return(self, node: ast.Return, bb: BB, jumps: Jumps) -> BB | None:
|
|
264
289
|
bb = self._build_node_value(node, bb)
|
|
290
|
+
bb.statements.append(node)
|
|
265
291
|
self.cfg.link(bb, jumps.return_bb)
|
|
266
292
|
return None
|
|
267
293
|
|
|
@@ -572,7 +598,7 @@ class BranchBuilder(AstVisitor[None]):
|
|
|
572
598
|
comparators[:-1], node.ops, comparators[1:], strict=True
|
|
573
599
|
)
|
|
574
600
|
]
|
|
575
|
-
conj = ast.BoolOp(op=ast.And(), values=values)
|
|
601
|
+
conj = ast.BoolOp(op=ast.And(), values=values) # type: ignore[arg-type]
|
|
576
602
|
set_location_from(conj, node)
|
|
577
603
|
self.visit_BoolOp(conj, bb, true_bb, false_bb)
|
|
578
604
|
else:
|
|
@@ -682,8 +708,8 @@ def is_comptime_expression(node: ast.AST) -> ComptimeExpr | None:
|
|
|
682
708
|
case [arg]:
|
|
683
709
|
pass
|
|
684
710
|
case args:
|
|
685
|
-
arg = with_loc(node, ast.Tuple(elts=args, ctx=ast.Load))
|
|
686
|
-
return with_loc(node, ComptimeExpr(
|
|
711
|
+
arg = with_loc(node, ast.Tuple(elts=args, ctx=ast.Load)) # type: ignore[arg-type]
|
|
712
|
+
return with_loc(node, ComptimeExpr(arg))
|
|
687
713
|
return None
|
|
688
714
|
|
|
689
715
|
|
|
@@ -704,7 +730,7 @@ def is_illegal_in_list_comp(node: ast.AST) -> bool:
|
|
|
704
730
|
|
|
705
731
|
def make_var(name: str, loc: ast.AST | None = None) -> ast.Name:
|
|
706
732
|
"""Creates an `ast.Name` node."""
|
|
707
|
-
node = ast.Name(id=name, ctx=ast.Load)
|
|
733
|
+
node = ast.Name(id=name, ctx=ast.Load) # type: ignore[arg-type]
|
|
708
734
|
if loc is not None:
|
|
709
735
|
set_location_from(node, loc)
|
|
710
736
|
return node
|
|
@@ -718,5 +744,8 @@ def make_assign(lhs: list[ast.AST], value: ast.expr) -> ast.Assign:
|
|
|
718
744
|
if len(lhs) == 1:
|
|
719
745
|
target = lhs[0]
|
|
720
746
|
else:
|
|
721
|
-
target = with_loc(
|
|
722
|
-
|
|
747
|
+
target = with_loc(
|
|
748
|
+
value,
|
|
749
|
+
ast.Tuple(elts=lhs, ctx=ast.Store()), # type: ignore[arg-type]
|
|
750
|
+
)
|
|
751
|
+
return with_loc(value, ast.Assign(targets=[target], value=value)) # type: ignore[list-item]
|
{guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/cfg/cfg.py
RENAMED
|
@@ -118,7 +118,7 @@ class CFG(BaseCFG[BB]):
|
|
|
118
118
|
# initial value in the liveness analysis. This solves the edge case that
|
|
119
119
|
# borrowed variables should be considered live, even if the exit is actually
|
|
120
120
|
# unreachable (to avoid linearity violations later).
|
|
121
|
-
inout_live =
|
|
121
|
+
inout_live = dict.fromkeys(inout_vars, self.exit_bb)
|
|
122
122
|
self.live_before = LivenessAnalysis(
|
|
123
123
|
stats, initial=inout_live, include_unreachable=True
|
|
124
124
|
).run(self.bbs)
|
{guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/checker/core.py
RENAMED
|
@@ -384,7 +384,7 @@ class Globals:
|
|
|
384
384
|
case _:
|
|
385
385
|
return assert_never(ty)
|
|
386
386
|
|
|
387
|
-
type_defn = cast(TypeDef, ENGINE.get_checked(type_defn.id))
|
|
387
|
+
type_defn = cast("TypeDef", ENGINE.get_checked(type_defn.id))
|
|
388
388
|
if type_defn.id in DEF_STORE.impls and name in DEF_STORE.impls[type_defn.id]:
|
|
389
389
|
def_id = DEF_STORE.impls[type_defn.id][name]
|
|
390
390
|
defn = ENGINE.get_parsed(def_id)
|
|
@@ -44,18 +44,6 @@ class ComptimeExprIncoherentListError(Error):
|
|
|
44
44
|
span_label: ClassVar[str] = "List contains elements with different types"
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
@dataclass(frozen=True)
|
|
48
|
-
class TketNotInstalled(Error):
|
|
49
|
-
title: ClassVar[str] = "Tket not installed"
|
|
50
|
-
span_label: ClassVar[str] = (
|
|
51
|
-
"Experimental pytket compatibility requires `tket` to be installed"
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
@dataclass(frozen=True)
|
|
55
|
-
class InstallInstruction(Help):
|
|
56
|
-
message: ClassVar[str] = "Install tket: `pip install tket`"
|
|
57
|
-
|
|
58
|
-
|
|
59
47
|
@dataclass(frozen=True)
|
|
60
48
|
class PytketSignatureMismatch(Error):
|
|
61
49
|
title: ClassVar[str] = "Signature mismatch"
|
|
@@ -21,6 +21,7 @@ can be used to infer a type for an expression.
|
|
|
21
21
|
"""
|
|
22
22
|
|
|
23
23
|
import ast
|
|
24
|
+
import copy
|
|
24
25
|
import sys
|
|
25
26
|
import traceback
|
|
26
27
|
from collections.abc import Sequence
|
|
@@ -235,7 +236,7 @@ class ExprChecker(AstVisitor[tuple[ast.expr, Subst]]):
|
|
|
235
236
|
if actual := get_type_opt(expr):
|
|
236
237
|
expr, subst, inst = check_type_against(actual, ty, expr, self.ctx, kind)
|
|
237
238
|
if inst:
|
|
238
|
-
expr = with_loc(expr, TypeApply(
|
|
239
|
+
expr = with_loc(expr, TypeApply(expr, inst))
|
|
239
240
|
return with_type(ty.substitute(subst), expr), subst
|
|
240
241
|
|
|
241
242
|
# When checking against a variable, we have to synthesize
|
|
@@ -371,7 +372,7 @@ class ExprChecker(AstVisitor[tuple[ast.expr, Subst]]):
|
|
|
371
372
|
|
|
372
373
|
# Apply instantiation of quantified type variables
|
|
373
374
|
if inst:
|
|
374
|
-
node = with_loc(node, TypeApply(
|
|
375
|
+
node = with_loc(node, TypeApply(node, inst))
|
|
375
376
|
|
|
376
377
|
return node, subst
|
|
377
378
|
|
|
@@ -476,6 +477,7 @@ class ExprSynthesizer(AstVisitor[tuple[ast.expr, Type]]):
|
|
|
476
477
|
|
|
477
478
|
def visit_Attribute(self, node: ast.Attribute) -> tuple[ast.expr, Type]:
|
|
478
479
|
from guppylang.defs import GuppyDefinition
|
|
480
|
+
|
|
479
481
|
from guppylang_internals.engine import ENGINE
|
|
480
482
|
|
|
481
483
|
# A `value.attr` attribute access. Unfortunately, the `attr` is just a string,
|
|
@@ -1008,11 +1010,13 @@ def type_check_args(
|
|
|
1008
1010
|
new_args.append(a)
|
|
1009
1011
|
assert next(comptime_args, None) is None
|
|
1010
1012
|
|
|
1011
|
-
#
|
|
1012
|
-
#
|
|
1013
|
-
|
|
1014
|
-
set.issubset(inp.ty.unsolved_vars, subst.keys())
|
|
1015
|
-
|
|
1013
|
+
# Check whether we have found instantiations for all unification variables occurring
|
|
1014
|
+
# in the input types
|
|
1015
|
+
for inp in func_ty.inputs:
|
|
1016
|
+
if not set.issubset(inp.ty.unsolved_vars, subst.keys()):
|
|
1017
|
+
raise GuppyTypeInferenceError(
|
|
1018
|
+
TypeInferenceError(node, inp.ty.substitute(subst))
|
|
1019
|
+
)
|
|
1016
1020
|
|
|
1017
1021
|
# We also have to check that we found instantiations for all vars in the return type
|
|
1018
1022
|
if not set.issubset(func_ty.output.unsolved_vars, subst.keys()):
|
|
@@ -1177,19 +1181,25 @@ def check_call(
|
|
|
1177
1181
|
# However the bad case, e.g. `x: int = foo(foo(...foo(?)...))`, shouldn't be common
|
|
1178
1182
|
# in practice. Can we do better than that?
|
|
1179
1183
|
|
|
1180
|
-
#
|
|
1181
|
-
|
|
1184
|
+
# synthesize_call may modify args and node in place,
|
|
1185
|
+
# hence we deepcopy them before passing in the function
|
|
1186
|
+
node_copy = copy.deepcopy(node)
|
|
1187
|
+
inputs_copy = copy.deepcopy(inputs)
|
|
1188
|
+
|
|
1182
1189
|
try:
|
|
1183
1190
|
inputs, synth, inst = synthesize_call(func_ty, inputs, node, ctx)
|
|
1184
|
-
res = synth, inst
|
|
1185
|
-
except GuppyTypeInferenceError:
|
|
1186
|
-
pass
|
|
1187
|
-
if res is not None:
|
|
1188
|
-
synth, inst = res
|
|
1189
1191
|
subst = unify(ty, synth, {})
|
|
1190
1192
|
if subst is None:
|
|
1191
1193
|
raise GuppyTypeError(TypeMismatchError(node, ty, synth, kind))
|
|
1192
|
-
|
|
1194
|
+
else:
|
|
1195
|
+
return inputs, subst, inst
|
|
1196
|
+
except GuppyTypeInferenceError:
|
|
1197
|
+
pass
|
|
1198
|
+
|
|
1199
|
+
# Restore the state of these values from before they were potentially
|
|
1200
|
+
# modified by `synthesize_call`.
|
|
1201
|
+
inputs = inputs_copy
|
|
1202
|
+
node = node_copy
|
|
1193
1203
|
|
|
1194
1204
|
# If synthesis fails, we try again, this time also using information from the
|
|
1195
1205
|
# expected return type
|
|
@@ -1278,7 +1288,7 @@ def instantiate_poly(node: ast.expr, ty: FunctionType, inst: Inst) -> ast.expr:
|
|
|
1278
1288
|
assert full_ty.params == ty.params
|
|
1279
1289
|
node.func = instantiate_poly(node.func, full_ty, inst)
|
|
1280
1290
|
else:
|
|
1281
|
-
node = with_loc(node, TypeApply(
|
|
1291
|
+
node = with_loc(node, TypeApply(with_type(ty, node), inst))
|
|
1282
1292
|
return with_type(ty.instantiate(inst), node)
|
|
1283
1293
|
return with_type(ty, node)
|
|
1284
1294
|
|
|
@@ -1404,7 +1414,7 @@ def python_value_to_guppy_type(
|
|
|
1404
1414
|
]
|
|
1405
1415
|
if any(ty is None for ty in tys):
|
|
1406
1416
|
return None
|
|
1407
|
-
return TupleType(cast(list[Type], tys))
|
|
1417
|
+
return TupleType(cast("list[Type]", tys))
|
|
1408
1418
|
case list():
|
|
1409
1419
|
return _python_list_to_guppy_type(v, node, globals, type_hint)
|
|
1410
1420
|
case None:
|
|
@@ -141,7 +141,7 @@ def check_global_func_def(
|
|
|
141
141
|
check_invalid_under_dagger(func_def, ty.unitary_flags)
|
|
142
142
|
cfg = CFGBuilder().build(func_def.body, returns_none, globals, ty.unitary_flags)
|
|
143
143
|
inputs = [
|
|
144
|
-
Variable(cast(str, inp.name), inp.ty, loc, inp.flags, is_func_input=True)
|
|
144
|
+
Variable(cast("str", inp.name), inp.ty, loc, inp.flags, is_func_input=True)
|
|
145
145
|
for inp, loc in zip(ty.inputs, args, strict=True)
|
|
146
146
|
# Comptime inputs are turned into generic args, so are not included here
|
|
147
147
|
if InputFlags.Comptime not in inp.flags
|
|
@@ -199,7 +199,7 @@ def check_nested_func_def(
|
|
|
199
199
|
|
|
200
200
|
# Construct inputs for checking the body CFG
|
|
201
201
|
inputs = [v for v, _ in captured.values()] + [
|
|
202
|
-
Variable(cast(str, inp.name), inp.ty, arg, inp.flags, is_func_input=True)
|
|
202
|
+
Variable(cast("str", inp.name), inp.ty, arg, inp.flags, is_func_input=True)
|
|
203
203
|
for arg, inp in zip(func_def.args.args, func_ty.inputs, strict=True)
|
|
204
204
|
# Comptime inputs are turned into generic args, so are not included here
|
|
205
205
|
if InputFlags.Comptime not in inp.flags
|
|
@@ -214,6 +214,7 @@ def check_nested_func_def(
|
|
|
214
214
|
if not captured:
|
|
215
215
|
# If there are no captured vars, we treat the function like a global name
|
|
216
216
|
from guppylang.defs import GuppyDefinition
|
|
217
|
+
|
|
217
218
|
from guppylang_internals.definition.function import ParsedFunctionDef
|
|
218
219
|
|
|
219
220
|
func = ParsedFunctionDef(def_id, func_def.name, func_def, func_ty, None)
|
|
@@ -288,7 +289,7 @@ def check_signature(
|
|
|
288
289
|
# Figure out if this is a method
|
|
289
290
|
self_defn: TypeDef | None = None
|
|
290
291
|
if def_id is not None and def_id in DEF_STORE.impl_parents:
|
|
291
|
-
self_defn = cast(TypeDef, ENGINE.get_checked(DEF_STORE.impl_parents[def_id]))
|
|
292
|
+
self_defn = cast("TypeDef", ENGINE.get_checked(DEF_STORE.impl_parents[def_id]))
|
|
292
293
|
assert isinstance(self_defn, TypeDef)
|
|
293
294
|
|
|
294
295
|
inputs = []
|
|
@@ -478,7 +478,7 @@ def parse_unpack_pattern(lhs: ast.Tuple | ast.List) -> UnpackPattern:
|
|
|
478
478
|
# that there is at most one starred expression)
|
|
479
479
|
left = list(takewhile(lambda e: not isinstance(e, ast.Starred), lhs.elts))
|
|
480
480
|
starred = (
|
|
481
|
-
cast(ast.Starred, lhs.elts[len(left)]).value
|
|
481
|
+
cast("ast.Starred", lhs.elts[len(left)]).value
|
|
482
482
|
if len(left) < len(lhs.elts)
|
|
483
483
|
else None
|
|
484
484
|
)
|
|
@@ -111,7 +111,7 @@ def compile_bb(
|
|
|
111
111
|
pred_ty = builder.hugr.port_type(branch_port.out_port())
|
|
112
112
|
assert pred_ty == OpaqueBool
|
|
113
113
|
branch_port = dfg.builder.add_op(read_bool(), branch_port)
|
|
114
|
-
branch_port = cast(Wire, branch_port)
|
|
114
|
+
branch_port = cast("Wire", branch_port)
|
|
115
115
|
else:
|
|
116
116
|
# Even if we don't branch, we still have to add a `Sum(())` predicates
|
|
117
117
|
branch_port = dfg.builder.add_op(ops.Tag(0, ht.UnitSum(1)))
|
{guppylang_internals-0.27.0 → guppylang_internals-0.28.0}/src/guppylang_internals/compiler/core.py
RENAMED
|
@@ -31,12 +31,14 @@ from guppylang_internals.definition.common import (
|
|
|
31
31
|
CompilableDef,
|
|
32
32
|
CompiledDef,
|
|
33
33
|
DefId,
|
|
34
|
+
Definition,
|
|
34
35
|
MonomorphizableDef,
|
|
36
|
+
RawDef,
|
|
35
37
|
)
|
|
36
38
|
from guppylang_internals.definition.ty import TypeDef
|
|
37
39
|
from guppylang_internals.definition.value import CompiledCallableDef
|
|
38
40
|
from guppylang_internals.diagnostic import Error
|
|
39
|
-
from guppylang_internals.engine import ENGINE
|
|
41
|
+
from guppylang_internals.engine import DEF_STORE, ENGINE
|
|
40
42
|
from guppylang_internals.error import GuppyError, InternalGuppyError
|
|
41
43
|
from guppylang_internals.std._internal.compiler.tket_exts import GUPPY_EXTENSION
|
|
42
44
|
from guppylang_internals.tys.arg import ConstArg, TypeArg
|
|
@@ -199,7 +201,7 @@ class CompilerContext(ToHugrContext):
|
|
|
199
201
|
params, type_args, self
|
|
200
202
|
)
|
|
201
203
|
compile_outer = lambda: monomorphizable.monomorphize( # noqa: E731 (assign-lambda)
|
|
202
|
-
self.module, mono_args, self
|
|
204
|
+
self.module, mono_args, self, get_parent_type(monomorphizable)
|
|
203
205
|
)
|
|
204
206
|
case CompilableDef() as compilable:
|
|
205
207
|
compile_outer = lambda: compilable.compile_outer(self.module, self) # noqa: E731
|
|
@@ -227,7 +229,9 @@ class CompilerContext(ToHugrContext):
|
|
|
227
229
|
raise GuppyError(err)
|
|
228
230
|
# Thus, the partial monomorphization for the entry point is always empty
|
|
229
231
|
entry_mono_args = tuple(None for _ in params)
|
|
230
|
-
entry_compiled = defn.monomorphize(
|
|
232
|
+
entry_compiled = defn.monomorphize(
|
|
233
|
+
self.module, entry_mono_args, self, get_parent_type(defn)
|
|
234
|
+
)
|
|
231
235
|
case CompilableDef() as defn:
|
|
232
236
|
entry_compiled = defn.compile_outer(self.module, self)
|
|
233
237
|
case CompiledDef() as defn:
|
|
@@ -371,7 +375,7 @@ class DFContainer:
|
|
|
371
375
|
ctx: CompilerContext,
|
|
372
376
|
locals: CompiledLocals | None = None,
|
|
373
377
|
) -> None:
|
|
374
|
-
generic_builder = cast(DfBase[ops.DfParentOp], builder)
|
|
378
|
+
generic_builder = cast("DfBase[ops.DfParentOp]", builder)
|
|
375
379
|
if locals is None:
|
|
376
380
|
locals = {}
|
|
377
381
|
self.builder = generic_builder
|
|
@@ -467,6 +471,15 @@ def is_return_var(x: str) -> bool:
|
|
|
467
471
|
return x.startswith("%ret")
|
|
468
472
|
|
|
469
473
|
|
|
474
|
+
def get_parent_type(defn: Definition) -> "RawDef | None":
|
|
475
|
+
"""Returns the RawDef registered as the parent of `child` in the DEF_STORE,
|
|
476
|
+
or None if it has no parent."""
|
|
477
|
+
if parent_ty_id := DEF_STORE.impl_parents.get(defn.id):
|
|
478
|
+
return DEF_STORE.raw_defs[parent_ty_id]
|
|
479
|
+
else:
|
|
480
|
+
return None
|
|
481
|
+
|
|
482
|
+
|
|
470
483
|
def require_monomorphization(params: Sequence[Parameter]) -> set[Parameter]:
|
|
471
484
|
"""Returns the subset of type parameters that must be monomorphized before compiling
|
|
472
485
|
to Hugr.
|