tla-ts 0.0.3-dev.b1578d0 → 0.0.3-dev.bcfa494
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/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 +14 -14
- package/dist/transfer.js +14 -14
- package/package.json +1 -1
- package/src/check.ts +67 -22
- package/src/environment.ts +78 -10
- package/src/errors.ts +9 -0
- package/src/evaluate.ts +10 -7
- package/src/instances.ts +3 -3
- package/src/live-check.ts +126 -70
- package/src/liveness.ts +51 -14
- package/src/parallel-worker.ts +2 -2
- package/src/parallel.ts +2 -2
- package/src/runtime.ts +2 -0
- package/src/standard-modules.ts +2 -7
- package/src/successors.ts +63 -7
- package/src/tableau.ts +50 -23
- package/src/tlc-module.ts +6 -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 +48 -11
package/src/live-check.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { TlaEvaluationError } from "./errors";
|
|
|
2
2
|
import { hasRepeatedEffects, type Environment } from "./evaluate";
|
|
3
3
|
import {
|
|
4
4
|
evaluateLive,
|
|
5
|
+
TAUTOLOGY_MESSAGE,
|
|
5
6
|
evaluateOnLasso,
|
|
6
7
|
toLiveExpression,
|
|
7
8
|
type ScopedExpression,
|
|
@@ -11,6 +12,7 @@ import {
|
|
|
11
12
|
createJunction,
|
|
12
13
|
createUnary,
|
|
13
14
|
getSolutions,
|
|
15
|
+
getTermKey,
|
|
14
16
|
isFulfilling,
|
|
15
17
|
type LiveExpression,
|
|
16
18
|
type Solution,
|
|
@@ -47,37 +49,21 @@ interface Check {
|
|
|
47
49
|
actionIds: Int32Array;
|
|
48
50
|
nodeStates: number[];
|
|
49
51
|
nodeTableaux: number[];
|
|
50
|
-
successors
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
// The successors a node gathers until it is written.
|
|
53
|
+
pending: (number[] | undefined)[];
|
|
54
|
+
// Each written node's state results, then its action results edge by edge, from the node's
|
|
55
|
+
// offset in one buffer, so a node costs no objects of its own. An unwritten node has offset -1.
|
|
56
|
+
offsets: number[];
|
|
57
|
+
results: { bytes: Uint8Array; length: number };
|
|
58
|
+
// Each written node's successor count, then its successors, from the node's edge offset.
|
|
59
|
+
edgeOffsets: number[];
|
|
60
|
+
edges: { ids: Int32Array; length: number };
|
|
54
61
|
initial: number[];
|
|
55
|
-
nodeIds:
|
|
56
|
-
nodesByState: Map<number, number[]>;
|
|
62
|
+
nodeIds: NodeTable;
|
|
57
63
|
isDone: boolean[];
|
|
58
64
|
errorNode: number | undefined;
|
|
59
65
|
}
|
|
60
66
|
|
|
61
|
-
const liveKeys = new WeakMap<LiveExpression, string>();
|
|
62
|
-
|
|
63
|
-
const atomCount = { value: 0 };
|
|
64
|
-
|
|
65
|
-
// Each solution builds its own junctions over shared atoms, so equal checks get equal keys.
|
|
66
|
-
const getLiveKey = (expression: LiveExpression): string => {
|
|
67
|
-
const cached = liveKeys.get(expression);
|
|
68
|
-
if (cached !== undefined) return cached;
|
|
69
|
-
const key =
|
|
70
|
-
expression.kind === "Boolean"
|
|
71
|
-
? String(expression.value)
|
|
72
|
-
: "body" in expression
|
|
73
|
-
? `${expression.kind}(${getLiveKey(expression.body)})`
|
|
74
|
-
: "operands" in expression
|
|
75
|
-
? `${expression.kind}(${expression.operands.map(getLiveKey).join(",")})`
|
|
76
|
-
: `${expression.kind}#${atomCount.value++}`;
|
|
77
|
-
liveKeys.set(expression, key);
|
|
78
|
-
return key;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
67
|
const isSameState = (left: Value[], right: Value[]) =>
|
|
82
68
|
left.every((value, position) => isSameValue(value, right[position]));
|
|
83
69
|
|
|
@@ -88,13 +74,43 @@ const removeRepeats = (path: number[]) =>
|
|
|
88
74
|
const pushNode = (check: Check, state: number, tableauNode: number) => {
|
|
89
75
|
check.nodeStates.push(state);
|
|
90
76
|
check.nodeTableaux.push(tableauNode);
|
|
91
|
-
check.
|
|
92
|
-
check.
|
|
93
|
-
check.
|
|
94
|
-
check.isWritten.push(false);
|
|
77
|
+
check.pending.push(undefined);
|
|
78
|
+
check.offsets.push(-1);
|
|
79
|
+
check.edgeOffsets.push(-1);
|
|
95
80
|
return check.nodeStates.length - 1;
|
|
96
81
|
};
|
|
97
82
|
|
|
83
|
+
// A Map holds at most 2^24 entries, so each tableau node of a state finds its node in an
|
|
84
|
+
// open-addressing table of (state plus one, tableau node, node) triples.
|
|
85
|
+
interface NodeTable {
|
|
86
|
+
slots: Int32Array;
|
|
87
|
+
size: number;
|
|
88
|
+
shift: number;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const getNodeSlot = (table: NodeTable, state: number, tableauNode: number) => {
|
|
92
|
+
const mask = table.slots.length / 3 - 1;
|
|
93
|
+
const hash = Math.imul(Math.imul(state, 0x9e3779b1) ^ tableauNode, 0x85ebca6b) >>> table.shift;
|
|
94
|
+
for (let index = hash; ; index = (index + 1) & mask) {
|
|
95
|
+
const slot = index * 3;
|
|
96
|
+
const stored = table.slots[slot];
|
|
97
|
+
if (stored === 0 || (stored === state + 1 && table.slots[slot + 1] === tableauNode))
|
|
98
|
+
return slot;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const isWritten = (check: Check, node: number) => check.offsets[node] !== -1;
|
|
103
|
+
|
|
104
|
+
const getPending = (check: Check, node: number) => (check.pending[node] ??= []);
|
|
105
|
+
|
|
106
|
+
const getSuccessors = (check: Check, node: number) => {
|
|
107
|
+
const offset = check.edgeOffsets[node];
|
|
108
|
+
return check.edges.ids.subarray(offset + 1, offset + 1 + check.edges.ids[offset]);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const getStateResult = (check: Check, node: number, position: number) =>
|
|
112
|
+
check.results.bytes[check.offsets[node] + position] === 1;
|
|
113
|
+
|
|
98
114
|
const SUCCESSOR_CAPACITY = 16;
|
|
99
115
|
|
|
100
116
|
const SCC_MARKER = -42;
|
|
@@ -121,26 +137,26 @@ export const createLivenessChecker = (
|
|
|
121
137
|
fairness.length === 0 ? violation : createJunction("And", [...fairness, violation]);
|
|
122
138
|
const solutions = getSolutions(formula);
|
|
123
139
|
if (solutions.length === 0) {
|
|
124
|
-
throw new TlaEvaluationError(
|
|
140
|
+
throw new TlaEvaluationError(TAUTOLOGY_MESSAGE);
|
|
125
141
|
}
|
|
126
142
|
const actionIds = new Map<string, number>();
|
|
127
143
|
const checks = solutions.map((solution): Check => ({
|
|
128
144
|
solution,
|
|
129
145
|
actionIds: Int32Array.from(solution.actionChecks, (predicate) => {
|
|
130
|
-
const key =
|
|
146
|
+
const key = getTermKey(predicate);
|
|
131
147
|
const id = actionIds.get(key) ?? actionIds.size;
|
|
132
148
|
actionIds.set(key, id);
|
|
133
149
|
return id;
|
|
134
150
|
}),
|
|
135
151
|
nodeStates: [],
|
|
136
152
|
nodeTableaux: [],
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
153
|
+
pending: [],
|
|
154
|
+
offsets: [],
|
|
155
|
+
results: { bytes: new Uint8Array(1024), length: 0 },
|
|
156
|
+
edgeOffsets: [],
|
|
157
|
+
edges: { ids: new Int32Array(1024), length: 0 },
|
|
141
158
|
initial: [],
|
|
142
|
-
nodeIds: new
|
|
143
|
-
nodesByState: new Map(),
|
|
159
|
+
nodeIds: { slots: new Int32Array(3 << 10), size: 0, shift: 22 },
|
|
144
160
|
isDone: [],
|
|
145
161
|
errorNode: undefined,
|
|
146
162
|
}));
|
|
@@ -226,18 +242,35 @@ export const createLivenessChecker = (
|
|
|
226
242
|
model.infinitelyOftenActions.length === 0,
|
|
227
243
|
);
|
|
228
244
|
|
|
229
|
-
const getNodeId = (check: Check, state: number, tableauNode: number) =>
|
|
230
|
-
check.solution.tableau
|
|
231
|
-
|
|
232
|
-
|
|
245
|
+
const getNodeId = (check: Check, state: number, tableauNode: number) => {
|
|
246
|
+
if (!check.solution.tableau) return state;
|
|
247
|
+
const slots = check.nodeIds.slots;
|
|
248
|
+
const slot = getNodeSlot(check.nodeIds, state, tableauNode);
|
|
249
|
+
return slots[slot] === 0 ? undefined : slots[slot + 2];
|
|
250
|
+
};
|
|
233
251
|
const recordNode = (check: Check, state: number, tableauNode: number) => {
|
|
234
252
|
const node = pushNode(check, state, tableauNode);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
253
|
+
const table = check.nodeIds;
|
|
254
|
+
if (++table.size * 2 > table.slots.length / 3) {
|
|
255
|
+
const old = table.slots;
|
|
256
|
+
table.slots = new Int32Array(old.length * 2);
|
|
257
|
+
table.shift--;
|
|
258
|
+
for (let slot = 0; slot < old.length; slot += 3) {
|
|
259
|
+
if (old[slot] !== 0)
|
|
260
|
+
table.slots.set(
|
|
261
|
+
old.subarray(slot, slot + 3),
|
|
262
|
+
getNodeSlot(table, old[slot] - 1, old[slot + 1]),
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
table.slots.set([state + 1, tableauNode, node], getNodeSlot(table, state, tableauNode));
|
|
239
267
|
return node;
|
|
240
268
|
};
|
|
269
|
+
// A state's nodes in the order they were recorded, which is the order of their ids.
|
|
270
|
+
const getStateNodes = (check: Check, tableau: Tableau, state: number) =>
|
|
271
|
+
tableau.nodes
|
|
272
|
+
.flatMap((_, tableauNode) => getNodeId(check, state, tableauNode) ?? [])
|
|
273
|
+
.sort((left, right) => left - right);
|
|
241
274
|
const writeNode = (
|
|
242
275
|
check: Check,
|
|
243
276
|
node: number,
|
|
@@ -245,11 +278,32 @@ export const createLivenessChecker = (
|
|
|
245
278
|
stateResults: Uint8Array,
|
|
246
279
|
) => {
|
|
247
280
|
const actionCount = check.solution.actionChecks.length;
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
281
|
+
const results = check.results;
|
|
282
|
+
const offset = results.length;
|
|
283
|
+
results.length += stateResults.length + actions.length * actionCount;
|
|
284
|
+
if (results.length > results.bytes.length) {
|
|
285
|
+
const grown = new Uint8Array(Math.max(2 * results.bytes.length, results.length));
|
|
286
|
+
grown.set(results.bytes);
|
|
287
|
+
results.bytes = grown;
|
|
288
|
+
}
|
|
289
|
+
results.bytes.set(stateResults, offset);
|
|
290
|
+
actions.forEach((edge, position) =>
|
|
291
|
+
results.bytes.set(edge, offset + stateResults.length + position * actionCount),
|
|
292
|
+
);
|
|
293
|
+
check.offsets[node] = offset;
|
|
294
|
+
const successors = check.pending[node] ?? [];
|
|
295
|
+
const edges = check.edges;
|
|
296
|
+
const edgeOffset = edges.length;
|
|
297
|
+
edges.length += successors.length + 1;
|
|
298
|
+
if (edges.length > edges.ids.length) {
|
|
299
|
+
const grown = new Int32Array(Math.max(2 * edges.ids.length, edges.length));
|
|
300
|
+
grown.set(edges.ids);
|
|
301
|
+
edges.ids = grown;
|
|
302
|
+
}
|
|
303
|
+
edges.ids[edgeOffset] = successors.length;
|
|
304
|
+
edges.ids.set(successors, edgeOffset + 1);
|
|
305
|
+
check.edgeOffsets[node] = edgeOffset;
|
|
306
|
+
check.pending[node] = undefined;
|
|
253
307
|
};
|
|
254
308
|
|
|
255
309
|
// TLC collects a state's successors and the state itself in a SetOfStates, a hash set it
|
|
@@ -302,7 +356,7 @@ export const createLivenessChecker = (
|
|
|
302
356
|
const stateResults = checkState(check, index, state);
|
|
303
357
|
const tableauNode = tableau.nodes[check.nodeTableaux[node]];
|
|
304
358
|
const actions: Uint8Array[] = [];
|
|
305
|
-
const successors = check
|
|
359
|
+
const successors = getPending(check, node);
|
|
306
360
|
const selfActions =
|
|
307
361
|
tableauNode.successors.length > 0
|
|
308
362
|
? checkAction(check, index, state, state)
|
|
@@ -351,8 +405,8 @@ export const createLivenessChecker = (
|
|
|
351
405
|
);
|
|
352
406
|
check.isDone[index] = true;
|
|
353
407
|
// TLC expands the nodes recorded before the loop, not the ones the loop records.
|
|
354
|
-
for (const node of (check
|
|
355
|
-
const successors = check
|
|
408
|
+
for (const node of getStateNodes(check, tableau, index)) {
|
|
409
|
+
const successors = getPending(check, node);
|
|
356
410
|
const actions: Uint8Array[] = [];
|
|
357
411
|
set.forEach((successor, position) => {
|
|
358
412
|
const isDone = check.isDone[successor.index] === true;
|
|
@@ -386,10 +440,10 @@ export const createLivenessChecker = (
|
|
|
386
440
|
index: number,
|
|
387
441
|
) => {
|
|
388
442
|
while (check.nodeStates.length <= index) pushNode(check, check.nodeStates.length, -1);
|
|
389
|
-
const successors = check
|
|
443
|
+
const successors = getPending(check, index);
|
|
390
444
|
const actions: Uint8Array[] = [];
|
|
391
445
|
set.forEach((successor, position) => {
|
|
392
|
-
if (check
|
|
446
|
+
if (isWritten(check, successor.index) && successors.includes(successor.index)) return;
|
|
393
447
|
successors.push(successor.index);
|
|
394
448
|
actions.push(actionResults[position]);
|
|
395
449
|
});
|
|
@@ -403,20 +457,20 @@ export const createLivenessChecker = (
|
|
|
403
457
|
const parents = new Map<number, number>();
|
|
404
458
|
const queue: number[] = [];
|
|
405
459
|
for (const node of check.initial) {
|
|
406
|
-
if (!check
|
|
460
|
+
if (!isWritten(check, node)) continue;
|
|
407
461
|
queue.push(node);
|
|
408
462
|
parents.set(node, -1);
|
|
409
463
|
}
|
|
410
464
|
for (let position = 0; position < queue.length; position++) {
|
|
411
465
|
const current = queue[position];
|
|
412
|
-
for (const next of check
|
|
466
|
+
for (const next of getSuccessors(check, current)) {
|
|
413
467
|
if (next === current && check.solution.tableau) continue;
|
|
414
468
|
if (next === target) {
|
|
415
469
|
const path = [target];
|
|
416
470
|
for (let node = current; node !== -1; node = parents.get(node) ?? -1) path.push(node);
|
|
417
471
|
return path;
|
|
418
472
|
}
|
|
419
|
-
if (!check
|
|
473
|
+
if (!isWritten(check, next) || parents.has(next)) continue;
|
|
420
474
|
parents.set(next, current);
|
|
421
475
|
queue.push(next);
|
|
422
476
|
}
|
|
@@ -428,16 +482,17 @@ export const createLivenessChecker = (
|
|
|
428
482
|
const findInModel = (check: Check, model: Solution["models"][number]): Lasso | undefined => {
|
|
429
483
|
const solution = check.solution;
|
|
430
484
|
const actionCount = solution.actionChecks.length;
|
|
485
|
+
const stateCount = solution.stateChecks.length;
|
|
431
486
|
const getAction = (node: number, edge: number, position: number) =>
|
|
432
|
-
check.
|
|
487
|
+
check.results.bytes[check.offsets[node] + stateCount + edge * actionCount + position] === 1;
|
|
433
488
|
const isAllowed = (node: number, edge: number) =>
|
|
434
489
|
model.eventuallyAlways.every((position) => getAction(node, edge, position));
|
|
435
490
|
const links = new Float64Array(check.nodeStates.length).fill(UNVISITED);
|
|
436
|
-
const queue = check.initial.filter((node) => check
|
|
491
|
+
const queue = check.initial.filter((node) => isWritten(check, node));
|
|
437
492
|
const components: number[] = [];
|
|
438
493
|
|
|
439
494
|
const isStuttering = (node: number) => {
|
|
440
|
-
const edge = check
|
|
495
|
+
const edge = getSuccessors(check, node).indexOf(node);
|
|
441
496
|
return edge !== -1 && isAllowed(node, edge);
|
|
442
497
|
};
|
|
443
498
|
const isFulfilled = (node: number, promise: Solution["promises"][number]) =>
|
|
@@ -461,11 +516,11 @@ export const createLivenessChecker = (
|
|
|
461
516
|
if (member === root) break;
|
|
462
517
|
}
|
|
463
518
|
const isStateSatisfied = model.infinitelyOftenStates.every((position) =>
|
|
464
|
-
[...members].some((node) => check
|
|
519
|
+
[...members].some((node) => getStateResult(check, node, position)),
|
|
465
520
|
);
|
|
466
521
|
const isActionSatisfied = model.infinitelyOftenActions.every((position) =>
|
|
467
522
|
[...members].some((node) =>
|
|
468
|
-
check
|
|
523
|
+
getSuccessors(check, node).some(
|
|
469
524
|
(next, edge) =>
|
|
470
525
|
members.has(next) && isAllowed(node, edge) && getAction(node, edge, position),
|
|
471
526
|
),
|
|
@@ -506,7 +561,7 @@ export const createLivenessChecker = (
|
|
|
506
561
|
const countAtStart = remaining.count;
|
|
507
562
|
while (true) {
|
|
508
563
|
model.infinitelyOftenStates.forEach((position, slot) => {
|
|
509
|
-
if (!stateDone[slot] && check
|
|
564
|
+
if (!stateDone[slot] && getStateResult(check, current.node, position)) {
|
|
510
565
|
stateDone[slot] = true;
|
|
511
566
|
remaining.count--;
|
|
512
567
|
}
|
|
@@ -520,7 +575,7 @@ export const createLivenessChecker = (
|
|
|
520
575
|
if (remaining.count <= 0) break;
|
|
521
576
|
const step = { last: -1, unvisited: -1 };
|
|
522
577
|
const countBeforeActions = remaining.count;
|
|
523
|
-
const successors = check
|
|
578
|
+
const successors = getSuccessors(check, current.node);
|
|
524
579
|
const taken = successors.some((next, edge) => {
|
|
525
580
|
if (membersByState.has(check.nodeStates[next])) {
|
|
526
581
|
if (!isMember(next) || !isAllowed(current.node, edge)) return false;
|
|
@@ -555,7 +610,8 @@ export const createLivenessChecker = (
|
|
|
555
610
|
}
|
|
556
611
|
current.node = previous;
|
|
557
612
|
step.unvisited =
|
|
558
|
-
check
|
|
613
|
+
getSuccessors(check, previous).find((next) => isMember(next) && !seen.has(next)) ??
|
|
614
|
+
-1;
|
|
559
615
|
}
|
|
560
616
|
take(step.unvisited);
|
|
561
617
|
seen.add(step.unvisited);
|
|
@@ -585,7 +641,7 @@ export const createLivenessChecker = (
|
|
|
585
641
|
const queue: [number, number][] = [];
|
|
586
642
|
for (let state = start, parent = -1, position = 0; ; position++) {
|
|
587
643
|
for (const node of membersByState.get(state) ?? []) {
|
|
588
|
-
for (const [edge, next] of check
|
|
644
|
+
for (const [edge, next] of getSuccessors(check, node).entries()) {
|
|
589
645
|
if (next === node || !isAllowedEdge(node, edge)) continue;
|
|
590
646
|
if (next === root) {
|
|
591
647
|
const path: number[] = [];
|
|
@@ -638,8 +694,8 @@ export const createLivenessChecker = (
|
|
|
638
694
|
stack.push(lowLink, node, SCC_MARKER);
|
|
639
695
|
components.push(node);
|
|
640
696
|
const nextLowLink = { value: counter.link++ };
|
|
641
|
-
check
|
|
642
|
-
if (!check
|
|
697
|
+
getSuccessors(check, node).forEach((next, edge) => {
|
|
698
|
+
if (!isWritten(check, next)) return;
|
|
643
699
|
if (!isAllowed(node, edge)) {
|
|
644
700
|
if (links[next] === UNVISITED) queue.push(next);
|
|
645
701
|
return;
|
package/src/liveness.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { isLocallyResolved, type Definition, type Expression } from "./ast";
|
|
2
2
|
import { TlaConfigError, TlaEvaluationError } from "./errors";
|
|
3
|
+
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
3
4
|
import {
|
|
4
5
|
describeLocation,
|
|
6
|
+
describeRange,
|
|
5
7
|
bindDefinitions,
|
|
6
8
|
bindOperatorArguments,
|
|
7
9
|
evaluate,
|
|
@@ -36,6 +38,10 @@ export interface ScopedExpression {
|
|
|
36
38
|
scope: Scope | undefined;
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
export interface NamedExpression extends ScopedExpression {
|
|
42
|
+
name: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
39
45
|
export interface TemporalProperty extends ScopedExpression {
|
|
40
46
|
name: string;
|
|
41
47
|
}
|
|
@@ -144,21 +150,27 @@ const getDefinitionLevel = (definition: Definition, environment: Environment) =>
|
|
|
144
150
|
return level;
|
|
145
151
|
};
|
|
146
152
|
|
|
153
|
+
export const TAUTOLOGY_MESSAGE = "Temporal formula is a tautology (its negation is unsatisfiable).";
|
|
154
|
+
|
|
155
|
+
// TLC names each part of a property after the operator it expands, or after the location of the
|
|
156
|
+
// conjunct or quantifier body it splits off.
|
|
147
157
|
export const expandTemporal = (
|
|
148
158
|
expression: Expression,
|
|
149
159
|
scope: Scope | undefined,
|
|
150
160
|
environment: Environment,
|
|
151
|
-
|
|
161
|
+
isProperty: boolean,
|
|
162
|
+
name = "",
|
|
152
163
|
expanding = new Set<Definition>(),
|
|
153
|
-
):
|
|
164
|
+
): NamedExpression[] => {
|
|
154
165
|
const expand = (
|
|
155
166
|
child: Expression,
|
|
156
167
|
childScope: Scope | undefined,
|
|
168
|
+
childName = name,
|
|
157
169
|
childExpanding = expanding,
|
|
158
|
-
):
|
|
159
|
-
expandTemporal(child, childScope, environment,
|
|
170
|
+
): NamedExpression[] =>
|
|
171
|
+
expandTemporal(child, childScope, environment, isProperty, childName, childExpanding);
|
|
160
172
|
if (expression.kind === "And") {
|
|
161
|
-
return expression.operands.flatMap((operand) => expand(operand, scope));
|
|
173
|
+
return expression.operands.flatMap((operand) => expand(operand, scope, describeRange(operand)));
|
|
162
174
|
}
|
|
163
175
|
if (expression.kind === "Label") return expand(expression.body, scope);
|
|
164
176
|
if (expression.kind === "Let") {
|
|
@@ -181,33 +193,58 @@ export const expandTemporal = (
|
|
|
181
193
|
if (expanding.has(definition)) {
|
|
182
194
|
throw new TlaConfigError(`The definition of ${expression.name} refers to itself`);
|
|
183
195
|
}
|
|
184
|
-
return expand(
|
|
196
|
+
return expand(
|
|
197
|
+
definition.body,
|
|
198
|
+
undefined,
|
|
199
|
+
expression.name,
|
|
200
|
+
new Set([...expanding, definition]),
|
|
201
|
+
);
|
|
185
202
|
}
|
|
186
203
|
}
|
|
187
204
|
const context = getConstantContext(environment, scope);
|
|
188
|
-
|
|
205
|
+
// A property expands every operator it applies and unrolls every \A over constant sets, but a
|
|
206
|
+
// specification only expands the temporal ones.
|
|
207
|
+
const isExpanded = (child: Expression) =>
|
|
208
|
+
isProperty || getLevel(child, scope, environment) === TEMPORAL_LEVEL;
|
|
209
|
+
if (expression.kind === "Apply" && isExpanded(expression)) {
|
|
189
210
|
const operator = resolveApplyOperator(expression, context);
|
|
190
211
|
const definition = isLocallyResolved(expression)
|
|
191
212
|
? undefined
|
|
192
213
|
: getDefinition(expression.operator, environment);
|
|
193
|
-
|
|
194
|
-
|
|
214
|
+
const isExpandable =
|
|
215
|
+
operator?.kind === "Closure" &&
|
|
216
|
+
operator.params.length === expression.args.length &&
|
|
217
|
+
!definition?.isRecursive;
|
|
218
|
+
if (isExpandable) {
|
|
219
|
+
return expand(
|
|
220
|
+
operator.body,
|
|
221
|
+
bindOperatorArguments(operator, expression.args, context),
|
|
222
|
+
expression.operator,
|
|
223
|
+
);
|
|
195
224
|
}
|
|
196
225
|
}
|
|
197
226
|
const isUnrolled =
|
|
198
|
-
|
|
227
|
+
isProperty &&
|
|
199
228
|
expression.kind === "Forall" &&
|
|
200
|
-
getLevel(expression.body, scope, environment) === TEMPORAL_LEVEL &&
|
|
201
229
|
expression.bounds.every((bound) => getLevel(bound.set, scope, environment) === 0);
|
|
202
230
|
if (isUnrolled) {
|
|
203
|
-
const expanded:
|
|
231
|
+
const expanded: NamedExpression[] = [];
|
|
232
|
+
const bindings = { count: 0 };
|
|
204
233
|
forEachBinding(expression.bounds, context, (boundScope) => {
|
|
205
|
-
|
|
234
|
+
bindings.count++;
|
|
235
|
+
expanded.push(...expand(expression.body, boundScope, describeRange(expression.body)));
|
|
206
236
|
return false;
|
|
207
237
|
});
|
|
238
|
+
// TLC rejects a property that quantifies over no elements before it checks anything.
|
|
239
|
+
if (bindings.count === 0) {
|
|
240
|
+
throw setExitCode(
|
|
241
|
+
new TlaEvaluationError(TAUTOLOGY_MESSAGE),
|
|
242
|
+
EXIT_STATUS.livenessEvaluationFailure,
|
|
243
|
+
);
|
|
244
|
+
}
|
|
208
245
|
return expanded;
|
|
209
246
|
}
|
|
210
|
-
return [{ expression, scope }];
|
|
247
|
+
return [{ expression, scope, name }];
|
|
211
248
|
};
|
|
212
249
|
|
|
213
250
|
const bindLetDefinitions = (
|
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/runtime.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface CheckerRuntime {
|
|
|
24
24
|
properties: Map<string, string>;
|
|
25
25
|
possibleCounts: Map<string, number>;
|
|
26
26
|
isStopped: boolean;
|
|
27
|
+
isStarted: boolean;
|
|
27
28
|
checkDeadlock: boolean;
|
|
28
29
|
startedAt: number;
|
|
29
30
|
}
|
|
@@ -75,6 +76,7 @@ export const createRuntime = (checkDeadlock: boolean, seed = 0n): CheckerRuntime
|
|
|
75
76
|
properties: new Map(),
|
|
76
77
|
possibleCounts: new Map(),
|
|
77
78
|
isStopped: false,
|
|
79
|
+
isStarted: false,
|
|
78
80
|
checkDeadlock,
|
|
79
81
|
startedAt: Date.now(),
|
|
80
82
|
};
|
package/src/standard-modules.ts
CHANGED
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
isEnumerable,
|
|
41
41
|
isFiniteSet,
|
|
42
42
|
isFunctionValue,
|
|
43
|
+
isReducible,
|
|
43
44
|
isSetValue,
|
|
44
45
|
toFiniteSet,
|
|
45
46
|
unionSorted,
|
|
@@ -47,7 +48,7 @@ import {
|
|
|
47
48
|
createEnumeratedSet,
|
|
48
49
|
EMPTY_SET,
|
|
49
50
|
isEnumeratedSet,
|
|
50
|
-
type
|
|
51
|
+
type ReducibleSet,
|
|
51
52
|
type MixedSetValue,
|
|
52
53
|
type SetOperationValue,
|
|
53
54
|
type SetValue,
|
|
@@ -75,12 +76,6 @@ const unionInTree = (sets: SetValue[], start: number, end: number): SetValue =>
|
|
|
75
76
|
|
|
76
77
|
const SET_OPERATORS: SetOperationValue["operator"][] = ["\\cup", "\\cap", "\\"];
|
|
77
78
|
|
|
78
|
-
type ReducibleSet = SetValue | MixedSetValue | IntervalValue;
|
|
79
|
-
|
|
80
|
-
const isReducible = (value: Value): value is ReducibleSet =>
|
|
81
|
-
typeof value === "object" &&
|
|
82
|
-
(value.kind === "Set" || value.kind === "MixedSet" || value.kind === "Interval");
|
|
83
|
-
|
|
84
79
|
const isMixedSet = (value: Value) => typeof value === "object" && value.kind === "MixedSet";
|
|
85
80
|
|
|
86
81
|
const getReducibleElements = (set: ReducibleSet) =>
|