tla-ts 0.0.8-dev.d9bffda → 0.0.9-dev.0493be549

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 (390) hide show
  1. package/README.md +30 -0
  2. package/dist/compile.cjs +23 -0
  3. package/dist/compile.js +23 -0
  4. package/dist/deciders.cjs +28 -28
  5. package/dist/deciders.js +43 -43
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +80 -10
  8. package/dist/index.d.ts +80 -10
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +116 -36
  15. package/dist/prove.js +116 -36
  16. package/dist/run.cjs +143 -31
  17. package/dist/run.js +143 -31
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +128 -103
  21. package/dist/transfer.js +128 -103
  22. package/dist/worker.cjs +7 -7
  23. package/dist/worker.js +7 -7
  24. package/package.json +3 -1
  25. package/src/ast.ts +7 -21
  26. package/src/bags.ts +99 -99
  27. package/src/builtins.ts +44 -75
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +605 -311
  30. package/src/cli/options.ts +12 -6
  31. package/src/cli/run.ts +2 -2
  32. package/src/cli/runtime-invariants.ts +135 -0
  33. package/src/cli/shared.ts +20 -9
  34. package/src/cli/tlapm.ts +0 -12
  35. package/src/cli/tlc-arguments.ts +646 -0
  36. package/src/cli/tlc-usage.ts +362 -0
  37. package/src/cli/tlc.ts +545 -218
  38. package/src/cli/typescript.ts +23 -0
  39. package/src/cli/xml-exporter.ts +4 -16
  40. package/src/cli.ts +0 -1
  41. package/src/codegen.ts +191 -64
  42. package/src/config.ts +140 -109
  43. package/src/coverage.ts +837 -0
  44. package/src/dependencies.ts +6 -40
  45. package/src/dfid.ts +618 -0
  46. package/src/environment.ts +240 -118
  47. package/src/errors.ts +70 -55
  48. package/src/evaluate.ts +632 -298
  49. package/src/exit-codes.ts +37 -3
  50. package/src/fingerprints.ts +10 -10
  51. package/src/index.ts +3 -0
  52. package/src/instances.ts +79 -11
  53. package/src/java-overrides.ts +2 -12
  54. package/src/json-reader.ts +456 -0
  55. package/src/json.ts +262 -139
  56. package/src/levels.ts +2 -3
  57. package/src/lexer.ts +17 -26
  58. package/src/liveness-checker.ts +10 -18
  59. package/src/liveness.ts +121 -49
  60. package/src/obligations/action.ts +4 -28
  61. package/src/obligations/anonymize.ts +84 -80
  62. package/src/obligations/equality.ts +1 -1
  63. package/src/obligations/expression.ts +2 -19
  64. package/src/obligations/format.ts +1 -9
  65. package/src/obligations/generate.ts +1 -11
  66. package/src/obligations/index.ts +0 -11
  67. package/src/obligations/levels.ts +4 -8
  68. package/src/obligations/module.ts +1 -15
  69. package/src/obligations/normalize.ts +5 -24
  70. package/src/obligations/operators.ts +1 -2
  71. package/src/obligations/pragma.ts +1 -10
  72. package/src/obligations/printer.ts +47 -46
  73. package/src/obligations/proof.ts +1 -5
  74. package/src/obligations/regroup.ts +1 -4
  75. package/src/obligations/simplify.ts +3 -14
  76. package/src/obligations/source.ts +1 -21
  77. package/src/obligations/subexpression.ts +5 -11
  78. package/src/obligations/substitution.ts +1 -3
  79. package/src/obligations/temporal.ts +8 -14
  80. package/src/obligations/tuples.ts +3 -9
  81. package/src/parallel-worker.ts +31 -38
  82. package/src/parallel.ts +41 -17
  83. package/src/parser.ts +436 -90
  84. package/src/pcal/ast.ts +7 -28
  85. package/src/pcal/parse.ts +11 -39
  86. package/src/pcal/tokenize.ts +4 -20
  87. package/src/pcal/translate.ts +10 -42
  88. package/src/pcal/validate.ts +3 -21
  89. package/src/pretty-print.ts +1 -2
  90. package/src/prover/decide-pool.ts +5 -10
  91. package/src/prover/deciders.ts +0 -4
  92. package/src/prover/first-order.ts +0 -11
  93. package/src/prover/isabelle/decide.ts +0 -6
  94. package/src/prover/isabelle/encode.ts +11 -23
  95. package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
  96. package/src/prover/isabelle/isar/method.ts +25 -38
  97. package/src/prover/isabelle/isar/proof.ts +1 -10
  98. package/src/prover/isabelle/isar/statement.ts +1 -6
  99. package/src/prover/isabelle/isar/theory.ts +15 -26
  100. package/src/prover/isabelle/isar/type-check.ts +11 -25
  101. package/src/prover/isabelle/provers/blast/blast.ts +10 -41
  102. package/src/prover/isabelle/provers/blast/branch.ts +1 -32
  103. package/src/prover/isabelle/provers/blast/prove.ts +1 -35
  104. package/src/prover/isabelle/provers/blast/rules.ts +6 -44
  105. package/src/prover/isabelle/provers/blast/state.ts +2 -28
  106. package/src/prover/isabelle/provers/blast/term.ts +9 -36
  107. package/src/prover/isabelle/provers/clasimp.ts +1 -13
  108. package/src/prover/isabelle/provers/classical.ts +14 -42
  109. package/src/prover/isabelle/provers/hypsubst.ts +11 -25
  110. package/src/prover/isabelle/pure/bicompose.ts +16 -13
  111. package/src/prover/isabelle/pure/consts.ts +1 -7
  112. package/src/prover/isabelle/pure/conv.ts +1 -9
  113. package/src/prover/isabelle/pure/drule.ts +24 -40
  114. package/src/prover/isabelle/pure/envir.ts +3 -52
  115. package/src/prover/isabelle/pure/goal.ts +1 -7
  116. package/src/prover/isabelle/pure/interrupt.ts +0 -5
  117. package/src/prover/isabelle/pure/list.ts +0 -3
  118. package/src/prover/isabelle/pure/logic.ts +1 -14
  119. package/src/prover/isabelle/pure/name.ts +2 -9
  120. package/src/prover/isabelle/pure/net.ts +3 -59
  121. package/src/prover/isabelle/pure/object-logic.ts +3 -10
  122. package/src/prover/isabelle/pure/pattern.ts +2 -19
  123. package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
  124. package/src/prover/isabelle/pure/rewriter.ts +26 -58
  125. package/src/prover/isabelle/pure/search.ts +3 -10
  126. package/src/prover/isabelle/pure/seq.ts +1 -10
  127. package/src/prover/isabelle/pure/simplifier.ts +4 -12
  128. package/src/prover/isabelle/pure/table.ts +1 -31
  129. package/src/prover/isabelle/pure/tactic.ts +12 -22
  130. package/src/prover/isabelle/pure/tactical.ts +6 -12
  131. package/src/prover/isabelle/pure/term-ord.ts +2 -6
  132. package/src/prover/isabelle/pure/term.ts +2 -43
  133. package/src/prover/isabelle/pure/thm.ts +13 -36
  134. package/src/prover/isabelle/pure/type.ts +2 -15
  135. package/src/prover/isabelle/pure/unify.ts +20 -30
  136. package/src/prover/isabelle/pure/variable.ts +3 -7
  137. package/src/prover/isabelle/tla/classical-setup.ts +9 -19
  138. package/src/prover/isabelle/tla/context.ts +8 -16
  139. package/src/prover/isabelle/tla/logic.ts +4 -11
  140. package/src/prover/isabelle/tla/simpdata.ts +46 -34
  141. package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
  142. package/src/prover/ocaml.ts +0 -6
  143. package/src/prover/prep/action.ts +4 -36
  144. package/src/prover/prep/enabled-axioms.ts +12 -19
  145. package/src/prover/prep/fingerprint.ts +0 -16
  146. package/src/prover/prep/level-comparison.ts +8 -12
  147. package/src/prover/prep/md5.ts +0 -2
  148. package/src/prover/prep/methods.ts +9 -36
  149. package/src/prover/prep/normalize.ts +4 -28
  150. package/src/prover/prove-worker.ts +0 -2
  151. package/src/prover/prove.ts +0 -36
  152. package/src/prover/ptl/decide.ts +7 -12
  153. package/src/prover/ptl/encode.ts +14 -36
  154. package/src/prover/ptl/sat.ts +24 -32
  155. package/src/prover/ptl/tableau.ts +12 -26
  156. package/src/prover/smt/axioms.ts +0 -7
  157. package/src/prover/smt/context.ts +19 -26
  158. package/src/prover/smt/data.ts +51 -54
  159. package/src/prover/smt/encode.ts +14 -35
  160. package/src/prover/smt/extensionality.ts +0 -10
  161. package/src/prover/smt/flatten.ts +3 -22
  162. package/src/prover/smt/format.ts +5 -10
  163. package/src/prover/smt/instances.ts +0 -10
  164. package/src/prover/smt/rewrite.ts +66 -101
  165. package/src/prover/smt/solver/act-cache.ts +0 -15
  166. package/src/prover/smt/solver/arith-rewriter.ts +3 -48
  167. package/src/prover/smt/solver/array.ts +1 -3
  168. package/src/prover/smt/solver/asserted-formulas.ts +1 -43
  169. package/src/prover/smt/solver/ast-lt.ts +1 -11
  170. package/src/prover/smt/solver/ast-util.ts +1 -6
  171. package/src/prover/smt/solver/ast.ts +1 -143
  172. package/src/prover/smt/solver/auf-solver.ts +6 -39
  173. package/src/prover/smt/solver/case-split-queue.ts +1 -9
  174. package/src/prover/smt/solver/cg-table.ts +1 -18
  175. package/src/prover/smt/solver/clause.ts +1 -27
  176. package/src/prover/smt/solver/conflict-resolution.ts +0 -9
  177. package/src/prover/smt/solver/context.ts +4 -61
  178. package/src/prover/smt/solver/ctx-simplify.ts +14 -41
  179. package/src/prover/smt/solver/der.ts +2 -21
  180. package/src/prover/smt/solver/dyn-ack.ts +1 -11
  181. package/src/prover/smt/solver/e-matching.ts +3 -34
  182. package/src/prover/smt/solver/enode.ts +1 -21
  183. package/src/prover/smt/solver/expr-ref.ts +1 -5
  184. package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
  185. package/src/prover/smt/solver/fingerprints.ts +1 -12
  186. package/src/prover/smt/solver/flat-literals.ts +1 -9
  187. package/src/prover/smt/solver/goal.ts +2 -14
  188. package/src/prover/smt/solver/hash.ts +0 -8
  189. package/src/prover/smt/solver/hashtable.ts +1 -12
  190. package/src/prover/smt/solver/internalizer.ts +6 -98
  191. package/src/prover/smt/solver/lbool.ts +1 -2
  192. package/src/prover/smt/solver/literal.ts +0 -3
  193. package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
  194. package/src/prover/smt/solver/lp/constraints.ts +2 -8
  195. package/src/prover/smt/solver/lp/containers.ts +12 -30
  196. package/src/prover/smt/solver/lp/core-solver.ts +10 -31
  197. package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
  198. package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
  199. package/src/prover/smt/solver/lp/dependency.ts +1 -4
  200. package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
  201. package/src/prover/smt/solver/lp/explanation.ts +1 -6
  202. package/src/prover/smt/solver/lp/gomory.ts +9 -22
  203. package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
  204. package/src/prover/smt/solver/lp/hnf.ts +11 -26
  205. package/src/prover/smt/solver/lp/int-cube.ts +15 -36
  206. package/src/prover/smt/solver/lp/int-solver.ts +4 -34
  207. package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
  208. package/src/prover/smt/solver/lp/lar-term.ts +1 -5
  209. package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
  210. package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
  211. package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
  212. package/src/prover/smt/solver/lp/nex.ts +1 -6
  213. package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
  214. package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
  215. package/src/prover/smt/solver/lp/nla-core.ts +35 -130
  216. package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
  217. package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
  218. package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
  219. package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
  220. package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
  221. package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
  222. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
  223. package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
  224. package/src/prover/smt/solver/lp/nla-order.ts +2 -13
  225. package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
  226. package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
  227. package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
  228. package/src/prover/smt/solver/lp/nla-types.ts +1 -11
  229. package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
  230. package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
  231. package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
  232. package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
  233. package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
  234. package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
  235. package/src/prover/smt/solver/lp/pdd.ts +7 -70
  236. package/src/prover/smt/solver/lp/random-updater.ts +1 -8
  237. package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
  238. package/src/prover/smt/solver/lp/union-find.ts +1 -6
  239. package/src/prover/smt/solver/mam-compiler.ts +14 -56
  240. package/src/prover/smt/solver/mam-interpreter.ts +1 -21
  241. package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
  242. package/src/prover/smt/solver/model-checker.ts +2 -36
  243. package/src/prover/smt/solver/model-evaluator.ts +3 -29
  244. package/src/prover/smt/solver/model-finder.ts +3 -15
  245. package/src/prover/smt/solver/model-generator.ts +1 -12
  246. package/src/prover/smt/solver/model-macro-solver.ts +12 -69
  247. package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
  248. package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
  249. package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
  250. package/src/prover/smt/solver/nlsat/explain.ts +3 -47
  251. package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
  252. package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
  253. package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
  254. package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
  255. package/src/prover/smt/solver/nlsat/solver.ts +7 -67
  256. package/src/prover/smt/solver/nlsat/types.ts +1 -8
  257. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
  258. package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
  259. package/src/prover/smt/solver/nnf.ts +3 -38
  260. package/src/prover/smt/solver/pattern-inference.ts +2 -15
  261. package/src/prover/smt/solver/poly-rewriter.ts +3 -23
  262. package/src/prover/smt/solver/propagate-values.ts +1 -10
  263. package/src/prover/smt/solver/proto-model.ts +3 -48
  264. package/src/prover/smt/solver/pull-quant.ts +1 -12
  265. package/src/prover/smt/solver/qe-lite-der.ts +1 -29
  266. package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
  267. package/src/prover/smt/solver/qe-lite.ts +3 -33
  268. package/src/prover/smt/solver/qi-queue.ts +1 -16
  269. package/src/prover/smt/solver/quant-tactics.ts +5 -22
  270. package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
  271. package/src/prover/smt/solver/quantifier-manager.ts +1 -8
  272. package/src/prover/smt/solver/random-gen.ts +1 -2
  273. package/src/prover/smt/solver/rational.ts +1 -8
  274. package/src/prover/smt/solver/ref-vector.ts +1 -6
  275. package/src/prover/smt/solver/relevancy.ts +2 -15
  276. package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
  277. package/src/prover/smt/solver/rewriter.ts +3 -85
  278. package/src/prover/smt/solver/rlimit.ts +2 -20
  279. package/src/prover/smt/solver/smtlib-parser.ts +2 -37
  280. package/src/prover/smt/solver/solver.ts +23 -34
  281. package/src/prover/smt/solver/sort.ts +1 -5
  282. package/src/prover/smt/solver/sticky-generations.ts +0 -5
  283. package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
  284. package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
  285. package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
  286. package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
  287. package/src/prover/smt/solver/theory-lra-model.ts +4 -19
  288. package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
  289. package/src/prover/smt/solver/theory-lra-state.ts +3 -8
  290. package/src/prover/smt/solver/theory-lra.ts +1 -8
  291. package/src/prover/smt/solver/var-subst.ts +2 -26
  292. package/src/prover/smt/table.ts +0 -8
  293. package/src/prover/tlapm/cache.ts +20 -25
  294. package/src/prover/tlapm/ocaml-marshal.ts +19 -21
  295. package/src/prover/tlapm/tlapm.ts +12 -17
  296. package/src/prover/verdict.ts +0 -2
  297. package/src/prover/zenon/check/check.ts +0 -9
  298. package/src/prover/zenon/check/definitions.ts +5 -15
  299. package/src/prover/zenon/check/equality.ts +0 -8
  300. package/src/prover/zenon/check/functions.ts +0 -4
  301. package/src/prover/zenon/check/keys.ts +0 -7
  302. package/src/prover/zenon/check/propositional.ts +0 -3
  303. package/src/prover/zenon/check/records.ts +0 -5
  304. package/src/prover/zenon/check/relations.ts +0 -13
  305. package/src/prover/zenon/check/rewrites.ts +0 -6
  306. package/src/prover/zenon/check/sets.ts +0 -3
  307. package/src/prover/zenon/check/terms.ts +0 -17
  308. package/src/prover/zenon/check/tla.ts +0 -6
  309. package/src/prover/zenon/decide.ts +0 -12
  310. package/src/prover/zenon/encode.ts +1 -8
  311. package/src/prover/zenon/eqrel.ts +0 -13
  312. package/src/prover/zenon/equality-rules.ts +0 -4
  313. package/src/prover/zenon/expr.ts +1 -26
  314. package/src/prover/zenon/index-table.ts +17 -38
  315. package/src/prover/zenon/isar-case.ts +9 -19
  316. package/src/prover/zenon/isar.ts +1 -29
  317. package/src/prover/zenon/limits.ts +0 -4
  318. package/src/prover/zenon/llproof.ts +0 -9
  319. package/src/prover/zenon/mltoll.ts +54 -76
  320. package/src/prover/zenon/node.ts +1 -11
  321. package/src/prover/zenon/ocaml.ts +1 -17
  322. package/src/prover/zenon/parse.ts +2 -7
  323. package/src/prover/zenon/phrase.ts +1 -11
  324. package/src/prover/zenon/proof.ts +0 -9
  325. package/src/prover/zenon/propositional-rules.ts +0 -5
  326. package/src/prover/zenon/rules.ts +2 -6
  327. package/src/prover/zenon/search.ts +1 -17
  328. package/src/prover/zenon/tla/functions.ts +57 -29
  329. package/src/prover/zenon/tla/llproof.ts +63 -70
  330. package/src/prover/zenon/tla/records.ts +56 -27
  331. package/src/prover/zenon/tla/rewrites.ts +12 -19
  332. package/src/prover/zenon/tla/sets.ts +68 -39
  333. package/src/prover/zenon/tla/terms.ts +0 -6
  334. package/src/prover/zenon/tla/tla.ts +59 -58
  335. package/src/randomization.ts +84 -35
  336. package/src/resolve.ts +18 -60
  337. package/src/runtime.ts +11 -4
  338. package/src/sany/builtins.ts +3 -4
  339. package/src/sany/generator.ts +128 -176
  340. package/src/sany/levels.ts +6 -30
  341. package/src/sany/lexer.ts +7 -23
  342. package/src/sany/linter.ts +31 -29
  343. package/src/sany/modules.ts +1 -5
  344. package/src/sany/nodes.ts +0 -31
  345. package/src/sany/parse-error.ts +39 -117
  346. package/src/sany/report.ts +29 -63
  347. package/src/sany/selectors.ts +15 -39
  348. package/src/sany/source.ts +1 -17
  349. package/src/sany/xml.ts +13 -63
  350. package/src/search.ts +533 -174
  351. package/src/simulate.ts +694 -0
  352. package/src/spec-description.ts +166 -48
  353. package/src/standard-definitions.ts +2 -3
  354. package/src/standard-modules.ts +264 -68
  355. package/src/state-graph.ts +51 -18
  356. package/src/subexpressions.ts +31 -5
  357. package/src/substitution-levels.ts +2 -3
  358. package/src/successors.ts +267 -77
  359. package/src/symmetry.ts +31 -8
  360. package/src/tableau.ts +27 -24
  361. package/src/tlc/fingerprint.ts +183 -61
  362. package/src/tlc/jar-data.ts +113 -6
  363. package/src/tlc/messages.ts +122 -37
  364. package/src/tlc/order.ts +33 -38
  365. package/src/tlc/random.ts +16 -16
  366. package/src/tlc/replay.ts +563 -211
  367. package/src/tlc/summary.ts +2 -4
  368. package/src/tlc/tlc-operators.ts +81 -36
  369. package/src/tlc/tlcext-operators.ts +138 -117
  370. package/src/tlc/trace-spec.ts +273 -0
  371. package/src/tlc/value-stream.ts +143 -0
  372. package/src/tlc/version.ts +2 -4
  373. package/src/transfer.ts +22 -25
  374. package/src/typescript/actions.ts +481 -0
  375. package/src/typescript/collections.ts +600 -0
  376. package/src/typescript/compile.ts +65 -0
  377. package/src/typescript/context.ts +94 -0
  378. package/src/typescript/emit.ts +121 -0
  379. package/src/typescript/expressions.ts +496 -0
  380. package/src/typescript/formula.ts +152 -0
  381. package/src/typescript/functions.ts +284 -0
  382. package/src/typescript/model.ts +163 -0
  383. package/src/typescript/names.ts +114 -0
  384. package/src/typescript/program.ts +48 -0
  385. package/src/typescript/properties.ts +139 -0
  386. package/src/typescript/scope.ts +112 -0
  387. package/src/typescript/steps.ts +165 -0
  388. package/src/typescript/types.ts +171 -0
  389. package/src/values.ts +832 -255
  390. package/src/worker.ts +7 -8
package/src/check.ts CHANGED
@@ -1,11 +1,19 @@
1
1
  import type { Expression } from "./ast";
2
2
  import { parseConfig, type ModelConfig } from "./config";
3
+ import {
4
+ addCoverageRelation,
5
+ buildCoverage,
6
+ countCoverageVariables,
7
+ createCoverage,
8
+ getCoverageLabel,
9
+ getCoverageReport,
10
+ type CoverageReport,
11
+ } from "./coverage";
3
12
  import { createEnvironment } from "./environment";
4
13
  import {
5
14
  createStackOverflowError,
6
15
  getErrorExitCode,
7
16
  isStackOverflow,
8
- TlaConfigError,
9
17
  TlaEvaluationError,
10
18
  TlaIllegalStateError,
11
19
  TlaIncompleteSuccessorError,
@@ -16,7 +24,7 @@ import {
16
24
  } from "./errors";
17
25
  import {
18
26
  createTracingEnvironment,
19
- evaluate,
27
+ describeRange,
20
28
  formatRange,
21
29
  getDefinition,
22
30
  isImpure,
@@ -24,7 +32,13 @@ import {
24
32
  type Environment,
25
33
  type FingerprintFailure,
26
34
  } from "./evaluate";
27
- import { EXIT_STATUS, getExitCode, setExitCode, withLivenessExitCode } from "./exit-codes";
35
+ import {
36
+ EXIT_STATUS,
37
+ getExitCode,
38
+ getMessageExitStatus,
39
+ setExitCode,
40
+ withLivenessExitCode,
41
+ } from "./exit-codes";
28
42
  import type { JavaOverride } from "./java-overrides";
29
43
  import {
30
44
  createLivenessChecker,
@@ -33,11 +47,10 @@ import {
33
47
  type LiveSuccessor,
34
48
  } from "./liveness-checker";
35
49
  import {
36
- createIdentifier,
50
+ createMissingOperatorError,
37
51
  createSearch,
52
+ getIncompleteSuccessorMessage,
38
53
  findAssumptionViolation,
39
- getConfigDefinition,
40
- getContext,
41
54
  reportInitialStatesProgress,
42
55
  reportStartup,
43
56
  withNextStateExitCode,
@@ -62,10 +75,10 @@ import {
62
75
  forEachSuccessor,
63
76
  getInitialStates,
64
77
  getSuccessors,
78
+ hasIncompleteSuccessor,
65
79
  type Successor,
66
80
  } from "./successors";
67
81
  import {
68
- formatNestedMessage,
69
82
  getCodedMessage,
70
83
  getFailureMessage,
71
84
  getWrappedException,
@@ -75,8 +88,17 @@ import {
75
88
  withUnexpectedException,
76
89
  type FailureMessage,
77
90
  } from "./tlc/messages";
91
+ import { createTautologyError } from "./liveness";
92
+ import { KEY_SEPARATOR } from "./resolve";
93
+ import { setFingerprintPolynomial } from "./tlc/fingerprint";
94
+ import { writeTraceSpec } from "./tlc/trace-spec";
78
95
  import { createTlcOrder } from "./tlc/order";
79
- import { replayInitialStates, replaySuccessors } from "./tlc/replay";
96
+ import {
97
+ getPrimedRanges,
98
+ replayInitialStates,
99
+ replaySuccessors,
100
+ walkSuccessors,
101
+ } from "./tlc/replay";
80
102
  import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc/summary";
81
103
  import { createActionRecord, createCounterExample } from "./tlc/tlcext-operators";
82
104
  import type { TlcVersion } from "./tlc/version";
@@ -87,13 +109,12 @@ import {
87
109
  formatState,
88
110
  getFingerprintError,
89
111
  getHeldValues,
112
+ getModelValues,
90
113
  getValueHash,
91
- isFunctionValue,
92
114
  isSameValue,
93
115
  markFingerprinted,
94
116
  setStringOrder,
95
- setValueVersion,
96
- toFiniteFunction,
117
+ setValueOptions,
97
118
  type Value,
98
119
  } from "./values";
99
120
 
@@ -105,34 +126,57 @@ export interface CheckOptions {
105
126
  onPrint?: (text: string) => void;
106
127
  onPause?: () => void;
107
128
  readFile?: (path: string) => string | undefined;
108
- writeFile?: (path: string, content: string) => void;
129
+ writeFile?: (path: string, content: string | Uint8Array) => void;
130
+ makeDirectory?: (path: string) => void;
109
131
  seed?: bigint;
110
132
  workers?: number;
111
- // TLC's -lncheck: "final" checks liveness only on the complete state graph.
112
- livenessCheck?: "default" | "final";
133
+ // TLC's -lncheck: "final" checks liveness only on the complete graph, "off" never looks for a cycle.
134
+ livenessCheck?: "default" | "final" | "off";
135
+ // TLC's -fp: the index of the polynomial in TLC's FP64.Polys that fingerprints states.
136
+ fingerprintPolynomial?: number;
137
+ // False for TLC's -terse, which prints a lazy value, such as SUBSET S, without enumerating it.
138
+ isLazyValueExpanded?: boolean;
139
+ // TLC's -view: prints each state as the value of the configuration's VIEW.
140
+ isViewPrinted?: boolean;
141
+ // TLC's -maxSetSize: the most elements TLC enumerates into a set, or states into a list of them.
142
+ maxSetSize?: number;
113
143
  // TLC's -dump: writes the reachable states, or with `dot` the state graph, through writeFile.
114
144
  dump?: StateDump;
115
145
  // TLC's -tool, which changes the messages of TLC's errors.
116
146
  isTool?: boolean;
117
- // Whether TLC records a binary trace for its trace exploration spec, for which it loads Integers.
118
- isTraceRecorded?: boolean;
147
+ // TLC's -continue: reports each violation through onProgress and goes on.
148
+ isContinued?: boolean;
149
+ moduleOperators?: ModuleOperator[];
150
+ // TLC's trace exploration spec, and the binary trace TLC records for it unless -noTEBin.
151
+ traceSpec?: TraceSpecOptions;
119
152
  // Whether the caller printed SANY's report, its warnings included, before the check.
120
153
  isSanyReported?: boolean;
121
- // False for TLC's -nowarning, which changes how TLC computes the successors of some actions.
154
+ // False for TLC's -nowarning, which changes how TLC computes some successors.
122
155
  isWarningEnabled?: boolean;
123
- // The TLC whose output tla-ts reproduces, which changes how TLC labels an action.
156
+ // TLC's -coverage, in minutes.
157
+ coverage?: number;
124
158
  version?: TlcVersion;
125
- // Reports the points of the search at which TLC prints a message.
126
159
  onProgress?: (progress: CheckProgress) => void;
127
160
  }
128
161
 
162
+ export interface TraceSpecOptions {
163
+ module: string;
164
+ traceFile?: string;
165
+ }
166
+
167
+ export interface ModuleOperator {
168
+ kind: "postcondition" | "constraint" | "view";
169
+ module: string;
170
+ operator: string;
171
+ constants?: Record<string, string>;
172
+ }
173
+
129
174
  export interface InitialStatesProgress {
130
175
  kind: "initial-states-progress";
131
176
  count: number;
132
177
  }
133
178
 
134
- // A check that TLC's DoInitFunctor reports as violated before it stops its replay of the initial
135
- // states.
179
+ // A check TLC reports as violated before it stops replaying the initial states.
136
180
  export interface InitialStateViolation {
137
181
  kind: "initial-state-violation";
138
182
  status: "invariant-violation" | "liveness-violation";
@@ -143,7 +187,6 @@ export interface InitialStateViolation {
143
187
  // A line the spec prints, or what TLC reports as it replays the initial states.
144
188
  export type OutputLine = string | InitialStatesProgress | InitialStateViolation;
145
189
 
146
- // The points of the search at which TLC prints a message.
147
190
  export type CheckProgress =
148
191
  | { kind: "parsed" }
149
192
  | { kind: "constant-level-invariant"; name: string }
@@ -163,14 +206,16 @@ export type CheckProgress =
163
206
  statistics: SearchStatistics;
164
207
  }
165
208
  | { kind: "liveness-finished" }
166
- // A warning TLC prints as it evaluates the spec, with its message code.
209
+ | { kind: "sequential-fallback"; string: string }
167
210
  | { kind: "warning"; code: number; text: string }
211
+ // A violation that the search goes on past with -continue.
212
+ | { kind: "violation"; status: CheckStatus; violation: Violation }
168
213
  // A method of the class named after a module, which TLC reports as it loads the class.
169
214
  | ({ kind: "java-override" } & JavaOverride);
170
215
 
171
216
  export interface SearchStatistics extends Pick<
172
217
  CheckResult,
173
- "generatedStates" | "distinctStates" | "queuedStates" | "depth"
218
+ "generatedStates" | "distinctStates" | "queuedStates" | "depth" | "coverage"
174
219
  > {}
175
220
 
176
221
  export type CheckStatus =
@@ -188,8 +233,7 @@ export interface TraceStep {
188
233
  // TLC's name, parameters and location for the action that took this step.
189
234
  label: string | undefined;
190
235
  state: Record<string, Value>;
191
- // What the spec prints, before TLC prints this step, as TLC evaluates it again to rebuild the
192
- // trace. The first step has what TLC prints before the trace.
236
+ // What the spec prints before this step as TLC rebuilds the trace, and before it for the first.
193
237
  output?: OutputLine[];
194
238
  }
195
239
 
@@ -198,16 +242,16 @@ export interface Violation {
198
242
  // Every temporal property that a liveness counterexample violates, in the configuration's order.
199
243
  properties?: string[];
200
244
  trace: TraceStep[];
201
- // What the spec prints after TLC prints the states of the trace, as TLC finds the step back into
202
- // the cycle of a lasso or rebuilds the trace once more.
245
+ // What the spec prints after the trace, as TLC finds the lasso's step back or rebuilds the trace.
203
246
  traceOutput?: OutputLine[];
247
+ // What the postconditions print, which TLC checks after the lasso's step back.
248
+ postconditionOutput?: OutputLine[];
204
249
  loopStart: number | undefined;
205
250
  loopLabel?: string;
206
251
  message?: string;
207
252
  counts?: string;
208
253
  unwitnessed?: Postcondition;
209
- // A POSTCONDITION that is false or fails after the counterexample, which TLC checks as it
210
- // prints one.
254
+ // A POSTCONDITION that is false or fails, which TLC checks as it prints the counterexample.
211
255
  postcondition?: Postcondition;
212
256
  // What TLC warns about after a counterexample, with its code.
213
257
  warning?: { code: number; text: string };
@@ -215,7 +259,6 @@ export interface Violation {
215
259
 
216
260
  export interface Postcondition {
217
261
  name: string;
218
- // TLC's message code.
219
262
  code: number;
220
263
  message: string;
221
264
  counts?: string;
@@ -223,7 +266,6 @@ export interface Postcondition {
223
266
 
224
267
  // An evaluation that failed during the search, with the behavior up to the state TLC was working on.
225
268
  export interface EvaluationFailure {
226
- // TLC's code for the message, and its text with and without -tool.
227
269
  code: number;
228
270
  message: string;
229
271
  toolMessage: string;
@@ -231,15 +273,13 @@ export interface EvaluationFailure {
231
273
  traceOutput?: OutputLine[];
232
274
  initialState: Record<string, Value> | undefined;
233
275
  exitCode: number;
234
- // The expressions TLC was evaluating when the failure occurred, outermost first, when TLC finds
235
- // them by replaying the failure.
276
+ // The expressions TLC was evaluating, outermost first, when its replay finds them.
236
277
  callStack: Expression[] | undefined;
237
278
  // Whether TLC prints the call stack before the error, as it does for a failed liveness check.
238
279
  isCallStackFirst?: boolean;
239
280
  // The FingerprintException the replay raises, which TLC reports in place of the call stack.
240
281
  fingerprint?: FingerprintFailure;
241
- // How TLC reports failing again as it prints the trace, since it can't fingerprint the state the
242
- // failure occurred in.
282
+ // How TLC reports failing again as it prints the trace, since it can't fingerprint the state.
243
283
  traceFailure?: FailureMessage;
244
284
  // A POSTCONDITION that is false or fails after the trace, which TLC checks as it prints one.
245
285
  postcondition?: Postcondition;
@@ -247,10 +287,10 @@ export interface EvaluationFailure {
247
287
  isWithoutStatistics?: boolean;
248
288
  }
249
289
 
250
- // Where TLC's replay of a failure fails.
251
290
  interface ReplayFailure {
252
291
  callStack: Expression[];
253
292
  fingerprint: FingerprintFailure | undefined;
293
+ replayError?: TlaEvaluationError;
254
294
  }
255
295
 
256
296
  export interface InitialStates {
@@ -266,23 +306,24 @@ export interface CheckResult {
266
306
  distinctStates: number;
267
307
  queuedStates: number;
268
308
  depth: number;
269
- // How many initial states TLC generated and how many of them were distinct, once it computed
270
- // them all without a violation or an error.
309
+ // Once TLC computed all the initial states without a violation or an error.
271
310
  initialStates: InitialStates | undefined;
272
- // How many states that TLC counts as expanded found each number of new states, when TLC prints
273
- // the outdegree of the state graph.
311
+ // How many expanded states found each number of new states, when TLC prints the outdegree.
274
312
  outDegrees: number[] | undefined;
275
- // The smallest distance between the fingerprints of two distinct states, when TLC estimates a
276
- // collision from the actual fingerprints.
313
+ // The smallest distance between two fingerprints, when TLC estimates a collision from them.
277
314
  fingerprintDistance: bigint | undefined;
278
- // A temporal property TLC finds violated as it adds a deadlocked state to the behavior graph,
279
- // which it reports after the deadlock.
315
+ // A temporal property TLC finds violated as it adds a deadlocked state, reported after.
280
316
  additionalViolation?: Violation;
281
317
  // Where TLC's worker fails to add the state to the behavior graph after it reports a violation.
282
318
  liveCallStack?: Expression[];
283
- // How many states that TLC counts as expanded found each number of new states, when its workers
284
- // stop on a violation without an error code, which TLC 1.7.4 reports as a successful search.
319
+ // The outdegrees when TLC's workers stop on a violation that TLC 1.7.4 reports as a success.
285
320
  violationOutDegrees?: number[];
321
+ traceSpec?: string;
322
+ coverage?: CoverageReport;
323
+ }
324
+
325
+ interface CoveredAction extends SpecAction {
326
+ node: number;
286
327
  }
287
328
 
288
329
  interface Behavior {
@@ -301,15 +342,14 @@ interface FailureOptions {
301
342
  outDegrees?: number[];
302
343
  callStack?: Expression[];
303
344
  fingerprint?: FingerprintFailure;
345
+ replayError?: TlaEvaluationError;
304
346
  isNextState?: boolean;
305
347
  isCallStackFirst?: boolean;
306
348
  traceFailure?: FailureMessage;
307
- // Whether the call stack is of adding the state to the behavior graph, which TLC prints instead
308
- // of replaying the error.
349
+ // Whether TLC prints the call stack of adding the state to the behavior graph, not a replay.
309
350
  isLiveCallStack?: boolean;
310
351
  }
311
352
 
312
- // TLC prints what the spec prints as it replays a failure after the trace.
313
353
  const appendTraceOutput = <Traced extends Behavior>(behavior: Traced, lines: OutputLine[]) => ({
314
354
  ...behavior,
315
355
  traceOutput: [...(behavior.traceOutput ?? []), ...lines],
@@ -318,45 +358,22 @@ const appendTraceOutput = <Traced extends Behavior>(behavior: Traced, lines: Out
318
358
  const INITIAL_RECOVERY_FAILURE = "Failed to recover the initial state from its fingerprint.";
319
359
  const NEXT_RECOVERY_FAILURE = "Failed to recover the next state from its fingerprint.";
320
360
 
321
- const toAliasRecord = (value: Value, fieldOrder: string[]) => {
322
- if (!isFunctionValue(value)) return undefined;
323
- const record = toFiniteFunction(value);
324
- if (!record.domain.every((key) => typeof key === "string")) return undefined;
325
- const entries = record.domain.map((key, index): [string, Value] => [
326
- String(key),
327
- record.range[index],
328
- ]);
329
- return Object.fromEntries(
330
- entries.sort((left, right) => fieldOrder.indexOf(left[0]) - fieldOrder.indexOf(right[0])),
331
- );
332
- };
333
-
334
361
  // Stops a replay where TLC stops it without a failure, as at a violated invariant.
335
362
  const STOP_REPLAY = new Error("The replay stopped");
363
+ const STOP_WALK = new Error("The walk stopped");
336
364
 
337
- // The codes of the errors in the configuration and the spec that TLC's EC.ExitStatus maps to a
338
- // configuration error.
339
- const CONFIG_ERROR_CODES = new Set([
340
- ...Array.from({ length: 24 }, (_, index) => 2222 + index),
341
- 2272,
342
- 2273,
343
- 2274,
344
- 2280,
345
- 2281,
346
- ]);
347
-
348
- // When TLC's replay of the initial states doesn't fail again, it exits with the code of the
349
- // TLCRuntimeException it reported.
365
+ // When TLC's replay of the initial states doesn't fail again, it exits with the error's code.
350
366
  const getInitialExitCode = (error: TlaEvaluationError) => {
351
367
  const coded = getCodedMessage(error.message);
352
- return coded && !coded.isEvalException && CONFIG_ERROR_CODES.has(coded.code)
368
+ return coded &&
369
+ !coded.isEvalException &&
370
+ getMessageExitStatus(coded.code) === EXIT_STATUS.configParseError
353
371
  ? EXIT_STATUS.configParseError
354
372
  : getErrorExitCode(error);
355
373
  };
356
374
 
357
- // When TLC's replay of an error fails again, an EvalException from a standard module's Java code
358
- // decides the exit status, and any other failure exits as a nested expression failure. An error
359
- // that heads or wraps another exits as the other.
375
+ // When the replay fails again, a standard module's EvalException decides the exit status, and
376
+ // any other failure exits as a nested expression failure. A heading or wrapping error defers.
360
377
  const getReplayExitCode = (error: TlaEvaluationError): number => {
361
378
  const inner = error.cause;
362
379
  if (inner instanceof TlaEvaluationError) return getReplayExitCode(inner);
@@ -376,8 +393,8 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
376
393
  }
377
394
  };
378
395
 
379
- // TLC checks liveness on the graph so far 3 seconds into the search and then every minute, once
380
- // the graph has grown by a tenth and liveness checking has taken at most a fifth of the time.
396
+ // TLC checks liveness on the graph so far after 3 seconds and then every minute, once the graph
397
+ // has grown by a tenth and liveness checking has taken at most a fifth of the time.
381
398
  const PERIODIC_START = 3000;
382
399
  const PROGRESS_INTERVAL = 60_000;
383
400
  const LIVENESS_GROWTH = 0.1;
@@ -389,8 +406,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
389
406
  ? parseConfig(options.config, options.version)
390
407
  : options.config;
391
408
  const onPrint = options.onPrint ?? console.log;
392
- // TLC prints again while it rebuilds a trace, between the states it prints, so rebuilding a trace
393
- // keeps what it prints for the trace.
409
+ // TLC prints again while it rebuilds a trace, so rebuilding keeps what it prints for the trace.
394
410
  const capturedOutput = { lines: undefined as OutputLine[] | undefined };
395
411
  const print = (text: string) => {
396
412
  if (capturedOutput.lines) capturedOutput.lines.push(text);
@@ -408,23 +424,41 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
408
424
  };
409
425
  const order = createTlcOrder(options.source, options.loadModule);
410
426
  setStringOrder(order.getStringOrder(config));
411
- setValueVersion(options.version);
427
+ setValueOptions(options);
428
+ setFingerprintPolynomial(options.fingerprintPolynomial ?? 0);
412
429
  const specification = createEnvironment(config, {
413
430
  source: options.source,
414
431
  loadModule: options.loadModule,
415
432
  order,
416
433
  loadClass: options.loadClass,
417
434
  print,
418
- files: { readFile: options.readFile, writeFile: options.writeFile },
435
+ files: {
436
+ readFile: options.readFile,
437
+ writeFile: options.writeFile,
438
+ makeDirectory: options.makeDirectory,
439
+ },
419
440
  seed: options.seed,
420
441
  isTool: options.isTool,
421
- isTraceRecorded: options.isTraceRecorded,
442
+ traceFile: options.traceSpec?.traceFile,
422
443
  isSanyReported: options.isSanyReported,
423
444
  isWarningEnabled: options.isWarningEnabled,
424
445
  version: options.version,
446
+ moduleOperators: options.moduleOperators,
425
447
  });
426
448
  reportStartup(specification, config, options.onProgress);
427
- const environment = specification.environment;
449
+ const coverage =
450
+ options.coverage === undefined
451
+ ? undefined
452
+ : createCoverage(specification.environment.variables.length);
453
+ const environment: Environment = coverage
454
+ ? {
455
+ ...specification.environment,
456
+ evaluators: new WeakMap(),
457
+ entryEvaluators: new WeakMap(),
458
+ definitionEvaluators: new WeakMap(),
459
+ coverage,
460
+ }
461
+ : specification.environment;
428
462
  const runtime = environment.runtime;
429
463
  const is174 = runtime.version === "1.7.4";
430
464
  runtime.pause = options.onPause ?? (() => {});
@@ -436,27 +470,58 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
436
470
  specification.instanceActions,
437
471
  );
438
472
  const statistics = { depth: 0, initialStates: undefined as InitialStates | undefined };
473
+ const getTraceSpec = (trace: TraceStep[], loopStart: number | undefined) =>
474
+ options.traceSpec &&
475
+ writeTraceSpec({
476
+ module: options.traceSpec.module,
477
+ specName: specification.rootName,
478
+ rawConstants: config.rawConstants,
479
+ states: trace.map((step) => getStepState(step)),
480
+ loopStart,
481
+ modelValues: getModelValues().map((value) => value.name),
482
+ isDefined: (name) =>
483
+ environment.definitions.has(name) ||
484
+ environment.constants.has(name) ||
485
+ [...environment.definitions.keys()].some((key) =>
486
+ key.startsWith(`${name}${KEY_SEPARATOR}`),
487
+ ),
488
+ });
439
489
  const createResult = (
440
490
  status: CheckStatus,
441
491
  violation?: Omit<Violation, "loopStart"> & { loopStart?: number },
442
492
  failure?: EvaluationFailure,
443
- ): CheckResult => ({
444
- status,
445
- violation: violation && { ...violation, loopStart: violation.loopStart },
446
- failure,
447
- generatedStates: runtime.generatedStates,
448
- distinctStates: runtime.distinctStates,
449
- queuedStates: runtime.queueSize,
450
- depth: runtime.generatedStates === 0 ? 0 : Math.max(statistics.depth, 1),
451
- initialStates: statistics.initialStates,
452
- outDegrees: undefined,
453
- fingerprintDistance: undefined,
454
- });
493
+ ): CheckResult => {
494
+ // TLC writes the trace it printed, and a safety property's counterexample doesn't loop back.
495
+ const traceSpec = getTraceSpec(
496
+ violation?.trace ?? failure?.trace ?? [],
497
+ status === "property-violation" ? undefined : violation?.loopStart,
498
+ );
499
+ return {
500
+ status,
501
+ violation: violation && { ...violation, loopStart: violation.loopStart },
502
+ failure,
503
+ generatedStates: runtime.generatedStates,
504
+ distinctStates: runtime.distinctStates,
505
+ queuedStates: runtime.queueSize,
506
+ depth: runtime.generatedStates === 0 ? 0 : Math.max(statistics.depth, 1),
507
+ initialStates: statistics.initialStates,
508
+ outDegrees: undefined,
509
+ fingerprintDistance: undefined,
510
+ coverage: coverage?.relations.some((relation) => relation.kind === "next")
511
+ ? getCoverageReport(
512
+ coverage,
513
+ environment,
514
+ specification.variableLocations,
515
+ search?.getTlcOrder() ?? [],
516
+ )
517
+ : undefined,
518
+ ...(traceSpec !== undefined && { traceSpec }),
519
+ };
520
+ };
455
521
  const outDegrees = Array.from({ length: OUT_DEGREE_BUCKETS }, () => 0);
456
522
  const expansion = { newStates: 0 };
457
523
  const getOutDegreeBucket = () => Math.min(expansion.newStates, OUT_DEGREE_BUCKETS - 1);
458
- // TLC counts the state it was expanding when an evaluation failed, except TLC 1.7.4, whose
459
- // worker stops before it counts the state.
524
+ // TLC counts the state it was expanding when an evaluation failed, except TLC 1.7.4.
460
525
  const getPartialOutDegrees = () =>
461
526
  outDegrees.map((count, degree) => (degree === getOutDegreeBucket() ? count + 1 : count));
462
527
  const getFailureOutDegrees = () => (is174 ? [...outDegrees] : getPartialOutDegrees());
@@ -484,8 +549,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
484
549
  const search = createSearch(
485
550
  config,
486
551
  environment,
552
+ specification.variableLocations,
487
553
  () => order.getDeclarationOrder("variable"),
488
554
  options.onProgress,
555
+ specification.moduleOperators,
489
556
  );
490
557
  const findViolatedAssumption = () =>
491
558
  findAssumptionViolation(specification.assumptions, environment);
@@ -502,9 +569,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
502
569
  });
503
570
  return createSuccess();
504
571
  }
505
- const hasPostconditions = config.postconditions.length > 0 || config.possible.length > 0;
506
- // The state of each step of a trace without the alias, and the action TLC finds for the step,
507
- // which CounterExample records.
572
+ const hasPostconditions =
573
+ config.postconditions.length > 0 ||
574
+ config.possible.length > 0 ||
575
+ specification.moduleOperators.some((operator) => operator.kind === "postcondition");
576
+ // The state of each step without the alias, and its action, which CounterExample records.
508
577
  const traceSteps = new WeakMap<
509
578
  TraceStep,
510
579
  { state: Record<string, Value>; action: SpecAction | undefined }
@@ -514,8 +583,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
514
583
  const action = traceSteps.get(step)?.action;
515
584
  return action ? toActionValue(action) : createActionRecord(step.action);
516
585
  };
517
- // Worker#printTrace checks the postconditions on the CounterExample of each trace it prints, so
518
- // what they print follows the trace.
586
+ // TLC checks the postconditions on each trace it prints, so what they print follows the trace.
519
587
  const checkTracePostconditions = (
520
588
  trace: TraceStep[],
521
589
  loop: { start: number; action: Value } | undefined,
@@ -543,19 +611,103 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
543
611
  violation.trace,
544
612
  start === undefined || !getLoopAction ? undefined : { start, action: getLoopAction() },
545
613
  );
546
- const traceOutput = [...(violation.traceOutput ?? []), ...checked.lines];
547
614
  return createResult(status, {
548
615
  ...violation,
549
- ...(traceOutput.length > 0 && { traceOutput }),
616
+ ...(checked.lines.length > 0 && { postconditionOutput: checked.lines }),
550
617
  ...(checked.unwitnessed && { unwitnessed: checked.unwitnessed }),
551
618
  ...(checked.postcondition && { postcondition: checked.postcondition }),
552
619
  });
553
620
  };
621
+ // With -continue, TLC prints the trace of a violation without checking the postconditions. It
622
+ // never records the violation, and reports a success at the end, where tla-ts ends with the
623
+ // status of the first violation, as -dfid and -simulate do.
624
+ const continued = { status: undefined as CheckStatus | undefined };
625
+ const reportContinuedViolation = (
626
+ status: CheckStatus,
627
+ violation: Omit<Violation, "loopStart">,
628
+ ) => {
629
+ continued.status ??= status;
630
+ options.onProgress?.({
631
+ kind: "violation",
632
+ status,
633
+ violation: { ...violation, loopStart: undefined },
634
+ });
635
+ };
554
636
  const spec = search.spec;
555
637
  const getFingerprintState = search.getFingerprintState;
556
638
  const specNextActions = { value: undefined as SpecAction[] | undefined };
557
639
  const getSpecNextActions = () =>
558
640
  (specNextActions.value ??= getNextActions(config, environment, specification.instanceActions));
641
+ // Tool's constructor splits the next-state relation into actions before TLC checks anything.
642
+ getSpecNextActions();
643
+ runtime.getSuccessorAction = (state, next) =>
644
+ getSpecNextActions().find((action) =>
645
+ getSuccessors(action.expression, state, environment, action.scope).some((successor) =>
646
+ successor.state.every((value, index) => isSameValue(value, next[index])),
647
+ ),
648
+ );
649
+ const addCoverageRelations = (kind: "init" | "next", actions: SpecAction[]) =>
650
+ actions.map((action): CoveredAction => ({
651
+ ...action,
652
+ node: coverage
653
+ ? addCoverageRelation(
654
+ coverage,
655
+ kind,
656
+ getCoverageLabel(action.name, action.expression, environment),
657
+ action.expression,
658
+ action.scope,
659
+ )
660
+ : -1,
661
+ }));
662
+ const coverageInits = addCoverageRelations(
663
+ "init",
664
+ coverage ? getInitActions(config, environment, specification.instanceActions) : [],
665
+ );
666
+ const coverageActions = addCoverageRelations("next", coverage ? getSpecNextActions() : []);
667
+ if (coverage) buildCoverage(coverage, environment, getPrimedRanges(coverageActions, environment));
668
+ const walkCoveredSuccessors = (
669
+ action: CoveredAction,
670
+ state: Value[],
671
+ onState: (successor: Value[]) => void,
672
+ ) =>
673
+ walkSuccessors(
674
+ action,
675
+ action.node,
676
+ state,
677
+ environment,
678
+ (successor) => {
679
+ if (coverage) coverage.primary[action.node]++;
680
+ onState(successor);
681
+ },
682
+ (partial) => {
683
+ const missing = environment.variables.filter((_, index) => partial[index] === undefined);
684
+ throw new TlaIncompleteSuccessorError(
685
+ `Successor state is not completely specified by action ${action.name}. The following variables are not assigned: ${missing.join(", ")}`,
686
+ partial,
687
+ action.name,
688
+ missing,
689
+ );
690
+ },
691
+ );
692
+ const getCoveredSuccessors = (action: CoveredAction, state: Value[]) => {
693
+ const successors: Successor[] = [];
694
+ walkCoveredSuccessors(action, state, (successor) =>
695
+ successors.push({ state: successor, action: action.name }),
696
+ );
697
+ return successors;
698
+ };
699
+ const getCoveredInitialStates = () => {
700
+ const initialStates: Value[][] = [];
701
+ replayInitialStates(
702
+ coverageInits,
703
+ environment,
704
+ (state) => initialStates.push(state),
705
+ (partial) => {
706
+ throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
707
+ },
708
+ );
709
+ return initialStates;
710
+ };
559
711
  const getReplayFailure = (replay: (tracing: Environment) => void): ReplayFailure | undefined => {
560
712
  const tracing = createTracingEnvironment(environment);
561
713
  const callStack = tracing.callStack;
@@ -566,11 +718,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
566
718
  // A replay that overflows the stack again has an empty call stack.
567
719
  if (isStackOverflow(error)) return { callStack: [], fingerprint: undefined };
568
720
  if (!(error instanceof TlaEvaluationError) || !callStack) return undefined;
569
- return { callStack: callStack.expressions, fingerprint: callStack.fingerprint };
721
+ return {
722
+ callStack: callStack.expressions,
723
+ fingerprint: callStack.fingerprint,
724
+ replayError: error,
725
+ };
570
726
  }
571
727
  };
572
- // The sources of the values a fingerprint fails inside, outermost first: each value fails as it
573
- // fingerprints a value it holds.
728
+ // Outermost first: each value fails as it fingerprints a value it holds.
574
729
  const findFailedSources = (value: Value, sources: CallStack["sources"]): Expression[] => {
575
730
  if (typeof value !== "object") return [];
576
731
  const source = sources.get(value);
@@ -580,8 +735,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
580
735
  ...(failed === undefined ? [] : findFailedSources(failed, sources)),
581
736
  ];
582
737
  };
583
- // TLC's replay fingerprints the states it finds, and a value the replay built raises a
584
- // FingerprintException when it fails to.
738
+ // A value the replay built raises a FingerprintException when TLC fails to fingerprint it.
585
739
  const fingerprintReplayed = (state: Value[], callStack: CallStack | undefined) => {
586
740
  for (const value of getFingerprintState(state)) {
587
741
  const error = getFingerprintError(value);
@@ -597,8 +751,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
597
751
  }
598
752
  state.forEach(markFingerprinted);
599
753
  };
600
- // The replay adds the states it hasn't seen to TLC's set of states, which already holds the state
601
- // that failed after TLC added it.
754
+ // TLC's set of states already holds the state that failed.
602
755
  const createReplayedStates = () => {
603
756
  const replayed = unstoredState.fingerprint ? [unstoredState.fingerprint] : [];
604
757
  return (state: Value[], callStack: CallStack | undefined) => {
@@ -613,12 +766,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
613
766
  return true;
614
767
  };
615
768
  };
616
- // TLC's DoInitFunctor reports its progress again as it replays the initial states, and adds each
617
- // one it hasn't seen to the behavior graph. After a FingerprintException, it only counts the
618
- // states left, then throws the exception.
769
+ // TLC reports its progress again as it replays the initial states. After a FingerprintException
770
+ // or a StackOverflowError, it only counts the states left, then throws the error.
619
771
  const replayInit = () => {
620
772
  const replayed = { count: 0 };
621
- const deferred: TlaEvaluationError[] = [];
773
+ const deferred: unknown[] = [];
622
774
  const addReplayed = createReplayedStates();
623
775
  return getReplayFailure((tracing) => {
624
776
  replayInitialStates(
@@ -648,9 +800,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
648
800
  throw STOP_REPLAY;
649
801
  }
650
802
  } catch (error) {
651
- if (!(error instanceof TlaEvaluationError) || !tracing.callStack?.fingerprint) {
652
- throw error;
653
- }
803
+ const isFingerprintFailure =
804
+ error instanceof TlaEvaluationError && tracing.callStack?.fingerprint !== undefined;
805
+ if (!isFingerprintFailure && !isStackOverflow(error)) throw error;
654
806
  deferred.push(error);
655
807
  }
656
808
  },
@@ -658,8 +810,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
658
810
  if (deferred.length > 0) throw deferred[0];
659
811
  });
660
812
  };
661
- // TLC replays the expansion of a state with ModelChecker.doNext, which writes each successor in
662
- // the model to the -dump state graph again.
813
+ // TLC's replay writes each successor in the model to the -dump state graph again.
663
814
  const replayNext = (index: number) =>
664
815
  getReplayFailure((tracing) => {
665
816
  const state = states[index];
@@ -673,9 +824,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
673
824
  source,
674
825
  getGraphState(next, depths[index] + 1),
675
826
  !isUnseen,
676
- isNamingEdges
677
- ? { name: action.name, signature: getActionSignature(action) }
678
- : undefined,
827
+ isNamingEdges ? getGraphAction(action) : undefined,
679
828
  );
680
829
  }
681
830
  return isUnseen;
@@ -703,33 +852,37 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
703
852
  getSuccessors: (source, state) => {
704
853
  const successors: LiveSuccessor[] = [];
705
854
  if (spec.next === undefined) return successors;
706
- // The constraints read the level of the state whose successors they check, as when TLC
707
- // explored it.
855
+ // The constraints read the level of the state whose successors they check.
708
856
  const livenessSource = current.livenessSource;
709
857
  current.livenessSource = source;
710
- forEachSuccessor(
711
- spec.next,
712
- state,
713
- environment,
714
- (successor) => {
715
- canonicalizeState(successor.state);
716
- const isInModel =
717
- search.satisfiesConstraints(successor.state, state) &&
718
- search.satisfiesActionConstraints(state, successor.state);
719
- if (!isInModel) return false;
720
- const fingerprintState = getFingerprintState(successor.state);
721
- const index = findStateIndex(getStateHash(fingerprintState), fingerprintState);
722
- successors.push({ index, state: successor.state });
723
- return false;
724
- },
725
- spec.scope,
726
- );
727
- current.livenessSource = livenessSource;
858
+ try {
859
+ forEachSuccessor(
860
+ spec.next,
861
+ state,
862
+ environment,
863
+ (successor) => {
864
+ canonicalizeState(successor.state);
865
+ const isInModel =
866
+ search.satisfiesConstraints(successor.state, state) &&
867
+ search.satisfiesActionConstraints(state, successor.state);
868
+ if (!isInModel) return false;
869
+ const fingerprintState = getFingerprintState(successor.state);
870
+ const index = findStateIndex(getStateHash(fingerprintState), fingerprintState);
871
+ successors.push({ index, state: successor.state });
872
+ return false;
873
+ },
874
+ spec.scope,
875
+ );
876
+ } finally {
877
+ current.livenessSource = livenessSource;
878
+ }
728
879
  return successors;
729
880
  },
730
881
  }),
731
882
  ),
732
883
  );
884
+ // ModelChecker rejects a temporal property whose negation has no solution.
885
+ if (liveness?.branches === 0) throw createTautologyError();
733
886
  // TLC 1.7.4 creates its model checker, which TLCGet reads, once it has built the liveness checker.
734
887
  runtime.isStarted = true;
735
888
  const isCanonicalizedFirst = search.isSymmetric || liveness !== undefined;
@@ -739,64 +892,68 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
739
892
  const parents: number[] = [];
740
893
  const actions: (string | undefined)[] = [];
741
894
  const depths: number[] = [];
742
- // A Map holds at most 2^24 entries, so an open-addressing table keeps each seen state's hash
743
- // and its index plus one side by side, probed by the hash.
895
+ // A Map holds at most 2^24 entries, so an open-addressing table keeps each hash and index + 1.
744
896
  const seenStates = { slots: new Int32Array(1 << 17), size: 0, shift: 16 };
745
897
  const canonicalizeState = createCanonicalizer();
746
898
 
747
- const toRecord = (state: Value[]): Record<string, Value> =>
748
- Object.fromEntries(
749
- search.getTlcOrder().map((index) => [environment.variables[index], state[index]]),
750
- );
899
+ const toRecord = search.toRecord;
751
900
  const getAliasState = (
752
901
  alias: string,
753
902
  steps: Successor[],
754
903
  position: number,
755
904
  loopStart: number | undefined,
756
905
  ) => {
757
- // TLC evaluates TLCGet("level") and Trace in an alias at the state's position in the trace.
906
+ // TLC evaluates TLCGet("level") and Trace in an alias at the state's position in the trace. The
907
+ // search reads them again once the alias is evaluated, as it goes on with -continue.
908
+ const searchLevel = runtime.getLevel;
909
+ const searchBehavior = runtime.getBehavior;
758
910
  runtime.getLevel = () => position + 1;
759
911
  runtime.getBehavior = () => steps.slice(0, position + 1).map((step) => step.state);
760
- return evaluateAlias(
761
- alias,
762
- steps[position].state,
763
- (steps[position + 1] ?? steps[loopStart ?? position]).state,
764
- );
765
- };
766
- const evaluateAlias = (alias: string, state: Value[], next: Value[] | undefined) => {
767
912
  try {
768
- const body = getConfigDefinition("alias", alias, environment).body;
769
- const value = evaluate(createIdentifier(alias), getContext(environment, state, next));
770
- const fieldOrder = body.kind === "Record" ? body.fields.map((field) => field.name) : [];
771
- return toAliasRecord(value, fieldOrder) ?? toRecord(state);
772
- } catch (error) {
773
- if (!(error instanceof TlaConfigError || error instanceof TlaEvaluationError)) throw error;
774
- return {
775
- ...toRecord(state),
776
- _ALIASEvalError: formatNestedMessage(error.message, options.isTool ?? false),
777
- };
913
+ return evaluateAlias(
914
+ alias,
915
+ steps[position].state,
916
+ (steps[position + 1] ?? steps[loopStart ?? position]).state,
917
+ );
918
+ } finally {
919
+ runtime.getLevel = searchLevel;
920
+ runtime.getBehavior = searchBehavior;
778
921
  }
779
922
  };
780
- // TLC finds the action of a step as the first action that takes it, evaluated as when the search
781
- // expanded the previous state, by the values of a successor it holds and otherwise by fingerprint.
923
+ const evaluateAlias = (alias: string, state: Value[], next: Value[] | undefined) =>
924
+ search.evaluateAlias(alias, state, next, options.isTool ?? false);
925
+ // TLC finds the action of a step as the first that takes it, evaluated as when the search
926
+ // expanded the previous state, by a held successor's values and otherwise by fingerprint.
782
927
  const findStepAction = (index: number, previous: Value[], state: Value[], isHeld: boolean) => {
783
928
  const actions = getSpecNextActions();
784
929
  const expanding = { ...current };
785
- Object.assign(current, { index, isExpanding: true, candidate: undefined });
930
+ Object.assign(current, {
931
+ index,
932
+ isExpanding: true,
933
+ candidate: undefined,
934
+ rebuilt: { state: previous, level: depths[index] },
935
+ });
786
936
  const getKey = isHeld ? (values: Value[]) => values : getFingerprintState;
787
937
  const key = getKey(state);
788
- const action = actions.find((item) =>
789
- getSuccessors(item.expression, previous, environment, item.scope).some((successor) =>
790
- isSameState(getKey(successor.state), key),
791
- ),
792
- );
793
- Object.assign(current, expanding);
794
- return action;
938
+ try {
939
+ return coverage
940
+ ? coverageActions.find((item) =>
941
+ getCoveredSuccessors(item, previous).some((successor) =>
942
+ isSameState(getKey(successor.state), key),
943
+ ),
944
+ )
945
+ : actions.find((item) =>
946
+ getSuccessors(item.expression, previous, environment, item.scope).some((successor) =>
947
+ isSameState(getKey(successor.state), key),
948
+ ),
949
+ );
950
+ } finally {
951
+ Object.assign(current, expanding);
952
+ }
795
953
  };
796
- // Before TLC prints a trace, it rebuilds from the initial predicate the states it does not keep,
797
- // all but the last `known` ones. As it prints each later step, it finds the action that takes
798
- // the step. Then it rebuilds the trace once more, unless the trace is a liveness counterexample
799
- // or TLC is 1.7.4.
954
+ // TLC rebuilds the states it doesn't keep, all but the last `known`, from the initial predicate,
955
+ // finds the action of each later step, and then rebuilds the trace once more, unless it is a
956
+ // liveness counterexample or TLC is 1.7.4.
800
957
  const toTrace = (
801
958
  steps: Successor[],
802
959
  path: number[],
@@ -821,9 +978,26 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
821
978
  );
822
979
  const outputs = stepActions.map((step) => step.lines);
823
980
  const loopStart = traceOptions.loopStart;
824
- // 1.7.4's LiveWorker#printTrace rebuilds a lasso up to the start of its cycle at once, and then
825
- // each state of the cycle as it prints it.
981
+ // TLC 1.7.4 rebuilds a lasso up to its cycle at once, then each cycle state as it prints it.
826
982
  const rebuilt = is174 && loopStart !== undefined ? loopStart + 1 : steps.length - known;
983
+ // What the trace prints once comes from each time TLC rebuilds it, which coverage counts.
984
+ if (coverage && steps.length > 1) {
985
+ const isRebuiltAgain = known > 0 && !is174;
986
+ if (rebuilt > 0 && isRebuiltAgain) captureOutput(getSpecInitialStates);
987
+ if (isRebuiltAgain) {
988
+ steps.slice(1).forEach((step, position) => {
989
+ if (step.action === "Stuttering") return;
990
+ captureOutput(() =>
991
+ findStepAction(
992
+ path[position],
993
+ steps[position].state,
994
+ step.state,
995
+ known === 2 && position === steps.length - 2,
996
+ ),
997
+ );
998
+ });
999
+ }
1000
+ }
827
1001
  const prefixOutput = rebuilt > 0 ? [initialOutput, ...outputs.slice(1, rebuilt)].flat() : [];
828
1002
  return {
829
1003
  trace: steps.map((step, position) => {
@@ -845,11 +1019,12 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
845
1019
  traceOutput: known > 0 && !is174 ? [initialOutput, ...outputs].flat() : [],
846
1020
  };
847
1021
  };
848
- const getSpecInitialStates = () =>
849
- spec.init === undefined ? [] : getInitialStates(spec.init, environment, spec.scope);
850
- // TLC's Tool#getState rebuilds a successor action by action, up to the first action that
851
- // generates it. A trace keeps what the spec prints as TLC rebuilds it, so finding its states
852
- // prints nothing.
1022
+ const getSpecInitialStates = () => {
1023
+ if (coverage) return getCoveredInitialStates();
1024
+ return spec.init === undefined ? [] : getInitialStates(spec.init, environment, spec.scope);
1025
+ };
1026
+ // TLC rebuilds a successor action by action, up to the first that generates it. A trace keeps
1027
+ // what the spec prints as TLC rebuilds it, so finding its states prints nothing.
853
1028
  const findTraceSuccessor = (state: Value[], isMatch: (successor: Successor) => boolean) =>
854
1029
  captureOutput(() => {
855
1030
  for (const action of getSpecNextActions()) {
@@ -878,7 +1053,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
878
1053
  steps.push({ state: previous, action: "Stuttering" });
879
1054
  continue;
880
1055
  }
1056
+ // TLC rebuilds each state at its level, which TLCGet reads.
1057
+ const rebuilt = current.rebuilt;
1058
+ current.rebuilt = { state: previous, level: depths[path[position - 1]] };
881
1059
  const successor = findSuccessorWithFingerprint(previous, path[position]);
1060
+ current.rebuilt = rebuilt;
882
1061
  if (!successor) throw new TlaEvaluationError(nextFailure);
883
1062
  steps.push(successor);
884
1063
  }
@@ -901,24 +1080,45 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
901
1080
  : lastSuccessor.action;
902
1081
  return toTrace([...steps, { state: lastSuccessor.state, action }], path, { known: 2 });
903
1082
  };
904
- // TLC prints a lone initial state without the alias. TLCTrace#getTrace still recovers it from the
905
- // initial predicate, printing again, though TLC 1.7.4 doesn't.
1083
+ // TLC rebuilds a lone initial state, unlike TLC 1.7.4. TLCTrace#printTrace prints it without the
1084
+ // alias, where tla-ts applies the alias as it does to every other trace.
906
1085
  const getStateTrace = (index: number): Behavior =>
907
1086
  parents[index] === -1
908
1087
  ? {
909
- trace: [{ action: undefined, label: undefined, state: toRecord(states[index]) }],
1088
+ trace: [
1089
+ {
1090
+ action: undefined,
1091
+ label: undefined,
1092
+ state:
1093
+ config.alias === undefined
1094
+ ? toRecord(states[index])
1095
+ : getAliasState(
1096
+ config.alias,
1097
+ [{ state: states[index], action: undefined }],
1098
+ 0,
1099
+ undefined,
1100
+ ),
1101
+ },
1102
+ ],
910
1103
  traceOutput: is174 ? [] : captureOutput(getSpecInitialStates).lines,
911
1104
  }
912
1105
  : getTrace(index);
913
- // TLC rebuilds the trace again for the postcondition after it prints a violation, but not after
914
- // an evaluation fails.
1106
+ // TLC rebuilds the trace for the postcondition after a violation, but not after a failure.
1107
+ // TLC fails again to fingerprint the successor in the trace, as an unexpected exception.
1108
+ const isUnfingerprintable = (state: Value[]) => {
1109
+ try {
1110
+ return getFingerprintState(state).some((value) => getFingerprintError(value) !== undefined);
1111
+ } catch (error) {
1112
+ if (!(error instanceof TlaEvaluationError)) throw error;
1113
+ return true;
1114
+ }
1115
+ };
915
1116
  const getFailedTrace = (index: number, successor: Successor): Behavior => ({
916
1117
  trace: getTrace(index, successor).trace,
917
1118
  });
918
1119
  // TLC names the initial state it was checking unless a standard module's Java code failed.
919
1120
  const getFailureExitCode = (error: TlaEvaluationError, failureOptions: FailureOptions) => {
920
- // TLC 1.7.4 exits with the result of its replay of the initial states, which only fails again
921
- // when the error isn't in adding a state it has already seen to the behavior graph.
1121
+ // TLC 1.7.4 exits with the result of replaying the initial states, which fails again only here.
922
1122
  if (
923
1123
  failureOptions.isInitial &&
924
1124
  !failureOptions.callStack &&
@@ -937,11 +1137,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
937
1137
  getExitCode(error) ?? (error instanceof TlaModuleError ? error.exitCode : EXIT_STATUS.error)
938
1138
  );
939
1139
  }
940
- // TLC exits with the code of a failed replay of the initial states regardless of the error, as
941
- // it does for a replay that fails to fingerprint.
1140
+ // TLC exits with the code of a failed initial replay whatever the error, as for a fingerprint.
942
1141
  return failureOptions.isInitial || failureOptions.fingerprint
943
1142
  ? EXIT_STATUS.specEvaluationFailure
944
- : getReplayExitCode(error);
1143
+ : getReplayExitCode(failureOptions.replayError ?? error);
945
1144
  };
946
1145
  const createFailureResult = (
947
1146
  failed: unknown,
@@ -975,21 +1174,27 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
975
1174
  outDegrees: failureOptions.outDegrees,
976
1175
  };
977
1176
  };
978
- // TLC reports a successor state that an action leaves incomplete with the trace to it, which ends
979
- // with the partial state. It names the action when the next-state relation has several.
1177
+ // TLC reports a partial successor with the trace to it, naming the action if there are several.
980
1178
  const reportIncompleteSuccessor = (index: number, error: TlaIncompleteSuccessorError) => {
981
1179
  runtime.generatedStates++;
982
1180
  const actions = getSpecNextActions();
1181
+ const named =
1182
+ actions.length === 1 ? actions : actions.filter((item) => item.name === error.action);
1183
+ // Inline disjuncts of the next-state relation share its name, so TLC's is the one that failed.
983
1184
  const action =
984
- actions.length === 1 ? actions[0] : actions.find((item) => item.name === error.action);
985
- const missing = error.variables;
986
- const subject =
987
- actions.length === 1
988
- ? "the next-state action"
989
- : `action ${error.action} of the next-state relation`;
990
- // TLC 1.7.4 says a variable is not assigned rather than not defined.
991
- const verb = is174 ? "assigned" : "defined";
992
- const message = `Successor state is not completely specified by ${subject}. The following variable${missing.length > 1 ? "s are" : " is"} not ${verb}: ${missing.join(", ")}.\n`;
1185
+ named.length === 1
1186
+ ? named[0]
1187
+ : captureOutput(() =>
1188
+ named.find((item) =>
1189
+ hasIncompleteSuccessor(item.expression, states[index], environment, item.scope),
1190
+ ),
1191
+ ).result;
1192
+ const message = getIncompleteSuccessorMessage(
1193
+ error.variables,
1194
+ error.action,
1195
+ actions.length,
1196
+ options.version,
1197
+ );
993
1198
  const undefinedValue = createModelValue("null");
994
1199
  const partial = error.state.map((value) => value ?? undefinedValue);
995
1200
  const failure = createFailureResult(error, getStateTrace(index));
@@ -1072,8 +1277,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1072
1277
  }
1073
1278
  insertSeen(hash, index + 1);
1074
1279
  };
1075
- // A new successor that TLC has added to its set of states before it checks the successor, which
1076
- // the check stores after.
1280
+ // TLC adds a new successor to its states before it checks it, which the check stores after.
1077
1281
  const unstoredState = { fingerprint: undefined as Value[] | undefined };
1078
1282
  const countDistinctState = (depth: number) => {
1079
1283
  runtime.distinctStates = states.length + 1;
@@ -1100,6 +1304,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1100
1304
  candidate: undefined as Value[] | undefined,
1101
1305
  candidateLevel: 0,
1102
1306
  livenessSource: -1,
1307
+ rebuilt: undefined as { state: Value[]; level: number } | undefined,
1103
1308
  };
1104
1309
  const getPath = (index: number): Value[][] =>
1105
1310
  index === -1 ? [] : [...getPath(parents[index]), states[index]];
@@ -1122,6 +1327,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1122
1327
  const explored = source !== -1 ? source : current.isExpanding ? current.index : -1;
1123
1328
  return explored === -1 ? 0 : depths[explored];
1124
1329
  }
1330
+ const rebuilt = current.rebuilt;
1331
+ if (rebuilt) return state === rebuilt.state ? rebuilt.level : rebuilt.level + 1;
1125
1332
  if (source !== -1) return state === states[source] ? depths[source] : depths[source] + 1;
1126
1333
  if (state === current.candidate) return current.candidateLevel;
1127
1334
  if (current.index === -1) return 0;
@@ -1129,6 +1336,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1129
1336
  return current.isExpanding ? depths[current.index] + 1 : 0;
1130
1337
  };
1131
1338
 
1339
+ const getGraphAction = (action: SpecAction) => ({
1340
+ name: action.name,
1341
+ signature: getActionSignature(action),
1342
+ });
1132
1343
  const getGraphState = (state: Value[], level: number): GraphState => ({
1133
1344
  fingerprint: BigInt.asIntN(64, runtime.getFingerprint(state)),
1134
1345
  level,
@@ -1164,7 +1375,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1164
1375
  liveness?.addInitialState(states.length, state);
1165
1376
  stateWriter?.writeInitialState(getGraphState(state, 1));
1166
1377
  }
1167
- const violated = search.findViolatedInvariant(state);
1378
+ if (options.isContinued) {
1379
+ search.getViolatedInvariants(state).forEach((invariant) =>
1380
+ reportContinuedViolation("invariant-violation", {
1381
+ name: invariant.name,
1382
+ ...toTrace([{ action: undefined, state }], []),
1383
+ }),
1384
+ );
1385
+ }
1386
+ const violated = options.isContinued ? undefined : search.findViolatedInvariant(state);
1168
1387
  if (violated) {
1169
1388
  return reportViolation("invariant-violation", {
1170
1389
  name: violated.name,
@@ -1212,9 +1431,22 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1212
1431
  source,
1213
1432
  getGraphState(successor.state, depths[index] + 1),
1214
1433
  existing !== -1,
1215
- action && { name: action.name, signature: getActionSignature(action) },
1434
+ action && getGraphAction(action),
1216
1435
  );
1217
1436
  }
1437
+ if (source && !isInModel && options.dump?.constrained) {
1438
+ const excluded = getGraphState(successor.state, depths[index] + 1);
1439
+ search
1440
+ .getExcludingConstraints(state, successor.state)
1441
+ .forEach((constraint) =>
1442
+ stateWriter?.writeConstrained(
1443
+ source,
1444
+ excluded,
1445
+ action && getGraphAction(action),
1446
+ constraint,
1447
+ ),
1448
+ );
1449
+ }
1218
1450
  if (existing !== -1 && liveness) {
1219
1451
  const stored = states[existing];
1220
1452
  const isStored = stored.every((value, position) => value === successor.state[position]);
@@ -1227,23 +1459,20 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1227
1459
  if (isNew) {
1228
1460
  countDistinctState(depths[index] + 1);
1229
1461
  expansion.newStates++;
1462
+ if (coverage) coverage.secondary[coveredAction.node]++;
1230
1463
  }
1231
1464
  if (existing === -1) {
1232
1465
  try {
1233
1466
  const violated = search.findViolatedInvariant(successor.state, state);
1234
- if (violated) {
1235
- return withOutDegrees(
1236
- reportViolation("invariant-violation", {
1237
- name: violated.name,
1238
- ...getTrace(index, successor),
1239
- }),
1240
- );
1467
+ const violation = violated && { name: violated.name, ...getTrace(index, successor) };
1468
+ if (violation && !options.isContinued) {
1469
+ return withOutDegrees(reportViolation("invariant-violation", violation));
1241
1470
  }
1471
+ if (violation) reportContinuedViolation("invariant-violation", violation);
1242
1472
  } catch (error) {
1243
1473
  if (isStackOverflow(error)) throw error;
1244
- // TLC replays the expansion and skips the invariants of a state it has seen, the failed one
1245
- // included unless the constraints exclude it. When the replay fails, TLC reports where and
1246
- // leaves out the outdegree.
1474
+ // TLC replays the expansion and skips the invariants of a seen state, the failed one
1475
+ // included unless the constraints exclude it. A failed replay leaves out the outdegree.
1247
1476
  const replay = captureOutput(() => replayNext(index));
1248
1477
  return createFailureResult(
1249
1478
  error,
@@ -1253,15 +1482,16 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1253
1482
  }
1254
1483
  }
1255
1484
  const violatedProperty = search.findViolatedActionProperty(state, successor.state);
1256
- if (violatedProperty) {
1257
- return withOutDegrees(
1258
- reportViolation("liveness-violation", {
1259
- name: violatedProperty.name,
1260
- ...getTrace(index, successor),
1261
- }),
1262
- );
1485
+ const propertyViolation = violatedProperty && {
1486
+ name: violatedProperty.name,
1487
+ ...getTrace(index, successor),
1488
+ };
1489
+ if (propertyViolation && !options.isContinued) {
1490
+ return withOutDegrees(reportViolation("liveness-violation", propertyViolation));
1263
1491
  }
1492
+ if (propertyViolation) reportContinuedViolation("liveness-violation", propertyViolation);
1264
1493
  if (!isNew) return undefined;
1494
+ if (coverage) countCoverageVariables(coverage, successor.state);
1265
1495
  if (!isCanonicalizedFirst) canonicalizeState(successor.state);
1266
1496
  markSeen(hash, states.length);
1267
1497
  addState(successor.state, fingerprintState, index, successor.action);
@@ -1270,38 +1500,64 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1270
1500
  };
1271
1501
 
1272
1502
  const outcome: { result: CheckResult | undefined } = { result: undefined };
1503
+ const coveredAction = { node: -1 };
1273
1504
  if (liveness) {
1274
1505
  options.onProgress?.({ kind: "liveness-prepared", branches: liveness.branches });
1275
1506
  }
1276
- // TLC checks the assumptions once it has built the liveness checker in ModelChecker's
1277
- // constructor.
1507
+ // TLC checks the assumptions once it has built the liveness checker.
1278
1508
  const assumptionViolation = findViolatedAssumption();
1279
1509
  if (assumptionViolation) return createResult("assumption-violation", assumptionViolation);
1280
1510
  options.onProgress?.({ kind: "initial-states-started" });
1281
1511
  if (spec.init !== undefined) {
1282
- try {
1283
- forEachInitialState(
1284
- spec.init,
1285
- environment,
1286
- (state) => {
1287
- reportInitialStatesProgress(runtime.initialStates, options.onProgress);
1288
- try {
1289
- outcome.result = visitInitialState(state);
1290
- } catch (error) {
1291
- const replay = captureOutput(replayInit);
1292
- outcome.result = createFailureResult(
1293
- error,
1294
- { trace: [], traceOutput: replay.lines },
1295
- { initialState: state, ...replay.result, isInitial: true },
1296
- );
1297
- }
1298
- return outcome.result !== undefined;
1299
- },
1300
- spec.scope,
1512
+ // TLC keeps an initial state's StackOverflowError, counts the states after it, then reports it.
1513
+ const overflow: { state: Value[] | undefined } = { state: undefined };
1514
+ const reportInitialFailure = (error: unknown, state: Value[]) => {
1515
+ const replay = captureOutput(replayInit);
1516
+ return createFailureResult(
1517
+ error,
1518
+ { trace: [], traceOutput: replay.lines },
1519
+ { initialState: state, ...replay.result, isInitial: true },
1301
1520
  );
1521
+ };
1522
+ try {
1523
+ const onInitialState = (state: Value[]) => {
1524
+ reportInitialStatesProgress(runtime.initialStates, options.onProgress);
1525
+ if (overflow.state) {
1526
+ runtime.generatedStates++;
1527
+ runtime.initialStates++;
1528
+ return false;
1529
+ }
1530
+ try {
1531
+ outcome.result = visitInitialState(state);
1532
+ } catch (error) {
1533
+ if (isStackOverflow(error)) overflow.state = state;
1534
+ else outcome.result = reportInitialFailure(error, state);
1535
+ }
1536
+ return outcome.result !== undefined;
1537
+ };
1538
+ if (coverage) {
1539
+ try {
1540
+ replayInitialStates(
1541
+ coverageInits,
1542
+ environment,
1543
+ (state) => {
1544
+ if (onInitialState(state)) throw STOP_WALK;
1545
+ },
1546
+ (partial) => {
1547
+ throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
1548
+ },
1549
+ );
1550
+ } catch (error) {
1551
+ if (error !== STOP_WALK) throw error;
1552
+ }
1553
+ } else {
1554
+ forEachInitialState(spec.init, environment, onInitialState, spec.scope);
1555
+ }
1556
+ if (overflow.state) {
1557
+ outcome.result = reportInitialFailure(createStackOverflowError(), overflow.state);
1558
+ }
1302
1559
  } catch (error) {
1303
- // TLC prints an illegal initial state with null for each variable it leaves undefined, and
1304
- // stops before it prints the statistics.
1560
+ // TLC prints null for each undefined variable and stops before the statistics.
1305
1561
  if (error instanceof TlaIllegalStateError) {
1306
1562
  const illegal = createFailureResult(
1307
1563
  error,
@@ -1341,15 +1597,33 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1341
1597
  }
1342
1598
  return createSuccess();
1343
1599
  }
1344
- // TLC labels and colors an edge of the -dump state graph by the action that generated it. When
1345
- // the graph names its edges, the search generates successors action by action, as TLC does.
1600
+ // TLC labels and colors a -dump edge by its action, so a graph that names its edges generates
1601
+ // successors action by action.
1346
1602
  const isNamingEdges = Boolean(
1347
1603
  options.dump?.dot && (options.dump.actionLabels || options.dump.colorize),
1348
1604
  );
1349
1605
  const forEachActionSuccessor = (
1350
1606
  state: Value[],
1607
+ onUnsatisfied:
1608
+ | ((successor: Value[], conjunct: Expression, action?: SpecAction) => void)
1609
+ | undefined,
1351
1610
  onSuccessor: (successor: Successor, action: SpecAction | undefined) => boolean,
1352
1611
  ) => {
1612
+ if (coverage) {
1613
+ const progress = { count: 0 };
1614
+ try {
1615
+ coverageActions.forEach((action) => {
1616
+ coveredAction.node = action.node;
1617
+ walkCoveredSuccessors(action, state, (successor) => {
1618
+ progress.count++;
1619
+ if (onSuccessor({ state: successor, action: action.name }, action)) throw STOP_WALK;
1620
+ });
1621
+ });
1622
+ } catch (error) {
1623
+ if (error !== STOP_WALK) throw error;
1624
+ }
1625
+ return progress.count;
1626
+ }
1353
1627
  if (!isNamingEdges) {
1354
1628
  return forEachSuccessor(
1355
1629
  next,
@@ -1357,6 +1631,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1357
1631
  environment,
1358
1632
  (successor) => onSuccessor(successor, undefined),
1359
1633
  spec.scope,
1634
+ undefined,
1635
+ onUnsatisfied,
1360
1636
  );
1361
1637
  }
1362
1638
  const progress = { isStopped: false };
@@ -1373,13 +1649,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1373
1649
  return progress.isStopped;
1374
1650
  },
1375
1651
  action.scope,
1652
+ undefined,
1653
+ onUnsatisfied && ((successor, conjunct) => onUnsatisfied(successor, conjunct, action)),
1376
1654
  )
1377
1655
  );
1378
1656
  }, 0);
1379
1657
  };
1380
- // TLC's worker adds a state to the behavior graph even after its next states fail or violate a
1381
- // property, and prints the call stack of an error in that, unless the error is a
1382
- // FingerprintException, which the worker doesn't catch. TLC 1.7.4 prints none.
1658
+ // TLC's worker adds a state to the behavior graph even after its next states fail, and prints
1659
+ // the call stack of an error in that, unless it is a FingerprintException. TLC 1.7.4 prints none.
1383
1660
  const getLiveCallStack = (index: number, liveSuccessors: LiveSuccessor[]) => {
1384
1661
  if (!liveness || is174) return undefined;
1385
1662
  const replay = getReplayFailure((tracing) =>
@@ -1387,9 +1664,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1387
1664
  );
1388
1665
  return replay?.callStack.length && !replay.fingerprint ? replay.callStack : undefined;
1389
1666
  };
1390
- // TLC's worker adds the state to the behavior graph after it prints the trace. On an error in that,
1391
- // it adds the state again to print the call stack instead of replaying the next-state relation,
1392
- // which TLC 1.7.4 doesn't.
1667
+ // On an error in adding the state after the trace, TLC adds it again to print the call stack
1668
+ // instead of replaying the next-state relation, which TLC 1.7.4 doesn't.
1393
1669
  const addFailedLiveState = (index: number, liveSuccessors: LiveSuccessor[]) => {
1394
1670
  try {
1395
1671
  liveness?.addState(index, states[index], liveSuccessors);
@@ -1408,10 +1684,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1408
1684
  const replay = captureOutput(() => replayNext(index));
1409
1685
  return { result: replay.result, lines: [...live.lines, ...replay.lines] };
1410
1686
  };
1411
- // TLC reports a stack overflow while it computes next states without replaying it, with the
1412
- // behavior up to the state it expands.
1687
+ // TLC reports a stack overflow in the next states without a replay, up to the state it expands.
1413
1688
  const reportNextStateOverflow = (index: number) =>
1414
- createFailureResult(createStackOverflowError(), getStateTrace(index));
1689
+ createFailureResult(createStackOverflowError(), getStateTrace(index), { isNextState: true });
1415
1690
  // After the trace, TLC replays the next-state relation with its call stack, printing again.
1416
1691
  const reportNextStateFailure = (
1417
1692
  error: unknown,
@@ -1429,7 +1704,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1429
1704
  const expandState = (index: number, liveSuccessors: LiveSuccessor[]) => {
1430
1705
  const state = states[index];
1431
1706
  const source = stateWriter && getGraphState(state, depths[index]);
1432
- const successorCount = forEachActionSuccessor(state, (successor, action) => {
1707
+ const writeUnsatisfied =
1708
+ source && options.dump?.constrained
1709
+ ? (successor: Value[], conjunct: Expression, action?: SpecAction) =>
1710
+ stateWriter?.writeConstrained(
1711
+ source,
1712
+ getGraphState(successor, depths[index] + 1),
1713
+ action && getGraphAction(action),
1714
+ describeRange(conjunct),
1715
+ )
1716
+ : undefined;
1717
+ const successorCount = forEachActionSuccessor(state, writeUnsatisfied, (successor, action) => {
1433
1718
  try {
1434
1719
  outcome.result = visitSuccessor(index, successor, liveSuccessors, source, action);
1435
1720
  } catch (error) {
@@ -1437,9 +1722,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1437
1722
  outcome.result = reportNextStateOverflow(index);
1438
1723
  return true;
1439
1724
  }
1440
- // TLC 1.7.4 reports the wrapped error without the trace, except for a failed property,
1441
- // which it reports with the trace before it rethrows. The error stops its worker before it
1442
- // adds the state to the behavior graph.
1725
+ // TLC 1.7.4 reports the wrapped error without the trace, except for a failed property, and
1726
+ // stops its worker before it adds the state to the behavior graph.
1443
1727
  const replay = is174
1444
1728
  ? captureOutput(() => replayNext(index))
1445
1729
  : replayFailedNext(index, liveSuccessors);
@@ -1451,11 +1735,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1451
1735
  );
1452
1736
  return true;
1453
1737
  }
1454
- // A successor TLC can't fingerprint fails again as TLC prints it in the trace, which TLC
1455
- // reports as an exception it didn't expect.
1456
- const isTraceFailed = getFingerprintState(successor.state).some(
1457
- (value) => getFingerprintError(value) !== undefined,
1458
- );
1738
+ const isTraceFailed = isUnfingerprintable(successor.state);
1459
1739
  const traceFailure =
1460
1740
  isTraceFailed && error instanceof TlaEvaluationError
1461
1741
  ? getFailureMessage(
@@ -1489,7 +1769,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1489
1769
  }
1490
1770
  if (result) return result;
1491
1771
  const addLiveState = () => {
1492
- if (liveness && source && is174) stateWriter?.writeStuttering(source);
1772
+ if (liveness && source && (is174 || options.dump?.stuttering)) {
1773
+ stateWriter?.writeStuttering(source);
1774
+ }
1493
1775
  const accepted = liveness?.addState(index, state, liveSuccessors);
1494
1776
  if (!liveness || !accepted) return undefined;
1495
1777
  const steps = getPathSteps(accepted);
@@ -1506,9 +1788,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1506
1788
  };
1507
1789
  if (successorCount === 0 && config.checkDeadlock) {
1508
1790
  const deadlock = reportViolation("deadlock", { name: "deadlock", ...getStateTrace(index) });
1509
- // TLC's worker still adds the deadlocked state to the behavior graph after it reports the
1510
- // deadlock, and reports a temporal property that this violates. Then it counts the state as
1511
- // expanded.
1791
+ // TLC's worker still adds the deadlocked state to the behavior graph, reports a temporal
1792
+ // property that violates, and then counts the state as expanded.
1512
1793
  const live = captureOutput(() => {
1513
1794
  try {
1514
1795
  return { additional: addLiveState()?.violation };
@@ -1532,8 +1813,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1532
1813
  try {
1533
1814
  return addLiveState();
1534
1815
  } catch (error) {
1535
- // TLC 1.7.4's worker reports an error in adding a state to the behavior graph as an exception
1536
- // it didn't expect, without the trace or a call stack, and exits as for any general error.
1816
+ // TLC 1.7.4 reports this as an unexpected exception, without the trace or a call stack.
1537
1817
  if (is174 && error instanceof TlaEvaluationError) {
1538
1818
  const unexpected = new TlaEvaluationError(
1539
1819
  `${isEvalException(error) ? UNEXPECTED_EVAL_EXCEPTION : UNEXPECTED_EXCEPTION}${error.message}`,
@@ -1544,8 +1824,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1544
1824
  { outDegrees: getFailureOutDegrees() },
1545
1825
  );
1546
1826
  }
1547
- // TLC's Worker#doNextCheckLiveness adds the state again to find the call stack, prints it
1548
- // before the error, and reports the error as one in computing next states.
1827
+ // TLC adds the state again for the call stack, prints it first, and blames the next states.
1549
1828
  const replay = getReplayFailure((tracing) =>
1550
1829
  liveness?.addState(index, state, liveSuccessors, tracing),
1551
1830
  );
@@ -1557,7 +1836,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1557
1836
  });
1558
1837
  }
1559
1838
  };
1560
- // TLC's Liveness#printStutteringCounterExampleWarning.
1561
1839
  const getStutteringWarning = () => {
1562
1840
  const name = config.specification;
1563
1841
  const book =
@@ -1613,9 +1891,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1613
1891
  : createActionRecord(findSuccessorWithFingerprint(lastState, cycleStart)?.action),
1614
1892
  );
1615
1893
  };
1616
- const isPeriodic = liveness !== undefined && options.livenessCheck !== "final";
1894
+ const isPeriodic = liveness !== undefined && (options.livenessCheck ?? "default") === "default";
1617
1895
  const startedAt = performance.now();
1618
- const periodic = { at: startedAt + PERIODIC_START, size: 1, time: 0 };
1896
+ const periodic = {
1897
+ at: startedAt + PERIODIC_START,
1898
+ size: 1,
1899
+ time: 0,
1900
+ coverageCount: Math.trunc(options.coverage ?? 0),
1901
+ };
1619
1902
  const findPeriodicViolation = (expanded: number) => {
1620
1903
  const now = performance.now();
1621
1904
  const isGrown = (expanded - periodic.size) / periodic.size > LIVENESS_GROWTH;
@@ -1651,45 +1934,56 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1651
1934
  if (outcome.result) return outcome.result;
1652
1935
  outDegrees[getOutDegreeBucket()]++;
1653
1936
  expansion.newStates = 0;
1654
- // TLC's AbstractChecker#runTLC checks the liveness properties on the state graph so far, then
1655
- // reports how far the search got.
1937
+ // TLC checks liveness on the graph so far, then reports how far the search got.
1656
1938
  if ((isPeriodic || options.onProgress) && performance.now() >= periodic.at) {
1657
1939
  periodic.at = performance.now() + PROGRESS_INTERVAL;
1658
1940
  const lasso = isPeriodic ? findPeriodicViolation(index + 1) : undefined;
1659
1941
  if (liveness && lasso) return reportLasso(liveness, lasso);
1660
- options.onProgress?.({ kind: "progress", statistics: createResult("success") });
1942
+ // TLC reports the coverage with every report after the first `coverage` reports since the last.
1943
+ const isCoverageDue = options.coverage !== undefined && periodic.coverageCount === 0;
1944
+ periodic.coverageCount = isCoverageDue
1945
+ ? Math.trunc(options.coverage ?? 0)
1946
+ : periodic.coverageCount - 1;
1947
+ const progress = createResult("success");
1948
+ options.onProgress?.({
1949
+ kind: "progress",
1950
+ statistics: { ...progress, coverage: isCoverageDue ? progress.coverage : undefined },
1951
+ });
1661
1952
  }
1662
1953
  }
1663
1954
 
1664
1955
  current.index = -1;
1665
1956
  current.candidate = undefined;
1666
- if (liveness) {
1957
+ const finalLiveness = options.livenessCheck === "off" ? undefined : liveness;
1958
+ if (finalLiveness) {
1667
1959
  options.onProgress?.({
1668
1960
  kind: "liveness-started",
1669
- branches: liveness.branches,
1961
+ branches: finalLiveness.branches,
1670
1962
  isComplete: true,
1671
1963
  states: runtime.distinctStates,
1672
1964
  statistics: createResult("success"),
1673
1965
  });
1674
1966
  }
1675
- const lasso = liveness?.findViolation();
1676
- if (liveness && lasso) return reportLasso(liveness, lasso);
1967
+ const lasso = finalLiveness?.findViolation();
1968
+ if (finalLiveness && lasso) return reportLasso(finalLiveness, lasso);
1677
1969
 
1678
1970
  // TLC finishes the check of the temporal properties before it checks the postconditions.
1679
- if (liveness) options.onProgress?.({ kind: "liveness-finished" });
1680
- try {
1681
- const postcondition = search.findPostconditionViolation();
1682
- if (postcondition) {
1683
- return createResult("postcondition-violation", {
1684
- name: postcondition.name,
1685
- message: postcondition.message,
1686
- counts: postcondition.counts,
1687
- trace: [],
1688
- postcondition,
1689
- });
1690
- }
1691
- } catch (error) {
1692
- return createFailureResult(error, { trace: [] });
1971
+ if (finalLiveness) options.onProgress?.({ kind: "liveness-finished" });
1972
+ const missingPostcondition = specification.moduleOperators.find(
1973
+ (operator) => operator.kind === "postcondition" && operator.key === undefined,
1974
+ );
1975
+ if (missingPostcondition) {
1976
+ return createFailureResult(createMissingOperatorError(missingPostcondition), { trace: [] });
1977
+ }
1978
+ const postcondition = search.findPostconditionViolation();
1979
+ if (postcondition) {
1980
+ return createResult("postcondition-violation", {
1981
+ name: postcondition.name,
1982
+ message: postcondition.message,
1983
+ counts: postcondition.counts,
1984
+ trace: [],
1985
+ postcondition,
1986
+ });
1693
1987
  }
1694
- return createSuccess();
1988
+ return continued.status ? createResult(continued.status) : createSuccess();
1695
1989
  };