tla-ts 0.0.3-dev.d9ff6f2 → 0.0.3-dev.e8bef80

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 +166 -40
  5. package/dist/index.d.ts +166 -40
  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 -22
  12. package/dist/run-cli.js +1351 -22
  13. package/dist/transfer.cjs +83 -34
  14. package/dist/transfer.js +83 -34
  15. package/package.json +5 -1
  16. package/src/ast.ts +55 -7
  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 +1331 -367
  22. package/src/cli.ts +8 -1
  23. package/src/codegen.ts +68 -21
  24. package/src/config.ts +226 -207
  25. package/src/environment.ts +423 -127
  26. package/src/errors.ts +168 -9
  27. package/src/evaluate.ts +720 -177
  28. package/src/exit-codes.ts +6 -24
  29. package/src/index.ts +1 -0
  30. package/src/instances.ts +3 -1
  31. package/src/java-overrides.ts +104 -25
  32. package/src/levels.ts +149 -31
  33. package/src/lexer.ts +122 -29
  34. package/src/live-check.ts +204 -148
  35. package/src/liveness.ts +191 -122
  36. package/src/obligation-expression.ts +2 -2
  37. package/src/obligation-source.ts +2 -0
  38. package/src/parallel-worker.ts +6 -1
  39. package/src/parallel.ts +57 -6
  40. package/src/parser.ts +428 -141
  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 +1436 -459
  48. package/src/run-cli.ts +1166 -181
  49. package/src/runtime.ts +16 -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 +356 -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 +25 -5
  63. package/src/standard-modules.ts +203 -146
  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 +161 -167
  69. package/src/symmetry.ts +168 -50
  70. package/src/tableau.ts +3 -1
  71. package/src/tlc-ext.ts +13 -17
  72. package/src/tlc-messages.ts +329 -0
  73. package/src/tlc-module.ts +49 -21
  74. package/src/tlc-modules.ts +0 -4
  75. package/src/tlc-order.ts +55 -9
  76. package/src/tlc-random.ts +28 -3
  77. package/src/tlc-replay.ts +655 -0
  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 +680 -255
package/src/live-check.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { TlaEvaluationError } from "./errors";
2
- import { EXIT_STATUS, setExitCode } from "./exit-codes";
3
2
  import { hasRepeatedEffects, type Environment } from "./evaluate";
4
3
  import {
4
+ createTautologyError,
5
5
  evaluateLive,
6
- TAUTOLOGY_MESSAGE,
7
6
  evaluateOnLasso,
8
7
  toLiveExpression,
9
8
  type ScopedExpression,
@@ -29,18 +28,38 @@ export interface LiveSuccessor {
29
28
  export interface Lasso {
30
29
  prefix: number[];
31
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;
32
34
  }
33
35
 
34
36
  export interface LivenessChecker {
35
- addInitialState: (index: number, state: Value[]) => void;
36
- 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;
37
48
  findViolation: () => Lasso | undefined;
38
49
  getViolatedProperties: (path: Value[][], cycleStart: number) => string[];
39
50
  }
40
51
 
41
52
  export interface LiveGraph {
42
- getFingerprint: (index: number) => number;
43
- 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;
44
63
  }
45
64
 
46
65
  // TLC's behavior graph for one solution: a node per state, or per state and tableau node.
@@ -50,69 +69,115 @@ interface Check {
50
69
  actionIds: Int32Array;
51
70
  nodeStates: number[];
52
71
  nodeTableaux: number[];
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 };
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>;
62
81
  initial: number[];
63
- nodeIds: NodeTable;
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[];
64
86
  isDone: boolean[];
65
87
  errorNode: number | undefined;
66
88
  }
67
89
 
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
+ }
104
+ };
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
+
68
116
  const isSameState = (left: Value[], right: Value[]) =>
69
117
  left.every((value, position) => isSameValue(value, right[position]));
70
118
 
71
119
  const removeRepeats = (path: number[]) =>
72
120
  path.filter((node, position) => position === 0 || path[position - 1] !== node);
73
121
 
74
- // A node owns one entry in each of its check's per-node arrays.
75
- const pushNode = (check: Check, state: number, tableauNode: number) => {
76
- check.nodeStates.push(state);
77
- check.nodeTableaux.push(tableauNode);
78
- check.pending.push(undefined);
79
- check.offsets.push(-1);
80
- check.edgeOffsets.push(-1);
81
- return check.nodeStates.length - 1;
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);
82
139
  };
83
140
 
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
- }
141
+ const NO_NODE = -1;
91
142
 
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
- };
143
+ const createNodes = (length: number) => new Int32Array(length).fill(NO_NODE);
102
144
 
103
- // Without a tableau a node is a state, so a successor the search hasn't expanded yet may lie past
104
- // the per-node arrays.
105
- const isWritten = (check: Check, node: number) => (check.offsets[node] ?? -1) !== -1;
145
+ const UNWRITTEN = -1;
106
146
 
107
- const getPending = (check: Check, node: number) => (check.pending[node] ??= []);
147
+ const isWritten = (check: Check, node: number) =>
148
+ (check.edgeStarts[node] ?? UNWRITTEN) !== UNWRITTEN;
108
149
 
109
150
  const getSuccessors = (check: Check, node: number) => {
110
- const offset = check.edgeOffsets[node];
111
- return check.edges.ids.subarray(offset + 1, offset + 1 + check.edges.ids[offset]);
151
+ const start = check.edgeStarts[node];
152
+ return check.edgeTargets.data.subarray(start, start + check.edgeCounts[node]);
112
153
  };
113
154
 
114
155
  const getStateResult = (check: Check, node: number, position: number) =>
115
- check.results.bytes[check.offsets[node] + position] === 1;
156
+ check.stateResults.data[check.nodeStates[node] * check.solution.stateChecks.length + position] ===
157
+ 1;
158
+
159
+ // A node owns one entry in each of its check's per-node arrays.
160
+ const pushNode = (check: Check, state: number, tableauNode: number) => {
161
+ check.nodeStates.push(state);
162
+ check.nodeTableaux.push(tableauNode);
163
+ check.edgeStarts.push(UNWRITTEN);
164
+ check.edgeCounts.push(0);
165
+ check.nextSiblings.push(NO_NODE);
166
+ return check.nodeStates.length - 1;
167
+ };
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
+ };
116
181
 
117
182
  const SUCCESSOR_CAPACITY = 16;
118
183
 
@@ -140,10 +205,7 @@ export const createLivenessChecker = (
140
205
  fairness.length === 0 ? violation : createJunction("And", [...fairness, violation]);
141
206
  const solutions = getSolutions(formula);
142
207
  if (solutions.length === 0) {
143
- throw setExitCode(
144
- new TlaEvaluationError(TAUTOLOGY_MESSAGE),
145
- EXIT_STATUS.livenessEvaluationFailure,
146
- );
208
+ throw createTautologyError();
147
209
  }
148
210
  const actionIds = new Map<string, number>();
149
211
  const checks = solutions.map((solution): Check => ({
@@ -156,13 +218,15 @@ export const createLivenessChecker = (
156
218
  }),
157
219
  nodeStates: [],
158
220
  nodeTableaux: [],
159
- pending: [],
160
- offsets: [],
161
- results: { bytes: new Uint8Array(1024), length: 0 },
162
- edgeOffsets: [],
163
- edges: { ids: new Int32Array(1024), length: 0 },
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)),
164
226
  initial: [],
165
- nodeIds: { slots: new Int32Array(3 << 10), size: 0, shift: 22 },
227
+ firstNodes: createPool(createNodes),
228
+ lastNodes: createPool(createNodes),
229
+ nextSiblings: [],
166
230
  isDone: [],
167
231
  errorNode: undefined,
168
232
  }));
@@ -171,6 +235,7 @@ export const createLivenessChecker = (
171
235
  // TLC evaluates every check on its own. Without side effects the order can't show, so the
172
236
  // checks of one state share their results.
173
237
  const isShared = !hasRepeatedEffects(environment);
238
+ const evaluation = { environment };
174
239
  const shared = {
175
240
  states: new Map<Value[], Map<LiveExpression, boolean>>(),
176
241
  actions: new Map<Value[], Map<Value[], Int8Array>>(),
@@ -192,7 +257,7 @@ export const createLivenessChecker = (
192
257
  predicate,
193
258
  state,
194
259
  undefined,
195
- environment,
260
+ evaluation.environment,
196
261
  isShared ? getStateCache(state) : new Map(),
197
262
  );
198
263
  const checkState = (check: Check, source: number, state: Value[]) =>
@@ -206,7 +271,7 @@ export const createLivenessChecker = (
206
271
  const predicates = check.solution.actionChecks;
207
272
  if (!isShared) {
208
273
  return Uint8Array.from(predicates, (predicate) =>
209
- evaluateLive(predicate, state, successor, environment, new Map()) ? 1 : 0,
274
+ evaluateLive(predicate, state, successor, evaluation.environment, new Map()) ? 1 : 0,
210
275
  );
211
276
  }
212
277
  const stateCache = getStateCache(state);
@@ -216,7 +281,13 @@ export const createLivenessChecker = (
216
281
  results.set(successor, known);
217
282
  return Uint8Array.from(check.actionIds, (id, position) => {
218
283
  if (known[id] === -1) {
219
- 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
+ )
220
291
  ? 1
221
292
  : 0;
222
293
  }
@@ -232,7 +303,10 @@ export const createLivenessChecker = (
232
303
  evaluateFrom(source, () =>
233
304
  tableau.nodes[node].statePredicates.every((predicate) => evaluateState(predicate, state)),
234
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.
235
308
  const isAccepting = (tableau: Tableau, node: number) => {
309
+ if (environment.runtime.version === "1.7.4") return false;
236
310
  const tableauNode = tableau.nodes[node];
237
311
  return (
238
312
  tableauNode.particle.length === 0 &&
@@ -248,68 +322,34 @@ export const createLivenessChecker = (
248
322
  model.infinitelyOftenActions.length === 0,
249
323
  );
250
324
 
251
- const getNodeId = (check: Check, state: number, tableauNode: number) => {
252
- if (!check.solution.tableau) return state;
253
- const slots = check.nodeIds.slots;
254
- const slot = getNodeSlot(check.nodeIds, state, tableauNode);
255
- return slots[slot] === 0 ? undefined : slots[slot + 2];
256
- };
325
+ const getNodeId = (check: Check, state: number, tableauNode: number) =>
326
+ check.solution.tableau
327
+ ? getStateNodes(check, state).find((node) => check.nodeTableaux[node] === tableauNode)
328
+ : state;
257
329
  const recordNode = (check: Check, state: number, tableauNode: number) => {
258
330
  const node = pushNode(check, state, tableauNode);
259
- const table = check.nodeIds;
260
- if (++table.size * 2 > table.slots.length / 3) {
261
- const old = table.slots;
262
- table.slots = new Int32Array(old.length * 2);
263
- table.shift--;
264
- for (let slot = 0; slot < old.length; slot += 3) {
265
- if (old[slot] !== 0)
266
- table.slots.set(
267
- old.subarray(slot, slot + 3),
268
- getNodeSlot(table, old[slot] - 1, old[slot + 1]),
269
- );
270
- }
271
- }
272
- table.slots.set([state + 1, tableauNode, node], getNodeSlot(table, state, tableauNode));
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]);
273
335
  return node;
274
336
  };
275
- // A state's nodes in the order they were recorded, which is the order of their ids.
276
- const getStateNodes = (check: Check, tableau: Tableau, state: number) =>
277
- tableau.nodes
278
- .flatMap((_, tableauNode) => getNodeId(check, state, tableauNode) ?? [])
279
- .sort((left, right) => left - right);
280
337
  const writeNode = (
281
338
  check: Check,
282
339
  node: number,
340
+ targets: number[],
283
341
  actions: Uint8Array[],
284
342
  stateResults: Uint8Array,
285
343
  ) => {
344
+ const start = check.edgeTargets.length;
286
345
  const actionCount = check.solution.actionChecks.length;
287
- const results = check.results;
288
- const offset = results.length;
289
- results.length += stateResults.length + actions.length * actionCount;
290
- if (results.length > results.bytes.length) {
291
- const grown = new Uint8Array(Math.max(2 * results.bytes.length, results.length));
292
- grown.set(results.bytes);
293
- results.bytes = grown;
294
- }
295
- results.bytes.set(stateResults, offset);
296
- actions.forEach((edge, position) =>
297
- results.bytes.set(edge, offset + stateResults.length + position * actionCount),
346
+ writeToPool(check.edgeTargets, start, targets);
347
+ actions.forEach((results, position) =>
348
+ writeToPool(check.edgeActions, (start + position) * actionCount, results),
298
349
  );
299
- check.offsets[node] = offset;
300
- const successors = check.pending[node] ?? [];
301
- const edges = check.edges;
302
- const edgeOffset = edges.length;
303
- edges.length += successors.length + 1;
304
- if (edges.length > edges.ids.length) {
305
- const grown = new Int32Array(Math.max(2 * edges.ids.length, edges.length));
306
- grown.set(edges.ids);
307
- edges.ids = grown;
308
- }
309
- edges.ids[edgeOffset] = successors.length;
310
- edges.ids.set(successors, edgeOffset + 1);
311
- check.edgeOffsets[node] = edgeOffset;
312
- check.pending[node] = undefined;
350
+ writeToPool(check.stateResults, check.nodeStates[node] * stateResults.length, stateResults);
351
+ check.edgeStarts[node] = start;
352
+ check.edgeCounts[node] = targets.length;
313
353
  };
314
354
 
315
355
  // TLC collects a state's successors and the state itself in a SetOfStates, a hash set it
@@ -324,7 +364,7 @@ export const createLivenessChecker = (
324
364
  };
325
365
  const insert = (slots: (LiveSuccessor | undefined)[], successor: LiveSuccessor) => {
326
366
  for (
327
- let slot = (graph.getFingerprint(successor.index) & 0x7fffffff) % slots.length;
367
+ let slot = (graph.getFingerprint(successor) & 0x7fffffff) % slots.length;
328
368
  ;
329
369
  slot = (slot + 1) % slots.length
330
370
  ) {
@@ -362,7 +402,7 @@ export const createLivenessChecker = (
362
402
  const stateResults = checkState(check, index, state);
363
403
  const tableauNode = tableau.nodes[check.nodeTableaux[node]];
364
404
  const actions: Uint8Array[] = [];
365
- const successors = getPending(check, node);
405
+ const successors: number[] = [];
366
406
  const selfActions =
367
407
  tableauNode.successors.length > 0
368
408
  ? checkAction(check, index, state, state)
@@ -380,11 +420,14 @@ export const createLivenessChecker = (
380
420
  actions.push(selfActions);
381
421
  if (existing === undefined) expandLate(check, tableau, state, index, target);
382
422
  }
383
- for (const successor of graph.getSuccessors(state)) {
423
+ for (const successor of graph.getSuccessors(index, state)) {
384
424
  const successorActions = checkAction(check, index, state, successor.state);
385
425
  const isDone = check.isDone[successor.index] === true;
386
426
  for (const next of tableauNode.successors) {
387
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;
388
431
  const existing = getNodeId(check, successor.index, next);
389
432
  if (existing !== undefined && successors.includes(existing)) continue;
390
433
  const target = existing ?? recordNode(check, successor.index, next);
@@ -395,7 +438,7 @@ export const createLivenessChecker = (
395
438
  }
396
439
  }
397
440
  }
398
- if (successors.length > 0) writeNode(check, node, actions, stateResults);
441
+ if (successors.length > 0) writeNode(check, node, successors, actions, stateResults);
399
442
  };
400
443
 
401
444
  const addTableauState = (
@@ -411,8 +454,8 @@ export const createLivenessChecker = (
411
454
  );
412
455
  check.isDone[index] = true;
413
456
  // TLC expands the nodes recorded before the loop, not the ones the loop records.
414
- for (const node of getStateNodes(check, tableau, index)) {
415
- const successors = getPending(check, node);
457
+ for (const node of getStateNodes(check, index)) {
458
+ const successors: number[] = [];
416
459
  const actions: Uint8Array[] = [];
417
460
  set.forEach((successor, position) => {
418
461
  const isDone = check.isDone[successor.index] === true;
@@ -428,7 +471,7 @@ export const createLivenessChecker = (
428
471
  }
429
472
  }
430
473
  });
431
- writeNode(check, node, actions, stateResults);
474
+ writeNode(check, node, successors, actions, stateResults);
432
475
  }
433
476
  if (check.errorNode === undefined) return undefined;
434
477
  return removeRepeats(
@@ -446,14 +489,14 @@ export const createLivenessChecker = (
446
489
  index: number,
447
490
  ) => {
448
491
  while (check.nodeStates.length <= index) pushNode(check, check.nodeStates.length, -1);
449
- const successors = getPending(check, index);
492
+ const successors: number[] = [];
450
493
  const actions: Uint8Array[] = [];
451
494
  set.forEach((successor, position) => {
452
495
  if (isWritten(check, successor.index) && successors.includes(successor.index)) return;
453
496
  successors.push(successor.index);
454
497
  actions.push(actionResults[position]);
455
498
  });
456
- writeNode(check, index, actions, stateResults);
499
+ writeNode(check, index, successors, actions, stateResults);
457
500
  return undefined;
458
501
  };
459
502
 
@@ -488,9 +531,8 @@ export const createLivenessChecker = (
488
531
  const findInModel = (check: Check, model: Solution["models"][number]): Lasso | undefined => {
489
532
  const solution = check.solution;
490
533
  const actionCount = solution.actionChecks.length;
491
- const stateCount = solution.stateChecks.length;
492
534
  const getAction = (node: number, edge: number, position: number) =>
493
- check.results.bytes[check.offsets[node] + stateCount + edge * actionCount + position] === 1;
535
+ check.edgeActions.data[(check.edgeStarts[node] + edge) * actionCount + position] === 1;
494
536
  const isAllowed = (node: number, edge: number) =>
495
537
  model.eventuallyAlways.every((position) => getAction(node, edge, position));
496
538
  const links = new Float64Array(check.nodeStates.length).fill(UNVISITED);
@@ -581,8 +623,7 @@ export const createLivenessChecker = (
581
623
  if (remaining.count <= 0) break;
582
624
  const step = { last: -1, unvisited: -1 };
583
625
  const countBeforeActions = remaining.count;
584
- const successors = getSuccessors(check, current.node);
585
- const taken = successors.some((next, edge) => {
626
+ const taken = getSuccessors(check, current.node).some((next, edge) => {
586
627
  if (membersByState.has(check.nodeStates[next])) {
587
628
  if (!isMember(next) || !isAllowed(current.node, edge)) return false;
588
629
  step.last = next;
@@ -630,7 +671,11 @@ export const createLivenessChecker = (
630
671
  }
631
672
  const cycleState = prefix[prefix.length - 1];
632
673
  if (postfix[postfix.length - 1] === cycleState) postfix.pop();
633
- 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
+ };
634
679
  };
635
680
 
636
681
  // TLC's LiveWorker#bfsPostFix, the states from the walk's end back to the root, last first.
@@ -716,37 +761,48 @@ export const createLivenessChecker = (
716
761
  };
717
762
 
718
763
  return {
719
- addInitialState: (index, state) => {
764
+ branches: checks.length,
765
+ addInitialState: (index, state, tracing) => {
766
+ evaluation.environment = tracing ?? environment;
720
767
  shared.states.clear();
721
768
  shared.actions.clear();
722
- for (const check of checks) {
723
- const tableau = check.solution.tableau;
724
- if (!tableau) {
725
- check.initial.push(index);
726
- continue;
727
- }
728
- for (let node = 0; node < tableau.initialCount; node++) {
729
- if (!isConsistent(tableau, node, undefined, state)) continue;
730
- 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
+ }
731
780
  }
781
+ } finally {
782
+ evaluation.environment = environment;
732
783
  }
733
784
  },
734
- addState: (index, state, successors) => {
785
+ addState: (index, state, successors, tracing) => {
786
+ evaluation.environment = tracing ?? environment;
735
787
  shared.states.clear();
736
788
  shared.actions.clear();
737
- const set = getSuccessorSet(index, state, successors);
738
- for (const check of checks) {
739
- const actionResults = set.map((successor) =>
740
- checkAction(check, index, state, successor.state),
741
- );
742
- const stateResults = checkState(check, index, state);
743
- const tableau = check.solution.tableau;
744
- const accepted = tableau
745
- ? addTableauState(check, tableau, set, actionResults, stateResults, index)
746
- : addPlainState(check, set, actionResults, stateResults, index);
747
- 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;
748
805
  }
749
- return undefined;
750
806
  },
751
807
  findViolation: () => {
752
808
  for (const check of checks) {