tla-ts 0.0.1 → 0.0.3-dev.19c763f
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 +98 -39
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +225 -30
- package/dist/index.d.ts +225 -30
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +2 -2
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +21 -1
- package/dist/run-cli.js +21 -1
- package/dist/transfer.cjs +400 -39
- package/dist/transfer.js +400 -39
- package/package.json +6 -2
- package/src/ast.ts +213 -6
- package/src/bags.ts +161 -71
- package/src/builtins.ts +203 -23
- package/src/bundled-modules.ts +63 -32
- package/src/check.ts +1086 -244
- package/src/cli-options.ts +64 -0
- package/src/codegen.ts +58 -34
- package/src/config.ts +39 -11
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +557 -153
- package/src/errors.ts +66 -1
- package/src/evaluate.ts +547 -255
- package/src/exit-codes.ts +53 -0
- package/src/fingerprints.ts +48 -13
- package/src/index.ts +9 -4
- package/src/instances.ts +235 -79
- package/src/java-overrides.ts +241 -0
- package/src/json.ts +153 -72
- package/src/levels.ts +850 -0
- package/src/lexer.ts +108 -29
- package/src/live-check.ts +710 -0
- package/src/liveness.ts +37 -599
- package/src/obligation-action.ts +384 -0
- package/src/obligation-anon.ts +575 -0
- package/src/obligation-deref.ts +637 -0
- package/src/obligation-expression.ts +1060 -0
- package/src/obligation-format.ts +406 -0
- package/src/obligation-generate.ts +1074 -0
- package/src/obligation-levels.ts +329 -0
- package/src/obligation-module.ts +1042 -0
- package/src/obligation-printer.ts +889 -0
- package/src/obligation-proof.ts +76 -0
- package/src/obligation-source.ts +1084 -0
- package/src/obligation-tuples.ts +184 -0
- package/src/obligations.ts +316 -0
- package/src/parallel-worker.ts +186 -201
- package/src/parallel.ts +179 -84
- package/src/parser.ts +970 -206
- package/src/pretty-print.ts +259 -0
- package/src/randomization.ts +24 -113
- package/src/resolve.ts +483 -51
- package/src/run-cli.ts +473 -62
- package/src/runtime.ts +65 -28
- package/src/spec-description.ts +521 -0
- package/src/standard-levels.ts +105 -0
- package/src/standard-modules.ts +223 -92
- package/src/state-graph.ts +157 -0
- package/src/subexpressions.ts +31 -45
- package/src/substitution-levels.ts +184 -0
- package/src/successors.ts +276 -53
- package/src/symmetry.ts +79 -23
- package/src/tableau.ts +43 -37
- package/src/tlc-ext.ts +148 -44
- package/src/tlc-module.ts +71 -66
- package/src/tlc-modules.ts +1022 -0
- package/src/tlc-order.ts +511 -0
- package/src/tlc-random.ts +411 -0
- package/src/tlc-summary.ts +109 -0
- package/src/transfer.ts +26 -5
- package/src/values.ts +1245 -176
package/src/tableau.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { Expression } from "./ast";
|
|
2
2
|
import { TlaEvaluationError } from "./errors";
|
|
3
3
|
import type { Scope } from "./evaluate";
|
|
4
|
+
import { ACTION_LEVEL, TEMPORAL_LEVEL } from "./levels";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
interface LiveBoolean {
|
|
6
7
|
kind: "Boolean";
|
|
7
8
|
value: boolean;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
interface LiveState {
|
|
11
12
|
kind: "State";
|
|
12
13
|
expression: Expression;
|
|
13
14
|
scope: Scope | undefined;
|
|
@@ -19,7 +20,7 @@ export interface LiveEnabled {
|
|
|
19
20
|
scope: Scope | undefined;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
interface LiveAction {
|
|
23
24
|
kind: "Action";
|
|
24
25
|
expression: Expression;
|
|
25
26
|
unchanged: Expression | undefined;
|
|
@@ -27,12 +28,12 @@ export interface LiveAction {
|
|
|
27
28
|
enabled?: LiveEnabled;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
interface LiveUnary {
|
|
31
32
|
kind: "Not" | "Always" | "Eventually" | "Next";
|
|
32
33
|
body: LiveExpression;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
interface LiveJunction {
|
|
36
37
|
kind: "And" | "Or";
|
|
37
38
|
operands: LiveExpression[];
|
|
38
39
|
}
|
|
@@ -45,7 +46,7 @@ export type LiveExpression =
|
|
|
45
46
|
| LiveUnary
|
|
46
47
|
| LiveJunction;
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
interface TableauNode {
|
|
49
50
|
particle: LiveExpression[];
|
|
50
51
|
successors: number[];
|
|
51
52
|
statePredicates: LiveExpression[];
|
|
@@ -56,7 +57,7 @@ export interface Tableau {
|
|
|
56
57
|
initialCount: number;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
interface ErrorModel {
|
|
60
61
|
eventuallyAlways: number[];
|
|
61
62
|
infinitelyOftenStates: number[];
|
|
62
63
|
infinitelyOftenActions: number[];
|
|
@@ -84,14 +85,12 @@ interface Triple {
|
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
const STATE_LEVEL = 1;
|
|
87
|
-
const ACTION_LEVEL = 2;
|
|
88
|
-
const TEMPORAL_LEVEL = 3;
|
|
89
88
|
const MAXIMUM_DISJUNCTS = 2147483647;
|
|
90
89
|
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
const TRUE: LiveBoolean = { kind: "Boolean", value: true };
|
|
91
|
+
const FALSE: LiveBoolean = { kind: "Boolean", value: false };
|
|
93
92
|
|
|
94
|
-
const createBoolean = (value: boolean) => (value ? TRUE : FALSE);
|
|
93
|
+
export const createBoolean = (value: boolean) => (value ? TRUE : FALSE);
|
|
95
94
|
|
|
96
95
|
const isAtom = (expression: LiveExpression) =>
|
|
97
96
|
expression.kind === "State" || expression.kind === "Enabled" || expression.kind === "Action";
|
|
@@ -265,6 +264,10 @@ const toDisjunctiveNormalForm = (expression: LiveExpression): LiveExpression =>
|
|
|
265
264
|
const total = { value: 1 };
|
|
266
265
|
for (const operand of expression.operands) {
|
|
267
266
|
const normal = toDisjunctiveNormalForm(operand);
|
|
267
|
+
if (normal.kind === "And") {
|
|
268
|
+
items.push(...normal.operands);
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
268
271
|
if (normal.kind === "Or") {
|
|
269
272
|
total.value *= normal.operands.length;
|
|
270
273
|
if (total.value > MAXIMUM_DISJUNCTS) {
|
|
@@ -272,12 +275,8 @@ const toDisjunctiveNormalForm = (expression: LiveExpression): LiveExpression =>
|
|
|
272
275
|
"TLC cannot handle the temporal formula because it exceeds the maximum supported size in disjunctive normal form",
|
|
273
276
|
);
|
|
274
277
|
}
|
|
275
|
-
items.push(normal);
|
|
276
|
-
} else if (normal.kind === "And") {
|
|
277
|
-
items.push(...normal.operands);
|
|
278
|
-
} else {
|
|
279
|
-
items.push(normal);
|
|
280
278
|
}
|
|
279
|
+
items.push(normal);
|
|
281
280
|
}
|
|
282
281
|
if (total.value === 1) return { kind: "And", operands: items };
|
|
283
282
|
const conjunctions = Array.from({ length: total.value }, (): LiveExpression[] => []);
|
|
@@ -427,9 +426,13 @@ const getExpansion = (
|
|
|
427
426
|
term: LiveExpression,
|
|
428
427
|
repeated: "Always" | "Eventually",
|
|
429
428
|
junction: "And" | "Or",
|
|
430
|
-
)
|
|
431
|
-
if (term.kind === repeated && "body" in term)
|
|
432
|
-
|
|
429
|
+
) => {
|
|
430
|
+
if (term.kind === repeated && "body" in term) {
|
|
431
|
+
return { first: term.body, second: createUnary("Next", term) };
|
|
432
|
+
}
|
|
433
|
+
if (term.kind === junction && "operands" in term) {
|
|
434
|
+
return { first: term.operands[0], second: term.operands[1] };
|
|
435
|
+
}
|
|
433
436
|
return undefined;
|
|
434
437
|
};
|
|
435
438
|
|
|
@@ -437,10 +440,10 @@ const getTriples = (
|
|
|
437
440
|
closure: LiveExpression[],
|
|
438
441
|
repeated: "Always" | "Eventually",
|
|
439
442
|
junction: "And" | "Or",
|
|
440
|
-
)
|
|
443
|
+
) =>
|
|
441
444
|
closure.flatMap((term): Triple[] => {
|
|
442
445
|
const parts = getExpansion(term, repeated, junction);
|
|
443
|
-
return parts ? [{ whole: term, first: parts
|
|
446
|
+
return parts ? [{ whole: term, first: parts.first, second: parts.second }] : [];
|
|
444
447
|
});
|
|
445
448
|
|
|
446
449
|
const isSameParticle = (left: LiveExpression[], right: LiveExpression[]) =>
|
|
@@ -451,7 +454,7 @@ const unionParticles = (left: LiveExpression[][], right: LiveExpression[][]) =>
|
|
|
451
454
|
...right,
|
|
452
455
|
];
|
|
453
456
|
|
|
454
|
-
const getParticleClosure = (terms: LiveExpression[])
|
|
457
|
+
const getParticleClosure = (terms: LiveExpression[]) => {
|
|
455
458
|
const closure = getPositiveClosure(terms);
|
|
456
459
|
const alphas = getTriples(closure, "Always", "And");
|
|
457
460
|
const betas = getTriples(closure, "Eventually", "Or");
|
|
@@ -460,9 +463,11 @@ const getParticleClosure = (terms: LiveExpression[]): LiveExpression[][] => {
|
|
|
460
463
|
for (const term of particle) {
|
|
461
464
|
const parts = getExpansion(term, "Eventually", "Or");
|
|
462
465
|
if (!parts) continue;
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
+
if (isMember(particle, parts.first) || isMember(particle, parts.second)) continue;
|
|
467
|
+
return unionParticles(
|
|
468
|
+
expand([...particle, parts.first]),
|
|
469
|
+
expand([...particle, parts.second]),
|
|
470
|
+
);
|
|
466
471
|
}
|
|
467
472
|
const beta = betas.find(
|
|
468
473
|
(triple) =>
|
|
@@ -478,9 +483,8 @@ const getParticleClosure = (terms: LiveExpression[]): LiveExpression[][] => {
|
|
|
478
483
|
for (let index = 0; index < expanded.length; index++) {
|
|
479
484
|
const parts = getExpansion(expanded[index], "Always", "And");
|
|
480
485
|
if (!parts) continue;
|
|
481
|
-
|
|
482
|
-
if (!isMember(expanded,
|
|
483
|
-
if (!isMember(expanded, second)) expanded.push(second);
|
|
486
|
+
if (!isMember(expanded, parts.first)) expanded.push(parts.first);
|
|
487
|
+
if (!isMember(expanded, parts.second)) expanded.push(parts.second);
|
|
484
488
|
}
|
|
485
489
|
const state = { isChanged: true };
|
|
486
490
|
while (state.isChanged) {
|
|
@@ -509,7 +513,7 @@ const createTableauNode = (particle: LiveExpression[]): TableauNode => ({
|
|
|
509
513
|
statePredicates: particle.filter((term) => getLiveLevel(term) <= STATE_LEVEL),
|
|
510
514
|
});
|
|
511
515
|
|
|
512
|
-
const createTableau = (formula: LiveExpression)
|
|
516
|
+
const createTableau = (formula: LiveExpression) => {
|
|
513
517
|
const nodes = getParticleClosure([formula]).map(createTableauNode);
|
|
514
518
|
const initialCount = nodes.length;
|
|
515
519
|
for (let index = 0; index < nodes.length; index++) {
|
|
@@ -529,11 +533,13 @@ export const isFulfilling = (particle: LiveExpression[], promise: LiveUnary) =>
|
|
|
529
533
|
!isMember(particle, promise) || isMember(particle, promise.body);
|
|
530
534
|
|
|
531
535
|
const classify = (expression: LiveExpression, classification: Classification) => {
|
|
532
|
-
if (
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
536
|
+
if (
|
|
537
|
+
expression.kind === "Eventually" &&
|
|
538
|
+
expression.body.kind === "Always" &&
|
|
539
|
+
getLiveLevel(expression.body.body) < TEMPORAL_LEVEL
|
|
540
|
+
) {
|
|
541
|
+
classification.eventuallyAlways.push(expression.body.body);
|
|
542
|
+
return;
|
|
537
543
|
}
|
|
538
544
|
const infinitelyOften = getInfinitelyOftenBody(expression);
|
|
539
545
|
if (infinitelyOften) {
|
|
@@ -592,13 +598,13 @@ export const getSolutions = (formula: LiveExpression): Solution[] => {
|
|
|
592
598
|
if (group) group.classifications.push(classification);
|
|
593
599
|
else groups.push({ formula: temporal, classifications: [classification] });
|
|
594
600
|
}
|
|
595
|
-
return groups.map((group)
|
|
601
|
+
return groups.map((group) => {
|
|
596
602
|
const binary = group.formula && makeBinary(group.formula);
|
|
597
603
|
const promises: LiveUnary[] = [];
|
|
598
604
|
if (binary) extractPromises(binary, promises);
|
|
599
605
|
const stateChecks: LiveExpression[] = [];
|
|
600
606
|
const actionChecks: LiveExpression[] = [];
|
|
601
|
-
const models = group.classifications.map((classification)
|
|
607
|
+
const models = group.classifications.map((classification) => ({
|
|
602
608
|
infinitelyOftenActions: classification.infinitelyOftenActions.map((check) =>
|
|
603
609
|
addToBin(actionChecks, check),
|
|
604
610
|
),
|
package/src/tlc-ext.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createJavaOverrideError,
|
|
3
3
|
defineHigherOrderOperator,
|
|
4
4
|
defineLazyOperator,
|
|
5
5
|
defineOperator,
|
|
@@ -8,16 +8,11 @@ import {
|
|
|
8
8
|
getThunk,
|
|
9
9
|
getValue,
|
|
10
10
|
} from "./builtins";
|
|
11
|
-
import { TlaEvaluationError } from "./errors";
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
isLocallyResolved,
|
|
17
|
-
type Builtin,
|
|
18
|
-
type Environment,
|
|
19
|
-
} from "./evaluate";
|
|
20
|
-
import type { Definition, Expression } from "./ast";
|
|
11
|
+
import { TlaEvaluationError, TlaModuleError, TlaUnsupportedError } from "./errors";
|
|
12
|
+
import { getTlcFingerprint } from "./tlc-random";
|
|
13
|
+
import { evaluate, expectBoolean, getDefinition, type Builtin, type Environment } from "./evaluate";
|
|
14
|
+
import { getChildren, isLocallyResolved, type Definition, type Expression } from "./ast";
|
|
15
|
+
import type { TraceStep } from "./check";
|
|
21
16
|
import {
|
|
22
17
|
getNamedRegisters,
|
|
23
18
|
getPossibleCounts,
|
|
@@ -31,18 +26,74 @@ import {
|
|
|
31
26
|
createSet,
|
|
32
27
|
createTuple,
|
|
33
28
|
formatValue,
|
|
29
|
+
getDomain,
|
|
34
30
|
getSequenceElements,
|
|
35
|
-
getValueHash,
|
|
36
31
|
getValueKey,
|
|
32
|
+
isFunctionValue,
|
|
37
33
|
toFiniteSet,
|
|
38
34
|
valuesEqual,
|
|
39
35
|
type Value,
|
|
40
36
|
} from "./values";
|
|
41
37
|
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
const OVERRIDE_PARAMETERS =
|
|
39
|
+
"tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel";
|
|
40
|
+
|
|
41
|
+
const ASSERT_ERROR_METHOD = `public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.assertError(${OVERRIDE_PARAMETERS})`;
|
|
42
|
+
|
|
43
|
+
const TRACE_METHOD = `public static tlc2.value.impl.TupleValue tlc2.module.TLCExt.getTrace(${OVERRIDE_PARAMETERS}) throws java.io.IOException`;
|
|
44
|
+
|
|
45
|
+
const PICK_SUCCESSOR_METHOD = `public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.pickSuccessor(${OVERRIDE_PARAMETERS})`;
|
|
46
|
+
|
|
47
|
+
const createEmptyCounterExample = () =>
|
|
48
|
+
createRecord([
|
|
49
|
+
["action", createSet([])],
|
|
50
|
+
["state", createSet([])],
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
const createBuiltinLocation = () =>
|
|
54
|
+
createRecord([
|
|
55
|
+
["beginLine", 0],
|
|
56
|
+
["beginColumn", 0],
|
|
57
|
+
["endLine", 0],
|
|
58
|
+
["endColumn", 0],
|
|
59
|
+
["module", "--TLA+ BUILTINS--"],
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
// TLC's record for an action it doesn't store, such as every action in breadth-first search.
|
|
63
|
+
export const createActionRecord = (action: string | undefined) =>
|
|
64
|
+
createRecord([
|
|
65
|
+
["name", action ?? "UnnamedAction"],
|
|
66
|
+
["location", createBuiltinLocation()],
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
// TLC's CounterExample is a graph of the violating behavior: the states numbered from 1, an edge
|
|
70
|
+
// for each step, and for a lasso an edge from the last state back to where the loop starts.
|
|
71
|
+
export const createCounterExample = (
|
|
72
|
+
trace: TraceStep[],
|
|
73
|
+
loop: { start: number; action: string | undefined } | undefined,
|
|
74
|
+
) => {
|
|
75
|
+
const states = trace.map((step, index) =>
|
|
76
|
+
createTuple([index + 1, createRecord(Object.entries(step.state))]),
|
|
77
|
+
);
|
|
78
|
+
const steps = states
|
|
79
|
+
.slice(1)
|
|
80
|
+
.map((state, index) =>
|
|
81
|
+
createTuple([states[index], createActionRecord(trace[index + 1].action), state]),
|
|
82
|
+
);
|
|
83
|
+
const closing = loop
|
|
84
|
+
? [
|
|
85
|
+
createTuple([
|
|
86
|
+
states[states.length - 1],
|
|
87
|
+
createActionRecord(loop.action),
|
|
88
|
+
states[loop.start],
|
|
89
|
+
]),
|
|
90
|
+
]
|
|
91
|
+
: [];
|
|
92
|
+
return createRecord([
|
|
93
|
+
["action", createSet([...steps, ...closing])],
|
|
94
|
+
["state", createSet(states)],
|
|
95
|
+
]);
|
|
96
|
+
};
|
|
46
97
|
|
|
47
98
|
const getRegister = (runtime: CheckerRuntime, key: Value) => {
|
|
48
99
|
if (typeof key === "number") return runtime.registers.get(key);
|
|
@@ -52,16 +103,36 @@ const getRegister = (runtime: CheckerRuntime, key: Value) => {
|
|
|
52
103
|
return undefined;
|
|
53
104
|
};
|
|
54
105
|
|
|
55
|
-
|
|
106
|
+
// TLC's TLCSet. TLCExt's TLCGetAndSet is a TLA+ definition that calls it.
|
|
107
|
+
export const setTlcValue = (
|
|
108
|
+
runtime: CheckerRuntime,
|
|
109
|
+
print: (text: string) => void,
|
|
110
|
+
key: Value,
|
|
111
|
+
value: Value,
|
|
112
|
+
) => {
|
|
56
113
|
if (typeof key === "number" && key >= 0) {
|
|
57
114
|
runtime.registers.set(key, value);
|
|
58
115
|
return;
|
|
59
116
|
}
|
|
117
|
+
if (key === "exit") {
|
|
118
|
+
if (value === true) runtime.isStopped = true;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (key === "pause") {
|
|
122
|
+
if (value !== true) return;
|
|
123
|
+
print("Press enter to resume model checking.");
|
|
124
|
+
runtime.pause();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
60
127
|
if (typeof key === "string" && key.startsWith(NAMED_REGISTER_PREFIX)) {
|
|
61
128
|
runtime.namedRegisters.set(key, value);
|
|
62
129
|
return;
|
|
63
130
|
}
|
|
64
|
-
|
|
131
|
+
if (typeof key === "string" && key.startsWith("-D")) {
|
|
132
|
+
runtime.properties.set(key.slice(2), formatValue(value));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
throw new TlaModuleError(
|
|
65
136
|
`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${formatValue(key)}`,
|
|
66
137
|
);
|
|
67
138
|
};
|
|
@@ -112,13 +183,20 @@ export const createTlcExtOperators = (
|
|
|
112
183
|
const right = getValue(args, 1, "AssertEq");
|
|
113
184
|
const isEqual = valuesEqual(left, right);
|
|
114
185
|
if (!isEqual) {
|
|
115
|
-
print("Assertion failed");
|
|
186
|
+
print(formatValue("Assertion failed", true));
|
|
116
187
|
print(formatValue(left, true));
|
|
117
188
|
print(formatValue(right, true));
|
|
118
189
|
}
|
|
119
190
|
return isEqual;
|
|
120
191
|
}),
|
|
121
192
|
defineLazyOperator("AssertError", 2, (args) => {
|
|
193
|
+
const message = getOperator(args, 0, "AssertError").expression;
|
|
194
|
+
if (message && message.kind !== "String") {
|
|
195
|
+
throw createJavaOverrideError(
|
|
196
|
+
ASSERT_ERROR_METHOD,
|
|
197
|
+
`In computing AssertError, a non-string expression (line ${message.location.line}, col ${message.location.column}) was used as the err of an AssertError(err, exp).`,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
122
200
|
const expected = getThunk(args, 0, "AssertError")();
|
|
123
201
|
try {
|
|
124
202
|
getThunk(args, 1, "AssertError")();
|
|
@@ -137,53 +215,80 @@ export const createTlcExtOperators = (
|
|
|
137
215
|
const key = getValue(args, 0, "TLCGetAndSet");
|
|
138
216
|
const previous = getRegister(runtime, key) ?? getValue(args, 3, "TLCGetAndSet");
|
|
139
217
|
const update = getOperator(args, 1, "TLCGetAndSet");
|
|
140
|
-
|
|
218
|
+
setTlcValue(
|
|
219
|
+
runtime,
|
|
220
|
+
print,
|
|
221
|
+
key,
|
|
222
|
+
update.call([previous, getValue(args, 2, "TLCGetAndSet")]),
|
|
223
|
+
);
|
|
141
224
|
return previous;
|
|
142
225
|
}),
|
|
143
226
|
isStateLevel: true,
|
|
144
227
|
},
|
|
145
228
|
defineStateOperator("Trace", 0, (_, context) => {
|
|
146
229
|
const state = context?.state;
|
|
147
|
-
if (!state || !isCompleteState(state)) {
|
|
148
|
-
|
|
149
|
-
|
|
230
|
+
if (!context || !state || !isCompleteState(state)) {
|
|
231
|
+
const unassigned = (context?.environment.variables ?? []).filter(
|
|
232
|
+
(_, index) => state?.[index] === undefined,
|
|
233
|
+
);
|
|
234
|
+
throw createJavaOverrideError(
|
|
235
|
+
TRACE_METHOD,
|
|
236
|
+
`In evaluating TLCExt!Trace, the state is not completely specified yet (variable${unassigned.length > 1 ? "s" : ""} ${unassigned.join(", ")} undefined).`,
|
|
150
237
|
);
|
|
151
238
|
}
|
|
152
239
|
return createTuple(
|
|
153
240
|
runtime.getBehavior(state).map((step) => toStateRecord(step, context.environment)),
|
|
154
241
|
);
|
|
155
242
|
}),
|
|
156
|
-
|
|
243
|
+
defineStateOperator(
|
|
244
|
+
"CounterExample",
|
|
245
|
+
0,
|
|
246
|
+
() => runtime.counterExample ?? createEmptyCounterExample(),
|
|
247
|
+
),
|
|
157
248
|
defineOperator("ToTrace", 1, (args) => {
|
|
158
249
|
const counterExample = getValue(args, 0, "ToTrace");
|
|
250
|
+
if (
|
|
251
|
+
!isFunctionValue(counterExample) ||
|
|
252
|
+
!valuesEqual(getDomain(counterExample), createSet(["action", "state"]))
|
|
253
|
+
) {
|
|
254
|
+
throw new TlaEvaluationError(
|
|
255
|
+
`The argument of ToTrace should be a CounterExample, but instead it is:\n${formatValue(counterExample)}`,
|
|
256
|
+
);
|
|
257
|
+
}
|
|
159
258
|
const states = toFiniteSet(applyFunction(counterExample, "state")).elements.map(
|
|
160
259
|
(pair) => getSequenceElements(pair) ?? [],
|
|
161
260
|
);
|
|
162
261
|
return createTuple(
|
|
163
|
-
[
|
|
164
|
-
.sort((left, right) => Number(left[0]) - Number(right[0]))
|
|
165
|
-
.map((pair) => pair[1]),
|
|
262
|
+
states.sort((left, right) => Number(left[0]) - Number(right[0])).map((pair) => pair[1]),
|
|
166
263
|
);
|
|
167
264
|
}),
|
|
168
265
|
defineOperator("TLCModelValue", 1, (args) => {
|
|
169
266
|
const name = getValue(args, 0, "TLCModelValue");
|
|
170
267
|
if (typeof name !== "string") {
|
|
171
|
-
throw new
|
|
268
|
+
throw new TlaModuleError(
|
|
172
269
|
`The argument of ModelValue should be a string, but instead it is:\n${formatValue(name)}`,
|
|
173
270
|
);
|
|
174
271
|
}
|
|
175
272
|
return createModelValue(name);
|
|
176
273
|
}),
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return true;
|
|
180
|
-
}),
|
|
274
|
+
// TLC runs the deferred expression only in simulation, when it extends a behavior.
|
|
275
|
+
defineLazyOperator("TLCDefer", 1, () => true),
|
|
181
276
|
defineOperator("TLCNoOp", 1, (args) => getValue(args, 0, "TLCNoOp")),
|
|
182
277
|
defineLazyOperator("PickSuccessor", 1, (args, context) => {
|
|
183
|
-
if (getThunk(args, 0, "PickSuccessor")() === true) return true;
|
|
184
278
|
const next = context?.next;
|
|
185
|
-
if (!next || !isCompleteState(next))
|
|
186
|
-
|
|
279
|
+
if (!next || !isCompleteState(next)) {
|
|
280
|
+
throw createJavaOverrideError(
|
|
281
|
+
PICK_SUCCESSOR_METHOD,
|
|
282
|
+
'Cannot invoke "tlc2.value.IValue.fingerPrint(long)" because "minVals[i]" is null',
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
if (runtime.isSeen(next)) return true;
|
|
286
|
+
if (expectBoolean(getThunk(args, 0, "PickSuccessor")(), "the condition of PickSuccessor")) {
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
throw new TlaUnsupportedError(
|
|
290
|
+
"PickSuccessor needs interactive input to extend the behavior with a new state",
|
|
291
|
+
);
|
|
187
292
|
}),
|
|
188
293
|
defineLazyOperator("TLCCache", 2, (args, context) => {
|
|
189
294
|
const expression = getOperator(args, 0, "TLCCache");
|
|
@@ -200,18 +305,20 @@ export const createTlcExtOperators = (
|
|
|
200
305
|
cache.set(closure, value);
|
|
201
306
|
return value;
|
|
202
307
|
}),
|
|
203
|
-
defineOperator("TLCFP", 1, (args) =>
|
|
308
|
+
defineOperator("TLCFP", 1, (args) =>
|
|
309
|
+
Number(BigInt.asIntN(32, getTlcFingerprint([getValue(args, 0, "TLCFP")]))),
|
|
310
|
+
),
|
|
204
311
|
defineStateOperator("TLCEvalDefinition", 1, (args, context) => {
|
|
205
312
|
const name = getValue(args, 0, "TLCEvalDefinition");
|
|
206
313
|
const definition =
|
|
207
314
|
typeof name === "string" && context ? getDefinition(name, context.environment) : undefined;
|
|
208
315
|
if (!definition || typeof name !== "string" || !context) {
|
|
209
|
-
throw new
|
|
316
|
+
throw new TlaModuleError(
|
|
210
317
|
`The argument of TLCEvalDefinition should be a name of a definition reachable from the root module, but instead it is:\n${formatValue(name)}`,
|
|
211
318
|
);
|
|
212
319
|
}
|
|
213
320
|
if (definition.kind === "Operator" && definition.params.length > 0) {
|
|
214
|
-
throw new
|
|
321
|
+
throw new TlaModuleError(
|
|
215
322
|
`The argument of TLCEvalDefinition should be a zero-arity definition, but instead it is:\n${name}`,
|
|
216
323
|
);
|
|
217
324
|
}
|
|
@@ -225,12 +332,9 @@ export const createPossibleOperators = (
|
|
|
225
332
|
runtime: CheckerRuntime,
|
|
226
333
|
): Builtin[] => [
|
|
227
334
|
defineStateOperator("_Track", 2, (args) => {
|
|
228
|
-
const name = getValue(args, 1, "_Track");
|
|
229
|
-
const count = runtime.possibleCounts.get(
|
|
230
|
-
runtime.possibleCounts.set(
|
|
231
|
-
String(name),
|
|
232
|
-
getValue(args, 0, "_Track") === true ? count + 1 : count,
|
|
233
|
-
);
|
|
335
|
+
const name = String(getValue(args, 1, "_Track"));
|
|
336
|
+
const count = runtime.possibleCounts.get(name) ?? 0;
|
|
337
|
+
runtime.possibleCounts.set(name, getValue(args, 0, "_Track") === true ? count + 1 : count);
|
|
234
338
|
return true;
|
|
235
339
|
}),
|
|
236
340
|
defineStateOperator("_Counts", 0, () => getPossibleCounts(runtime)),
|