tla-ts 0.0.3-dev.a57ca4f → 0.0.3-dev.b0d11a3
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/index.d.cts +22 -22
- package/dist/index.d.ts +22 -22
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +1 -1
- package/dist/transfer.cjs +21 -18
- package/dist/transfer.js +21 -18
- package/package.json +1 -1
- package/src/check.ts +85 -16
- package/src/codegen.ts +6 -3
- package/src/environment.ts +25 -14
- package/src/errors.ts +26 -0
- package/src/evaluate.ts +39 -7
- package/src/live-check.ts +129 -70
- package/src/liveness.ts +3 -5
- package/src/parallel-worker.ts +2 -2
- package/src/parallel.ts +2 -2
- package/src/successors.ts +35 -18
- package/src/symmetry.ts +16 -6
- package/src/tableau.ts +51 -24
- package/src/tlc-module.ts +6 -6
- package/src/tlc-modules.ts +4 -0
- package/src/tlc-order.ts +8 -4
- package/src/tlc-random.ts +9 -6
- package/src/tlc-summary.ts +20 -5
- package/src/values.ts +88 -13
package/src/live-check.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TlaEvaluationError } from "./errors";
|
|
2
|
+
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
2
3
|
import { hasRepeatedEffects, type Environment } from "./evaluate";
|
|
3
4
|
import {
|
|
4
5
|
evaluateLive,
|
|
@@ -12,6 +13,7 @@ import {
|
|
|
12
13
|
createJunction,
|
|
13
14
|
createUnary,
|
|
14
15
|
getSolutions,
|
|
16
|
+
getTermKey,
|
|
15
17
|
isFulfilling,
|
|
16
18
|
type LiveExpression,
|
|
17
19
|
type Solution,
|
|
@@ -48,37 +50,21 @@ interface Check {
|
|
|
48
50
|
actionIds: Int32Array;
|
|
49
51
|
nodeStates: number[];
|
|
50
52
|
nodeTableaux: number[];
|
|
51
|
-
successors
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
// The successors a node gathers until it is written.
|
|
54
|
+
pending: (number[] | undefined)[];
|
|
55
|
+
// Each written node's state results, then its action results edge by edge, from the node's
|
|
56
|
+
// offset in one buffer, so a node costs no objects of its own. An unwritten node has offset -1.
|
|
57
|
+
offsets: number[];
|
|
58
|
+
results: { bytes: Uint8Array; length: number };
|
|
59
|
+
// Each written node's successor count, then its successors, from the node's edge offset.
|
|
60
|
+
edgeOffsets: number[];
|
|
61
|
+
edges: { ids: Int32Array; length: number };
|
|
55
62
|
initial: number[];
|
|
56
|
-
nodeIds:
|
|
57
|
-
nodesByState: Map<number, number[]>;
|
|
63
|
+
nodeIds: NodeTable;
|
|
58
64
|
isDone: boolean[];
|
|
59
65
|
errorNode: number | undefined;
|
|
60
66
|
}
|
|
61
67
|
|
|
62
|
-
const liveKeys = new WeakMap<LiveExpression, string>();
|
|
63
|
-
|
|
64
|
-
const atomCount = { value: 0 };
|
|
65
|
-
|
|
66
|
-
// Each solution builds its own junctions over shared atoms, so equal checks get equal keys.
|
|
67
|
-
const getLiveKey = (expression: LiveExpression): string => {
|
|
68
|
-
const cached = liveKeys.get(expression);
|
|
69
|
-
if (cached !== undefined) return cached;
|
|
70
|
-
const key =
|
|
71
|
-
expression.kind === "Boolean"
|
|
72
|
-
? String(expression.value)
|
|
73
|
-
: "body" in expression
|
|
74
|
-
? `${expression.kind}(${getLiveKey(expression.body)})`
|
|
75
|
-
: "operands" in expression
|
|
76
|
-
? `${expression.kind}(${expression.operands.map(getLiveKey).join(",")})`
|
|
77
|
-
: `${expression.kind}#${atomCount.value++}`;
|
|
78
|
-
liveKeys.set(expression, key);
|
|
79
|
-
return key;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
68
|
const isSameState = (left: Value[], right: Value[]) =>
|
|
83
69
|
left.every((value, position) => isSameValue(value, right[position]));
|
|
84
70
|
|
|
@@ -89,13 +75,43 @@ const removeRepeats = (path: number[]) =>
|
|
|
89
75
|
const pushNode = (check: Check, state: number, tableauNode: number) => {
|
|
90
76
|
check.nodeStates.push(state);
|
|
91
77
|
check.nodeTableaux.push(tableauNode);
|
|
92
|
-
check.
|
|
93
|
-
check.
|
|
94
|
-
check.
|
|
95
|
-
check.isWritten.push(false);
|
|
78
|
+
check.pending.push(undefined);
|
|
79
|
+
check.offsets.push(-1);
|
|
80
|
+
check.edgeOffsets.push(-1);
|
|
96
81
|
return check.nodeStates.length - 1;
|
|
97
82
|
};
|
|
98
83
|
|
|
84
|
+
// A Map holds at most 2^24 entries, so each tableau node of a state finds its node in an
|
|
85
|
+
// open-addressing table of (state plus one, tableau node, node) triples.
|
|
86
|
+
interface NodeTable {
|
|
87
|
+
slots: Int32Array;
|
|
88
|
+
size: number;
|
|
89
|
+
shift: number;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const getNodeSlot = (table: NodeTable, state: number, tableauNode: number) => {
|
|
93
|
+
const mask = table.slots.length / 3 - 1;
|
|
94
|
+
const hash = Math.imul(Math.imul(state, 0x9e3779b1) ^ tableauNode, 0x85ebca6b) >>> table.shift;
|
|
95
|
+
for (let index = hash; ; index = (index + 1) & mask) {
|
|
96
|
+
const slot = index * 3;
|
|
97
|
+
const stored = table.slots[slot];
|
|
98
|
+
if (stored === 0 || (stored === state + 1 && table.slots[slot + 1] === tableauNode))
|
|
99
|
+
return slot;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const isWritten = (check: Check, node: number) => check.offsets[node] !== -1;
|
|
104
|
+
|
|
105
|
+
const getPending = (check: Check, node: number) => (check.pending[node] ??= []);
|
|
106
|
+
|
|
107
|
+
const getSuccessors = (check: Check, node: number) => {
|
|
108
|
+
const offset = check.edgeOffsets[node];
|
|
109
|
+
return check.edges.ids.subarray(offset + 1, offset + 1 + check.edges.ids[offset]);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const getStateResult = (check: Check, node: number, position: number) =>
|
|
113
|
+
check.results.bytes[check.offsets[node] + position] === 1;
|
|
114
|
+
|
|
99
115
|
const SUCCESSOR_CAPACITY = 16;
|
|
100
116
|
|
|
101
117
|
const SCC_MARKER = -42;
|
|
@@ -122,26 +138,29 @@ export const createLivenessChecker = (
|
|
|
122
138
|
fairness.length === 0 ? violation : createJunction("And", [...fairness, violation]);
|
|
123
139
|
const solutions = getSolutions(formula);
|
|
124
140
|
if (solutions.length === 0) {
|
|
125
|
-
throw
|
|
141
|
+
throw setExitCode(
|
|
142
|
+
new TlaEvaluationError(TAUTOLOGY_MESSAGE),
|
|
143
|
+
EXIT_STATUS.livenessEvaluationFailure,
|
|
144
|
+
);
|
|
126
145
|
}
|
|
127
146
|
const actionIds = new Map<string, number>();
|
|
128
147
|
const checks = solutions.map((solution): Check => ({
|
|
129
148
|
solution,
|
|
130
149
|
actionIds: Int32Array.from(solution.actionChecks, (predicate) => {
|
|
131
|
-
const key =
|
|
150
|
+
const key = getTermKey(predicate);
|
|
132
151
|
const id = actionIds.get(key) ?? actionIds.size;
|
|
133
152
|
actionIds.set(key, id);
|
|
134
153
|
return id;
|
|
135
154
|
}),
|
|
136
155
|
nodeStates: [],
|
|
137
156
|
nodeTableaux: [],
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
157
|
+
pending: [],
|
|
158
|
+
offsets: [],
|
|
159
|
+
results: { bytes: new Uint8Array(1024), length: 0 },
|
|
160
|
+
edgeOffsets: [],
|
|
161
|
+
edges: { ids: new Int32Array(1024), length: 0 },
|
|
142
162
|
initial: [],
|
|
143
|
-
nodeIds: new
|
|
144
|
-
nodesByState: new Map(),
|
|
163
|
+
nodeIds: { slots: new Int32Array(3 << 10), size: 0, shift: 22 },
|
|
145
164
|
isDone: [],
|
|
146
165
|
errorNode: undefined,
|
|
147
166
|
}));
|
|
@@ -227,18 +246,35 @@ export const createLivenessChecker = (
|
|
|
227
246
|
model.infinitelyOftenActions.length === 0,
|
|
228
247
|
);
|
|
229
248
|
|
|
230
|
-
const getNodeId = (check: Check, state: number, tableauNode: number) =>
|
|
231
|
-
check.solution.tableau
|
|
232
|
-
|
|
233
|
-
|
|
249
|
+
const getNodeId = (check: Check, state: number, tableauNode: number) => {
|
|
250
|
+
if (!check.solution.tableau) return state;
|
|
251
|
+
const slots = check.nodeIds.slots;
|
|
252
|
+
const slot = getNodeSlot(check.nodeIds, state, tableauNode);
|
|
253
|
+
return slots[slot] === 0 ? undefined : slots[slot + 2];
|
|
254
|
+
};
|
|
234
255
|
const recordNode = (check: Check, state: number, tableauNode: number) => {
|
|
235
256
|
const node = pushNode(check, state, tableauNode);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
257
|
+
const table = check.nodeIds;
|
|
258
|
+
if (++table.size * 2 > table.slots.length / 3) {
|
|
259
|
+
const old = table.slots;
|
|
260
|
+
table.slots = new Int32Array(old.length * 2);
|
|
261
|
+
table.shift--;
|
|
262
|
+
for (let slot = 0; slot < old.length; slot += 3) {
|
|
263
|
+
if (old[slot] !== 0)
|
|
264
|
+
table.slots.set(
|
|
265
|
+
old.subarray(slot, slot + 3),
|
|
266
|
+
getNodeSlot(table, old[slot] - 1, old[slot + 1]),
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
table.slots.set([state + 1, tableauNode, node], getNodeSlot(table, state, tableauNode));
|
|
240
271
|
return node;
|
|
241
272
|
};
|
|
273
|
+
// A state's nodes in the order they were recorded, which is the order of their ids.
|
|
274
|
+
const getStateNodes = (check: Check, tableau: Tableau, state: number) =>
|
|
275
|
+
tableau.nodes
|
|
276
|
+
.flatMap((_, tableauNode) => getNodeId(check, state, tableauNode) ?? [])
|
|
277
|
+
.sort((left, right) => left - right);
|
|
242
278
|
const writeNode = (
|
|
243
279
|
check: Check,
|
|
244
280
|
node: number,
|
|
@@ -246,11 +282,32 @@ export const createLivenessChecker = (
|
|
|
246
282
|
stateResults: Uint8Array,
|
|
247
283
|
) => {
|
|
248
284
|
const actionCount = check.solution.actionChecks.length;
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
285
|
+
const results = check.results;
|
|
286
|
+
const offset = results.length;
|
|
287
|
+
results.length += stateResults.length + actions.length * actionCount;
|
|
288
|
+
if (results.length > results.bytes.length) {
|
|
289
|
+
const grown = new Uint8Array(Math.max(2 * results.bytes.length, results.length));
|
|
290
|
+
grown.set(results.bytes);
|
|
291
|
+
results.bytes = grown;
|
|
292
|
+
}
|
|
293
|
+
results.bytes.set(stateResults, offset);
|
|
294
|
+
actions.forEach((edge, position) =>
|
|
295
|
+
results.bytes.set(edge, offset + stateResults.length + position * actionCount),
|
|
296
|
+
);
|
|
297
|
+
check.offsets[node] = offset;
|
|
298
|
+
const successors = check.pending[node] ?? [];
|
|
299
|
+
const edges = check.edges;
|
|
300
|
+
const edgeOffset = edges.length;
|
|
301
|
+
edges.length += successors.length + 1;
|
|
302
|
+
if (edges.length > edges.ids.length) {
|
|
303
|
+
const grown = new Int32Array(Math.max(2 * edges.ids.length, edges.length));
|
|
304
|
+
grown.set(edges.ids);
|
|
305
|
+
edges.ids = grown;
|
|
306
|
+
}
|
|
307
|
+
edges.ids[edgeOffset] = successors.length;
|
|
308
|
+
edges.ids.set(successors, edgeOffset + 1);
|
|
309
|
+
check.edgeOffsets[node] = edgeOffset;
|
|
310
|
+
check.pending[node] = undefined;
|
|
254
311
|
};
|
|
255
312
|
|
|
256
313
|
// TLC collects a state's successors and the state itself in a SetOfStates, a hash set it
|
|
@@ -303,7 +360,7 @@ export const createLivenessChecker = (
|
|
|
303
360
|
const stateResults = checkState(check, index, state);
|
|
304
361
|
const tableauNode = tableau.nodes[check.nodeTableaux[node]];
|
|
305
362
|
const actions: Uint8Array[] = [];
|
|
306
|
-
const successors = check
|
|
363
|
+
const successors = getPending(check, node);
|
|
307
364
|
const selfActions =
|
|
308
365
|
tableauNode.successors.length > 0
|
|
309
366
|
? checkAction(check, index, state, state)
|
|
@@ -352,8 +409,8 @@ export const createLivenessChecker = (
|
|
|
352
409
|
);
|
|
353
410
|
check.isDone[index] = true;
|
|
354
411
|
// TLC expands the nodes recorded before the loop, not the ones the loop records.
|
|
355
|
-
for (const node of (check
|
|
356
|
-
const successors = check
|
|
412
|
+
for (const node of getStateNodes(check, tableau, index)) {
|
|
413
|
+
const successors = getPending(check, node);
|
|
357
414
|
const actions: Uint8Array[] = [];
|
|
358
415
|
set.forEach((successor, position) => {
|
|
359
416
|
const isDone = check.isDone[successor.index] === true;
|
|
@@ -387,10 +444,10 @@ export const createLivenessChecker = (
|
|
|
387
444
|
index: number,
|
|
388
445
|
) => {
|
|
389
446
|
while (check.nodeStates.length <= index) pushNode(check, check.nodeStates.length, -1);
|
|
390
|
-
const successors = check
|
|
447
|
+
const successors = getPending(check, index);
|
|
391
448
|
const actions: Uint8Array[] = [];
|
|
392
449
|
set.forEach((successor, position) => {
|
|
393
|
-
if (check
|
|
450
|
+
if (isWritten(check, successor.index) && successors.includes(successor.index)) return;
|
|
394
451
|
successors.push(successor.index);
|
|
395
452
|
actions.push(actionResults[position]);
|
|
396
453
|
});
|
|
@@ -404,20 +461,20 @@ export const createLivenessChecker = (
|
|
|
404
461
|
const parents = new Map<number, number>();
|
|
405
462
|
const queue: number[] = [];
|
|
406
463
|
for (const node of check.initial) {
|
|
407
|
-
if (!check
|
|
464
|
+
if (!isWritten(check, node)) continue;
|
|
408
465
|
queue.push(node);
|
|
409
466
|
parents.set(node, -1);
|
|
410
467
|
}
|
|
411
468
|
for (let position = 0; position < queue.length; position++) {
|
|
412
469
|
const current = queue[position];
|
|
413
|
-
for (const next of check
|
|
470
|
+
for (const next of getSuccessors(check, current)) {
|
|
414
471
|
if (next === current && check.solution.tableau) continue;
|
|
415
472
|
if (next === target) {
|
|
416
473
|
const path = [target];
|
|
417
474
|
for (let node = current; node !== -1; node = parents.get(node) ?? -1) path.push(node);
|
|
418
475
|
return path;
|
|
419
476
|
}
|
|
420
|
-
if (!check
|
|
477
|
+
if (!isWritten(check, next) || parents.has(next)) continue;
|
|
421
478
|
parents.set(next, current);
|
|
422
479
|
queue.push(next);
|
|
423
480
|
}
|
|
@@ -429,16 +486,17 @@ export const createLivenessChecker = (
|
|
|
429
486
|
const findInModel = (check: Check, model: Solution["models"][number]): Lasso | undefined => {
|
|
430
487
|
const solution = check.solution;
|
|
431
488
|
const actionCount = solution.actionChecks.length;
|
|
489
|
+
const stateCount = solution.stateChecks.length;
|
|
432
490
|
const getAction = (node: number, edge: number, position: number) =>
|
|
433
|
-
check.
|
|
491
|
+
check.results.bytes[check.offsets[node] + stateCount + edge * actionCount + position] === 1;
|
|
434
492
|
const isAllowed = (node: number, edge: number) =>
|
|
435
493
|
model.eventuallyAlways.every((position) => getAction(node, edge, position));
|
|
436
494
|
const links = new Float64Array(check.nodeStates.length).fill(UNVISITED);
|
|
437
|
-
const queue = check.initial.filter((node) => check
|
|
495
|
+
const queue = check.initial.filter((node) => isWritten(check, node));
|
|
438
496
|
const components: number[] = [];
|
|
439
497
|
|
|
440
498
|
const isStuttering = (node: number) => {
|
|
441
|
-
const edge = check
|
|
499
|
+
const edge = getSuccessors(check, node).indexOf(node);
|
|
442
500
|
return edge !== -1 && isAllowed(node, edge);
|
|
443
501
|
};
|
|
444
502
|
const isFulfilled = (node: number, promise: Solution["promises"][number]) =>
|
|
@@ -462,11 +520,11 @@ export const createLivenessChecker = (
|
|
|
462
520
|
if (member === root) break;
|
|
463
521
|
}
|
|
464
522
|
const isStateSatisfied = model.infinitelyOftenStates.every((position) =>
|
|
465
|
-
[...members].some((node) => check
|
|
523
|
+
[...members].some((node) => getStateResult(check, node, position)),
|
|
466
524
|
);
|
|
467
525
|
const isActionSatisfied = model.infinitelyOftenActions.every((position) =>
|
|
468
526
|
[...members].some((node) =>
|
|
469
|
-
check
|
|
527
|
+
getSuccessors(check, node).some(
|
|
470
528
|
(next, edge) =>
|
|
471
529
|
members.has(next) && isAllowed(node, edge) && getAction(node, edge, position),
|
|
472
530
|
),
|
|
@@ -507,7 +565,7 @@ export const createLivenessChecker = (
|
|
|
507
565
|
const countAtStart = remaining.count;
|
|
508
566
|
while (true) {
|
|
509
567
|
model.infinitelyOftenStates.forEach((position, slot) => {
|
|
510
|
-
if (!stateDone[slot] && check
|
|
568
|
+
if (!stateDone[slot] && getStateResult(check, current.node, position)) {
|
|
511
569
|
stateDone[slot] = true;
|
|
512
570
|
remaining.count--;
|
|
513
571
|
}
|
|
@@ -521,7 +579,7 @@ export const createLivenessChecker = (
|
|
|
521
579
|
if (remaining.count <= 0) break;
|
|
522
580
|
const step = { last: -1, unvisited: -1 };
|
|
523
581
|
const countBeforeActions = remaining.count;
|
|
524
|
-
const successors = check
|
|
582
|
+
const successors = getSuccessors(check, current.node);
|
|
525
583
|
const taken = successors.some((next, edge) => {
|
|
526
584
|
if (membersByState.has(check.nodeStates[next])) {
|
|
527
585
|
if (!isMember(next) || !isAllowed(current.node, edge)) return false;
|
|
@@ -556,7 +614,8 @@ export const createLivenessChecker = (
|
|
|
556
614
|
}
|
|
557
615
|
current.node = previous;
|
|
558
616
|
step.unvisited =
|
|
559
|
-
check
|
|
617
|
+
getSuccessors(check, previous).find((next) => isMember(next) && !seen.has(next)) ??
|
|
618
|
+
-1;
|
|
560
619
|
}
|
|
561
620
|
take(step.unvisited);
|
|
562
621
|
seen.add(step.unvisited);
|
|
@@ -586,7 +645,7 @@ export const createLivenessChecker = (
|
|
|
586
645
|
const queue: [number, number][] = [];
|
|
587
646
|
for (let state = start, parent = -1, position = 0; ; position++) {
|
|
588
647
|
for (const node of membersByState.get(state) ?? []) {
|
|
589
|
-
for (const [edge, next] of check
|
|
648
|
+
for (const [edge, next] of getSuccessors(check, node).entries()) {
|
|
590
649
|
if (next === node || !isAllowedEdge(node, edge)) continue;
|
|
591
650
|
if (next === root) {
|
|
592
651
|
const path: number[] = [];
|
|
@@ -639,8 +698,8 @@ export const createLivenessChecker = (
|
|
|
639
698
|
stack.push(lowLink, node, SCC_MARKER);
|
|
640
699
|
components.push(node);
|
|
641
700
|
const nextLowLink = { value: counter.link++ };
|
|
642
|
-
check
|
|
643
|
-
if (!check
|
|
701
|
+
getSuccessors(check, node).forEach((next, edge) => {
|
|
702
|
+
if (!isWritten(check, next)) return;
|
|
644
703
|
if (!isAllowed(node, edge)) {
|
|
645
704
|
if (links[next] === UNVISITED) queue.push(next);
|
|
646
705
|
return;
|
package/src/liveness.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isLocallyResolved, type Definition, type Expression } from "./ast";
|
|
2
|
-
import {
|
|
2
|
+
import { STACK_OVERFLOW, TlaEvaluationError } from "./errors";
|
|
3
3
|
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
4
4
|
import {
|
|
5
5
|
describeLocation,
|
|
@@ -191,7 +191,7 @@ export const expandTemporal = (
|
|
|
191
191
|
getDefinitionLevel(definition, environment) > 0
|
|
192
192
|
) {
|
|
193
193
|
if (expanding.has(definition)) {
|
|
194
|
-
throw new
|
|
194
|
+
throw setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error);
|
|
195
195
|
}
|
|
196
196
|
return expand(
|
|
197
197
|
definition.body,
|
|
@@ -299,9 +299,7 @@ export const toLiveExpression = (
|
|
|
299
299
|
scope: Scope | undefined,
|
|
300
300
|
) => {
|
|
301
301
|
if (expansion.depth >= MAXIMUM_EXPANSION_DEPTH) {
|
|
302
|
-
throw new TlaEvaluationError(
|
|
303
|
-
`TLC overflowed the stack while expanding the temporal formula at ${describeLocation(expression)}`,
|
|
304
|
-
);
|
|
302
|
+
throw setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error);
|
|
305
303
|
}
|
|
306
304
|
expansion.depth++;
|
|
307
305
|
const result = convert(body, bodyScope);
|
package/src/parallel-worker.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
WorkerMessage,
|
|
16
16
|
} from "./parallel";
|
|
17
17
|
import { getSuccessors, type Successor } from "./successors";
|
|
18
|
-
import { getTlcStringOrder,
|
|
18
|
+
import { getTlcStringOrder, getTlcDeclarationOrder } from "./tlc-order";
|
|
19
19
|
import { OUT_DEGREE_BUCKETS } from "./tlc-summary";
|
|
20
20
|
import { createStateDecoder, createStateEncoder, type EncodedStates } from "./transfer";
|
|
21
21
|
import { getRankedStringCount, setStringOrder, type Value } from "./values";
|
|
@@ -61,7 +61,7 @@ const run = (start: StartMessage, parent: Port) => {
|
|
|
61
61
|
});
|
|
62
62
|
const environment = specification.environment;
|
|
63
63
|
const search = createSearch(start.config, environment, () =>
|
|
64
|
-
|
|
64
|
+
getTlcDeclarationOrder(start.source, loadModule, "variable"),
|
|
65
65
|
);
|
|
66
66
|
const nextAction = search?.spec.next;
|
|
67
67
|
if (!search || nextAction === undefined)
|
package/src/parallel.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
type SharedFingerprints,
|
|
21
21
|
} from "./fingerprints";
|
|
22
22
|
import { getInitialStates } from "./successors";
|
|
23
|
-
import { getTlcStringOrder,
|
|
23
|
+
import { getTlcStringOrder, getTlcDeclarationOrder } from "./tlc-order";
|
|
24
24
|
import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc-summary";
|
|
25
25
|
import { createStateEncoder, type EncodedStates } from "./transfer";
|
|
26
26
|
import { getRankedStringCount, setStringOrder, type Value } from "./values";
|
|
@@ -150,7 +150,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
150
150
|
});
|
|
151
151
|
const environment = specification.environment;
|
|
152
152
|
const search = createSearch(config, environment, () =>
|
|
153
|
-
|
|
153
|
+
getTlcDeclarationOrder(options.source, loadModule, "variable"),
|
|
154
154
|
);
|
|
155
155
|
if (findAssumptionViolation(specification.assumptions, environment)) return fallBack();
|
|
156
156
|
if (
|
package/src/successors.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type QuantifierExpression,
|
|
8
8
|
} from "./ast";
|
|
9
9
|
import { getReadVariables } from "./dependencies";
|
|
10
|
-
import { TlaEvaluationError,
|
|
10
|
+
import { TlaEvaluationError, TlaIncompleteStateError } from "./errors";
|
|
11
11
|
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
12
12
|
import {
|
|
13
13
|
describeLocation,
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
bindValue,
|
|
19
19
|
compileArgumentScope,
|
|
20
20
|
evaluate,
|
|
21
|
+
getEntryEvaluator,
|
|
21
22
|
expectBoolean,
|
|
22
23
|
forEachBinding,
|
|
23
24
|
getBoundsDomain,
|
|
@@ -29,6 +30,7 @@ import {
|
|
|
29
30
|
resolveGlobalOperator,
|
|
30
31
|
type Context,
|
|
31
32
|
type Environment,
|
|
33
|
+
type Evaluator,
|
|
32
34
|
type Scope,
|
|
33
35
|
type State,
|
|
34
36
|
} from "./evaluate";
|
|
@@ -87,15 +89,25 @@ const assign = (partial: State, index: number, value: Value) => {
|
|
|
87
89
|
return copy;
|
|
88
90
|
};
|
|
89
91
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
// TLC's Tool.getInitStates and Tool.getNextStates report a value where they expect a formula.
|
|
93
|
+
const expectFormula = (expression: Expression, value: Value, isInit: boolean) => {
|
|
92
94
|
if (typeof value === "boolean") return value;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
throw new TlaEvaluationError(
|
|
96
|
+
`In computing ${isInit ? "initial" : "next"} states, TLC expected a boolean expression,\nbut instead found ${formatValue(value)}.\n${describeRange(expression)}`,
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const holds = (expression: Expression, context: Context, value = evaluate(expression, context)) => {
|
|
101
|
+
// TLC rejects a number in the next-state relation when it splits the relation into actions.
|
|
102
|
+
if (context.next !== undefined && expression.kind === "Number") {
|
|
103
|
+
throw setExitCode(
|
|
104
|
+
new TlaEvaluationError(
|
|
105
|
+
`The next state relation is not a boolean expression.\n${expression.text ?? expression.value}`,
|
|
106
|
+
),
|
|
107
|
+
EXIT_STATUS.error,
|
|
108
|
+
);
|
|
98
109
|
}
|
|
110
|
+
return expectFormula(expression, value, context.next === undefined);
|
|
99
111
|
};
|
|
100
112
|
|
|
101
113
|
const isAssignmentOperator = (operator: string) =>
|
|
@@ -320,6 +332,7 @@ const compileConjunction = (
|
|
|
320
332
|
isInit: boolean,
|
|
321
333
|
): Runner => {
|
|
322
334
|
const conjuncts = operands.map((operand) => toConjunct(operand, environment, isInit));
|
|
335
|
+
const evaluators: (Evaluator | undefined)[] = conjuncts.map(() => undefined);
|
|
323
336
|
const runFrom = (
|
|
324
337
|
start: number,
|
|
325
338
|
run: Run,
|
|
@@ -342,12 +355,17 @@ const compileConjunction = (
|
|
|
342
355
|
const conjunct = conjuncts[index];
|
|
343
356
|
if (conjunct.kind === "Guard") {
|
|
344
357
|
context ??= getContext(run, scope, current);
|
|
345
|
-
|
|
358
|
+
const evaluator = (evaluators[index] ??= getEntryEvaluator(
|
|
359
|
+
conjunct.expression,
|
|
360
|
+
environment,
|
|
361
|
+
));
|
|
362
|
+
if (!holds(conjunct.expression, context, evaluator(context))) return;
|
|
346
363
|
continue;
|
|
347
364
|
}
|
|
348
365
|
if (conjunct.kind === "Assign") {
|
|
349
366
|
context ??= getContext(run, scope, current);
|
|
350
|
-
const
|
|
367
|
+
const evaluator = (evaluators[index] ??= getEntryEvaluator(conjunct.value, environment));
|
|
368
|
+
const value = evaluator(context);
|
|
351
369
|
const assigned = current[conjunct.index];
|
|
352
370
|
if (assigned === undefined) {
|
|
353
371
|
current = assign(current, conjunct.index, value);
|
|
@@ -384,10 +402,7 @@ const compileConjunction = (
|
|
|
384
402
|
};
|
|
385
403
|
|
|
386
404
|
const holdsInInit = (expression: Expression, context: Context) =>
|
|
387
|
-
|
|
388
|
-
evaluate(expression, context),
|
|
389
|
-
`the initial predicate at ${describeLocation(expression)}`,
|
|
390
|
-
);
|
|
405
|
+
expectFormula(expression, evaluate(expression, context), true);
|
|
391
406
|
|
|
392
407
|
const compileGuard =
|
|
393
408
|
(expression: Expression): Runner =>
|
|
@@ -412,7 +427,7 @@ const compileMembership = (
|
|
|
412
427
|
expression.operator === "\\subseteq" ? { kind: "Subset", base: evaluated } : evaluated;
|
|
413
428
|
if (!isEnumerable(value)) {
|
|
414
429
|
throw new TlaEvaluationError(
|
|
415
|
-
`In computing next states, the right side of \\
|
|
430
|
+
`In computing ${run.isInit ? "initial" : "next"} states, the right side of \\IN is not enumerable.\n${describeRange(expression)}`,
|
|
416
431
|
);
|
|
417
432
|
}
|
|
418
433
|
const elements = getStreamedElements(value);
|
|
@@ -859,7 +874,7 @@ const compileAction = (
|
|
|
859
874
|
const body = arm?.body ?? other;
|
|
860
875
|
if (!body)
|
|
861
876
|
throw new TlaEvaluationError(
|
|
862
|
-
|
|
877
|
+
`In computing ${run.isInit ? "initial" : "next"} states, TLC encountered a CASE with no conditions true.\n${describeRange(expression)}`,
|
|
863
878
|
);
|
|
864
879
|
body(run, scope, partial, action, isFixed, onComplete);
|
|
865
880
|
};
|
|
@@ -1050,8 +1065,10 @@ export const forEachSuccessor = (
|
|
|
1050
1065
|
(partial, action) => {
|
|
1051
1066
|
if (run.isStopped) return;
|
|
1052
1067
|
if (!isComplete(partial)) {
|
|
1053
|
-
throw new
|
|
1054
|
-
|
|
1068
|
+
throw new TlaIncompleteStateError(
|
|
1069
|
+
partial,
|
|
1070
|
+
action,
|
|
1071
|
+
getMissingVariables(partial, environment).sort(),
|
|
1055
1072
|
);
|
|
1056
1073
|
}
|
|
1057
1074
|
counter.successors++;
|
package/src/symmetry.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { TlaConfigError } from "./errors";
|
|
1
|
+
import { TlaConfigError, TlaEvaluationError, UNEXPECTED_EXCEPTION } from "./errors";
|
|
2
2
|
import { evaluate, type Environment } from "./evaluate";
|
|
3
|
+
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
3
4
|
import {
|
|
4
5
|
compareValues,
|
|
5
6
|
createFunction,
|
|
@@ -47,9 +48,13 @@ const composePermutations = (first: Images, second: Images) => {
|
|
|
47
48
|
return composed;
|
|
48
49
|
};
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
// TLC checks the symmetry set outside any phase that reports an error itself.
|
|
52
|
+
const createSymmetryError = (message: string) =>
|
|
53
|
+
setExitCode(new TlaEvaluationError(`${UNEXPECTED_EXCEPTION}${message}`), EXIT_STATUS.error);
|
|
54
|
+
|
|
55
|
+
const toImages = (value: Value) => {
|
|
51
56
|
if (!isFunctionValue(value)) {
|
|
52
|
-
throw
|
|
57
|
+
throw createSymmetryError("The symmetry values must be function records.");
|
|
53
58
|
}
|
|
54
59
|
const functionValue = toFiniteFunction(value);
|
|
55
60
|
const permutation: Images = new Map();
|
|
@@ -65,8 +70,13 @@ const toImages = (value: Value, name: string) => {
|
|
|
65
70
|
|
|
66
71
|
export const getSymmetryGroup = (name: string, environment: Environment): Permutation[] => {
|
|
67
72
|
const definition = environment.definitions.get(name);
|
|
73
|
+
if (definition === undefined && !environment.constants.has(name)) {
|
|
74
|
+
throw new TlaConfigError(
|
|
75
|
+
`The symmetry function ${name} specified in the configuration file\nis not defined in the specification.`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
68
78
|
if (definition?.kind !== "Operator" || definition.params.length > 0) {
|
|
69
|
-
throw
|
|
79
|
+
throw createSymmetryError(`The symmetry function ${name} must specify a set of permutations.`);
|
|
70
80
|
}
|
|
71
81
|
const value = evaluate(definition.body, {
|
|
72
82
|
environment,
|
|
@@ -75,9 +85,9 @@ export const getSymmetryGroup = (name: string, environment: Environment): Permut
|
|
|
75
85
|
next: undefined,
|
|
76
86
|
});
|
|
77
87
|
if (!isSetValue(value) || !isEnumerable(value)) {
|
|
78
|
-
throw
|
|
88
|
+
throw createSymmetryError("The symmetry operator must specify a set of functions.");
|
|
79
89
|
}
|
|
80
|
-
const permutations = toFiniteSet(value).elements.map(
|
|
90
|
+
const permutations = toFiniteSet(value).elements.map(toImages);
|
|
81
91
|
const isDisabled =
|
|
82
92
|
definition.body.kind === "Apply" && definition.body.args.length >= permutations.length;
|
|
83
93
|
if (isDisabled) return [];
|