tla-ts 0.0.3-dev.3c70a97 → 0.0.3-dev.3ce2f00

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 (50) hide show
  1. package/README.md +5 -1
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.d.cts +53 -22
  4. package/dist/index.d.ts +53 -22
  5. package/dist/index.js +1 -1
  6. package/dist/parallel-worker.cjs +1 -1
  7. package/dist/parallel-worker.js +2 -2
  8. package/dist/parallel.cjs +1 -1
  9. package/dist/parallel.js +2 -2
  10. package/dist/run-cli.cjs +19 -17
  11. package/dist/run-cli.js +20 -18
  12. package/dist/transfer.cjs +33 -17
  13. package/dist/transfer.js +33 -17
  14. package/package.json +1 -1
  15. package/src/ast.ts +3 -0
  16. package/src/builtins.ts +9 -3
  17. package/src/check.ts +455 -93
  18. package/src/cli-options.ts +11 -5
  19. package/src/codegen.ts +6 -3
  20. package/src/config.ts +224 -170
  21. package/src/environment.ts +115 -19
  22. package/src/errors.ts +78 -1
  23. package/src/evaluate.ts +182 -26
  24. package/src/exit-codes.ts +22 -3
  25. package/src/fingerprints.ts +2 -1
  26. package/src/instances.ts +4 -4
  27. package/src/levels.ts +82 -36
  28. package/src/live-check.ts +132 -70
  29. package/src/liveness.ts +117 -22
  30. package/src/parallel-worker.ts +2 -2
  31. package/src/parallel.ts +5 -2
  32. package/src/parser.ts +57 -16
  33. package/src/resolve.ts +106 -29
  34. package/src/run-cli.ts +103 -18
  35. package/src/runtime.ts +2 -0
  36. package/src/spec-description.ts +12 -6
  37. package/src/standard-modules.ts +54 -45
  38. package/src/state-graph.ts +157 -0
  39. package/src/substitution-levels.ts +35 -11
  40. package/src/successors.ts +169 -33
  41. package/src/symmetry.ts +16 -6
  42. package/src/tableau.ts +51 -24
  43. package/src/tlc-ext.ts +27 -2
  44. package/src/tlc-module.ts +14 -33
  45. package/src/tlc-modules.ts +4 -0
  46. package/src/tlc-order.ts +8 -4
  47. package/src/tlc-random.ts +9 -6
  48. package/src/tlc-summary.ts +20 -5
  49. package/src/value-sources.ts +29 -0
  50. package/src/values.ts +242 -61
package/src/levels.ts CHANGED
@@ -5,11 +5,10 @@ import {
5
5
  type Expression,
6
6
  type Module,
7
7
  type OperatorParam,
8
- type SourceLocation,
9
8
  } from "./ast";
10
- import { TlaSyntaxError } from "./errors";
9
+ import { createSemanticError, TlaSyntaxError } from "./errors";
11
10
  import { mapChildren } from "./instances";
12
- import { getBoundNames, getPatternNames } from "./resolve";
11
+ import { collectSemanticErrors, getBoundNames, getPatternNames } from "./resolve";
13
12
  import { STANDARD_LEVELS } from "./standard-levels";
14
13
 
15
14
  interface LevelData {
@@ -34,6 +33,7 @@ interface LevelContext {
34
33
  constants: Set<string>;
35
34
  variables: Set<string>;
36
35
  getDefinition: (name: string) => Definition | undefined;
36
+ getQualifiedName?: (name: string) => string | undefined;
37
37
  }
38
38
 
39
39
  type ScopeEntry =
@@ -176,8 +176,13 @@ export const ACTION_LEVEL = 2;
176
176
 
177
177
  export const TEMPORAL_LEVEL = 3;
178
178
 
179
- const createLevelError = (message: string, location: SourceLocation) =>
180
- new TlaSyntaxError(`${message} at line ${location.line}, column ${location.column}`);
179
+ // SANY reports a level error at the range of the expression it rejects.
180
+ const createLevelError = (message: string, expression: Expression) =>
181
+ expression.location.range
182
+ ? createSemanticError(`${message}.`, expression.location.range)
183
+ : new TlaSyntaxError(
184
+ `${message} at line ${expression.location.line}, column ${expression.location.column}`,
185
+ );
181
186
 
182
187
  const LOGICAL_OPERATORS = new Set(["/\\", "\\/", "=>", "<=>"]);
183
188
 
@@ -201,7 +206,13 @@ export const createLevelAnalyzer = (context: LevelContext) => {
201
206
  if (context.variables.has(name)) return { kind: "Declared", name, level: 1, arity: 0 };
202
207
  const definition = context.getDefinition(name);
203
208
  if (definition) {
204
- return { kind: "Defined", levels: analyzeDefinition(definition, new Map()) };
209
+ const levels = analyzeDefinition(definition, new Map());
210
+ // SANY names a definition of an instance by its qualified name, as in I!Foo.
211
+ const qualifiedName = context.getQualifiedName?.(name);
212
+ return {
213
+ kind: "Defined",
214
+ levels: qualifiedName ? { ...levels, name: qualifiedName } : levels,
215
+ };
205
216
  }
206
217
  const signature = CORE_SIGNATURES.get(name) ?? STANDARD_LEVELS.get(name);
207
218
  if (signature) return { kind: "Defined", levels: signature };
@@ -237,13 +248,13 @@ export const createLevelAnalyzer = (context: LevelContext) => {
237
248
  if (operand.operator || operand.declared) return;
238
249
  if (operand.data.level > getMaxLevel(operator, index)) {
239
250
  throw new TlaSyntaxError(
240
- `Level error in applying operator ${operator.name}: The level of argument ${index + 1} exceeds the maximum level allowed by the operator.`,
251
+ `Level error in applying operator ${operator.name}:\nThe level of argument ${index + 1} exceeds the maximum level allowed by the operator`,
241
252
  );
242
253
  }
243
254
  });
244
255
  if (ranges.some((range) => range.level > ACTION_LEVEL)) {
245
256
  throw new TlaSyntaxError(
246
- `Level error in applying operator ${operator.name}: The level of the range for a bounded variable exceeds the maximum level allowed by the operator.`,
257
+ `Level error in applying operator ${operator.name}:\nThe level of the range for a bounded variable exceeds the maximum level allowed by the operator`,
247
258
  );
248
259
  }
249
260
  const getOperand = (formal: string) => {
@@ -444,10 +455,13 @@ export const createLevelAnalyzer = (context: LevelContext) => {
444
455
  ? applyDeclared(resolved.name, resolved.level, operands)
445
456
  : applyDefined(resolved.levels, operands);
446
457
 
447
- const checkJunction = (operands: Operand[], location: SourceLocation) => {
458
+ const checkJunction = (operands: Operand[], expression: Expression) => {
448
459
  const levels = operands.map((operand) => operand.data.level);
449
460
  if (levels.includes(ACTION_LEVEL) && levels.includes(TEMPORAL_LEVEL)) {
450
- throw createLevelError("Formula has both temporal formula and action as arguments", location);
461
+ throw createLevelError(
462
+ "Formula has both temporal formula and action as arguments",
463
+ expression,
464
+ );
451
465
  }
452
466
  };
453
467
 
@@ -456,10 +470,10 @@ export const createLevelAnalyzer = (context: LevelContext) => {
456
470
  if (isLeadsTo && operands.some((operand) => operand.data.level === ACTION_LEVEL)) {
457
471
  throw createLevelError(
458
472
  "Action used where only temporal formula or state predicate allowed",
459
- expression.location,
473
+ expression,
460
474
  );
461
475
  }
462
- if (LOGICAL_OPERATORS.has(expression.operator)) checkJunction(operands, expression.location);
476
+ if (LOGICAL_OPERATORS.has(expression.operator)) checkJunction(operands, expression);
463
477
  };
464
478
 
465
479
  const checkTemporal = (
@@ -473,7 +487,7 @@ export const createLevelAnalyzer = (context: LevelContext) => {
473
487
  expression.kind === "Always"
474
488
  ? "[] followed by action not of form [A]_v"
475
489
  : "<> followed by action not of form <<A>>_v",
476
- expression.location,
490
+ expression,
477
491
  );
478
492
  };
479
493
 
@@ -501,7 +515,17 @@ export const createLevelAnalyzer = (context: LevelContext) => {
501
515
  return data;
502
516
  };
503
517
 
518
+ // SANY reports a level error of an operator's arguments at the application.
504
519
  const analyze = (expression: Expression, scope: Scope): LevelData => {
520
+ try {
521
+ return analyzeNode(expression, scope);
522
+ } catch (error) {
523
+ if (!(error instanceof TlaSyntaxError) || error.sany) throw error;
524
+ throw createLevelError(error.message, expression);
525
+ }
526
+ };
527
+
528
+ const analyzeNode = (expression: Expression, scope: Scope): LevelData => {
505
529
  switch (expression.kind) {
506
530
  case "Number":
507
531
  case "Decimal":
@@ -521,7 +545,7 @@ export const createLevelAnalyzer = (context: LevelContext) => {
521
545
  case "And":
522
546
  case "Or": {
523
547
  const operands = toOperands(expression.operands, scope);
524
- checkJunction(operands, expression.location);
548
+ checkJunction(operands, expression);
525
549
  return applyDefined(JUNCTION_LEVELS, operands);
526
550
  }
527
551
  case "Prime":
@@ -561,13 +585,14 @@ export const createLevelAnalyzer = (context: LevelContext) => {
561
585
  expression.bounds.map((bound) => bound.set),
562
586
  getBoundNames(expression.bounds),
563
587
  );
564
- if (
565
- data.level === TEMPORAL_LEVEL &&
566
- expression.bounds.some((bound) => analyze(bound.set, scope).level === ACTION_LEVEL)
567
- ) {
588
+ const actionBound =
589
+ data.level === TEMPORAL_LEVEL
590
+ ? expression.bounds.find((bound) => analyze(bound.set, scope).level === ACTION_LEVEL)
591
+ : undefined;
592
+ if (actionBound) {
568
593
  throw createLevelError(
569
594
  "Action-level bound of quantified temporal formula",
570
- expression.location,
595
+ actionBound.set,
571
596
  );
572
597
  }
573
598
  return data;
@@ -817,34 +842,55 @@ export const createLevelAnalyzer = (context: LevelContext) => {
817
842
  return { analyze, analyzeDefinition, toOperand };
818
843
  };
819
844
 
820
- const analyzeAssumeProve = (
845
+ export const analyzeAssumeProve = (
821
846
  assumeProve: AssumeProve,
822
847
  scope: Scope,
823
848
  analyzer: ReturnType<typeof createLevelAnalyzer>,
824
- ) => {
849
+ ): LevelData => {
825
850
  const inner = new Map(scope);
826
- assumeProve.assumptions.forEach((assumption) => {
851
+ const parts = assumeProve.assumptions.flatMap((assumption) => {
827
852
  if (assumption.kind === "NewSymbol") {
828
- if (assumption.set) analyzer.analyze(assumption.set, inner);
853
+ const set = assumption.set && analyzer.analyze(assumption.set, inner);
829
854
  inner.set(assumption.name, { kind: "Formal", arity: assumption.arity });
830
- return;
855
+ return set ? [set] : [];
831
856
  }
832
- if (assumption.kind === "AssumeProve") analyzeAssumeProve(assumption, inner, analyzer);
833
- else analyzer.analyze(assumption, inner);
857
+ return [
858
+ assumption.kind === "AssumeProve"
859
+ ? analyzeAssumeProve(assumption, inner, analyzer)
860
+ : analyzer.analyze(assumption, inner),
861
+ ];
862
+ });
863
+ parts.push(analyzer.analyze(assumeProve.conclusion, inner));
864
+ const data = createData(Math.max(...parts.map((part) => part.level)));
865
+ parts.forEach((part) => {
866
+ part.params.forEach((param) => data.params.add(param));
867
+ part.constraints.forEach((value, key) => putConstraint(data.constraints, key, value));
868
+ part.argConstraints.forEach((value, key) => putArgConstraint(data.argConstraints, key, value));
869
+ part.argParams.forEach((key) => data.argParams.add(key));
834
870
  });
835
- analyzer.analyze(assumeProve.conclusion, inner);
871
+ return data;
836
872
  };
837
873
 
838
874
  // SANY checks the level of every definition, assumption, and theorem of a module.
839
875
  export const checkModuleLevels = (module: Module, context: LevelContext) => {
840
876
  const analyzer = createLevelAnalyzer(context);
841
- module.definitions
842
- .filter((definition) => !definition.name.includes("!"))
843
- .forEach((definition) => analyzer.analyzeDefinition(definition, new Map()));
844
- module.assumptions.forEach((assumption) => analyzer.analyze(assumption.expression, new Map()));
845
- module.theorems.forEach((theorem) =>
846
- theorem.statement.kind === "AssumeProve"
847
- ? analyzeAssumeProve(theorem.statement, new Map(), analyzer)
848
- : analyzer.analyze(theorem.statement, new Map()),
849
- );
877
+ collectSemanticErrors([
878
+ ...module.definitions
879
+ .filter((definition) => !definition.name.includes("!"))
880
+ .map((definition) => ({
881
+ location: definition.location,
882
+ check: () => analyzer.analyzeDefinition(definition, new Map()),
883
+ })),
884
+ ...module.assumptions.map((assumption) => ({
885
+ location: assumption.location,
886
+ check: () => analyzer.analyze(assumption.expression, new Map()),
887
+ })),
888
+ ...module.theorems.map((theorem) => ({
889
+ location: theorem.location,
890
+ check: () =>
891
+ theorem.statement.kind === "AssumeProve"
892
+ ? analyzeAssumeProve(theorem.statement, new Map(), analyzer)
893
+ : analyzer.analyze(theorem.statement, new Map()),
894
+ })),
895
+ ]);
850
896
  };
package/src/live-check.ts CHANGED
@@ -1,7 +1,9 @@
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,
6
+ TAUTOLOGY_MESSAGE,
5
7
  evaluateOnLasso,
6
8
  toLiveExpression,
7
9
  type ScopedExpression,
@@ -11,6 +13,7 @@ import {
11
13
  createJunction,
12
14
  createUnary,
13
15
  getSolutions,
16
+ getTermKey,
14
17
  isFulfilling,
15
18
  type LiveExpression,
16
19
  type Solution,
@@ -47,37 +50,21 @@ interface Check {
47
50
  actionIds: Int32Array;
48
51
  nodeStates: number[];
49
52
  nodeTableaux: number[];
50
- successors: number[][];
51
- actions: Uint8Array[];
52
- stateResults: Uint8Array[];
53
- isWritten: boolean[];
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 };
54
62
  initial: number[];
55
- nodeIds: Map<number, number>;
56
- nodesByState: Map<number, number[]>;
63
+ nodeIds: NodeTable;
57
64
  isDone: boolean[];
58
65
  errorNode: number | undefined;
59
66
  }
60
67
 
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
68
  const isSameState = (left: Value[], right: Value[]) =>
82
69
  left.every((value, position) => isSameValue(value, right[position]));
83
70
 
@@ -88,13 +75,45 @@ const removeRepeats = (path: number[]) =>
88
75
  const pushNode = (check: Check, state: number, tableauNode: number) => {
89
76
  check.nodeStates.push(state);
90
77
  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);
78
+ check.pending.push(undefined);
79
+ check.offsets.push(-1);
80
+ check.edgeOffsets.push(-1);
95
81
  return check.nodeStates.length - 1;
96
82
  };
97
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
+ // 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;
106
+
107
+ const getPending = (check: Check, node: number) => (check.pending[node] ??= []);
108
+
109
+ 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]);
112
+ };
113
+
114
+ const getStateResult = (check: Check, node: number, position: number) =>
115
+ check.results.bytes[check.offsets[node] + position] === 1;
116
+
98
117
  const SUCCESSOR_CAPACITY = 16;
99
118
 
100
119
  const SCC_MARKER = -42;
@@ -121,26 +140,29 @@ export const createLivenessChecker = (
121
140
  fairness.length === 0 ? violation : createJunction("And", [...fairness, violation]);
122
141
  const solutions = getSolutions(formula);
123
142
  if (solutions.length === 0) {
124
- throw new TlaEvaluationError("Temporal formula is a tautology (its negation is unsatisfiable)");
143
+ throw setExitCode(
144
+ new TlaEvaluationError(TAUTOLOGY_MESSAGE),
145
+ EXIT_STATUS.livenessEvaluationFailure,
146
+ );
125
147
  }
126
148
  const actionIds = new Map<string, number>();
127
149
  const checks = solutions.map((solution): Check => ({
128
150
  solution,
129
151
  actionIds: Int32Array.from(solution.actionChecks, (predicate) => {
130
- const key = getLiveKey(predicate);
152
+ const key = getTermKey(predicate);
131
153
  const id = actionIds.get(key) ?? actionIds.size;
132
154
  actionIds.set(key, id);
133
155
  return id;
134
156
  }),
135
157
  nodeStates: [],
136
158
  nodeTableaux: [],
137
- successors: [],
138
- actions: [],
139
- stateResults: [],
140
- isWritten: [],
159
+ pending: [],
160
+ offsets: [],
161
+ results: { bytes: new Uint8Array(1024), length: 0 },
162
+ edgeOffsets: [],
163
+ edges: { ids: new Int32Array(1024), length: 0 },
141
164
  initial: [],
142
- nodeIds: new Map(),
143
- nodesByState: new Map(),
165
+ nodeIds: { slots: new Int32Array(3 << 10), size: 0, shift: 22 },
144
166
  isDone: [],
145
167
  errorNode: undefined,
146
168
  }));
@@ -226,18 +248,35 @@ export const createLivenessChecker = (
226
248
  model.infinitelyOftenActions.length === 0,
227
249
  );
228
250
 
229
- const getNodeId = (check: Check, state: number, tableauNode: number) =>
230
- check.solution.tableau
231
- ? check.nodeIds.get(state * check.solution.tableau.nodes.length + tableauNode)
232
- : state;
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
+ };
233
257
  const recordNode = (check: Check, state: number, tableauNode: number) => {
234
258
  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]);
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));
239
273
  return node;
240
274
  };
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);
241
280
  const writeNode = (
242
281
  check: Check,
243
282
  node: number,
@@ -245,11 +284,32 @@ export const createLivenessChecker = (
245
284
  stateResults: Uint8Array,
246
285
  ) => {
247
286
  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;
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),
298
+ );
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;
253
313
  };
254
314
 
255
315
  // TLC collects a state's successors and the state itself in a SetOfStates, a hash set it
@@ -302,7 +362,7 @@ export const createLivenessChecker = (
302
362
  const stateResults = checkState(check, index, state);
303
363
  const tableauNode = tableau.nodes[check.nodeTableaux[node]];
304
364
  const actions: Uint8Array[] = [];
305
- const successors = check.successors[node];
365
+ const successors = getPending(check, node);
306
366
  const selfActions =
307
367
  tableauNode.successors.length > 0
308
368
  ? checkAction(check, index, state, state)
@@ -351,8 +411,8 @@ export const createLivenessChecker = (
351
411
  );
352
412
  check.isDone[index] = true;
353
413
  // 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];
414
+ for (const node of getStateNodes(check, tableau, index)) {
415
+ const successors = getPending(check, node);
356
416
  const actions: Uint8Array[] = [];
357
417
  set.forEach((successor, position) => {
358
418
  const isDone = check.isDone[successor.index] === true;
@@ -386,10 +446,10 @@ export const createLivenessChecker = (
386
446
  index: number,
387
447
  ) => {
388
448
  while (check.nodeStates.length <= index) pushNode(check, check.nodeStates.length, -1);
389
- const successors = check.successors[index];
449
+ const successors = getPending(check, index);
390
450
  const actions: Uint8Array[] = [];
391
451
  set.forEach((successor, position) => {
392
- if (check.isWritten[successor.index] && successors.includes(successor.index)) return;
452
+ if (isWritten(check, successor.index) && successors.includes(successor.index)) return;
393
453
  successors.push(successor.index);
394
454
  actions.push(actionResults[position]);
395
455
  });
@@ -403,20 +463,20 @@ export const createLivenessChecker = (
403
463
  const parents = new Map<number, number>();
404
464
  const queue: number[] = [];
405
465
  for (const node of check.initial) {
406
- if (!check.isWritten[node]) continue;
466
+ if (!isWritten(check, node)) continue;
407
467
  queue.push(node);
408
468
  parents.set(node, -1);
409
469
  }
410
470
  for (let position = 0; position < queue.length; position++) {
411
471
  const current = queue[position];
412
- for (const next of check.successors[current]) {
472
+ for (const next of getSuccessors(check, current)) {
413
473
  if (next === current && check.solution.tableau) continue;
414
474
  if (next === target) {
415
475
  const path = [target];
416
476
  for (let node = current; node !== -1; node = parents.get(node) ?? -1) path.push(node);
417
477
  return path;
418
478
  }
419
- if (!check.isWritten[next] || parents.has(next)) continue;
479
+ if (!isWritten(check, next) || parents.has(next)) continue;
420
480
  parents.set(next, current);
421
481
  queue.push(next);
422
482
  }
@@ -428,16 +488,17 @@ export const createLivenessChecker = (
428
488
  const findInModel = (check: Check, model: Solution["models"][number]): Lasso | undefined => {
429
489
  const solution = check.solution;
430
490
  const actionCount = solution.actionChecks.length;
491
+ const stateCount = solution.stateChecks.length;
431
492
  const getAction = (node: number, edge: number, position: number) =>
432
- check.actions[node][edge * actionCount + position] === 1;
493
+ check.results.bytes[check.offsets[node] + stateCount + edge * actionCount + position] === 1;
433
494
  const isAllowed = (node: number, edge: number) =>
434
495
  model.eventuallyAlways.every((position) => getAction(node, edge, position));
435
496
  const links = new Float64Array(check.nodeStates.length).fill(UNVISITED);
436
- const queue = check.initial.filter((node) => check.isWritten[node]);
497
+ const queue = check.initial.filter((node) => isWritten(check, node));
437
498
  const components: number[] = [];
438
499
 
439
500
  const isStuttering = (node: number) => {
440
- const edge = check.successors[node].indexOf(node);
501
+ const edge = getSuccessors(check, node).indexOf(node);
441
502
  return edge !== -1 && isAllowed(node, edge);
442
503
  };
443
504
  const isFulfilled = (node: number, promise: Solution["promises"][number]) =>
@@ -461,11 +522,11 @@ export const createLivenessChecker = (
461
522
  if (member === root) break;
462
523
  }
463
524
  const isStateSatisfied = model.infinitelyOftenStates.every((position) =>
464
- [...members].some((node) => check.stateResults[node][position] === 1),
525
+ [...members].some((node) => getStateResult(check, node, position)),
465
526
  );
466
527
  const isActionSatisfied = model.infinitelyOftenActions.every((position) =>
467
528
  [...members].some((node) =>
468
- check.successors[node].some(
529
+ getSuccessors(check, node).some(
469
530
  (next, edge) =>
470
531
  members.has(next) && isAllowed(node, edge) && getAction(node, edge, position),
471
532
  ),
@@ -506,7 +567,7 @@ export const createLivenessChecker = (
506
567
  const countAtStart = remaining.count;
507
568
  while (true) {
508
569
  model.infinitelyOftenStates.forEach((position, slot) => {
509
- if (!stateDone[slot] && check.stateResults[current.node][position] === 1) {
570
+ if (!stateDone[slot] && getStateResult(check, current.node, position)) {
510
571
  stateDone[slot] = true;
511
572
  remaining.count--;
512
573
  }
@@ -520,7 +581,7 @@ export const createLivenessChecker = (
520
581
  if (remaining.count <= 0) break;
521
582
  const step = { last: -1, unvisited: -1 };
522
583
  const countBeforeActions = remaining.count;
523
- const successors = check.successors[current.node];
584
+ const successors = getSuccessors(check, current.node);
524
585
  const taken = successors.some((next, edge) => {
525
586
  if (membersByState.has(check.nodeStates[next])) {
526
587
  if (!isMember(next) || !isAllowed(current.node, edge)) return false;
@@ -555,7 +616,8 @@ export const createLivenessChecker = (
555
616
  }
556
617
  current.node = previous;
557
618
  step.unvisited =
558
- check.successors[previous].find((next) => isMember(next) && !seen.has(next)) ?? -1;
619
+ getSuccessors(check, previous).find((next) => isMember(next) && !seen.has(next)) ??
620
+ -1;
559
621
  }
560
622
  take(step.unvisited);
561
623
  seen.add(step.unvisited);
@@ -585,7 +647,7 @@ export const createLivenessChecker = (
585
647
  const queue: [number, number][] = [];
586
648
  for (let state = start, parent = -1, position = 0; ; position++) {
587
649
  for (const node of membersByState.get(state) ?? []) {
588
- for (const [edge, next] of check.successors[node].entries()) {
650
+ for (const [edge, next] of getSuccessors(check, node).entries()) {
589
651
  if (next === node || !isAllowedEdge(node, edge)) continue;
590
652
  if (next === root) {
591
653
  const path: number[] = [];
@@ -638,8 +700,8 @@ export const createLivenessChecker = (
638
700
  stack.push(lowLink, node, SCC_MARKER);
639
701
  components.push(node);
640
702
  const nextLowLink = { value: counter.link++ };
641
- check.successors[node].forEach((next, edge) => {
642
- if (!check.isWritten[next]) return;
703
+ getSuccessors(check, node).forEach((next, edge) => {
704
+ if (!isWritten(check, next)) return;
643
705
  if (!isAllowed(node, edge)) {
644
706
  if (links[next] === UNVISITED) queue.push(next);
645
707
  return;