guppylang-internals 0.21.0__py3-none-any.whl
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/__init__.py +3 -0
- guppylang_internals/ast_util.py +350 -0
- guppylang_internals/cfg/__init__.py +0 -0
- guppylang_internals/cfg/analysis.py +230 -0
- guppylang_internals/cfg/bb.py +221 -0
- guppylang_internals/cfg/builder.py +606 -0
- guppylang_internals/cfg/cfg.py +117 -0
- guppylang_internals/checker/__init__.py +0 -0
- guppylang_internals/checker/cfg_checker.py +388 -0
- guppylang_internals/checker/core.py +550 -0
- guppylang_internals/checker/errors/__init__.py +0 -0
- guppylang_internals/checker/errors/comptime_errors.py +106 -0
- guppylang_internals/checker/errors/generic.py +45 -0
- guppylang_internals/checker/errors/linearity.py +300 -0
- guppylang_internals/checker/errors/type_errors.py +344 -0
- guppylang_internals/checker/errors/wasm.py +34 -0
- guppylang_internals/checker/expr_checker.py +1413 -0
- guppylang_internals/checker/func_checker.py +269 -0
- guppylang_internals/checker/linearity_checker.py +821 -0
- guppylang_internals/checker/stmt_checker.py +447 -0
- guppylang_internals/compiler/__init__.py +0 -0
- guppylang_internals/compiler/cfg_compiler.py +233 -0
- guppylang_internals/compiler/core.py +613 -0
- guppylang_internals/compiler/expr_compiler.py +989 -0
- guppylang_internals/compiler/func_compiler.py +97 -0
- guppylang_internals/compiler/hugr_extension.py +224 -0
- guppylang_internals/compiler/qtm_platform_extension.py +0 -0
- guppylang_internals/compiler/stmt_compiler.py +212 -0
- guppylang_internals/decorator.py +246 -0
- guppylang_internals/definition/__init__.py +0 -0
- guppylang_internals/definition/common.py +214 -0
- guppylang_internals/definition/const.py +74 -0
- guppylang_internals/definition/custom.py +492 -0
- guppylang_internals/definition/declaration.py +171 -0
- guppylang_internals/definition/extern.py +89 -0
- guppylang_internals/definition/function.py +302 -0
- guppylang_internals/definition/overloaded.py +150 -0
- guppylang_internals/definition/parameter.py +82 -0
- guppylang_internals/definition/pytket_circuits.py +405 -0
- guppylang_internals/definition/struct.py +392 -0
- guppylang_internals/definition/traced.py +151 -0
- guppylang_internals/definition/ty.py +51 -0
- guppylang_internals/definition/value.py +115 -0
- guppylang_internals/definition/wasm.py +61 -0
- guppylang_internals/diagnostic.py +523 -0
- guppylang_internals/dummy_decorator.py +76 -0
- guppylang_internals/engine.py +295 -0
- guppylang_internals/error.py +107 -0
- guppylang_internals/experimental.py +92 -0
- guppylang_internals/ipython_inspect.py +28 -0
- guppylang_internals/nodes.py +427 -0
- guppylang_internals/py.typed +0 -0
- guppylang_internals/span.py +150 -0
- guppylang_internals/std/__init__.py +0 -0
- guppylang_internals/std/_internal/__init__.py +0 -0
- guppylang_internals/std/_internal/checker.py +573 -0
- guppylang_internals/std/_internal/compiler/__init__.py +0 -0
- guppylang_internals/std/_internal/compiler/arithmetic.py +136 -0
- guppylang_internals/std/_internal/compiler/array.py +569 -0
- guppylang_internals/std/_internal/compiler/either.py +131 -0
- guppylang_internals/std/_internal/compiler/frozenarray.py +68 -0
- guppylang_internals/std/_internal/compiler/futures.py +30 -0
- guppylang_internals/std/_internal/compiler/list.py +348 -0
- guppylang_internals/std/_internal/compiler/mem.py +13 -0
- guppylang_internals/std/_internal/compiler/option.py +78 -0
- guppylang_internals/std/_internal/compiler/prelude.py +271 -0
- guppylang_internals/std/_internal/compiler/qsystem.py +48 -0
- guppylang_internals/std/_internal/compiler/quantum.py +118 -0
- guppylang_internals/std/_internal/compiler/tket_bool.py +55 -0
- guppylang_internals/std/_internal/compiler/tket_exts.py +59 -0
- guppylang_internals/std/_internal/compiler/wasm.py +135 -0
- guppylang_internals/std/_internal/compiler.py +0 -0
- guppylang_internals/std/_internal/debug.py +95 -0
- guppylang_internals/std/_internal/util.py +271 -0
- guppylang_internals/tracing/__init__.py +0 -0
- guppylang_internals/tracing/builtins_mock.py +62 -0
- guppylang_internals/tracing/frozenlist.py +57 -0
- guppylang_internals/tracing/function.py +186 -0
- guppylang_internals/tracing/object.py +551 -0
- guppylang_internals/tracing/state.py +69 -0
- guppylang_internals/tracing/unpacking.py +194 -0
- guppylang_internals/tracing/util.py +86 -0
- guppylang_internals/tys/__init__.py +0 -0
- guppylang_internals/tys/arg.py +115 -0
- guppylang_internals/tys/builtin.py +382 -0
- guppylang_internals/tys/common.py +110 -0
- guppylang_internals/tys/const.py +114 -0
- guppylang_internals/tys/errors.py +178 -0
- guppylang_internals/tys/param.py +251 -0
- guppylang_internals/tys/parsing.py +425 -0
- guppylang_internals/tys/printing.py +174 -0
- guppylang_internals/tys/subst.py +112 -0
- guppylang_internals/tys/ty.py +876 -0
- guppylang_internals/tys/var.py +49 -0
- guppylang_internals-0.21.0.dist-info/METADATA +253 -0
- guppylang_internals-0.21.0.dist-info/RECORD +98 -0
- guppylang_internals-0.21.0.dist-info/WHEEL +4 -0
- guppylang_internals-0.21.0.dist-info/licenses/LICENCE +201 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
from collections.abc import Sequence
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from guppylang_internals.error import InternalGuppyError
|
|
6
|
+
from guppylang_internals.tys.arg import Argument, ConstArg, TypeArg
|
|
7
|
+
from guppylang_internals.tys.common import Transformer, Visitor
|
|
8
|
+
from guppylang_internals.tys.const import (
|
|
9
|
+
BoundConstVar,
|
|
10
|
+
Const,
|
|
11
|
+
ConstBase,
|
|
12
|
+
ExistentialConstVar,
|
|
13
|
+
)
|
|
14
|
+
from guppylang_internals.tys.ty import (
|
|
15
|
+
BoundTypeVar,
|
|
16
|
+
ExistentialTypeVar,
|
|
17
|
+
FunctionType,
|
|
18
|
+
Type,
|
|
19
|
+
TypeBase,
|
|
20
|
+
)
|
|
21
|
+
from guppylang_internals.tys.var import BoundVar, ExistentialVar
|
|
22
|
+
|
|
23
|
+
Subst = dict[ExistentialVar, Type | Const]
|
|
24
|
+
Inst = Sequence[Argument]
|
|
25
|
+
PartialInst = Sequence["Argument | None"]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Substituter(Transformer):
|
|
29
|
+
"""Type transformer that applies a substitution of existential variables."""
|
|
30
|
+
|
|
31
|
+
def __init__(self, subst: Subst) -> None:
|
|
32
|
+
self.subst = subst
|
|
33
|
+
|
|
34
|
+
@functools.singledispatchmethod
|
|
35
|
+
def transform(self, ty: Any) -> Any | None: # type: ignore[override]
|
|
36
|
+
return None
|
|
37
|
+
|
|
38
|
+
@transform.register
|
|
39
|
+
def _transform_ExistentialTypeVar(self, ty: ExistentialTypeVar) -> Type | None:
|
|
40
|
+
s = self.subst.get(ty, None)
|
|
41
|
+
assert not isinstance(s, ConstBase)
|
|
42
|
+
return s
|
|
43
|
+
|
|
44
|
+
@transform.register
|
|
45
|
+
def _transform_ExistentialConstVar(self, c: ExistentialConstVar) -> Const | None:
|
|
46
|
+
s = self.subst.get(c, None)
|
|
47
|
+
assert not isinstance(s, TypeBase)
|
|
48
|
+
return s
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class Instantiator(Transformer):
|
|
52
|
+
"""Type transformer that instantiates bound variables."""
|
|
53
|
+
|
|
54
|
+
def __init__(self, inst: Inst) -> None:
|
|
55
|
+
self.inst = inst
|
|
56
|
+
|
|
57
|
+
@functools.singledispatchmethod
|
|
58
|
+
def transform(self, ty: Any) -> Any | None: # type: ignore[override]
|
|
59
|
+
return None
|
|
60
|
+
|
|
61
|
+
@transform.register
|
|
62
|
+
def _transform_BoundTypeVar(self, ty: BoundTypeVar) -> Type | None:
|
|
63
|
+
# Instantiate if type for the index is available
|
|
64
|
+
if ty.idx < len(self.inst):
|
|
65
|
+
arg = self.inst[ty.idx]
|
|
66
|
+
assert isinstance(arg, TypeArg)
|
|
67
|
+
return arg.ty
|
|
68
|
+
|
|
69
|
+
# Otherwise, lower the de Bruijn index
|
|
70
|
+
return BoundTypeVar(
|
|
71
|
+
ty.display_name, ty.idx - len(self.inst), ty.copyable, ty.droppable
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
@transform.register
|
|
75
|
+
def _transform_BoundConstVar(self, c: BoundConstVar) -> Const | None:
|
|
76
|
+
# Instantiate if const value for the index is available
|
|
77
|
+
if c.idx < len(self.inst):
|
|
78
|
+
arg = self.inst[c.idx]
|
|
79
|
+
assert isinstance(arg, ConstArg)
|
|
80
|
+
return arg.const
|
|
81
|
+
|
|
82
|
+
# Otherwise, lower the de Bruijn index
|
|
83
|
+
return BoundConstVar(c.ty, c.display_name, c.idx - len(self.inst))
|
|
84
|
+
|
|
85
|
+
@transform.register
|
|
86
|
+
def _transform_FunctionType(self, ty: FunctionType) -> Type | None:
|
|
87
|
+
if ty.parametrized:
|
|
88
|
+
raise InternalGuppyError("Tried to instantiate under binder")
|
|
89
|
+
return None
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class BoundVarFinder(Visitor):
|
|
93
|
+
"""Type visitor that looks for occurrences of bound variables."""
|
|
94
|
+
|
|
95
|
+
bound_vars: set[BoundVar]
|
|
96
|
+
|
|
97
|
+
def __init__(self) -> None:
|
|
98
|
+
self.bound_vars = set()
|
|
99
|
+
|
|
100
|
+
@functools.singledispatchmethod
|
|
101
|
+
def visit(self, ty: Any) -> bool: # type: ignore[override]
|
|
102
|
+
return False
|
|
103
|
+
|
|
104
|
+
@visit.register
|
|
105
|
+
def _transform_BoundTypeVar(self, ty: BoundTypeVar) -> bool:
|
|
106
|
+
self.bound_vars.add(ty)
|
|
107
|
+
return False
|
|
108
|
+
|
|
109
|
+
@visit.register
|
|
110
|
+
def _transform_BoundConstVar(self, c: BoundConstVar) -> bool:
|
|
111
|
+
self.bound_vars.add(c)
|
|
112
|
+
return False
|