tla-ts 0.0.3 → 0.0.4-dev.2a873ee

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 (370) hide show
  1. package/README.md +46 -115
  2. package/dist/cli.cjs +1 -1
  3. package/dist/cli.js +1 -1
  4. package/dist/deciders.cjs +366 -0
  5. package/dist/deciders.js +366 -0
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +194 -8
  8. package/dist/index.d.ts +194 -8
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -4
  11. package/dist/parallel-worker.js +1 -4
  12. package/dist/prove-worker.cjs +9 -0
  13. package/dist/prove-worker.d.cts +9 -0
  14. package/dist/prove-worker.d.ts +9 -0
  15. package/dist/prove-worker.js +9 -0
  16. package/dist/prove.cjs +996 -0
  17. package/dist/prove.js +996 -0
  18. package/dist/run-cli.cjs +37 -20
  19. package/dist/run-cli.js +37 -20
  20. package/dist/tlapm.cjs +10 -0
  21. package/dist/tlapm.js +10 -0
  22. package/dist/transfer.cjs +1387 -18
  23. package/dist/transfer.js +1387 -18
  24. package/dist/worker.cjs +21 -0
  25. package/dist/worker.js +21 -0
  26. package/package.json +24 -11
  27. package/src/ast.ts +149 -8
  28. package/src/bags.ts +4 -7
  29. package/src/builtins.ts +29 -11
  30. package/src/bundled-modules.ts +3 -3
  31. package/src/canonical.ts +4 -3
  32. package/src/check.ts +1540 -235
  33. package/src/cli-options.ts +12 -6
  34. package/src/cli.ts +8 -1
  35. package/src/codegen.ts +98 -39
  36. package/src/config.ts +254 -181
  37. package/src/dependencies.ts +2 -2
  38. package/src/environment.ts +540 -140
  39. package/src/errors.ts +284 -4
  40. package/src/evaluate.ts +1043 -293
  41. package/src/exit-codes.ts +22 -43
  42. package/src/fingerprints.ts +46 -11
  43. package/src/index.ts +11 -0
  44. package/src/instances.ts +19 -16
  45. package/src/java-overrides.ts +104 -25
  46. package/src/levels.ts +191 -45
  47. package/src/lexer.ts +127 -30
  48. package/src/live-check.ts +867 -0
  49. package/src/liveness.ts +218 -572
  50. package/src/{obligation-action.ts → obligations/action.ts} +247 -69
  51. package/src/{obligation-anon.ts → obligations/anon.ts} +49 -47
  52. package/src/obligations/ctx.ts +64 -0
  53. package/src/{obligation-deref.ts → obligations/deref.ts} +51 -92
  54. package/src/{obligation-expression.ts → obligations/expression.ts} +117 -57
  55. package/src/{obligation-format.ts → obligations/format.ts} +7 -8
  56. package/src/{obligation-generate.ts → obligations/generate.ts} +170 -192
  57. package/src/{obligations.ts → obligations/index.ts} +32 -16
  58. package/src/{obligation-levels.ts → obligations/levels.ts} +26 -28
  59. package/src/{obligation-module.ts → obligations/module.ts} +113 -121
  60. package/src/obligations/pickle.ts +98 -0
  61. package/src/obligations/pragma.ts +189 -0
  62. package/src/{obligation-printer.ts → obligations/printer.ts} +22 -80
  63. package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
  64. package/src/{obligation-source.ts → obligations/source.ts} +156 -99
  65. package/src/obligations/temporal.ts +321 -0
  66. package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
  67. package/src/ocaml-marshal.ts +166 -0
  68. package/src/parallel-worker.ts +169 -224
  69. package/src/parallel.ts +140 -81
  70. package/src/parser.ts +456 -147
  71. package/src/pcal-ast.ts +770 -0
  72. package/src/pcal-parse.ts +1523 -0
  73. package/src/pcal-tokenize.ts +516 -0
  74. package/src/pcal-translate.ts +1230 -0
  75. package/src/pcal-validate.ts +454 -0
  76. package/src/prove/decide-pool.ts +95 -0
  77. package/src/prove/deciders.ts +33 -0
  78. package/src/prove/first-order.ts +78 -0
  79. package/src/prove/isabelle/LICENSE +36 -0
  80. package/src/prove/isabelle/LICENSE-tlapm +26 -0
  81. package/src/prove/isabelle/decide.ts +47 -0
  82. package/src/prove/isabelle/encode.ts +446 -0
  83. package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
  84. package/src/prove/isabelle/isar/method.ts +367 -0
  85. package/src/prove/isabelle/isar/proof.ts +28 -0
  86. package/src/prove/isabelle/isar/statement.ts +57 -0
  87. package/src/prove/isabelle/isar/theory.ts +192 -0
  88. package/src/prove/isabelle/isar/type-check.ts +278 -0
  89. package/src/prove/isabelle/provers/blast/blast.ts +258 -0
  90. package/src/prove/isabelle/provers/blast/branch.ts +322 -0
  91. package/src/prove/isabelle/provers/blast/prove.ts +347 -0
  92. package/src/prove/isabelle/provers/blast/rules.ts +330 -0
  93. package/src/prove/isabelle/provers/blast/state.ts +180 -0
  94. package/src/prove/isabelle/provers/blast/term.ts +546 -0
  95. package/src/prove/isabelle/provers/clasimp.ts +150 -0
  96. package/src/prove/isabelle/provers/classical.ts +389 -0
  97. package/src/prove/isabelle/provers/hypsubst.ts +433 -0
  98. package/src/prove/isabelle/pure/bicompose.ts +174 -0
  99. package/src/prove/isabelle/pure/consts.ts +32 -0
  100. package/src/prove/isabelle/pure/conv.ts +79 -0
  101. package/src/prove/isabelle/pure/drule.ts +264 -0
  102. package/src/prove/isabelle/pure/envir.ts +331 -0
  103. package/src/prove/isabelle/pure/goal.ts +53 -0
  104. package/src/prove/isabelle/pure/interrupt.ts +16 -0
  105. package/src/prove/isabelle/pure/list.ts +12 -0
  106. package/src/prove/isabelle/pure/logic.ts +330 -0
  107. package/src/prove/isabelle/pure/name.ts +98 -0
  108. package/src/prove/isabelle/pure/net.ts +215 -0
  109. package/src/prove/isabelle/pure/object-logic.ts +41 -0
  110. package/src/prove/isabelle/pure/pattern.ts +631 -0
  111. package/src/prove/isabelle/pure/raw-simplifier.ts +338 -0
  112. package/src/prove/isabelle/pure/rewriter.ts +602 -0
  113. package/src/prove/isabelle/pure/search.ts +68 -0
  114. package/src/prove/isabelle/pure/seq.ts +133 -0
  115. package/src/prove/isabelle/pure/simplifier.ts +106 -0
  116. package/src/prove/isabelle/pure/table.ts +201 -0
  117. package/src/prove/isabelle/pure/tactic.ts +168 -0
  118. package/src/prove/isabelle/pure/tactical.ts +264 -0
  119. package/src/prove/isabelle/pure/term-ord.ts +105 -0
  120. package/src/prove/isabelle/pure/term.ts +688 -0
  121. package/src/prove/isabelle/pure/thm.ts +783 -0
  122. package/src/prove/isabelle/pure/type.ts +121 -0
  123. package/src/prove/isabelle/pure/unify.ts +753 -0
  124. package/src/prove/isabelle/pure/variable.ts +25 -0
  125. package/src/prove/isabelle/tla/classical-setup.ts +101 -0
  126. package/src/prove/isabelle/tla/context.ts +74 -0
  127. package/src/prove/isabelle/tla/logic-data.ts +5 -0
  128. package/src/prove/isabelle/tla/logic.ts +215 -0
  129. package/src/prove/isabelle/tla/simpdata.ts +241 -0
  130. package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
  131. package/src/prove/ocaml.ts +22 -0
  132. package/src/prove/prep/action.ts +508 -0
  133. package/src/prove/prep/defs.ts +33 -0
  134. package/src/prove/prep/elab.ts +156 -0
  135. package/src/prove/prep/enabled-axioms.ts +189 -0
  136. package/src/prove/prep/enabled.ts +43 -0
  137. package/src/prove/prep/fingerprint.ts +388 -0
  138. package/src/prove/prep/flatten.ts +70 -0
  139. package/src/prove/prep/level-comparison.ts +529 -0
  140. package/src/prove/prep/md5.ts +67 -0
  141. package/src/prove/prep/pragma.ts +221 -0
  142. package/src/prove/prep/trivial.ts +22 -0
  143. package/src/prove/prove-worker.ts +22 -0
  144. package/src/prove/prove.ts +498 -0
  145. package/src/prove/ptl/decide.ts +68 -0
  146. package/src/prove/ptl/encode.ts +255 -0
  147. package/src/prove/ptl/sat.ts +151 -0
  148. package/src/prove/ptl/tableau.ts +276 -0
  149. package/src/prove/smt/axiomatize.ts +69 -0
  150. package/src/prove/smt/axioms.ts +209 -0
  151. package/src/prove/smt/context.ts +108 -0
  152. package/src/prove/smt/data.ts +636 -0
  153. package/src/prove/smt/encode.ts +164 -0
  154. package/src/prove/smt/extensionality.ts +65 -0
  155. package/src/prove/smt/flatten.ts +112 -0
  156. package/src/prove/smt/format.ts +154 -0
  157. package/src/prove/smt/instances.ts +181 -0
  158. package/src/prove/smt/rewrite.ts +772 -0
  159. package/src/prove/smt/simplify.ts +57 -0
  160. package/src/prove/smt/solver/act-cache.ts +265 -0
  161. package/src/prove/smt/solver/arith-rewriter.ts +962 -0
  162. package/src/prove/smt/solver/array.ts +22 -0
  163. package/src/prove/smt/solver/asserted-formulas.ts +469 -0
  164. package/src/prove/smt/solver/ast-lt.ts +157 -0
  165. package/src/prove/smt/solver/ast-util.ts +91 -0
  166. package/src/prove/smt/solver/ast.ts +1315 -0
  167. package/src/prove/smt/solver/auf-solver.ts +572 -0
  168. package/src/prove/smt/solver/case-split-queue.ts +178 -0
  169. package/src/prove/smt/solver/cg-table.ts +175 -0
  170. package/src/prove/smt/solver/clause.ts +276 -0
  171. package/src/prove/smt/solver/conflict-resolution.ts +343 -0
  172. package/src/prove/smt/solver/context.ts +1292 -0
  173. package/src/prove/smt/solver/ctx-simplify.ts +334 -0
  174. package/src/prove/smt/solver/der.ts +224 -0
  175. package/src/prove/smt/solver/dyn-ack.ts +141 -0
  176. package/src/prove/smt/solver/e-matching.ts +659 -0
  177. package/src/prove/smt/solver/enode.ts +259 -0
  178. package/src/prove/smt/solver/expr-ref.ts +21 -0
  179. package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
  180. package/src/prove/smt/solver/fingerprints.ts +92 -0
  181. package/src/prove/smt/solver/flat-literals.ts +51 -0
  182. package/src/prove/smt/solver/goal.ts +138 -0
  183. package/src/prove/smt/solver/hash.ts +173 -0
  184. package/src/prove/smt/solver/hashtable.ts +166 -0
  185. package/src/prove/smt/solver/internalizer.ts +1381 -0
  186. package/src/prove/smt/solver/lbool.ts +5 -0
  187. package/src/prove/smt/solver/literal.ts +24 -0
  188. package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
  189. package/src/prove/smt/solver/lp/constraints.ts +78 -0
  190. package/src/prove/smt/solver/lp/containers.ts +296 -0
  191. package/src/prove/smt/solver/lp/core-solver.ts +504 -0
  192. package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
  193. package/src/prove/smt/solver/lp/dep-intervals.ts +642 -0
  194. package/src/prove/smt/solver/lp/dependency.ts +51 -0
  195. package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
  196. package/src/prove/smt/solver/lp/explanation.ts +46 -0
  197. package/src/prove/smt/solver/lp/gomory.ts +255 -0
  198. package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
  199. package/src/prove/smt/solver/lp/hnf.ts +281 -0
  200. package/src/prove/smt/solver/lp/int-cube.ts +295 -0
  201. package/src/prove/smt/solver/lp/int-solver.ts +514 -0
  202. package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
  203. package/src/prove/smt/solver/lp/lar-term.ts +62 -0
  204. package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
  205. package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
  206. package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
  207. package/src/prove/smt/solver/lp/nex.ts +120 -0
  208. package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
  209. package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
  210. package/src/prove/smt/solver/lp/nla-core.ts +968 -0
  211. package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
  212. package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
  213. package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
  214. package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
  215. package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
  216. package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
  217. package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
  218. package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
  219. package/src/prove/smt/solver/lp/nla-order.ts +307 -0
  220. package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
  221. package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
  222. package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
  223. package/src/prove/smt/solver/lp/nla-types.ts +124 -0
  224. package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
  225. package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
  226. package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
  227. package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
  228. package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
  229. package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
  230. package/src/prove/smt/solver/lp/pdd.ts +971 -0
  231. package/src/prove/smt/solver/lp/random-updater.ts +138 -0
  232. package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
  233. package/src/prove/smt/solver/lp/union-find.ts +96 -0
  234. package/src/prove/smt/solver/mam-compiler.ts +847 -0
  235. package/src/prove/smt/solver/mam-interpreter.ts +400 -0
  236. package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
  237. package/src/prove/smt/solver/model-checker.ts +347 -0
  238. package/src/prove/smt/solver/model-evaluator.ts +262 -0
  239. package/src/prove/smt/solver/model-finder.ts +155 -0
  240. package/src/prove/smt/solver/model-generator.ts +97 -0
  241. package/src/prove/smt/solver/model-macro-solver.ts +728 -0
  242. package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
  243. package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
  244. package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
  245. package/src/prove/smt/solver/nlsat/explain.ts +607 -0
  246. package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
  247. package/src/prove/smt/solver/nlsat/levelwise.ts +737 -0
  248. package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
  249. package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
  250. package/src/prove/smt/solver/nlsat/solver.ts +911 -0
  251. package/src/prove/smt/solver/nlsat/types.ts +43 -0
  252. package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
  253. package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
  254. package/src/prove/smt/solver/nnf.ts +469 -0
  255. package/src/prove/smt/solver/pattern-inference.ts +351 -0
  256. package/src/prove/smt/solver/poly-rewriter.ts +477 -0
  257. package/src/prove/smt/solver/propagate-values.ts +83 -0
  258. package/src/prove/smt/solver/proto-model.ts +551 -0
  259. package/src/prove/smt/solver/pull-quant.ts +139 -0
  260. package/src/prove/smt/solver/qe-lite-der.ts +526 -0
  261. package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
  262. package/src/prove/smt/solver/qe-lite.ts +381 -0
  263. package/src/prove/smt/solver/qi-queue.ts +362 -0
  264. package/src/prove/smt/solver/quant-tactics.ts +117 -0
  265. package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
  266. package/src/prove/smt/solver/quantifier-manager.ts +186 -0
  267. package/src/prove/smt/solver/random-gen.ts +10 -0
  268. package/src/prove/smt/solver/rational.ts +165 -0
  269. package/src/prove/smt/solver/ref-vector.ts +62 -0
  270. package/src/prove/smt/solver/relevancy.ts +247 -0
  271. package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
  272. package/src/prove/smt/solver/rewriter.ts +843 -0
  273. package/src/prove/smt/solver/rlimit.ts +79 -0
  274. package/src/prove/smt/solver/smtlib-parser.ts +526 -0
  275. package/src/prove/smt/solver/solver.ts +71 -0
  276. package/src/prove/smt/solver/sort.ts +35 -0
  277. package/src/prove/smt/solver/sticky-generations.ts +69 -0
  278. package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
  279. package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
  280. package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
  281. package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
  282. package/src/prove/smt/solver/theory-lra-model.ts +243 -0
  283. package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
  284. package/src/prove/smt/solver/theory-lra-state.ts +43 -0
  285. package/src/prove/smt/solver/theory-lra.ts +56 -0
  286. package/src/prove/smt/solver/var-subst.ts +258 -0
  287. package/src/prove/smt/solver/z3-license.txt +10 -0
  288. package/src/prove/smt/table.ts +170 -0
  289. package/src/prove/tlapm/tlapm.ts +96 -0
  290. package/src/prove/tlaps-module.ts +510 -0
  291. package/src/prove/verdict.ts +18 -0
  292. package/src/prove/zenon/LICENSE +32 -0
  293. package/src/prove/zenon/check/check.ts +105 -0
  294. package/src/prove/zenon/check/definitions.ts +144 -0
  295. package/src/prove/zenon/check/equality.ts +182 -0
  296. package/src/prove/zenon/check/functions.ts +62 -0
  297. package/src/prove/zenon/check/keys.ts +125 -0
  298. package/src/prove/zenon/check/propositional.ts +104 -0
  299. package/src/prove/zenon/check/records.ts +188 -0
  300. package/src/prove/zenon/check/relations.ts +121 -0
  301. package/src/prove/zenon/check/rewrites.ts +224 -0
  302. package/src/prove/zenon/check/sets.ts +302 -0
  303. package/src/prove/zenon/check/terms.ts +127 -0
  304. package/src/prove/zenon/check/tla.ts +126 -0
  305. package/src/prove/zenon/decide.ts +113 -0
  306. package/src/prove/zenon/encode.ts +379 -0
  307. package/src/prove/zenon/eqrel.ts +300 -0
  308. package/src/prove/zenon/equality-rules.ts +435 -0
  309. package/src/prove/zenon/expr.ts +551 -0
  310. package/src/prove/zenon/index-table.ts +350 -0
  311. package/src/prove/zenon/isar-case.ts +513 -0
  312. package/src/prove/zenon/isar.ts +1249 -0
  313. package/src/prove/zenon/limits.ts +15 -0
  314. package/src/prove/zenon/llproof.ts +173 -0
  315. package/src/prove/zenon/mltoll.ts +1566 -0
  316. package/src/prove/zenon/node.ts +297 -0
  317. package/src/prove/zenon/ocaml.ts +169 -0
  318. package/src/prove/zenon/parse.ts +247 -0
  319. package/src/prove/zenon/phrase.ts +191 -0
  320. package/src/prove/zenon/proof.ts +198 -0
  321. package/src/prove/zenon/propositional-rules.ts +387 -0
  322. package/src/prove/zenon/rules.ts +94 -0
  323. package/src/prove/zenon/search.ts +288 -0
  324. package/src/prove/zenon/tla/functions.ts +151 -0
  325. package/src/prove/zenon/tla/llproof.ts +480 -0
  326. package/src/prove/zenon/tla/records.ts +225 -0
  327. package/src/prove/zenon/tla/rewrites.ts +447 -0
  328. package/src/prove/zenon/tla/sets.ts +304 -0
  329. package/src/prove/zenon/tla/terms.ts +162 -0
  330. package/src/prove/zenon/tla/tla.ts +506 -0
  331. package/src/randomization.ts +24 -7
  332. package/src/resolve.ts +1481 -426
  333. package/src/run-cli.ts +1483 -212
  334. package/src/runtime.ts +19 -1
  335. package/src/sany-builtins.ts +147 -0
  336. package/src/sany-generator.ts +3128 -0
  337. package/src/sany-levels.ts +1208 -0
  338. package/src/sany-lexer.ts +545 -0
  339. package/src/sany-linter.ts +122 -0
  340. package/src/sany-modules.ts +1398 -0
  341. package/src/sany-nodes.ts +463 -0
  342. package/src/sany-parse-error.ts +2161 -0
  343. package/src/sany-report.ts +356 -0
  344. package/src/sany-selectors.ts +738 -0
  345. package/src/sany-source.ts +248 -0
  346. package/src/sany-xml.ts +1017 -0
  347. package/src/spec-description.ts +42 -11
  348. package/src/standard-modules.ts +203 -148
  349. package/src/standard-ranges.ts +116 -0
  350. package/src/state-graph.ts +180 -0
  351. package/src/subexpressions.ts +231 -171
  352. package/src/substitution-levels.ts +38 -17
  353. package/src/successors.ts +241 -110
  354. package/src/symmetry.ts +194 -54
  355. package/src/tableau.ts +54 -25
  356. package/src/tlapm-cache.ts +236 -0
  357. package/src/tlc-ext.ts +42 -29
  358. package/src/tlc-messages.ts +329 -0
  359. package/src/tlc-module.ts +52 -43
  360. package/src/tlc-modules.ts +4 -0
  361. package/src/tlc-order.ts +78 -10
  362. package/src/tlc-random.ts +84 -33
  363. package/src/tlc-replay.ts +655 -0
  364. package/src/tlc-summary.ts +20 -5
  365. package/src/tlc-version.ts +19 -0
  366. package/src/transfer.ts +15 -3
  367. package/src/values.ts +787 -190
  368. package/src/worker.ts +65 -0
  369. package/dist/parallel.cjs +0 -12
  370. package/dist/parallel.js +0 -12
package/src/errors.ts CHANGED
@@ -1,4 +1,20 @@
1
- import { EXIT_STATUS, getExitCode, setModuleExitCode } from "./exit-codes";
1
+ import type { SourceRange } from "./ast";
2
+ import { EXIT_STATUS, getExitCode } from "./exit-codes";
3
+ import type { PcalNode } from "./pcal-ast";
4
+ import type { Value } from "./values";
5
+
6
+ // The start of TLC's message for an exception of a Java class it didn't expect.
7
+ export const getUnexpectedException = (exceptionClass: string) =>
8
+ `TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a ${exceptionClass}\n: `;
9
+
10
+ // How TLC reports a RuntimeException it did not expect, such as one raised while computing next
11
+ // states.
12
+ export const UNEXPECTED_EXCEPTION = getUnexpectedException("java.lang.RuntimeException");
13
+
14
+ // Whether an error is V8's RangeError for a stack overflow, which TLC raises as a Java
15
+ // StackOverflowError.
16
+ export const isStackOverflow = (error: unknown) =>
17
+ error instanceof RangeError && error.message === "Maximum call stack size exceeded";
2
18
 
3
19
  export class TlaError extends Error {
4
20
  constructor(message: string, cause?: unknown) {
@@ -14,16 +30,95 @@ export interface SyntaxFailure {
14
30
  isEnd: boolean;
15
31
  }
16
32
 
33
+ // An error SANY reports at a location, such as "In module M" or a range in a module.
34
+ export interface SanyError {
35
+ location: string;
36
+ message: string;
37
+ }
38
+
39
+ // The errors SANY reports for a spec, and the warnings it prints before them. A fatal error stops it
40
+ // before semantic analysis. SANY's parser prints its message for a module it rejects before the
41
+ // report.
42
+ interface SanyReport {
43
+ errors: SanyError[];
44
+ warnings: SanyError[];
45
+ isFatal: boolean;
46
+ parseError?: string;
47
+ }
48
+
17
49
  export class TlaSyntaxError extends TlaError {
18
50
  failure: SyntaxFailure | undefined;
51
+ sany: SanyReport | undefined;
19
52
 
20
- constructor(message: string, cause?: unknown, failure?: SyntaxFailure) {
53
+ constructor(message: string, cause?: unknown, failure?: SyntaxFailure, sany?: SanyReport) {
21
54
  super(message, cause);
22
55
  this.name = "TlaSyntaxError";
23
56
  this.failure = failure;
57
+ this.sany = sany;
58
+ }
59
+ }
60
+
61
+ // A fatal error of SANY's parsing phase: a module SANY can't find or parse, a file whose name
62
+ // doesn't match its module's, or a circular dependency. SANY reports it in the module that imports
63
+ // or holds the failed one, or without a location, after its JavaCC parser's report of a module it
64
+ // failed to parse. It keeps the name TlaSyntaxError, and index.ts doesn't export it.
65
+ export class TlaSanyFatalError extends TlaSyntaxError {
66
+ location: string | undefined;
67
+ parseError: string | undefined;
68
+
69
+ constructor(message: string, location: string | undefined, parseError?: string) {
70
+ super(message);
71
+ this.location = location;
72
+ this.parseError = parseError;
24
73
  }
25
74
  }
26
75
 
76
+ // A module that another imports and SANY can't find, which SANY reports in the importer, except
77
+ // TLC 1.7.4's SANY, which gives it no location.
78
+ export class TlaMissingModuleError extends TlaSanyFatalError {
79
+ constructor(name: string, importer: string | undefined, isLocated = true) {
80
+ super(
81
+ `Cannot find source file for module ${name} imported in module ${importer}.`,
82
+ isLocated ? importer : undefined,
83
+ );
84
+ }
85
+ }
86
+
87
+ export const createSanyError = (
88
+ errors: SanyError[],
89
+ isFatal = false,
90
+ parseError?: string,
91
+ warnings: SanyError[] = [],
92
+ ) =>
93
+ new TlaSyntaxError(
94
+ errors.map((error) => `${error.location}\n\n${error.message}`).join("\n\n"),
95
+ undefined,
96
+ undefined,
97
+ { errors, warnings, isFatal, parseError },
98
+ );
99
+
100
+ // SANY reports a module it can't find in the module that imports it.
101
+ export const createMissingModuleError = (name: string, importer: string | undefined) =>
102
+ createSanyError(
103
+ [
104
+ {
105
+ location: `In module ${importer}`,
106
+ message: `Cannot find source file for module ${name} imported in module ${importer}.`,
107
+ },
108
+ ],
109
+ true,
110
+ );
111
+
112
+ // How SANY prints the warnings it reports, which do not stop TLC.
113
+ export const formatSanyWarnings = (warnings: SanyError[]) =>
114
+ `*** Warnings: ${warnings.length}\n\n${warnings.map((warning) => `${warning.location}\n\n${warning.message}\n\n\n`).join("\n")}`;
115
+
116
+ export const formatRange = (range: SourceRange) =>
117
+ `line ${range.start.line}, col ${range.start.column} to line ${range.end.line}, col ${range.end.column} of module ${range.module}`;
118
+
119
+ export const createSemanticError = (message: string, range: SourceRange) =>
120
+ createSanyError([{ location: formatRange(range), message }]);
121
+
27
122
  export class TlaConfigError extends TlaError {
28
123
  constructor(message: string, cause?: unknown) {
29
124
  super(message, cause);
@@ -38,17 +133,72 @@ export class TlaEvaluationError extends TlaError {
38
133
  }
39
134
  }
40
135
 
136
+ // How TLC reports a Java StackOverflowError.
137
+ export const STACK_OVERFLOW_MESSAGE =
138
+ "This was a Java StackOverflowError. It was probably the result\nof an incorrect recursive function definition that caused TLC to enter\nan infinite loop when trying to compute the function or its application\nto an element in its putative domain.";
139
+
140
+ // A Java StackOverflowError, which TLC catches only at the top, unlike the exceptions of evaluation.
141
+ export class TlaStackOverflowError extends TlaEvaluationError {
142
+ constructor() {
143
+ super(STACK_OVERFLOW_MESSAGE);
144
+ }
145
+ }
146
+
147
+ // A next-state action left variables of a successor state unassigned. TLC reports the partial
148
+ // state, with null for each unassigned variable.
149
+ export class TlaIncompleteSuccessorError extends TlaEvaluationError {
150
+ state: (Value | undefined)[];
151
+ action: string | undefined;
152
+ variables: string[];
153
+
154
+ constructor(
155
+ message: string,
156
+ state: (Value | undefined)[],
157
+ action: string | undefined,
158
+ variables: string[],
159
+ ) {
160
+ super(message);
161
+ this.state = state;
162
+ this.action = action;
163
+ this.variables = variables;
164
+ }
165
+ }
166
+
167
+ // An expression read a variable that its state doesn't assign. It keeps the name
168
+ // TlaEvaluationError, and index.ts doesn't export it.
169
+ export class TlaUnassignedError extends TlaEvaluationError {
170
+ variable: string;
171
+
172
+ constructor(message: string, variable: string) {
173
+ super(message);
174
+ this.variable = variable;
175
+ }
176
+ }
177
+
41
178
  // An evaluation error that TLC raises as an EvalException from a standard module's Java code. It
42
179
  // keeps the name TlaEvaluationError, and index.ts doesn't export it.
43
180
  export class TlaModuleError extends TlaEvaluationError {
181
+ exitCode: number;
182
+
44
183
  constructor(message: string, exitCode: number = EXIT_STATUS.error) {
45
184
  super(message);
46
185
  this.name = "TlaEvaluationError";
47
- setModuleExitCode(this, exitCode);
186
+ this.exitCode = exitCode;
187
+ }
188
+ }
189
+
190
+ // TLC reports an initial state that the initial predicate leaves incomplete as an illegal state.
191
+ export class TlaIllegalStateError extends TlaEvaluationError {
192
+ state: (Value | undefined)[];
193
+
194
+ constructor(state: (Value | undefined)[]) {
195
+ super("current state is not a legal state");
196
+ this.name = "TlaEvaluationError";
197
+ this.state = state;
48
198
  }
49
199
  }
50
200
 
51
- export interface TlapmReport {
201
+ interface TlapmReport {
52
202
  failure?: string;
53
203
  exception?: string;
54
204
  }
@@ -74,6 +224,39 @@ export class TlapmBugError extends TlaProofError {
74
224
  }
75
225
  }
76
226
 
227
+ // A backend can't take an obligation, which tlapm reports as not tried.
228
+ export class TlaProverError extends TlaError {
229
+ constructor(message: string, cause?: unknown) {
230
+ super(message, cause);
231
+ this.name = "TlaProverError";
232
+ }
233
+ }
234
+
235
+ // Zenon gives up on a .znn file the way the OCaml Zenon raises an exception and prints no proof.
236
+ export class TlaZenonError extends TlaError {
237
+ constructor(message: string, cause?: unknown) {
238
+ super(message, cause);
239
+ this.name = "TlaZenonError";
240
+ }
241
+ }
242
+
243
+ // The exceptions Isabelle raises: ERROR for a rejected theory or a failed proof, TERM, TYPE and THM
244
+ // for an ill-formed term, type or theorem, and Interrupt when the time limit runs out.
245
+ type IsabelleException = "ERROR" | "TERM" | "TYPE" | "THM" | "Interrupt";
246
+
247
+ // Isabelle's tactics raise and handle these as control flow, often millions of times per proof, and
248
+ // decideIsabelle answers "unknown" for any that escape. So unlike an Error, it skips the stack trace.
249
+ export class TlaIsabelleError {
250
+ readonly name = "TlaIsabelleError";
251
+ readonly exception: IsabelleException;
252
+ readonly message: string;
253
+
254
+ constructor(exception: IsabelleException, message: string) {
255
+ this.exception = exception;
256
+ this.message = message;
257
+ }
258
+ }
259
+
77
260
  export class TlaUnsupportedError extends TlaError {
78
261
  constructor(message: string, cause?: unknown) {
79
262
  super(message, cause);
@@ -81,6 +264,71 @@ export class TlaUnsupportedError extends TlaError {
81
264
  }
82
265
  }
83
266
 
267
+ // The SMT solver met input outside the SMT-LIB subset that tlapm emits, or a numeral too large for
268
+ // its exact arithmetic. The solver answers unknown.
269
+ export class SmtUnsupportedError extends TlaError {
270
+ constructor(message: string, cause?: unknown) {
271
+ super(message, cause);
272
+ this.name = "SmtUnsupportedError";
273
+ }
274
+ }
275
+
276
+ // The SMT solver ran past its time limit, or its signal aborted, in the middle of a rewrite. The
277
+ // solver answers unknown.
278
+ export class SmtCanceledError extends TlaError {
279
+ constructor() {
280
+ super("the SMT solver was canceled");
281
+ this.name = "SmtCanceledError";
282
+ }
283
+ }
284
+
285
+ // The SMT solver broke one of its own invariants, a bug in the port rather than in the input. It
286
+ // keeps its name, and index.ts doesn't export it.
287
+ export class SmtInvariantError extends TlaError {
288
+ constructor(message: string) {
289
+ super(message);
290
+ this.name = "SmtInvariantError";
291
+ }
292
+ }
293
+
294
+ // nlsat reached a case Z3 leaves unimplemented, where Z3 exits the process. nra answers unknown
295
+ // instead. index.ts doesn't export it.
296
+ export class NlsatUnsupportedError extends TlaError {
297
+ constructor(reason: string) {
298
+ super(`nlsat does not implement ${reason}`);
299
+ this.name = "NlsatUnsupportedError";
300
+ }
301
+ }
302
+
303
+ // mem_out: the pdd manager needed a node past its limit outside an operation. Grobner catches it
304
+ // and gives up on the round. index.ts doesn't export it.
305
+ export class PddMemoryOutError extends TlaError {
306
+ constructor() {
307
+ super("the pdd manager ran out of nodes");
308
+ this.name = "PddMemoryOutError";
309
+ }
310
+ }
311
+
312
+ // The SMT-LIB input is malformed: a syntax error, an undeclared symbol, or an ill-sorted application.
313
+ export class SmtParseError extends TlaError {
314
+ constructor(message: string, cause?: unknown) {
315
+ super(message, cause);
316
+ this.name = "SmtParseError";
317
+ }
318
+ }
319
+
320
+ // An exception that TLC's Java code throws and nothing catches, with the stack trace it prints, after
321
+ // what the frames that the exception unwinds print about it.
322
+ export class TlaJavaException extends TlaUnsupportedError {
323
+ unwound: string;
324
+
325
+ constructor(message: string, unwound: string) {
326
+ super(message);
327
+ this.name = "TlaJavaException";
328
+ this.unwound = unwound;
329
+ }
330
+ }
331
+
84
332
  export const getErrorExitCode = (error: TlaError) =>
85
333
  getExitCode(error) ??
86
334
  (error instanceof TlaSyntaxError
@@ -90,3 +338,35 @@ export const getErrorExitCode = (error: TlaError) =>
90
338
  : error instanceof TlaEvaluationError
91
339
  ? EXIT_STATUS.specEvaluationFailure
92
340
  : EXIT_STATUS.error);
341
+
342
+ // pcal.UnrecoverableException and its subclasses: an error the PlusCal translator reports as
343
+ // "Unrecoverable error". UnrecoverablePositionedException adds the statement the error is at.
344
+ export class PcalError extends TlaError {
345
+ node: PcalNode | undefined;
346
+
347
+ constructor(message: string, node?: PcalNode) {
348
+ super(message);
349
+ this.name = "PcalError";
350
+ this.node = node;
351
+ }
352
+ }
353
+
354
+ // A RuntimeException the translator's Java code throws, such as an index out of bounds, which
355
+ // ParseAlgorithm.getAlgorithm turns into a parsing error.
356
+ export class PcalRuntimeError extends TlaError {
357
+ constructor(message: string) {
358
+ super(message);
359
+ this.name = "PcalRuntimeError";
360
+ }
361
+ }
362
+
363
+ // PcalDebug.ReportBug: the translator found itself in a state it considers a bug, and throws a
364
+ // java.lang.Error that nothing in SANY catches.
365
+ export class PcalBugError extends TlaError {
366
+ constructor(message: string) {
367
+ super(
368
+ `You have discovered a bug in pcal.trans.\nSend the following information and the\ninput file to the current maintainer(s).\n\n -- ${message}.`,
369
+ );
370
+ this.name = "PcalBugError";
371
+ }
372
+ }