tla-ts 0.0.10-dev.8aec06f77 → 0.0.10-dev.94c3dd828

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 (196) hide show
  1. package/dist/deciders.cjs +37 -36
  2. package/dist/deciders.js +55 -54
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.cts +3 -0
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.js +1 -1
  7. package/dist/parallel-worker.cjs +1 -1
  8. package/dist/parallel-worker.js +1 -1
  9. package/dist/prove.cjs +146 -58
  10. package/dist/prove.js +142 -54
  11. package/dist/run.cjs +45 -43
  12. package/dist/run.js +47 -45
  13. package/dist/transfer.cjs +39 -36
  14. package/dist/transfer.js +23 -20
  15. package/dist/worker.cjs +1 -1
  16. package/dist/worker.js +1 -1
  17. package/package.json +1 -1
  18. package/src/ast.ts +3 -3
  19. package/src/check.ts +203 -33
  20. package/src/cli/tlapm.ts +261 -68
  21. package/src/dependencies.ts +23 -2
  22. package/src/errors.ts +1 -1
  23. package/src/exit-codes.ts +1 -0
  24. package/src/liveness-checker.ts +530 -201
  25. package/src/liveness.ts +47 -32
  26. package/src/obligations/anonymize.ts +2 -4
  27. package/src/obligations/index.ts +5 -3
  28. package/src/obligations/pragma.ts +2 -2
  29. package/src/parallel.ts +2 -2
  30. package/src/parser.ts +151 -42
  31. package/src/prover/deciders.ts +1 -8
  32. package/src/prover/isabelle/isar/attrib.ts +86 -45
  33. package/src/prover/isabelle/isar/context.ts +25 -22
  34. package/src/prover/isabelle/isar/induct.ts +2 -5
  35. package/src/prover/isabelle/isar/method.ts +5 -7
  36. package/src/prover/isabelle/isar/proof.ts +33 -16
  37. package/src/prover/isabelle/isar/rule-cases.ts +6 -14
  38. package/src/prover/isabelle/isar/theory.ts +16 -17
  39. package/src/prover/isabelle/isar/toplevel.ts +46 -52
  40. package/src/prover/isabelle/provers/classical.ts +1 -1
  41. package/src/prover/ocaml.ts +4 -1
  42. package/src/prover/prep/action.ts +1 -0
  43. package/src/prover/prep/methods.ts +50 -3
  44. package/src/prover/prep/normalize.ts +4 -1
  45. package/src/prover/prove.ts +58 -32
  46. package/src/prover/ptl/decide.ts +43 -63
  47. package/src/prover/smt/data.ts +51 -45
  48. package/src/prover/smt/encode.ts +1 -2
  49. package/src/prover/smt/rewrite.ts +1 -0
  50. package/src/prover/smt/solver/aig-tactic.ts +25 -15
  51. package/src/prover/smt/solver/arith-rewriter.ts +3 -5
  52. package/src/prover/smt/solver/asserted-formulas.ts +1 -1
  53. package/src/prover/smt/solver/ast-util.ts +3 -1
  54. package/src/prover/smt/solver/ast.ts +110 -152
  55. package/src/prover/smt/solver/bound-manager.ts +39 -28
  56. package/src/prover/smt/solver/bv-bound-chk.ts +2 -8
  57. package/src/prover/smt/solver/bv-rewriter.ts +14 -16
  58. package/src/prover/smt/solver/bv1-blast.ts +1 -9
  59. package/src/prover/smt/solver/cg-table.ts +19 -14
  60. package/src/prover/smt/solver/check-logic.ts +6 -1
  61. package/src/prover/smt/solver/context.ts +20 -10
  62. package/src/prover/smt/solver/demodulator.ts +2 -2
  63. package/src/prover/smt/solver/dependent-expr-state.ts +16 -0
  64. package/src/prover/smt/solver/distribute-forall.ts +1 -10
  65. package/src/prover/smt/solver/dom-simplify.ts +1 -1
  66. package/src/prover/smt/solver/dt2bv-tactic.ts +2 -7
  67. package/src/prover/smt/solver/e-matching.ts +6 -6
  68. package/src/prover/smt/solver/elim-uncnstr.ts +3 -14
  69. package/src/prover/smt/solver/enode.ts +15 -1
  70. package/src/prover/smt/solver/euf/array-internalize.ts +19 -8
  71. package/src/prover/smt/solver/euf/dt-solver.ts +19 -19
  72. package/src/prover/smt/solver/euf/egraph.ts +65 -32
  73. package/src/prover/smt/solver/euf/euf-solver.ts +35 -18
  74. package/src/prover/smt/solver/euf/fpa-solver.ts +37 -51
  75. package/src/prover/smt/solver/euf/mam.ts +6 -48
  76. package/src/prover/smt/solver/euf/q-ematch.ts +21 -94
  77. package/src/prover/smt/solver/euf/q-mbi.ts +4 -2
  78. package/src/prover/smt/solver/euf/q-model-fixer.ts +1 -1
  79. package/src/prover/smt/solver/euf/q-solver.ts +2 -0
  80. package/src/prover/smt/solver/euf/th-solver.ts +1 -1
  81. package/src/prover/smt/solver/factor.ts +1 -11
  82. package/src/prover/smt/solver/fd-solver.ts +1 -2
  83. package/src/prover/smt/solver/fm-tactic.ts +19 -13
  84. package/src/prover/smt/solver/fpa-rewriter.ts +3 -1
  85. package/src/prover/smt/solver/fpa2bv-converter.ts +10 -6
  86. package/src/prover/smt/solver/internalizer.ts +41 -2
  87. package/src/prover/smt/solver/lia2pb.ts +18 -4
  88. package/src/prover/smt/solver/lp/lar-solver.ts +1 -1
  89. package/src/prover/smt/solver/lp/nla-powers.ts +144 -107
  90. package/src/prover/smt/solver/lp/nla-transcendentals.ts +50 -17
  91. package/src/prover/smt/solver/macro-finder.ts +1 -1
  92. package/src/prover/smt/solver/mam-compiler.ts +13 -13
  93. package/src/prover/smt/solver/max-bv-sharing-tactic.ts +1 -11
  94. package/src/prover/smt/solver/maxcore.ts +4 -12
  95. package/src/prover/smt/solver/maxlex.ts +0 -7
  96. package/src/prover/smt/solver/maxsmt-base.ts +7 -0
  97. package/src/prover/smt/solver/mbp/mbp-arith.ts +2 -11
  98. package/src/prover/smt/solver/mbp/mbp-plugin.ts +9 -0
  99. package/src/prover/smt/solver/mbp/mbp-solve-plugin.ts +1 -9
  100. package/src/prover/smt/solver/model-evaluator.ts +9 -5
  101. package/src/prover/smt/solver/model-macro-solver.ts +3 -3
  102. package/src/prover/smt/solver/muz/dl-context.ts +57 -3
  103. package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +68 -20
  104. package/src/prover/smt/solver/muz/dl-mk-elim-term-ite.ts +7 -1
  105. package/src/prover/smt/solver/muz/dl-mk-rule-inliner.ts +39 -10
  106. package/src/prover/smt/solver/muz/dl-mk-slice.ts +76 -13
  107. package/src/prover/smt/solver/muz/dl-mk-subsumption-checker.ts +9 -2
  108. package/src/prover/smt/solver/muz/dl-rule-transformer.ts +0 -2
  109. package/src/prover/smt/solver/muz/dl-rule.ts +93 -29
  110. package/src/prover/smt/solver/muz/hnf.ts +6 -5
  111. package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +178 -0
  112. package/src/prover/smt/solver/muz/horn-tactic.ts +14 -3
  113. package/src/prover/smt/solver/muz/rule-properties.ts +194 -36
  114. package/src/prover/smt/solver/muz/spacer-context.ts +102 -84
  115. package/src/prover/smt/solver/muz/spacer-dl-interface.ts +15 -2
  116. package/src/prover/smt/solver/muz/spacer-pdr.ts +3 -3
  117. package/src/prover/smt/solver/muz/spacer-prop-solver.ts +2 -7
  118. package/src/prover/smt/solver/muz/spacer-util.ts +2 -2
  119. package/src/prover/smt/solver/muz/substitution.ts +88 -37
  120. package/src/prover/smt/solver/nlqsat.ts +2 -2
  121. package/src/prover/smt/solver/nlsat/algebraic.ts +1 -2
  122. package/src/prover/smt/solver/nlsat/explain.ts +5 -0
  123. package/src/prover/smt/solver/nlsat/solver.ts +36 -25
  124. package/src/prover/smt/solver/opt-context.ts +9 -8
  125. package/src/prover/smt/solver/opt-nlsat.ts +68 -58
  126. package/src/prover/smt/solver/opt-solver.ts +16 -7
  127. package/src/prover/smt/solver/optsmt.ts +12 -9
  128. package/src/prover/smt/solver/pattern-inference.ts +2 -2
  129. package/src/prover/smt/solver/pb-rewriter.ts +13 -13
  130. package/src/prover/smt/solver/poly-rewriter.ts +2 -2
  131. package/src/prover/smt/solver/probes.ts +1 -1
  132. package/src/prover/smt/solver/propagate-values.ts +4 -0
  133. package/src/prover/smt/solver/proto-model.ts +5 -5
  134. package/src/prover/smt/solver/purify-arith.ts +50 -15
  135. package/src/prover/smt/solver/qe-arith-plugin.ts +2 -1
  136. package/src/prover/smt/solver/qe-mbp.ts +13 -23
  137. package/src/prover/smt/solver/qe.ts +45 -53
  138. package/src/prover/smt/solver/qsat.ts +70 -90
  139. package/src/prover/smt/solver/quantifier-analyzer.ts +9 -9
  140. package/src/prover/smt/solver/quasi-macros.ts +9 -18
  141. package/src/prover/smt/solver/rational.ts +17 -0
  142. package/src/prover/smt/solver/recfun-decl-plugin.ts +33 -19
  143. package/src/prover/smt/solver/recfun-rewriter.ts +1 -1
  144. package/src/prover/smt/solver/rewriter-tpl.ts +6 -2
  145. package/src/prover/smt/solver/rewriter.ts +1 -1
  146. package/src/prover/smt/solver/sat/asymm-branch.ts +59 -46
  147. package/src/prover/smt/solver/sat/clause-use-list.ts +0 -6
  148. package/src/prover/smt/solver/sat/clause.ts +1 -3
  149. package/src/prover/smt/solver/sat/config.ts +3 -3
  150. package/src/prover/smt/solver/sat/consequences.ts +1 -1
  151. package/src/prover/smt/solver/sat/goal2sat.ts +1 -1
  152. package/src/prover/smt/solver/sat/inc-sat-solver.ts +4 -12
  153. package/src/prover/smt/solver/sat/model-converter.ts +1 -15
  154. package/src/prover/smt/solver/sat/pb-solver.ts +49 -23
  155. package/src/prover/smt/solver/sat/probing.ts +22 -19
  156. package/src/prover/smt/solver/sat/sat2goal.ts +9 -10
  157. package/src/prover/smt/solver/sat/simplifier.ts +15 -56
  158. package/src/prover/smt/solver/sat/solver.ts +20 -19
  159. package/src/prover/smt/solver/sat/watch-list.ts +7 -0
  160. package/src/prover/smt/solver/seq-decl-plugin.ts +7 -7
  161. package/src/prover/smt/solver/seq-derive.ts +6 -7
  162. package/src/prover/smt/solver/seq-eq-solver.ts +7 -7
  163. package/src/prover/smt/solver/seq-range-predicate.ts +14 -1
  164. package/src/prover/smt/solver/seq-re-rewriter.ts +1 -10
  165. package/src/prover/smt/solver/seq-re-util.ts +1 -2
  166. package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
  167. package/src/prover/smt/solver/seq-regex-live.ts +4 -4
  168. package/src/prover/smt/solver/seq-rewriter.ts +1 -4
  169. package/src/prover/smt/solver/smt-setup.ts +15 -9
  170. package/src/prover/smt/solver/smtlib-parser.ts +1174 -579
  171. package/src/prover/smt/solver/smtlib-script.ts +866 -728
  172. package/src/prover/smt/solver/tactic.ts +66 -14
  173. package/src/prover/smt/solver/theory-array.ts +25 -58
  174. package/src/prover/smt/solver/theory-bv.ts +13 -50
  175. package/src/prover/smt/solver/theory-fpa.ts +46 -78
  176. package/src/prover/smt/solver/theory-pb.ts +10 -6
  177. package/src/prover/smt/solver/theory-recfun.ts +2 -2
  178. package/src/prover/smt/solver/theory-seq-regex.ts +3 -6
  179. package/src/prover/smt/solver/theory-seq-solve.ts +5 -5
  180. package/src/prover/smt/solver/theory-seq-state.ts +6 -3
  181. package/src/prover/smt/solver/theory-seq.ts +32 -54
  182. package/src/prover/smt/solver/theory.ts +16 -1
  183. package/src/prover/smt/solver/tseitin-cnf.ts +3 -3
  184. package/src/prover/smt/solver/var-subst.ts +2 -2
  185. package/src/prover/smt/table.ts +3 -2
  186. package/src/prover/zenon/decide.ts +9 -11
  187. package/src/prover/zenon/node.ts +12 -11
  188. package/src/prover/zenon/tla/sets.ts +1 -1
  189. package/src/search.ts +131 -16
  190. package/src/successors.ts +1 -1
  191. package/src/symmetry.ts +2 -2
  192. package/src/tableau.ts +2 -2
  193. package/src/tlc/fingerprint.ts +81 -9
  194. package/src/tlc/summary.ts +29 -14
  195. package/src/typed-tier.ts +6535 -0
  196. package/src/prover/smt/solver/seq-regex-witness.ts +0 -100
@@ -1,9 +1,11 @@
1
1
  import { TlaEvaluationError } from "./errors";
2
+ import { isExpressionImpure } from "./dependencies";
2
3
  import { hasRepeatedEffects, type Environment } from "./evaluate";
3
4
  import {
4
- evaluateLive,
5
5
  evaluateOnLasso,
6
+ getInterpretedAtoms,
6
7
  toLiveExpression,
8
+ type LiveAtoms,
7
9
  type ScopedExpression,
8
10
  type TemporalProperty,
9
11
  } from "./liveness";
@@ -13,15 +15,18 @@ import {
13
15
  getSolutions,
14
16
  getTermKey,
15
17
  isFulfilling,
18
+ type LiveAction,
19
+ type LiveEnabled,
16
20
  type LiveExpression,
21
+ type LiveState,
17
22
  type Solution,
18
23
  type Tableau,
19
24
  } from "./tableau";
20
25
  import { isSameValue, type Value } from "./values";
21
26
 
22
- export interface LiveSuccessor {
27
+ export interface LiveSuccessor<State = Value[]> {
23
28
  index: number;
24
- state: Value[];
29
+ state: State;
25
30
  }
26
31
 
27
32
  export interface Lasso {
@@ -32,6 +37,7 @@ export interface Lasso {
32
37
 
33
38
  export interface LivenessChecker {
34
39
  branches: number;
40
+ solutions: Solution[];
35
41
  addInitialState: (index: number, state: Value[], tracing?: Environment) => void;
36
42
  addState: (
37
43
  index: number,
@@ -43,9 +49,30 @@ export interface LivenessChecker {
43
49
  getViolatedProperties: (path: Value[][], cycleStart: number) => string[];
44
50
  }
45
51
 
46
- interface SearchGraph {
47
- getFingerprint: (successor: LiveSuccessor) => number;
48
- getSuccessors: (index: number, state: Value[]) => LiveSuccessor[];
52
+ export interface LiveGraph<State> {
53
+ branches: number;
54
+ addInitialState: (index: number, state: State) => void;
55
+ // The path to an accepting node the state reaches, if any.
56
+ addState: (
57
+ index: number,
58
+ state: State,
59
+ successors: LiveSuccessor<State>[],
60
+ ) => number[] | undefined;
61
+ findViolation: () => Lasso | undefined;
62
+ }
63
+
64
+ export interface SearchGraph<State> {
65
+ getFingerprint: (successor: LiveSuccessor<State>) => number;
66
+ getSuccessors: (index: number, state: State) => LiveSuccessor<State>[];
67
+ }
68
+
69
+ export interface LiveEvaluation<State> {
70
+ atoms: LiveAtoms<State>;
71
+ // Whether a check's result for a state holds for every step from it.
72
+ isShared: boolean;
73
+ isSame: (left: State, right: State) => boolean;
74
+ // Evaluates the checks of a state the search found from the state at source.
75
+ evaluateFrom: <Result>(source: number | undefined, evaluate: () => Result) => Result;
49
76
  }
50
77
 
51
78
  interface Pool<Data extends Int32Array | Uint8Array> {
@@ -54,8 +81,25 @@ interface Pool<Data extends Int32Array | Uint8Array> {
54
81
  create: (length: number) => Data;
55
82
  }
56
83
 
57
- interface BehaviorGraph {
84
+ // A check reads and fills the state atoms of a state in its row, which starts at offset.
85
+ type Check<State> = (
86
+ state: State,
87
+ row: Int8Array,
88
+ offset: number,
89
+ next: State | undefined,
90
+ ) => boolean;
91
+
92
+ interface BehaviorChecks<State> {
93
+ states: Check<State>[];
94
+ actions: Check<State>[];
95
+ // The state predicates of each tableau node, or, where its checks share results and it has only
96
+ // state atoms and their negations, each atom's id * 2 plus 1 if it must hold.
97
+ nodes: (Check<State>[] | Int32Array)[];
98
+ }
99
+
100
+ interface BehaviorGraph<State> {
58
101
  solution: Solution;
102
+ checks: BehaviorChecks<State>;
59
103
  actionIds: Int32Array;
60
104
  nodeStates: number[];
61
105
  nodeTableaux: number[];
@@ -112,14 +156,18 @@ const writeToPool = <Data extends Int32Array | Uint8Array>(
112
156
  pool: Pool<Data>,
113
157
  offset: number,
114
158
  values: ArrayLike<number>,
159
+ start = 0,
160
+ length = values.length - start,
115
161
  ) => {
116
- const end = offset + values.length;
162
+ const end = offset + length;
117
163
  if (end > pool.data.length) {
118
164
  const data = pool.create(Math.max(2 * pool.data.length, end));
119
165
  data.set(pool.data);
120
166
  pool.data = data;
121
167
  }
122
- pool.data.set(values, offset);
168
+ for (let position = 0; position < length; position++) {
169
+ pool.data[offset + position] = values[start + position];
170
+ }
123
171
  pool.length = Math.max(pool.length, end);
124
172
  };
125
173
 
@@ -148,20 +196,20 @@ const createNodes = (length: number) => new Int32Array(length).fill(NO_NODE);
148
196
 
149
197
  const UNWRITTEN = -1;
150
198
 
151
- const isWritten = (behavior: BehaviorGraph, node: number) =>
199
+ const isWritten = <State>(behavior: BehaviorGraph<State>, node: number) =>
152
200
  (behavior.edgeStarts[node] ?? UNWRITTEN) !== UNWRITTEN;
153
201
 
154
- const getNodeSuccessors = (behavior: BehaviorGraph, node: number) => {
202
+ const getNodeSuccessors = <State>(behavior: BehaviorGraph<State>, node: number) => {
155
203
  const start = behavior.edgeStarts[node];
156
204
  return behavior.edgeTargets.data.subarray(start, start + behavior.edgeCounts[node]);
157
205
  };
158
206
 
159
- const getStateResult = (behavior: BehaviorGraph, node: number, position: number) =>
207
+ const getStateResult = <State>(behavior: BehaviorGraph<State>, node: number, position: number) =>
160
208
  behavior.stateResults.data[
161
209
  behavior.nodeStates[node] * behavior.solution.stateChecks.length + position
162
210
  ] === 1;
163
211
 
164
- const pushNode = (behavior: BehaviorGraph, state: number, tableauNode: number) => {
212
+ const pushNode = <State>(behavior: BehaviorGraph<State>, state: number, tableauNode: number) => {
165
213
  behavior.nodeStates.push(state);
166
214
  behavior.nodeTableaux.push(tableauNode);
167
215
  behavior.edgeStarts.push(UNWRITTEN);
@@ -170,7 +218,7 @@ const pushNode = (behavior: BehaviorGraph, state: number, tableauNode: number) =
170
218
  return behavior.nodeStates.length - 1;
171
219
  };
172
220
 
173
- const getStateNodes = (behavior: BehaviorGraph, state: number) => {
221
+ const getStateNodes = <State>(behavior: BehaviorGraph<State>, state: number) => {
174
222
  const nodes: number[] = [];
175
223
  for (
176
224
  let node = behavior.firstNodes.data[state] ?? NO_NODE;
@@ -190,13 +238,11 @@ const UNVISITED = -1;
190
238
 
191
239
  const MAXIMUM_LINK = Number.MAX_SAFE_INTEGER;
192
240
 
193
- export const createLivenessChecker = (
241
+ const getLiveFormula = (
194
242
  properties: TemporalProperty[],
195
243
  temporals: ScopedExpression[],
196
244
  environment: Environment,
197
- search: SearchGraph,
198
- ): LivenessChecker | undefined => {
199
- if (properties.length === 0) return undefined;
245
+ ) => {
200
246
  const fairness = temporals.map((item) =>
201
247
  toLiveExpression(item.expression, item.scope, environment),
202
248
  );
@@ -206,10 +252,240 @@ export const createLivenessChecker = (
206
252
  const violation = negations.length === 1 ? negations[0] : createJunction("Or", negations);
207
253
  const formula =
208
254
  fairness.length === 0 ? violation : createJunction("And", [...fairness, violation]);
209
- const solutions = getSolutions(formula);
255
+ return { formula, negations };
256
+ };
257
+
258
+ export type LiveAtom = LiveState | LiveEnabled | LiveAction;
259
+
260
+ const getAtomExpressions = (atom: LiveAtom): ScopedExpression[] => {
261
+ switch (atom.kind) {
262
+ case "State":
263
+ return [atom];
264
+ case "Enabled":
265
+ return [{ expression: atom.step, scope: atom.scope }];
266
+ case "Action":
267
+ return [atom.expression, atom.subscript].flatMap((inner) =>
268
+ inner ? [{ expression: inner, scope: atom.scope }] : [],
269
+ );
270
+ }
271
+ };
272
+
273
+ const collectAtoms = (expression: LiveExpression, atoms: Set<LiveAtom>) => {
274
+ switch (expression.kind) {
275
+ case "Boolean":
276
+ return;
277
+ case "State":
278
+ case "Enabled":
279
+ case "Action":
280
+ atoms.add(expression);
281
+ return;
282
+ case "And":
283
+ case "Or":
284
+ expression.operands.forEach((operand) => collectAtoms(operand, atoms));
285
+ return;
286
+ default:
287
+ collectAtoms(expression.body, atoms);
288
+ }
289
+ };
290
+
291
+ // The atoms the checks of the solutions evaluate.
292
+ export const getLiveAtoms = (solutions: Solution[]) => {
293
+ const atoms = new Set<LiveAtom>();
294
+ for (const solution of solutions) {
295
+ [
296
+ ...solution.stateChecks,
297
+ ...solution.actionChecks,
298
+ ...(solution.tableau?.nodes.flatMap((node) => node.statePredicates) ?? []),
299
+ ].forEach((check) => collectAtoms(check, atoms));
300
+ }
301
+ return [...atoms];
302
+ };
303
+
304
+ // The expressions the checks of the solutions evaluate.
305
+ export const getLiveExpressions = (solutions: Solution[]) =>
306
+ getLiveAtoms(solutions).flatMap((atom) =>
307
+ getAtomExpressions(atom).map((item) => item.expression),
308
+ );
309
+
310
+ export const createLivenessChecker = (
311
+ properties: TemporalProperty[],
312
+ temporals: ScopedExpression[],
313
+ environment: Environment,
314
+ search: SearchGraph<Value[]>,
315
+ ): LivenessChecker | undefined => {
316
+ if (properties.length === 0) return undefined;
317
+ const live = getLiveFormula(properties, temporals, environment);
318
+ // A check evaluated once for a state shows what TLC shows when no check repeats an effect. A
319
+ // definition TLC evaluates as it starts repeats nothing, but a scope can bind any definition.
320
+ const formulaAtoms = new Set<LiveAtom>();
321
+ collectAtoms(live.formula, formulaAtoms);
322
+ const checked = [...formulaAtoms].flatMap(getAtomExpressions);
323
+ const isShared = checked.every((item) => item.scope === undefined)
324
+ ? !isExpressionImpure(
325
+ checked.map((item) => item.expression),
326
+ environment,
327
+ "repeated",
328
+ )
329
+ : !hasRepeatedEffects(environment);
330
+ const tracing = { environment, atoms: getInterpretedAtoms(environment) };
331
+ const solutions = getSolutions(live.formula);
332
+ const graph = createLiveGraph(
333
+ solutions,
334
+ {
335
+ atoms: {
336
+ holdsState: (atom, state) => tracing.atoms.holdsState(atom, state),
337
+ holdsAction: (atom, state, next) => tracing.atoms.holdsAction(atom, state, next),
338
+ },
339
+ isShared,
340
+ isSame: isSameState,
341
+ evaluateFrom: (source, evaluate) => {
342
+ environment.runtime.setLivenessSource(source);
343
+ try {
344
+ return evaluate();
345
+ } finally {
346
+ environment.runtime.setLivenessSource(undefined);
347
+ }
348
+ },
349
+ },
350
+ search,
351
+ environment.runtime.version !== "1.7.4",
352
+ );
353
+ const traceWith = <Result>(replay: Environment | undefined, run: () => Result) => {
354
+ if (replay === undefined) return run();
355
+ tracing.atoms = getInterpretedAtoms(replay);
356
+ try {
357
+ return run();
358
+ } finally {
359
+ tracing.atoms = getInterpretedAtoms(environment);
360
+ }
361
+ };
362
+ return {
363
+ branches: graph.branches,
364
+ solutions,
365
+ addInitialState: (index, state, replay) =>
366
+ traceWith(replay, () => graph.addInitialState(index, state)),
367
+ addState: (index, state, successors, replay) =>
368
+ traceWith(replay, () => graph.addState(index, state, successors)),
369
+ findViolation: graph.findViolation,
370
+ getViolatedProperties: (path, cycleStart) => [
371
+ ...new Set(
372
+ properties
373
+ .filter(
374
+ (_property, position) =>
375
+ !evaluateOnLasso(live.negations[position].body, path, cycleStart, 0, environment),
376
+ )
377
+ .map((property) => property.name),
378
+ ),
379
+ ],
380
+ };
381
+ };
382
+
383
+ export const createLiveGraph = <State>(
384
+ solutions: Solution[],
385
+ evaluation: LiveEvaluation<State>,
386
+ search: SearchGraph<State>,
387
+ isAcceptingFound: boolean,
388
+ ): LiveGraph<State> => {
210
389
  const actionIds = new Map<string, number>();
211
- const behaviors = solutions.map((solution): BehaviorGraph => ({
390
+ let capacityMultiplier = 1;
391
+ const isShared = evaluation.isShared;
392
+ const atoms = evaluation.atoms;
393
+ const evaluateFrom = evaluation.evaluateFrom;
394
+ const stateAtoms = new Map<LiveState | LiveEnabled, number>();
395
+ const atomsById: (LiveState | LiveEnabled)[] = [];
396
+ const getAtomId = (atom: LiveState | LiveEnabled) => {
397
+ const id = stateAtoms.get(atom) ?? stateAtoms.size;
398
+ stateAtoms.set(atom, id);
399
+ atomsById[id] = atom;
400
+ return id;
401
+ };
402
+ const getLiterals = (expression: LiveExpression): number[] | undefined => {
403
+ if (expression.kind === "State" || expression.kind === "Enabled") {
404
+ return [getAtomId(expression) * 2 + 1];
405
+ }
406
+ if (expression.kind === "Not") {
407
+ const body = expression.body;
408
+ return body.kind === "State" || body.kind === "Enabled" ? [getAtomId(body) * 2] : undefined;
409
+ }
410
+ if (expression.kind !== "And") return undefined;
411
+ const operands = expression.operands.map(getLiterals);
412
+ return operands.every((operand) => operand !== undefined) ? operands.flat() : undefined;
413
+ };
414
+ // The rows of states, one after another, hold whether each state atom holds of a state: 1 or 0,
415
+ // or -1 before it is evaluated.
416
+ const createRows = (count: number) => new Int8Array(count * stateAtoms.size).fill(-1);
417
+ // The edge rows of steps hold the result of each action check, shared by the behaviors that
418
+ // check it.
419
+ const createEdgeRows = (count: number) => new Int8Array(count * actionIds.size).fill(-1);
420
+ // Unless the checks share results, each check evaluates its atoms afresh.
421
+ const runCheck = (
422
+ check: Check<State>,
423
+ state: State,
424
+ row: Int8Array,
425
+ offset: number,
426
+ next?: State,
427
+ ) => (isShared ? check(state, row, offset, next) : check(state, createRows(1), 0, next));
428
+ const compileCheck = (expression: LiveExpression): Check<State> => {
429
+ switch (expression.kind) {
430
+ case "Boolean": {
431
+ const value = expression.value;
432
+ return () => value;
433
+ }
434
+ case "State":
435
+ case "Enabled": {
436
+ const id = getAtomId(expression);
437
+ return (state, row, offset) => {
438
+ if (row[offset + id] === -1) {
439
+ row[offset + id] = atoms.holdsState(expression, state) ? 1 : 0;
440
+ }
441
+ return row[offset + id] === 1;
442
+ };
443
+ }
444
+ case "Action": {
445
+ const enabled = expression.enabled && getAtomId(expression.enabled);
446
+ return (state, row, offset, next) =>
447
+ !(enabled !== undefined && row[offset + enabled] === 0) &&
448
+ next !== undefined &&
449
+ atoms.holdsAction(expression, state, next);
450
+ }
451
+ case "Not": {
452
+ const body = compileCheck(expression.body);
453
+ return (state, row, offset, next) => !body(state, row, offset, next);
454
+ }
455
+ case "And": {
456
+ const operands = expression.operands.map(compileCheck);
457
+ return (state, row, offset, next) =>
458
+ operands.every((operand) => operand(state, row, offset, next));
459
+ }
460
+ case "Or": {
461
+ const operands = expression.operands.map(compileCheck);
462
+ return (state, row, offset, next) =>
463
+ operands.some((operand) => operand(state, row, offset, next));
464
+ }
465
+ case "Next": {
466
+ const body = compileCheck(expression.body);
467
+ return (state, _row, _offset, next) => body(next ?? state, createRows(1), 0, undefined);
468
+ }
469
+ case "Always":
470
+ case "Eventually":
471
+ return () => {
472
+ throw new TlaEvaluationError("TLC cannot evaluate a temporal formula in a single step");
473
+ };
474
+ }
475
+ };
476
+ const behaviors = solutions.map((solution): BehaviorGraph<State> => ({
212
477
  solution,
478
+ checks: {
479
+ states: solution.stateChecks.map(compileCheck),
480
+ actions: solution.actionChecks.map(compileCheck),
481
+ nodes:
482
+ solution.tableau?.nodes.map((node) => {
483
+ const literals = isShared
484
+ ? getLiterals({ kind: "And", operands: node.statePredicates })
485
+ : undefined;
486
+ return literals ? Int32Array.from(literals) : node.statePredicates.map(compileCheck);
487
+ }) ?? [],
488
+ },
213
489
  actionIds: Int32Array.from(solution.actionChecks, (predicate) => {
214
490
  const key = getTermKey(predicate);
215
491
  const actionId = actionIds.get(key) ?? actionIds.size;
@@ -231,83 +507,85 @@ export const createLivenessChecker = (
231
507
  isDone: [],
232
508
  errorNode: undefined,
233
509
  }));
234
- let capacityMultiplier = 1;
235
-
236
- const isShared = !hasRepeatedEffects(environment);
237
- let evaluationEnvironment = environment;
238
- const sharedStates = new Map<Value[], Map<LiveExpression, boolean>>();
239
- const sharedActions = new Map<Value[], Map<Value[], Int8Array>>();
240
- const getStateCache = (state: Value[]) => {
241
- const cache = sharedStates.get(state) ?? new Map<LiveExpression, boolean>();
242
- sharedStates.set(state, cache);
243
- return cache;
244
- };
245
- const evaluateFrom = <Result>(source: number | undefined, evaluate: () => Result) => {
246
- environment.runtime.setLivenessSource(source);
247
- try {
248
- return evaluate();
249
- } finally {
250
- environment.runtime.setLivenessSource(undefined);
251
- }
252
- };
253
- const evaluateState = (predicate: LiveExpression, state: Value[]) =>
254
- evaluateLive(
255
- predicate,
256
- state,
257
- undefined,
258
- evaluationEnvironment,
259
- isShared ? getStateCache(state) : new Map(),
260
- );
261
- const checkState = (behavior: BehaviorGraph, source: number, state: Value[]) =>
262
- evaluateFrom(source, () =>
263
- Uint8Array.from(behavior.solution.stateChecks, (predicate) =>
264
- evaluateState(predicate, state) ? 1 : 0,
265
- ),
266
- );
510
+ const checkState = (
511
+ behavior: BehaviorGraph<State>,
512
+ source: number,
513
+ state: State,
514
+ row: Int8Array,
515
+ offset: number,
516
+ ) =>
517
+ evaluateFrom(source, () => {
518
+ const checks = behavior.checks.states;
519
+ const results = new Uint8Array(checks.length);
520
+ checks.forEach((check, position) => {
521
+ results[position] = runCheck(check, state, row, offset) ? 1 : 0;
522
+ });
523
+ return results;
524
+ });
525
+ // Writes the result of each action check of the step to successor at resultOffset in results.
267
526
  const checkAction = (
268
- behavior: BehaviorGraph,
527
+ behavior: BehaviorGraph<State>,
269
528
  source: number,
270
- state: Value[],
271
- successor: Value[],
529
+ state: State,
530
+ row: Int8Array,
531
+ offset: number,
532
+ successor: State,
533
+ edges: Int8Array,
534
+ edgeOffset: number,
535
+ results: Uint8Array,
536
+ resultOffset: number,
272
537
  ) =>
273
538
  evaluateFrom(source, () => {
274
- const predicates = behavior.solution.actionChecks;
275
- if (!isShared) {
276
- return Uint8Array.from(predicates, (predicate) =>
277
- evaluateLive(predicate, state, successor, evaluationEnvironment, new Map()) ? 1 : 0,
278
- );
279
- }
280
- const stateCache = getStateCache(state);
281
- const results = sharedActions.get(state) ?? new Map<Value[], Int8Array>();
282
- sharedActions.set(state, results);
283
- const known = results.get(successor) ?? new Int8Array(actionIds.size).fill(-1);
284
- results.set(successor, known);
285
- return Uint8Array.from(behavior.actionIds, (actionId, position) => {
286
- if (known[actionId] === -1) {
287
- known[actionId] = evaluateLive(
288
- predicates[position],
539
+ const actions = behavior.checks.actions;
540
+ for (let position = 0; position < actions.length; position++) {
541
+ if (!isShared) {
542
+ results[resultOffset + position] = runCheck(
543
+ actions[position],
289
544
  state,
545
+ row,
546
+ offset,
290
547
  successor,
291
- evaluationEnvironment,
292
- stateCache,
293
548
  )
294
549
  ? 1
295
550
  : 0;
551
+ continue;
296
552
  }
297
- return known[actionId];
298
- });
553
+ const edge = edgeOffset + behavior.actionIds[position];
554
+ if (edges[edge] === -1)
555
+ edges[edge] = actions[position](state, row, offset, successor) ? 1 : 0;
556
+ results[resultOffset + position] = edges[edge];
557
+ }
299
558
  });
559
+ const holdsNode = (
560
+ behavior: BehaviorGraph<State>,
561
+ node: number,
562
+ state: State,
563
+ row: Int8Array,
564
+ offset: number,
565
+ ) => {
566
+ const checks = behavior.checks.nodes[node];
567
+ if (!(checks instanceof Int32Array)) {
568
+ return checks.every((check) => runCheck(check, state, row, offset));
569
+ }
570
+ for (let position = 0; position < checks.length; position++) {
571
+ const literal: number = checks[position];
572
+ const cell = offset + (literal >> 1);
573
+ if (row[cell] === -1) row[cell] = atoms.holdsState(atomsById[literal >> 1], state) ? 1 : 0;
574
+ if (row[cell] !== (literal & 1)) return false;
575
+ }
576
+ return true;
577
+ };
300
578
  const isConsistent = (
301
- tableau: Tableau,
579
+ behavior: BehaviorGraph<State>,
302
580
  node: number,
303
581
  source: number | undefined,
304
- state: Value[],
305
- ) =>
306
- evaluateFrom(source, () =>
307
- tableau.nodes[node].statePredicates.every((predicate) => evaluateState(predicate, state)),
308
- );
582
+ state: State,
583
+ row: Int8Array,
584
+ offset: number,
585
+ ) => evaluateFrom(source, () => holdsNode(behavior, node, state, row, offset));
586
+
309
587
  const isAccepting = (tableau: Tableau, node: number) => {
310
- if (environment.runtime.version === "1.7.4") return false;
588
+ if (!isAcceptingFound) return false;
311
589
  const tableauNode = tableau.nodes[node];
312
590
  return (
313
591
  tableauNode.particle.length === 0 &&
@@ -316,13 +594,13 @@ export const createLivenessChecker = (
316
594
  );
317
595
  };
318
596
 
319
- const getNodeId = (behavior: BehaviorGraph, state: number, tableauNode: number) => {
597
+ const getNodeId = (behavior: BehaviorGraph<State>, state: number, tableauNode: number) => {
320
598
  if (!behavior.solution.tableau) return state;
321
599
  const slots = behavior.nodeIds.slots;
322
600
  const slot = getNodeSlot(behavior.nodeIds, state, tableauNode);
323
601
  return slots[slot] === 0 ? undefined : slots[slot + 2];
324
602
  };
325
- const recordNode = (behavior: BehaviorGraph, state: number, tableauNode: number) => {
603
+ const recordNode = (behavior: BehaviorGraph<State>, state: number, tableauNode: number) => {
326
604
  const node = pushNode(behavior, state, tableauNode);
327
605
  const table = behavior.nodeIds;
328
606
  if (++table.size * 2 > table.slots.length / 3) {
@@ -345,18 +623,26 @@ export const createLivenessChecker = (
345
623
  writeToPool(behavior.lastNodes, state, [node]);
346
624
  return node;
347
625
  };
626
+ // The action results of the edge to each target are at its position in actions.
348
627
  const writeNode = (
349
- behavior: BehaviorGraph,
628
+ behavior: BehaviorGraph<State>,
350
629
  node: number,
351
630
  targets: number[],
352
- actions: Uint8Array[],
631
+ actionResults: Uint8Array,
632
+ actions: number[],
353
633
  stateResults: Uint8Array,
354
634
  ) => {
355
635
  const start = behavior.edgeTargets.length;
356
636
  const actionCount = behavior.solution.actionChecks.length;
357
637
  writeToPool(behavior.edgeTargets, start, targets);
358
- actions.forEach((results, position) =>
359
- writeToPool(behavior.edgeActions, (start + position) * actionCount, results),
638
+ actions.forEach((position, edge) =>
639
+ writeToPool(
640
+ behavior.edgeActions,
641
+ (start + edge) * actionCount,
642
+ actionResults,
643
+ position * actionCount,
644
+ actionCount,
645
+ ),
360
646
  );
361
647
  writeToPool(
362
648
  behavior.stateResults,
@@ -368,57 +654,68 @@ export const createLivenessChecker = (
368
654
  };
369
655
 
370
656
  // TLC iterates a state's successors and the state itself in the slot order of a SetOfStates, a hash set whose capacity grows with every set that outgrows it.
371
- const getSuccessorSet = (index: number, state: Value[], successors: LiveSuccessor[]) => {
372
- let successorSlots = Array.from<LiveSuccessor | undefined>({
373
- length: SUCCESSOR_CAPACITY * capacityMultiplier,
374
- });
375
- let successorCount = 0;
376
- const insertSuccessor = (slots: (LiveSuccessor | undefined)[], successor: LiveSuccessor) => {
657
+ // Each slot holds a candidate's position plus one, or 0 when it is empty.
658
+ const successorSet = { slots: new Int32Array(0) };
659
+ const getSuccessorSet = (index: number, state: State, successors: LiveSuccessor<State>[]) => {
660
+ const candidates = [...successors, { index, state }];
661
+ const capacity = SUCCESSOR_CAPACITY * capacityMultiplier;
662
+ successorSet.slots =
663
+ successorSet.slots.length === capacity
664
+ ? successorSet.slots.fill(0)
665
+ : new Int32Array(capacity);
666
+ const insert = (position: number) => {
667
+ const slots = successorSet.slots;
668
+ const candidate = candidates[position];
377
669
  for (
378
- let slot = (search.getFingerprint(successor) & 0x7fffffff) % slots.length;
670
+ let slot = (search.getFingerprint(candidate) & 0x7fffffff) % slots.length;
379
671
  ;
380
672
  slot = (slot + 1) % slots.length
381
673
  ) {
382
674
  const entry = slots[slot];
383
- if (entry === undefined) {
384
- slots[slot] = successor;
675
+ if (entry === 0) {
676
+ slots[slot] = position + 1;
385
677
  return true;
386
678
  }
387
- if (entry.index === successor.index && isSameState(entry.state, successor.state))
679
+ const stored = candidates[entry - 1];
680
+ if (stored.index === candidate.index && evaluation.isSame(stored.state, candidate.state))
388
681
  return false;
389
682
  }
390
683
  };
391
- const addSuccessor = (successor: LiveSuccessor) => {
392
- if (successorCount >= successorSlots.length >> 1) {
393
- const old = successorSlots;
394
- successorSlots = Array.from<LiveSuccessor | undefined>({ length: 2 * old.length + 1 });
395
- for (const entry of old) if (entry) insertSuccessor(successorSlots, entry);
684
+ let count = 0;
685
+ for (let position = 0; position < candidates.length; position++) {
686
+ if (count >= successorSet.slots.length >> 1) {
687
+ const old = successorSet.slots;
688
+ successorSet.slots = new Int32Array(2 * old.length + 1);
689
+ for (const entry of old) if (entry !== 0) insert(entry - 1);
396
690
  }
397
- if (insertSuccessor(successorSlots, successor)) successorCount++;
398
- };
399
- successors.forEach(addSuccessor);
400
- addSuccessor({ index, state });
401
- if (successorSlots.length > SUCCESSOR_CAPACITY * capacityMultiplier) capacityMultiplier++;
402
- return successorSlots.filter((entry): entry is LiveSuccessor => entry !== undefined);
691
+ if (insert(position)) count++;
692
+ }
693
+ if (successorSet.slots.length > capacity) capacityMultiplier++;
694
+ const set: LiveSuccessor<State>[] = [];
695
+ for (const entry of successorSet.slots) if (entry !== 0) set.push(candidates[entry - 1]);
696
+ return set;
403
697
  };
404
698
 
405
699
  const expandLate = (
406
- behavior: BehaviorGraph,
700
+ behavior: BehaviorGraph<State>,
407
701
  tableau: Tableau,
408
- state: Value[],
702
+ state: State,
409
703
  index: number,
410
704
  node: number,
705
+ row: Int8Array,
706
+ offset: number,
411
707
  ) => {
412
- const stateResults = checkState(behavior, index, state);
708
+ const stateResults = checkState(behavior, index, state, row, offset);
413
709
  const tableauNode = tableau.nodes[behavior.nodeTableaux[node]];
414
- const actions: Uint8Array[] = [];
710
+ const actionCount = behavior.checks.actions.length;
711
+ const actions: number[] = [];
415
712
  const successors: number[] = [];
416
- const selfActions =
417
- tableauNode.successors.length > 0
418
- ? checkAction(behavior, index, state, state)
419
- : new Uint8Array(0);
713
+ const selfResults = new Uint8Array(actionCount);
714
+ if (tableauNode.successors.length > 0) {
715
+ checkAction(behavior, index, state, row, offset, state, createEdgeRows(1), 0, selfResults, 0);
716
+ }
420
717
  for (const next of tableauNode.successors) {
421
- if (!isConsistent(tableau, next, index, state)) continue;
718
+ if (!isConsistent(behavior, next, index, state, row, offset)) continue;
422
719
  if (
423
720
  isAccepting(tableau, next) &&
424
721
  behavior.errorNode === undefined &&
@@ -431,60 +728,97 @@ export const createLivenessChecker = (
431
728
  if (existing !== undefined && successors.includes(existing)) continue;
432
729
  const target = existing ?? recordNode(behavior, index, next);
433
730
  successors.push(target);
434
- actions.push(selfActions);
435
- if (existing === undefined) expandLate(behavior, tableau, state, index, target);
731
+ actions.push(0);
732
+ if (existing === undefined) expandLate(behavior, tableau, state, index, target, row, offset);
436
733
  }
437
- for (const successor of search.getSuccessors(index, state)) {
438
- const successorActions = checkAction(behavior, index, state, successor.state);
734
+ const nextStates = search.getSuccessors(index, state);
735
+ // The results of the step to the state itself come first, then those of each successor.
736
+ const actionResults = new Uint8Array((nextStates.length + 1) * actionCount);
737
+ actionResults.set(selfResults);
738
+ const edges = createEdgeRows(nextStates.length);
739
+ nextStates.forEach((successor, position) => {
740
+ const successorRow = createRows(1);
741
+ checkAction(
742
+ behavior,
743
+ index,
744
+ state,
745
+ row,
746
+ offset,
747
+ successor.state,
748
+ edges,
749
+ position * actionIds.size,
750
+ actionResults,
751
+ (position + 1) * actionCount,
752
+ );
439
753
  const isDone = behavior.isDone[successor.index] === true;
440
754
  for (const next of tableauNode.successors) {
441
- if (!isConsistent(tableau, next, index, successor.state)) continue;
755
+ if (!isConsistent(behavior, next, index, successor.state, successorRow, 0)) continue;
442
756
  // Deviation from TLC: TLC records the node of a successor the search never stored, which it never expands.
443
757
  if (successor.index === -1) continue;
444
758
  const existing = getNodeId(behavior, successor.index, next);
445
759
  if (existing !== undefined && successors.includes(existing)) continue;
446
760
  const target = existing ?? recordNode(behavior, successor.index, next);
447
761
  successors.push(target);
448
- actions.push(successorActions);
762
+ actions.push(position + 1);
449
763
  if (existing === undefined && isDone) {
450
- expandLate(behavior, tableau, successor.state, successor.index, target);
764
+ expandLate(behavior, tableau, successor.state, successor.index, target, successorRow, 0);
451
765
  }
452
766
  }
767
+ });
768
+ if (successors.length > 0) {
769
+ writeNode(behavior, node, successors, actionResults, actions, stateResults);
453
770
  }
454
- if (successors.length > 0) writeNode(behavior, node, successors, actions, stateResults);
455
771
  };
456
772
 
457
773
  const addTableauState = (
458
- behavior: BehaviorGraph,
774
+ behavior: BehaviorGraph<State>,
459
775
  tableau: Tableau,
460
- set: LiveSuccessor[],
461
- actionResults: Uint8Array[],
776
+ set: LiveSuccessor<State>[],
777
+ rows: Int8Array,
778
+ actionResults: Uint8Array,
462
779
  stateResults: Uint8Array,
463
780
  index: number,
464
781
  ) => {
465
- const consistency = tableau.nodes.map((_tableauNode, node) =>
466
- set.map((successor) => isConsistent(tableau, node, index, successor.state)),
467
- );
782
+ const atomCount = stateAtoms.size;
783
+ // Whether each successor is consistent with each tableau node, node by node.
784
+ const consistency = new Uint8Array(tableau.nodes.length * set.length);
785
+ evaluateFrom(index, () => {
786
+ for (let node = 0; node < tableau.nodes.length; node++) {
787
+ for (let position = 0; position < set.length; position++) {
788
+ if (holdsNode(behavior, node, set[position].state, rows, position * atomCount)) {
789
+ consistency[node * set.length + position] = 1;
790
+ }
791
+ }
792
+ }
793
+ });
468
794
  behavior.isDone[index] = true;
469
795
  // TLC expands the nodes recorded before the loop, not the ones the loop records.
470
796
  for (const node of getStateNodes(behavior, index)) {
471
797
  const successors: number[] = [];
472
- const actions: Uint8Array[] = [];
798
+ const actions: number[] = [];
473
799
  set.forEach((successor, position) => {
474
800
  const isDone = behavior.isDone[successor.index] === true;
475
801
  for (const next of tableau.nodes[behavior.nodeTableaux[node]].successors) {
476
- if (!consistency[next][position]) continue;
802
+ if (consistency[next * set.length + position] === 0) continue;
477
803
  const existing = getNodeId(behavior, successor.index, next);
478
804
  if (existing !== undefined && successors.includes(existing)) continue;
479
805
  const target = existing ?? recordNode(behavior, successor.index, next);
480
806
  successors.push(target);
481
- actions.push(actionResults[position]);
807
+ actions.push(position);
482
808
  if (existing === undefined && isDone) {
483
- expandLate(behavior, tableau, successor.state, successor.index, target);
809
+ expandLate(
810
+ behavior,
811
+ tableau,
812
+ successor.state,
813
+ successor.index,
814
+ target,
815
+ rows,
816
+ position * atomCount,
817
+ );
484
818
  }
485
819
  }
486
820
  });
487
- writeNode(behavior, node, successors, actions, stateResults);
821
+ writeNode(behavior, node, successors, actionResults, actions, stateResults);
488
822
  }
489
823
  return behavior.errorNode === undefined
490
824
  ? undefined
@@ -492,24 +826,24 @@ export const createLivenessChecker = (
492
826
  };
493
827
 
494
828
  const addPlainState = (
495
- behavior: BehaviorGraph,
496
- set: LiveSuccessor[],
497
- actionResults: Uint8Array[],
829
+ behavior: BehaviorGraph<State>,
830
+ set: LiveSuccessor<State>[],
831
+ actionResults: Uint8Array,
498
832
  stateResults: Uint8Array,
499
833
  index: number,
500
834
  ) => {
501
835
  while (behavior.nodeStates.length <= index) pushNode(behavior, behavior.nodeStates.length, -1);
502
836
  const successors: number[] = [];
503
- const actions: Uint8Array[] = [];
837
+ const actions: number[] = [];
504
838
  set.forEach((successor, position) => {
505
839
  if (isWritten(behavior, successor.index) && successors.includes(successor.index)) return;
506
840
  successors.push(successor.index);
507
- actions.push(actionResults[position]);
841
+ actions.push(position);
508
842
  });
509
- writeNode(behavior, index, successors, actions, stateResults);
843
+ writeNode(behavior, index, successors, actionResults, actions, stateResults);
510
844
  };
511
845
 
512
- const getPath = (behavior: BehaviorGraph, target: number) => {
846
+ const getPath = (behavior: BehaviorGraph<State>, target: number) => {
513
847
  if (behavior.initial.includes(target)) return [target];
514
848
  const parents = new Map<number, number>();
515
849
  const queue: number[] = [];
@@ -535,7 +869,7 @@ export const createLivenessChecker = (
535
869
  throw new TlaEvaluationError(`Couldn't re-create liveness trace (path) starting at: ${target}`);
536
870
  };
537
871
 
538
- const getStatePath = (behavior: BehaviorGraph, target: number) =>
872
+ const getStatePath = (behavior: BehaviorGraph<State>, target: number) =>
539
873
  removeRepeats(
540
874
  getPath(behavior, target)
541
875
  .reverse()
@@ -543,7 +877,7 @@ export const createLivenessChecker = (
543
877
  );
544
878
 
545
879
  const findLassoInModel = (
546
- behavior: BehaviorGraph,
880
+ behavior: BehaviorGraph<State>,
547
881
  model: Solution["models"][number],
548
882
  ): Lasso | undefined => {
549
883
  const solution = behavior.solution;
@@ -768,58 +1102,63 @@ export const createLivenessChecker = (
768
1102
 
769
1103
  return {
770
1104
  branches: behaviors.length,
771
- addInitialState: (index, state, tracing) => {
772
- evaluationEnvironment = tracing ?? environment;
773
- sharedStates.clear();
774
- sharedActions.clear();
775
- try {
776
- for (const behavior of behaviors) {
777
- const tableau = behavior.solution.tableau;
778
- if (!tableau) {
779
- behavior.initial.push(index);
780
- continue;
781
- }
782
- for (let node = 0; node < tableau.initialCount; node++) {
783
- if (!isConsistent(tableau, node, undefined, state)) continue;
784
- behavior.initial.push(
785
- getNodeId(behavior, index, node) ?? recordNode(behavior, index, node),
786
- );
787
- }
1105
+ addInitialState: (index, state) => {
1106
+ const row = createRows(1);
1107
+ for (const behavior of behaviors) {
1108
+ const tableau = behavior.solution.tableau;
1109
+ if (!tableau) {
1110
+ behavior.initial.push(index);
1111
+ continue;
1112
+ }
1113
+ for (let node = 0; node < tableau.initialCount; node++) {
1114
+ if (!isConsistent(behavior, node, undefined, state, row, 0)) continue;
1115
+ behavior.initial.push(
1116
+ getNodeId(behavior, index, node) ?? recordNode(behavior, index, node),
1117
+ );
788
1118
  }
789
- } finally {
790
- evaluationEnvironment = environment;
791
1119
  }
792
1120
  },
793
- addState: (index, state, successors, tracing) => {
794
- evaluationEnvironment = tracing ?? environment;
795
- sharedStates.clear();
796
- sharedActions.clear();
797
- try {
798
- const set = getSuccessorSet(index, state, successors);
799
- for (const behavior of behaviors) {
800
- const actionResults = set.map((successor) =>
801
- checkAction(behavior, index, state, successor.state),
802
- );
803
- const stateResults = checkState(behavior, index, state);
804
- const tableau = behavior.solution.tableau;
805
- if (!tableau) {
806
- addPlainState(behavior, set, actionResults, stateResults, index);
807
- continue;
808
- }
809
- const accepted = addTableauState(
1121
+ addState: (index, state, successors) => {
1122
+ const set = getSuccessorSet(index, state, successors);
1123
+ const rows = createRows(set.length);
1124
+ // The set holds the state itself, as a successor of the same index.
1125
+ const offset = set.findIndex((successor) => successor.index === index) * stateAtoms.size;
1126
+ const edges = createEdgeRows(set.length);
1127
+ for (const behavior of behaviors) {
1128
+ const actionCount = behavior.checks.actions.length;
1129
+ const actionResults = new Uint8Array(set.length * actionCount);
1130
+ set.forEach((successor, position) =>
1131
+ checkAction(
810
1132
  behavior,
811
- tableau,
812
- set,
813
- actionResults,
814
- stateResults,
815
1133
  index,
816
- );
817
- if (accepted) return accepted;
1134
+ state,
1135
+ rows,
1136
+ offset,
1137
+ successor.state,
1138
+ edges,
1139
+ position * actionIds.size,
1140
+ actionResults,
1141
+ position * actionCount,
1142
+ ),
1143
+ );
1144
+ const stateResults = checkState(behavior, index, state, rows, offset);
1145
+ const tableau = behavior.solution.tableau;
1146
+ if (!tableau) {
1147
+ addPlainState(behavior, set, actionResults, stateResults, index);
1148
+ continue;
818
1149
  }
819
- return undefined;
820
- } finally {
821
- evaluationEnvironment = environment;
1150
+ const accepted = addTableauState(
1151
+ behavior,
1152
+ tableau,
1153
+ set,
1154
+ rows,
1155
+ actionResults,
1156
+ stateResults,
1157
+ index,
1158
+ );
1159
+ if (accepted) return accepted;
822
1160
  }
1161
+ return undefined;
823
1162
  },
824
1163
  findViolation: () => {
825
1164
  for (const behavior of behaviors) {
@@ -830,15 +1169,5 @@ export const createLivenessChecker = (
830
1169
  }
831
1170
  return undefined;
832
1171
  },
833
- getViolatedProperties: (path, cycleStart) => [
834
- ...new Set(
835
- properties
836
- .filter(
837
- (_property, position) =>
838
- !evaluateOnLasso(negations[position].body, path, cycleStart, 0, environment),
839
- )
840
- .map((property) => property.name),
841
- ),
842
- ],
843
1172
  };
844
1173
  };