tla-ts 0.0.3-dev.b1578d0 → 0.0.3-dev.b4e335d

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.
Files changed (81) hide show
  1. package/dist/cli.cjs +1 -1
  2. package/dist/cli.js +1 -1
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.cts +150 -8
  5. package/dist/index.d.ts +150 -8
  6. package/dist/index.js +1 -1
  7. package/dist/parallel-worker.cjs +1 -1
  8. package/dist/parallel-worker.js +2 -2
  9. package/dist/parallel.cjs +1 -1
  10. package/dist/parallel.js +2 -2
  11. package/dist/run-cli.cjs +1351 -20
  12. package/dist/run-cli.js +1351 -20
  13. package/dist/transfer.cjs +86 -28
  14. package/dist/transfer.js +86 -28
  15. package/package.json +5 -1
  16. package/src/ast.ts +57 -6
  17. package/src/bags.ts +4 -7
  18. package/src/builtins.ts +29 -11
  19. package/src/bundled-modules.ts +3 -3
  20. package/src/canonical.ts +4 -3
  21. package/src/check.ts +1396 -227
  22. package/src/cli.ts +8 -1
  23. package/src/codegen.ts +68 -18
  24. package/src/config.ts +252 -179
  25. package/src/environment.ts +514 -130
  26. package/src/errors.ts +217 -3
  27. package/src/evaluate.ts +722 -112
  28. package/src/exit-codes.ts +5 -4
  29. package/src/index.ts +1 -0
  30. package/src/instances.ts +7 -5
  31. package/src/java-overrides.ts +104 -25
  32. package/src/levels.ts +183 -37
  33. package/src/lexer.ts +112 -29
  34. package/src/live-check.ts +220 -102
  35. package/src/liveness.ts +216 -52
  36. package/src/obligation-expression.ts +2 -2
  37. package/src/obligation-source.ts +2 -0
  38. package/src/parallel-worker.ts +8 -3
  39. package/src/parallel.ts +56 -5
  40. package/src/parser.ts +445 -147
  41. package/src/pcal-ast.ts +770 -0
  42. package/src/pcal-parse.ts +1523 -0
  43. package/src/pcal-tokenize.ts +516 -0
  44. package/src/pcal-translate.ts +1230 -0
  45. package/src/pcal-validate.ts +454 -0
  46. package/src/randomization.ts +24 -7
  47. package/src/resolve.ts +1465 -411
  48. package/src/run-cli.ts +1167 -155
  49. package/src/runtime.ts +18 -0
  50. package/src/sany-builtins.ts +147 -0
  51. package/src/sany-generator.ts +3128 -0
  52. package/src/sany-levels.ts +1208 -0
  53. package/src/sany-lexer.ts +545 -0
  54. package/src/sany-linter.ts +122 -0
  55. package/src/sany-modules.ts +1398 -0
  56. package/src/sany-nodes.ts +463 -0
  57. package/src/sany-parse-error.ts +2161 -0
  58. package/src/sany-report.ts +354 -0
  59. package/src/sany-selectors.ts +738 -0
  60. package/src/sany-source.ts +248 -0
  61. package/src/sany-xml.ts +1017 -0
  62. package/src/spec-description.ts +26 -7
  63. package/src/standard-modules.ts +200 -148
  64. package/src/standard-ranges.ts +116 -0
  65. package/src/state-graph.ts +29 -6
  66. package/src/subexpressions.ts +221 -161
  67. package/src/substitution-levels.ts +38 -17
  68. package/src/successors.ts +207 -103
  69. package/src/symmetry.ts +180 -52
  70. package/src/tableau.ts +54 -25
  71. package/src/tlc-ext.ts +13 -17
  72. package/src/tlc-messages.ts +329 -0
  73. package/src/tlc-module.ts +49 -15
  74. package/src/tlc-order.ts +56 -6
  75. package/src/tlc-random.ts +37 -9
  76. package/src/tlc-replay.ts +655 -0
  77. package/src/tlc-summary.ts +20 -5
  78. package/src/tlc-version.ts +18 -0
  79. package/src/transfer.ts +15 -3
  80. package/src/value-sources.ts +29 -0
  81. package/src/values.ts +697 -180
package/src/live-check.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { TlaEvaluationError } from "./errors";
2
2
  import { hasRepeatedEffects, type Environment } from "./evaluate";
3
3
  import {
4
+ createTautologyError,
4
5
  evaluateLive,
5
6
  evaluateOnLasso,
6
7
  toLiveExpression,
@@ -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,
@@ -26,18 +28,38 @@ export interface LiveSuccessor {
26
28
  export interface Lasso {
27
29
  prefix: number[];
28
30
  cycle: number[];
31
+ // Whether the solution that the lasso violates constrains the cycle, as a liveness property does.
32
+ // TLC warns that a stuttering counterexample to one may come from a missing fairness constraint.
33
+ isCycleConstrained: boolean;
29
34
  }
30
35
 
31
36
  export interface LivenessChecker {
32
- addInitialState: (index: number, state: Value[]) => void;
33
- addState: (index: number, state: Value[], successors: LiveSuccessor[]) => number[] | undefined;
37
+ // How many solutions of the negated properties TLC checks, which it calls branches.
38
+ branches: number;
39
+ // With a tracing environment, the checks record their call stack as TLC's replay of a failed
40
+ // check does.
41
+ addInitialState: (index: number, state: Value[], tracing?: Environment) => void;
42
+ addState: (
43
+ index: number,
44
+ state: Value[],
45
+ successors: LiveSuccessor[],
46
+ tracing?: Environment,
47
+ ) => number[] | undefined;
34
48
  findViolation: () => Lasso | undefined;
35
49
  getViolatedProperties: (path: Value[][], cycleStart: number) => string[];
36
50
  }
37
51
 
38
52
  export interface LiveGraph {
39
- getFingerprint: (index: number) => number;
40
- getSuccessors: (state: Value[]) => LiveSuccessor[];
53
+ getFingerprint: (successor: LiveSuccessor) => number;
54
+ getSuccessors: (index: number, state: Value[]) => LiveSuccessor[];
55
+ }
56
+
57
+ // Numbers in a typed array that doubles as it fills, so a graph of millions of nodes takes a few
58
+ // bytes for each.
59
+ interface Pool<Data extends Int32Array | Uint8Array> {
60
+ data: Data;
61
+ length: number;
62
+ create: (length: number) => Data;
41
63
  }
42
64
 
43
65
  // TLC's behavior graph for one solution: a node per state, or per state and tableau node.
@@ -47,54 +69,116 @@ interface Check {
47
69
  actionIds: Int32Array;
48
70
  nodeStates: number[];
49
71
  nodeTableaux: number[];
50
- successors: number[][];
51
- actions: Uint8Array[];
52
- stateResults: Uint8Array[];
53
- isWritten: boolean[];
72
+ // Where a node's edges start in edgeTargets, or UNWRITTEN until TLC writes the node with its
73
+ // successors, and how many it has.
74
+ edgeStarts: number[];
75
+ edgeCounts: number[];
76
+ edgeTargets: Pool<Int32Array>;
77
+ // The results of the action checks on each edge, and of the state checks on each state, which
78
+ // are the same for every node of the state.
79
+ edgeActions: Pool<Uint8Array>;
80
+ stateResults: Pool<Uint8Array>;
54
81
  initial: number[];
55
- nodeIds: Map<number, number>;
56
- nodesByState: Map<number, number[]>;
82
+ // The nodes of each state in the order the check records them, a list through nextSiblings.
83
+ firstNodes: Pool<Int32Array>;
84
+ lastNodes: Pool<Int32Array>;
85
+ nextSiblings: number[];
57
86
  isDone: boolean[];
58
87
  errorNode: number | undefined;
59
88
  }
60
89
 
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;
90
+ const containsAlways = (expression: LiveExpression): boolean => {
91
+ switch (expression.kind) {
92
+ case "Always":
93
+ return true;
94
+ case "Eventually":
95
+ case "Not":
96
+ case "Next":
97
+ return containsAlways(expression.body);
98
+ case "And":
99
+ case "Or":
100
+ return expression.operands.some(containsAlways);
101
+ default:
102
+ return false;
103
+ }
79
104
  };
80
105
 
106
+ // TLC's OrderOfSolution#hasEmptyPEMAndBoxFreePromises, negated.
107
+ const isCycleConstrained = (solution: Solution) =>
108
+ solution.promises.some((promise) => containsAlways(promise.body)) ||
109
+ solution.models.some(
110
+ (model) =>
111
+ model.eventuallyAlways.length > 0 ||
112
+ model.infinitelyOftenStates.length > 0 ||
113
+ model.infinitelyOftenActions.length > 0,
114
+ );
115
+
81
116
  const isSameState = (left: Value[], right: Value[]) =>
82
117
  left.every((value, position) => isSameValue(value, right[position]));
83
118
 
84
119
  const removeRepeats = (path: number[]) =>
85
120
  path.filter((node, position) => position === 0 || path[position - 1] !== node);
86
121
 
122
+ const createPool = <Data extends Int32Array | Uint8Array>(
123
+ create: (length: number) => Data,
124
+ ): Pool<Data> => ({ data: create(1024), length: 0, create });
125
+
126
+ const writeToPool = <Data extends Int32Array | Uint8Array>(
127
+ pool: Pool<Data>,
128
+ offset: number,
129
+ values: ArrayLike<number>,
130
+ ) => {
131
+ const end = offset + values.length;
132
+ if (end > pool.data.length) {
133
+ const data = pool.create(Math.max(2 * pool.data.length, end));
134
+ data.set(pool.data);
135
+ pool.data = data;
136
+ }
137
+ pool.data.set(values, offset);
138
+ pool.length = Math.max(pool.length, end);
139
+ };
140
+
141
+ const NO_NODE = -1;
142
+
143
+ const createNodes = (length: number) => new Int32Array(length).fill(NO_NODE);
144
+
145
+ const UNWRITTEN = -1;
146
+
147
+ const isWritten = (check: Check, node: number) =>
148
+ (check.edgeStarts[node] ?? UNWRITTEN) !== UNWRITTEN;
149
+
150
+ const getSuccessors = (check: Check, node: number) => {
151
+ const start = check.edgeStarts[node];
152
+ return check.edgeTargets.data.subarray(start, start + check.edgeCounts[node]);
153
+ };
154
+
155
+ const getStateResult = (check: Check, node: number, position: number) =>
156
+ check.stateResults.data[check.nodeStates[node] * check.solution.stateChecks.length + position] ===
157
+ 1;
158
+
87
159
  // A node owns one entry in each of its check's per-node arrays.
88
160
  const pushNode = (check: Check, state: number, tableauNode: number) => {
89
161
  check.nodeStates.push(state);
90
162
  check.nodeTableaux.push(tableauNode);
91
- check.successors.push([]);
92
- check.actions.push(new Uint8Array(0));
93
- check.stateResults.push(new Uint8Array(0));
94
- check.isWritten.push(false);
163
+ check.edgeStarts.push(UNWRITTEN);
164
+ check.edgeCounts.push(0);
165
+ check.nextSiblings.push(NO_NODE);
95
166
  return check.nodeStates.length - 1;
96
167
  };
97
168
 
169
+ // The nodes of the state, in the order the check recorded them.
170
+ const getStateNodes = (check: Check, state: number) => {
171
+ const nodes: number[] = [];
172
+ for (
173
+ let node = check.firstNodes.data[state] ?? NO_NODE;
174
+ node !== NO_NODE;
175
+ node = check.nextSiblings[node]
176
+ ) {
177
+ nodes.push(node);
178
+ }
179
+ return nodes;
180
+ };
181
+
98
182
  const SUCCESSOR_CAPACITY = 16;
99
183
 
100
184
  const SCC_MARKER = -42;
@@ -121,26 +205,28 @@ export const createLivenessChecker = (
121
205
  fairness.length === 0 ? violation : createJunction("And", [...fairness, violation]);
122
206
  const solutions = getSolutions(formula);
123
207
  if (solutions.length === 0) {
124
- throw new TlaEvaluationError("Temporal formula is a tautology (its negation is unsatisfiable)");
208
+ throw createTautologyError();
125
209
  }
126
210
  const actionIds = new Map<string, number>();
127
211
  const checks = solutions.map((solution): Check => ({
128
212
  solution,
129
213
  actionIds: Int32Array.from(solution.actionChecks, (predicate) => {
130
- const key = getLiveKey(predicate);
214
+ const key = getTermKey(predicate);
131
215
  const id = actionIds.get(key) ?? actionIds.size;
132
216
  actionIds.set(key, id);
133
217
  return id;
134
218
  }),
135
219
  nodeStates: [],
136
220
  nodeTableaux: [],
137
- successors: [],
138
- actions: [],
139
- stateResults: [],
140
- isWritten: [],
221
+ edgeStarts: [],
222
+ edgeCounts: [],
223
+ edgeTargets: createPool((length) => new Int32Array(length)),
224
+ edgeActions: createPool((length) => new Uint8Array(length)),
225
+ stateResults: createPool((length) => new Uint8Array(length)),
141
226
  initial: [],
142
- nodeIds: new Map(),
143
- nodesByState: new Map(),
227
+ firstNodes: createPool(createNodes),
228
+ lastNodes: createPool(createNodes),
229
+ nextSiblings: [],
144
230
  isDone: [],
145
231
  errorNode: undefined,
146
232
  }));
@@ -149,6 +235,7 @@ export const createLivenessChecker = (
149
235
  // TLC evaluates every check on its own. Without side effects the order can't show, so the
150
236
  // checks of one state share their results.
151
237
  const isShared = !hasRepeatedEffects(environment);
238
+ const evaluation = { environment };
152
239
  const shared = {
153
240
  states: new Map<Value[], Map<LiveExpression, boolean>>(),
154
241
  actions: new Map<Value[], Map<Value[], Int8Array>>(),
@@ -170,7 +257,7 @@ export const createLivenessChecker = (
170
257
  predicate,
171
258
  state,
172
259
  undefined,
173
- environment,
260
+ evaluation.environment,
174
261
  isShared ? getStateCache(state) : new Map(),
175
262
  );
176
263
  const checkState = (check: Check, source: number, state: Value[]) =>
@@ -184,7 +271,7 @@ export const createLivenessChecker = (
184
271
  const predicates = check.solution.actionChecks;
185
272
  if (!isShared) {
186
273
  return Uint8Array.from(predicates, (predicate) =>
187
- evaluateLive(predicate, state, successor, environment, new Map()) ? 1 : 0,
274
+ evaluateLive(predicate, state, successor, evaluation.environment, new Map()) ? 1 : 0,
188
275
  );
189
276
  }
190
277
  const stateCache = getStateCache(state);
@@ -194,7 +281,13 @@ export const createLivenessChecker = (
194
281
  results.set(successor, known);
195
282
  return Uint8Array.from(check.actionIds, (id, position) => {
196
283
  if (known[id] === -1) {
197
- known[id] = evaluateLive(predicates[position], state, successor, environment, stateCache)
284
+ known[id] = evaluateLive(
285
+ predicates[position],
286
+ state,
287
+ successor,
288
+ evaluation.environment,
289
+ stateCache,
290
+ )
198
291
  ? 1
199
292
  : 0;
200
293
  }
@@ -210,7 +303,10 @@ export const createLivenessChecker = (
210
303
  evaluateFrom(source, () =>
211
304
  tableau.nodes[node].statePredicates.every((predicate) => evaluateState(predicate, state)),
212
305
  );
306
+ // TLC 1.7.4 doesn't stop at a tableau node that accepts every behavior, so it finds a violation
307
+ // of a property like a safety property only in its liveness checks.
213
308
  const isAccepting = (tableau: Tableau, node: number) => {
309
+ if (environment.runtime.version === "1.7.4") return false;
214
310
  const tableauNode = tableau.nodes[node];
215
311
  return (
216
312
  tableauNode.particle.length === 0 &&
@@ -228,28 +324,32 @@ export const createLivenessChecker = (
228
324
 
229
325
  const getNodeId = (check: Check, state: number, tableauNode: number) =>
230
326
  check.solution.tableau
231
- ? check.nodeIds.get(state * check.solution.tableau.nodes.length + tableauNode)
327
+ ? getStateNodes(check, state).find((node) => check.nodeTableaux[node] === tableauNode)
232
328
  : state;
233
329
  const recordNode = (check: Check, state: number, tableauNode: number) => {
234
330
  const node = pushNode(check, state, tableauNode);
235
- check.nodeIds.set(state * (check.solution.tableau?.nodes.length ?? 1) + tableauNode, node);
236
- const siblings = check.nodesByState.get(state);
237
- if (siblings) siblings.push(node);
238
- else check.nodesByState.set(state, [node]);
331
+ const last = check.lastNodes.data[state] ?? NO_NODE;
332
+ if (last === NO_NODE) writeToPool(check.firstNodes, state, [node]);
333
+ else check.nextSiblings[last] = node;
334
+ writeToPool(check.lastNodes, state, [node]);
239
335
  return node;
240
336
  };
241
337
  const writeNode = (
242
338
  check: Check,
243
339
  node: number,
340
+ targets: number[],
244
341
  actions: Uint8Array[],
245
342
  stateResults: Uint8Array,
246
343
  ) => {
344
+ const start = check.edgeTargets.length;
247
345
  const actionCount = check.solution.actionChecks.length;
248
- const packed = new Uint8Array(actions.length * actionCount);
249
- actions.forEach((results, position) => packed.set(results, position * actionCount));
250
- check.actions[node] = packed;
251
- check.stateResults[node] = stateResults;
252
- check.isWritten[node] = true;
346
+ writeToPool(check.edgeTargets, start, targets);
347
+ actions.forEach((results, position) =>
348
+ writeToPool(check.edgeActions, (start + position) * actionCount, results),
349
+ );
350
+ writeToPool(check.stateResults, check.nodeStates[node] * stateResults.length, stateResults);
351
+ check.edgeStarts[node] = start;
352
+ check.edgeCounts[node] = targets.length;
253
353
  };
254
354
 
255
355
  // TLC collects a state's successors and the state itself in a SetOfStates, a hash set it
@@ -264,7 +364,7 @@ export const createLivenessChecker = (
264
364
  };
265
365
  const insert = (slots: (LiveSuccessor | undefined)[], successor: LiveSuccessor) => {
266
366
  for (
267
- let slot = (graph.getFingerprint(successor.index) & 0x7fffffff) % slots.length;
367
+ let slot = (graph.getFingerprint(successor) & 0x7fffffff) % slots.length;
268
368
  ;
269
369
  slot = (slot + 1) % slots.length
270
370
  ) {
@@ -302,7 +402,7 @@ export const createLivenessChecker = (
302
402
  const stateResults = checkState(check, index, state);
303
403
  const tableauNode = tableau.nodes[check.nodeTableaux[node]];
304
404
  const actions: Uint8Array[] = [];
305
- const successors = check.successors[node];
405
+ const successors: number[] = [];
306
406
  const selfActions =
307
407
  tableauNode.successors.length > 0
308
408
  ? checkAction(check, index, state, state)
@@ -320,11 +420,14 @@ export const createLivenessChecker = (
320
420
  actions.push(selfActions);
321
421
  if (existing === undefined) expandLate(check, tableau, state, index, target);
322
422
  }
323
- for (const successor of graph.getSuccessors(state)) {
423
+ for (const successor of graph.getSuccessors(index, state)) {
324
424
  const successorActions = checkAction(check, index, state, successor.state);
325
425
  const isDone = check.isDone[successor.index] === true;
326
426
  for (const next of tableauNode.successors) {
327
427
  if (!isConsistent(tableau, next, index, successor.state)) continue;
428
+ // A successor the search never stored follows a violation or an error, after which nothing
429
+ // checks the graph. TLC records its node, which it never expands.
430
+ if (successor.index === -1) continue;
328
431
  const existing = getNodeId(check, successor.index, next);
329
432
  if (existing !== undefined && successors.includes(existing)) continue;
330
433
  const target = existing ?? recordNode(check, successor.index, next);
@@ -335,7 +438,7 @@ export const createLivenessChecker = (
335
438
  }
336
439
  }
337
440
  }
338
- if (successors.length > 0) writeNode(check, node, actions, stateResults);
441
+ if (successors.length > 0) writeNode(check, node, successors, actions, stateResults);
339
442
  };
340
443
 
341
444
  const addTableauState = (
@@ -351,8 +454,8 @@ export const createLivenessChecker = (
351
454
  );
352
455
  check.isDone[index] = true;
353
456
  // TLC expands the nodes recorded before the loop, not the ones the loop records.
354
- for (const node of (check.nodesByState.get(index) ?? []).slice()) {
355
- const successors = check.successors[node];
457
+ for (const node of getStateNodes(check, index)) {
458
+ const successors: number[] = [];
356
459
  const actions: Uint8Array[] = [];
357
460
  set.forEach((successor, position) => {
358
461
  const isDone = check.isDone[successor.index] === true;
@@ -368,7 +471,7 @@ export const createLivenessChecker = (
368
471
  }
369
472
  }
370
473
  });
371
- writeNode(check, node, actions, stateResults);
474
+ writeNode(check, node, successors, actions, stateResults);
372
475
  }
373
476
  if (check.errorNode === undefined) return undefined;
374
477
  return removeRepeats(
@@ -386,14 +489,14 @@ export const createLivenessChecker = (
386
489
  index: number,
387
490
  ) => {
388
491
  while (check.nodeStates.length <= index) pushNode(check, check.nodeStates.length, -1);
389
- const successors = check.successors[index];
492
+ const successors: number[] = [];
390
493
  const actions: Uint8Array[] = [];
391
494
  set.forEach((successor, position) => {
392
- if (check.isWritten[successor.index] && successors.includes(successor.index)) return;
495
+ if (isWritten(check, successor.index) && successors.includes(successor.index)) return;
393
496
  successors.push(successor.index);
394
497
  actions.push(actionResults[position]);
395
498
  });
396
- writeNode(check, index, actions, stateResults);
499
+ writeNode(check, index, successors, actions, stateResults);
397
500
  return undefined;
398
501
  };
399
502
 
@@ -403,20 +506,20 @@ export const createLivenessChecker = (
403
506
  const parents = new Map<number, number>();
404
507
  const queue: number[] = [];
405
508
  for (const node of check.initial) {
406
- if (!check.isWritten[node]) continue;
509
+ if (!isWritten(check, node)) continue;
407
510
  queue.push(node);
408
511
  parents.set(node, -1);
409
512
  }
410
513
  for (let position = 0; position < queue.length; position++) {
411
514
  const current = queue[position];
412
- for (const next of check.successors[current]) {
515
+ for (const next of getSuccessors(check, current)) {
413
516
  if (next === current && check.solution.tableau) continue;
414
517
  if (next === target) {
415
518
  const path = [target];
416
519
  for (let node = current; node !== -1; node = parents.get(node) ?? -1) path.push(node);
417
520
  return path;
418
521
  }
419
- if (!check.isWritten[next] || parents.has(next)) continue;
522
+ if (!isWritten(check, next) || parents.has(next)) continue;
420
523
  parents.set(next, current);
421
524
  queue.push(next);
422
525
  }
@@ -429,15 +532,15 @@ export const createLivenessChecker = (
429
532
  const solution = check.solution;
430
533
  const actionCount = solution.actionChecks.length;
431
534
  const getAction = (node: number, edge: number, position: number) =>
432
- check.actions[node][edge * actionCount + position] === 1;
535
+ check.edgeActions.data[(check.edgeStarts[node] + edge) * actionCount + position] === 1;
433
536
  const isAllowed = (node: number, edge: number) =>
434
537
  model.eventuallyAlways.every((position) => getAction(node, edge, position));
435
538
  const links = new Float64Array(check.nodeStates.length).fill(UNVISITED);
436
- const queue = check.initial.filter((node) => check.isWritten[node]);
539
+ const queue = check.initial.filter((node) => isWritten(check, node));
437
540
  const components: number[] = [];
438
541
 
439
542
  const isStuttering = (node: number) => {
440
- const edge = check.successors[node].indexOf(node);
543
+ const edge = getSuccessors(check, node).indexOf(node);
441
544
  return edge !== -1 && isAllowed(node, edge);
442
545
  };
443
546
  const isFulfilled = (node: number, promise: Solution["promises"][number]) =>
@@ -461,11 +564,11 @@ export const createLivenessChecker = (
461
564
  if (member === root) break;
462
565
  }
463
566
  const isStateSatisfied = model.infinitelyOftenStates.every((position) =>
464
- [...members].some((node) => check.stateResults[node][position] === 1),
567
+ [...members].some((node) => getStateResult(check, node, position)),
465
568
  );
466
569
  const isActionSatisfied = model.infinitelyOftenActions.every((position) =>
467
570
  [...members].some((node) =>
468
- check.successors[node].some(
571
+ getSuccessors(check, node).some(
469
572
  (next, edge) =>
470
573
  members.has(next) && isAllowed(node, edge) && getAction(node, edge, position),
471
574
  ),
@@ -506,7 +609,7 @@ export const createLivenessChecker = (
506
609
  const countAtStart = remaining.count;
507
610
  while (true) {
508
611
  model.infinitelyOftenStates.forEach((position, slot) => {
509
- if (!stateDone[slot] && check.stateResults[current.node][position] === 1) {
612
+ if (!stateDone[slot] && getStateResult(check, current.node, position)) {
510
613
  stateDone[slot] = true;
511
614
  remaining.count--;
512
615
  }
@@ -520,8 +623,7 @@ export const createLivenessChecker = (
520
623
  if (remaining.count <= 0) break;
521
624
  const step = { last: -1, unvisited: -1 };
522
625
  const countBeforeActions = remaining.count;
523
- const successors = check.successors[current.node];
524
- const taken = successors.some((next, edge) => {
626
+ const taken = getSuccessors(check, current.node).some((next, edge) => {
525
627
  if (membersByState.has(check.nodeStates[next])) {
526
628
  if (!isMember(next) || !isAllowed(current.node, edge)) return false;
527
629
  step.last = next;
@@ -555,7 +657,8 @@ export const createLivenessChecker = (
555
657
  }
556
658
  current.node = previous;
557
659
  step.unvisited =
558
- check.successors[previous].find((next) => isMember(next) && !seen.has(next)) ?? -1;
660
+ getSuccessors(check, previous).find((next) => isMember(next) && !seen.has(next)) ??
661
+ -1;
559
662
  }
560
663
  take(step.unvisited);
561
664
  seen.add(step.unvisited);
@@ -568,7 +671,11 @@ export const createLivenessChecker = (
568
671
  }
569
672
  const cycleState = prefix[prefix.length - 1];
570
673
  if (postfix[postfix.length - 1] === cycleState) postfix.pop();
571
- return { prefix: prefix.slice(0, -1), cycle: [cycleState, ...postfix.reverse()] };
674
+ return {
675
+ prefix: prefix.slice(0, -1),
676
+ cycle: [cycleState, ...postfix.reverse()],
677
+ isCycleConstrained: isCycleConstrained(solution),
678
+ };
572
679
  };
573
680
 
574
681
  // TLC's LiveWorker#bfsPostFix, the states from the walk's end back to the root, last first.
@@ -585,7 +692,7 @@ export const createLivenessChecker = (
585
692
  const queue: [number, number][] = [];
586
693
  for (let state = start, parent = -1, position = 0; ; position++) {
587
694
  for (const node of membersByState.get(state) ?? []) {
588
- for (const [edge, next] of check.successors[node].entries()) {
695
+ for (const [edge, next] of getSuccessors(check, node).entries()) {
589
696
  if (next === node || !isAllowedEdge(node, edge)) continue;
590
697
  if (next === root) {
591
698
  const path: number[] = [];
@@ -638,8 +745,8 @@ export const createLivenessChecker = (
638
745
  stack.push(lowLink, node, SCC_MARKER);
639
746
  components.push(node);
640
747
  const nextLowLink = { value: counter.link++ };
641
- check.successors[node].forEach((next, edge) => {
642
- if (!check.isWritten[next]) return;
748
+ getSuccessors(check, node).forEach((next, edge) => {
749
+ if (!isWritten(check, next)) return;
643
750
  if (!isAllowed(node, edge)) {
644
751
  if (links[next] === UNVISITED) queue.push(next);
645
752
  return;
@@ -654,37 +761,48 @@ export const createLivenessChecker = (
654
761
  };
655
762
 
656
763
  return {
657
- addInitialState: (index, state) => {
764
+ branches: checks.length,
765
+ addInitialState: (index, state, tracing) => {
766
+ evaluation.environment = tracing ?? environment;
658
767
  shared.states.clear();
659
768
  shared.actions.clear();
660
- for (const check of checks) {
661
- const tableau = check.solution.tableau;
662
- if (!tableau) {
663
- check.initial.push(index);
664
- continue;
665
- }
666
- for (let node = 0; node < tableau.initialCount; node++) {
667
- if (!isConsistent(tableau, node, undefined, state)) continue;
668
- check.initial.push(getNodeId(check, index, node) ?? recordNode(check, index, node));
769
+ try {
770
+ for (const check of checks) {
771
+ const tableau = check.solution.tableau;
772
+ if (!tableau) {
773
+ check.initial.push(index);
774
+ continue;
775
+ }
776
+ for (let node = 0; node < tableau.initialCount; node++) {
777
+ if (!isConsistent(tableau, node, undefined, state)) continue;
778
+ check.initial.push(getNodeId(check, index, node) ?? recordNode(check, index, node));
779
+ }
669
780
  }
781
+ } finally {
782
+ evaluation.environment = environment;
670
783
  }
671
784
  },
672
- addState: (index, state, successors) => {
785
+ addState: (index, state, successors, tracing) => {
786
+ evaluation.environment = tracing ?? environment;
673
787
  shared.states.clear();
674
788
  shared.actions.clear();
675
- const set = getSuccessorSet(index, state, successors);
676
- for (const check of checks) {
677
- const actionResults = set.map((successor) =>
678
- checkAction(check, index, state, successor.state),
679
- );
680
- const stateResults = checkState(check, index, state);
681
- const tableau = check.solution.tableau;
682
- const accepted = tableau
683
- ? addTableauState(check, tableau, set, actionResults, stateResults, index)
684
- : addPlainState(check, set, actionResults, stateResults, index);
685
- if (accepted) return accepted;
789
+ try {
790
+ const set = getSuccessorSet(index, state, successors);
791
+ for (const check of checks) {
792
+ const actionResults = set.map((successor) =>
793
+ checkAction(check, index, state, successor.state),
794
+ );
795
+ const stateResults = checkState(check, index, state);
796
+ const tableau = check.solution.tableau;
797
+ const accepted = tableau
798
+ ? addTableauState(check, tableau, set, actionResults, stateResults, index)
799
+ : addPlainState(check, set, actionResults, stateResults, index);
800
+ if (accepted) return accepted;
801
+ }
802
+ return undefined;
803
+ } finally {
804
+ evaluation.environment = environment;
686
805
  }
687
- return undefined;
688
806
  },
689
807
  findViolation: () => {
690
808
  for (const check of checks) {