tla-ts 0.0.2 → 0.0.3-dev.14337b3
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.
- package/README.md +78 -12
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +85 -15
- package/dist/index.d.ts +85 -15
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +2 -2
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +22 -2
- package/dist/run-cli.js +22 -2
- package/dist/transfer.cjs +37 -16
- package/dist/transfer.js +37 -16
- package/package.json +3 -1
- package/src/ast.ts +137 -4
- package/src/check.ts +378 -100
- package/src/cli-options.ts +64 -0
- package/src/codegen.ts +15 -22
- package/src/config.ts +224 -170
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +116 -28
- package/src/errors.ts +101 -3
- package/src/evaluate.ts +129 -153
- package/src/exit-codes.ts +39 -42
- package/src/fingerprints.ts +46 -11
- package/src/instances.ts +16 -15
- package/src/levels.ts +62 -34
- package/src/lexer.ts +11 -2
- package/src/live-check.ts +772 -0
- package/src/liveness.ts +116 -543
- package/src/obligation-action.ts +384 -0
- package/src/obligation-anon.ts +575 -0
- package/src/obligation-deref.ts +637 -0
- package/src/obligation-expression.ts +1060 -0
- package/src/obligation-format.ts +406 -0
- package/src/obligation-generate.ts +1074 -0
- package/src/obligation-levels.ts +329 -0
- package/src/obligation-module.ts +1042 -0
- package/src/obligation-printer.ts +889 -0
- package/src/obligation-proof.ts +76 -0
- package/src/obligation-source.ts +1084 -0
- package/src/obligation-tuples.ts +184 -0
- package/src/obligations.ts +316 -0
- package/src/parallel-worker.ts +168 -212
- package/src/parallel.ts +78 -37
- package/src/parser.ts +315 -60
- package/src/resolve.ts +122 -44
- package/src/run-cli.ts +376 -44
- package/src/runtime.ts +3 -1
- package/src/spec-description.ts +19 -8
- package/src/standard-levels.ts +3 -3
- package/src/standard-modules.ts +2 -7
- package/src/state-graph.ts +157 -0
- package/src/subexpressions.ts +10 -10
- package/src/successors.ts +99 -25
- package/src/symmetry.ts +30 -8
- package/src/tableau.ts +51 -24
- package/src/tlc-ext.ts +29 -12
- package/src/tlc-module.ts +14 -33
- package/src/tlc-modules.ts +4 -0
- package/src/tlc-order.ts +25 -7
- package/src/tlc-random.ts +9 -6
- package/src/tlc-summary.ts +20 -5
- package/src/transfer.ts +22 -1
- package/src/values.ts +179 -42
package/src/resolve.ts
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import {
|
|
2
|
+
getChildren,
|
|
3
|
+
isLocallyResolved,
|
|
4
|
+
type AssumeProve,
|
|
5
|
+
type Bound,
|
|
6
|
+
type BoundPattern,
|
|
7
|
+
type Definition,
|
|
8
|
+
type Expression,
|
|
9
|
+
type Instance,
|
|
10
|
+
type Module,
|
|
11
|
+
type NewSymbol,
|
|
12
|
+
type OperatorParam,
|
|
13
|
+
type Proof,
|
|
14
|
+
type ProofStep,
|
|
15
|
+
type SourceLocation,
|
|
16
|
+
type SourceRange,
|
|
17
|
+
type Theorem,
|
|
15
18
|
} from "./ast";
|
|
16
|
-
import {
|
|
17
|
-
|
|
19
|
+
import {
|
|
20
|
+
createSanyError,
|
|
21
|
+
createSemanticError,
|
|
22
|
+
formatRange,
|
|
23
|
+
TlaSyntaxError,
|
|
24
|
+
type SanyError,
|
|
25
|
+
} from "./errors";
|
|
18
26
|
|
|
19
27
|
export interface ModuleSymbol {
|
|
20
28
|
key: string;
|
|
@@ -102,6 +110,21 @@ const findSymbol = (name: string, unit: Unit): ModuleSymbol | undefined => {
|
|
|
102
110
|
: unit.imported.get(name);
|
|
103
111
|
};
|
|
104
112
|
|
|
113
|
+
// SANY reports a name at the range of its text.
|
|
114
|
+
const getNameRange = (location: SourceLocation, name: string): SourceRange => ({
|
|
115
|
+
module: location.range?.module ?? "",
|
|
116
|
+
start: location,
|
|
117
|
+
end: { line: location.line, column: location.column + name.length - 1 },
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// SANY reports an operator symbol applied to operands as one it cannot resolve.
|
|
121
|
+
const getFixity = (expression: Expression) => {
|
|
122
|
+
if (expression.kind !== "Apply") return undefined;
|
|
123
|
+
if (expression.args.length === 2) return "infix";
|
|
124
|
+
if (expression.args.length !== 1) return undefined;
|
|
125
|
+
return isBefore(expression.location, expression.args[0].location) ? "prefix" : "postfix";
|
|
126
|
+
};
|
|
127
|
+
|
|
105
128
|
// SANY names an undefined operator symbol such as + differently from an undefined identifier.
|
|
106
129
|
const isOperatorSymbol = (name: string) =>
|
|
107
130
|
name[0].toLowerCase() === name[0].toUpperCase() &&
|
|
@@ -134,7 +157,7 @@ const getSymbolArity = (
|
|
|
134
157
|
}
|
|
135
158
|
// A name such as Inv!P1 selects the label P1 of a definition or theorem, which takes its own
|
|
136
159
|
// arguments.
|
|
137
|
-
const prefix = name.slice(0, name.indexOf("!"));
|
|
160
|
+
const prefix = name.includes("!") ? name.slice(0, name.indexOf("!")) : "";
|
|
138
161
|
const isSelected =
|
|
139
162
|
prefix !== "" &&
|
|
140
163
|
(lookupLocal(scope, prefix) !== undefined ||
|
|
@@ -143,11 +166,23 @@ const getSymbolArity = (
|
|
|
143
166
|
if (isSelected) {
|
|
144
167
|
return expression.kind === "Apply" ? expression.args.length : 0;
|
|
145
168
|
}
|
|
146
|
-
const
|
|
147
|
-
throw
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
169
|
+
const range = getNameRange(location, name === "-." ? "-" : name);
|
|
170
|
+
if (!isOperatorSymbol(name)) throw createSemanticError(`Unknown operator: \`${name}'.`, range);
|
|
171
|
+
const missing = {
|
|
172
|
+
location: formatRange(range),
|
|
173
|
+
message: `Could not find declaration or definition of symbol '${name}'.`,
|
|
174
|
+
};
|
|
175
|
+
const fixity = getFixity(expression);
|
|
176
|
+
throw createSanyError(
|
|
177
|
+
fixity && location.range
|
|
178
|
+
? [
|
|
179
|
+
missing,
|
|
180
|
+
{
|
|
181
|
+
location: formatRange(location.range),
|
|
182
|
+
message: `Couldn't resolve ${fixity} operator symbol \`${name}'.`,
|
|
183
|
+
},
|
|
184
|
+
]
|
|
185
|
+
: [missing],
|
|
151
186
|
);
|
|
152
187
|
};
|
|
153
188
|
|
|
@@ -234,13 +269,13 @@ const resolveApply = (
|
|
|
234
269
|
scope: LocalName | undefined,
|
|
235
270
|
unit: Unit,
|
|
236
271
|
) => {
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const arity = getSymbolArity(expression, expression.operator, scope, unit);
|
|
272
|
+
const operator = expression.operator;
|
|
273
|
+
const callee = lookupLocal(scope, operator) ? undefined : getVisibleDefinition(operator, unit);
|
|
274
|
+
const arity = getSymbolArity(expression, operator, scope, unit);
|
|
241
275
|
if (arity !== expression.args.length) {
|
|
242
|
-
throw
|
|
243
|
-
`The operator ${
|
|
276
|
+
throw createSemanticError(
|
|
277
|
+
`The operator ${operator} requires ${arity} arguments.`,
|
|
278
|
+
expression.argumentsRange ?? getNameRange(expression.location, operator),
|
|
244
279
|
);
|
|
245
280
|
}
|
|
246
281
|
expression.args.forEach((arg, index) => {
|
|
@@ -274,10 +309,12 @@ const resolveExpression = (
|
|
|
274
309
|
case "ExceptAt":
|
|
275
310
|
return;
|
|
276
311
|
case "Identifier": {
|
|
277
|
-
const
|
|
312
|
+
const name = expression.name;
|
|
313
|
+
const arity = getSymbolArity(expression, name, scope, unit);
|
|
278
314
|
if (arity > 0) {
|
|
279
|
-
throw
|
|
280
|
-
`The operator ${
|
|
315
|
+
throw createSemanticError(
|
|
316
|
+
`The operator ${name} requires ${arity} arguments.`,
|
|
317
|
+
getNameRange(expression.location, name),
|
|
281
318
|
);
|
|
282
319
|
}
|
|
283
320
|
return;
|
|
@@ -346,14 +383,21 @@ const resolveExpression = (
|
|
|
346
383
|
resolveAll([expression.domain, expression.range]);
|
|
347
384
|
return;
|
|
348
385
|
case "Record":
|
|
349
|
-
case "RecordSet":
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
386
|
+
case "RecordSet": {
|
|
387
|
+
const repeated = expression.fields.filter((field, index) =>
|
|
388
|
+
expression.fields.slice(0, index).some((earlier) => earlier.name === field.name),
|
|
389
|
+
);
|
|
390
|
+
if (repeated.length > 0) {
|
|
391
|
+
throw createSanyError(
|
|
392
|
+
repeated.map((field) => ({
|
|
393
|
+
location: formatRange(field.location.range ?? getNameRange(field.location, field.name)),
|
|
394
|
+
message: "Non-unique fields in constructor.",
|
|
395
|
+
})),
|
|
353
396
|
);
|
|
354
397
|
}
|
|
355
398
|
resolveAll(expression.fields.map((field) => field.value));
|
|
356
399
|
return;
|
|
400
|
+
}
|
|
357
401
|
case "Except":
|
|
358
402
|
resolveAll([
|
|
359
403
|
expression.function,
|
|
@@ -768,6 +812,29 @@ export const resolveSubstitutions = (
|
|
|
768
812
|
);
|
|
769
813
|
};
|
|
770
814
|
|
|
815
|
+
// SANY reports the errors of every unit it checks, in the order of the units in the module.
|
|
816
|
+
export const collectSemanticErrors = (units: { location: SourceLocation; check: () => void }[]) => {
|
|
817
|
+
const errors: SanyError[] = [];
|
|
818
|
+
units
|
|
819
|
+
.toSorted((left, right) => (isBefore(left.location, right.location) ? -1 : 1))
|
|
820
|
+
.forEach((unit) => {
|
|
821
|
+
try {
|
|
822
|
+
unit.check();
|
|
823
|
+
} catch (error) {
|
|
824
|
+
if (!(error instanceof TlaSyntaxError) || !error.sany) throw error;
|
|
825
|
+
error.sany.errors
|
|
826
|
+
.filter((item) =>
|
|
827
|
+
errors.every(
|
|
828
|
+
(existing) =>
|
|
829
|
+
existing.location !== item.location || existing.message !== item.message,
|
|
830
|
+
),
|
|
831
|
+
)
|
|
832
|
+
.forEach((item) => errors.push(item));
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
if (errors.length > 0) throw createSanyError(errors);
|
|
836
|
+
};
|
|
837
|
+
|
|
771
838
|
export const resolveModule = (module: Module, unit: ModuleUnit) => {
|
|
772
839
|
const symbols = createSymbols(module, unit.imported);
|
|
773
840
|
const facts = new Set(
|
|
@@ -781,13 +848,24 @@ export const resolveModule = (module: Module, unit: ModuleUnit) => {
|
|
|
781
848
|
self,
|
|
782
849
|
facts,
|
|
783
850
|
});
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
851
|
+
collectSemanticErrors([
|
|
852
|
+
...module.definitions.map((definition) => ({
|
|
853
|
+
location: definition.location,
|
|
854
|
+
check: () =>
|
|
855
|
+
resolveDefinition(definition, undefined, createUnit(definition.location, definition)),
|
|
856
|
+
})),
|
|
857
|
+
...module.assumptions.map((assumption) => ({
|
|
858
|
+
location: assumption.location,
|
|
859
|
+
check: () =>
|
|
860
|
+
resolveExpression(
|
|
861
|
+
assumption.expression,
|
|
862
|
+
undefined,
|
|
863
|
+
createUnit(assumption.location, undefined),
|
|
864
|
+
),
|
|
865
|
+
})),
|
|
866
|
+
...module.theorems.map((theorem) => ({
|
|
867
|
+
location: theorem.location,
|
|
868
|
+
check: () => resolveTheorem(theorem, createUnit(theorem.location, undefined)),
|
|
869
|
+
})),
|
|
870
|
+
]);
|
|
793
871
|
};
|