tla-ts 0.0.9 → 0.0.10-dev.b4a856304

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 +29 -1
  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 +72 -10
  8. package/dist/index.d.ts +72 -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 +576 -300
  30. package/src/cli/options.ts +11 -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 +538 -220
  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 +630 -297
  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 +29 -39
  82. package/src/parallel.ts +29 -13
  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 +119 -169
  340. package/src/sany/levels.ts +6 -30
  341. package/src/sany/lexer.ts +7 -23
  342. package/src/sany/linter.ts +1 -8
  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 +494 -154
  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 +826 -276
  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,37 +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
- // TLC's -continue: the search reports each violated invariant and action property through
118
- // onProgress and goes on.
147
+ // TLC's -continue: reports each violation through onProgress and goes on.
119
148
  isContinued?: boolean;
120
- // Whether TLC records a binary trace for its trace exploration spec, for which it loads Integers.
121
- isTraceRecorded?: boolean;
149
+ moduleOperators?: ModuleOperator[];
150
+ // TLC's trace exploration spec, and the binary trace TLC records for it unless -noTEBin.
151
+ traceSpec?: TraceSpecOptions;
122
152
  // Whether the caller printed SANY's report, its warnings included, before the check.
123
153
  isSanyReported?: boolean;
124
- // 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.
125
155
  isWarningEnabled?: boolean;
126
- // The TLC whose output tla-ts reproduces, which changes how TLC labels an action.
156
+ // TLC's -coverage, in minutes.
157
+ coverage?: number;
127
158
  version?: TlcVersion;
128
- // Reports the points of the search at which TLC prints a message.
129
159
  onProgress?: (progress: CheckProgress) => void;
130
160
  }
131
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
+
132
174
  export interface InitialStatesProgress {
133
175
  kind: "initial-states-progress";
134
176
  count: number;
135
177
  }
136
178
 
137
- // A check that TLC's DoInitFunctor reports as violated before it stops its replay of the initial
138
- // states.
179
+ // A check TLC reports as violated before it stops replaying the initial states.
139
180
  export interface InitialStateViolation {
140
181
  kind: "initial-state-violation";
141
182
  status: "invariant-violation" | "liveness-violation";
@@ -146,7 +187,6 @@ export interface InitialStateViolation {
146
187
  // A line the spec prints, or what TLC reports as it replays the initial states.
147
188
  export type OutputLine = string | InitialStatesProgress | InitialStateViolation;
148
189
 
149
- // The points of the search at which TLC prints a message.
150
190
  export type CheckProgress =
151
191
  | { kind: "parsed" }
152
192
  | { kind: "constant-level-invariant"; name: string }
@@ -167,7 +207,6 @@ export type CheckProgress =
167
207
  }
168
208
  | { kind: "liveness-finished" }
169
209
  | { kind: "sequential-fallback"; string: string }
170
- // A warning TLC prints as it evaluates the spec, with its message code.
171
210
  | { kind: "warning"; code: number; text: string }
172
211
  // A violation that the search goes on past with -continue.
173
212
  | { kind: "violation"; status: CheckStatus; violation: Violation }
@@ -176,7 +215,7 @@ export type CheckProgress =
176
215
 
177
216
  export interface SearchStatistics extends Pick<
178
217
  CheckResult,
179
- "generatedStates" | "distinctStates" | "queuedStates" | "depth"
218
+ "generatedStates" | "distinctStates" | "queuedStates" | "depth" | "coverage"
180
219
  > {}
181
220
 
182
221
  export type CheckStatus =
@@ -194,8 +233,7 @@ export interface TraceStep {
194
233
  // TLC's name, parameters and location for the action that took this step.
195
234
  label: string | undefined;
196
235
  state: Record<string, Value>;
197
- // What the spec prints, before TLC prints this step, as TLC evaluates it again to rebuild the
198
- // 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.
199
237
  output?: OutputLine[];
200
238
  }
201
239
 
@@ -204,16 +242,16 @@ export interface Violation {
204
242
  // Every temporal property that a liveness counterexample violates, in the configuration's order.
205
243
  properties?: string[];
206
244
  trace: TraceStep[];
207
- // What the spec prints after TLC prints the states of the trace, as TLC finds the step back into
208
- // 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.
209
246
  traceOutput?: OutputLine[];
247
+ // What the postconditions print, which TLC checks after the lasso's step back.
248
+ postconditionOutput?: OutputLine[];
210
249
  loopStart: number | undefined;
211
250
  loopLabel?: string;
212
251
  message?: string;
213
252
  counts?: string;
214
253
  unwitnessed?: Postcondition;
215
- // A POSTCONDITION that is false or fails after the counterexample, which TLC checks as it
216
- // prints one.
254
+ // A POSTCONDITION that is false or fails, which TLC checks as it prints the counterexample.
217
255
  postcondition?: Postcondition;
218
256
  // What TLC warns about after a counterexample, with its code.
219
257
  warning?: { code: number; text: string };
@@ -221,7 +259,6 @@ export interface Violation {
221
259
 
222
260
  export interface Postcondition {
223
261
  name: string;
224
- // TLC's message code.
225
262
  code: number;
226
263
  message: string;
227
264
  counts?: string;
@@ -229,7 +266,6 @@ export interface Postcondition {
229
266
 
230
267
  // An evaluation that failed during the search, with the behavior up to the state TLC was working on.
231
268
  export interface EvaluationFailure {
232
- // TLC's code for the message, and its text with and without -tool.
233
269
  code: number;
234
270
  message: string;
235
271
  toolMessage: string;
@@ -237,15 +273,13 @@ export interface EvaluationFailure {
237
273
  traceOutput?: OutputLine[];
238
274
  initialState: Record<string, Value> | undefined;
239
275
  exitCode: number;
240
- // The expressions TLC was evaluating when the failure occurred, outermost first, when TLC finds
241
- // them by replaying the failure.
276
+ // The expressions TLC was evaluating, outermost first, when its replay finds them.
242
277
  callStack: Expression[] | undefined;
243
278
  // Whether TLC prints the call stack before the error, as it does for a failed liveness check.
244
279
  isCallStackFirst?: boolean;
245
280
  // The FingerprintException the replay raises, which TLC reports in place of the call stack.
246
281
  fingerprint?: FingerprintFailure;
247
- // How TLC reports failing again as it prints the trace, since it can't fingerprint the state the
248
- // failure occurred in.
282
+ // How TLC reports failing again as it prints the trace, since it can't fingerprint the state.
249
283
  traceFailure?: FailureMessage;
250
284
  // A POSTCONDITION that is false or fails after the trace, which TLC checks as it prints one.
251
285
  postcondition?: Postcondition;
@@ -253,10 +287,10 @@ export interface EvaluationFailure {
253
287
  isWithoutStatistics?: boolean;
254
288
  }
255
289
 
256
- // Where TLC's replay of a failure fails.
257
290
  interface ReplayFailure {
258
291
  callStack: Expression[];
259
292
  fingerprint: FingerprintFailure | undefined;
293
+ replayError?: TlaEvaluationError;
260
294
  }
261
295
 
262
296
  export interface InitialStates {
@@ -272,23 +306,24 @@ export interface CheckResult {
272
306
  distinctStates: number;
273
307
  queuedStates: number;
274
308
  depth: number;
275
- // How many initial states TLC generated and how many of them were distinct, once it computed
276
- // them all without a violation or an error.
309
+ // Once TLC computed all the initial states without a violation or an error.
277
310
  initialStates: InitialStates | undefined;
278
- // How many states that TLC counts as expanded found each number of new states, when TLC prints
279
- // the outdegree of the state graph.
311
+ // How many expanded states found each number of new states, when TLC prints the outdegree.
280
312
  outDegrees: number[] | undefined;
281
- // The smallest distance between the fingerprints of two distinct states, when TLC estimates a
282
- // collision from the actual fingerprints.
313
+ // The smallest distance between two fingerprints, when TLC estimates a collision from them.
283
314
  fingerprintDistance: bigint | undefined;
284
- // A temporal property TLC finds violated as it adds a deadlocked state to the behavior graph,
285
- // which it reports after the deadlock.
315
+ // A temporal property TLC finds violated as it adds a deadlocked state, reported after.
286
316
  additionalViolation?: Violation;
287
317
  // Where TLC's worker fails to add the state to the behavior graph after it reports a violation.
288
318
  liveCallStack?: Expression[];
289
- // How many states that TLC counts as expanded found each number of new states, when its workers
290
- // 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.
291
320
  violationOutDegrees?: number[];
321
+ traceSpec?: string;
322
+ coverage?: CoverageReport;
323
+ }
324
+
325
+ interface CoveredAction extends SpecAction {
326
+ node: number;
292
327
  }
293
328
 
294
329
  interface Behavior {
@@ -307,15 +342,14 @@ interface FailureOptions {
307
342
  outDegrees?: number[];
308
343
  callStack?: Expression[];
309
344
  fingerprint?: FingerprintFailure;
345
+ replayError?: TlaEvaluationError;
310
346
  isNextState?: boolean;
311
347
  isCallStackFirst?: boolean;
312
348
  traceFailure?: FailureMessage;
313
- // Whether the call stack is of adding the state to the behavior graph, which TLC prints instead
314
- // of replaying the error.
349
+ // Whether TLC prints the call stack of adding the state to the behavior graph, not a replay.
315
350
  isLiveCallStack?: boolean;
316
351
  }
317
352
 
318
- // TLC prints what the spec prints as it replays a failure after the trace.
319
353
  const appendTraceOutput = <Traced extends Behavior>(behavior: Traced, lines: OutputLine[]) => ({
320
354
  ...behavior,
321
355
  traceOutput: [...(behavior.traceOutput ?? []), ...lines],
@@ -324,45 +358,22 @@ const appendTraceOutput = <Traced extends Behavior>(behavior: Traced, lines: Out
324
358
  const INITIAL_RECOVERY_FAILURE = "Failed to recover the initial state from its fingerprint.";
325
359
  const NEXT_RECOVERY_FAILURE = "Failed to recover the next state from its fingerprint.";
326
360
 
327
- const toAliasRecord = (value: Value, fieldOrder: string[]) => {
328
- if (!isFunctionValue(value)) return undefined;
329
- const record = toFiniteFunction(value);
330
- if (!record.domain.every((key) => typeof key === "string")) return undefined;
331
- const entries = record.domain.map((key, index): [string, Value] => [
332
- String(key),
333
- record.range[index],
334
- ]);
335
- return Object.fromEntries(
336
- entries.sort((left, right) => fieldOrder.indexOf(left[0]) - fieldOrder.indexOf(right[0])),
337
- );
338
- };
339
-
340
361
  // Stops a replay where TLC stops it without a failure, as at a violated invariant.
341
362
  const STOP_REPLAY = new Error("The replay stopped");
363
+ const STOP_WALK = new Error("The walk stopped");
342
364
 
343
- // The codes of the errors in the configuration and the spec that TLC's EC.ExitStatus maps to a
344
- // configuration error.
345
- const CONFIG_ERROR_CODES = new Set([
346
- ...Array.from({ length: 24 }, (_, index) => 2222 + index),
347
- 2272,
348
- 2273,
349
- 2274,
350
- 2280,
351
- 2281,
352
- ]);
353
-
354
- // When TLC's replay of the initial states doesn't fail again, it exits with the code of the
355
- // TLCRuntimeException it reported.
365
+ // When TLC's replay of the initial states doesn't fail again, it exits with the error's code.
356
366
  const getInitialExitCode = (error: TlaEvaluationError) => {
357
367
  const coded = getCodedMessage(error.message);
358
- return coded && !coded.isEvalException && CONFIG_ERROR_CODES.has(coded.code)
368
+ return coded &&
369
+ !coded.isEvalException &&
370
+ getMessageExitStatus(coded.code) === EXIT_STATUS.configParseError
359
371
  ? EXIT_STATUS.configParseError
360
372
  : getErrorExitCode(error);
361
373
  };
362
374
 
363
- // When TLC's replay of an error fails again, an EvalException from a standard module's Java code
364
- // decides the exit status, and any other failure exits as a nested expression failure. An error
365
- // 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.
366
377
  const getReplayExitCode = (error: TlaEvaluationError): number => {
367
378
  const inner = error.cause;
368
379
  if (inner instanceof TlaEvaluationError) return getReplayExitCode(inner);
@@ -382,8 +393,8 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
382
393
  }
383
394
  };
384
395
 
385
- // TLC checks liveness on the graph so far 3 seconds into the search and then every minute, once
386
- // 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.
387
398
  const PERIODIC_START = 3000;
388
399
  const PROGRESS_INTERVAL = 60_000;
389
400
  const LIVENESS_GROWTH = 0.1;
@@ -395,8 +406,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
395
406
  ? parseConfig(options.config, options.version)
396
407
  : options.config;
397
408
  const onPrint = options.onPrint ?? console.log;
398
- // TLC prints again while it rebuilds a trace, between the states it prints, so rebuilding a trace
399
- // 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.
400
410
  const capturedOutput = { lines: undefined as OutputLine[] | undefined };
401
411
  const print = (text: string) => {
402
412
  if (capturedOutput.lines) capturedOutput.lines.push(text);
@@ -414,23 +424,41 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
414
424
  };
415
425
  const order = createTlcOrder(options.source, options.loadModule);
416
426
  setStringOrder(order.getStringOrder(config));
417
- setValueVersion(options.version);
427
+ setValueOptions(options);
428
+ setFingerprintPolynomial(options.fingerprintPolynomial ?? 0);
418
429
  const specification = createEnvironment(config, {
419
430
  source: options.source,
420
431
  loadModule: options.loadModule,
421
432
  order,
422
433
  loadClass: options.loadClass,
423
434
  print,
424
- files: { readFile: options.readFile, writeFile: options.writeFile },
435
+ files: {
436
+ readFile: options.readFile,
437
+ writeFile: options.writeFile,
438
+ makeDirectory: options.makeDirectory,
439
+ },
425
440
  seed: options.seed,
426
441
  isTool: options.isTool,
427
- isTraceRecorded: options.isTraceRecorded,
442
+ traceFile: options.traceSpec?.traceFile,
428
443
  isSanyReported: options.isSanyReported,
429
444
  isWarningEnabled: options.isWarningEnabled,
430
445
  version: options.version,
446
+ moduleOperators: options.moduleOperators,
431
447
  });
432
448
  reportStartup(specification, config, options.onProgress);
433
- 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;
434
462
  const runtime = environment.runtime;
435
463
  const is174 = runtime.version === "1.7.4";
436
464
  runtime.pause = options.onPause ?? (() => {});
@@ -442,27 +470,58 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
442
470
  specification.instanceActions,
443
471
  );
444
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
+ });
445
489
  const createResult = (
446
490
  status: CheckStatus,
447
491
  violation?: Omit<Violation, "loopStart"> & { loopStart?: number },
448
492
  failure?: EvaluationFailure,
449
- ): CheckResult => ({
450
- status,
451
- violation: violation && { ...violation, loopStart: violation.loopStart },
452
- failure,
453
- generatedStates: runtime.generatedStates,
454
- distinctStates: runtime.distinctStates,
455
- queuedStates: runtime.queueSize,
456
- depth: runtime.generatedStates === 0 ? 0 : Math.max(statistics.depth, 1),
457
- initialStates: statistics.initialStates,
458
- outDegrees: undefined,
459
- fingerprintDistance: undefined,
460
- });
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
+ };
461
521
  const outDegrees = Array.from({ length: OUT_DEGREE_BUCKETS }, () => 0);
462
522
  const expansion = { newStates: 0 };
463
523
  const getOutDegreeBucket = () => Math.min(expansion.newStates, OUT_DEGREE_BUCKETS - 1);
464
- // TLC counts the state it was expanding when an evaluation failed, except TLC 1.7.4, whose
465
- // worker stops before it counts the state.
524
+ // TLC counts the state it was expanding when an evaluation failed, except TLC 1.7.4.
466
525
  const getPartialOutDegrees = () =>
467
526
  outDegrees.map((count, degree) => (degree === getOutDegreeBucket() ? count + 1 : count));
468
527
  const getFailureOutDegrees = () => (is174 ? [...outDegrees] : getPartialOutDegrees());
@@ -490,8 +549,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
490
549
  const search = createSearch(
491
550
  config,
492
551
  environment,
552
+ specification.variableLocations,
493
553
  () => order.getDeclarationOrder("variable"),
494
554
  options.onProgress,
555
+ specification.moduleOperators,
495
556
  );
496
557
  const findViolatedAssumption = () =>
497
558
  findAssumptionViolation(specification.assumptions, environment);
@@ -508,9 +569,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
508
569
  });
509
570
  return createSuccess();
510
571
  }
511
- const hasPostconditions = config.postconditions.length > 0 || config.possible.length > 0;
512
- // The state of each step of a trace without the alias, and the action TLC finds for the step,
513
- // 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.
514
577
  const traceSteps = new WeakMap<
515
578
  TraceStep,
516
579
  { state: Record<string, Value>; action: SpecAction | undefined }
@@ -520,8 +583,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
520
583
  const action = traceSteps.get(step)?.action;
521
584
  return action ? toActionValue(action) : createActionRecord(step.action);
522
585
  };
523
- // Worker#printTrace checks the postconditions on the CounterExample of each trace it prints, so
524
- // what they print follows the trace.
586
+ // TLC checks the postconditions on each trace it prints, so what they print follows the trace.
525
587
  const checkTracePostconditions = (
526
588
  trace: TraceStep[],
527
589
  loop: { start: number; action: Value } | undefined,
@@ -549,26 +611,103 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
549
611
  violation.trace,
550
612
  start === undefined || !getLoopAction ? undefined : { start, action: getLoopAction() },
551
613
  );
552
- const traceOutput = [...(violation.traceOutput ?? []), ...checked.lines];
553
614
  return createResult(status, {
554
615
  ...violation,
555
- ...(traceOutput.length > 0 && { traceOutput }),
616
+ ...(checked.lines.length > 0 && { postconditionOutput: checked.lines }),
556
617
  ...(checked.unwitnessed && { unwitnessed: checked.unwitnessed }),
557
618
  ...(checked.postcondition && { postcondition: checked.postcondition }),
558
619
  });
559
620
  };
560
- // With -continue, TLC prints the trace of a violation without checking the postconditions.
561
- const reportContinuedViolation = (status: CheckStatus, violation: Omit<Violation, "loopStart">) =>
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;
562
630
  options.onProgress?.({
563
631
  kind: "violation",
564
632
  status,
565
633
  violation: { ...violation, loopStart: undefined },
566
634
  });
635
+ };
567
636
  const spec = search.spec;
568
637
  const getFingerprintState = search.getFingerprintState;
569
638
  const specNextActions = { value: undefined as SpecAction[] | undefined };
570
639
  const getSpecNextActions = () =>
571
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
+ };
572
711
  const getReplayFailure = (replay: (tracing: Environment) => void): ReplayFailure | undefined => {
573
712
  const tracing = createTracingEnvironment(environment);
574
713
  const callStack = tracing.callStack;
@@ -579,11 +718,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
579
718
  // A replay that overflows the stack again has an empty call stack.
580
719
  if (isStackOverflow(error)) return { callStack: [], fingerprint: undefined };
581
720
  if (!(error instanceof TlaEvaluationError) || !callStack) return undefined;
582
- return { callStack: callStack.expressions, fingerprint: callStack.fingerprint };
721
+ return {
722
+ callStack: callStack.expressions,
723
+ fingerprint: callStack.fingerprint,
724
+ replayError: error,
725
+ };
583
726
  }
584
727
  };
585
- // The sources of the values a fingerprint fails inside, outermost first: each value fails as it
586
- // fingerprints a value it holds.
728
+ // Outermost first: each value fails as it fingerprints a value it holds.
587
729
  const findFailedSources = (value: Value, sources: CallStack["sources"]): Expression[] => {
588
730
  if (typeof value !== "object") return [];
589
731
  const source = sources.get(value);
@@ -593,8 +735,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
593
735
  ...(failed === undefined ? [] : findFailedSources(failed, sources)),
594
736
  ];
595
737
  };
596
- // TLC's replay fingerprints the states it finds, and a value the replay built raises a
597
- // FingerprintException when it fails to.
738
+ // A value the replay built raises a FingerprintException when TLC fails to fingerprint it.
598
739
  const fingerprintReplayed = (state: Value[], callStack: CallStack | undefined) => {
599
740
  for (const value of getFingerprintState(state)) {
600
741
  const error = getFingerprintError(value);
@@ -610,8 +751,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
610
751
  }
611
752
  state.forEach(markFingerprinted);
612
753
  };
613
- // The replay adds the states it hasn't seen to TLC's set of states, which already holds the state
614
- // that failed after TLC added it.
754
+ // TLC's set of states already holds the state that failed.
615
755
  const createReplayedStates = () => {
616
756
  const replayed = unstoredState.fingerprint ? [unstoredState.fingerprint] : [];
617
757
  return (state: Value[], callStack: CallStack | undefined) => {
@@ -626,12 +766,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
626
766
  return true;
627
767
  };
628
768
  };
629
- // TLC's DoInitFunctor reports its progress again as it replays the initial states, and adds each
630
- // one it hasn't seen to the behavior graph. After a FingerprintException, it only counts the
631
- // 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.
632
771
  const replayInit = () => {
633
772
  const replayed = { count: 0 };
634
- const deferred: TlaEvaluationError[] = [];
773
+ const deferred: unknown[] = [];
635
774
  const addReplayed = createReplayedStates();
636
775
  return getReplayFailure((tracing) => {
637
776
  replayInitialStates(
@@ -661,9 +800,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
661
800
  throw STOP_REPLAY;
662
801
  }
663
802
  } catch (error) {
664
- if (!(error instanceof TlaEvaluationError) || !tracing.callStack?.fingerprint) {
665
- throw error;
666
- }
803
+ const isFingerprintFailure =
804
+ error instanceof TlaEvaluationError && tracing.callStack?.fingerprint !== undefined;
805
+ if (!isFingerprintFailure && !isStackOverflow(error)) throw error;
667
806
  deferred.push(error);
668
807
  }
669
808
  },
@@ -671,8 +810,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
671
810
  if (deferred.length > 0) throw deferred[0];
672
811
  });
673
812
  };
674
- // TLC replays the expansion of a state with ModelChecker.doNext, which writes each successor in
675
- // the model to the -dump state graph again.
813
+ // TLC's replay writes each successor in the model to the -dump state graph again.
676
814
  const replayNext = (index: number) =>
677
815
  getReplayFailure((tracing) => {
678
816
  const state = states[index];
@@ -686,9 +824,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
686
824
  source,
687
825
  getGraphState(next, depths[index] + 1),
688
826
  !isUnseen,
689
- isNamingEdges
690
- ? { name: action.name, signature: getActionSignature(action) }
691
- : undefined,
827
+ isNamingEdges ? getGraphAction(action) : undefined,
692
828
  );
693
829
  }
694
830
  return isUnseen;
@@ -716,33 +852,37 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
716
852
  getSuccessors: (source, state) => {
717
853
  const successors: LiveSuccessor[] = [];
718
854
  if (spec.next === undefined) return successors;
719
- // The constraints read the level of the state whose successors they check, as when TLC
720
- // explored it.
855
+ // The constraints read the level of the state whose successors they check.
721
856
  const livenessSource = current.livenessSource;
722
857
  current.livenessSource = source;
723
- forEachSuccessor(
724
- spec.next,
725
- state,
726
- environment,
727
- (successor) => {
728
- canonicalizeState(successor.state);
729
- const isInModel =
730
- search.satisfiesConstraints(successor.state, state) &&
731
- search.satisfiesActionConstraints(state, successor.state);
732
- if (!isInModel) return false;
733
- const fingerprintState = getFingerprintState(successor.state);
734
- const index = findStateIndex(getStateHash(fingerprintState), fingerprintState);
735
- successors.push({ index, state: successor.state });
736
- return false;
737
- },
738
- spec.scope,
739
- );
740
- 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
+ }
741
879
  return successors;
742
880
  },
743
881
  }),
744
882
  ),
745
883
  );
884
+ // ModelChecker rejects a temporal property whose negation has no solution.
885
+ if (liveness?.branches === 0) throw createTautologyError();
746
886
  // TLC 1.7.4 creates its model checker, which TLCGet reads, once it has built the liveness checker.
747
887
  runtime.isStarted = true;
748
888
  const isCanonicalizedFirst = search.isSymmetric || liveness !== undefined;
@@ -752,64 +892,68 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
752
892
  const parents: number[] = [];
753
893
  const actions: (string | undefined)[] = [];
754
894
  const depths: number[] = [];
755
- // A Map holds at most 2^24 entries, so an open-addressing table keeps each seen state's hash
756
- // 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.
757
896
  const seenStates = { slots: new Int32Array(1 << 17), size: 0, shift: 16 };
758
897
  const canonicalizeState = createCanonicalizer();
759
898
 
760
- const toRecord = (state: Value[]): Record<string, Value> =>
761
- Object.fromEntries(
762
- search.getTlcOrder().map((index) => [environment.variables[index], state[index]]),
763
- );
899
+ const toRecord = search.toRecord;
764
900
  const getAliasState = (
765
901
  alias: string,
766
902
  steps: Successor[],
767
903
  position: number,
768
904
  loopStart: number | undefined,
769
905
  ) => {
770
- // 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;
771
910
  runtime.getLevel = () => position + 1;
772
911
  runtime.getBehavior = () => steps.slice(0, position + 1).map((step) => step.state);
773
- return evaluateAlias(
774
- alias,
775
- steps[position].state,
776
- (steps[position + 1] ?? steps[loopStart ?? position]).state,
777
- );
778
- };
779
- const evaluateAlias = (alias: string, state: Value[], next: Value[] | undefined) => {
780
912
  try {
781
- const body = getConfigDefinition("alias", alias, environment).body;
782
- const value = evaluate(createIdentifier(alias), getContext(environment, state, next));
783
- const fieldOrder = body.kind === "Record" ? body.fields.map((field) => field.name) : [];
784
- return toAliasRecord(value, fieldOrder) ?? toRecord(state);
785
- } catch (error) {
786
- if (!(error instanceof TlaConfigError || error instanceof TlaEvaluationError)) throw error;
787
- return {
788
- ...toRecord(state),
789
- _ALIASEvalError: formatNestedMessage(error.message, options.isTool ?? false),
790
- };
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;
791
921
  }
792
922
  };
793
- // TLC finds the action of a step as the first action that takes it, evaluated as when the search
794
- // 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.
795
927
  const findStepAction = (index: number, previous: Value[], state: Value[], isHeld: boolean) => {
796
928
  const actions = getSpecNextActions();
797
929
  const expanding = { ...current };
798
- 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
+ });
799
936
  const getKey = isHeld ? (values: Value[]) => values : getFingerprintState;
800
937
  const key = getKey(state);
801
- const action = actions.find((item) =>
802
- getSuccessors(item.expression, previous, environment, item.scope).some((successor) =>
803
- isSameState(getKey(successor.state), key),
804
- ),
805
- );
806
- Object.assign(current, expanding);
807
- 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
+ }
808
953
  };
809
- // Before TLC prints a trace, it rebuilds from the initial predicate the states it does not keep,
810
- // all but the last `known` ones. As it prints each later step, it finds the action that takes
811
- // the step. Then it rebuilds the trace once more, unless the trace is a liveness counterexample
812
- // 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.
813
957
  const toTrace = (
814
958
  steps: Successor[],
815
959
  path: number[],
@@ -834,9 +978,26 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
834
978
  );
835
979
  const outputs = stepActions.map((step) => step.lines);
836
980
  const loopStart = traceOptions.loopStart;
837
- // 1.7.4's LiveWorker#printTrace rebuilds a lasso up to the start of its cycle at once, and then
838
- // 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.
839
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
+ }
840
1001
  const prefixOutput = rebuilt > 0 ? [initialOutput, ...outputs.slice(1, rebuilt)].flat() : [];
841
1002
  return {
842
1003
  trace: steps.map((step, position) => {
@@ -858,11 +1019,12 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
858
1019
  traceOutput: known > 0 && !is174 ? [initialOutput, ...outputs].flat() : [],
859
1020
  };
860
1021
  };
861
- const getSpecInitialStates = () =>
862
- spec.init === undefined ? [] : getInitialStates(spec.init, environment, spec.scope);
863
- // TLC's Tool#getState rebuilds a successor action by action, up to the first action that
864
- // generates it. A trace keeps what the spec prints as TLC rebuilds it, so finding its states
865
- // 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.
866
1028
  const findTraceSuccessor = (state: Value[], isMatch: (successor: Successor) => boolean) =>
867
1029
  captureOutput(() => {
868
1030
  for (const action of getSpecNextActions()) {
@@ -891,7 +1053,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
891
1053
  steps.push({ state: previous, action: "Stuttering" });
892
1054
  continue;
893
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]] };
894
1059
  const successor = findSuccessorWithFingerprint(previous, path[position]);
1060
+ current.rebuilt = rebuilt;
895
1061
  if (!successor) throw new TlaEvaluationError(nextFailure);
896
1062
  steps.push(successor);
897
1063
  }
@@ -914,24 +1080,45 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
914
1080
  : lastSuccessor.action;
915
1081
  return toTrace([...steps, { state: lastSuccessor.state, action }], path, { known: 2 });
916
1082
  };
917
- // TLC prints a lone initial state without the alias. TLCTrace#getTrace still recovers it from the
918
- // 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.
919
1085
  const getStateTrace = (index: number): Behavior =>
920
1086
  parents[index] === -1
921
1087
  ? {
922
- 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
+ ],
923
1103
  traceOutput: is174 ? [] : captureOutput(getSpecInitialStates).lines,
924
1104
  }
925
1105
  : getTrace(index);
926
- // TLC rebuilds the trace again for the postcondition after it prints a violation, but not after
927
- // 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
+ };
928
1116
  const getFailedTrace = (index: number, successor: Successor): Behavior => ({
929
1117
  trace: getTrace(index, successor).trace,
930
1118
  });
931
1119
  // TLC names the initial state it was checking unless a standard module's Java code failed.
932
1120
  const getFailureExitCode = (error: TlaEvaluationError, failureOptions: FailureOptions) => {
933
- // TLC 1.7.4 exits with the result of its replay of the initial states, which only fails again
934
- // 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.
935
1122
  if (
936
1123
  failureOptions.isInitial &&
937
1124
  !failureOptions.callStack &&
@@ -950,11 +1137,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
950
1137
  getExitCode(error) ?? (error instanceof TlaModuleError ? error.exitCode : EXIT_STATUS.error)
951
1138
  );
952
1139
  }
953
- // TLC exits with the code of a failed replay of the initial states regardless of the error, as
954
- // 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.
955
1141
  return failureOptions.isInitial || failureOptions.fingerprint
956
1142
  ? EXIT_STATUS.specEvaluationFailure
957
- : getReplayExitCode(error);
1143
+ : getReplayExitCode(failureOptions.replayError ?? error);
958
1144
  };
959
1145
  const createFailureResult = (
960
1146
  failed: unknown,
@@ -988,21 +1174,27 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
988
1174
  outDegrees: failureOptions.outDegrees,
989
1175
  };
990
1176
  };
991
- // TLC reports a successor state that an action leaves incomplete with the trace to it, which ends
992
- // 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.
993
1178
  const reportIncompleteSuccessor = (index: number, error: TlaIncompleteSuccessorError) => {
994
1179
  runtime.generatedStates++;
995
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.
996
1184
  const action =
997
- actions.length === 1 ? actions[0] : actions.find((item) => item.name === error.action);
998
- const missing = error.variables;
999
- const subject =
1000
- actions.length === 1
1001
- ? "the next-state action"
1002
- : `action ${error.action} of the next-state relation`;
1003
- // TLC 1.7.4 says a variable is not assigned rather than not defined.
1004
- const verb = is174 ? "assigned" : "defined";
1005
- 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
+ );
1006
1198
  const undefinedValue = createModelValue("null");
1007
1199
  const partial = error.state.map((value) => value ?? undefinedValue);
1008
1200
  const failure = createFailureResult(error, getStateTrace(index));
@@ -1085,8 +1277,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1085
1277
  }
1086
1278
  insertSeen(hash, index + 1);
1087
1279
  };
1088
- // A new successor that TLC has added to its set of states before it checks the successor, which
1089
- // the check stores after.
1280
+ // TLC adds a new successor to its states before it checks it, which the check stores after.
1090
1281
  const unstoredState = { fingerprint: undefined as Value[] | undefined };
1091
1282
  const countDistinctState = (depth: number) => {
1092
1283
  runtime.distinctStates = states.length + 1;
@@ -1113,6 +1304,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1113
1304
  candidate: undefined as Value[] | undefined,
1114
1305
  candidateLevel: 0,
1115
1306
  livenessSource: -1,
1307
+ rebuilt: undefined as { state: Value[]; level: number } | undefined,
1116
1308
  };
1117
1309
  const getPath = (index: number): Value[][] =>
1118
1310
  index === -1 ? [] : [...getPath(parents[index]), states[index]];
@@ -1135,6 +1327,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1135
1327
  const explored = source !== -1 ? source : current.isExpanding ? current.index : -1;
1136
1328
  return explored === -1 ? 0 : depths[explored];
1137
1329
  }
1330
+ const rebuilt = current.rebuilt;
1331
+ if (rebuilt) return state === rebuilt.state ? rebuilt.level : rebuilt.level + 1;
1138
1332
  if (source !== -1) return state === states[source] ? depths[source] : depths[source] + 1;
1139
1333
  if (state === current.candidate) return current.candidateLevel;
1140
1334
  if (current.index === -1) return 0;
@@ -1142,6 +1336,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1142
1336
  return current.isExpanding ? depths[current.index] + 1 : 0;
1143
1337
  };
1144
1338
 
1339
+ const getGraphAction = (action: SpecAction) => ({
1340
+ name: action.name,
1341
+ signature: getActionSignature(action),
1342
+ });
1145
1343
  const getGraphState = (state: Value[], level: number): GraphState => ({
1146
1344
  fingerprint: BigInt.asIntN(64, runtime.getFingerprint(state)),
1147
1345
  level,
@@ -1233,9 +1431,22 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1233
1431
  source,
1234
1432
  getGraphState(successor.state, depths[index] + 1),
1235
1433
  existing !== -1,
1236
- action && { name: action.name, signature: getActionSignature(action) },
1434
+ action && getGraphAction(action),
1237
1435
  );
1238
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
+ }
1239
1450
  if (existing !== -1 && liveness) {
1240
1451
  const stored = states[existing];
1241
1452
  const isStored = stored.every((value, position) => value === successor.state[position]);
@@ -1248,6 +1459,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1248
1459
  if (isNew) {
1249
1460
  countDistinctState(depths[index] + 1);
1250
1461
  expansion.newStates++;
1462
+ if (coverage) coverage.secondary[coveredAction.node]++;
1251
1463
  }
1252
1464
  if (existing === -1) {
1253
1465
  try {
@@ -1259,9 +1471,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1259
1471
  if (violation) reportContinuedViolation("invariant-violation", violation);
1260
1472
  } catch (error) {
1261
1473
  if (isStackOverflow(error)) throw error;
1262
- // TLC replays the expansion and skips the invariants of a state it has seen, the failed one
1263
- // included unless the constraints exclude it. When the replay fails, TLC reports where and
1264
- // 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.
1265
1476
  const replay = captureOutput(() => replayNext(index));
1266
1477
  return createFailureResult(
1267
1478
  error,
@@ -1280,6 +1491,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1280
1491
  }
1281
1492
  if (propertyViolation) reportContinuedViolation("liveness-violation", propertyViolation);
1282
1493
  if (!isNew) return undefined;
1494
+ if (coverage) countCoverageVariables(coverage, successor.state);
1283
1495
  if (!isCanonicalizedFirst) canonicalizeState(successor.state);
1284
1496
  markSeen(hash, states.length);
1285
1497
  addState(successor.state, fingerprintState, index, successor.action);
@@ -1288,38 +1500,64 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1288
1500
  };
1289
1501
 
1290
1502
  const outcome: { result: CheckResult | undefined } = { result: undefined };
1503
+ const coveredAction = { node: -1 };
1291
1504
  if (liveness) {
1292
1505
  options.onProgress?.({ kind: "liveness-prepared", branches: liveness.branches });
1293
1506
  }
1294
- // TLC checks the assumptions once it has built the liveness checker in ModelChecker's
1295
- // constructor.
1507
+ // TLC checks the assumptions once it has built the liveness checker.
1296
1508
  const assumptionViolation = findViolatedAssumption();
1297
1509
  if (assumptionViolation) return createResult("assumption-violation", assumptionViolation);
1298
1510
  options.onProgress?.({ kind: "initial-states-started" });
1299
1511
  if (spec.init !== undefined) {
1300
- try {
1301
- forEachInitialState(
1302
- spec.init,
1303
- environment,
1304
- (state) => {
1305
- reportInitialStatesProgress(runtime.initialStates, options.onProgress);
1306
- try {
1307
- outcome.result = visitInitialState(state);
1308
- } catch (error) {
1309
- const replay = captureOutput(replayInit);
1310
- outcome.result = createFailureResult(
1311
- error,
1312
- { trace: [], traceOutput: replay.lines },
1313
- { initialState: state, ...replay.result, isInitial: true },
1314
- );
1315
- }
1316
- return outcome.result !== undefined;
1317
- },
1318
- 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 },
1319
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
+ }
1320
1559
  } catch (error) {
1321
- // TLC prints an illegal initial state with null for each variable it leaves undefined, and
1322
- // stops before it prints the statistics.
1560
+ // TLC prints null for each undefined variable and stops before the statistics.
1323
1561
  if (error instanceof TlaIllegalStateError) {
1324
1562
  const illegal = createFailureResult(
1325
1563
  error,
@@ -1359,15 +1597,33 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1359
1597
  }
1360
1598
  return createSuccess();
1361
1599
  }
1362
- // TLC labels and colors an edge of the -dump state graph by the action that generated it. When
1363
- // 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.
1364
1602
  const isNamingEdges = Boolean(
1365
1603
  options.dump?.dot && (options.dump.actionLabels || options.dump.colorize),
1366
1604
  );
1367
1605
  const forEachActionSuccessor = (
1368
1606
  state: Value[],
1607
+ onUnsatisfied:
1608
+ | ((successor: Value[], conjunct: Expression, action?: SpecAction) => void)
1609
+ | undefined,
1369
1610
  onSuccessor: (successor: Successor, action: SpecAction | undefined) => boolean,
1370
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
+ }
1371
1627
  if (!isNamingEdges) {
1372
1628
  return forEachSuccessor(
1373
1629
  next,
@@ -1375,6 +1631,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1375
1631
  environment,
1376
1632
  (successor) => onSuccessor(successor, undefined),
1377
1633
  spec.scope,
1634
+ undefined,
1635
+ onUnsatisfied,
1378
1636
  );
1379
1637
  }
1380
1638
  const progress = { isStopped: false };
@@ -1391,13 +1649,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1391
1649
  return progress.isStopped;
1392
1650
  },
1393
1651
  action.scope,
1652
+ undefined,
1653
+ onUnsatisfied && ((successor, conjunct) => onUnsatisfied(successor, conjunct, action)),
1394
1654
  )
1395
1655
  );
1396
1656
  }, 0);
1397
1657
  };
1398
- // TLC's worker adds a state to the behavior graph even after its next states fail or violate a
1399
- // property, and prints the call stack of an error in that, unless the error is a
1400
- // 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.
1401
1660
  const getLiveCallStack = (index: number, liveSuccessors: LiveSuccessor[]) => {
1402
1661
  if (!liveness || is174) return undefined;
1403
1662
  const replay = getReplayFailure((tracing) =>
@@ -1405,9 +1664,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1405
1664
  );
1406
1665
  return replay?.callStack.length && !replay.fingerprint ? replay.callStack : undefined;
1407
1666
  };
1408
- // TLC's worker adds the state to the behavior graph after it prints the trace. On an error in that,
1409
- // it adds the state again to print the call stack instead of replaying the next-state relation,
1410
- // 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.
1411
1669
  const addFailedLiveState = (index: number, liveSuccessors: LiveSuccessor[]) => {
1412
1670
  try {
1413
1671
  liveness?.addState(index, states[index], liveSuccessors);
@@ -1426,10 +1684,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1426
1684
  const replay = captureOutput(() => replayNext(index));
1427
1685
  return { result: replay.result, lines: [...live.lines, ...replay.lines] };
1428
1686
  };
1429
- // TLC reports a stack overflow while it computes next states without replaying it, with the
1430
- // 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.
1431
1688
  const reportNextStateOverflow = (index: number) =>
1432
- createFailureResult(createStackOverflowError(), getStateTrace(index));
1689
+ createFailureResult(createStackOverflowError(), getStateTrace(index), { isNextState: true });
1433
1690
  // After the trace, TLC replays the next-state relation with its call stack, printing again.
1434
1691
  const reportNextStateFailure = (
1435
1692
  error: unknown,
@@ -1447,7 +1704,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1447
1704
  const expandState = (index: number, liveSuccessors: LiveSuccessor[]) => {
1448
1705
  const state = states[index];
1449
1706
  const source = stateWriter && getGraphState(state, depths[index]);
1450
- 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) => {
1451
1718
  try {
1452
1719
  outcome.result = visitSuccessor(index, successor, liveSuccessors, source, action);
1453
1720
  } catch (error) {
@@ -1455,9 +1722,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1455
1722
  outcome.result = reportNextStateOverflow(index);
1456
1723
  return true;
1457
1724
  }
1458
- // TLC 1.7.4 reports the wrapped error without the trace, except for a failed property,
1459
- // which it reports with the trace before it rethrows. The error stops its worker before it
1460
- // 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.
1461
1727
  const replay = is174
1462
1728
  ? captureOutput(() => replayNext(index))
1463
1729
  : replayFailedNext(index, liveSuccessors);
@@ -1469,11 +1735,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1469
1735
  );
1470
1736
  return true;
1471
1737
  }
1472
- // A successor TLC can't fingerprint fails again as TLC prints it in the trace, which TLC
1473
- // reports as an exception it didn't expect.
1474
- const isTraceFailed = getFingerprintState(successor.state).some(
1475
- (value) => getFingerprintError(value) !== undefined,
1476
- );
1738
+ const isTraceFailed = isUnfingerprintable(successor.state);
1477
1739
  const traceFailure =
1478
1740
  isTraceFailed && error instanceof TlaEvaluationError
1479
1741
  ? getFailureMessage(
@@ -1507,7 +1769,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1507
1769
  }
1508
1770
  if (result) return result;
1509
1771
  const addLiveState = () => {
1510
- if (liveness && source && is174) stateWriter?.writeStuttering(source);
1772
+ if (liveness && source && (is174 || options.dump?.stuttering)) {
1773
+ stateWriter?.writeStuttering(source);
1774
+ }
1511
1775
  const accepted = liveness?.addState(index, state, liveSuccessors);
1512
1776
  if (!liveness || !accepted) return undefined;
1513
1777
  const steps = getPathSteps(accepted);
@@ -1524,9 +1788,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1524
1788
  };
1525
1789
  if (successorCount === 0 && config.checkDeadlock) {
1526
1790
  const deadlock = reportViolation("deadlock", { name: "deadlock", ...getStateTrace(index) });
1527
- // TLC's worker still adds the deadlocked state to the behavior graph after it reports the
1528
- // deadlock, and reports a temporal property that this violates. Then it counts the state as
1529
- // 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.
1530
1793
  const live = captureOutput(() => {
1531
1794
  try {
1532
1795
  return { additional: addLiveState()?.violation };
@@ -1550,8 +1813,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1550
1813
  try {
1551
1814
  return addLiveState();
1552
1815
  } catch (error) {
1553
- // TLC 1.7.4's worker reports an error in adding a state to the behavior graph as an exception
1554
- // 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.
1555
1817
  if (is174 && error instanceof TlaEvaluationError) {
1556
1818
  const unexpected = new TlaEvaluationError(
1557
1819
  `${isEvalException(error) ? UNEXPECTED_EVAL_EXCEPTION : UNEXPECTED_EXCEPTION}${error.message}`,
@@ -1562,8 +1824,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1562
1824
  { outDegrees: getFailureOutDegrees() },
1563
1825
  );
1564
1826
  }
1565
- // TLC's Worker#doNextCheckLiveness adds the state again to find the call stack, prints it
1566
- // 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.
1567
1828
  const replay = getReplayFailure((tracing) =>
1568
1829
  liveness?.addState(index, state, liveSuccessors, tracing),
1569
1830
  );
@@ -1575,7 +1836,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1575
1836
  });
1576
1837
  }
1577
1838
  };
1578
- // TLC's Liveness#printStutteringCounterExampleWarning.
1579
1839
  const getStutteringWarning = () => {
1580
1840
  const name = config.specification;
1581
1841
  const book =
@@ -1631,9 +1891,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1631
1891
  : createActionRecord(findSuccessorWithFingerprint(lastState, cycleStart)?.action),
1632
1892
  );
1633
1893
  };
1634
- const isPeriodic = liveness !== undefined && options.livenessCheck !== "final";
1894
+ const isPeriodic = liveness !== undefined && (options.livenessCheck ?? "default") === "default";
1635
1895
  const startedAt = performance.now();
1636
- 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
+ };
1637
1902
  const findPeriodicViolation = (expanded: number) => {
1638
1903
  const now = performance.now();
1639
1904
  const isGrown = (expanded - periodic.size) / periodic.size > LIVENESS_GROWTH;
@@ -1669,45 +1934,56 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1669
1934
  if (outcome.result) return outcome.result;
1670
1935
  outDegrees[getOutDegreeBucket()]++;
1671
1936
  expansion.newStates = 0;
1672
- // TLC's AbstractChecker#runTLC checks the liveness properties on the state graph so far, then
1673
- // reports how far the search got.
1937
+ // TLC checks liveness on the graph so far, then reports how far the search got.
1674
1938
  if ((isPeriodic || options.onProgress) && performance.now() >= periodic.at) {
1675
1939
  periodic.at = performance.now() + PROGRESS_INTERVAL;
1676
1940
  const lasso = isPeriodic ? findPeriodicViolation(index + 1) : undefined;
1677
1941
  if (liveness && lasso) return reportLasso(liveness, lasso);
1678
- 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
+ });
1679
1952
  }
1680
1953
  }
1681
1954
 
1682
1955
  current.index = -1;
1683
1956
  current.candidate = undefined;
1684
- if (liveness) {
1957
+ const finalLiveness = options.livenessCheck === "off" ? undefined : liveness;
1958
+ if (finalLiveness) {
1685
1959
  options.onProgress?.({
1686
1960
  kind: "liveness-started",
1687
- branches: liveness.branches,
1961
+ branches: finalLiveness.branches,
1688
1962
  isComplete: true,
1689
1963
  states: runtime.distinctStates,
1690
1964
  statistics: createResult("success"),
1691
1965
  });
1692
1966
  }
1693
- const lasso = liveness?.findViolation();
1694
- if (liveness && lasso) return reportLasso(liveness, lasso);
1967
+ const lasso = finalLiveness?.findViolation();
1968
+ if (finalLiveness && lasso) return reportLasso(finalLiveness, lasso);
1695
1969
 
1696
1970
  // TLC finishes the check of the temporal properties before it checks the postconditions.
1697
- if (liveness) options.onProgress?.({ kind: "liveness-finished" });
1698
- try {
1699
- const postcondition = search.findPostconditionViolation();
1700
- if (postcondition) {
1701
- return createResult("postcondition-violation", {
1702
- name: postcondition.name,
1703
- message: postcondition.message,
1704
- counts: postcondition.counts,
1705
- trace: [],
1706
- postcondition,
1707
- });
1708
- }
1709
- } catch (error) {
1710
- 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
+ });
1711
1987
  }
1712
- return createSuccess();
1988
+ return continued.status ? createResult(continued.status) : createSuccess();
1713
1989
  };