tla-ts 0.0.3-dev.bffbba3 → 0.0.3-dev.c8c988d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/levels.ts CHANGED
@@ -5,11 +5,18 @@ import {
5
5
  type Expression,
6
6
  type Module,
7
7
  type OperatorParam,
8
- type SourceLocation,
8
+ type Proof,
9
+ type ProofStep,
9
10
  } from "./ast";
10
- import { TlaSyntaxError } from "./errors";
11
+ import {
12
+ createSanyError,
13
+ createSemanticError,
14
+ formatRange,
15
+ TlaSyntaxError,
16
+ type SanyError,
17
+ } from "./errors";
11
18
  import { mapChildren } from "./instances";
12
- import { getBoundNames, getPatternNames } from "./resolve";
19
+ import { collectSemanticErrors, getBoundNames, getPatternNames } from "./resolve";
13
20
  import { STANDARD_LEVELS } from "./standard-levels";
14
21
 
15
22
  interface LevelData {
@@ -34,6 +41,7 @@ interface LevelContext {
34
41
  constants: Set<string>;
35
42
  variables: Set<string>;
36
43
  getDefinition: (name: string) => Definition | undefined;
44
+ getQualifiedName?: (name: string) => string | undefined;
37
45
  }
38
46
 
39
47
  type ScopeEntry =
@@ -176,8 +184,13 @@ export const ACTION_LEVEL = 2;
176
184
 
177
185
  export const TEMPORAL_LEVEL = 3;
178
186
 
179
- const createLevelError = (message: string, location: SourceLocation) =>
180
- new TlaSyntaxError(`${message} at line ${location.line}, column ${location.column}`);
187
+ // SANY reports a level error at the range of the expression it rejects.
188
+ const createLevelError = (message: string, expression: Expression) =>
189
+ expression.location.range
190
+ ? createSemanticError(`${message}.`, expression.location.range)
191
+ : new TlaSyntaxError(
192
+ `${message} at line ${expression.location.line}, column ${expression.location.column}`,
193
+ );
181
194
 
182
195
  const LOGICAL_OPERATORS = new Set(["/\\", "\\/", "=>", "<=>"]);
183
196
 
@@ -201,7 +214,13 @@ export const createLevelAnalyzer = (context: LevelContext) => {
201
214
  if (context.variables.has(name)) return { kind: "Declared", name, level: 1, arity: 0 };
202
215
  const definition = context.getDefinition(name);
203
216
  if (definition) {
204
- return { kind: "Defined", levels: analyzeDefinition(definition, new Map()) };
217
+ const levels = analyzeDefinition(definition, new Map());
218
+ // SANY names a definition of an instance by its qualified name, as in I!Foo.
219
+ const qualifiedName = context.getQualifiedName?.(name);
220
+ return {
221
+ kind: "Defined",
222
+ levels: qualifiedName ? { ...levels, name: qualifiedName } : levels,
223
+ };
205
224
  }
206
225
  const signature = CORE_SIGNATURES.get(name) ?? STANDARD_LEVELS.get(name);
207
226
  if (signature) return { kind: "Defined", levels: signature };
@@ -237,13 +256,13 @@ export const createLevelAnalyzer = (context: LevelContext) => {
237
256
  if (operand.operator || operand.declared) return;
238
257
  if (operand.data.level > getMaxLevel(operator, index)) {
239
258
  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.`,
259
+ `Level error in applying operator ${operator.name}:\nThe level of argument ${index + 1} exceeds the maximum level allowed by the operator`,
241
260
  );
242
261
  }
243
262
  });
244
263
  if (ranges.some((range) => range.level > ACTION_LEVEL)) {
245
264
  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.`,
265
+ `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
266
  );
248
267
  }
249
268
  const getOperand = (formal: string) => {
@@ -444,10 +463,13 @@ export const createLevelAnalyzer = (context: LevelContext) => {
444
463
  ? applyDeclared(resolved.name, resolved.level, operands)
445
464
  : applyDefined(resolved.levels, operands);
446
465
 
447
- const checkJunction = (operands: Operand[], location: SourceLocation) => {
466
+ const checkJunction = (operands: Operand[], expression: Expression) => {
448
467
  const levels = operands.map((operand) => operand.data.level);
449
468
  if (levels.includes(ACTION_LEVEL) && levels.includes(TEMPORAL_LEVEL)) {
450
- throw createLevelError("Formula has both temporal formula and action as arguments", location);
469
+ throw createLevelError(
470
+ "Formula has both temporal formula and action as arguments",
471
+ expression,
472
+ );
451
473
  }
452
474
  };
453
475
 
@@ -456,10 +478,10 @@ export const createLevelAnalyzer = (context: LevelContext) => {
456
478
  if (isLeadsTo && operands.some((operand) => operand.data.level === ACTION_LEVEL)) {
457
479
  throw createLevelError(
458
480
  "Action used where only temporal formula or state predicate allowed",
459
- expression.location,
481
+ expression,
460
482
  );
461
483
  }
462
- if (LOGICAL_OPERATORS.has(expression.operator)) checkJunction(operands, expression.location);
484
+ if (LOGICAL_OPERATORS.has(expression.operator)) checkJunction(operands, expression);
463
485
  };
464
486
 
465
487
  const checkTemporal = (
@@ -473,7 +495,7 @@ export const createLevelAnalyzer = (context: LevelContext) => {
473
495
  expression.kind === "Always"
474
496
  ? "[] followed by action not of form [A]_v"
475
497
  : "<> followed by action not of form <<A>>_v",
476
- expression.location,
498
+ expression,
477
499
  );
478
500
  };
479
501
 
@@ -501,7 +523,17 @@ export const createLevelAnalyzer = (context: LevelContext) => {
501
523
  return data;
502
524
  };
503
525
 
526
+ // SANY reports a level error of an operator's arguments at the application.
504
527
  const analyze = (expression: Expression, scope: Scope): LevelData => {
528
+ try {
529
+ return analyzeNode(expression, scope);
530
+ } catch (error) {
531
+ if (!(error instanceof TlaSyntaxError) || error.sany) throw error;
532
+ throw createLevelError(error.message, expression);
533
+ }
534
+ };
535
+
536
+ const analyzeNode = (expression: Expression, scope: Scope): LevelData => {
505
537
  switch (expression.kind) {
506
538
  case "Number":
507
539
  case "Decimal":
@@ -521,7 +553,7 @@ export const createLevelAnalyzer = (context: LevelContext) => {
521
553
  case "And":
522
554
  case "Or": {
523
555
  const operands = toOperands(expression.operands, scope);
524
- checkJunction(operands, expression.location);
556
+ checkJunction(operands, expression);
525
557
  return applyDefined(JUNCTION_LEVELS, operands);
526
558
  }
527
559
  case "Prime":
@@ -561,13 +593,14 @@ export const createLevelAnalyzer = (context: LevelContext) => {
561
593
  expression.bounds.map((bound) => bound.set),
562
594
  getBoundNames(expression.bounds),
563
595
  );
564
- if (
565
- data.level === TEMPORAL_LEVEL &&
566
- expression.bounds.some((bound) => analyze(bound.set, scope).level === ACTION_LEVEL)
567
- ) {
596
+ const actionBound =
597
+ data.level === TEMPORAL_LEVEL
598
+ ? expression.bounds.find((bound) => analyze(bound.set, scope).level === ACTION_LEVEL)
599
+ : undefined;
600
+ if (actionBound) {
568
601
  throw createLevelError(
569
602
  "Action-level bound of quantified temporal formula",
570
- expression.location,
603
+ actionBound.set,
571
604
  );
572
605
  }
573
606
  return data;
@@ -817,34 +850,131 @@ export const createLevelAnalyzer = (context: LevelContext) => {
817
850
  return { analyze, analyzeDefinition, toOperand };
818
851
  };
819
852
 
820
- const analyzeAssumeProve = (
853
+ export const analyzeAssumeProve = (
821
854
  assumeProve: AssumeProve,
822
855
  scope: Scope,
823
856
  analyzer: ReturnType<typeof createLevelAnalyzer>,
824
- ) => {
857
+ ): LevelData => {
825
858
  const inner = new Map(scope);
826
- assumeProve.assumptions.forEach((assumption) => {
859
+ const parts = assumeProve.assumptions.flatMap((assumption) => {
827
860
  if (assumption.kind === "NewSymbol") {
828
- if (assumption.set) analyzer.analyze(assumption.set, inner);
861
+ const set = assumption.set && analyzer.analyze(assumption.set, inner);
829
862
  inner.set(assumption.name, { kind: "Formal", arity: assumption.arity });
830
- return;
863
+ return set ? [set] : [];
831
864
  }
832
- if (assumption.kind === "AssumeProve") analyzeAssumeProve(assumption, inner, analyzer);
833
- else analyzer.analyze(assumption, inner);
865
+ return [
866
+ assumption.kind === "AssumeProve"
867
+ ? analyzeAssumeProve(assumption, inner, analyzer)
868
+ : analyzer.analyze(assumption, inner),
869
+ ];
834
870
  });
835
- analyzer.analyze(assumeProve.conclusion, inner);
871
+ parts.push(analyzer.analyze(assumeProve.conclusion, inner));
872
+ const data = createData(Math.max(...parts.map((part) => part.level)));
873
+ parts.forEach((part) => {
874
+ part.params.forEach((param) => data.params.add(param));
875
+ part.constraints.forEach((value, key) => putConstraint(data.constraints, key, value));
876
+ part.argConstraints.forEach((value, key) => putArgConstraint(data.argConstraints, key, value));
877
+ part.argParams.forEach((key) => data.argParams.add(key));
878
+ });
879
+ return data;
836
880
  };
837
881
 
838
882
  // SANY checks the level of every definition, assumption, and theorem of a module.
839
883
  export const checkModuleLevels = (module: Module, context: LevelContext) => {
840
884
  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
- );
885
+ const getLevel = (expressions: Expression[]) =>
886
+ Math.max(0, ...expressions.map((expression) => analyzer.analyze(expression, new Map()).level));
887
+ const getStepLevel = (step: ProofStep) => {
888
+ const body = step.body;
889
+ if (body.kind === "Have" || body.kind === "Case") return getLevel([body.expression]);
890
+ if (body.kind === "Witness") return getLevel(body.expressions);
891
+ if (body.kind === "Take") return getLevel(body.bounds.map((bound) => bound.set));
892
+ if (body.kind === "Pick") {
893
+ return getLevel([body.body, ...body.bounds.map((bound) => bound.set)]);
894
+ }
895
+ if (body.kind !== "Assert") return 0;
896
+ return body.statement.kind === "AssumeProve"
897
+ ? analyzeAssumeProve(body.statement, new Map(), analyzer).level
898
+ : getLevel([body.statement]);
899
+ };
900
+ // SANY's TheoremNode.LevelCheckTemporal: the proof of a temporal goal may only assume constants.
901
+ const checkTemporalGoal = (proof: Proof | undefined): SanyError[] =>
902
+ proof?.kind !== "Steps"
903
+ ? []
904
+ : proof.steps.flatMap((step) => {
905
+ const location = formatRange(step.statement);
906
+ const isConstant = () => getStepLevel(step) === 0;
907
+ if (
908
+ step.body.kind === "Have" ||
909
+ step.body.kind === "Take" ||
910
+ step.body.kind === "Witness"
911
+ ) {
912
+ return isConstant()
913
+ ? []
914
+ : [{ location, message: "Non-constant TAKE, WITNESS, or HAVE for temporal goal." }];
915
+ }
916
+ if (step.body.kind === "Case") {
917
+ return [
918
+ ...(isConstant()
919
+ ? []
920
+ : [{ location, message: "Non-constant CASE for temporal goal." }]),
921
+ ...checkTemporalGoal(step.proof),
922
+ ];
923
+ }
924
+ return step.body.kind === "Qed" ? checkTemporalGoal(step.proof) : [];
925
+ });
926
+ // SANY checks each step as a theorem of its own after the steps of its proof.
927
+ const checkProof = (proof: Proof | undefined): SanyError[] =>
928
+ proof?.kind !== "Steps"
929
+ ? []
930
+ : proof.steps.flatMap((step) => {
931
+ const body = step.body;
932
+ const isTemporal = () => getStepLevel(step) === TEMPORAL_LEVEL;
933
+ const pickErrors =
934
+ body.kind === "Pick" && body.bounds.length > 0 && isTemporal()
935
+ ? body.bounds
936
+ .filter((bound) => getLevel([bound.set]) !== 0)
937
+ .flatMap((bound) =>
938
+ bound.set.location.range
939
+ ? [
940
+ {
941
+ location: formatRange(bound.set.location.range),
942
+ message: "Non-constant bound of temporal PICK.",
943
+ },
944
+ ]
945
+ : [],
946
+ )
947
+ : [];
948
+ return [
949
+ ...checkProof(step.proof),
950
+ ...pickErrors,
951
+ ...(step.proof?.kind === "Steps" && isTemporal() ? checkTemporalGoal(step.proof) : []),
952
+ ];
953
+ });
954
+ collectSemanticErrors([
955
+ ...module.definitions
956
+ .filter((definition) => !definition.name.includes("!"))
957
+ .map((definition) => ({
958
+ location: definition.location,
959
+ check: () => analyzer.analyzeDefinition(definition, new Map()),
960
+ })),
961
+ ...module.assumptions.map((assumption) => ({
962
+ location: assumption.location,
963
+ check: () => analyzer.analyze(assumption.expression, new Map()),
964
+ })),
965
+ ...module.theorems.map((theorem) => ({
966
+ location: theorem.location,
967
+ check: () => {
968
+ const data =
969
+ theorem.statement.kind === "AssumeProve"
970
+ ? analyzeAssumeProve(theorem.statement, new Map(), analyzer)
971
+ : analyzer.analyze(theorem.statement, new Map());
972
+ const errors = [
973
+ ...checkProof(theorem.proof),
974
+ ...(data.level === TEMPORAL_LEVEL ? checkTemporalGoal(theorem.proof) : []),
975
+ ];
976
+ if (errors.length > 0) throw createSanyError(errors);
977
+ },
978
+ })),
979
+ ]);
850
980
  };
package/src/live-check.ts CHANGED
@@ -1,4 +1,5 @@
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,
@@ -49,13 +50,17 @@ interface Check {
49
50
  actionIds: Int32Array;
50
51
  nodeStates: number[];
51
52
  nodeTableaux: number[];
52
- successors: number[][];
53
- actions: Uint8Array[];
54
- stateResults: Uint8Array[];
55
- 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 };
56
62
  initial: number[];
57
- nodeIds: Map<number, number>;
58
- nodesByState: Map<number, number[]>;
63
+ nodeIds: NodeTable;
59
64
  isDone: boolean[];
60
65
  errorNode: number | undefined;
61
66
  }
@@ -70,13 +75,45 @@ const removeRepeats = (path: number[]) =>
70
75
  const pushNode = (check: Check, state: number, tableauNode: number) => {
71
76
  check.nodeStates.push(state);
72
77
  check.nodeTableaux.push(tableauNode);
73
- check.successors.push([]);
74
- check.actions.push(new Uint8Array(0));
75
- check.stateResults.push(new Uint8Array(0));
76
- check.isWritten.push(false);
78
+ check.pending.push(undefined);
79
+ check.offsets.push(-1);
80
+ check.edgeOffsets.push(-1);
77
81
  return check.nodeStates.length - 1;
78
82
  };
79
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
+
80
117
  const SUCCESSOR_CAPACITY = 16;
81
118
 
82
119
  const SCC_MARKER = -42;
@@ -103,7 +140,10 @@ export const createLivenessChecker = (
103
140
  fairness.length === 0 ? violation : createJunction("And", [...fairness, violation]);
104
141
  const solutions = getSolutions(formula);
105
142
  if (solutions.length === 0) {
106
- throw new TlaEvaluationError(TAUTOLOGY_MESSAGE);
143
+ throw setExitCode(
144
+ new TlaEvaluationError(TAUTOLOGY_MESSAGE),
145
+ EXIT_STATUS.livenessEvaluationFailure,
146
+ );
107
147
  }
108
148
  const actionIds = new Map<string, number>();
109
149
  const checks = solutions.map((solution): Check => ({
@@ -116,13 +156,13 @@ export const createLivenessChecker = (
116
156
  }),
117
157
  nodeStates: [],
118
158
  nodeTableaux: [],
119
- successors: [],
120
- actions: [],
121
- stateResults: [],
122
- isWritten: [],
159
+ pending: [],
160
+ offsets: [],
161
+ results: { bytes: new Uint8Array(1024), length: 0 },
162
+ edgeOffsets: [],
163
+ edges: { ids: new Int32Array(1024), length: 0 },
123
164
  initial: [],
124
- nodeIds: new Map(),
125
- nodesByState: new Map(),
165
+ nodeIds: { slots: new Int32Array(3 << 10), size: 0, shift: 22 },
126
166
  isDone: [],
127
167
  errorNode: undefined,
128
168
  }));
@@ -208,18 +248,35 @@ export const createLivenessChecker = (
208
248
  model.infinitelyOftenActions.length === 0,
209
249
  );
210
250
 
211
- const getNodeId = (check: Check, state: number, tableauNode: number) =>
212
- check.solution.tableau
213
- ? check.nodeIds.get(state * check.solution.tableau.nodes.length + tableauNode)
214
- : 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
+ };
215
257
  const recordNode = (check: Check, state: number, tableauNode: number) => {
216
258
  const node = pushNode(check, state, tableauNode);
217
- check.nodeIds.set(state * (check.solution.tableau?.nodes.length ?? 1) + tableauNode, node);
218
- const siblings = check.nodesByState.get(state);
219
- if (siblings) siblings.push(node);
220
- 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));
221
273
  return node;
222
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);
223
280
  const writeNode = (
224
281
  check: Check,
225
282
  node: number,
@@ -227,11 +284,32 @@ export const createLivenessChecker = (
227
284
  stateResults: Uint8Array,
228
285
  ) => {
229
286
  const actionCount = check.solution.actionChecks.length;
230
- const packed = new Uint8Array(actions.length * actionCount);
231
- actions.forEach((results, position) => packed.set(results, position * actionCount));
232
- check.actions[node] = packed;
233
- check.stateResults[node] = stateResults;
234
- 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;
235
313
  };
236
314
 
237
315
  // TLC collects a state's successors and the state itself in a SetOfStates, a hash set it
@@ -284,7 +362,7 @@ export const createLivenessChecker = (
284
362
  const stateResults = checkState(check, index, state);
285
363
  const tableauNode = tableau.nodes[check.nodeTableaux[node]];
286
364
  const actions: Uint8Array[] = [];
287
- const successors = check.successors[node];
365
+ const successors = getPending(check, node);
288
366
  const selfActions =
289
367
  tableauNode.successors.length > 0
290
368
  ? checkAction(check, index, state, state)
@@ -333,8 +411,8 @@ export const createLivenessChecker = (
333
411
  );
334
412
  check.isDone[index] = true;
335
413
  // TLC expands the nodes recorded before the loop, not the ones the loop records.
336
- for (const node of (check.nodesByState.get(index) ?? []).slice()) {
337
- const successors = check.successors[node];
414
+ for (const node of getStateNodes(check, tableau, index)) {
415
+ const successors = getPending(check, node);
338
416
  const actions: Uint8Array[] = [];
339
417
  set.forEach((successor, position) => {
340
418
  const isDone = check.isDone[successor.index] === true;
@@ -368,10 +446,10 @@ export const createLivenessChecker = (
368
446
  index: number,
369
447
  ) => {
370
448
  while (check.nodeStates.length <= index) pushNode(check, check.nodeStates.length, -1);
371
- const successors = check.successors[index];
449
+ const successors = getPending(check, index);
372
450
  const actions: Uint8Array[] = [];
373
451
  set.forEach((successor, position) => {
374
- if (check.isWritten[successor.index] && successors.includes(successor.index)) return;
452
+ if (isWritten(check, successor.index) && successors.includes(successor.index)) return;
375
453
  successors.push(successor.index);
376
454
  actions.push(actionResults[position]);
377
455
  });
@@ -385,20 +463,20 @@ export const createLivenessChecker = (
385
463
  const parents = new Map<number, number>();
386
464
  const queue: number[] = [];
387
465
  for (const node of check.initial) {
388
- if (!check.isWritten[node]) continue;
466
+ if (!isWritten(check, node)) continue;
389
467
  queue.push(node);
390
468
  parents.set(node, -1);
391
469
  }
392
470
  for (let position = 0; position < queue.length; position++) {
393
471
  const current = queue[position];
394
- for (const next of check.successors[current]) {
472
+ for (const next of getSuccessors(check, current)) {
395
473
  if (next === current && check.solution.tableau) continue;
396
474
  if (next === target) {
397
475
  const path = [target];
398
476
  for (let node = current; node !== -1; node = parents.get(node) ?? -1) path.push(node);
399
477
  return path;
400
478
  }
401
- if (!check.isWritten[next] || parents.has(next)) continue;
479
+ if (!isWritten(check, next) || parents.has(next)) continue;
402
480
  parents.set(next, current);
403
481
  queue.push(next);
404
482
  }
@@ -410,16 +488,17 @@ export const createLivenessChecker = (
410
488
  const findInModel = (check: Check, model: Solution["models"][number]): Lasso | undefined => {
411
489
  const solution = check.solution;
412
490
  const actionCount = solution.actionChecks.length;
491
+ const stateCount = solution.stateChecks.length;
413
492
  const getAction = (node: number, edge: number, position: number) =>
414
- check.actions[node][edge * actionCount + position] === 1;
493
+ check.results.bytes[check.offsets[node] + stateCount + edge * actionCount + position] === 1;
415
494
  const isAllowed = (node: number, edge: number) =>
416
495
  model.eventuallyAlways.every((position) => getAction(node, edge, position));
417
496
  const links = new Float64Array(check.nodeStates.length).fill(UNVISITED);
418
- const queue = check.initial.filter((node) => check.isWritten[node]);
497
+ const queue = check.initial.filter((node) => isWritten(check, node));
419
498
  const components: number[] = [];
420
499
 
421
500
  const isStuttering = (node: number) => {
422
- const edge = check.successors[node].indexOf(node);
501
+ const edge = getSuccessors(check, node).indexOf(node);
423
502
  return edge !== -1 && isAllowed(node, edge);
424
503
  };
425
504
  const isFulfilled = (node: number, promise: Solution["promises"][number]) =>
@@ -443,11 +522,11 @@ export const createLivenessChecker = (
443
522
  if (member === root) break;
444
523
  }
445
524
  const isStateSatisfied = model.infinitelyOftenStates.every((position) =>
446
- [...members].some((node) => check.stateResults[node][position] === 1),
525
+ [...members].some((node) => getStateResult(check, node, position)),
447
526
  );
448
527
  const isActionSatisfied = model.infinitelyOftenActions.every((position) =>
449
528
  [...members].some((node) =>
450
- check.successors[node].some(
529
+ getSuccessors(check, node).some(
451
530
  (next, edge) =>
452
531
  members.has(next) && isAllowed(node, edge) && getAction(node, edge, position),
453
532
  ),
@@ -488,7 +567,7 @@ export const createLivenessChecker = (
488
567
  const countAtStart = remaining.count;
489
568
  while (true) {
490
569
  model.infinitelyOftenStates.forEach((position, slot) => {
491
- if (!stateDone[slot] && check.stateResults[current.node][position] === 1) {
570
+ if (!stateDone[slot] && getStateResult(check, current.node, position)) {
492
571
  stateDone[slot] = true;
493
572
  remaining.count--;
494
573
  }
@@ -502,7 +581,7 @@ export const createLivenessChecker = (
502
581
  if (remaining.count <= 0) break;
503
582
  const step = { last: -1, unvisited: -1 };
504
583
  const countBeforeActions = remaining.count;
505
- const successors = check.successors[current.node];
584
+ const successors = getSuccessors(check, current.node);
506
585
  const taken = successors.some((next, edge) => {
507
586
  if (membersByState.has(check.nodeStates[next])) {
508
587
  if (!isMember(next) || !isAllowed(current.node, edge)) return false;
@@ -537,7 +616,8 @@ export const createLivenessChecker = (
537
616
  }
538
617
  current.node = previous;
539
618
  step.unvisited =
540
- check.successors[previous].find((next) => isMember(next) && !seen.has(next)) ?? -1;
619
+ getSuccessors(check, previous).find((next) => isMember(next) && !seen.has(next)) ??
620
+ -1;
541
621
  }
542
622
  take(step.unvisited);
543
623
  seen.add(step.unvisited);
@@ -567,7 +647,7 @@ export const createLivenessChecker = (
567
647
  const queue: [number, number][] = [];
568
648
  for (let state = start, parent = -1, position = 0; ; position++) {
569
649
  for (const node of membersByState.get(state) ?? []) {
570
- for (const [edge, next] of check.successors[node].entries()) {
650
+ for (const [edge, next] of getSuccessors(check, node).entries()) {
571
651
  if (next === node || !isAllowedEdge(node, edge)) continue;
572
652
  if (next === root) {
573
653
  const path: number[] = [];
@@ -620,8 +700,8 @@ export const createLivenessChecker = (
620
700
  stack.push(lowLink, node, SCC_MARKER);
621
701
  components.push(node);
622
702
  const nextLowLink = { value: counter.link++ };
623
- check.successors[node].forEach((next, edge) => {
624
- if (!check.isWritten[next]) return;
703
+ getSuccessors(check, node).forEach((next, edge) => {
704
+ if (!isWritten(check, next)) return;
625
705
  if (!isAllowed(node, edge)) {
626
706
  if (links[next] === UNVISITED) queue.push(next);
627
707
  return;