tla-ts 0.0.3-dev.4cf9a33 → 0.0.3-dev.4fdd845
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 +164 -40
- package/dist/index.d.ts +164 -40
- 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 -22
- package/dist/run-cli.js +1351 -22
- package/dist/transfer.cjs +83 -34
- package/dist/transfer.js +83 -34
- package/package.json +5 -1
- package/src/ast.ts +49 -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 +1331 -367
- package/src/cli.ts +8 -1
- package/src/codegen.ts +68 -21
- package/src/config.ts +225 -206
- package/src/environment.ts +417 -124
- package/src/errors.ts +168 -9
- package/src/evaluate.ts +720 -177
- package/src/exit-codes.ts +6 -24
- package/src/index.ts +1 -0
- package/src/instances.ts +3 -1
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +149 -31
- package/src/lexer.ts +32 -4
- package/src/live-check.ts +204 -148
- package/src/liveness.ts +191 -122
- package/src/obligation-expression.ts +2 -2
- package/src/obligation-source.ts +2 -0
- package/src/parallel-worker.ts +6 -1
- package/src/parallel.ts +57 -6
- package/src/parser.ts +419 -122
- 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 +1334 -452
- package/src/run-cli.ts +1166 -181
- 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 +25 -5
- 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 +161 -167
- package/src/symmetry.ts +168 -50
- package/src/tableau.ts +3 -1
- package/src/tlc-ext.ts +13 -17
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +49 -21
- package/src/tlc-modules.ts +0 -4
- package/src/tlc-order.ts +55 -9
- 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 +683 -256
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,54 +92,57 @@ const assign = (partial: State, index: number, value: Value) => {
|
|
|
89
92
|
return copy;
|
|
90
93
|
};
|
|
91
94
|
|
|
92
|
-
// TLC
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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);
|
|
98
103
|
};
|
|
99
104
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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}`;
|
|
109
118
|
}
|
|
110
|
-
return
|
|
119
|
+
return `In computing ${getComputation(run)}, TLC expected a boolean expression,\nbut instead found ${formatValue(value)}.\n${node}`;
|
|
111
120
|
};
|
|
112
121
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const
|
|
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
|
+
};
|
|
117
131
|
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return runners[isInit ? 0 : 1];
|
|
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));
|
|
123
136
|
};
|
|
124
137
|
|
|
138
|
+
const isAssignmentOperator = (operator: string) =>
|
|
139
|
+
operator === "=" || operator === "\\in" || operator === "\\subseteq";
|
|
140
|
+
|
|
125
141
|
const getRunner = (expression: Expression, environment: Environment, isInit: boolean): Runner => {
|
|
126
|
-
const runners =
|
|
142
|
+
const runners = isInit ? initRunners : nextRunners;
|
|
127
143
|
const cached = runners.get(expression);
|
|
128
144
|
if (cached) return cached;
|
|
129
|
-
const
|
|
130
|
-
const trace = environment.trace;
|
|
131
|
-
// TLC's CallStackTool keeps an action's expression on the stack while the rest of the action runs.
|
|
132
|
-
const runner: Runner = trace
|
|
133
|
-
? (run, scope, partial, action, isFixed, onComplete) => {
|
|
134
|
-
const depth = trace.length;
|
|
135
|
-
trace.push(expression);
|
|
136
|
-
compiled(run, scope, partial, action, isFixed, onComplete);
|
|
137
|
-
trace.length = depth;
|
|
138
|
-
}
|
|
139
|
-
: compiled;
|
|
145
|
+
const runner = compileAction(expression, environment, isInit);
|
|
140
146
|
runners.set(expression, runner);
|
|
141
147
|
return runner;
|
|
142
148
|
};
|
|
@@ -220,23 +226,6 @@ const getUnchangedIndices = (
|
|
|
220
226
|
return getUnchangedIndices(definition.body, environment, visited);
|
|
221
227
|
};
|
|
222
228
|
|
|
223
|
-
// TLC's CallStackTool keeps each expression that UNCHANGED takes apart on the stack.
|
|
224
|
-
const getUnchangedFrames = (expression: Expression, environment: Environment): Expression[] => {
|
|
225
|
-
if (expression.kind === "Tuple") {
|
|
226
|
-
return [
|
|
227
|
-
expression,
|
|
228
|
-
...expression.elements.flatMap((element) => getUnchangedFrames(element, environment)),
|
|
229
|
-
];
|
|
230
|
-
}
|
|
231
|
-
const definition =
|
|
232
|
-
expression.kind === "Identifier" && !environment.variableIndex.has(expression.name)
|
|
233
|
-
? getZeroArityBody(expression.name, environment)
|
|
234
|
-
: undefined;
|
|
235
|
-
return definition
|
|
236
|
-
? [expression, ...getUnchangedFrames(definition.body, environment)]
|
|
237
|
-
: [expression];
|
|
238
|
-
};
|
|
239
|
-
|
|
240
229
|
const ACTION_KINDS = new Set([
|
|
241
230
|
"Label",
|
|
242
231
|
"And",
|
|
@@ -368,8 +357,6 @@ const compileConjunction = (
|
|
|
368
357
|
isInit: boolean,
|
|
369
358
|
): Runner => {
|
|
370
359
|
const conjuncts = operands.map((operand) => toConjunct(operand, environment, isInit));
|
|
371
|
-
const evaluators: (Evaluator | undefined)[] = conjuncts.map(() => undefined);
|
|
372
|
-
const trace = environment.trace;
|
|
373
360
|
const runFrom = (
|
|
374
361
|
start: number,
|
|
375
362
|
run: Run,
|
|
@@ -380,35 +367,25 @@ const compileConjunction = (
|
|
|
380
367
|
): void => {
|
|
381
368
|
let current = partial;
|
|
382
369
|
let context: Context | undefined;
|
|
370
|
+
const isShortcut = isAssignedShortcut(run);
|
|
383
371
|
for (let index = start; index < conjuncts.length; index++) {
|
|
384
|
-
if (index > 0 &&
|
|
372
|
+
if (index > 0 && isShortcut && isComplete(current)) {
|
|
385
373
|
context ??= getContext(run, scope, current);
|
|
386
374
|
for (let rest = index; rest < conjuncts.length; rest++) {
|
|
387
|
-
if (!
|
|
375
|
+
if (!holds(run, conjuncts[rest].expression, context, false)) return;
|
|
388
376
|
}
|
|
389
377
|
onComplete(current, action);
|
|
390
378
|
return;
|
|
391
379
|
}
|
|
392
380
|
const conjunct = conjuncts[index];
|
|
393
|
-
if (trace) {
|
|
394
|
-
trace.push(conjunct.expression);
|
|
395
|
-
if (conjunct.expression.kind === "Unchanged") {
|
|
396
|
-
trace.push(...getUnchangedFrames(conjunct.expression.expression, environment));
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
381
|
if (conjunct.kind === "Guard") {
|
|
400
382
|
context ??= getContext(run, scope, current);
|
|
401
|
-
|
|
402
|
-
conjunct.expression,
|
|
403
|
-
environment,
|
|
404
|
-
));
|
|
405
|
-
if (!holds(conjunct.expression, context, evaluator(context))) return;
|
|
383
|
+
if (!holds(run, conjunct.expression, context)) return;
|
|
406
384
|
continue;
|
|
407
385
|
}
|
|
408
386
|
if (conjunct.kind === "Assign") {
|
|
409
387
|
context ??= getContext(run, scope, current);
|
|
410
|
-
const
|
|
411
|
-
const value = evaluator(context);
|
|
388
|
+
const value = evaluate(conjunct.value, context);
|
|
412
389
|
const assigned = current[conjunct.index];
|
|
413
390
|
if (assigned === undefined) {
|
|
414
391
|
current = assign(current, conjunct.index, value);
|
|
@@ -444,13 +421,10 @@ const compileConjunction = (
|
|
|
444
421
|
runFrom(0, run, scope, partial, action, onComplete);
|
|
445
422
|
};
|
|
446
423
|
|
|
447
|
-
const holdsInInit = (expression: Expression, context: Context) =>
|
|
448
|
-
expectFormula(expression, evaluate(expression, context), true);
|
|
449
|
-
|
|
450
424
|
const compileGuard =
|
|
451
425
|
(expression: Expression): Runner =>
|
|
452
426
|
(run, scope, partial, action, _isFixed, onComplete) => {
|
|
453
|
-
if (holds(expression, getContext(run, scope, partial))) onComplete(partial, action);
|
|
427
|
+
if (holds(run, expression, getContext(run, scope, partial))) onComplete(partial, action);
|
|
454
428
|
};
|
|
455
429
|
|
|
456
430
|
const compileMembership = (
|
|
@@ -462,16 +436,17 @@ const compileMembership = (
|
|
|
462
436
|
const index = getIndex(run, scope, partial);
|
|
463
437
|
const context = getContext(run, scope, partial);
|
|
464
438
|
if (partial[index] !== undefined) {
|
|
465
|
-
if (holds(expression, context)) onComplete(partial, action);
|
|
439
|
+
if (holds(run, expression, context)) onComplete(partial, action);
|
|
466
440
|
return;
|
|
467
441
|
}
|
|
468
442
|
const evaluated = evaluate(set, context);
|
|
469
443
|
const value: Value =
|
|
470
444
|
expression.operator === "\\subseteq" ? { kind: "Subset", base: evaluated } : evaluated;
|
|
471
|
-
if (!
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
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)}`);
|
|
475
450
|
}
|
|
476
451
|
const elements = getStreamedElements(value);
|
|
477
452
|
for (let position = 0; position < elements.length && !run.isStopped; position++) {
|
|
@@ -521,65 +496,43 @@ const compileDynamicAssignment = (
|
|
|
521
496
|
};
|
|
522
497
|
};
|
|
523
498
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
body: Expression;
|
|
527
|
-
scope: Scope | undefined;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
const getFunctionAction = (
|
|
531
|
-
expression: Expression,
|
|
532
|
-
scope: Scope | undefined,
|
|
533
|
-
partial: State,
|
|
534
|
-
run: Run,
|
|
535
|
-
): FunctionAction | undefined => {
|
|
536
|
-
if (expression.kind === "FunctionConstruction") {
|
|
537
|
-
return { bounds: expression.bounds, body: expression.body, scope };
|
|
538
|
-
}
|
|
539
|
-
if (expression.kind !== "Identifier") return undefined;
|
|
540
|
-
const binding = lookupScope(scope, expression.name);
|
|
541
|
-
if (binding?.kind === "Thunk") {
|
|
542
|
-
return getFunctionAction(binding.expression, binding.scope, partial, run);
|
|
543
|
-
}
|
|
544
|
-
const definition = binding ? undefined : getDefinition(expression.name, run.environment);
|
|
545
|
-
if (definition?.kind !== "Function") return undefined;
|
|
546
|
-
const self = evaluate(expression, getContext(run, undefined, partial));
|
|
547
|
-
return {
|
|
548
|
-
bounds: definition.bounds,
|
|
549
|
-
body: definition.body,
|
|
550
|
-
scope: bindValue(undefined, definition.name, self),
|
|
551
|
-
};
|
|
552
|
-
};
|
|
553
|
-
|
|
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.
|
|
554
501
|
const compileFunctionAction = (
|
|
555
502
|
expression: Expression & { kind: "FunctionApplication" },
|
|
556
503
|
environment: Environment,
|
|
557
504
|
isInit: boolean,
|
|
558
505
|
): Runner => {
|
|
559
|
-
const
|
|
506
|
+
const node = describeRange(expression);
|
|
560
507
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
561
|
-
const
|
|
562
|
-
|
|
563
|
-
|
|
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
|
+
);
|
|
564
520
|
return;
|
|
565
521
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
if (!isElementOf(argument, domain)) {
|
|
571
|
-
throw new TlaEvaluationError(
|
|
572
|
-
`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}`,
|
|
573
526
|
);
|
|
574
527
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
);
|
|
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);
|
|
583
536
|
};
|
|
584
537
|
};
|
|
585
538
|
|
|
@@ -603,7 +556,7 @@ const compileUnchanged = (expression: Expression, environment: Environment): Run
|
|
|
603
556
|
);
|
|
604
557
|
return;
|
|
605
558
|
}
|
|
606
|
-
if (holds(unchanged, getContext(run, scope, partial))) onComplete(partial, action);
|
|
559
|
+
if (holds(run, unchanged, getContext(run, scope, partial))) onComplete(partial, action);
|
|
607
560
|
};
|
|
608
561
|
};
|
|
609
562
|
|
|
@@ -798,9 +751,10 @@ const compileAction = (
|
|
|
798
751
|
if (expression.bounds.length === 1 && bound.pattern.kind === "Name") {
|
|
799
752
|
const name = bound.pattern.name;
|
|
800
753
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
801
|
-
const elements =
|
|
754
|
+
const elements = getContextElements(
|
|
802
755
|
evaluate(bound.set, getContext(run, scope, partial)),
|
|
803
756
|
bound.set,
|
|
757
|
+
environment.runtime.version,
|
|
804
758
|
);
|
|
805
759
|
for (let index = 0; index < elements.length && !run.isStopped; index++) {
|
|
806
760
|
body(
|
|
@@ -814,14 +768,17 @@ const compileAction = (
|
|
|
814
768
|
}
|
|
815
769
|
};
|
|
816
770
|
}
|
|
817
|
-
const hoisted =
|
|
818
|
-
isInit || environment.trace ? undefined : getHoistedGuards(expression, environment);
|
|
771
|
+
const hoisted = isInit ? undefined : getHoistedGuards(expression, environment);
|
|
819
772
|
if (hoisted) {
|
|
820
773
|
const rest = compileConjunction(hoisted.rest, environment, isInit);
|
|
821
774
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
822
775
|
const context = getContext(run, scope, partial);
|
|
823
776
|
const sets = expression.bounds.map((innerBound) =>
|
|
824
|
-
|
|
777
|
+
getContextElements(
|
|
778
|
+
evaluate(innerBound.set, context),
|
|
779
|
+
innerBound.set,
|
|
780
|
+
environment.runtime.version,
|
|
781
|
+
),
|
|
825
782
|
);
|
|
826
783
|
if (sets.some((elements) => elements.length === 0)) return;
|
|
827
784
|
const visit = (index: number, boundScope: Scope | undefined): void => {
|
|
@@ -834,7 +791,7 @@ const compileAction = (
|
|
|
834
791
|
const elementScope = bindValue(boundScope, hoisted.names[index], element);
|
|
835
792
|
if (index === sets.length - 1) {
|
|
836
793
|
const guardContext = getContext(run, elementScope, partial);
|
|
837
|
-
if (!hoisted.guards.every((guard) => holds(guard, guardContext))) continue;
|
|
794
|
+
if (!hoisted.guards.every((guard) => holds(run, guard, guardContext))) continue;
|
|
838
795
|
}
|
|
839
796
|
visit(index - 1, elementScope);
|
|
840
797
|
}
|
|
@@ -869,7 +826,7 @@ const compileAction = (
|
|
|
869
826
|
);
|
|
870
827
|
if (isBoundToValues) {
|
|
871
828
|
const isSatisfied = scopes.every((boundScope) =>
|
|
872
|
-
holds(expression.body, getContext(run, boundScope, partial)),
|
|
829
|
+
holds(run, expression.body, getContext(run, boundScope, partial)),
|
|
873
830
|
);
|
|
874
831
|
if (isSatisfied) onComplete(partial, action);
|
|
875
832
|
return;
|
|
@@ -883,7 +840,7 @@ const compileAction = (
|
|
|
883
840
|
const isSatisfied = scopes
|
|
884
841
|
.slice(index)
|
|
885
842
|
.every((boundScope) =>
|
|
886
|
-
|
|
843
|
+
holds(run, expression.body, getContext(run, boundScope, nextPartial)),
|
|
887
844
|
);
|
|
888
845
|
if (isSatisfied) onComplete(nextPartial, nextAction);
|
|
889
846
|
return;
|
|
@@ -900,26 +857,38 @@ const compileAction = (
|
|
|
900
857
|
const alternative = child(expression.alternative);
|
|
901
858
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
902
859
|
const condition = evaluate(expression.condition, getContext(run, scope, partial));
|
|
903
|
-
|
|
860
|
+
if (typeof condition !== "boolean") {
|
|
861
|
+
throw createRunError(run, getIfConditionMessage(run, condition, expression));
|
|
862
|
+
}
|
|
863
|
+
const branch = condition ? consequent : alternative;
|
|
904
864
|
branch(run, scope, partial, action, isFixed, onComplete);
|
|
905
865
|
};
|
|
906
866
|
}
|
|
907
867
|
case "Case": {
|
|
908
868
|
const arms = expression.arms.map((arm) => ({
|
|
909
869
|
condition: arm.condition,
|
|
870
|
+
source: arm.body,
|
|
910
871
|
body: child(arm.body),
|
|
911
872
|
}));
|
|
912
873
|
const other = expression.other ? child(expression.other) : undefined;
|
|
913
874
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
914
875
|
const context = getContext(run, scope, partial);
|
|
915
|
-
const arm = arms.find((candidate) =>
|
|
916
|
-
|
|
917
|
-
|
|
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
|
+
});
|
|
918
885
|
const body = arm?.body ?? other;
|
|
919
|
-
if (!body)
|
|
920
|
-
throw
|
|
921
|
-
|
|
886
|
+
if (!body) {
|
|
887
|
+
throw createRunError(
|
|
888
|
+
run,
|
|
889
|
+
`In computing ${getComputation(run)}, TLC encountered a CASE with no conditions true.\n${describeRange(expression)}`,
|
|
922
890
|
);
|
|
891
|
+
}
|
|
923
892
|
body(run, scope, partial, action, isFixed, onComplete);
|
|
924
893
|
};
|
|
925
894
|
}
|
|
@@ -948,10 +917,18 @@ const compileAction = (
|
|
|
948
917
|
case "AngleAction": {
|
|
949
918
|
const body = child(expression.action);
|
|
950
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
|
+
};
|
|
951
929
|
return (run, scope, partial, action, isFixed, onComplete) =>
|
|
952
930
|
body(run, scope, partial, action, isFixed, (nextPartial, nextAction) => {
|
|
953
|
-
if (!
|
|
954
|
-
onComplete(nextPartial, nextAction);
|
|
931
|
+
if (!isUnchanged(run, scope, nextPartial)) onComplete(nextPartial, nextAction);
|
|
955
932
|
});
|
|
956
933
|
}
|
|
957
934
|
case "BoxAction":
|
|
@@ -1028,7 +1005,15 @@ export const isEnabled = (expression: Expression, context: Context): boolean =>
|
|
|
1028
1005
|
);
|
|
1029
1006
|
}
|
|
1030
1007
|
const environment = context.environment;
|
|
1031
|
-
|
|
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
|
+
};
|
|
1032
1017
|
// TLC stops computing ENABLED at the first successor, so it skips the rest of the action.
|
|
1033
1018
|
getRunner(expression, environment, false)(
|
|
1034
1019
|
run,
|
|
@@ -1049,7 +1034,13 @@ export const forEachInitialState = (
|
|
|
1049
1034
|
onState: (state: Value[]) => boolean,
|
|
1050
1035
|
scope?: Scope,
|
|
1051
1036
|
) => {
|
|
1052
|
-
const run: Run = {
|
|
1037
|
+
const run: Run = {
|
|
1038
|
+
environment,
|
|
1039
|
+
isInit: true,
|
|
1040
|
+
isEnabled: false,
|
|
1041
|
+
current: undefined,
|
|
1042
|
+
isStopped: false,
|
|
1043
|
+
};
|
|
1053
1044
|
getRunner(expression, environment, true)(
|
|
1054
1045
|
run,
|
|
1055
1046
|
scope,
|
|
@@ -1061,12 +1052,7 @@ export const forEachInitialState = (
|
|
|
1061
1052
|
if (!isComplete(partial)) {
|
|
1062
1053
|
// TLC reports an initial state that isn't completely specified as an illegal state, not as
|
|
1063
1054
|
// an evaluation failure.
|
|
1064
|
-
throw setExitCode(
|
|
1065
|
-
new TlaEvaluationError(
|
|
1066
|
-
`The initial predicate does not assign ${getMissingVariables(partial, environment).join(", ")}`,
|
|
1067
|
-
),
|
|
1068
|
-
EXIT_STATUS.error,
|
|
1069
|
-
);
|
|
1055
|
+
throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
|
|
1070
1056
|
}
|
|
1071
1057
|
run.isStopped = onState(partial);
|
|
1072
1058
|
},
|
|
@@ -1098,7 +1084,13 @@ export const forEachSuccessor = (
|
|
|
1098
1084
|
onSuccessor: (successor: Successor) => boolean,
|
|
1099
1085
|
scope?: Scope,
|
|
1100
1086
|
) => {
|
|
1101
|
-
const run: Run = {
|
|
1087
|
+
const run: Run = {
|
|
1088
|
+
environment,
|
|
1089
|
+
isInit: false,
|
|
1090
|
+
isEnabled: false,
|
|
1091
|
+
current: state,
|
|
1092
|
+
isStopped: false,
|
|
1093
|
+
};
|
|
1102
1094
|
const counter = { successors: 0 };
|
|
1103
1095
|
getRunner(expression, environment, false)(
|
|
1104
1096
|
run,
|
|
@@ -1109,10 +1101,12 @@ export const forEachSuccessor = (
|
|
|
1109
1101
|
(partial, action) => {
|
|
1110
1102
|
if (run.isStopped) return;
|
|
1111
1103
|
if (!isComplete(partial)) {
|
|
1112
|
-
|
|
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(", ")}`,
|
|
1113
1107
|
partial,
|
|
1114
1108
|
action,
|
|
1115
|
-
|
|
1109
|
+
missing,
|
|
1116
1110
|
);
|
|
1117
1111
|
}
|
|
1118
1112
|
counter.successors++;
|