tla-ts 0.0.3-dev.5e6ab4d → 0.0.3-dev.5e999f2
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 +5 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +31 -22
- package/dist/index.d.ts +31 -22
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +17 -16
- package/dist/run-cli.js +6 -5
- package/dist/transfer.cjs +26 -11
- package/dist/transfer.js +26 -11
- package/package.json +1 -1
- package/src/ast.ts +90 -0
- package/src/check.ts +314 -80
- package/src/cli-options.ts +11 -5
- package/src/codegen.ts +15 -22
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +94 -24
- package/src/errors.ts +35 -2
- package/src/evaluate.ts +122 -147
- package/src/exit-codes.ts +21 -43
- package/src/instances.ts +15 -14
- package/src/levels.ts +8 -8
- package/src/live-check.ts +770 -0
- package/src/liveness.ts +57 -540
- package/src/parallel-worker.ts +2 -2
- package/src/parallel.ts +20 -4
- package/src/resolve.ts +16 -15
- package/src/run-cli.ts +58 -13
- package/src/runtime.ts +3 -1
- package/src/spec-description.ts +18 -6
- package/src/standard-modules.ts +2 -7
- package/src/state-graph.ts +157 -0
- package/src/subexpressions.ts +10 -10
- package/src/successors.ts +82 -16
- package/src/symmetry.ts +16 -6
- 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 +8 -4
- package/src/tlc-random.ts +9 -6
- package/src/tlc-summary.ts +20 -5
- package/src/values.ts +121 -20
package/src/evaluate.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import {
|
|
2
|
+
getChildren,
|
|
3
|
+
isLocallyResolved,
|
|
4
|
+
type Bound,
|
|
5
|
+
type BoundPattern,
|
|
6
|
+
type DecimalExpression,
|
|
7
|
+
type Definition,
|
|
8
|
+
type Expression,
|
|
9
|
+
type FunctionDefinition,
|
|
10
|
+
type NumberExpression,
|
|
11
|
+
type OperatorParam,
|
|
12
|
+
type RecordField,
|
|
13
|
+
type SourceRange,
|
|
12
14
|
} from "./ast";
|
|
13
15
|
import { getKindString } from "./builtins";
|
|
14
16
|
import { TlaEvaluationError } from "./errors";
|
|
@@ -28,23 +30,26 @@ import {
|
|
|
28
30
|
createSortedSet,
|
|
29
31
|
createWrittenRecord,
|
|
30
32
|
createTuple,
|
|
33
|
+
describeMissingField,
|
|
31
34
|
formatValue,
|
|
32
35
|
getDomain,
|
|
33
36
|
getFunctionDomain,
|
|
34
37
|
getIntervalElements,
|
|
35
38
|
getSequenceElements,
|
|
36
39
|
getValueHash,
|
|
37
|
-
isEnumerable,
|
|
38
40
|
isFunctionValue,
|
|
39
41
|
isOverriddenSet,
|
|
42
|
+
isRecordValue,
|
|
40
43
|
isSameValue,
|
|
41
44
|
markLambdaFunction,
|
|
45
|
+
isReducible,
|
|
42
46
|
isSetValue,
|
|
43
47
|
MAXIMUM_INTEGER,
|
|
44
48
|
MINIMUM_INTEGER,
|
|
45
49
|
toFiniteSet,
|
|
46
50
|
updateFunction,
|
|
47
51
|
valuesEqual,
|
|
52
|
+
type FunctionValue,
|
|
48
53
|
type LazyFunctionSource,
|
|
49
54
|
type LazyFunctionValue,
|
|
50
55
|
type Value,
|
|
@@ -180,8 +185,17 @@ export const getConjunctError = (
|
|
|
180
185
|
};
|
|
181
186
|
|
|
182
187
|
export const getFieldError =
|
|
183
|
-
(expression: Expression & { kind: "FieldAccess" }) => (record:
|
|
184
|
-
|
|
188
|
+
(expression: Expression & { kind: "FieldAccess" }) => (record: FunctionValue) =>
|
|
189
|
+
isRecordValue(record)
|
|
190
|
+
? `Attempted to select nonexistent field "${expression.field}" from the record\n${formatValue(record)}\n${describeRange(expression)}`
|
|
191
|
+
: describeMissingField(record, expression.field);
|
|
192
|
+
|
|
193
|
+
export const getNonFunctionError = (expression: Expression) => (value: Value) =>
|
|
194
|
+
`A non-function (${getKindString(value)}) was applied as a function.\n${describeRange(expression)}`;
|
|
195
|
+
|
|
196
|
+
export const getNonRecordError =
|
|
197
|
+
(expression: Expression & { kind: "FieldAccess" }) => (value: Value) =>
|
|
198
|
+
`Attempted to select field "${expression.field}" from a non-record value ${formatValue(value)}\n${describeRange(expression)}`;
|
|
185
199
|
|
|
186
200
|
export const getDomainOperator = (expression: Expression) => (value: Value) => {
|
|
187
201
|
if (!isFunctionValue(value)) {
|
|
@@ -262,96 +276,6 @@ export const expectBoolean = (value: Value, description: string) => {
|
|
|
262
276
|
return value;
|
|
263
277
|
};
|
|
264
278
|
|
|
265
|
-
export const getChildren = (expression: Expression): Expression[] => {
|
|
266
|
-
switch (expression.kind) {
|
|
267
|
-
case "Number":
|
|
268
|
-
case "Decimal":
|
|
269
|
-
case "String":
|
|
270
|
-
case "Identifier":
|
|
271
|
-
case "OperatorReference":
|
|
272
|
-
case "ExceptAt":
|
|
273
|
-
return [];
|
|
274
|
-
case "Apply":
|
|
275
|
-
return expression.args;
|
|
276
|
-
case "Lambda":
|
|
277
|
-
return [expression.body];
|
|
278
|
-
case "And":
|
|
279
|
-
case "Or":
|
|
280
|
-
return expression.operands;
|
|
281
|
-
case "Prime":
|
|
282
|
-
case "Unchanged":
|
|
283
|
-
case "Enabled":
|
|
284
|
-
case "Always":
|
|
285
|
-
case "Eventually":
|
|
286
|
-
return [expression.expression];
|
|
287
|
-
case "If":
|
|
288
|
-
return [expression.condition, expression.consequent, expression.alternative];
|
|
289
|
-
case "Case":
|
|
290
|
-
return [
|
|
291
|
-
...expression.arms.flatMap((arm) => [arm.condition, arm.body]),
|
|
292
|
-
...(expression.other ? [expression.other] : []),
|
|
293
|
-
];
|
|
294
|
-
case "Let":
|
|
295
|
-
return [
|
|
296
|
-
...expression.definitions.flatMap((definition) =>
|
|
297
|
-
definition.kind === "Function"
|
|
298
|
-
? [...definition.bounds.map((bound) => bound.set), definition.body]
|
|
299
|
-
: [definition.body],
|
|
300
|
-
),
|
|
301
|
-
expression.body,
|
|
302
|
-
];
|
|
303
|
-
case "Forall":
|
|
304
|
-
case "Exists":
|
|
305
|
-
return [...expression.bounds.map((bound) => bound.set), expression.body];
|
|
306
|
-
case "UnboundedQuantifier":
|
|
307
|
-
return [expression.body];
|
|
308
|
-
case "Choose":
|
|
309
|
-
return [...(expression.set ? [expression.set] : []), expression.body];
|
|
310
|
-
case "SetEnumeration":
|
|
311
|
-
case "Tuple":
|
|
312
|
-
return expression.elements;
|
|
313
|
-
case "SetFilter":
|
|
314
|
-
return [expression.bound.set, expression.predicate];
|
|
315
|
-
case "SetMap":
|
|
316
|
-
return [expression.expression, ...expression.bounds.map((bound) => bound.set)];
|
|
317
|
-
case "FunctionConstruction":
|
|
318
|
-
return [...expression.bounds.map((bound) => bound.set), expression.body];
|
|
319
|
-
case "FunctionSet":
|
|
320
|
-
return [expression.domain, expression.range];
|
|
321
|
-
case "Record":
|
|
322
|
-
case "RecordSet":
|
|
323
|
-
return expression.fields.map((field) => field.value);
|
|
324
|
-
case "Except":
|
|
325
|
-
return [
|
|
326
|
-
expression.function,
|
|
327
|
-
...expression.updates.flatMap((update) => [
|
|
328
|
-
...update.path.flatMap((step) => (step.kind === "Index" ? step.args : [])),
|
|
329
|
-
update.value,
|
|
330
|
-
]),
|
|
331
|
-
];
|
|
332
|
-
case "FunctionApplication":
|
|
333
|
-
return [expression.function, ...expression.args];
|
|
334
|
-
case "FieldAccess":
|
|
335
|
-
return [expression.record];
|
|
336
|
-
case "Product":
|
|
337
|
-
return expression.factors;
|
|
338
|
-
case "BoxAction":
|
|
339
|
-
case "AngleAction":
|
|
340
|
-
return [expression.action, expression.subscript];
|
|
341
|
-
case "WeakFairness":
|
|
342
|
-
case "StrongFairness":
|
|
343
|
-
return [expression.subscript, expression.action];
|
|
344
|
-
case "Label":
|
|
345
|
-
return [expression.body];
|
|
346
|
-
case "Subexpression":
|
|
347
|
-
return expression.selectors.flatMap((selector) => ("args" in selector ? selector.args : []));
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
export const isLocallyResolved = (expression: Expression) =>
|
|
352
|
-
(expression.kind === "Identifier" || expression.kind === "Apply") &&
|
|
353
|
-
expression.resolution?.kind === "Local";
|
|
354
|
-
|
|
355
279
|
export const getDefinition = (name: string, environment: Environment) =>
|
|
356
280
|
environment.definitions.get(environment.substitutions.get(name) ?? name);
|
|
357
281
|
|
|
@@ -859,11 +783,7 @@ const evaluateLocalIdentifier = (name: string, expression: Expression, context:
|
|
|
859
783
|
const global = findGlobalName(name, context.environment);
|
|
860
784
|
if (global?.kind === "Variable") {
|
|
861
785
|
const value = context.state?.[global.index];
|
|
862
|
-
if (value === undefined)
|
|
863
|
-
throw new TlaEvaluationError(
|
|
864
|
-
`The variable ${name} is not assigned at ${describeLocation(expression)}`,
|
|
865
|
-
);
|
|
866
|
-
}
|
|
786
|
+
if (value === undefined) throw createUnassignedError(name, expression);
|
|
867
787
|
return value;
|
|
868
788
|
}
|
|
869
789
|
if (global?.kind === "Value") return global.value;
|
|
@@ -889,14 +809,29 @@ const IMPURE_BUILTINS = new Set([
|
|
|
889
809
|
export const isImpureBuiltin = (name: string, environment: Environment) =>
|
|
890
810
|
IMPURE_BUILTINS.has(name) || environment.builtins.get(name)?.isStateLevel === true;
|
|
891
811
|
|
|
892
|
-
|
|
812
|
+
interface Impurity {
|
|
813
|
+
builtins: Set<string>;
|
|
814
|
+
definitions: WeakMap<Definition, boolean>;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
const ANY_EFFECT: Impurity = { builtins: IMPURE_BUILTINS, definitions: new WeakMap() };
|
|
818
|
+
|
|
819
|
+
// An Assert that held holds again, so evaluating it twice looks the same as evaluating it once.
|
|
820
|
+
const REPEATED_EFFECT: Impurity = {
|
|
821
|
+
builtins: new Set([...IMPURE_BUILTINS].filter((name) => name !== "Assert")),
|
|
822
|
+
definitions: new WeakMap(),
|
|
823
|
+
};
|
|
893
824
|
|
|
894
825
|
const isEvaluatedOnce = (definition: Definition, environment: Environment) =>
|
|
895
826
|
definition.kind === "Operator" &&
|
|
896
827
|
definition.params.length === 0 &&
|
|
897
828
|
isConstantLevel(definition, environment);
|
|
898
829
|
|
|
899
|
-
const callsImpureBuiltin = (
|
|
830
|
+
const callsImpureBuiltin = (
|
|
831
|
+
expression: Expression,
|
|
832
|
+
environment: Environment,
|
|
833
|
+
impurity: Impurity,
|
|
834
|
+
): boolean => {
|
|
900
835
|
const name =
|
|
901
836
|
expression.kind === "Identifier"
|
|
902
837
|
? expression.name
|
|
@@ -905,29 +840,35 @@ const callsImpureBuiltin = (expression: Expression, environment: Environment): b
|
|
|
905
840
|
: undefined;
|
|
906
841
|
if (name !== undefined && !isLocallyResolved(expression)) {
|
|
907
842
|
const definition = getDefinition(name, environment);
|
|
908
|
-
|
|
843
|
+
const isImpureCall =
|
|
844
|
+
impurity.builtins.has(name) || environment.builtins.get(name)?.isStateLevel === true;
|
|
845
|
+
if (!definition && isImpureCall) return true;
|
|
909
846
|
if (
|
|
910
847
|
definition &&
|
|
911
848
|
!isEvaluatedOnce(definition, environment) &&
|
|
912
|
-
isImpureDefinition(definition, environment)
|
|
849
|
+
isImpureDefinition(definition, environment, impurity)
|
|
913
850
|
) {
|
|
914
851
|
return true;
|
|
915
852
|
}
|
|
916
853
|
}
|
|
917
|
-
return getChildren(expression).some((child) => callsImpureBuiltin(child, environment));
|
|
854
|
+
return getChildren(expression).some((child) => callsImpureBuiltin(child, environment, impurity));
|
|
918
855
|
};
|
|
919
856
|
|
|
920
857
|
// TLC evaluates a constant definition without parameters once, so only other definitions pass
|
|
921
858
|
// on the side effects and random choices of the builtins they call.
|
|
922
|
-
const isImpureDefinition = (
|
|
923
|
-
|
|
859
|
+
const isImpureDefinition = (
|
|
860
|
+
definition: Definition,
|
|
861
|
+
environment: Environment,
|
|
862
|
+
impurity = ANY_EFFECT,
|
|
863
|
+
): boolean => {
|
|
864
|
+
const cached = impurity.definitions.get(definition);
|
|
924
865
|
if (cached !== undefined) return cached;
|
|
925
|
-
|
|
866
|
+
impurity.definitions.set(definition, false);
|
|
926
867
|
const isImpure =
|
|
927
|
-
callsImpureBuiltin(definition.body, environment) ||
|
|
868
|
+
callsImpureBuiltin(definition.body, environment, impurity) ||
|
|
928
869
|
(definition.kind === "Function" &&
|
|
929
|
-
definition.bounds.some((bound) => callsImpureBuiltin(bound.set, environment)));
|
|
930
|
-
|
|
870
|
+
definition.bounds.some((bound) => callsImpureBuiltin(bound.set, environment, impurity)));
|
|
871
|
+
impurity.definitions.set(definition, isImpure);
|
|
931
872
|
return isImpure;
|
|
932
873
|
};
|
|
933
874
|
|
|
@@ -941,6 +882,12 @@ export const isImpure = (environment: Environment) =>
|
|
|
941
882
|
isImpureDefinition(definition, environment),
|
|
942
883
|
);
|
|
943
884
|
|
|
885
|
+
// Whether evaluating a definition again can show, such as by printing twice.
|
|
886
|
+
export const hasRepeatedEffects = (environment: Environment) =>
|
|
887
|
+
[...environment.definitions.values()].some((definition) =>
|
|
888
|
+
isImpureDefinition(definition, environment, REPEATED_EFFECT),
|
|
889
|
+
);
|
|
890
|
+
|
|
944
891
|
const closedConstants = new WeakMap<Expression, boolean>();
|
|
945
892
|
|
|
946
893
|
export const isClosedConstant = (expression: Expression, environment: Environment): boolean => {
|
|
@@ -1092,7 +1039,7 @@ export const getEvaluator = (expression: Expression, environment: Environment):
|
|
|
1092
1039
|
|
|
1093
1040
|
const entryEvaluators = new WeakMap<Expression, Evaluator>();
|
|
1094
1041
|
|
|
1095
|
-
const getEntryEvaluator = (expression: Expression, environment: Environment) => {
|
|
1042
|
+
export const getEntryEvaluator = (expression: Expression, environment: Environment) => {
|
|
1096
1043
|
const cached = entryEvaluators.get(expression);
|
|
1097
1044
|
if (cached) return cached;
|
|
1098
1045
|
const evaluator =
|
|
@@ -1116,11 +1063,7 @@ const compileIdentifier = (
|
|
|
1116
1063
|
const index = global.index;
|
|
1117
1064
|
return (context) => {
|
|
1118
1065
|
const value = context.state?.[index];
|
|
1119
|
-
if (value === undefined)
|
|
1120
|
-
throw new TlaEvaluationError(
|
|
1121
|
-
`The variable ${name} is not assigned at ${describeLocation(expression)}`,
|
|
1122
|
-
);
|
|
1123
|
-
}
|
|
1066
|
+
if (value === undefined) throw createUnassignedError(name, expression);
|
|
1124
1067
|
return value;
|
|
1125
1068
|
};
|
|
1126
1069
|
}
|
|
@@ -1394,6 +1337,11 @@ const compileApply = (
|
|
|
1394
1337
|
if (definition?.kind === "Function") {
|
|
1395
1338
|
throw new TlaEvaluationError(`${expression.operator} is a function; apply it with brackets`);
|
|
1396
1339
|
}
|
|
1340
|
+
if (expression.operator === "\\cdot") {
|
|
1341
|
+
throw new TlaEvaluationError(
|
|
1342
|
+
"The current version of TLC does not support action composition. An incomplete implementation can be enabled via the tlc2.tool.impl.Tool.cdot=true java property.",
|
|
1343
|
+
);
|
|
1344
|
+
}
|
|
1397
1345
|
throw new TlaEvaluationError(
|
|
1398
1346
|
`Unknown operator ${expression.operator} at ${describeLocation(expression)}`,
|
|
1399
1347
|
);
|
|
@@ -1489,7 +1437,13 @@ const compileFunctionConstruction = (
|
|
|
1489
1437
|
const set = getEvaluator(bound.set, environment);
|
|
1490
1438
|
return (context) => {
|
|
1491
1439
|
const domain = isSingleName ? set(context) : getBoundsDomain(bounds, context);
|
|
1492
|
-
|
|
1440
|
+
// TLC builds the function only when it reduces every domain, and evaluates the body lazily
|
|
1441
|
+
// otherwise.
|
|
1442
|
+
const domains =
|
|
1443
|
+
typeof domain === "object" && domain.kind === "ProductSet" && bounds.length > 1
|
|
1444
|
+
? domain.factors
|
|
1445
|
+
: [domain];
|
|
1446
|
+
if (expression.isRecursive || isKeptLazy || !domains.every(isReducible)) {
|
|
1493
1447
|
const functionValue = createLazyFunction(
|
|
1494
1448
|
domain,
|
|
1495
1449
|
(argument) => body(withScope(context, bindArgument(bounds, context.scope, argument))),
|
|
@@ -1583,10 +1537,7 @@ const compileSetComprehension = (
|
|
|
1583
1537
|
predicate(withScope(context, bindPattern(context.scope, pattern, element))),
|
|
1584
1538
|
"a set filter predicate",
|
|
1585
1539
|
);
|
|
1586
|
-
|
|
1587
|
-
typeof base === "object" &&
|
|
1588
|
-
(base.kind === "Set" || base.kind === "MixedSet" || base.kind === "Interval");
|
|
1589
|
-
if (!isReducible) {
|
|
1540
|
+
if (!isReducible(base)) {
|
|
1590
1541
|
if (isSetValue(base)) return { kind: "FilteredSet", base, test };
|
|
1591
1542
|
throw new TlaEvaluationError(
|
|
1592
1543
|
`TLC encountered a non-enumerable quantifier bound ${formatValue(base)} at ${describeLocation(expression.bound.set)}`,
|
|
@@ -1632,11 +1583,26 @@ const compileSetComprehension = (
|
|
|
1632
1583
|
};
|
|
1633
1584
|
};
|
|
1634
1585
|
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1586
|
+
// TLC orders a record's fields by name.
|
|
1587
|
+
export const getSortedFields = (fields: RecordField[]) =>
|
|
1588
|
+
[...fields].sort((left, right) => compareValues(left.name, right.name));
|
|
1589
|
+
|
|
1590
|
+
export const hasDuplicateFields = (sortedFields: RecordField[]) =>
|
|
1591
|
+
sortedFields.some((field, index) => index > 0 && sortedFields[index - 1].name === field.name);
|
|
1592
|
+
|
|
1593
|
+
export const createUnassignedError = (name: string, expression: Expression) =>
|
|
1594
|
+
new TlaEvaluationError(
|
|
1595
|
+
`In evaluation, the identifier ${name} is either undefined or not an operator.\n${describeRange(expression)}`,
|
|
1639
1596
|
);
|
|
1597
|
+
|
|
1598
|
+
export const createPrimeOutsideActionError = (expression: Expression) =>
|
|
1599
|
+
new TlaEvaluationError(
|
|
1600
|
+
`A primed expression appears outside an action at ${describeLocation(expression)}`,
|
|
1601
|
+
);
|
|
1602
|
+
|
|
1603
|
+
const compileRecord = (recordFields: RecordField[], environment: Environment): Evaluator => {
|
|
1604
|
+
const fields = getSortedFields(recordFields);
|
|
1605
|
+
const hasDuplicates = hasDuplicateFields(fields);
|
|
1640
1606
|
const values = fields.map((field) => getEvaluator(field.value, environment));
|
|
1641
1607
|
if (hasDuplicates) {
|
|
1642
1608
|
return (context) =>
|
|
@@ -1714,11 +1680,7 @@ const compile = (expression: Expression, environment: Environment): Evaluator =>
|
|
|
1714
1680
|
case "Prime": {
|
|
1715
1681
|
const inner = child(expression.expression);
|
|
1716
1682
|
return (context) => {
|
|
1717
|
-
if (!context.next)
|
|
1718
|
-
throw new TlaEvaluationError(
|
|
1719
|
-
`A primed expression appears outside an action at ${describeLocation(expression)}`,
|
|
1720
|
-
);
|
|
1721
|
-
}
|
|
1683
|
+
if (!context.next) throw createPrimeOutsideActionError(expression);
|
|
1722
1684
|
return inner({
|
|
1723
1685
|
environment: context.environment,
|
|
1724
1686
|
scope: context.scope,
|
|
@@ -1757,7 +1719,9 @@ const compile = (expression: Expression, environment: Environment): Evaluator =>
|
|
|
1757
1719
|
if (expectBoolean(arm.condition(context), "a CASE guard")) return arm.body(context);
|
|
1758
1720
|
}
|
|
1759
1721
|
if (other) return other(context);
|
|
1760
|
-
throw new TlaEvaluationError(
|
|
1722
|
+
throw new TlaEvaluationError(
|
|
1723
|
+
`Attempted to evaluate a CASE with no conditions true.\n${describeRange(expression)}`,
|
|
1724
|
+
);
|
|
1761
1725
|
};
|
|
1762
1726
|
}
|
|
1763
1727
|
case "Let": {
|
|
@@ -1796,9 +1760,7 @@ const compile = (expression: Expression, environment: Environment): Evaluator =>
|
|
|
1796
1760
|
case "Record":
|
|
1797
1761
|
return compileRecord(expression.fields, environment);
|
|
1798
1762
|
case "RecordSet": {
|
|
1799
|
-
const fields =
|
|
1800
|
-
compareValues(left.name, right.name),
|
|
1801
|
-
);
|
|
1763
|
+
const fields = getSortedFields(expression.fields);
|
|
1802
1764
|
const names = fields.map((field) => field.name);
|
|
1803
1765
|
const sets = fields.map((field) => child(field.value));
|
|
1804
1766
|
return (context) => ({ kind: "RecordSet", names, sets: sets.map((set) => set(context)) });
|
|
@@ -1819,18 +1781,31 @@ const compile = (expression: Expression, environment: Environment): Evaluator =>
|
|
|
1819
1781
|
keepLazy(expression.function);
|
|
1820
1782
|
const evaluateFunction = child(expression.function);
|
|
1821
1783
|
const args = expression.args.map(child);
|
|
1784
|
+
const describeNonFunction = getNonFunctionError(expression);
|
|
1822
1785
|
if (args.length === 1) {
|
|
1823
1786
|
const argument = args[0];
|
|
1824
|
-
return (context) =>
|
|
1787
|
+
return (context) =>
|
|
1788
|
+
applyFunction(
|
|
1789
|
+
evaluateFunction(context),
|
|
1790
|
+
argument(context),
|
|
1791
|
+
undefined,
|
|
1792
|
+
describeNonFunction,
|
|
1793
|
+
);
|
|
1825
1794
|
}
|
|
1826
1795
|
return (context) =>
|
|
1827
|
-
applyFunction(
|
|
1796
|
+
applyFunction(
|
|
1797
|
+
evaluateFunction(context),
|
|
1798
|
+
createTuple(args.map((arg) => arg(context))),
|
|
1799
|
+
undefined,
|
|
1800
|
+
describeNonFunction,
|
|
1801
|
+
);
|
|
1828
1802
|
}
|
|
1829
1803
|
case "FieldAccess": {
|
|
1830
1804
|
const record = child(expression.record);
|
|
1831
1805
|
const field = expression.field;
|
|
1832
1806
|
const describeMissing = getFieldError(expression);
|
|
1833
|
-
|
|
1807
|
+
const describeNonRecord = getNonRecordError(expression);
|
|
1808
|
+
return (context) => applyFunction(record(context), field, describeMissing, describeNonRecord);
|
|
1834
1809
|
}
|
|
1835
1810
|
case "Product": {
|
|
1836
1811
|
const factors = expression.factors.map(child);
|
package/src/exit-codes.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LivenessChecker } from "./
|
|
1
|
+
import type { LivenessChecker } from "./live-check";
|
|
2
2
|
|
|
3
3
|
// TLC's exit statuses, from EC.ExitStatus.
|
|
4
4
|
export const EXIT_STATUS = {
|
|
@@ -17,12 +17,6 @@ export const EXIT_STATUS = {
|
|
|
17
17
|
} as const;
|
|
18
18
|
|
|
19
19
|
const exitCodes = new WeakMap<Error, number>();
|
|
20
|
-
const moduleExitCodes = new WeakMap<Error, number>();
|
|
21
|
-
const phase = { isNextState: false };
|
|
22
|
-
|
|
23
|
-
export const setNextStatePhase = (isNextState: boolean) => {
|
|
24
|
-
phase.isNextState = isNextState;
|
|
25
|
-
};
|
|
26
20
|
|
|
27
21
|
// The innermost site that knows TLC's exit status for an error sets it first and wins.
|
|
28
22
|
export const setExitCode = <Thrown>(error: Thrown, code: number) => {
|
|
@@ -30,46 +24,30 @@ export const setExitCode = <Thrown>(error: Thrown, code: number) => {
|
|
|
30
24
|
return error;
|
|
31
25
|
};
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
// escapes the computation of next states. In every other phase, the phase decides the code.
|
|
35
|
-
export const setModuleExitCode = (error: Error, code: number) => {
|
|
36
|
-
if (phase.isNextState) moduleExitCodes.set(error, code);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const getExitCode = (error: Error) => exitCodes.get(error) ?? moduleExitCodes.get(error);
|
|
27
|
+
export const getExitCode = (error: Error) => exitCodes.get(error);
|
|
40
28
|
|
|
41
29
|
// TLC exits with 255 when it fails to process or evaluate a liveness property, in any phase.
|
|
42
|
-
|
|
43
|
-
create: () => LivenessChecker | undefined,
|
|
44
|
-
): LivenessChecker | undefined => {
|
|
30
|
+
const withErrorExitCode = <Result>(run: () => Result) => {
|
|
45
31
|
try {
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
checker && {
|
|
49
|
-
addInitialState: (index, state) => {
|
|
50
|
-
try {
|
|
51
|
-
checker.addInitialState(index, state);
|
|
52
|
-
} catch (error) {
|
|
53
|
-
throw setExitCode(error, EXIT_STATUS.error);
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
addState: (index, state, successors) => {
|
|
57
|
-
try {
|
|
58
|
-
return checker.addState(index, state, successors);
|
|
59
|
-
} catch (error) {
|
|
60
|
-
throw setExitCode(error, EXIT_STATUS.error);
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
findViolation: () => {
|
|
64
|
-
try {
|
|
65
|
-
return checker.findViolation();
|
|
66
|
-
} catch (error) {
|
|
67
|
-
throw setExitCode(error, EXIT_STATUS.error);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
}
|
|
71
|
-
);
|
|
32
|
+
return run();
|
|
72
33
|
} catch (error) {
|
|
73
34
|
throw setExitCode(error, EXIT_STATUS.error);
|
|
74
35
|
}
|
|
75
36
|
};
|
|
37
|
+
|
|
38
|
+
export const withLivenessExitCode = (
|
|
39
|
+
create: () => LivenessChecker | undefined,
|
|
40
|
+
): LivenessChecker | undefined => {
|
|
41
|
+
const checker = withErrorExitCode(create);
|
|
42
|
+
return (
|
|
43
|
+
checker && {
|
|
44
|
+
addInitialState: (index, state) =>
|
|
45
|
+
withErrorExitCode(() => checker.addInitialState(index, state)),
|
|
46
|
+
addState: (index, state, successors) =>
|
|
47
|
+
withErrorExitCode(() => checker.addState(index, state, successors)),
|
|
48
|
+
findViolation: () => withErrorExitCode(() => checker.findViolation()),
|
|
49
|
+
getViolatedProperties: (path, cycleStart) =>
|
|
50
|
+
withErrorExitCode(() => checker.getViolatedProperties(path, cycleStart)),
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
};
|
package/src/instances.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import {
|
|
2
|
+
getChildren,
|
|
3
|
+
isLocallyResolved,
|
|
4
|
+
type Bound,
|
|
5
|
+
type BoundPattern,
|
|
6
|
+
type Definition,
|
|
7
|
+
type Expression,
|
|
8
|
+
type Instance,
|
|
9
|
+
type Module,
|
|
10
|
+
type OperatorParam,
|
|
11
|
+
type SourceLocation,
|
|
12
|
+
type Theorem,
|
|
11
13
|
} from "./ast";
|
|
12
14
|
import { TlaSyntaxError } from "./errors";
|
|
13
|
-
import { getChildren, isLocallyResolved } from "./evaluate";
|
|
14
15
|
import { getArity, getBoundNames, getPatternNames, isBefore } from "./resolve";
|
|
15
16
|
|
|
16
17
|
export const substitutedExpressions = new WeakSet<Expression>();
|
|
@@ -218,7 +219,7 @@ interface Instantiation {
|
|
|
218
219
|
variables: Set<string>;
|
|
219
220
|
getDefinition: (key: string) => Definition | undefined;
|
|
220
221
|
isParameterized: (key: string) => boolean;
|
|
221
|
-
addDefinition: (name: string, create: (key: string) => Definition) => string;
|
|
222
|
+
addDefinition: (source: string, name: string, create: (key: string) => Definition) => string;
|
|
222
223
|
createName: (name: string) => string;
|
|
223
224
|
}
|
|
224
225
|
|
|
@@ -639,7 +640,7 @@ const copyDefinition = (rewrite: Rewrite, key: string): string => {
|
|
|
639
640
|
const instantiation = rewrite.instantiation;
|
|
640
641
|
const definition = instantiation.getDefinition(key);
|
|
641
642
|
if (!definition) return key;
|
|
642
|
-
return instantiation.addDefinition(definition.name, (copyKey) => {
|
|
643
|
+
return instantiation.addDefinition(key, definition.name, (copyKey) => {
|
|
643
644
|
rewrite.copies.set(key, copyKey);
|
|
644
645
|
const rename = createRenamer(rewrite);
|
|
645
646
|
const mapped = renameParams(
|
|
@@ -678,7 +679,7 @@ export const createInstantiation = (instantiation: Instantiation) => {
|
|
|
678
679
|
if (copy !== undefined) return copy;
|
|
679
680
|
const definition = instantiation.getDefinition(key);
|
|
680
681
|
if (!definition) return key;
|
|
681
|
-
return instantiation.addDefinition(definition.name, () =>
|
|
682
|
+
return instantiation.addDefinition(key, definition.name, () =>
|
|
682
683
|
withInstanceParams(definition, instantiation.params, definition.location),
|
|
683
684
|
);
|
|
684
685
|
},
|
package/src/levels.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import {
|
|
2
|
+
getChildren,
|
|
3
|
+
type AssumeProve,
|
|
4
|
+
type Definition,
|
|
5
|
+
type Expression,
|
|
6
|
+
type Module,
|
|
7
|
+
type OperatorParam,
|
|
8
|
+
type SourceLocation,
|
|
8
9
|
} from "./ast";
|
|
9
10
|
import { TlaSyntaxError } from "./errors";
|
|
10
|
-
import { getChildren } from "./evaluate";
|
|
11
11
|
import { mapChildren } from "./instances";
|
|
12
12
|
import { getBoundNames, getPatternNames } from "./resolve";
|
|
13
13
|
import { STANDARD_LEVELS } from "./standard-levels";
|