tla-ts 0.0.3-dev.037ac3b → 0.0.3-dev.0ad0249
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 +146 -8
- package/dist/index.d.ts +146 -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 +4 -1
- package/src/ast.ts +48 -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 +1330 -215
- 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 +724 -117
- 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 +14 -1
- package/src/live-check.ts +220 -84
- 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 +423 -126
- 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 +1363 -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 +162 -114
- package/src/symmetry.ts +180 -52
- package/src/tableau.ts +4 -2
- 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 +28 -3
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-version.ts +18 -0
- package/src/transfer.ts +15 -3
- package/src/value-sources.ts +29 -0
- package/src/values.ts +684 -204
package/src/successors.ts
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
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,
|
|
19
20
|
compileArgumentScope,
|
|
20
21
|
evaluate,
|
|
21
|
-
getEntryEvaluator,
|
|
22
22
|
expectBoolean,
|
|
23
23
|
forEachBinding,
|
|
24
|
-
|
|
24
|
+
getLazyFunction,
|
|
25
|
+
toKeepLazyContext,
|
|
25
26
|
getDefinition,
|
|
26
|
-
|
|
27
|
+
getContextElements,
|
|
27
28
|
getReevaluatedDefinitions,
|
|
28
29
|
lookupScope,
|
|
29
30
|
resolveApplyOperator,
|
|
30
31
|
resolveGlobalOperator,
|
|
32
|
+
toUnspecifiedSubscriptError,
|
|
31
33
|
type Context,
|
|
32
34
|
type Environment,
|
|
33
|
-
type Evaluator,
|
|
34
35
|
type Scope,
|
|
35
36
|
type State,
|
|
36
37
|
} from "./evaluate";
|
|
37
38
|
import { mapChildren } from "./instances";
|
|
39
|
+
import { isAssignedShortcut, LITERAL_KINDS, replayEnabled } from "./tlc-replay";
|
|
38
40
|
import {
|
|
39
|
-
createTuple,
|
|
40
41
|
formatValue,
|
|
41
42
|
getStreamedElements,
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
isFunctionValue,
|
|
44
|
+
isTlcEnumerable,
|
|
44
45
|
valuesEqual,
|
|
45
46
|
type Value,
|
|
46
47
|
} from "./values";
|
|
@@ -53,6 +54,8 @@ export interface Successor {
|
|
|
53
54
|
interface Run {
|
|
54
55
|
environment: Environment;
|
|
55
56
|
isInit: boolean;
|
|
57
|
+
// Whether the run computes ENABLED rather than the successors of the state.
|
|
58
|
+
isEnabled: boolean;
|
|
56
59
|
current: Value[] | undefined;
|
|
57
60
|
isStopped: boolean;
|
|
58
61
|
}
|
|
@@ -89,14 +92,47 @@ const assign = (partial: State, index: number, value: Value) => {
|
|
|
89
92
|
return copy;
|
|
90
93
|
};
|
|
91
94
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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}`;
|
|
99
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) => {
|
|
133
|
+
const value = evaluate(expression, context);
|
|
134
|
+
if (typeof value === "boolean") return value;
|
|
135
|
+
throw createRunError(run, getNonBooleanMessage(run, value, expression, isWalked));
|
|
100
136
|
};
|
|
101
137
|
|
|
102
138
|
const isAssignmentOperator = (operator: string) =>
|
|
@@ -321,7 +357,6 @@ const compileConjunction = (
|
|
|
321
357
|
isInit: boolean,
|
|
322
358
|
): Runner => {
|
|
323
359
|
const conjuncts = operands.map((operand) => toConjunct(operand, environment, isInit));
|
|
324
|
-
const evaluators: (Evaluator | undefined)[] = conjuncts.map(() => undefined);
|
|
325
360
|
const runFrom = (
|
|
326
361
|
start: number,
|
|
327
362
|
run: Run,
|
|
@@ -332,11 +367,12 @@ const compileConjunction = (
|
|
|
332
367
|
): void => {
|
|
333
368
|
let current = partial;
|
|
334
369
|
let context: Context | undefined;
|
|
370
|
+
const isShortcut = isAssignedShortcut(run);
|
|
335
371
|
for (let index = start; index < conjuncts.length; index++) {
|
|
336
|
-
if (index > 0 &&
|
|
372
|
+
if (index > 0 && isShortcut && isComplete(current)) {
|
|
337
373
|
context ??= getContext(run, scope, current);
|
|
338
374
|
for (let rest = index; rest < conjuncts.length; rest++) {
|
|
339
|
-
if (!
|
|
375
|
+
if (!holds(run, conjuncts[rest].expression, context, false)) return;
|
|
340
376
|
}
|
|
341
377
|
onComplete(current, action);
|
|
342
378
|
return;
|
|
@@ -344,17 +380,12 @@ const compileConjunction = (
|
|
|
344
380
|
const conjunct = conjuncts[index];
|
|
345
381
|
if (conjunct.kind === "Guard") {
|
|
346
382
|
context ??= getContext(run, scope, current);
|
|
347
|
-
|
|
348
|
-
conjunct.expression,
|
|
349
|
-
environment,
|
|
350
|
-
));
|
|
351
|
-
if (!holds(conjunct.expression, context, evaluator(context))) return;
|
|
383
|
+
if (!holds(run, conjunct.expression, context)) return;
|
|
352
384
|
continue;
|
|
353
385
|
}
|
|
354
386
|
if (conjunct.kind === "Assign") {
|
|
355
387
|
context ??= getContext(run, scope, current);
|
|
356
|
-
const
|
|
357
|
-
const value = evaluator(context);
|
|
388
|
+
const value = evaluate(conjunct.value, context);
|
|
358
389
|
const assigned = current[conjunct.index];
|
|
359
390
|
if (assigned === undefined) {
|
|
360
391
|
current = assign(current, conjunct.index, value);
|
|
@@ -390,16 +421,10 @@ const compileConjunction = (
|
|
|
390
421
|
runFrom(0, run, scope, partial, action, onComplete);
|
|
391
422
|
};
|
|
392
423
|
|
|
393
|
-
const holdsInInit = (expression: Expression, context: Context) =>
|
|
394
|
-
expectBoolean(
|
|
395
|
-
evaluate(expression, context),
|
|
396
|
-
`the initial predicate at ${describeLocation(expression)}`,
|
|
397
|
-
);
|
|
398
|
-
|
|
399
424
|
const compileGuard =
|
|
400
425
|
(expression: Expression): Runner =>
|
|
401
426
|
(run, scope, partial, action, _isFixed, onComplete) => {
|
|
402
|
-
if (holds(expression, getContext(run, scope, partial))) onComplete(partial, action);
|
|
427
|
+
if (holds(run, expression, getContext(run, scope, partial))) onComplete(partial, action);
|
|
403
428
|
};
|
|
404
429
|
|
|
405
430
|
const compileMembership = (
|
|
@@ -411,16 +436,17 @@ const compileMembership = (
|
|
|
411
436
|
const index = getIndex(run, scope, partial);
|
|
412
437
|
const context = getContext(run, scope, partial);
|
|
413
438
|
if (partial[index] !== undefined) {
|
|
414
|
-
if (holds(expression, context)) onComplete(partial, action);
|
|
439
|
+
if (holds(run, expression, context)) onComplete(partial, action);
|
|
415
440
|
return;
|
|
416
441
|
}
|
|
417
442
|
const evaluated = evaluate(set, context);
|
|
418
443
|
const value: Value =
|
|
419
444
|
expression.operator === "\\subseteq" ? { kind: "Subset", base: evaluated } : evaluated;
|
|
420
|
-
if (!
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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)}`);
|
|
424
450
|
}
|
|
425
451
|
const elements = getStreamedElements(value);
|
|
426
452
|
for (let position = 0; position < elements.length && !run.isStopped; position++) {
|
|
@@ -470,65 +496,43 @@ const compileDynamicAssignment = (
|
|
|
470
496
|
};
|
|
471
497
|
};
|
|
472
498
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
body: Expression;
|
|
476
|
-
scope: Scope | undefined;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
const getFunctionAction = (
|
|
480
|
-
expression: Expression,
|
|
481
|
-
scope: Scope | undefined,
|
|
482
|
-
partial: State,
|
|
483
|
-
run: Run,
|
|
484
|
-
): FunctionAction | undefined => {
|
|
485
|
-
if (expression.kind === "FunctionConstruction") {
|
|
486
|
-
return { bounds: expression.bounds, body: expression.body, scope };
|
|
487
|
-
}
|
|
488
|
-
if (expression.kind !== "Identifier") return undefined;
|
|
489
|
-
const binding = lookupScope(scope, expression.name);
|
|
490
|
-
if (binding?.kind === "Thunk") {
|
|
491
|
-
return getFunctionAction(binding.expression, binding.scope, partial, run);
|
|
492
|
-
}
|
|
493
|
-
const definition = binding ? undefined : getDefinition(expression.name, run.environment);
|
|
494
|
-
if (definition?.kind !== "Function") return undefined;
|
|
495
|
-
const self = evaluate(expression, getContext(run, undefined, partial));
|
|
496
|
-
return {
|
|
497
|
-
bounds: definition.bounds,
|
|
498
|
-
body: definition.body,
|
|
499
|
-
scope: bindValue(undefined, definition.name, self),
|
|
500
|
-
};
|
|
501
|
-
};
|
|
502
|
-
|
|
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.
|
|
503
501
|
const compileFunctionAction = (
|
|
504
502
|
expression: Expression & { kind: "FunctionApplication" },
|
|
505
503
|
environment: Environment,
|
|
506
504
|
isInit: boolean,
|
|
507
505
|
): Runner => {
|
|
508
|
-
const
|
|
506
|
+
const node = describeRange(expression);
|
|
509
507
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
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
|
+
);
|
|
513
520
|
return;
|
|
514
521
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
if (!isElementOf(argument, domain)) {
|
|
520
|
-
throw new TlaEvaluationError(
|
|
521
|
-
`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}`,
|
|
522
526
|
);
|
|
523
527
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
);
|
|
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);
|
|
532
536
|
};
|
|
533
537
|
};
|
|
534
538
|
|
|
@@ -552,7 +556,7 @@ const compileUnchanged = (expression: Expression, environment: Environment): Run
|
|
|
552
556
|
);
|
|
553
557
|
return;
|
|
554
558
|
}
|
|
555
|
-
if (holds(unchanged, getContext(run, scope, partial))) onComplete(partial, action);
|
|
559
|
+
if (holds(run, unchanged, getContext(run, scope, partial))) onComplete(partial, action);
|
|
556
560
|
};
|
|
557
561
|
};
|
|
558
562
|
|
|
@@ -747,9 +751,10 @@ const compileAction = (
|
|
|
747
751
|
if (expression.bounds.length === 1 && bound.pattern.kind === "Name") {
|
|
748
752
|
const name = bound.pattern.name;
|
|
749
753
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
750
|
-
const elements =
|
|
754
|
+
const elements = getContextElements(
|
|
751
755
|
evaluate(bound.set, getContext(run, scope, partial)),
|
|
752
756
|
bound.set,
|
|
757
|
+
environment.runtime.version,
|
|
753
758
|
);
|
|
754
759
|
for (let index = 0; index < elements.length && !run.isStopped; index++) {
|
|
755
760
|
body(
|
|
@@ -769,7 +774,11 @@ const compileAction = (
|
|
|
769
774
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
770
775
|
const context = getContext(run, scope, partial);
|
|
771
776
|
const sets = expression.bounds.map((innerBound) =>
|
|
772
|
-
|
|
777
|
+
getContextElements(
|
|
778
|
+
evaluate(innerBound.set, context),
|
|
779
|
+
innerBound.set,
|
|
780
|
+
environment.runtime.version,
|
|
781
|
+
),
|
|
773
782
|
);
|
|
774
783
|
if (sets.some((elements) => elements.length === 0)) return;
|
|
775
784
|
const visit = (index: number, boundScope: Scope | undefined): void => {
|
|
@@ -782,7 +791,7 @@ const compileAction = (
|
|
|
782
791
|
const elementScope = bindValue(boundScope, hoisted.names[index], element);
|
|
783
792
|
if (index === sets.length - 1) {
|
|
784
793
|
const guardContext = getContext(run, elementScope, partial);
|
|
785
|
-
if (!hoisted.guards.every((guard) => holds(guard, guardContext))) continue;
|
|
794
|
+
if (!hoisted.guards.every((guard) => holds(run, guard, guardContext))) continue;
|
|
786
795
|
}
|
|
787
796
|
visit(index - 1, elementScope);
|
|
788
797
|
}
|
|
@@ -817,7 +826,7 @@ const compileAction = (
|
|
|
817
826
|
);
|
|
818
827
|
if (isBoundToValues) {
|
|
819
828
|
const isSatisfied = scopes.every((boundScope) =>
|
|
820
|
-
holds(expression.body, getContext(run, boundScope, partial)),
|
|
829
|
+
holds(run, expression.body, getContext(run, boundScope, partial)),
|
|
821
830
|
);
|
|
822
831
|
if (isSatisfied) onComplete(partial, action);
|
|
823
832
|
return;
|
|
@@ -831,7 +840,7 @@ const compileAction = (
|
|
|
831
840
|
const isSatisfied = scopes
|
|
832
841
|
.slice(index)
|
|
833
842
|
.every((boundScope) =>
|
|
834
|
-
|
|
843
|
+
holds(run, expression.body, getContext(run, boundScope, nextPartial)),
|
|
835
844
|
);
|
|
836
845
|
if (isSatisfied) onComplete(nextPartial, nextAction);
|
|
837
846
|
return;
|
|
@@ -848,26 +857,38 @@ const compileAction = (
|
|
|
848
857
|
const alternative = child(expression.alternative);
|
|
849
858
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
850
859
|
const condition = evaluate(expression.condition, getContext(run, scope, partial));
|
|
851
|
-
|
|
860
|
+
if (typeof condition !== "boolean") {
|
|
861
|
+
throw createRunError(run, getIfConditionMessage(run, condition, expression));
|
|
862
|
+
}
|
|
863
|
+
const branch = condition ? consequent : alternative;
|
|
852
864
|
branch(run, scope, partial, action, isFixed, onComplete);
|
|
853
865
|
};
|
|
854
866
|
}
|
|
855
867
|
case "Case": {
|
|
856
868
|
const arms = expression.arms.map((arm) => ({
|
|
857
869
|
condition: arm.condition,
|
|
870
|
+
source: arm.body,
|
|
858
871
|
body: child(arm.body),
|
|
859
872
|
}));
|
|
860
873
|
const other = expression.other ? child(expression.other) : undefined;
|
|
861
874
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
862
875
|
const context = getContext(run, scope, partial);
|
|
863
|
-
const arm = arms.find((candidate) =>
|
|
864
|
-
|
|
865
|
-
|
|
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
|
+
});
|
|
866
885
|
const body = arm?.body ?? other;
|
|
867
|
-
if (!body)
|
|
868
|
-
throw
|
|
869
|
-
|
|
886
|
+
if (!body) {
|
|
887
|
+
throw createRunError(
|
|
888
|
+
run,
|
|
889
|
+
`In computing ${getComputation(run)}, TLC encountered a CASE with no conditions true.\n${describeRange(expression)}`,
|
|
870
890
|
);
|
|
891
|
+
}
|
|
871
892
|
body(run, scope, partial, action, isFixed, onComplete);
|
|
872
893
|
};
|
|
873
894
|
}
|
|
@@ -896,10 +917,18 @@ const compileAction = (
|
|
|
896
917
|
case "AngleAction": {
|
|
897
918
|
const body = child(expression.action);
|
|
898
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
|
+
};
|
|
899
929
|
return (run, scope, partial, action, isFixed, onComplete) =>
|
|
900
930
|
body(run, scope, partial, action, isFixed, (nextPartial, nextAction) => {
|
|
901
|
-
if (!
|
|
902
|
-
onComplete(nextPartial, nextAction);
|
|
931
|
+
if (!isUnchanged(run, scope, nextPartial)) onComplete(nextPartial, nextAction);
|
|
903
932
|
});
|
|
904
933
|
}
|
|
905
934
|
case "BoxAction":
|
|
@@ -976,7 +1005,15 @@ export const isEnabled = (expression: Expression, context: Context): boolean =>
|
|
|
976
1005
|
);
|
|
977
1006
|
}
|
|
978
1007
|
const environment = context.environment;
|
|
979
|
-
|
|
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
|
+
};
|
|
980
1017
|
// TLC stops computing ENABLED at the first successor, so it skips the rest of the action.
|
|
981
1018
|
getRunner(expression, environment, false)(
|
|
982
1019
|
run,
|
|
@@ -997,7 +1034,13 @@ export const forEachInitialState = (
|
|
|
997
1034
|
onState: (state: Value[]) => boolean,
|
|
998
1035
|
scope?: Scope,
|
|
999
1036
|
) => {
|
|
1000
|
-
const run: Run = {
|
|
1037
|
+
const run: Run = {
|
|
1038
|
+
environment,
|
|
1039
|
+
isInit: true,
|
|
1040
|
+
isEnabled: false,
|
|
1041
|
+
current: undefined,
|
|
1042
|
+
isStopped: false,
|
|
1043
|
+
};
|
|
1001
1044
|
getRunner(expression, environment, true)(
|
|
1002
1045
|
run,
|
|
1003
1046
|
scope,
|
|
@@ -1009,12 +1052,7 @@ export const forEachInitialState = (
|
|
|
1009
1052
|
if (!isComplete(partial)) {
|
|
1010
1053
|
// TLC reports an initial state that isn't completely specified as an illegal state, not as
|
|
1011
1054
|
// an evaluation failure.
|
|
1012
|
-
throw setExitCode(
|
|
1013
|
-
new TlaEvaluationError(
|
|
1014
|
-
`The initial predicate does not assign ${getMissingVariables(partial, environment).join(", ")}`,
|
|
1015
|
-
),
|
|
1016
|
-
EXIT_STATUS.error,
|
|
1017
|
-
);
|
|
1055
|
+
throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
|
|
1018
1056
|
}
|
|
1019
1057
|
run.isStopped = onState(partial);
|
|
1020
1058
|
},
|
|
@@ -1046,7 +1084,13 @@ export const forEachSuccessor = (
|
|
|
1046
1084
|
onSuccessor: (successor: Successor) => boolean,
|
|
1047
1085
|
scope?: Scope,
|
|
1048
1086
|
) => {
|
|
1049
|
-
const run: Run = {
|
|
1087
|
+
const run: Run = {
|
|
1088
|
+
environment,
|
|
1089
|
+
isInit: false,
|
|
1090
|
+
isEnabled: false,
|
|
1091
|
+
current: state,
|
|
1092
|
+
isStopped: false,
|
|
1093
|
+
};
|
|
1050
1094
|
const counter = { successors: 0 };
|
|
1051
1095
|
getRunner(expression, environment, false)(
|
|
1052
1096
|
run,
|
|
@@ -1057,8 +1101,12 @@ export const forEachSuccessor = (
|
|
|
1057
1101
|
(partial, action) => {
|
|
1058
1102
|
if (run.isStopped) return;
|
|
1059
1103
|
if (!isComplete(partial)) {
|
|
1060
|
-
|
|
1061
|
-
|
|
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,
|
|
1062
1110
|
);
|
|
1063
1111
|
}
|
|
1064
1112
|
counter.successors++;
|