tla-ts 0.0.3-dev.e927a09 → 0.0.3-dev.e9c5857

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 (47) hide show
  1. package/README.md +5 -1
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.d.cts +52 -22
  4. package/dist/index.d.ts +52 -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 +32 -15
  13. package/dist/transfer.js +32 -15
  14. package/package.json +1 -1
  15. package/src/ast.ts +3 -0
  16. package/src/check.ts +419 -68
  17. package/src/cli-options.ts +11 -5
  18. package/src/codegen.ts +6 -3
  19. package/src/config.ts +224 -170
  20. package/src/environment.ts +106 -18
  21. package/src/errors.ts +71 -3
  22. package/src/evaluate.ts +178 -23
  23. package/src/exit-codes.ts +21 -14
  24. package/src/instances.ts +4 -4
  25. package/src/levels.ts +55 -27
  26. package/src/live-check.ts +132 -70
  27. package/src/liveness.ts +117 -22
  28. package/src/parallel-worker.ts +2 -2
  29. package/src/parallel.ts +5 -2
  30. package/src/parser.ts +21 -10
  31. package/src/resolve.ts +106 -29
  32. package/src/run-cli.ts +90 -17
  33. package/src/runtime.ts +2 -0
  34. package/src/spec-description.ts +12 -6
  35. package/src/standard-modules.ts +10 -9
  36. package/src/state-graph.ts +157 -0
  37. package/src/successors.ts +131 -28
  38. package/src/symmetry.ts +16 -6
  39. package/src/tableau.ts +51 -24
  40. package/src/tlc-ext.ts +27 -2
  41. package/src/tlc-module.ts +14 -33
  42. package/src/tlc-modules.ts +4 -0
  43. package/src/tlc-order.ts +8 -4
  44. package/src/tlc-random.ts +9 -6
  45. package/src/tlc-summary.ts +20 -5
  46. package/src/value-sources.ts +29 -0
  47. package/src/values.ts +172 -53
package/src/exit-codes.ts CHANGED
@@ -17,12 +17,6 @@ export const EXIT_STATUS = {
17
17
  } as const;
18
18
 
19
19
  const exitCodes = new WeakMap<Error, number>();
20
- const moduleExitCodes = new WeakMap<Error, number>();
21
- const phase = { isNextState: false };
22
-
23
- export const setNextStatePhase = (isNextState: boolean) => {
24
- phase.isNextState = isNextState;
25
- };
26
20
 
27
21
  // The innermost site that knows TLC's exit status for an error sets it first and wins.
28
22
  export const setExitCode = <Thrown>(error: Thrown, code: number) => {
@@ -30,15 +24,21 @@ export const setExitCode = <Thrown>(error: Thrown, code: number) => {
30
24
  return error;
31
25
  };
32
26
 
33
- // TLC exits with the code of an exception from a standard module's Java code only when the exception
34
- // escapes the computation of next states. In every other phase, the phase decides the code.
35
- export const setModuleExitCode = (error: Error, code: number) => {
36
- if (phase.isNextState) moduleExitCodes.set(error, code);
27
+ export const getExitCode = (error: Error) => exitCodes.get(error);
28
+
29
+ const ownExitCodes = new WeakMap<Error, number>();
30
+
31
+ // The exit status of the error code TLC gives an EvalException, which TLC uses only where it
32
+ // doesn't report the error again as a nested expression.
33
+ export const setOwnExitCode = <Thrown extends Error>(error: Thrown, code: number) => {
34
+ ownExitCodes.set(error, code);
35
+ return error;
37
36
  };
38
37
 
39
- export const getExitCode = (error: Error) => exitCodes.get(error) ?? moduleExitCodes.get(error);
38
+ export const getOwnExitCode = (error: unknown) =>
39
+ error instanceof Error ? ownExitCodes.get(error) : undefined;
40
40
 
41
- // TLC exits with 255 when it fails to process or evaluate a liveness property, in any phase.
41
+ // TLC exits with 255 when it fails to process or evaluate a liveness property.
42
42
  const withErrorExitCode = <Result>(run: () => Result) => {
43
43
  try {
44
44
  return run();
@@ -53,8 +53,15 @@ export const withLivenessExitCode = (
53
53
  const checker = withErrorExitCode(create);
54
54
  return (
55
55
  checker && {
56
- addInitialState: (index, state) =>
57
- withErrorExitCode(() => checker.addInitialState(index, state)),
56
+ // TLC replays the initial states to report an error, but skips the liveness check of a
57
+ // state it has already seen, so it exits with the status of the error's own code.
58
+ addInitialState: (index, state) => {
59
+ try {
60
+ checker.addInitialState(index, state);
61
+ } catch (error) {
62
+ throw setExitCode(error, getOwnExitCode(error) ?? EXIT_STATUS.error);
63
+ }
64
+ },
58
65
  addState: (index, state, successors) =>
59
66
  withErrorExitCode(() => checker.addState(index, state, successors)),
60
67
  findViolation: () => withErrorExitCode(() => checker.findViolation()),
package/src/instances.ts CHANGED
@@ -164,7 +164,7 @@ export const mapChildren = (
164
164
  case "RecordSet":
165
165
  return {
166
166
  ...expression,
167
- fields: expression.fields.map((field) => ({ name: field.name, value: plain(field.value) })),
167
+ fields: expression.fields.map((field) => ({ ...field, value: plain(field.value) })),
168
168
  };
169
169
  case "Except":
170
170
  return {
@@ -219,7 +219,7 @@ interface Instantiation {
219
219
  variables: Set<string>;
220
220
  getDefinition: (key: string) => Definition | undefined;
221
221
  isParameterized: (key: string) => boolean;
222
- addDefinition: (name: string, create: (key: string) => Definition) => string;
222
+ addDefinition: (source: string, name: string, create: (key: string) => Definition) => string;
223
223
  createName: (name: string) => string;
224
224
  }
225
225
 
@@ -640,7 +640,7 @@ const copyDefinition = (rewrite: Rewrite, key: string): string => {
640
640
  const instantiation = rewrite.instantiation;
641
641
  const definition = instantiation.getDefinition(key);
642
642
  if (!definition) return key;
643
- return instantiation.addDefinition(definition.name, (copyKey) => {
643
+ return instantiation.addDefinition(key, definition.name, (copyKey) => {
644
644
  rewrite.copies.set(key, copyKey);
645
645
  const rename = createRenamer(rewrite);
646
646
  const mapped = renameParams(
@@ -679,7 +679,7 @@ export const createInstantiation = (instantiation: Instantiation) => {
679
679
  if (copy !== undefined) return copy;
680
680
  const definition = instantiation.getDefinition(key);
681
681
  if (!definition) return key;
682
- return instantiation.addDefinition(definition.name, () =>
682
+ return instantiation.addDefinition(key, definition.name, () =>
683
683
  withInstanceParams(definition, instantiation.params, definition.location),
684
684
  );
685
685
  },
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 {
@@ -176,8 +175,13 @@ export const ACTION_LEVEL = 2;
176
175
 
177
176
  export const TEMPORAL_LEVEL = 3;
178
177
 
179
- const createLevelError = (message: string, location: SourceLocation) =>
180
- new TlaSyntaxError(`${message} at line ${location.line}, column ${location.column}`);
178
+ // SANY reports a level error at the range of the expression it rejects.
179
+ const createLevelError = (message: string, expression: Expression) =>
180
+ expression.location.range
181
+ ? createSemanticError(`${message}.`, expression.location.range)
182
+ : new TlaSyntaxError(
183
+ `${message} at line ${expression.location.line}, column ${expression.location.column}`,
184
+ );
181
185
 
182
186
  const LOGICAL_OPERATORS = new Set(["/\\", "\\/", "=>", "<=>"]);
183
187
 
@@ -237,13 +241,13 @@ export const createLevelAnalyzer = (context: LevelContext) => {
237
241
  if (operand.operator || operand.declared) return;
238
242
  if (operand.data.level > getMaxLevel(operator, index)) {
239
243
  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.`,
244
+ `Level error in applying operator ${operator.name}:\nThe level of argument ${index + 1} exceeds the maximum level allowed by the operator`,
241
245
  );
242
246
  }
243
247
  });
244
248
  if (ranges.some((range) => range.level > ACTION_LEVEL)) {
245
249
  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.`,
250
+ `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
251
  );
248
252
  }
249
253
  const getOperand = (formal: string) => {
@@ -444,10 +448,13 @@ export const createLevelAnalyzer = (context: LevelContext) => {
444
448
  ? applyDeclared(resolved.name, resolved.level, operands)
445
449
  : applyDefined(resolved.levels, operands);
446
450
 
447
- const checkJunction = (operands: Operand[], location: SourceLocation) => {
451
+ const checkJunction = (operands: Operand[], expression: Expression) => {
448
452
  const levels = operands.map((operand) => operand.data.level);
449
453
  if (levels.includes(ACTION_LEVEL) && levels.includes(TEMPORAL_LEVEL)) {
450
- throw createLevelError("Formula has both temporal formula and action as arguments", location);
454
+ throw createLevelError(
455
+ "Formula has both temporal formula and action as arguments",
456
+ expression,
457
+ );
451
458
  }
452
459
  };
453
460
 
@@ -456,10 +463,10 @@ export const createLevelAnalyzer = (context: LevelContext) => {
456
463
  if (isLeadsTo && operands.some((operand) => operand.data.level === ACTION_LEVEL)) {
457
464
  throw createLevelError(
458
465
  "Action used where only temporal formula or state predicate allowed",
459
- expression.location,
466
+ expression,
460
467
  );
461
468
  }
462
- if (LOGICAL_OPERATORS.has(expression.operator)) checkJunction(operands, expression.location);
469
+ if (LOGICAL_OPERATORS.has(expression.operator)) checkJunction(operands, expression);
463
470
  };
464
471
 
465
472
  const checkTemporal = (
@@ -473,7 +480,7 @@ export const createLevelAnalyzer = (context: LevelContext) => {
473
480
  expression.kind === "Always"
474
481
  ? "[] followed by action not of form [A]_v"
475
482
  : "<> followed by action not of form <<A>>_v",
476
- expression.location,
483
+ expression,
477
484
  );
478
485
  };
479
486
 
@@ -501,7 +508,17 @@ export const createLevelAnalyzer = (context: LevelContext) => {
501
508
  return data;
502
509
  };
503
510
 
511
+ // SANY reports a level error of an operator's arguments at the application.
504
512
  const analyze = (expression: Expression, scope: Scope): LevelData => {
513
+ try {
514
+ return analyzeNode(expression, scope);
515
+ } catch (error) {
516
+ if (!(error instanceof TlaSyntaxError) || error.sany) throw error;
517
+ throw createLevelError(error.message, expression);
518
+ }
519
+ };
520
+
521
+ const analyzeNode = (expression: Expression, scope: Scope): LevelData => {
505
522
  switch (expression.kind) {
506
523
  case "Number":
507
524
  case "Decimal":
@@ -521,7 +538,7 @@ export const createLevelAnalyzer = (context: LevelContext) => {
521
538
  case "And":
522
539
  case "Or": {
523
540
  const operands = toOperands(expression.operands, scope);
524
- checkJunction(operands, expression.location);
541
+ checkJunction(operands, expression);
525
542
  return applyDefined(JUNCTION_LEVELS, operands);
526
543
  }
527
544
  case "Prime":
@@ -561,13 +578,14 @@ export const createLevelAnalyzer = (context: LevelContext) => {
561
578
  expression.bounds.map((bound) => bound.set),
562
579
  getBoundNames(expression.bounds),
563
580
  );
564
- if (
565
- data.level === TEMPORAL_LEVEL &&
566
- expression.bounds.some((bound) => analyze(bound.set, scope).level === ACTION_LEVEL)
567
- ) {
581
+ const actionBound =
582
+ data.level === TEMPORAL_LEVEL
583
+ ? expression.bounds.find((bound) => analyze(bound.set, scope).level === ACTION_LEVEL)
584
+ : undefined;
585
+ if (actionBound) {
568
586
  throw createLevelError(
569
587
  "Action-level bound of quantified temporal formula",
570
- expression.location,
588
+ actionBound.set,
571
589
  );
572
590
  }
573
591
  return data;
@@ -838,13 +856,23 @@ const analyzeAssumeProve = (
838
856
  // SANY checks the level of every definition, assumption, and theorem of a module.
839
857
  export const checkModuleLevels = (module: Module, context: LevelContext) => {
840
858
  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
- );
859
+ collectSemanticErrors([
860
+ ...module.definitions
861
+ .filter((definition) => !definition.name.includes("!"))
862
+ .map((definition) => ({
863
+ location: definition.location,
864
+ check: () => analyzer.analyzeDefinition(definition, new Map()),
865
+ })),
866
+ ...module.assumptions.map((assumption) => ({
867
+ location: assumption.location,
868
+ check: () => analyzer.analyze(assumption.expression, new Map()),
869
+ })),
870
+ ...module.theorems.map((theorem) => ({
871
+ location: theorem.location,
872
+ check: () =>
873
+ theorem.statement.kind === "AssumeProve"
874
+ ? analyzeAssumeProve(theorem.statement, new Map(), analyzer)
875
+ : analyzer.analyze(theorem.statement, new Map()),
876
+ })),
877
+ ]);
850
878
  };
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;