tla-ts 0.0.3-dev.a57ca4f → 0.0.3-dev.a91da46
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/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +148 -8
- package/dist/index.d.ts +148 -8
- 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 +1351 -20
- package/dist/run-cli.js +1351 -20
- package/dist/transfer.cjs +86 -28
- package/dist/transfer.js +86 -28
- package/package.json +5 -1
- package/src/ast.ts +52 -6
- package/src/bags.ts +4 -7
- package/src/builtins.ts +29 -11
- package/src/bundled-modules.ts +3 -3
- package/src/canonical.ts +4 -3
- package/src/check.ts +1358 -219
- package/src/cli.ts +8 -1
- package/src/codegen.ts +68 -18
- package/src/config.ts +252 -179
- package/src/environment.ts +451 -129
- package/src/errors.ts +217 -3
- package/src/evaluate.ts +723 -116
- package/src/exit-codes.ts +5 -4
- package/src/index.ts +1 -0
- package/src/instances.ts +4 -2
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +183 -37
- package/src/lexer.ts +32 -4
- package/src/live-check.ts +220 -103
- package/src/liveness.ts +192 -65
- package/src/obligation-expression.ts +2 -2
- package/src/obligation-source.ts +2 -0
- package/src/parallel-worker.ts +8 -3
- package/src/parallel.ts +56 -5
- package/src/parser.ts +436 -128
- package/src/pcal-ast.ts +770 -0
- package/src/pcal-parse.ts +1523 -0
- package/src/pcal-tokenize.ts +516 -0
- package/src/pcal-translate.ts +1230 -0
- package/src/pcal-validate.ts +454 -0
- package/src/randomization.ts +24 -7
- package/src/resolve.ts +1364 -405
- package/src/run-cli.ts +1167 -155
- package/src/runtime.ts +16 -0
- package/src/sany-builtins.ts +147 -0
- package/src/sany-generator.ts +3112 -0
- package/src/sany-levels.ts +1208 -0
- package/src/sany-lexer.ts +545 -0
- package/src/sany-linter.ts +122 -0
- package/src/sany-modules.ts +1398 -0
- package/src/sany-nodes.ts +463 -0
- package/src/sany-parse-error.ts +2161 -0
- package/src/sany-report.ts +354 -0
- package/src/sany-selectors.ts +738 -0
- package/src/sany-source.ts +248 -0
- package/src/sany-xml.ts +1017 -0
- package/src/spec-description.ts +26 -7
- package/src/standard-modules.ts +203 -146
- package/src/standard-ranges.ts +116 -0
- package/src/state-graph.ts +29 -6
- package/src/subexpressions.ts +221 -161
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +160 -105
- package/src/symmetry.ts +180 -52
- package/src/tableau.ts +54 -25
- package/src/tlc-ext.ts +13 -17
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +46 -18
- package/src/tlc-order.ts +56 -6
- package/src/tlc-random.ts +37 -9
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-summary.ts +20 -5
- package/src/tlc-version.ts +18 -0
- package/src/transfer.ts +15 -3
- package/src/value-sources.ts +29 -0
- package/src/values.ts +680 -178
package/src/successors.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getChildren,
|
|
3
3
|
isLocallyResolved,
|
|
4
|
-
type Bound,
|
|
5
4
|
type Definition,
|
|
6
5
|
type Expression,
|
|
7
6
|
type QuantifierExpression,
|
|
8
7
|
} from "./ast";
|
|
8
|
+
import { getKindString } from "./builtins";
|
|
9
9
|
import { getReadVariables } from "./dependencies";
|
|
10
|
-
import { TlaEvaluationError,
|
|
10
|
+
import { TlaEvaluationError, TlaIllegalStateError, TlaIncompleteSuccessorError } from "./errors";
|
|
11
11
|
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
12
12
|
import {
|
|
13
13
|
describeLocation,
|
|
14
|
+
describeNode,
|
|
14
15
|
describeRange,
|
|
15
|
-
|
|
16
|
+
bindLazyArguments,
|
|
16
17
|
bindDefinitions,
|
|
17
18
|
bindOperatorArguments,
|
|
18
19
|
bindValue,
|
|
@@ -20,25 +21,27 @@ import {
|
|
|
20
21
|
evaluate,
|
|
21
22
|
expectBoolean,
|
|
22
23
|
forEachBinding,
|
|
23
|
-
|
|
24
|
+
getLazyFunction,
|
|
25
|
+
toKeepLazyContext,
|
|
24
26
|
getDefinition,
|
|
25
|
-
|
|
27
|
+
getContextElements,
|
|
26
28
|
getReevaluatedDefinitions,
|
|
27
29
|
lookupScope,
|
|
28
30
|
resolveApplyOperator,
|
|
29
31
|
resolveGlobalOperator,
|
|
32
|
+
toUnspecifiedSubscriptError,
|
|
30
33
|
type Context,
|
|
31
34
|
type Environment,
|
|
32
35
|
type Scope,
|
|
33
36
|
type State,
|
|
34
37
|
} from "./evaluate";
|
|
35
38
|
import { mapChildren } from "./instances";
|
|
39
|
+
import { isAssignedShortcut, LITERAL_KINDS, replayEnabled } from "./tlc-replay";
|
|
36
40
|
import {
|
|
37
|
-
createTuple,
|
|
38
41
|
formatValue,
|
|
39
42
|
getStreamedElements,
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
isFunctionValue,
|
|
44
|
+
isTlcEnumerable,
|
|
42
45
|
valuesEqual,
|
|
43
46
|
type Value,
|
|
44
47
|
} from "./values";
|
|
@@ -51,6 +54,8 @@ export interface Successor {
|
|
|
51
54
|
interface Run {
|
|
52
55
|
environment: Environment;
|
|
53
56
|
isInit: boolean;
|
|
57
|
+
// Whether the run computes ENABLED rather than the successors of the state.
|
|
58
|
+
isEnabled: boolean;
|
|
54
59
|
current: Value[] | undefined;
|
|
55
60
|
isStopped: boolean;
|
|
56
61
|
}
|
|
@@ -87,15 +92,47 @@ const assign = (partial: State, index: number, value: Value) => {
|
|
|
87
92
|
return copy;
|
|
88
93
|
};
|
|
89
94
|
|
|
90
|
-
|
|
95
|
+
// What TLC says it was computing when it fails.
|
|
96
|
+
const getComputation = (run: Run) =>
|
|
97
|
+
run.isInit ? "initial states" : run.isEnabled ? "ENABLED" : "next states";
|
|
98
|
+
|
|
99
|
+
// TLC fails with an unexpected exception when it fails to compute the next states or ENABLED.
|
|
100
|
+
const createRunError = (run: Run, message: string) => {
|
|
101
|
+
const error = new TlaEvaluationError(message);
|
|
102
|
+
return run.isInit ? error : setExitCode(error, EXIT_STATUS.error);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// TLC's message for a conjunct that isn't a boolean, which differs for a literal it walks to rather
|
|
106
|
+
// than evaluates.
|
|
107
|
+
const getNonBooleanMessage = (
|
|
108
|
+
run: Run,
|
|
109
|
+
value: Value,
|
|
110
|
+
expression: Expression,
|
|
111
|
+
isWalked: boolean,
|
|
112
|
+
) => {
|
|
113
|
+
const node = describeNode(expression);
|
|
114
|
+
if (isWalked && LITERAL_KINDS.has(expression.kind)) {
|
|
115
|
+
return run.isEnabled
|
|
116
|
+
? `Attempted to compute ENABLED on a non-boolean expression.\n${node}`
|
|
117
|
+
: `The ${run.isInit ? "init" : "next"} state relation is not a boolean expression.\n${node}`;
|
|
118
|
+
}
|
|
119
|
+
return `In computing ${getComputation(run)}, TLC expected a boolean expression,\nbut instead found ${formatValue(value)}.\n${node}`;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// TLC words an IF whose condition isn't a boolean differently for each computation.
|
|
123
|
+
const getIfConditionMessage = (run: Run, value: Value, expression: Expression) => {
|
|
124
|
+
const kind = getKindString(value);
|
|
125
|
+
const range = describeRange(expression);
|
|
126
|
+
if (run.isEnabled) {
|
|
127
|
+
return `In computing ENABLED, a non-boolean expression(${kind}) was used as the guard condition of an IF.\n${range}`;
|
|
128
|
+
}
|
|
129
|
+
return `In computing ${getComputation(run)}, a non-boolean expression (${kind}) was used as the condition of an IF.${run.isInit ? "\n" : ""}${range}`;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const holds = (run: Run, expression: Expression, context: Context, isWalked = true) => {
|
|
91
133
|
const value = evaluate(expression, context);
|
|
92
134
|
if (typeof value === "boolean") return value;
|
|
93
|
-
|
|
94
|
-
return expectBoolean(value, `the action at ${describeLocation(expression)}`);
|
|
95
|
-
} catch (error) {
|
|
96
|
-
// TLC fails with an unexpected exception when the next-state relation isn't a boolean.
|
|
97
|
-
throw context.next === undefined ? error : setExitCode(error, EXIT_STATUS.error);
|
|
98
|
-
}
|
|
135
|
+
throw createRunError(run, getNonBooleanMessage(run, value, expression, isWalked));
|
|
99
136
|
};
|
|
100
137
|
|
|
101
138
|
const isAssignmentOperator = (operator: string) =>
|
|
@@ -330,11 +367,12 @@ const compileConjunction = (
|
|
|
330
367
|
): void => {
|
|
331
368
|
let current = partial;
|
|
332
369
|
let context: Context | undefined;
|
|
370
|
+
const isShortcut = isAssignedShortcut(run);
|
|
333
371
|
for (let index = start; index < conjuncts.length; index++) {
|
|
334
|
-
if (index > 0 &&
|
|
372
|
+
if (index > 0 && isShortcut && isComplete(current)) {
|
|
335
373
|
context ??= getContext(run, scope, current);
|
|
336
374
|
for (let rest = index; rest < conjuncts.length; rest++) {
|
|
337
|
-
if (!
|
|
375
|
+
if (!holds(run, conjuncts[rest].expression, context, false)) return;
|
|
338
376
|
}
|
|
339
377
|
onComplete(current, action);
|
|
340
378
|
return;
|
|
@@ -342,7 +380,7 @@ const compileConjunction = (
|
|
|
342
380
|
const conjunct = conjuncts[index];
|
|
343
381
|
if (conjunct.kind === "Guard") {
|
|
344
382
|
context ??= getContext(run, scope, current);
|
|
345
|
-
if (!holds(conjunct.expression, context)) return;
|
|
383
|
+
if (!holds(run, conjunct.expression, context)) return;
|
|
346
384
|
continue;
|
|
347
385
|
}
|
|
348
386
|
if (conjunct.kind === "Assign") {
|
|
@@ -383,16 +421,10 @@ const compileConjunction = (
|
|
|
383
421
|
runFrom(0, run, scope, partial, action, onComplete);
|
|
384
422
|
};
|
|
385
423
|
|
|
386
|
-
const holdsInInit = (expression: Expression, context: Context) =>
|
|
387
|
-
expectBoolean(
|
|
388
|
-
evaluate(expression, context),
|
|
389
|
-
`the initial predicate at ${describeLocation(expression)}`,
|
|
390
|
-
);
|
|
391
|
-
|
|
392
424
|
const compileGuard =
|
|
393
425
|
(expression: Expression): Runner =>
|
|
394
426
|
(run, scope, partial, action, _isFixed, onComplete) => {
|
|
395
|
-
if (holds(expression, getContext(run, scope, partial))) onComplete(partial, action);
|
|
427
|
+
if (holds(run, expression, getContext(run, scope, partial))) onComplete(partial, action);
|
|
396
428
|
};
|
|
397
429
|
|
|
398
430
|
const compileMembership = (
|
|
@@ -404,16 +436,17 @@ const compileMembership = (
|
|
|
404
436
|
const index = getIndex(run, scope, partial);
|
|
405
437
|
const context = getContext(run, scope, partial);
|
|
406
438
|
if (partial[index] !== undefined) {
|
|
407
|
-
if (holds(expression, context)) onComplete(partial, action);
|
|
439
|
+
if (holds(run, expression, context)) onComplete(partial, action);
|
|
408
440
|
return;
|
|
409
441
|
}
|
|
410
442
|
const evaluated = evaluate(set, context);
|
|
411
443
|
const value: Value =
|
|
412
444
|
expression.operator === "\\subseteq" ? { kind: "Subset", base: evaluated } : evaluated;
|
|
413
|
-
if (!
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
445
|
+
if (!isTlcEnumerable(value)) {
|
|
446
|
+
const message = run.isEnabled
|
|
447
|
+
? "The right side of \\IN is not enumerable."
|
|
448
|
+
: `In computing ${getComputation(run)}, the right side of \\IN is not enumerable.`;
|
|
449
|
+
throw createRunError(run, `${message}\n${describeRange(expression)}`);
|
|
417
450
|
}
|
|
418
451
|
const elements = getStreamedElements(value);
|
|
419
452
|
for (let position = 0; position < elements.length && !run.isStopped; position++) {
|
|
@@ -463,65 +496,43 @@ const compileDynamicAssignment = (
|
|
|
463
496
|
};
|
|
464
497
|
};
|
|
465
498
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
body: Expression;
|
|
469
|
-
scope: Scope | undefined;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
const getFunctionAction = (
|
|
473
|
-
expression: Expression,
|
|
474
|
-
scope: Scope | undefined,
|
|
475
|
-
partial: State,
|
|
476
|
-
run: Run,
|
|
477
|
-
): FunctionAction | undefined => {
|
|
478
|
-
if (expression.kind === "FunctionConstruction") {
|
|
479
|
-
return { bounds: expression.bounds, body: expression.body, scope };
|
|
480
|
-
}
|
|
481
|
-
if (expression.kind !== "Identifier") return undefined;
|
|
482
|
-
const binding = lookupScope(scope, expression.name);
|
|
483
|
-
if (binding?.kind === "Thunk") {
|
|
484
|
-
return getFunctionAction(binding.expression, binding.scope, partial, run);
|
|
485
|
-
}
|
|
486
|
-
const definition = binding ? undefined : getDefinition(expression.name, run.environment);
|
|
487
|
-
if (definition?.kind !== "Function") return undefined;
|
|
488
|
-
const self = evaluate(expression, getContext(run, undefined, partial));
|
|
489
|
-
return {
|
|
490
|
-
bounds: definition.bounds,
|
|
491
|
-
body: definition.body,
|
|
492
|
-
scope: bindValue(undefined, definition.name, self),
|
|
493
|
-
};
|
|
494
|
-
};
|
|
495
|
-
|
|
499
|
+
// Tool.getInitStates and Tool.getNextStates walk the body of a function they apply that is still
|
|
500
|
+
// lazy, which they evaluate as TLC computes the initial states eagerly, and otherwise apply it.
|
|
496
501
|
const compileFunctionAction = (
|
|
497
502
|
expression: Expression & { kind: "FunctionApplication" },
|
|
498
503
|
environment: Environment,
|
|
499
504
|
isInit: boolean,
|
|
500
505
|
): Runner => {
|
|
501
|
-
const
|
|
506
|
+
const node = describeRange(expression);
|
|
502
507
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
503
|
-
const
|
|
504
|
-
|
|
505
|
-
|
|
508
|
+
const context = getContext(run, scope, partial);
|
|
509
|
+
const value = evaluate(expression.function, isInit ? context : toKeepLazyContext(context));
|
|
510
|
+
const lambda = getLazyFunction(value);
|
|
511
|
+
if (lambda !== undefined) {
|
|
512
|
+
getRunner(lambda.body, environment, isInit)(
|
|
513
|
+
run,
|
|
514
|
+
bindLazyArguments(lambda, expression, context),
|
|
515
|
+
partial,
|
|
516
|
+
action,
|
|
517
|
+
isFixed,
|
|
518
|
+
onComplete,
|
|
519
|
+
);
|
|
506
520
|
return;
|
|
507
521
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
if (!isElementOf(argument, domain)) {
|
|
513
|
-
throw new TlaEvaluationError(
|
|
514
|
-
`Attempted to apply a function to ${formatValue(argument)}, which is not in its domain at ${describeLocation(expression)}`,
|
|
522
|
+
if (!isFunctionValue(value)) {
|
|
523
|
+
throw createRunError(
|
|
524
|
+
run,
|
|
525
|
+
`In computing ${getComputation(run)}, a non-function (${getKindString(value)}) was applied as a function.\n${node}`,
|
|
515
526
|
);
|
|
516
527
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
);
|
|
528
|
+
const result = evaluate(expression, context);
|
|
529
|
+
if (typeof result !== "boolean") {
|
|
530
|
+
throw createRunError(
|
|
531
|
+
run,
|
|
532
|
+
`In computing ${getComputation(run)}, TLC expected a boolean expression,\nbut didn't find one.\n${node}`,
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
if (result) onComplete(partial, action);
|
|
525
536
|
};
|
|
526
537
|
};
|
|
527
538
|
|
|
@@ -545,7 +556,7 @@ const compileUnchanged = (expression: Expression, environment: Environment): Run
|
|
|
545
556
|
);
|
|
546
557
|
return;
|
|
547
558
|
}
|
|
548
|
-
if (holds(unchanged, getContext(run, scope, partial))) onComplete(partial, action);
|
|
559
|
+
if (holds(run, unchanged, getContext(run, scope, partial))) onComplete(partial, action);
|
|
549
560
|
};
|
|
550
561
|
};
|
|
551
562
|
|
|
@@ -740,9 +751,10 @@ const compileAction = (
|
|
|
740
751
|
if (expression.bounds.length === 1 && bound.pattern.kind === "Name") {
|
|
741
752
|
const name = bound.pattern.name;
|
|
742
753
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
743
|
-
const elements =
|
|
754
|
+
const elements = getContextElements(
|
|
744
755
|
evaluate(bound.set, getContext(run, scope, partial)),
|
|
745
756
|
bound.set,
|
|
757
|
+
environment.runtime.version,
|
|
746
758
|
);
|
|
747
759
|
for (let index = 0; index < elements.length && !run.isStopped; index++) {
|
|
748
760
|
body(
|
|
@@ -762,7 +774,11 @@ const compileAction = (
|
|
|
762
774
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
763
775
|
const context = getContext(run, scope, partial);
|
|
764
776
|
const sets = expression.bounds.map((innerBound) =>
|
|
765
|
-
|
|
777
|
+
getContextElements(
|
|
778
|
+
evaluate(innerBound.set, context),
|
|
779
|
+
innerBound.set,
|
|
780
|
+
environment.runtime.version,
|
|
781
|
+
),
|
|
766
782
|
);
|
|
767
783
|
if (sets.some((elements) => elements.length === 0)) return;
|
|
768
784
|
const visit = (index: number, boundScope: Scope | undefined): void => {
|
|
@@ -775,7 +791,7 @@ const compileAction = (
|
|
|
775
791
|
const elementScope = bindValue(boundScope, hoisted.names[index], element);
|
|
776
792
|
if (index === sets.length - 1) {
|
|
777
793
|
const guardContext = getContext(run, elementScope, partial);
|
|
778
|
-
if (!hoisted.guards.every((guard) => holds(guard, guardContext))) continue;
|
|
794
|
+
if (!hoisted.guards.every((guard) => holds(run, guard, guardContext))) continue;
|
|
779
795
|
}
|
|
780
796
|
visit(index - 1, elementScope);
|
|
781
797
|
}
|
|
@@ -810,7 +826,7 @@ const compileAction = (
|
|
|
810
826
|
);
|
|
811
827
|
if (isBoundToValues) {
|
|
812
828
|
const isSatisfied = scopes.every((boundScope) =>
|
|
813
|
-
holds(expression.body, getContext(run, boundScope, partial)),
|
|
829
|
+
holds(run, expression.body, getContext(run, boundScope, partial)),
|
|
814
830
|
);
|
|
815
831
|
if (isSatisfied) onComplete(partial, action);
|
|
816
832
|
return;
|
|
@@ -824,7 +840,7 @@ const compileAction = (
|
|
|
824
840
|
const isSatisfied = scopes
|
|
825
841
|
.slice(index)
|
|
826
842
|
.every((boundScope) =>
|
|
827
|
-
|
|
843
|
+
holds(run, expression.body, getContext(run, boundScope, nextPartial)),
|
|
828
844
|
);
|
|
829
845
|
if (isSatisfied) onComplete(nextPartial, nextAction);
|
|
830
846
|
return;
|
|
@@ -841,26 +857,38 @@ const compileAction = (
|
|
|
841
857
|
const alternative = child(expression.alternative);
|
|
842
858
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
843
859
|
const condition = evaluate(expression.condition, getContext(run, scope, partial));
|
|
844
|
-
|
|
860
|
+
if (typeof condition !== "boolean") {
|
|
861
|
+
throw createRunError(run, getIfConditionMessage(run, condition, expression));
|
|
862
|
+
}
|
|
863
|
+
const branch = condition ? consequent : alternative;
|
|
845
864
|
branch(run, scope, partial, action, isFixed, onComplete);
|
|
846
865
|
};
|
|
847
866
|
}
|
|
848
867
|
case "Case": {
|
|
849
868
|
const arms = expression.arms.map((arm) => ({
|
|
850
869
|
condition: arm.condition,
|
|
870
|
+
source: arm.body,
|
|
851
871
|
body: child(arm.body),
|
|
852
872
|
}));
|
|
853
873
|
const other = expression.other ? child(expression.other) : undefined;
|
|
854
874
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
855
875
|
const context = getContext(run, scope, partial);
|
|
856
|
-
const arm = arms.find((candidate) =>
|
|
857
|
-
|
|
858
|
-
|
|
876
|
+
const arm = arms.find((candidate) => {
|
|
877
|
+
const value = evaluate(candidate.condition, context);
|
|
878
|
+
if (typeof value === "boolean") return value;
|
|
879
|
+
// TLC leaves out the space before the kind under ENABLED.
|
|
880
|
+
throw createRunError(
|
|
881
|
+
run,
|
|
882
|
+
`In computing ${getComputation(run)}, a non-boolean expression${run.isEnabled ? "" : " "}(${getKindString(value)}) was used as a guard condition of a CASE.\n${describeNode(candidate.source)}`,
|
|
883
|
+
);
|
|
884
|
+
});
|
|
859
885
|
const body = arm?.body ?? other;
|
|
860
|
-
if (!body)
|
|
861
|
-
throw
|
|
862
|
-
|
|
886
|
+
if (!body) {
|
|
887
|
+
throw createRunError(
|
|
888
|
+
run,
|
|
889
|
+
`In computing ${getComputation(run)}, TLC encountered a CASE with no conditions true.\n${describeRange(expression)}`,
|
|
863
890
|
);
|
|
891
|
+
}
|
|
864
892
|
body(run, scope, partial, action, isFixed, onComplete);
|
|
865
893
|
};
|
|
866
894
|
}
|
|
@@ -889,10 +917,18 @@ const compileAction = (
|
|
|
889
917
|
case "AngleAction": {
|
|
890
918
|
const body = child(expression.action);
|
|
891
919
|
const unchanged = getUnchangedWrapper(expression.subscript);
|
|
920
|
+
const isUnchanged = (run: Run, scope: Scope | undefined, nextPartial: State) => {
|
|
921
|
+
try {
|
|
922
|
+
return holds(run, unchanged, getContext(run, scope, nextPartial));
|
|
923
|
+
} catch (error) {
|
|
924
|
+
throw run.isEnabled
|
|
925
|
+
? toUnspecifiedSubscriptError(error, environment.runtime.version)
|
|
926
|
+
: error;
|
|
927
|
+
}
|
|
928
|
+
};
|
|
892
929
|
return (run, scope, partial, action, isFixed, onComplete) =>
|
|
893
930
|
body(run, scope, partial, action, isFixed, (nextPartial, nextAction) => {
|
|
894
|
-
if (!
|
|
895
|
-
onComplete(nextPartial, nextAction);
|
|
931
|
+
if (!isUnchanged(run, scope, nextPartial)) onComplete(nextPartial, nextAction);
|
|
896
932
|
});
|
|
897
933
|
}
|
|
898
934
|
case "BoxAction":
|
|
@@ -969,7 +1005,15 @@ export const isEnabled = (expression: Expression, context: Context): boolean =>
|
|
|
969
1005
|
);
|
|
970
1006
|
}
|
|
971
1007
|
const environment = context.environment;
|
|
972
|
-
|
|
1008
|
+
// TLC computes ENABLED again with its call stack recorded as it computes successors.
|
|
1009
|
+
if (environment.callStack) return replayEnabled(expression, context.scope, state, environment);
|
|
1010
|
+
const run: Run = {
|
|
1011
|
+
environment,
|
|
1012
|
+
isInit: false,
|
|
1013
|
+
isEnabled: true,
|
|
1014
|
+
current: state,
|
|
1015
|
+
isStopped: false,
|
|
1016
|
+
};
|
|
973
1017
|
// TLC stops computing ENABLED at the first successor, so it skips the rest of the action.
|
|
974
1018
|
getRunner(expression, environment, false)(
|
|
975
1019
|
run,
|
|
@@ -990,7 +1034,13 @@ export const forEachInitialState = (
|
|
|
990
1034
|
onState: (state: Value[]) => boolean,
|
|
991
1035
|
scope?: Scope,
|
|
992
1036
|
) => {
|
|
993
|
-
const run: Run = {
|
|
1037
|
+
const run: Run = {
|
|
1038
|
+
environment,
|
|
1039
|
+
isInit: true,
|
|
1040
|
+
isEnabled: false,
|
|
1041
|
+
current: undefined,
|
|
1042
|
+
isStopped: false,
|
|
1043
|
+
};
|
|
994
1044
|
getRunner(expression, environment, true)(
|
|
995
1045
|
run,
|
|
996
1046
|
scope,
|
|
@@ -1002,12 +1052,7 @@ export const forEachInitialState = (
|
|
|
1002
1052
|
if (!isComplete(partial)) {
|
|
1003
1053
|
// TLC reports an initial state that isn't completely specified as an illegal state, not as
|
|
1004
1054
|
// an evaluation failure.
|
|
1005
|
-
throw setExitCode(
|
|
1006
|
-
new TlaEvaluationError(
|
|
1007
|
-
`The initial predicate does not assign ${getMissingVariables(partial, environment).join(", ")}`,
|
|
1008
|
-
),
|
|
1009
|
-
EXIT_STATUS.error,
|
|
1010
|
-
);
|
|
1055
|
+
throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
|
|
1011
1056
|
}
|
|
1012
1057
|
run.isStopped = onState(partial);
|
|
1013
1058
|
},
|
|
@@ -1039,7 +1084,13 @@ export const forEachSuccessor = (
|
|
|
1039
1084
|
onSuccessor: (successor: Successor) => boolean,
|
|
1040
1085
|
scope?: Scope,
|
|
1041
1086
|
) => {
|
|
1042
|
-
const run: Run = {
|
|
1087
|
+
const run: Run = {
|
|
1088
|
+
environment,
|
|
1089
|
+
isInit: false,
|
|
1090
|
+
isEnabled: false,
|
|
1091
|
+
current: state,
|
|
1092
|
+
isStopped: false,
|
|
1093
|
+
};
|
|
1043
1094
|
const counter = { successors: 0 };
|
|
1044
1095
|
getRunner(expression, environment, false)(
|
|
1045
1096
|
run,
|
|
@@ -1050,8 +1101,12 @@ export const forEachSuccessor = (
|
|
|
1050
1101
|
(partial, action) => {
|
|
1051
1102
|
if (run.isStopped) return;
|
|
1052
1103
|
if (!isComplete(partial)) {
|
|
1053
|
-
|
|
1054
|
-
|
|
1104
|
+
const missing = getMissingVariables(partial, environment);
|
|
1105
|
+
throw new TlaIncompleteSuccessorError(
|
|
1106
|
+
`Successor state is not completely specified by action ${action ?? "Next"}. The following variables are not assigned: ${missing.join(", ")}`,
|
|
1107
|
+
partial,
|
|
1108
|
+
action,
|
|
1109
|
+
missing,
|
|
1055
1110
|
);
|
|
1056
1111
|
}
|
|
1057
1112
|
counter.successors++;
|