tla-ts 0.0.10-dev.99796fe03 → 0.0.10-dev.a17d6d9fa

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 (226) hide show
  1. package/dist/compile.cjs +3 -3
  2. package/dist/compile.js +1 -1
  3. package/dist/deciders.cjs +36 -36
  4. package/dist/deciders.js +54 -54
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.d.cts +3 -2
  7. package/dist/index.d.ts +3 -2
  8. package/dist/index.js +1 -1
  9. package/dist/parallel-worker.cjs +1 -1
  10. package/dist/parallel-worker.js +1 -1
  11. package/dist/prove-worker.cjs +1 -1
  12. package/dist/prove-worker.js +1 -1
  13. package/dist/prove.cjs +60 -60
  14. package/dist/prove.js +78 -78
  15. package/dist/run.cjs +42 -44
  16. package/dist/run.js +44 -46
  17. package/dist/tlapm.cjs +1 -1
  18. package/dist/tlapm.js +2 -2
  19. package/dist/transfer.cjs +43 -43
  20. package/dist/transfer.js +39 -39
  21. package/dist/worker.cjs +6 -6
  22. package/dist/worker.js +6 -6
  23. package/package.json +1 -1
  24. package/src/ast.ts +1 -0
  25. package/src/bags.ts +50 -29
  26. package/src/builtins.ts +4 -3
  27. package/src/check-failure.ts +1 -1
  28. package/src/check-trace.ts +90 -51
  29. package/src/check.ts +367 -178
  30. package/src/cli/runtime-invariants.ts +20 -56
  31. package/src/cli/tlc-arguments.ts +2 -2
  32. package/src/cli/tlc-output.ts +1 -2
  33. package/src/cli/tlc.ts +16 -10
  34. package/src/cli/xml-exporter.ts +1 -1
  35. package/src/codegen.ts +26 -9
  36. package/src/dependencies.ts +49 -9
  37. package/src/dfid.ts +22 -10
  38. package/src/environment.ts +58 -33
  39. package/src/errors.ts +7 -0
  40. package/src/evaluate.ts +117 -41
  41. package/src/exit-codes.ts +4 -2
  42. package/src/instances.ts +5 -5
  43. package/src/java-hash.ts +14 -0
  44. package/src/java-overrides.ts +2 -2
  45. package/src/levels.ts +138 -90
  46. package/src/liveness-checker.ts +81 -33
  47. package/src/liveness.ts +49 -11
  48. package/src/obligations/index.ts +1 -1
  49. package/src/obligations/normalize.ts +1 -4
  50. package/src/obligations/printer.ts +5 -5
  51. package/src/parallel-worker.ts +8 -2
  52. package/src/parallel.ts +5 -0
  53. package/src/parser.ts +112 -145
  54. package/src/prover/isabelle/isar/attrib.ts +4 -4
  55. package/src/prover/isabelle/isar/rule-cases.ts +8 -6
  56. package/src/prover/isabelle/provers/clasimp.ts +1 -1
  57. package/src/prover/isabelle/provers/hypsubst.ts +2 -2
  58. package/src/prover/isabelle/pure/rewriter.ts +3 -3
  59. package/src/prover/isabelle/pure/term.ts +3 -3
  60. package/src/prover/prep/md5.ts +26 -29
  61. package/src/prover/smt/rewrite.ts +2 -7
  62. package/src/prover/smt/simplify.ts +1 -1
  63. package/src/prover/smt/solver/arith-rewriter.ts +11 -3
  64. package/src/prover/smt/solver/array-rewriter.ts +12 -2
  65. package/src/prover/smt/solver/asserted-formulas.ts +169 -58
  66. package/src/prover/smt/solver/ast-lt.ts +1 -1
  67. package/src/prover/smt/solver/ast.ts +63 -14
  68. package/src/prover/smt/solver/auf-solver.ts +23 -12
  69. package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
  70. package/src/prover/smt/solver/blast-term-ite.ts +47 -0
  71. package/src/prover/smt/solver/bound-simplifier.ts +11 -13
  72. package/src/prover/smt/solver/bv-decl-plugin.ts +13 -10
  73. package/src/prover/smt/solver/bv-rewriter.ts +1 -1
  74. package/src/prover/smt/solver/card2bv.ts +32 -18
  75. package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -24
  76. package/src/prover/smt/solver/context.ts +47 -9
  77. package/src/prover/smt/solver/ctx-simplify.ts +1 -2
  78. package/src/prover/smt/solver/datatype-decl-plugin.ts +15 -7
  79. package/src/prover/smt/solver/dependent-expr-state.ts +9 -4
  80. package/src/prover/smt/solver/diff-neq.ts +1 -2
  81. package/src/prover/smt/solver/elim-bounds.ts +89 -0
  82. package/src/prover/smt/solver/elim-term-ite-tactic.ts +48 -0
  83. package/src/prover/smt/solver/elim-uncnstr.ts +5 -8
  84. package/src/prover/smt/solver/euf/arith-internalize.ts +1 -1
  85. package/src/prover/smt/solver/euf/array-internalize.ts +1 -1
  86. package/src/prover/smt/solver/euf/bv-internalize.ts +1 -1
  87. package/src/prover/smt/solver/euf/egraph.ts +4 -11
  88. package/src/prover/smt/solver/euf/euf-solver.ts +1 -2
  89. package/src/prover/smt/solver/euf/mam.ts +1 -5
  90. package/src/prover/smt/solver/euf/q-ematch.ts +1 -2
  91. package/src/prover/smt/solver/euf/th-solver.ts +0 -7
  92. package/src/prover/smt/solver/expr2polynomial.ts +204 -79
  93. package/src/prover/smt/solver/factor.ts +36 -14
  94. package/src/prover/smt/solver/fd-solver.ts +2 -0
  95. package/src/prover/smt/solver/fix-dl-var.ts +1 -2
  96. package/src/prover/smt/solver/fpa-rewriter.ts +1 -2
  97. package/src/prover/smt/solver/fpa2bv-converter.ts +3 -1
  98. package/src/prover/smt/solver/fpa2bv-rewriter.ts +1 -0
  99. package/src/prover/smt/solver/goal.ts +6 -3
  100. package/src/prover/smt/solver/goal2nlsat.ts +57 -30
  101. package/src/prover/smt/solver/hashtable.ts +4 -0
  102. package/src/prover/smt/solver/internalizer.ts +1 -1
  103. package/src/prover/smt/solver/logic-tactics.ts +9 -2
  104. package/src/prover/smt/solver/lp/lp-settings.ts +5 -1
  105. package/src/prover/smt/solver/lp/nla-core.ts +1 -1
  106. package/src/prover/smt/solver/lp/nla-grobner.ts +2 -2
  107. package/src/prover/smt/solver/lp/nra-solver.ts +45 -39
  108. package/src/prover/smt/solver/lp/pdd.ts +2 -3
  109. package/src/prover/smt/solver/lp/union-find.ts +1 -1
  110. package/src/prover/smt/solver/mam-compiler.ts +1 -1
  111. package/src/prover/smt/solver/model-based-opt.ts +1 -1
  112. package/src/prover/smt/solver/model-evaluator.ts +2 -0
  113. package/src/prover/smt/solver/model-generator.ts +85 -43
  114. package/src/prover/smt/solver/mpf.ts +2 -4
  115. package/src/prover/smt/solver/mus.ts +2 -3
  116. package/src/prover/smt/solver/muz/dl-context.ts +10 -4
  117. package/src/prover/smt/solver/muz/dl-mk-slice.ts +3 -3
  118. package/src/prover/smt/solver/muz/dl-rule.ts +2 -2
  119. package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +1 -1
  120. package/src/prover/smt/solver/muz/horn-tactic.ts +1 -1
  121. package/src/prover/smt/solver/muz/spacer-context.ts +2 -4
  122. package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
  123. package/src/prover/smt/solver/nlqsat.ts +1 -1
  124. package/src/prover/smt/solver/nlsat/algebraic.ts +196 -92
  125. package/src/prover/smt/solver/nlsat/atoms.ts +52 -33
  126. package/src/prover/smt/solver/nlsat/explain.ts +375 -217
  127. package/src/prover/smt/solver/nlsat/levelwise.ts +460 -240
  128. package/src/prover/smt/solver/nlsat/polynomial.ts +2366 -681
  129. package/src/prover/smt/solver/nlsat/solver.ts +74 -64
  130. package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -17
  131. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -4
  132. package/src/prover/smt/solver/nlsat/upolynomial.ts +41 -18
  133. package/src/prover/smt/solver/nlsat-tactic.ts +1 -1
  134. package/src/prover/smt/solver/nnf.ts +6 -2
  135. package/src/prover/smt/solver/opt-context.ts +20 -7
  136. package/src/prover/smt/solver/opt-nlsat.ts +29 -18
  137. package/src/prover/smt/solver/opt-pareto.ts +19 -0
  138. package/src/prover/smt/solver/opt-preprocess.ts +1 -1
  139. package/src/prover/smt/solver/opt-solver.ts +9 -5
  140. package/src/prover/smt/solver/optsmt.ts +1 -1
  141. package/src/prover/smt/solver/pb-rewriter.ts +1 -4
  142. package/src/prover/smt/solver/poly-rewriter.ts +75 -18
  143. package/src/prover/smt/solver/probes.ts +88 -23
  144. package/src/prover/smt/solver/proto-model.ts +8 -8
  145. package/src/prover/smt/solver/push-app-ite.ts +37 -0
  146. package/src/prover/smt/solver/qe-arith-plugin.ts +2 -4
  147. package/src/prover/smt/solver/qe-lite.ts +2 -2
  148. package/src/prover/smt/solver/qe.ts +3 -2
  149. package/src/prover/smt/solver/qsat.ts +16 -6
  150. package/src/prover/smt/solver/quantifier-manager.ts +14 -9
  151. package/src/prover/smt/solver/recfun-decl-plugin.ts +2 -1
  152. package/src/prover/smt/solver/rewriter.ts +31 -25
  153. package/src/prover/smt/solver/rlimit.ts +4 -0
  154. package/src/prover/smt/solver/sat/config.ts +1 -1
  155. package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
  156. package/src/prover/smt/solver/sat/inc-sat-solver.ts +39 -5
  157. package/src/prover/smt/solver/sat/model-converter.ts +1 -1
  158. package/src/prover/smt/solver/sat/pb-solver.ts +1 -1
  159. package/src/prover/smt/solver/sat/sat-tactic.ts +13 -5
  160. package/src/prover/smt/solver/sat/simplifier.ts +1 -1
  161. package/src/prover/smt/solver/sat/solver.ts +25 -47
  162. package/src/prover/smt/solver/seq-axioms.ts +20 -35
  163. package/src/prover/smt/solver/seq-decl-plugin.ts +1 -1
  164. package/src/prover/smt/solver/seq-derive.ts +2 -2
  165. package/src/prover/smt/solver/seq-eq-solver.ts +2 -2
  166. package/src/prover/smt/solver/seq-monadic.ts +7 -5
  167. package/src/prover/smt/solver/seq-re-rewriter.ts +2 -1
  168. package/src/prover/smt/solver/seq-re-util.ts +1 -1
  169. package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
  170. package/src/prover/smt/solver/seq-regex-live.ts +2 -2
  171. package/src/prover/smt/solver/seq-rewriter.ts +31 -29
  172. package/src/prover/smt/solver/seq-skolem.ts +0 -23
  173. package/src/prover/smt/solver/seq-view-witness.ts +4 -4
  174. package/src/prover/smt/solver/smt-kernel.ts +39 -5
  175. package/src/prover/smt/solver/smt-setup.ts +96 -10
  176. package/src/prover/smt/solver/smtlib-parser.ts +584 -223
  177. package/src/prover/smt/solver/smtlib-script.ts +509 -154
  178. package/src/prover/smt/solver/solve-eqs.ts +36 -37
  179. package/src/prover/smt/solver/solver.ts +18 -3
  180. package/src/prover/smt/solver/tactic.ts +284 -168
  181. package/src/prover/smt/solver/theory-bv.ts +13 -3
  182. package/src/prover/smt/solver/theory-fpa.ts +1 -1
  183. package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
  184. package/src/prover/smt/solver/theory-lra-internalize.ts +2 -0
  185. package/src/prover/smt/solver/theory-lra-propagate.ts +11 -3
  186. package/src/prover/smt/solver/theory-lra.ts +1 -1
  187. package/src/prover/smt/solver/theory-pb.ts +24 -7
  188. package/src/prover/smt/solver/theory-seq-solve.ts +1 -1
  189. package/src/prover/smt/solver/theory-seq-state.ts +2 -21
  190. package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
  191. package/src/prover/tlapm/cache.ts +8 -8
  192. package/src/prover/zenon/index-table.ts +5 -2
  193. package/src/prover/zenon/isar-case.ts +1 -1
  194. package/src/prover/zenon/isar.ts +2 -2
  195. package/src/prover/zenon/phrase.ts +1 -1
  196. package/src/resolve.ts +959 -243
  197. package/src/runtime.ts +7 -1
  198. package/src/sany/builtins.ts +10 -10
  199. package/src/sany/generation.ts +2 -13
  200. package/src/sany/generator-definitions.ts +3 -1
  201. package/src/sany/generator-expressions.ts +36 -30
  202. package/src/sany/generator-proofs.ts +5 -3
  203. package/src/sany/generator.ts +2 -1
  204. package/src/sany/lexer.ts +3 -3
  205. package/src/sany/modules.ts +4 -2
  206. package/src/sany/nodes.ts +1 -1
  207. package/src/sany/selectors.ts +11 -6
  208. package/src/sany/xml.ts +2 -3
  209. package/src/search.ts +166 -101
  210. package/src/simulate.ts +110 -50
  211. package/src/spec-description.ts +5 -6
  212. package/src/standard-modules.ts +15 -6
  213. package/src/subexpressions.ts +398 -108
  214. package/src/successors.ts +4 -2
  215. package/src/symmetry.ts +1 -1
  216. package/src/tlc/jar-data.ts +10 -0
  217. package/src/tlc/messages.ts +3 -3
  218. package/src/tlc/order.ts +14 -3
  219. package/src/tlc/random.ts +2 -1
  220. package/src/tlc/replay.ts +3 -2
  221. package/src/tlc/tlc-operators.ts +10 -8
  222. package/src/tlc/tlcext-operators.ts +44 -15
  223. package/src/tlc/trace-spec.ts +9 -22
  224. package/src/typed-tier.ts +32 -25
  225. package/src/typescript/types.ts +2 -2
  226. package/src/values.ts +135 -78
package/src/levels.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  getChildren,
3
3
  type AssumeProve,
4
+ type Bound,
4
5
  type Definition,
5
6
  type Expression,
6
7
  type Module,
@@ -18,6 +19,7 @@ import {
18
19
  } from "./errors";
19
20
  import { forEachChild } from "./instances";
20
21
  import { collectSemanticErrors, getBoundNames, getPatternNames } from "./resolve";
22
+ import { resolveSynonym } from "./tlc/jar-data";
21
23
  import { STANDARD_LEVELS } from "./standard-definitions";
22
24
 
23
25
  interface LevelData {
@@ -154,27 +156,50 @@ const CORE_SIGNATURES = new Map(
154
156
  ["BOOLEAN", 0, [], []],
155
157
  ["STRING", 0, [], []],
156
158
  ] as const
157
- ).map(([name, level, maxLevels, weights]): [string, OperatorLevels] => [
158
- name,
159
+ ).map((signature): [string, OperatorLevels] => [
160
+ signature[0],
159
161
  {
160
- ...createSignature(name, level, [...maxLevels], [...weights]),
161
- nonLeibniz: new Set(level > 1 ? [0, 1] : []),
162
+ ...createSignature(signature[0], signature[1], [...signature[2]], [...signature[3]]),
163
+ nonLeibniz: new Set(signature[1] > 1 ? [0, 1] : []),
162
164
  },
163
165
  ]),
164
166
  );
165
167
 
166
- const SET_LEVELS = createSignature("$Set", 0, [2], [1]);
167
- const JUNCTION_LEVELS = createSignature("$Junction", 0, [3], [1]);
168
- const CHOOSE_LEVELS = createSignature("$Choose", 0, [2], [1]);
169
- const FUNCTION_LEVELS = createSignature("$Function", 0, [3], [1]);
170
- const APPLY_LEVELS = createSignature("$FcnApply", 0, [2, 2], [1, 1]);
171
- const SELECT_LEVELS = createSignature("$RcdSelect", 0, [2, 0], [1, 1]);
172
168
  const PRIME_LEVELS = createSignature("'", 2, [1], [0]);
169
+ const UNCHANGED_LEVELS = createSignature("UNCHANGED", 2, [1], [0]);
173
170
  const ENABLED_LEVELS = createSignature("ENABLED", 1, [2], [0]);
174
- const TEMPORAL_LEVELS = createSignature("[]", 3, [3], [0]);
175
- const ACTION_LEVELS = createSignature("$SquareAct", 2, [2, 1], [0, 0]);
176
- const FAIRNESS_LEVELS = createSignature("$WF", 3, [1, 2], [0, 0]);
177
- const TEMPORAL_QUANTIFIER_LEVELS = createSignature("$TemporalExists", 3, [3], [0]);
171
+ const ALWAYS_LEVELS = createSignature("[]", 3, [3], [0]);
172
+ const EVENTUALLY_LEVELS = createSignature("<>", 3, [3], [0]);
173
+ const AND_LEVELS = createSignature("$ConjList", 0, [3], [1]);
174
+ const OR_LEVELS = createSignature("$DisjList", 0, [3], [1]);
175
+ const IF_LEVELS = createSignature("$IfThenElse", 0, [3], [1]);
176
+ const CASE_LEVELS = createSignature("$Case", 0, [3], [1]);
177
+ const FORALL_LEVELS = createSignature("$BoundedForall", 0, [3], [1]);
178
+ const EXISTS_LEVELS = createSignature("$BoundedExists", 0, [3], [1]);
179
+ const UNBOUNDED_FORALL_LEVELS = createSignature("$UnboundedForall", 0, [3], [1]);
180
+ const UNBOUNDED_EXISTS_LEVELS = createSignature("$UnboundedExists", 0, [3], [1]);
181
+ const TEMPORAL_FORALL_LEVELS = createSignature("$TemporalForall", 3, [3], [0]);
182
+ const TEMPORAL_EXISTS_LEVELS = createSignature("$TemporalExists", 3, [3], [0]);
183
+ const BOUNDED_CHOOSE_LEVELS = createSignature("$BoundedChoose", 0, [2], [1]);
184
+ const UNBOUNDED_CHOOSE_LEVELS = createSignature("$UnboundedChoose", 0, [2], [1]);
185
+ const SET_ENUMERATE_LEVELS = createSignature("$SetEnumerate", 0, [2], [1]);
186
+ const TUPLE_LEVELS = createSignature("$Tuple", 0, [2], [1]);
187
+ const SET_OF_FCNS_LEVELS = createSignature("$SetOfFcns", 0, [2], [1]);
188
+ const CARTESIAN_PROD_LEVELS = createSignature("$CartesianProd", 0, [2], [1]);
189
+ const SUBSET_OF_LEVELS = createSignature("$SubsetOf", 0, [2], [1]);
190
+ const SET_OF_ALL_LEVELS = createSignature("$SetOfAll", 0, [2], [1]);
191
+ const FCN_CONSTRUCTOR_LEVELS = createSignature("$FcnConstructor", 0, [3], [1]);
192
+ const RCD_CONSTRUCTOR_LEVELS = createSignature("$RcdConstructor", 0, [3], [1]);
193
+ const SET_OF_RCDS_LEVELS = createSignature("$SetOfRcds", 0, [2], [1]);
194
+ const EXCEPT_LEVELS = createSignature("$Except", 0, [2], [1]);
195
+ const PAIR_LEVELS = createSignature("$Pair", 0, [3], [1]);
196
+ const SEQ_LEVELS = createSignature("$Seq", 0, [2], [1]);
197
+ const APPLY_LEVELS = createSignature("$FcnApply", 0, [2, 2], [1, 1]);
198
+ const SELECT_LEVELS = createSignature("$RcdSelect", 0, [2, 0], [1, 1]);
199
+ const SQUARE_ACT_LEVELS = createSignature("$SquareAct", 2, [2, 1], [0, 0]);
200
+ const ANGLE_ACT_LEVELS = createSignature("$AngleAct", 2, [2, 1], [0, 0]);
201
+ const WF_LEVELS = createSignature("$WF", 3, [1, 2], [0, 0]);
202
+ const SF_LEVELS = createSignature("$SF", 3, [1, 2], [0, 0]);
178
203
 
179
204
  const bindFormals = (scope: Scope, formals: OperatorParam[]) =>
180
205
  formals.length === 0
@@ -253,15 +278,10 @@ export const createLevelAnalyzer = (context: LevelContext) => {
253
278
  if (operand.kind !== "Value") return;
254
279
  if (operand.data.level > getMaxLevel(operator, index)) {
255
280
  throw new TlaSyntaxError(
256
- `Level error in applying operator ${operator.name}:\nThe level of argument ${index + 1} exceeds the maximum level allowed by the operator`,
281
+ `Level error in applying operator ${resolveSynonym(operator.name)}:\nThe level of argument ${index + 1} exceeds the maximum level allowed by the operator`,
257
282
  );
258
283
  }
259
284
  });
260
- if (ranges.some((range) => range.level > ACTION_LEVEL)) {
261
- throw new TlaSyntaxError(
262
- `Level error in applying operator ${operator.name}:\nThe level of the range for a bounded variable exceeds the maximum level allowed by the operator`,
263
- );
264
- }
265
285
  const getOperand = (formal: string) => {
266
286
  const index = operator.formals.findIndex((param) => param.name === formal);
267
287
  return index === -1 ? undefined : operands[index];
@@ -448,16 +468,20 @@ export const createLevelAnalyzer = (context: LevelContext) => {
448
468
  operator: OperatorLevels,
449
469
  expressions: Expression[],
450
470
  scope: Scope,
451
- ranges: Expression[] = [],
452
- bound: string[] = [],
471
+ bounds: Bound[] = [],
472
+ bound = getBoundNames(bounds),
453
473
  ) => {
454
- const inner = bindFormals(scope, toFormals(bound));
455
- return applyDefined(
456
- operator,
457
- toOperands(expressions, inner),
458
- ranges.map((range) => analyze(range, scope)),
459
- bound,
460
- );
474
+ const operands = toOperands(expressions, bindFormals(scope, toFormals(bound)));
475
+ const ranges = bounds.map((range) => analyze(range.set, scope));
476
+ const data = applyDefined(operator, operands, ranges, bound);
477
+ const pattern = bounds[ranges.findIndex((range) => range.level > ACTION_LEVEL)]?.pattern;
478
+ if (pattern) {
479
+ const range = pattern.ranges?.[0];
480
+ throw new TlaSyntaxError(
481
+ `Level error in applying operator ${operator.name}:\nThe level of the range for the bounded variable ${range ? formatRange(range) : getPatternNames(pattern)[0]} \nexceeds the maximum level allowed by the operator`,
482
+ );
483
+ }
484
+ return data;
461
485
  };
462
486
 
463
487
  const applyResolved = (resolved: Resolved, operands: Operand[]) =>
@@ -465,11 +489,11 @@ export const createLevelAnalyzer = (context: LevelContext) => {
465
489
  ? applyDeclared(resolved.name, resolved.level, operands)
466
490
  : applyDefined(resolved.levels, operands);
467
491
 
468
- const checkJunction = (operands: Operand[], expression: Expression) => {
492
+ const checkJunction = (operands: Operand[], expression: Expression, name: string) => {
469
493
  const levels = operands.map((operand) => operand.data.level);
470
494
  if (levels.includes(ACTION_LEVEL) && levels.includes(TEMPORAL_LEVEL)) {
471
495
  throw createLevelError(
472
- "Formula has both temporal formula and action as arguments",
496
+ `${name} has both temporal formula and action as arguments`,
473
497
  expression,
474
498
  );
475
499
  }
@@ -483,7 +507,9 @@ export const createLevelAnalyzer = (context: LevelContext) => {
483
507
  expression,
484
508
  );
485
509
  }
486
- if (LOGICAL_OPERATORS.has(expression.operator)) checkJunction(operands, expression);
510
+ if (LOGICAL_OPERATORS.has(expression.operator)) {
511
+ checkJunction(operands, expression, resolveSynonym(expression.operator));
512
+ }
487
513
  };
488
514
 
489
515
  const checkTemporal = (
@@ -549,29 +575,41 @@ export const createLevelAnalyzer = (context: LevelContext) => {
549
575
  case "And":
550
576
  case "Or": {
551
577
  const operands = toOperands(expression.operands, scope);
552
- checkJunction(operands, expression);
553
- return applyDefined(JUNCTION_LEVELS, operands);
578
+ const isAnd = expression.kind === "And";
579
+ checkJunction(
580
+ operands,
581
+ expression,
582
+ expression.isBulleted
583
+ ? `${isAnd ? "Conjunction" : "Disjunction"} list`
584
+ : isAnd
585
+ ? "\\land"
586
+ : "\\lor",
587
+ );
588
+ return applyDefined(isAnd ? AND_LEVELS : OR_LEVELS, operands);
554
589
  }
555
590
  case "Prime":
556
- case "Unchanged":
557
591
  return applyBuiltin(PRIME_LEVELS, [expression.expression], scope);
592
+ case "Unchanged":
593
+ return applyBuiltin(UNCHANGED_LEVELS, [expression.expression], scope);
558
594
  case "Enabled":
559
595
  return applyBuiltin(ENABLED_LEVELS, [expression.expression], scope);
560
596
  case "Always":
561
597
  case "Eventually": {
562
598
  const operand = toOperand(expression.expression, scope);
563
599
  checkTemporal(expression, operand.data.level);
564
- return applyDefined(TEMPORAL_LEVELS, [operand]);
600
+ return applyDefined(expression.kind === "Always" ? ALWAYS_LEVELS : EVENTUALLY_LEVELS, [
601
+ operand,
602
+ ]);
565
603
  }
566
604
  case "If":
567
605
  return applyBuiltin(
568
- JUNCTION_LEVELS,
606
+ IF_LEVELS,
569
607
  [expression.condition, expression.consequent, expression.alternative],
570
608
  scope,
571
609
  );
572
610
  case "Case":
573
611
  return applyBuiltin(
574
- JUNCTION_LEVELS,
612
+ CASE_LEVELS,
575
613
  [
576
614
  ...expression.arms.flatMap((arm) => [arm.condition, arm.body]),
577
615
  ...(expression.other ? [expression.other] : []),
@@ -583,11 +621,10 @@ export const createLevelAnalyzer = (context: LevelContext) => {
583
621
  case "Forall":
584
622
  case "Exists": {
585
623
  const data = applyBuiltin(
586
- JUNCTION_LEVELS,
624
+ expression.kind === "Forall" ? FORALL_LEVELS : EXISTS_LEVELS,
587
625
  [expression.body],
588
626
  scope,
589
- expression.bounds.map((bound) => bound.set),
590
- getBoundNames(expression.bounds),
627
+ expression.bounds,
591
628
  );
592
629
  const actionBound =
593
630
  data.level === TEMPORAL_LEVEL
@@ -603,7 +640,13 @@ export const createLevelAnalyzer = (context: LevelContext) => {
603
640
  }
604
641
  case "UnboundedQuantifier":
605
642
  return applyBuiltin(
606
- expression.isTemporal ? TEMPORAL_QUANTIFIER_LEVELS : JUNCTION_LEVELS,
643
+ expression.isTemporal
644
+ ? expression.quantifier === "Forall"
645
+ ? TEMPORAL_FORALL_LEVELS
646
+ : TEMPORAL_EXISTS_LEVELS
647
+ : expression.quantifier === "Forall"
648
+ ? UNBOUNDED_FORALL_LEVELS
649
+ : UNBOUNDED_EXISTS_LEVELS,
607
650
  [expression.body],
608
651
  scope,
609
652
  [],
@@ -611,79 +654,67 @@ export const createLevelAnalyzer = (context: LevelContext) => {
611
654
  );
612
655
  case "Choose":
613
656
  return applyBuiltin(
614
- CHOOSE_LEVELS,
657
+ expression.set ? BOUNDED_CHOOSE_LEVELS : UNBOUNDED_CHOOSE_LEVELS,
615
658
  [expression.body],
616
659
  scope,
617
- expression.set ? [expression.set] : [],
660
+ expression.set ? [{ pattern: expression.pattern, set: expression.set }] : [],
618
661
  getPatternNames(expression.pattern),
619
662
  );
620
663
  case "SetEnumeration":
664
+ return applyBuiltin(SET_ENUMERATE_LEVELS, expression.elements, scope);
621
665
  case "Tuple":
666
+ return applyBuiltin(TUPLE_LEVELS, expression.elements, scope);
622
667
  case "FunctionSet":
668
+ return applyBuiltin(SET_OF_FCNS_LEVELS, [expression.domain, expression.range], scope);
623
669
  case "Product":
624
- return applyBuiltin(
625
- SET_LEVELS,
626
- expression.kind === "FunctionSet"
627
- ? [expression.domain, expression.range]
628
- : expression.kind === "Product"
629
- ? expression.factors
630
- : expression.elements,
631
- scope,
632
- );
670
+ return applyBuiltin(CARTESIAN_PROD_LEVELS, expression.factors, scope);
633
671
  case "SetFilter":
634
- return applyBuiltin(
635
- SET_LEVELS,
636
- [expression.predicate],
637
- scope,
638
- [expression.bound.set],
639
- getPatternNames(expression.bound.pattern),
640
- );
672
+ return applyBuiltin(SUBSET_OF_LEVELS, [expression.predicate], scope, [expression.bound]);
641
673
  case "SetMap":
642
- return applyBuiltin(
643
- SET_LEVELS,
644
- [expression.expression],
645
- scope,
646
- expression.bounds.map((bound) => bound.set),
647
- getBoundNames(expression.bounds),
648
- );
674
+ return applyBuiltin(SET_OF_ALL_LEVELS, [expression.expression], scope, expression.bounds);
649
675
  case "FunctionConstruction":
650
- return applyBuiltin(
651
- FUNCTION_LEVELS,
652
- [expression.body],
653
- scope,
654
- expression.bounds.map((bound) => bound.set),
655
- getBoundNames(expression.bounds),
656
- );
676
+ return applyBuiltin(FCN_CONSTRUCTOR_LEVELS, [expression.body], scope, expression.bounds);
657
677
  case "Record":
658
678
  return applyBuiltin(
659
- FUNCTION_LEVELS,
679
+ RCD_CONSTRUCTOR_LEVELS,
660
680
  expression.fields.map((field) => field.value),
661
681
  scope,
662
682
  );
663
683
  case "RecordSet":
664
684
  return applyBuiltin(
665
- SET_LEVELS,
685
+ SET_OF_RCDS_LEVELS,
666
686
  expression.fields.map((field) => field.value),
667
687
  scope,
668
688
  );
669
689
  case "Except":
670
- return applyBuiltin(
671
- SET_LEVELS,
672
- [
673
- expression.function,
674
- ...expression.updates.flatMap((update) => [
675
- ...update.path.flatMap((step) => (step.kind === "Index" ? step.args : [])),
676
- update.value,
690
+ return applyDefined(EXCEPT_LEVELS, [
691
+ toOperand(expression.function, scope),
692
+ ...expression.updates.map((update): Operand => ({
693
+ kind: "Value",
694
+ data: applyDefined(PAIR_LEVELS, [
695
+ {
696
+ kind: "Value",
697
+ data: applyDefined(
698
+ SEQ_LEVELS,
699
+ update.path.map((step): Operand =>
700
+ step.kind === "Field"
701
+ ? { kind: "Value", data: createData() }
702
+ : step.args.length === 1
703
+ ? toOperand(step.args[0], scope)
704
+ : { kind: "Value", data: applyBuiltin(TUPLE_LEVELS, step.args, scope) },
705
+ ),
706
+ ),
707
+ },
708
+ toOperand(update.value, scope),
677
709
  ]),
678
- ],
679
- scope,
680
- );
710
+ })),
711
+ ]);
681
712
  case "FunctionApplication":
682
713
  return applyDefined(APPLY_LEVELS, [
683
714
  toOperand(expression.function, scope),
684
715
  expression.args.length === 1
685
716
  ? toOperand(expression.args[0], scope)
686
- : { kind: "Value", data: applyBuiltin(SET_LEVELS, expression.args, scope) },
717
+ : { kind: "Value", data: applyBuiltin(TUPLE_LEVELS, expression.args, scope) },
687
718
  ]);
688
719
  case "Bracket":
689
720
  return createData();
@@ -694,10 +725,18 @@ export const createLevelAnalyzer = (context: LevelContext) => {
694
725
  ]);
695
726
  case "BoxAction":
696
727
  case "AngleAction":
697
- return applyBuiltin(ACTION_LEVELS, [expression.action, expression.subscript], scope);
728
+ return applyBuiltin(
729
+ expression.kind === "BoxAction" ? SQUARE_ACT_LEVELS : ANGLE_ACT_LEVELS,
730
+ [expression.action, expression.subscript],
731
+ scope,
732
+ );
698
733
  case "WeakFairness":
699
734
  case "StrongFairness":
700
- return applyBuiltin(FAIRNESS_LEVELS, [expression.subscript, expression.action], scope);
735
+ return applyBuiltin(
736
+ expression.kind === "WeakFairness" ? WF_LEVELS : SF_LEVELS,
737
+ [expression.subscript, expression.action],
738
+ scope,
739
+ );
701
740
  case "Label":
702
741
  return analyze(expression.body, scope);
703
742
  case "Subexpression":
@@ -957,7 +996,16 @@ export const checkModuleLevels = (
957
996
  })),
958
997
  ...module.assumptions.map((assumption) => ({
959
998
  location: assumption.location,
960
- check: () => analyzer.analyze(assumption.expression, new Map()),
999
+ check: () => {
1000
+ const level = analyzer.analyze(assumption.expression, new Map()).level;
1001
+ const range = assumption.location.range;
1002
+ if (level !== CONSTANT_LEVEL && range) {
1003
+ throw createSemanticError(
1004
+ `Level error: assumptions must be level 0 (Constant), \nbut this one has level ${level}.`,
1005
+ range,
1006
+ );
1007
+ }
1008
+ },
961
1009
  })),
962
1010
  ...module.theorems.map((theorem) => ({
963
1011
  location: theorem.location,
@@ -46,6 +46,7 @@ export interface LivenessChecker {
46
46
  tracing?: Environment,
47
47
  ) => number[] | undefined;
48
48
  storeState: (pending: number, index: number) => void;
49
+ getStateCounts: () => number[];
49
50
  findViolation: () => Lasso | undefined;
50
51
  getViolatedProperties: (path: Value[][], cycleStart: number) => string[];
51
52
  }
@@ -58,14 +59,20 @@ export interface LiveGraph<State> {
58
59
  index: number,
59
60
  state: State,
60
61
  successors: LiveSuccessor<State>[],
62
+ isRerun?: boolean,
61
63
  ) => number[] | undefined;
62
64
  storeState: (pending: number, index: number) => void;
65
+ getStateCounts: () => number[];
63
66
  findViolation: () => Lasso | undefined;
64
67
  }
65
68
 
66
69
  export interface SearchGraph<State> {
67
70
  getFingerprint: (successor: LiveSuccessor<State>) => number;
68
- getSuccessors: (index: number, state: State) => LiveSuccessor<State>[];
71
+ forEachActionSuccessors: (
72
+ index: number,
73
+ state: State,
74
+ onSuccessors: (successors: LiveSuccessor<State>[]) => void,
75
+ ) => void;
69
76
  }
70
77
 
71
78
  export interface LiveEvaluation<State> {
@@ -116,6 +123,7 @@ interface BehaviorGraph<State> {
116
123
  nextSiblings: number[];
117
124
  nodeIds: NodeTable;
118
125
  isDone: boolean[];
126
+ stateCount: number;
119
127
  errorNode: number | undefined;
120
128
  }
121
129
 
@@ -367,8 +375,9 @@ export const createLivenessChecker = (
367
375
  addInitialState: (index, state, replay) =>
368
376
  traceWith(replay, () => graph.addInitialState(index, state)),
369
377
  addState: (index, state, successors, replay) =>
370
- traceWith(replay, () => graph.addState(index, state, successors)),
378
+ traceWith(replay, () => graph.addState(index, state, successors, replay !== undefined)),
371
379
  storeState: graph.storeState,
380
+ getStateCounts: graph.getStateCounts,
372
381
  findViolation: graph.findViolation,
373
382
  getViolatedProperties: (path, cycleStart) => [
374
383
  ...new Set(
@@ -508,6 +517,7 @@ export const createLiveGraph = <State>(
508
517
  nextSiblings: [],
509
518
  nodeIds: { slots: new Int32Array(3 << 10), size: 0, shift: 22 },
510
519
  isDone: [],
520
+ stateCount: 0,
511
521
  errorNode: undefined,
512
522
  }));
513
523
  const checkState = (
@@ -631,8 +641,16 @@ export const createLiveGraph = <State>(
631
641
  writeToPool(behavior.lastNodes, state, [node]);
632
642
  return node;
633
643
  };
634
- const recordNode = (behavior: BehaviorGraph<State>, state: number, tableauNode: number) =>
635
- linkNode(behavior, state, tableauNode, pushNode(behavior, state, tableauNode));
644
+ const hasState = (behavior: BehaviorGraph<State>, state: number) =>
645
+ state < 0
646
+ ? behavior.checks.nodes.some(
647
+ (_checks, tableauNode) => getNodeId(behavior, state, tableauNode) !== undefined,
648
+ )
649
+ : behavior.isDone[state] === true || (behavior.firstNodes.data[state] ?? NO_NODE) !== NO_NODE;
650
+ const recordNode = (behavior: BehaviorGraph<State>, state: number, tableauNode: number) => {
651
+ if (!hasState(behavior, state)) behavior.stateCount++;
652
+ return linkNode(behavior, state, tableauNode, pushNode(behavior, state, tableauNode));
653
+ };
636
654
  // The action results of the edge to each target are at its position in actions.
637
655
  const writeNode = (
638
656
  behavior: BehaviorGraph<State>,
@@ -741,39 +759,57 @@ export const createLiveGraph = <State>(
741
759
  actions.push(0);
742
760
  if (existing === undefined) expandLate(behavior, tableau, state, index, target, row, offset);
743
761
  }
744
- const nextStates = search.getSuccessors(index, state);
745
762
  // The results of the step to the state itself come first, then those of each successor.
746
- const actionResults = new Uint8Array((nextStates.length + 1) * actionCount);
747
- actionResults.set(selfResults);
748
- const edges = createEdgeRows(nextStates.length);
749
- nextStates.forEach((successor, position) => {
750
- const successorRow = createRows(1);
751
- checkAction(
752
- behavior,
753
- index,
754
- state,
755
- row,
756
- offset,
757
- successor.state,
758
- edges,
759
- position * actionIds.size,
760
- actionResults,
761
- (position + 1) * actionCount,
762
- );
763
- const isDone = behavior.isDone[successor.index] === true;
764
- for (const next of tableauNode.successors) {
765
- if (!isConsistent(behavior, next, index, successor.state, successorRow, 0)) continue;
766
- const existing = getNodeId(behavior, successor.index, next);
767
- if (existing !== undefined && successors.includes(existing)) continue;
768
- const target = existing ?? recordNode(behavior, successor.index, next);
769
- successors.push(target);
770
- actions.push(position + 1);
771
- if (existing === undefined && isDone) {
772
- expandLate(behavior, tableau, successor.state, successor.index, target, successorRow, 0);
763
+ const actionBatches = [selfResults];
764
+ let stepCount = 1;
765
+ search.forEachActionSuccessors(index, state, (nextStates) => {
766
+ const edges = createEdgeRows(nextStates.length);
767
+ const results = new Uint8Array(nextStates.length * actionCount);
768
+ actionBatches.push(results);
769
+ for (let position = 0; position < nextStates.length; position++) {
770
+ const successor = nextStates[position];
771
+ const successorRow = createRows(1);
772
+ checkAction(
773
+ behavior,
774
+ index,
775
+ state,
776
+ row,
777
+ offset,
778
+ successor.state,
779
+ edges,
780
+ position * actionIds.size,
781
+ results,
782
+ position * actionCount,
783
+ );
784
+ const isDone = behavior.isDone[successor.index] === true;
785
+ for (const next of tableauNode.successors) {
786
+ if (!isConsistent(behavior, next, index, successor.state, successorRow, 0)) continue;
787
+ const existing = getNodeId(behavior, successor.index, next);
788
+ if (existing !== undefined && successors.includes(existing)) continue;
789
+ const target = existing ?? recordNode(behavior, successor.index, next);
790
+ successors.push(target);
791
+ actions.push(stepCount + position);
792
+ if (existing === undefined && isDone) {
793
+ expandLate(
794
+ behavior,
795
+ tableau,
796
+ successor.state,
797
+ successor.index,
798
+ target,
799
+ successorRow,
800
+ 0,
801
+ );
802
+ }
773
803
  }
774
804
  }
805
+ stepCount += nextStates.length;
775
806
  });
776
807
  if (successors.length > 0) {
808
+ const actionResults = new Uint8Array(stepCount * actionCount);
809
+ for (let batch = 0, resultOffset = 0; batch < actionBatches.length; batch++) {
810
+ actionResults.set(actionBatches[batch], resultOffset);
811
+ resultOffset += actionBatches[batch].length;
812
+ }
777
813
  writeNode(behavior, node, successors, actionResults, actions, stateResults);
778
814
  }
779
815
  };
@@ -799,6 +835,7 @@ export const createLiveGraph = <State>(
799
835
  }
800
836
  }
801
837
  });
838
+ if (!hasState(behavior, index)) behavior.stateCount++;
802
839
  behavior.isDone[index] = true;
803
840
  // TLC expands the nodes recorded before the loop, not the ones the loop records.
804
841
  for (const node of getStateNodes(behavior, index)) {
@@ -848,6 +885,7 @@ export const createLiveGraph = <State>(
848
885
  successors.push(successor.index);
849
886
  actions.push(position);
850
887
  });
888
+ if (!isWritten(behavior, index)) behavior.stateCount++;
851
889
  writeNode(behavior, index, successors, actionResults, actions, stateResults);
852
890
  };
853
891
 
@@ -1126,7 +1164,7 @@ export const createLiveGraph = <State>(
1126
1164
  }
1127
1165
  }
1128
1166
  },
1129
- addState: (index, state, successors) => {
1167
+ addState: (index, state, successors, isRerun) => {
1130
1168
  const set = getSuccessorSet(index, state, successors);
1131
1169
  const rows = createRows(set.length);
1132
1170
  // The set holds the state itself, as a successor of the same index.
@@ -1151,6 +1189,15 @@ export const createLiveGraph = <State>(
1151
1189
  );
1152
1190
  const stateResults = checkState(behavior, index, state, rows, offset);
1153
1191
  const tableau = behavior.solution.tableau;
1192
+ // TLC's rerun for a call stack fails an assertion, without a call stack, on a branch that has every edge of the state.
1193
+ if (
1194
+ isRerun &&
1195
+ (tableau
1196
+ ? getStateNodes(behavior, index).some((node) => behavior.edgeCounts[node] > 0)
1197
+ : set.every((successor) => isWritten(behavior, successor.index)))
1198
+ ) {
1199
+ throw new TlaEvaluationError("The behavior graph holds every edge of the state already.");
1200
+ }
1154
1201
  if (!tableau) {
1155
1202
  addPlainState(behavior, set, actionResults, stateResults, index);
1156
1203
  continue;
@@ -1183,6 +1230,7 @@ export const createLiveGraph = <State>(
1183
1230
  }
1184
1231
  }
1185
1232
  },
1233
+ getStateCounts: () => behaviors.map((behavior) => behavior.stateCount),
1186
1234
  findViolation: () => {
1187
1235
  for (const behavior of behaviors) {
1188
1236
  for (const model of behavior.solution.models) {