tla-ts 0.0.10-dev.09e53c2a6 → 0.0.10-dev.1ebc153bd

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 (214) 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 +2 -1
  7. package/dist/index.d.ts +2 -1
  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 +43 -43
  14. package/dist/prove.js +78 -78
  15. package/dist/run.cjs +33 -35
  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 +38 -38
  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 +46 -28
  26. package/src/check-trace.ts +2 -16
  27. package/src/check.ts +152 -64
  28. package/src/cli/runtime-invariants.ts +20 -56
  29. package/src/cli/tlc-arguments.ts +2 -2
  30. package/src/cli/tlc-output.ts +1 -2
  31. package/src/cli/tlc.ts +13 -8
  32. package/src/cli/xml-exporter.ts +1 -1
  33. package/src/codegen.ts +9 -5
  34. package/src/dependencies.ts +49 -9
  35. package/src/dfid.ts +9 -2
  36. package/src/environment.ts +57 -33
  37. package/src/errors.ts +7 -0
  38. package/src/evaluate.ts +92 -32
  39. package/src/exit-codes.ts +4 -2
  40. package/src/instances.ts +5 -5
  41. package/src/java-overrides.ts +2 -2
  42. package/src/levels.ts +138 -90
  43. package/src/liveness-checker.ts +43 -4
  44. package/src/liveness.ts +1 -1
  45. package/src/obligations/index.ts +1 -1
  46. package/src/obligations/normalize.ts +1 -4
  47. package/src/obligations/printer.ts +5 -5
  48. package/src/parallel-worker.ts +8 -2
  49. package/src/parallel.ts +5 -0
  50. package/src/parser.ts +106 -144
  51. package/src/prover/isabelle/isar/attrib.ts +4 -4
  52. package/src/prover/isabelle/isar/rule-cases.ts +8 -6
  53. package/src/prover/isabelle/provers/clasimp.ts +1 -1
  54. package/src/prover/isabelle/provers/hypsubst.ts +2 -2
  55. package/src/prover/isabelle/pure/rewriter.ts +3 -3
  56. package/src/prover/isabelle/pure/term.ts +3 -3
  57. package/src/prover/prep/md5.ts +26 -29
  58. package/src/prover/smt/rewrite.ts +2 -7
  59. package/src/prover/smt/simplify.ts +1 -1
  60. package/src/prover/smt/solver/asserted-formulas.ts +66 -1
  61. package/src/prover/smt/solver/ast-lt.ts +1 -1
  62. package/src/prover/smt/solver/ast.ts +58 -11
  63. package/src/prover/smt/solver/blast-term-ite.ts +47 -0
  64. package/src/prover/smt/solver/bound-simplifier.ts +2 -3
  65. package/src/prover/smt/solver/bv-decl-plugin.ts +13 -10
  66. package/src/prover/smt/solver/bv-rewriter.ts +1 -1
  67. package/src/prover/smt/solver/card2bv.ts +3 -5
  68. package/src/prover/smt/solver/cofactor-elim-term-ite.ts +2 -3
  69. package/src/prover/smt/solver/context.ts +24 -3
  70. package/src/prover/smt/solver/ctx-simplify.ts +1 -2
  71. package/src/prover/smt/solver/datatype-decl-plugin.ts +15 -7
  72. package/src/prover/smt/solver/dependent-expr-state.ts +9 -4
  73. package/src/prover/smt/solver/diff-neq.ts +1 -2
  74. package/src/prover/smt/solver/elim-term-ite-tactic.ts +48 -0
  75. package/src/prover/smt/solver/elim-uncnstr.ts +4 -7
  76. package/src/prover/smt/solver/euf/arith-internalize.ts +1 -1
  77. package/src/prover/smt/solver/euf/array-internalize.ts +1 -1
  78. package/src/prover/smt/solver/euf/bv-internalize.ts +1 -1
  79. package/src/prover/smt/solver/euf/egraph.ts +4 -10
  80. package/src/prover/smt/solver/euf/euf-solver.ts +1 -2
  81. package/src/prover/smt/solver/euf/mam.ts +1 -5
  82. package/src/prover/smt/solver/euf/q-ematch.ts +1 -2
  83. package/src/prover/smt/solver/euf/th-solver.ts +0 -7
  84. package/src/prover/smt/solver/expr2polynomial.ts +204 -79
  85. package/src/prover/smt/solver/factor.ts +36 -14
  86. package/src/prover/smt/solver/fd-solver.ts +2 -0
  87. package/src/prover/smt/solver/fix-dl-var.ts +1 -2
  88. package/src/prover/smt/solver/fpa-rewriter.ts +1 -2
  89. package/src/prover/smt/solver/fpa2bv-converter.ts +3 -1
  90. package/src/prover/smt/solver/fpa2bv-rewriter.ts +1 -0
  91. package/src/prover/smt/solver/goal.ts +6 -3
  92. package/src/prover/smt/solver/goal2nlsat.ts +57 -30
  93. package/src/prover/smt/solver/hashtable.ts +4 -0
  94. package/src/prover/smt/solver/logic-tactics.ts +9 -2
  95. package/src/prover/smt/solver/lp/containers.ts +7 -1
  96. package/src/prover/smt/solver/lp/cross-nested.ts +1 -3
  97. package/src/prover/smt/solver/lp/lp-settings.ts +1 -1
  98. package/src/prover/smt/solver/lp/nex-creator.ts +3 -2
  99. package/src/prover/smt/solver/lp/nex.ts +2 -1
  100. package/src/prover/smt/solver/lp/nla-core.ts +1 -1
  101. package/src/prover/smt/solver/lp/nla-grobner.ts +158 -80
  102. package/src/prover/smt/solver/lp/nra-solver.ts +45 -39
  103. package/src/prover/smt/solver/lp/pdd-interval.ts +6 -2
  104. package/src/prover/smt/solver/lp/pdd-simplifier.ts +60 -20
  105. package/src/prover/smt/solver/lp/pdd-solver.ts +72 -39
  106. package/src/prover/smt/solver/lp/pdd.ts +725 -290
  107. package/src/prover/smt/solver/lp/union-find.ts +1 -1
  108. package/src/prover/smt/solver/mam-compiler.ts +1 -1
  109. package/src/prover/smt/solver/model-based-opt.ts +1 -1
  110. package/src/prover/smt/solver/model-generator.ts +3 -1
  111. package/src/prover/smt/solver/mpf.ts +2 -4
  112. package/src/prover/smt/solver/mus.ts +2 -3
  113. package/src/prover/smt/solver/muz/dl-context.ts +10 -4
  114. package/src/prover/smt/solver/muz/dl-mk-slice.ts +3 -3
  115. package/src/prover/smt/solver/muz/dl-rule.ts +2 -2
  116. package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +1 -1
  117. package/src/prover/smt/solver/muz/horn-tactic.ts +1 -1
  118. package/src/prover/smt/solver/muz/spacer-context.ts +2 -4
  119. package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
  120. package/src/prover/smt/solver/nlqsat.ts +1 -1
  121. package/src/prover/smt/solver/nlsat/algebraic.ts +196 -92
  122. package/src/prover/smt/solver/nlsat/atoms.ts +52 -33
  123. package/src/prover/smt/solver/nlsat/explain.ts +375 -217
  124. package/src/prover/smt/solver/nlsat/levelwise.ts +460 -240
  125. package/src/prover/smt/solver/nlsat/polynomial.ts +2366 -681
  126. package/src/prover/smt/solver/nlsat/solver.ts +74 -64
  127. package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -17
  128. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -4
  129. package/src/prover/smt/solver/nlsat/upolynomial.ts +41 -18
  130. package/src/prover/smt/solver/nlsat-tactic.ts +1 -1
  131. package/src/prover/smt/solver/nnf.ts +6 -2
  132. package/src/prover/smt/solver/opt-context.ts +9 -3
  133. package/src/prover/smt/solver/opt-nlsat.ts +29 -18
  134. package/src/prover/smt/solver/opt-preprocess.ts +1 -1
  135. package/src/prover/smt/solver/opt-solver.ts +6 -3
  136. package/src/prover/smt/solver/optsmt.ts +1 -1
  137. package/src/prover/smt/solver/pb-rewriter.ts +1 -4
  138. package/src/prover/smt/solver/poly-rewriter.ts +74 -18
  139. package/src/prover/smt/solver/probes.ts +88 -23
  140. package/src/prover/smt/solver/proto-model.ts +4 -6
  141. package/src/prover/smt/solver/qe-arith-plugin.ts +2 -4
  142. package/src/prover/smt/solver/qe-lite.ts +2 -2
  143. package/src/prover/smt/solver/qe.ts +3 -2
  144. package/src/prover/smt/solver/quantifier-manager.ts +14 -9
  145. package/src/prover/smt/solver/recfun-decl-plugin.ts +2 -1
  146. package/src/prover/smt/solver/rlimit.ts +4 -0
  147. package/src/prover/smt/solver/sat/config.ts +1 -1
  148. package/src/prover/smt/solver/sat/inc-sat-solver.ts +26 -1
  149. package/src/prover/smt/solver/sat/model-converter.ts +1 -1
  150. package/src/prover/smt/solver/sat/pb-solver.ts +1 -1
  151. package/src/prover/smt/solver/sat/sat-tactic.ts +4 -3
  152. package/src/prover/smt/solver/sat/simplifier.ts +1 -1
  153. package/src/prover/smt/solver/sat/solver.ts +25 -47
  154. package/src/prover/smt/solver/seq-axioms.ts +20 -35
  155. package/src/prover/smt/solver/seq-decl-plugin.ts +1 -1
  156. package/src/prover/smt/solver/seq-derive.ts +4 -7
  157. package/src/prover/smt/solver/seq-eq-solver.ts +2 -2
  158. package/src/prover/smt/solver/seq-monadic.ts +7 -5
  159. package/src/prover/smt/solver/seq-re-rewriter.ts +2 -1
  160. package/src/prover/smt/solver/seq-re-util.ts +1 -1
  161. package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
  162. package/src/prover/smt/solver/seq-regex-live.ts +2 -2
  163. package/src/prover/smt/solver/seq-rewriter.ts +31 -29
  164. package/src/prover/smt/solver/seq-skolem.ts +0 -23
  165. package/src/prover/smt/solver/seq-view-witness.ts +4 -4
  166. package/src/prover/smt/solver/smt-kernel.ts +9 -3
  167. package/src/prover/smt/solver/smt-setup.ts +68 -6
  168. package/src/prover/smt/solver/smtlib-parser.ts +558 -220
  169. package/src/prover/smt/solver/smtlib-script.ts +495 -153
  170. package/src/prover/smt/solver/solve-eqs.ts +13 -21
  171. package/src/prover/smt/solver/tactic.ts +219 -130
  172. package/src/prover/smt/solver/theory-bv.ts +2 -2
  173. package/src/prover/smt/solver/theory-lra-final-check.ts +1 -1
  174. package/src/prover/smt/solver/theory-lra-internalize.ts +1 -0
  175. package/src/prover/smt/solver/theory-lra-propagate.ts +6 -4
  176. package/src/prover/smt/solver/theory-lra.ts +0 -1
  177. package/src/prover/smt/solver/theory-pb.ts +24 -7
  178. package/src/prover/smt/solver/theory-seq-solve.ts +1 -1
  179. package/src/prover/smt/solver/theory-seq-state.ts +2 -21
  180. package/src/prover/tlapm/cache.ts +8 -8
  181. package/src/prover/zenon/equality-rules.ts +24 -0
  182. package/src/prover/zenon/expr.ts +21 -0
  183. package/src/prover/zenon/index-table.ts +7 -2
  184. package/src/prover/zenon/isar-case.ts +1 -1
  185. package/src/prover/zenon/isar.ts +2 -2
  186. package/src/prover/zenon/phrase.ts +1 -1
  187. package/src/prover/zenon/rules.ts +2 -1
  188. package/src/resolve.ts +624 -187
  189. package/src/runtime.ts +3 -1
  190. package/src/sany/builtins.ts +10 -10
  191. package/src/sany/generation.ts +2 -13
  192. package/src/sany/generator-definitions.ts +3 -1
  193. package/src/sany/generator-expressions.ts +36 -30
  194. package/src/sany/generator-proofs.ts +5 -3
  195. package/src/sany/generator.ts +2 -1
  196. package/src/sany/lexer.ts +3 -3
  197. package/src/sany/modules.ts +4 -2
  198. package/src/sany/nodes.ts +1 -1
  199. package/src/sany/selectors.ts +11 -6
  200. package/src/sany/xml.ts +2 -3
  201. package/src/search.ts +51 -22
  202. package/src/spec-description.ts +2 -2
  203. package/src/subexpressions.ts +265 -94
  204. package/src/successors.ts +1 -0
  205. package/src/symmetry.ts +1 -1
  206. package/src/tlc/jar-data.ts +10 -0
  207. package/src/tlc/messages.ts +3 -3
  208. package/src/tlc/order.ts +14 -3
  209. package/src/tlc/tlc-operators.ts +3 -1
  210. package/src/tlc/tlcext-operators.ts +18 -5
  211. package/src/tlc/trace-spec.ts +5 -5
  212. package/src/typed-tier.ts +29 -23
  213. package/src/typescript/types.ts +2 -2
  214. package/src/values.ts +46 -27
@@ -184,8 +184,8 @@ const readClassFile = (bytes: Uint8Array) => {
184
184
  getJavaClassName(pool, thrown.readUint16()),
185
185
  )
186
186
  : [];
187
- const modifiers = METHOD_MODIFIERS.filter(([flag]) => (access & flag) !== 0).map(
188
- ([, modifier]) => modifier,
187
+ const modifiers = METHOD_MODIFIERS.filter((entry) => (access & entry[0]) !== 0).map(
188
+ (entry) => entry[1],
189
189
  );
190
190
  const returnType = getTypeNames(descriptor.slice(parametersEnd + 1))[0];
191
191
  const throwsClause = exceptions.length === 0 ? "" : ` throws ${exceptions.join(",")}`;
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,
@@ -45,6 +45,8 @@ export interface LivenessChecker {
45
45
  successors: LiveSuccessor[],
46
46
  tracing?: Environment,
47
47
  ) => number[] | undefined;
48
+ storeState: (pending: number, index: number) => void;
49
+ getStateCounts: () => number[];
48
50
  findViolation: () => Lasso | undefined;
49
51
  getViolatedProperties: (path: Value[][], cycleStart: number) => string[];
50
52
  }
@@ -58,6 +60,8 @@ export interface LiveGraph<State> {
58
60
  state: State,
59
61
  successors: LiveSuccessor<State>[],
60
62
  ) => number[] | undefined;
63
+ storeState: (pending: number, index: number) => void;
64
+ getStateCounts: () => number[];
61
65
  findViolation: () => Lasso | undefined;
62
66
  }
63
67
 
@@ -114,6 +118,7 @@ interface BehaviorGraph<State> {
114
118
  nextSiblings: number[];
115
119
  nodeIds: NodeTable;
116
120
  isDone: boolean[];
121
+ stateCount: number;
117
122
  errorNode: number | undefined;
118
123
  }
119
124
 
@@ -366,6 +371,8 @@ export const createLivenessChecker = (
366
371
  traceWith(replay, () => graph.addInitialState(index, state)),
367
372
  addState: (index, state, successors, replay) =>
368
373
  traceWith(replay, () => graph.addState(index, state, successors)),
374
+ storeState: graph.storeState,
375
+ getStateCounts: graph.getStateCounts,
369
376
  findViolation: graph.findViolation,
370
377
  getViolatedProperties: (path, cycleStart) => [
371
378
  ...new Set(
@@ -505,6 +512,7 @@ export const createLiveGraph = <State>(
505
512
  nextSiblings: [],
506
513
  nodeIds: { slots: new Int32Array(3 << 10), size: 0, shift: 22 },
507
514
  isDone: [],
515
+ stateCount: 0,
508
516
  errorNode: undefined,
509
517
  }));
510
518
  const checkState = (
@@ -600,8 +608,12 @@ export const createLiveGraph = <State>(
600
608
  const slot = getNodeSlot(behavior.nodeIds, state, tableauNode);
601
609
  return slots[slot] === 0 ? undefined : slots[slot + 2];
602
610
  };
603
- const recordNode = (behavior: BehaviorGraph<State>, state: number, tableauNode: number) => {
604
- const node = pushNode(behavior, state, tableauNode);
611
+ const linkNode = (
612
+ behavior: BehaviorGraph<State>,
613
+ state: number,
614
+ tableauNode: number,
615
+ node: number,
616
+ ) => {
605
617
  const table = behavior.nodeIds;
606
618
  if (++table.size * 2 > table.slots.length / 3) {
607
619
  const old = table.slots;
@@ -617,12 +629,23 @@ export const createLiveGraph = <State>(
617
629
  }
618
630
  }
619
631
  table.slots.set([state + 1, tableauNode, node], getNodeSlot(table, state, tableauNode));
632
+ if (state < 0) return node;
620
633
  const last = behavior.lastNodes.data[state] ?? NO_NODE;
621
634
  if (last === NO_NODE) writeToPool(behavior.firstNodes, state, [node]);
622
635
  else behavior.nextSiblings[last] = node;
623
636
  writeToPool(behavior.lastNodes, state, [node]);
624
637
  return node;
625
638
  };
639
+ const hasState = (behavior: BehaviorGraph<State>, state: number) =>
640
+ state < 0
641
+ ? behavior.checks.nodes.some(
642
+ (_checks, tableauNode) => getNodeId(behavior, state, tableauNode) !== undefined,
643
+ )
644
+ : behavior.isDone[state] === true || (behavior.firstNodes.data[state] ?? NO_NODE) !== NO_NODE;
645
+ const recordNode = (behavior: BehaviorGraph<State>, state: number, tableauNode: number) => {
646
+ if (!hasState(behavior, state)) behavior.stateCount++;
647
+ return linkNode(behavior, state, tableauNode, pushNode(behavior, state, tableauNode));
648
+ };
626
649
  // The action results of the edge to each target are at its position in actions.
627
650
  const writeNode = (
628
651
  behavior: BehaviorGraph<State>,
@@ -753,8 +776,6 @@ export const createLiveGraph = <State>(
753
776
  const isDone = behavior.isDone[successor.index] === true;
754
777
  for (const next of tableauNode.successors) {
755
778
  if (!isConsistent(behavior, next, index, successor.state, successorRow, 0)) continue;
756
- // Deviation from TLC: TLC records the node of a successor the search never stored, which it never expands.
757
- if (successor.index === -1) continue;
758
779
  const existing = getNodeId(behavior, successor.index, next);
759
780
  if (existing !== undefined && successors.includes(existing)) continue;
760
781
  const target = existing ?? recordNode(behavior, successor.index, next);
@@ -791,6 +812,7 @@ export const createLiveGraph = <State>(
791
812
  }
792
813
  }
793
814
  });
815
+ if (!hasState(behavior, index)) behavior.stateCount++;
794
816
  behavior.isDone[index] = true;
795
817
  // TLC expands the nodes recorded before the loop, not the ones the loop records.
796
818
  for (const node of getStateNodes(behavior, index)) {
@@ -840,6 +862,7 @@ export const createLiveGraph = <State>(
840
862
  successors.push(successor.index);
841
863
  actions.push(position);
842
864
  });
865
+ if (!isWritten(behavior, index)) behavior.stateCount++;
843
866
  writeNode(behavior, index, successors, actionResults, actions, stateResults);
844
867
  };
845
868
 
@@ -1160,6 +1183,22 @@ export const createLiveGraph = <State>(
1160
1183
  }
1161
1184
  return undefined;
1162
1185
  },
1186
+ storeState: (pending, index) => {
1187
+ for (const behavior of behaviors) {
1188
+ const tableau = behavior.solution.tableau;
1189
+ if (!tableau) continue;
1190
+ const nodes: number[] = [];
1191
+ for (let tableauNode = 0; tableauNode < tableau.nodes.length; tableauNode++) {
1192
+ const node = getNodeId(behavior, pending, tableauNode);
1193
+ if (node !== undefined) nodes.push(node);
1194
+ }
1195
+ for (const node of nodes.sort((left, right) => left - right)) {
1196
+ behavior.nodeStates[node] = index;
1197
+ linkNode(behavior, index, behavior.nodeTableaux[node], node);
1198
+ }
1199
+ }
1200
+ },
1201
+ getStateCounts: () => behaviors.map((behavior) => behavior.stateCount),
1163
1202
  findViolation: () => {
1164
1203
  for (const behavior of behaviors) {
1165
1204
  for (const model of behavior.solution.models) {
package/src/liveness.ts CHANGED
@@ -636,7 +636,7 @@ export const getInterpretedAtoms = (environment: Environment): LiveAtoms<Value[]
636
636
  },
637
637
  });
638
638
 
639
- export const evaluateLive = <State>(
639
+ const evaluateLive = <State>(
640
640
  expression: LiveExpression,
641
641
  state: State,
642
642
  next: State | undefined,
@@ -179,7 +179,7 @@ const loadMule = (
179
179
 
180
180
  const schedule = (modules: Map<string, Mule>) => {
181
181
  const dependencies = new Map(
182
- [...modules].map(([name, module]) => [name, getDependencies(module).dependencies]),
182
+ [...modules].map((entry) => [entry[0], getDependencies(entry[1]).dependencies]),
183
183
  );
184
184
  const seen = new Set<string>();
185
185
  const order: Mule[] = [];
@@ -351,10 +351,7 @@ const instantiate = (
351
351
  substitutes.set(name, at({ kind: "Opaque", name }, { location }));
352
352
  }
353
353
  const anonymized = new Map(
354
- [...substitutes].map(([name, expression]) => [
355
- name,
356
- pipeline.anonymizer.expr(instanceScope, expression),
357
- ]),
354
+ [...substitutes].map((entry) => [entry[0], pipeline.anonymizer.expr(instanceScope, entry[1])]),
358
355
  );
359
356
  const body = substituteUnits(
360
357
  shift((instanceScope?.size ?? 0) - (module.depth ?? 0)),
@@ -430,26 +430,26 @@ const createPrinter = (hyps: Hyp[] = [], options: PrinterOptions = {}) => {
430
430
  );
431
431
  case "Choose": {
432
432
  const domainDoc = expression.domain && printExpr(expression.domain);
433
- return withNames(context, [expression.name], ([name]) =>
433
+ return withNames(context, [expression.name], (names) =>
434
434
  createBig(
435
435
  domainDoc
436
436
  ? format(
437
437
  "@[<b2>CHOOSE @[<b2>%s \\in@ %a@] :@ %a@]",
438
- name,
438
+ names[0],
439
439
  domainDoc,
440
440
  printExpr(expression.body),
441
441
  )
442
- : format("@[<b2>CHOOSE %s :@ %a@]", name, printExpr(expression.body)),
442
+ : format("@[<b2>CHOOSE %s :@ %a@]", names[0], printExpr(expression.body)),
443
443
  ),
444
444
  );
445
445
  }
446
446
  case "SetSt": {
447
447
  const domainDoc = printExpr(expression.domain);
448
- return withNames(context, [expression.name], ([name]) =>
448
+ return withNames(context, [expression.name], (names) =>
449
449
  createAtom(
450
450
  format(
451
451
  "@[<b3>{@[<b2>%s \\in@ %a@] :@ %a}@]",
452
- name,
452
+ names[0],
453
453
  domainDoc,
454
454
  printExpr(expression.body),
455
455
  ),
@@ -41,8 +41,14 @@ const runWorker = (start: StartMessage, parent: Port) => {
41
41
  );
42
42
  const specification = created.specification;
43
43
  const environment = specification.environment;
44
- const search = createSearch(start.config, environment, specification.variableLocations, () =>
45
- created.order.getDeclarationOrder("variable"),
44
+ const search = createSearch(
45
+ start.config,
46
+ environment,
47
+ specification.variableLocations,
48
+ () => created.order.getDeclarationOrder("variable"),
49
+ undefined,
50
+ [],
51
+ specification.runtimeInvariants,
46
52
  );
47
53
  const nextAction = search?.spec.next;
48
54
  if (!search || nextAction === undefined)
package/src/parallel.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  } from "./check";
9
9
  import { parseConfig, type ModelConfig } from "./config";
10
10
  import { TlaEvaluationError } from "./errors";
11
+ import type { RuntimeInvariant } from "./environment";
11
12
  import { isImpure } from "./evaluate";
12
13
  import {
13
14
  createSharedFingerprints,
@@ -43,6 +44,7 @@ export interface StartMessage extends Pick<
43
44
  > {
44
45
  type: "start";
45
46
  config: ModelConfig;
47
+ runtimeInvariants: RuntimeInvariant[];
46
48
  modules: [string, string | undefined][];
47
49
  classes: [string, Uint8Array | undefined][];
48
50
  index: number;
@@ -146,6 +148,8 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
146
148
  specification.variableLocations,
147
149
  () => created.order.getDeclarationOrder("variable"),
148
150
  report,
151
+ [],
152
+ specification.runtimeInvariants,
149
153
  );
150
154
  if (findAssumptionViolation(specification.assumptions, environment)) return fallBack();
151
155
  if (
@@ -273,6 +277,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
273
277
  type: "start",
274
278
  source: options.source,
275
279
  config,
280
+ runtimeInvariants: specification.runtimeInvariants,
276
281
  modules: [...modules],
277
282
  classes: [...classes],
278
283
  index,