tla-ts 0.0.9 → 0.0.10-dev.28c823e4b

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 +106 -10
  8. package/dist/index.d.ts +106 -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 +129 -104
  21. package/dist/transfer.js +129 -104
  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 +4 -23
  26. package/src/bags.ts +99 -102
  27. package/src/builtins.ts +40 -78
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +599 -388
  30. package/src/cli/options.ts +11 -6
  31. package/src/cli/run.ts +0 -2
  32. package/src/cli/runtime-invariants.ts +136 -0
  33. package/src/cli/shared.ts +18 -11
  34. package/src/cli/tlapm.ts +0 -12
  35. package/src/cli/tlc-arguments.ts +640 -0
  36. package/src/cli/tlc-usage.ts +361 -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 +596 -339
  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 +4 -19
  54. package/src/json-reader.ts +455 -0
  55. package/src/json.ts +255 -139
  56. package/src/levels.ts +8 -17
  57. package/src/lexer.ts +80 -100
  58. package/src/liveness-checker.ts +82 -119
  59. package/src/liveness.ts +112 -64
  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 +53 -44
  83. package/src/parser.ts +565 -282
  84. package/src/pcal/ast.ts +53 -86
  85. package/src/pcal/parse.ts +144 -219
  86. package/src/pcal/tokenize.ts +91 -131
  87. package/src/pcal/translate.ts +83 -130
  88. package/src/pcal/validate.ts +48 -68
  89. package/src/pretty-print.ts +7 -8
  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 +81 -35
  336. package/src/resolve.ts +12 -112
  337. package/src/runtime.ts +22 -22
  338. package/src/sany/builtins.ts +2 -5
  339. package/src/sany/generator.ts +149 -252
  340. package/src/sany/levels.ts +6 -34
  341. package/src/sany/lexer.ts +41 -61
  342. package/src/sany/linter.ts +1 -9
  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 +495 -155
  351. package/src/simulate.ts +685 -0
  352. package/src/spec-description.ts +176 -69
  353. package/src/standard-definitions.ts +0 -4
  354. package/src/standard-modules.ts +254 -69
  355. package/src/state-graph.ts +50 -24
  356. package/src/subexpressions.ts +69 -52
  357. package/src/substitution-levels.ts +2 -3
  358. package/src/successors.ts +263 -94
  359. package/src/symmetry.ts +33 -25
  360. package/src/tableau.ts +27 -24
  361. package/src/tlc/fingerprint.ts +183 -67
  362. package/src/tlc/jar-data.ts +112 -6
  363. package/src/tlc/messages.ts +110 -44
  364. package/src/tlc/order.ts +37 -60
  365. package/src/tlc/random.ts +33 -45
  366. package/src/tlc/replay.ts +549 -217
  367. package/src/tlc/summary.ts +36 -47
  368. package/src/tlc/tlc-operators.ts +76 -41
  369. package/src/tlc/tlcext-operators.ts +139 -122
  370. package/src/tlc/trace-spec.ts +269 -0
  371. package/src/tlc/value-stream.ts +139 -0
  372. package/src/tlc/version.ts +1 -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 +780 -337
  390. package/src/worker.ts +7 -8
@@ -430,6 +430,16 @@ export const TLC_RUNTIME_STRINGS = [
430
430
  "levelmean",
431
431
  "levelvariance",
432
432
  "bfs",
433
+ "beginLine",
434
+ "beginColumn",
435
+ "endLine",
436
+ "endColumn",
437
+ "module",
438
+ "name",
439
+ "location",
440
+ "context",
441
+ "parameters",
442
+ "_action",
433
443
  ];
434
444
 
435
445
  export const SANY_NODE_NAMES = [
@@ -550,10 +560,6 @@ export const SANY_NODE_NAMES = [
550
560
  "N_AssertStep",
551
561
  ];
552
562
 
553
- // The standard modules that a spec may ship its own file of, such as CommunityModules' Json.tla,
554
- // which SANY reads in place of its own.
555
- export const USER_STANDARD_MODULES = new Set(["Bags", "Json", "Randomization", "TLCExt"]);
556
-
557
563
  export const TLC_MODULE_SOURCES = new Map([
558
564
  [
559
565
  "Naturals",
@@ -925,9 +931,56 @@ _PrintCounts == PrintT(_Counts)
925
931
  ],
926
932
  ]);
927
933
 
928
- // The Java methods that override standard module operators, as java.lang.reflect.Method prints
929
- // them in TLC's errors.
930
934
  export const TLC_JAVA_METHODS = new Map([
935
+ [
936
+ "Bags",
937
+ new Map([
938
+ [
939
+ "IsABag",
940
+ "public static tlc2.value.IBoolValue tlc2.module.Bags.IsABag(tlc2.value.impl.Value)",
941
+ ],
942
+ [
943
+ "BagCardinality",
944
+ "public static tlc2.value.impl.IntValue tlc2.module.Bags.BagCardinality(tlc2.value.impl.Value)",
945
+ ],
946
+ [
947
+ "BagIn",
948
+ "public static tlc2.value.IBoolValue tlc2.module.Bags.BagIn(tlc2.value.impl.Value,tlc2.value.impl.Value)",
949
+ ],
950
+ [
951
+ "CopiesIn",
952
+ "public static tlc2.value.impl.IntValue tlc2.module.Bags.CopiesIn(tlc2.value.impl.Value,tlc2.value.impl.Value)",
953
+ ],
954
+ [
955
+ "\\oplus",
956
+ "public static tlc2.value.impl.Value tlc2.module.Bags.BagCup(tlc2.value.impl.Value,tlc2.value.impl.Value)",
957
+ ],
958
+ [
959
+ "\\ominus",
960
+ "public static tlc2.value.impl.Value tlc2.module.Bags.BagDiff(tlc2.value.impl.Value,tlc2.value.impl.Value)",
961
+ ],
962
+ [
963
+ "BagUnion",
964
+ "public static tlc2.value.impl.Value tlc2.module.Bags.BagUnion(tlc2.value.impl.Value)",
965
+ ],
966
+ [
967
+ "\\sqsubseteq",
968
+ "public static tlc2.value.IBoolValue tlc2.module.Bags.SqSubseteq(tlc2.value.impl.Value,tlc2.value.impl.Value)",
969
+ ],
970
+ [
971
+ "BagOfAll",
972
+ "public static tlc2.value.impl.Value tlc2.module.Bags.BagOfAll(tlc2.value.impl.Value,tlc2.value.impl.Value)",
973
+ ],
974
+ [
975
+ "BagToSet",
976
+ "public static tlc2.value.impl.Value tlc2.module.Bags.BagToSet(tlc2.value.impl.Value)",
977
+ ],
978
+ [
979
+ "SetToBag",
980
+ "public static tlc2.value.impl.Value tlc2.module.Bags.SetToBag(tlc2.value.impl.Value)",
981
+ ],
982
+ ]),
983
+ ],
931
984
  [
932
985
  "FiniteSets",
933
986
  new Map([
@@ -1023,4 +1076,57 @@ export const TLC_JAVA_METHODS = new Map([
1023
1076
  ],
1024
1077
  ]),
1025
1078
  ],
1079
+ [
1080
+ "TLCExt",
1081
+ new Map([
1082
+ [
1083
+ "AssertError",
1084
+ "public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.assertError(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)",
1085
+ ],
1086
+ [
1087
+ "PickSuccessor",
1088
+ "public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.pickSuccessor(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)",
1089
+ ],
1090
+ [
1091
+ "ToTrace",
1092
+ "public static tlc2.value.impl.Value tlc2.module.TLCExt.lassoOrdinal(tlc2.value.impl.Value)",
1093
+ ],
1094
+ [
1095
+ "CounterExample",
1096
+ "public static tlc2.value.impl.Value tlc2.module.TLCExt.error(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel) throws java.io.IOException",
1097
+ ],
1098
+ [
1099
+ "Trace",
1100
+ "public static tlc2.value.impl.TupleValue tlc2.module.TLCExt.getTrace(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel) throws java.io.IOException",
1101
+ ],
1102
+ [
1103
+ "TLCDefer",
1104
+ "public static tlc2.value.impl.Value tlc2.module.TLCExt.tlcDefer(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)",
1105
+ ],
1106
+ [
1107
+ "TLCNoOp",
1108
+ "public static tlc2.value.impl.Value tlc2.module.TLCExt.tlcNoOp(tlc2.value.impl.Value)",
1109
+ ],
1110
+ [
1111
+ "TLCModelValue",
1112
+ "public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.tlcModelValue(tlc2.value.impl.Value)",
1113
+ ],
1114
+ [
1115
+ "TLCCache",
1116
+ "public static tlc2.value.impl.Value tlc2.module.TLCExt.tlcEval2(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)",
1117
+ ],
1118
+ [
1119
+ "TLCFP",
1120
+ "public static synchronized tlc2.value.impl.IntValue tlc2.module.TLCExt.tlcFingerprint(tlc2.value.impl.Value)",
1121
+ ],
1122
+ [
1123
+ "TLCEvalDefinition",
1124
+ "public static tlc2.value.impl.Value tlc2.module.TLCExt.tlcDefByName(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)",
1125
+ ],
1126
+ [
1127
+ "TLCGetOrDefault",
1128
+ "public static tlc2.value.impl.Value tlc2.module.TLCExt.tlcGetOrDefault(tlc2.value.impl.Value,tlc2.value.impl.Value)",
1129
+ ],
1130
+ ]),
1131
+ ],
1026
1132
  ]);
@@ -1,24 +1,32 @@
1
1
  import {
2
2
  getErrorExitCode,
3
+ getUnexpectedException,
3
4
  STACK_OVERFLOW_MESSAGE,
4
5
  TlaEvaluationError,
5
6
  TlaModuleError,
7
+ TlaSetBoundError,
8
+ TlaStackOverflowError,
9
+ TlaUncodedError,
10
+ TlaWarningAsError,
11
+ TOO_MANY_STATES_MESSAGE,
6
12
  UNEXPECTED_EVAL_EXCEPTION,
7
13
  UNEXPECTED_EXCEPTION,
8
14
  } from "../errors";
9
15
  import { setExitCode } from "../exit-codes";
10
16
  import type { TlcVersion } from "./version";
11
17
 
12
- // TLC's codes for the messages it prints, from tlc2.output.EC.
13
18
  export const MESSAGE_CODE = {
14
19
  general: 1000,
20
+ stackOverflow: 1005,
15
21
  commandLineError: 1102,
16
22
  initialState: 2102,
17
23
  nestedExpression: 2103,
18
24
  assumptionFalse: 2104,
19
25
  assumptionEvaluationError: 2105,
26
+ unchangedVariableChanged: 2143,
20
27
  exceptAppliedToUnknownField: 2144,
21
28
  fingerprintFailed: 2147,
29
+ initialStateIncomplete: 2106,
22
30
  invariantViolatedInitial: 2107,
23
31
  incompleteSuccessor: 2109,
24
32
  propertyViolatedInitial: 2108,
@@ -28,13 +36,20 @@ export const MESSAGE_CODE = {
28
36
  actionPropertyEvaluationFailed: 2113,
29
37
  deadlockReached: 2114,
30
38
  temporalPropertyViolated: 2116,
39
+ noInitialStates: 2118,
40
+ errorState: 2120,
31
41
  behaviorUpToThisPoint: 2121,
32
42
  backToState: 2122,
43
+ subscriptUndetermined: 2139,
44
+ subscriptMissingVariable: 2140,
33
45
  constantLevelInvariant: 2149,
34
46
  javaOverrideLoaded: 2168,
35
47
  starting: 2185,
36
48
  modelChecking: 2187,
49
+ simulating: 2188,
37
50
  finished: 2186,
51
+ traceSpecWritten: 2501,
52
+ traceSpecFailed: 2502,
38
53
  computingInit: 2189,
39
54
  initGenerated1: 2190,
40
55
  initGenerated2: 2191,
@@ -43,14 +58,27 @@ export const MESSAGE_CODE = {
43
58
  searchDepth: 2194,
44
59
  stats: 2199,
45
60
  progress: 2200,
61
+ coverageStart: 2201,
62
+ coverageEnd: 2202,
63
+ coverageValue: 2221,
64
+ depthFirstStats: 2204,
65
+ depthFirstLevel: 2205,
66
+ depthFirstProgress: 2206,
67
+ depthFirstInitGenerated: 2208,
68
+ simulationProgress: 2209,
69
+ simulationStats: 2210,
46
70
  temporalBranches: 2212,
71
+ statePrint1: 2216,
47
72
  statePrint2: 2217,
48
73
  statePrint3: 2218,
49
74
  sanyFinished: 2219,
50
75
  startingSany: 2220,
51
76
  stateLevelProperty: 2255,
77
+ noInitialStatesInModel: 2256,
52
78
  version: 2262,
79
+ depthFirstModelChecking: 2271,
53
80
  noSpecificationButProperty: 2257,
81
+ fairnessTautology: 2258,
54
82
  noFairnessButProperty: 2259,
55
83
  counterExample: 2264,
56
84
  checkingTemporalEnd: 2267,
@@ -62,17 +90,23 @@ export const MESSAGE_CODE = {
62
90
  javaOverrideMismatch: 2400,
63
91
  postconditionFalse: 2404,
64
92
  postconditionFailed: 2405,
93
+ coverageNext: 2772,
94
+ coverageInit: 2773,
95
+ coverageProperty: 2774,
96
+ coverageValueCost: 2775,
97
+ coverageEndOverhead: 2777,
98
+ coverageConstraint: 2778,
99
+ coverageVariable: 2779,
65
100
  possibleUnwitnessed: 2780,
66
101
  parsingFailed: 3002,
67
102
  configFileError: 5001,
103
+ moduleOverrideStdout: 20000,
68
104
  } as const;
69
105
 
70
- // TLC's message levels, from tlc2.output.MP.
71
106
  export const MESSAGE_LEVEL = { none: 0, error: 1, warning: 3, state: 4 } as const;
72
107
 
73
108
  type MessageLevel = (typeof MESSAGE_LEVEL)[keyof typeof MESSAGE_LEVEL];
74
109
 
75
- // Without -tool, TLC starts a message with the prefix of its level.
76
110
  const LEVEL_PREFIXES: Record<MessageLevel, string> = {
77
111
  0: "",
78
112
  1: "Error: ",
@@ -86,14 +120,17 @@ export interface MessagePrinter {
86
120
  print: (code: number, level: MessageLevel, text: string) => void;
87
121
  }
88
122
 
89
- // With -tool, TLC wraps each message in markers that name its code and level, so that a program
90
- // can read the output. Lines outside the markers, such as the output of Print, stay as they are.
91
- // MP.printWarning prints a warning once, which -nowarning drops, and without -tool, TLC follows the
92
- // first warning with how to drop them.
123
+ export const formatMessage = (isTool: boolean, code: number, level: MessageLevel, text: string) =>
124
+ isTool
125
+ ? `@!@!@STARTMSG ${code}:${level} @!@!@\n${text}\n@!@!@ENDMSG ${code} @!@!@`
126
+ : `${LEVEL_PREFIXES[level]}${text}`;
127
+
93
128
  export const createMessagePrinter = (
94
129
  isTool: boolean,
95
130
  isWarningEnabled = true,
96
131
  version: TlcVersion = "master",
132
+ suppressedCodes: number[] = [],
133
+ errorCodes: number[] = [],
97
134
  ): MessagePrinter => {
98
135
  const warnings = new Set<string>();
99
136
  return {
@@ -101,14 +138,16 @@ export const createMessagePrinter = (
101
138
  version,
102
139
  print: (code, level, text) => {
103
140
  const isWarning = level === MESSAGE_LEVEL.warning;
141
+ if (isWarning && errorCodes.includes(code)) {
142
+ throw new TlaWarningAsError(code, text);
143
+ }
104
144
  if (isWarning && !isWarningEnabled) return;
145
+ if (level !== MESSAGE_LEVEL.error && suppressedCodes.includes(code)) return;
105
146
  const hint =
106
147
  isWarning && !isTool && warnings.size === 0
107
148
  ? "\n(Use the -nowarning option to disable this warning.)"
108
149
  : "";
109
- const message = isTool
110
- ? `@!@!@STARTMSG ${code}:${level} @!@!@\n${text}\n@!@!@ENDMSG ${code} @!@!@`
111
- : `${LEVEL_PREFIXES[level]}${text}${hint}`;
150
+ const message = formatMessage(isTool, code, level, `${text}${hint}`);
112
151
  if (isWarning && warnings.has(message)) return;
113
152
  if (isWarning) warnings.add(message);
114
153
  console.log(message);
@@ -116,19 +155,22 @@ export const createMessagePrinter = (
116
155
  };
117
156
  };
118
157
 
119
- // TLC 1.7.4's message for a missing initial predicate, which blames a parameterized INSTANCE as
120
- // well.
121
158
  export const MISSING_INIT_174 =
122
159
  "The configuration file did not specify the initial state predicate.\nCan also be caused by trying to run TLC on a specification from\na module imported with a parameterized INSTANCE statement.";
123
160
 
124
- // The messages that TLC builds from a message code, from tlc2.output.MP, by their code and
125
- // template, with whether TLC throws them as an EvalException rather than a TLCRuntimeException.
126
- // TLC's -tool output wraps such a message in its own markers even inside another message.
127
161
  const CODED_MESSAGES: [code: number, template: string, isEvalException: boolean][] = [
128
162
  [1005, STACK_OVERFLOW_MESSAGE, false],
163
+ [
164
+ 1000,
165
+ "In evaluating TLCExt!Trace, the state is not completely specified yet (variable%1% %2% undefined).",
166
+ false,
167
+ ],
168
+ [1000, "Could not find operator: %1% in module: %2%", false],
129
169
  [2117, "Failed to recover the next state from its fingerprint.", true],
130
170
  [2123, "Failed to recover the initial state from its fingerprint.", true],
131
171
  [2132, "The first argument of Assert evaluated to FALSE; the second argument was:\n%1%", true],
172
+ [2143, "The variable %1% was changed while it is specified as UNCHANGED at\n%2%", false],
173
+ [2144, "The EXCEPT was applied to non-existing fields of the value at\n%1%", false],
132
174
  [2145, "TLCGet(%1%) was undefined.", true],
133
175
  [
134
176
  2154,
@@ -147,8 +189,13 @@ const CODED_MESSAGES: [code: number, template: string, isEvalException: boolean]
147
189
  "Attempted to apply TransitiveClosure to a set containing\nthe following value:\n%1%",
148
190
  true,
149
191
  ],
192
+ [2156, "TLC supports at most %1% model values, but model value %2% exceeds this limit.", false],
193
+ [2156, "tla-ts can't recover a model check from the checkpoint in %1%.", false],
150
194
  [2165, "Choose can only deal with numbers up to %1%", false],
151
195
  [2169, "The %1% argument of %2% should be a %3%, but instead it is:\n%4%", true],
196
+ [2170, "Argument mismatch in operator application.%1%", false],
197
+ [2171, "Parsing or semantic analysis failed.%1%", false],
198
+ [2172, TOO_MANY_STATES_MESSAGE, false],
152
199
  [2176, "Applying %1% to the following value,\nwhich is not %2%:\n%3%", true],
153
200
  [
154
201
  2177,
@@ -207,12 +254,23 @@ const CODED_MESSAGES: [code: number, template: string, isEvalException: boolean]
207
254
  [2233, "The %1% %2% cannot be a constant.", false],
208
255
  [2234, "The operator %1% cannot take any argument.", false],
209
256
  [2235, "The operator %1% is not defined in the spec.", false],
257
+ [2236, "The operator %1%, which equals %2%,\ncannot be used as a %3%", false],
210
258
  [2237, "The spec is trivially false because %1% is false.", false],
211
259
  [2238, "TLC cannot handle subscript %1%", false],
212
260
  [2239, "TLC cannot handle this conjunct of the spec:\n%1%", false],
261
+ [
262
+ 2240,
263
+ "The specification contains more than one conjunct of the form [][Next]_v,\nbut TLC can handle only specifications with one next-state relation.",
264
+ false,
265
+ ],
213
266
  [2241, "The property %1% is not correctly defined.", false],
214
267
  [2242, "The arity of the operator %1% is inconsistent in the configuration file.", false],
215
268
  [2244, "TLC can't handle real numbers.\n%1%", false],
269
+ [
270
+ 2245,
271
+ "In the configuration file, the module name %1% is not a module in the specification.",
272
+ false,
273
+ ],
216
274
  [2247, "In computing %1%, TLC expected a %2% expression,\nbut instead found %3%.\n%4%", false],
217
275
  [2248, "In computing %1%, TLC expected a %2% expression,\nbut didn't find one.\n%3%", false],
218
276
  [2260, "In computing ENABLED, TLC encountered a temporal formula (%1%).\n%2%", false],
@@ -223,6 +281,21 @@ const CODED_MESSAGES: [code: number, template: string, isEvalException: boolean]
223
281
  ],
224
282
  [2265, "TLC can't handle a number this big.\n%1%", false],
225
283
  [2266, "The %1% argument of %2% should be an %3%, but instead it is:\n%4%", true],
284
+ [
285
+ 2272,
286
+ "The formula %1% at %2% is an action-level formula (i.e., it contains no temporal operators). Only temporal-level (or state-level) formulas are allowed under PROPERTY or PROPERTIES. To check that action %1% holds in *every* step of the behavior, define a temporal property: Let A be the formula at %2%; rewrite A as [][A]_v, where v is a state function (typically the tuple of variables) (compare page 90 of Specifying Systems at https://lamport.azurewebsites.net/tla/book.html).",
287
+ false,
288
+ ],
289
+ [
290
+ 2273,
291
+ 'The formula %1% at %2% is an action-level formula (i.e., it contains no temporal operators). Only temporal-level (or state-level) formulas are allowed under PROPERTY or PROPERTIES. To check that action %1% holds in *every* step of the behavior, define a temporal property by applying the "always" temporal operator ([]) to the formula at %2% (compare page 90 of Specifying Systems at https://lamport.azurewebsites.net/tla/book.html).',
292
+ false,
293
+ ],
294
+ [
295
+ 2274,
296
+ 'The formula %1% at %2% is an action-level formula (i.e., it contains no temporal operators). Only temporal-level (or state-level) formulas are allowed under PROPERTY or PROPERTIES. To check that infinitely many %1% steps occur, define a temporal property by applying the "always eventually" temporal operator combination ([]<>) to the formula at %2% (compare page 91 of Specifying Systems at https://lamport.azurewebsites.net/tla/book.html).',
297
+ false,
298
+ ],
226
299
  [2280, "In evaluation, the identifier %1% is either undefined or not an operator.\n%2%", false],
227
300
  [2281, "The configuration file substitutes constant %1% with non-constant %2%%3%", false],
228
301
  [2283, "The argument of %1% should be a %2%, but instead it is:\n%3%", true],
@@ -249,6 +322,8 @@ const CODED_MESSAGES: [code: number, template: string, isEvalException: boolean]
249
322
  [5007, "TLC found an error in the configuration file:\n%1%", false],
250
323
  // The general message is a prefix of the others above.
251
324
  [5002, "TLC found an error in the configuration file at line %1%\n", false],
325
+ [2250, "A state predicate was evaluated to a non-boolean value.", false],
326
+ [2252, "Encountered an action predicate that's not a boolean.", false],
252
327
  [2253, "Temporal formula is a tautology (its negation is unsatisfiable).", false],
253
328
  [
254
329
  2301,
@@ -262,12 +337,10 @@ interface CodedMessage {
262
337
  isEvalException: boolean;
263
338
  }
264
339
 
265
- const codedMessagePatterns = {
266
- value: undefined as { pattern: RegExp; message: CodedMessage }[] | undefined,
267
- };
340
+ let codedMessagePatterns: { pattern: RegExp; message: CodedMessage }[] | undefined;
268
341
 
269
342
  const getCodedMessagePatterns = () =>
270
- (codedMessagePatterns.value ??= CODED_MESSAGES.map(([code, template, isEvalException]) => ({
343
+ (codedMessagePatterns ??= CODED_MESSAGES.map(([code, template, isEvalException]) => ({
271
344
  pattern: new RegExp(
272
345
  `^${template
273
346
  .split(/%\d+%/)
@@ -277,33 +350,27 @@ const getCodedMessagePatterns = () =>
277
350
  message: { code, isEvalException },
278
351
  })));
279
352
 
280
- // The overflows of SetOfFcnsValue and SetOfTuplesValue, which TLC raises with a plain message that
281
- // reads like the coded overflow of SetOfRcdsValue and SubsetValue.
282
353
  const UNCODED_MESSAGE_PATTERN =
283
- /^Overflow when computing the number of elements in( |:\n\[(?![A-Za-z0-9_]+ : ))/;
354
+ /^Overflow when computing the number of elements in( |:\n\[(?![A-Za-z0-9_]+: ))|\nis an element of a set of \d+-tuples\.$|^In computing ENABLED, TLC encountered a temporal formula \(a (~> b|-\+-> formula)\)\./;
284
355
 
285
356
  export const getCodedMessage = (text: string): CodedMessage | undefined =>
286
357
  UNCODED_MESSAGE_PATTERN.test(text)
287
358
  ? undefined
288
359
  : getCodedMessagePatterns().find((item) => item.pattern.test(text))?.message;
289
360
 
290
- // Whether TLC raises an error as an EvalException, which only a standard module's Java code throws,
291
- // rather than as the TLCRuntimeException of every Assert.fail.
292
361
  export const isEvalException = (error: TlaEvaluationError) =>
293
362
  error instanceof TlaModuleError || getCodedMessage(error.message)?.isEvalException === true;
294
363
 
295
- // The messages that end with the message of the error they report, after this text.
296
364
  const INNER_MESSAGE_PREFIXES = new Map([
297
- // "The exception was a <class>\n: "
298
365
  [1000, "\n: "],
299
366
  [2105, "failed.\n"],
300
367
  [2154, "but it produced the following error:\n"],
368
+ [2171, "Parsing or semantic analysis failed."],
301
369
  [2213, ":\n"],
302
370
  [2281, " - specifically: "],
371
+ [2405, "failed.\n"],
303
372
  ]);
304
373
 
305
- // The text of a coded message with the message of the error it reports marked in -tool output, as
306
- // TLC's message holds that error's text as TLC printed it.
307
374
  export const formatInnerMessage = (code: number, text: string, isTool: boolean) => {
308
375
  const prefix = isTool ? INNER_MESSAGE_PREFIXES.get(code) : undefined;
309
376
  const index = prefix === undefined ? -1 : text.indexOf(prefix);
@@ -312,7 +379,6 @@ export const formatInnerMessage = (code: number, text: string, isTool: boolean)
312
379
  return `${text.slice(0, end)}${formatNestedMessage(text.slice(end), isTool)}`;
313
380
  };
314
381
 
315
- // The text of an error's message as TLC prints it inside another message.
316
382
  export const formatNestedMessage = (text: string, isTool: boolean): string => {
317
383
  const code = isTool ? getCodedMessage(text)?.code : undefined;
318
384
  return code === undefined
@@ -322,7 +388,6 @@ export const formatNestedMessage = (text: string, isTool: boolean): string => {
322
388
 
323
389
  const zeroPad = (value: number) => String(value).padStart(2, "0");
324
390
 
325
- // TLC's convertRuntimeToHumanReadable: a duration in its two largest units.
326
391
  export const formatTlcDuration = (milliseconds: number) => {
327
392
  const seconds = Math.floor(milliseconds / 1000) % 60;
328
393
  const minutes = Math.floor(milliseconds / 60_000) % 60;
@@ -334,12 +399,9 @@ export const formatTlcDuration = (milliseconds: number) => {
334
399
  : `${zeroPad(seconds)}s`;
335
400
  };
336
401
 
337
- // TLC's SimpleDateFormat("yyyy-MM-dd HH:mm:ss") in the local time zone.
338
402
  export const formatTlcDate = (date: Date) =>
339
403
  `${date.getFullYear()}-${zeroPad(date.getMonth() + 1)}-${zeroPad(date.getDate())} ${zeroPad(date.getHours())}:${zeroPad(date.getMinutes())}:${zeroPad(date.getSeconds())}`;
340
404
 
341
- // An error that TLC reports with a message of its own, by that message's code and first line, and
342
- // the error whose message follows.
343
405
  interface HeadedError {
344
406
  code: number;
345
407
  headline: string;
@@ -360,18 +422,16 @@ export const withHeadline = (error: unknown, code: number, headline: string) =>
360
422
 
361
423
  export const isHeadedError = (error: Error) => headedErrors.has(error);
362
424
 
425
+ const WRONG_INVOCATION_EXCEPTION = getUnexpectedException("util.WrongInvocationException");
426
+
363
427
  const UNEXPECTED_HEADLINE = UNEXPECTED_EXCEPTION.slice(0, UNEXPECTED_EXCEPTION.indexOf("\n"));
364
428
 
365
- // TLC 1.7.4's Worker wraps an error in adding a successor in a RuntimeException, whose message
366
- // names the class of the error.
367
429
  const WRAPPED_EVAL_EXCEPTION = `${UNEXPECTED_EXCEPTION}tlc2.tool.EvalException: `;
368
430
  const WRAPPED_RUNTIME_EXCEPTION = `${UNEXPECTED_EXCEPTION}util.Assert$TLCRuntimeException: `;
369
431
 
370
432
  export const getWrappedException = (error: TlaEvaluationError) =>
371
433
  isEvalException(error) ? WRAPPED_EVAL_EXCEPTION : WRAPPED_RUNTIME_EXCEPTION;
372
434
 
373
- // TLC reports an EvalException, or a TLCRuntimeException without a message of its own, as an
374
- // exception it didn't expect.
375
435
  export const withUnexpectedException = <Result>(compute: () => Result) => {
376
436
  try {
377
437
  return compute();
@@ -392,19 +452,15 @@ const UNEXPECTED_EXCEPTION_PREFIXES = [
392
452
  UNEXPECTED_EVAL_EXCEPTION,
393
453
  ];
394
454
 
395
- // The text of an error's message, with the message of a coded error inside it marked in -tool
396
- // output as TLC marks it.
397
455
  const formatErrorMessage = (error: TlaEvaluationError, isTool: boolean): string => {
398
456
  const headed = headedErrors.get(error);
399
457
  if (headed) return `${headed.headline}\n${formatErrorMessage(headed.inner, isTool)}`;
400
458
  const message = error.message;
459
+ if (error instanceof TlaUncodedError) return message;
401
460
  const prefix = UNEXPECTED_EXCEPTION_PREFIXES.find((start) => message.startsWith(start)) ?? "";
402
461
  return `${prefix}${formatNestedMessage(message.slice(prefix.length), isTool)}`;
403
462
  };
404
463
 
405
- // How TLC reports an error: with the code of its own message for an error that it reports with a
406
- // headline; and, when the error escapes the computation of next states, with the code of an
407
- // EvalException, or as an unexpected exception for any other error.
408
464
  export interface FailureMessage {
409
465
  code: number;
410
466
  message: string;
@@ -424,6 +480,13 @@ export const getFailureMessage = (
424
480
  toolMessage: formatErrorMessage(error, true),
425
481
  };
426
482
  }
483
+ if (error instanceof TlaStackOverflowError) {
484
+ return {
485
+ code: isNextState ? MESSAGE_CODE.stackOverflow : MESSAGE_CODE.general,
486
+ message,
487
+ toolMessage: message,
488
+ };
489
+ }
427
490
  if (isNextState && isEvalException(error)) {
428
491
  return {
429
492
  code: getCodedMessage(message)?.code ?? MESSAGE_CODE.general,
@@ -431,8 +494,11 @@ export const getFailureMessage = (
431
494
  toolMessage: message,
432
495
  };
433
496
  }
434
- const isUnexpected = isNextState && !message.startsWith(UNEXPECTED_HEADLINE);
435
- const prefix = isUnexpected ? UNEXPECTED_EXCEPTION : "";
497
+ const isUnexpected =
498
+ isNextState && !message.startsWith(UNEXPECTED_HEADLINE) && !(error instanceof TlaUncodedError);
499
+ const exception =
500
+ error instanceof TlaSetBoundError ? WRONG_INVOCATION_EXCEPTION : UNEXPECTED_EXCEPTION;
501
+ const prefix = isUnexpected ? exception : "";
436
502
  return {
437
503
  code: MESSAGE_CODE.general,
438
504
  message: `${prefix}${message}`,