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,300 @@
|
|
|
1
|
+
"""Collection of error messages emitted during linearity checking."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import TYPE_CHECKING, ClassVar
|
|
7
|
+
|
|
8
|
+
from guppylang_internals.diagnostic import Error, Help, Note
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from guppylang_internals.checker.core import (
|
|
12
|
+
Place,
|
|
13
|
+
Variable,
|
|
14
|
+
)
|
|
15
|
+
from guppylang_internals.checker.linearity_checker import UseKind
|
|
16
|
+
from guppylang_internals.definition.struct import StructField
|
|
17
|
+
from guppylang_internals.tys.ty import (
|
|
18
|
+
StructType,
|
|
19
|
+
TupleType,
|
|
20
|
+
Type,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True)
|
|
25
|
+
class AlreadyUsedError(Error):
|
|
26
|
+
title: ClassVar[str] = "Copy violation"
|
|
27
|
+
span_label: ClassVar[str] = (
|
|
28
|
+
"{place.describe} with non-copyable type `{place.ty}` cannot be "
|
|
29
|
+
"{kind.subjunctive} ..."
|
|
30
|
+
)
|
|
31
|
+
place: Place
|
|
32
|
+
kind: UseKind
|
|
33
|
+
|
|
34
|
+
@dataclass(frozen=True)
|
|
35
|
+
class PrevUse(Note):
|
|
36
|
+
span_label: ClassVar[str] = "since it was already {prev_kind.subjunctive} here"
|
|
37
|
+
prev_kind: UseKind
|
|
38
|
+
|
|
39
|
+
@dataclass(frozen=True)
|
|
40
|
+
class MakeCopy(Help):
|
|
41
|
+
message: ClassVar[str] = (
|
|
42
|
+
"Consider copying `{place}` instead of moving it: `{place}.copy()`"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(frozen=True)
|
|
47
|
+
class ComprAlreadyUsedError(Error):
|
|
48
|
+
title: ClassVar[str] = "Copy violation"
|
|
49
|
+
span_label: ClassVar[str] = (
|
|
50
|
+
"{place.describe} with non-copyable type `{place.ty}` would be "
|
|
51
|
+
"{kind.subjunctive} multiple times when evaluating this comprehension"
|
|
52
|
+
)
|
|
53
|
+
place: Place
|
|
54
|
+
kind: UseKind
|
|
55
|
+
|
|
56
|
+
@dataclass(frozen=True)
|
|
57
|
+
class PrevUse(Note):
|
|
58
|
+
span_label: ClassVar[str] = "since it was already {prev_kind.subjunctive} here"
|
|
59
|
+
prev_kind: UseKind
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass(frozen=True)
|
|
63
|
+
class PlaceNotUsedError(Error):
|
|
64
|
+
title: ClassVar[str] = "Drop violation"
|
|
65
|
+
place: Place
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def rendered_span_label(self) -> str:
|
|
69
|
+
s = f"{self.place.describe} with non-droppable type `{self.place.ty}` "
|
|
70
|
+
match self.children:
|
|
71
|
+
case [PlaceNotUsedError.Branch(), *_]:
|
|
72
|
+
return s + "may be leaked ..."
|
|
73
|
+
case _:
|
|
74
|
+
return s + "is leaked"
|
|
75
|
+
|
|
76
|
+
@dataclass(frozen=True)
|
|
77
|
+
class Branch(Note):
|
|
78
|
+
span_label: ClassVar[str] = "if this expression is `{truth_value}`"
|
|
79
|
+
truth_value: bool
|
|
80
|
+
|
|
81
|
+
@dataclass(frozen=True)
|
|
82
|
+
class Fix(Help):
|
|
83
|
+
message: ClassVar[str] = (
|
|
84
|
+
"Make sure that `{place}` is consumed or returned to avoid the leak"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@dataclass(frozen=True)
|
|
89
|
+
class UnnamedExprNotUsedError(Error):
|
|
90
|
+
title: ClassVar[str] = "Drop violation"
|
|
91
|
+
span_label: ClassVar[str] = "Expression with non-droppable type `{ty}` is leaked"
|
|
92
|
+
ty: Type
|
|
93
|
+
|
|
94
|
+
@dataclass(frozen=True)
|
|
95
|
+
class Fix(Help):
|
|
96
|
+
message: ClassVar[str] = "Consider assigning this value to a local variable"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@dataclass(frozen=True)
|
|
100
|
+
class UnnamedFieldNotUsedError(Error):
|
|
101
|
+
title: ClassVar[str] = "Drop violation"
|
|
102
|
+
span_label: ClassVar[str] = (
|
|
103
|
+
"Non-droppable field `{field.name}` of expression with type `{struct_ty}` is "
|
|
104
|
+
"leaked"
|
|
105
|
+
)
|
|
106
|
+
field: StructField
|
|
107
|
+
struct_ty: StructType
|
|
108
|
+
|
|
109
|
+
@dataclass(frozen=True)
|
|
110
|
+
class Fix(Help):
|
|
111
|
+
message: ClassVar[str] = (
|
|
112
|
+
"Consider assigning this value to a local variable before accessing the "
|
|
113
|
+
"field `{used_field.name}`"
|
|
114
|
+
)
|
|
115
|
+
used_field: StructField
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@dataclass(frozen=True)
|
|
119
|
+
class UnnamedSubscriptNotUsedError(Error):
|
|
120
|
+
title: ClassVar[str] = "Drop violation"
|
|
121
|
+
span_label: ClassVar[str] = (
|
|
122
|
+
"Non-droppable items of expression with type `{container_ty}` are leaked ..."
|
|
123
|
+
)
|
|
124
|
+
container_ty: Type
|
|
125
|
+
|
|
126
|
+
@dataclass(frozen=True)
|
|
127
|
+
class SubscriptHint(Note):
|
|
128
|
+
span_label: ClassVar[str] = "since only this subscript is used"
|
|
129
|
+
|
|
130
|
+
@dataclass(frozen=True)
|
|
131
|
+
class Fix(Help):
|
|
132
|
+
message: ClassVar[str] = (
|
|
133
|
+
"Consider assigning this value to a local variable before subscripting it"
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@dataclass(frozen=True)
|
|
138
|
+
class UnnamedTupleNotUsedError(Error):
|
|
139
|
+
title: ClassVar[str] = "Drop violation"
|
|
140
|
+
span_label: ClassVar[str] = (
|
|
141
|
+
"Non-droppable items inside expression of type `{tuple_ty}` are leaked"
|
|
142
|
+
)
|
|
143
|
+
tuple_ty: TupleType
|
|
144
|
+
|
|
145
|
+
@dataclass(frozen=True)
|
|
146
|
+
class Fix(Help):
|
|
147
|
+
message: ClassVar[str] = (
|
|
148
|
+
"Consider assigning this value to a local variable before subscripting it"
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@dataclass(frozen=True)
|
|
153
|
+
class NotOwnedError(Error):
|
|
154
|
+
title: ClassVar[str] = "Not owned"
|
|
155
|
+
place: Place
|
|
156
|
+
kind: UseKind
|
|
157
|
+
is_call_arg: bool
|
|
158
|
+
func_name: str | None
|
|
159
|
+
calling_func_name: str
|
|
160
|
+
|
|
161
|
+
@property
|
|
162
|
+
def rendered_span_label(self) -> str:
|
|
163
|
+
if self.is_call_arg:
|
|
164
|
+
f = f"Function `{self.func_name}`" if self.func_name else "Function"
|
|
165
|
+
return (
|
|
166
|
+
f"{f} wants to take ownership of this argument, but "
|
|
167
|
+
f"`{self.calling_func_name}` doesn't own `{self.place}`"
|
|
168
|
+
)
|
|
169
|
+
return (
|
|
170
|
+
f"Cannot {self.kind.indicative} `{self.place}` since "
|
|
171
|
+
f"`{self.calling_func_name}` doesn't own it"
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
@dataclass(frozen=True)
|
|
175
|
+
class MakeOwned(Help):
|
|
176
|
+
span_label: ClassVar[str] = (
|
|
177
|
+
"Argument `{place.root.name}` is only borrowed. Consider taking ownership: "
|
|
178
|
+
"`{place.root.name}: {place.root.ty} @owned`"
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
@dataclass(frozen=True)
|
|
182
|
+
class MakeCopy(Help):
|
|
183
|
+
span_label: ClassVar[str] = (
|
|
184
|
+
"Or consider copying this argument: `{place}.copy()`"
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
@dataclass(frozen=True)
|
|
189
|
+
class MoveOutOfSubscriptError(Error):
|
|
190
|
+
title: ClassVar[str] = "Subscript {kind.subjunctive}"
|
|
191
|
+
span_label: ClassVar[str] = (
|
|
192
|
+
"Cannot {kind.indicative} a subscript of `{parent}` with non-copyable type "
|
|
193
|
+
"`{parent.ty}`"
|
|
194
|
+
)
|
|
195
|
+
kind: UseKind
|
|
196
|
+
parent: Place
|
|
197
|
+
|
|
198
|
+
@dataclass(frozen=True)
|
|
199
|
+
class Explanation(Note):
|
|
200
|
+
message: ClassVar[str] = (
|
|
201
|
+
"Subscripts on non-copyable types are only allowed to be borrowed, not "
|
|
202
|
+
"{kind.subjunctive}"
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
@dataclass(frozen=True)
|
|
207
|
+
class BorrowShadowedError(Error):
|
|
208
|
+
title: ClassVar[str] = "Borrow shadowed"
|
|
209
|
+
span_label: ClassVar[str] = "Assignment shadows borrowed argument `{place}`"
|
|
210
|
+
place: Place
|
|
211
|
+
|
|
212
|
+
@dataclass(frozen=True)
|
|
213
|
+
class Rename(Help):
|
|
214
|
+
message: ClassVar[str] = "Consider assigning to a different name"
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
@dataclass(frozen=True)
|
|
218
|
+
class BorrowSubPlaceUsedError(Error):
|
|
219
|
+
title: ClassVar[str] = "Copy violation"
|
|
220
|
+
span_label: ClassVar[str] = (
|
|
221
|
+
"Borrowed argument {borrowed_var} cannot be returned to the caller ..."
|
|
222
|
+
)
|
|
223
|
+
borrowed_var: Variable
|
|
224
|
+
sub_place: Place
|
|
225
|
+
|
|
226
|
+
@dataclass(frozen=True)
|
|
227
|
+
class PrevUse(Note):
|
|
228
|
+
span_label: ClassVar[str] = (
|
|
229
|
+
"since `{sub_place}` with non-copyable type `{sub_place.ty}` was already "
|
|
230
|
+
"{kind.subjunctive} here"
|
|
231
|
+
)
|
|
232
|
+
kind: UseKind
|
|
233
|
+
|
|
234
|
+
@dataclass(frozen=True)
|
|
235
|
+
class Fix(Help):
|
|
236
|
+
message: ClassVar[str] = (
|
|
237
|
+
"Consider writing a value back into `{sub_place}` before returning"
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
@dataclass(frozen=True)
|
|
242
|
+
class DropAfterCallError(Error):
|
|
243
|
+
title: ClassVar[str] = "Drop violation"
|
|
244
|
+
span_label: ClassVar[str] = (
|
|
245
|
+
"Value with non-droppable type `{ty}` would be leaked after {func} returns"
|
|
246
|
+
)
|
|
247
|
+
ty: Type
|
|
248
|
+
func_name: str | None
|
|
249
|
+
|
|
250
|
+
@property
|
|
251
|
+
def func(self) -> str:
|
|
252
|
+
return f"`{self.func_name}`" if self.func_name else "the function"
|
|
253
|
+
|
|
254
|
+
@dataclass(frozen=True)
|
|
255
|
+
class Assign(Help):
|
|
256
|
+
message: ClassVar[str] = (
|
|
257
|
+
"Consider assigning the value to a local variable before passing it to "
|
|
258
|
+
"{func}"
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
@dataclass(frozen=True)
|
|
263
|
+
class NonCopyableCaptureError(Error):
|
|
264
|
+
title: ClassVar[str] = "Copy violation"
|
|
265
|
+
span_label: ClassVar[str] = (
|
|
266
|
+
"{var.describe} with non-copyable type {var.ty} cannot be used here since "
|
|
267
|
+
"`{var}` is captured from an outer scope"
|
|
268
|
+
)
|
|
269
|
+
var: Variable
|
|
270
|
+
|
|
271
|
+
@dataclass(frozen=True)
|
|
272
|
+
class DefinedHere(Note):
|
|
273
|
+
span_label: ClassVar[str] = "`{var}` defined here"
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
@dataclass(frozen=True)
|
|
277
|
+
class NonCopyablePartialApplyError(Error):
|
|
278
|
+
title: ClassVar[str] = "Copy violation"
|
|
279
|
+
span_label: ClassVar[str] = (
|
|
280
|
+
"This expression implicitly constructs a closure that captures a non-copyable "
|
|
281
|
+
"value"
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
@dataclass(frozen=True)
|
|
285
|
+
class Captured(Note):
|
|
286
|
+
span_label: ClassVar[str] = (
|
|
287
|
+
"This expression with non-copyable type `{ty}` is implicitly captured"
|
|
288
|
+
)
|
|
289
|
+
ty: Type
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
@dataclass(frozen=True)
|
|
293
|
+
class NonDroppableForBreakError(Error):
|
|
294
|
+
title: ClassVar[str] = "Break in non-droppable loop"
|
|
295
|
+
span_label: ClassVar[str] = "Early exit in non-droppable loops is not allowed"
|
|
296
|
+
|
|
297
|
+
@dataclass(frozen=True)
|
|
298
|
+
class NonDroppableIteratorType(Note):
|
|
299
|
+
span_label: ClassVar[str] = "Iterator has non-droppable type `{ty}`"
|
|
300
|
+
ty: Type
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import TYPE_CHECKING, ClassVar
|
|
5
|
+
|
|
6
|
+
from guppylang_internals.diagnostic import Error, Help, Note
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from guppylang_internals.definition.struct import StructField
|
|
10
|
+
from guppylang_internals.tys.const import Const
|
|
11
|
+
from guppylang_internals.tys.param import TypeParam
|
|
12
|
+
from guppylang_internals.tys.ty import FunctionType, Type
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(frozen=True)
|
|
16
|
+
class TypeMismatchError(Error):
|
|
17
|
+
title: ClassVar[str] = "Type mismatch"
|
|
18
|
+
span_label: ClassVar[str] = "Expected {kind} of type `{expected}`, got `{actual}`"
|
|
19
|
+
|
|
20
|
+
expected: Type
|
|
21
|
+
actual: Type
|
|
22
|
+
kind: str = "expression"
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True)
|
|
25
|
+
class CantInferParam(Note):
|
|
26
|
+
message: ClassVar[str] = (
|
|
27
|
+
"Couldn't infer an instantiation for type variable `?{type_var}` "
|
|
28
|
+
"(higher-rank polymorphic types are not supported)"
|
|
29
|
+
)
|
|
30
|
+
type_var: str
|
|
31
|
+
|
|
32
|
+
@dataclass(frozen=True)
|
|
33
|
+
class CantInstantiateFreeVars(Note):
|
|
34
|
+
message: ClassVar[str] = (
|
|
35
|
+
"Can't instantiate parameter `{param}` with type `{illegal_inst}` "
|
|
36
|
+
"containing free variables"
|
|
37
|
+
)
|
|
38
|
+
param: str
|
|
39
|
+
illegal_inst: Type | Const
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass(frozen=True)
|
|
43
|
+
class ConstMismatchError(Error):
|
|
44
|
+
title: ClassVar[str] = "Value mismatch"
|
|
45
|
+
span_label: ClassVar[str] = "Expected constant `{expected}`, got `{actual}`"
|
|
46
|
+
|
|
47
|
+
expected: Const
|
|
48
|
+
actual: Const
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass(frozen=True)
|
|
52
|
+
class AssignFieldTypeMismatchError(Error):
|
|
53
|
+
title: ClassVar[str] = "Type mismatch"
|
|
54
|
+
span_label: ClassVar[str] = (
|
|
55
|
+
"Cannot assign expression of type `{actual}` to field `{field.name}` of type "
|
|
56
|
+
"`{field.ty}`"
|
|
57
|
+
)
|
|
58
|
+
actual: Type
|
|
59
|
+
field: StructField
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass(frozen=True)
|
|
63
|
+
class AssignSubscriptTypeMismatchError(Error):
|
|
64
|
+
title: ClassVar[str] = "Type mismatch"
|
|
65
|
+
span_label: ClassVar[str] = (
|
|
66
|
+
"Cannot assign expression of type `{actual}` to array element of type "
|
|
67
|
+
"`{expected}`"
|
|
68
|
+
)
|
|
69
|
+
actual: Type
|
|
70
|
+
expected: Type
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@dataclass(frozen=True)
|
|
74
|
+
class NonLinearInstantiateError(Error):
|
|
75
|
+
title: ClassVar[str] = "Not defined for linear argument"
|
|
76
|
+
span_label: ClassVar[str] = (
|
|
77
|
+
"Cannot instantiate {expected} type parameter `{param.name}` in type "
|
|
78
|
+
"`{func_ty}` with non-{expected} type `{ty}`"
|
|
79
|
+
)
|
|
80
|
+
param: TypeParam
|
|
81
|
+
func_ty: FunctionType
|
|
82
|
+
ty: Type
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def expected(self) -> str:
|
|
86
|
+
return "copyable" if self.param.must_be_copyable else "droppable"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@dataclass(frozen=True)
|
|
90
|
+
class TypeInferenceError(Error):
|
|
91
|
+
title: ClassVar[str] = "Cannot infer type"
|
|
92
|
+
span_label: ClassVar[str] = (
|
|
93
|
+
"Cannot infer type variables in expression of type `{unsolved_ty}`"
|
|
94
|
+
)
|
|
95
|
+
unsolved_ty: Type
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@dataclass(frozen=True)
|
|
99
|
+
class IllegalConstant(Error):
|
|
100
|
+
title: ClassVar[str] = "Unsupported constant"
|
|
101
|
+
span_label: ClassVar[str] = "Type `{python_ty.__name__}` is not supported"
|
|
102
|
+
python_ty: type
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@dataclass(frozen=True)
|
|
106
|
+
class ModuleMemberNotFoundError(Error):
|
|
107
|
+
title: ClassVar[str] = "Not found in module"
|
|
108
|
+
span_label: ClassVar[str] = "Module `{module_name}` has no member `{member}`"
|
|
109
|
+
module_name: str
|
|
110
|
+
member: str
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@dataclass(frozen=True)
|
|
114
|
+
class AttributeNotFoundError(Error):
|
|
115
|
+
title: ClassVar[str] = "Attribute not found"
|
|
116
|
+
span_label: ClassVar[str] = "`{ty}` has no attribute `{attribute}`"
|
|
117
|
+
ty: Type
|
|
118
|
+
attribute: str
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@dataclass(frozen=True)
|
|
122
|
+
class UnaryOperatorNotDefinedError(Error):
|
|
123
|
+
title: ClassVar[str] = "Operator not defined"
|
|
124
|
+
span_label: ClassVar[str] = "Unary operator `{op}` not defined for `{ty}`"
|
|
125
|
+
ty: Type
|
|
126
|
+
op: str
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@dataclass(frozen=True)
|
|
130
|
+
class BinaryOperatorNotDefinedError(Error):
|
|
131
|
+
title: ClassVar[str] = "Operator not defined"
|
|
132
|
+
span_label: ClassVar[str] = (
|
|
133
|
+
"Binary operator `{op}` not defined for `{left_ty}` and `{right_ty}`"
|
|
134
|
+
)
|
|
135
|
+
left_ty: Type
|
|
136
|
+
right_ty: Type
|
|
137
|
+
op: str
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
@dataclass(frozen=True)
|
|
141
|
+
class BadProtocolError(Error):
|
|
142
|
+
title: ClassVar[str] = "Not {is_not}"
|
|
143
|
+
span_label: ClassVar[str] = "Expression of type `{ty}` is not {is_not}"
|
|
144
|
+
ty: Type
|
|
145
|
+
is_not: str
|
|
146
|
+
|
|
147
|
+
@dataclass(frozen=True)
|
|
148
|
+
class MethodMissing(Help):
|
|
149
|
+
message: ClassVar[str] = "Implement missing method: `{method}: {signature}`"
|
|
150
|
+
method: str
|
|
151
|
+
signature: FunctionType
|
|
152
|
+
|
|
153
|
+
@dataclass(frozen=True)
|
|
154
|
+
class BadSignature(Help):
|
|
155
|
+
message: ClassVar[str] = (
|
|
156
|
+
"Fix signature of method `{ty}.{method}`: Expected `{exp_signature}`, got "
|
|
157
|
+
"`{act_signature}`"
|
|
158
|
+
)
|
|
159
|
+
ty: Type
|
|
160
|
+
method: str
|
|
161
|
+
exp_signature: FunctionType
|
|
162
|
+
act_signature: FunctionType
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
@dataclass(frozen=True)
|
|
166
|
+
class MissingReturnValueError(Error):
|
|
167
|
+
title: ClassVar[str] = "Missing return value"
|
|
168
|
+
span_label: ClassVar[str] = "Expected return value of type `{ty}`"
|
|
169
|
+
ty: Type
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
@dataclass(frozen=True)
|
|
173
|
+
class TypeApplyNotGenericError(Error):
|
|
174
|
+
title: ClassVar[str] = "Not generic"
|
|
175
|
+
span_label: ClassVar[str] = (
|
|
176
|
+
"{thing} is not generic, so no type parameters can be provided"
|
|
177
|
+
)
|
|
178
|
+
func_name: str | None
|
|
179
|
+
|
|
180
|
+
@property
|
|
181
|
+
def thing(self) -> str:
|
|
182
|
+
return f"`{self.func_name}`" if self.func_name else "This function"
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@dataclass(frozen=True)
|
|
186
|
+
class NotCallableError(Error):
|
|
187
|
+
title: ClassVar[str] = "Not callable"
|
|
188
|
+
span_label: ClassVar[str] = "Expected a function, got expression of type `{actual}`"
|
|
189
|
+
actual: Type
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
@dataclass(frozen=True)
|
|
193
|
+
class WrongNumberOfArgsError(Error):
|
|
194
|
+
title: ClassVar[str] = "" # Custom implementation in `rendered_title`
|
|
195
|
+
expected: int
|
|
196
|
+
actual: int
|
|
197
|
+
detailed: bool = True
|
|
198
|
+
is_type_apply: bool = False
|
|
199
|
+
|
|
200
|
+
@property
|
|
201
|
+
def rendered_title(self) -> str:
|
|
202
|
+
return (
|
|
203
|
+
f"Not enough {self.argument_kind}s"
|
|
204
|
+
if self.expected > self.actual
|
|
205
|
+
else f"Too many {self.argument_kind}s"
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
@property
|
|
209
|
+
def argument_kind(self) -> str:
|
|
210
|
+
return "type argument" if self.is_type_apply else "argument"
|
|
211
|
+
|
|
212
|
+
@property
|
|
213
|
+
def rendered_span_label(self) -> str:
|
|
214
|
+
if not self.detailed:
|
|
215
|
+
return f"Expected {self.expected}, got {self.actual}"
|
|
216
|
+
diff = self.expected - self.actual
|
|
217
|
+
if diff < 0:
|
|
218
|
+
msg = f"Unexpected {self.argument_kind}"
|
|
219
|
+
if diff < -1:
|
|
220
|
+
msg += "s"
|
|
221
|
+
else:
|
|
222
|
+
msg = f"Missing {self.argument_kind}"
|
|
223
|
+
if diff > 1:
|
|
224
|
+
msg += "s"
|
|
225
|
+
return f"{msg} (expected {self.expected}, got {self.actual})"
|
|
226
|
+
|
|
227
|
+
@dataclass(frozen=True)
|
|
228
|
+
class SignatureHint(Note):
|
|
229
|
+
message: ClassVar[str] = "Function signature is `{sig}`"
|
|
230
|
+
sig: FunctionType
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
@dataclass(frozen=True)
|
|
234
|
+
class WrongNumberOfUnpacksError(Error):
|
|
235
|
+
title: ClassVar[str] = "{prefix} values to unpack"
|
|
236
|
+
expected: int
|
|
237
|
+
actual: int
|
|
238
|
+
at_least: bool
|
|
239
|
+
|
|
240
|
+
@property
|
|
241
|
+
def prefix(self) -> str:
|
|
242
|
+
return "Not enough" if self.expected > self.actual else "Too many"
|
|
243
|
+
|
|
244
|
+
@property
|
|
245
|
+
def rendered_span_label(self) -> str:
|
|
246
|
+
diff = self.expected - self.actual
|
|
247
|
+
if diff < 0:
|
|
248
|
+
msg = "Unexpected assignment " + ("targets" if diff < -1 else "target")
|
|
249
|
+
at_least = "at least " if self.at_least else ""
|
|
250
|
+
else:
|
|
251
|
+
msg = "Not enough assignment targets"
|
|
252
|
+
assert not self.at_least
|
|
253
|
+
at_least = ""
|
|
254
|
+
return f"{msg} (expected {self.expected}, got {at_least}{self.actual})"
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
@dataclass(frozen=True)
|
|
258
|
+
class UnpackableError(Error):
|
|
259
|
+
title: ClassVar[str] = "Unpackable"
|
|
260
|
+
span_label: ClassVar[str] = "Expression of type `{ty}` cannot be unpacked"
|
|
261
|
+
ty: Type
|
|
262
|
+
|
|
263
|
+
@dataclass(frozen=True)
|
|
264
|
+
class NonStaticIter(Note):
|
|
265
|
+
message: ClassVar[str] = (
|
|
266
|
+
"Unpacking of iterable types like `{ty}` is only allowed if the number of "
|
|
267
|
+
"items yielded by the iterator is statically known. This is not the case "
|
|
268
|
+
"for `{ty}`."
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
@dataclass(frozen=True)
|
|
272
|
+
class GenericSize(Note):
|
|
273
|
+
message: ClassVar[str] = (
|
|
274
|
+
"Unpacking of iterable types like `{ty}` is only allowed if the number of "
|
|
275
|
+
"items yielded by the iterator is statically known. Here, the number of "
|
|
276
|
+
"items `{num}` is generic and can change between different function "
|
|
277
|
+
"invocations."
|
|
278
|
+
)
|
|
279
|
+
num: Const
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
@dataclass(frozen=True)
|
|
283
|
+
class StarredTupleUnpackError(Error):
|
|
284
|
+
title: ClassVar[str] = "Invalid starred unpacking"
|
|
285
|
+
span_label: ClassVar[str] = (
|
|
286
|
+
"Expression of type `{ty}` cannot be collected into a starred assignment since "
|
|
287
|
+
"the yielded items have different types"
|
|
288
|
+
)
|
|
289
|
+
ty: Type
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
@dataclass(frozen=True)
|
|
293
|
+
class AssignNonPlaceHelp(Help):
|
|
294
|
+
message: ClassVar[str] = (
|
|
295
|
+
"Consider assigning this value to a local variable first before assigning the "
|
|
296
|
+
"field `{field.name}`"
|
|
297
|
+
)
|
|
298
|
+
field: StructField
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
@dataclass(frozen=True)
|
|
302
|
+
class ArrayComprUnknownSizeError(Error):
|
|
303
|
+
title: ClassVar[str] = "Array comprehension with nonstatic size"
|
|
304
|
+
span_label: ClassVar[str] = "Cannot infer the size of this array comprehension ..."
|
|
305
|
+
|
|
306
|
+
@dataclass(frozen=True)
|
|
307
|
+
class IfGuard(Note):
|
|
308
|
+
span_label: ClassVar[str] = "since it depends on this condition"
|
|
309
|
+
|
|
310
|
+
@dataclass(frozen=True)
|
|
311
|
+
class DynamicIterator(Note):
|
|
312
|
+
span_label: ClassVar[str] = (
|
|
313
|
+
"since the number of elements yielded by this iterator is not statically "
|
|
314
|
+
"known"
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
@dataclass(frozen=True)
|
|
319
|
+
class TupleIndexOutOfBoundsError(Error):
|
|
320
|
+
title: ClassVar[str] = "Tuple index out of bounds"
|
|
321
|
+
span_label: ClassVar[str] = (
|
|
322
|
+
"Tuple index `{index}` is out of bounds for tuple of size `{size}`"
|
|
323
|
+
)
|
|
324
|
+
index: int
|
|
325
|
+
size: int
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
@dataclass(frozen=True)
|
|
329
|
+
class IntOverflowError(Error):
|
|
330
|
+
title: ClassVar[str] = "Integer {over_under}flow"
|
|
331
|
+
span_label: ClassVar[str] = (
|
|
332
|
+
"Value does not fit into a {bits}-bit {signed_unsigned} integer"
|
|
333
|
+
)
|
|
334
|
+
signed: bool
|
|
335
|
+
bits: int
|
|
336
|
+
is_underflow: bool
|
|
337
|
+
|
|
338
|
+
@property
|
|
339
|
+
def over_under(self) -> str:
|
|
340
|
+
return "under" if self.is_underflow else "over"
|
|
341
|
+
|
|
342
|
+
@property
|
|
343
|
+
def signed_unsigned(self) -> str:
|
|
344
|
+
return "signed" if self.signed else "unsigned"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import ClassVar
|
|
3
|
+
|
|
4
|
+
from guppylang_internals.diagnostic import Error
|
|
5
|
+
from guppylang_internals.tys.ty import Type
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass(frozen=True)
|
|
9
|
+
class WasmError(Error):
|
|
10
|
+
title: ClassVar[str] = "WASM signature error"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True)
|
|
14
|
+
class FirstArgNotModule(WasmError):
|
|
15
|
+
span_label: ClassVar[str] = (
|
|
16
|
+
"First argument to WASM function should be a reference to a WASM module."
|
|
17
|
+
" Found `{ty}` instead"
|
|
18
|
+
)
|
|
19
|
+
ty: Type
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True)
|
|
23
|
+
class UnWasmableType(WasmError):
|
|
24
|
+
span_label: ClassVar[str] = (
|
|
25
|
+
"WASM function signature contained an unsupported type: `{ty}`"
|
|
26
|
+
)
|
|
27
|
+
ty: Type
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass(frozen=True)
|
|
31
|
+
class WasmTypeConversionError(Error):
|
|
32
|
+
title: ClassVar[str] = "Can't convert type to WASM"
|
|
33
|
+
span_label: ClassVar[str] = "`{thing}` cannot be converted to WASM"
|
|
34
|
+
ty: Type
|