tla-ts 0.0.4-dev.0be9567 → 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 (320) hide show
  1. package/README.md +37 -126
  2. package/dist/deciders.cjs +366 -0
  3. package/dist/deciders.js +366 -0
  4. package/dist/index.cjs +1 -1
  5. package/dist/index.d.cts +33 -1
  6. package/dist/index.d.ts +33 -1
  7. package/dist/index.js +1 -1
  8. package/dist/parallel-worker.cjs +1 -4
  9. package/dist/parallel-worker.js +1 -4
  10. package/dist/prove-worker.cjs +9 -0
  11. package/dist/prove-worker.d.cts +9 -0
  12. package/dist/prove-worker.d.ts +9 -0
  13. package/dist/prove-worker.js +9 -0
  14. package/dist/prove.cjs +996 -0
  15. package/dist/prove.js +996 -0
  16. package/dist/run-cli.cjs +37 -47
  17. package/dist/run-cli.js +37 -47
  18. package/dist/tlapm.cjs +10 -0
  19. package/dist/tlapm.js +10 -0
  20. package/dist/transfer.cjs +38 -44
  21. package/dist/transfer.js +38 -44
  22. package/dist/worker.cjs +21 -0
  23. package/dist/worker.js +21 -0
  24. package/package.json +21 -12
  25. package/src/ast.ts +2 -2
  26. package/src/check.ts +1 -0
  27. package/src/cli-options.ts +1 -1
  28. package/src/errors.ts +88 -29
  29. package/src/evaluate.ts +56 -21
  30. package/src/index.ts +10 -0
  31. package/src/live-check.ts +1 -1
  32. package/src/{obligation-action.ts → obligations/action.ts} +247 -69
  33. package/src/{obligation-anon.ts → obligations/anon.ts} +49 -47
  34. package/src/obligations/ctx.ts +64 -0
  35. package/src/{obligation-deref.ts → obligations/deref.ts} +51 -92
  36. package/src/{obligation-expression.ts → obligations/expression.ts} +117 -57
  37. package/src/{obligation-format.ts → obligations/format.ts} +7 -8
  38. package/src/{obligation-generate.ts → obligations/generate.ts} +170 -192
  39. package/src/{obligations.ts → obligations/index.ts} +32 -16
  40. package/src/{obligation-levels.ts → obligations/levels.ts} +26 -28
  41. package/src/{obligation-module.ts → obligations/module.ts} +113 -121
  42. package/src/obligations/pickle.ts +98 -0
  43. package/src/obligations/pragma.ts +189 -0
  44. package/src/{obligation-printer.ts → obligations/printer.ts} +22 -80
  45. package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
  46. package/src/{obligation-source.ts → obligations/source.ts} +154 -99
  47. package/src/obligations/temporal.ts +321 -0
  48. package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
  49. package/src/ocaml-marshal.ts +166 -0
  50. package/src/parallel-worker.ts +2 -18
  51. package/src/parallel.ts +10 -43
  52. package/src/prove/decide-pool.ts +95 -0
  53. package/src/prove/deciders.ts +33 -0
  54. package/src/prove/first-order.ts +78 -0
  55. package/src/prove/isabelle/LICENSE +36 -0
  56. package/src/prove/isabelle/LICENSE-tlapm +26 -0
  57. package/src/prove/isabelle/decide.ts +47 -0
  58. package/src/prove/isabelle/encode.ts +446 -0
  59. package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
  60. package/src/prove/isabelle/isar/method.ts +367 -0
  61. package/src/prove/isabelle/isar/proof.ts +28 -0
  62. package/src/prove/isabelle/isar/statement.ts +57 -0
  63. package/src/prove/isabelle/isar/theory.ts +192 -0
  64. package/src/prove/isabelle/isar/type-check.ts +278 -0
  65. package/src/prove/isabelle/provers/blast/blast.ts +258 -0
  66. package/src/prove/isabelle/provers/blast/branch.ts +322 -0
  67. package/src/prove/isabelle/provers/blast/prove.ts +347 -0
  68. package/src/prove/isabelle/provers/blast/rules.ts +330 -0
  69. package/src/prove/isabelle/provers/blast/state.ts +180 -0
  70. package/src/prove/isabelle/provers/blast/term.ts +546 -0
  71. package/src/prove/isabelle/provers/clasimp.ts +150 -0
  72. package/src/prove/isabelle/provers/classical.ts +389 -0
  73. package/src/prove/isabelle/provers/hypsubst.ts +433 -0
  74. package/src/prove/isabelle/pure/bicompose.ts +174 -0
  75. package/src/prove/isabelle/pure/consts.ts +32 -0
  76. package/src/prove/isabelle/pure/conv.ts +79 -0
  77. package/src/prove/isabelle/pure/drule.ts +264 -0
  78. package/src/prove/isabelle/pure/envir.ts +331 -0
  79. package/src/prove/isabelle/pure/goal.ts +53 -0
  80. package/src/prove/isabelle/pure/interrupt.ts +16 -0
  81. package/src/prove/isabelle/pure/list.ts +12 -0
  82. package/src/prove/isabelle/pure/logic.ts +330 -0
  83. package/src/prove/isabelle/pure/name.ts +98 -0
  84. package/src/prove/isabelle/pure/net.ts +215 -0
  85. package/src/prove/isabelle/pure/object-logic.ts +41 -0
  86. package/src/prove/isabelle/pure/pattern.ts +631 -0
  87. package/src/prove/isabelle/pure/raw-simplifier.ts +338 -0
  88. package/src/prove/isabelle/pure/rewriter.ts +602 -0
  89. package/src/prove/isabelle/pure/search.ts +68 -0
  90. package/src/prove/isabelle/pure/seq.ts +133 -0
  91. package/src/prove/isabelle/pure/simplifier.ts +106 -0
  92. package/src/prove/isabelle/pure/table.ts +201 -0
  93. package/src/prove/isabelle/pure/tactic.ts +168 -0
  94. package/src/prove/isabelle/pure/tactical.ts +264 -0
  95. package/src/prove/isabelle/pure/term-ord.ts +105 -0
  96. package/src/prove/isabelle/pure/term.ts +688 -0
  97. package/src/prove/isabelle/pure/thm.ts +783 -0
  98. package/src/prove/isabelle/pure/type.ts +121 -0
  99. package/src/prove/isabelle/pure/unify.ts +753 -0
  100. package/src/prove/isabelle/pure/variable.ts +25 -0
  101. package/src/prove/isabelle/tla/classical-setup.ts +101 -0
  102. package/src/prove/isabelle/tla/context.ts +74 -0
  103. package/src/prove/isabelle/tla/logic-data.ts +5 -0
  104. package/src/prove/isabelle/tla/logic.ts +215 -0
  105. package/src/prove/isabelle/tla/simpdata.ts +241 -0
  106. package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
  107. package/src/prove/ocaml.ts +22 -0
  108. package/src/prove/prep/action.ts +508 -0
  109. package/src/prove/prep/defs.ts +33 -0
  110. package/src/prove/prep/elab.ts +156 -0
  111. package/src/prove/prep/enabled-axioms.ts +189 -0
  112. package/src/prove/prep/enabled.ts +43 -0
  113. package/src/prove/prep/fingerprint.ts +388 -0
  114. package/src/prove/prep/flatten.ts +70 -0
  115. package/src/prove/prep/level-comparison.ts +529 -0
  116. package/src/prove/prep/md5.ts +67 -0
  117. package/src/prove/prep/pragma.ts +221 -0
  118. package/src/prove/prep/trivial.ts +22 -0
  119. package/src/prove/prove-worker.ts +22 -0
  120. package/src/prove/prove.ts +498 -0
  121. package/src/prove/ptl/decide.ts +68 -0
  122. package/src/prove/ptl/encode.ts +255 -0
  123. package/src/prove/ptl/sat.ts +151 -0
  124. package/src/prove/ptl/tableau.ts +276 -0
  125. package/src/prove/smt/axiomatize.ts +69 -0
  126. package/src/prove/smt/axioms.ts +209 -0
  127. package/src/prove/smt/context.ts +108 -0
  128. package/src/prove/smt/data.ts +636 -0
  129. package/src/prove/smt/encode.ts +164 -0
  130. package/src/prove/smt/extensionality.ts +65 -0
  131. package/src/prove/smt/flatten.ts +112 -0
  132. package/src/prove/smt/format.ts +154 -0
  133. package/src/prove/smt/instances.ts +181 -0
  134. package/src/prove/smt/rewrite.ts +772 -0
  135. package/src/prove/smt/simplify.ts +57 -0
  136. package/src/prove/smt/solver/act-cache.ts +265 -0
  137. package/src/prove/smt/solver/arith-rewriter.ts +962 -0
  138. package/src/prove/smt/solver/array.ts +22 -0
  139. package/src/prove/smt/solver/asserted-formulas.ts +469 -0
  140. package/src/prove/smt/solver/ast-lt.ts +157 -0
  141. package/src/prove/smt/solver/ast-util.ts +91 -0
  142. package/src/prove/smt/solver/ast.ts +1315 -0
  143. package/src/prove/smt/solver/auf-solver.ts +572 -0
  144. package/src/prove/smt/solver/case-split-queue.ts +178 -0
  145. package/src/prove/smt/solver/cg-table.ts +175 -0
  146. package/src/prove/smt/solver/clause.ts +276 -0
  147. package/src/prove/smt/solver/conflict-resolution.ts +343 -0
  148. package/src/prove/smt/solver/context.ts +1292 -0
  149. package/src/prove/smt/solver/ctx-simplify.ts +334 -0
  150. package/src/prove/smt/solver/der.ts +224 -0
  151. package/src/prove/smt/solver/dyn-ack.ts +141 -0
  152. package/src/prove/smt/solver/e-matching.ts +659 -0
  153. package/src/prove/smt/solver/enode.ts +259 -0
  154. package/src/prove/smt/solver/expr-ref.ts +21 -0
  155. package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
  156. package/src/prove/smt/solver/fingerprints.ts +92 -0
  157. package/src/prove/smt/solver/flat-literals.ts +51 -0
  158. package/src/prove/smt/solver/goal.ts +138 -0
  159. package/src/prove/smt/solver/hash.ts +173 -0
  160. package/src/prove/smt/solver/hashtable.ts +166 -0
  161. package/src/prove/smt/solver/internalizer.ts +1381 -0
  162. package/src/prove/smt/solver/lbool.ts +5 -0
  163. package/src/prove/smt/solver/literal.ts +24 -0
  164. package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
  165. package/src/prove/smt/solver/lp/constraints.ts +78 -0
  166. package/src/prove/smt/solver/lp/containers.ts +296 -0
  167. package/src/prove/smt/solver/lp/core-solver.ts +504 -0
  168. package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
  169. package/src/prove/smt/solver/lp/dep-intervals.ts +642 -0
  170. package/src/prove/smt/solver/lp/dependency.ts +51 -0
  171. package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
  172. package/src/prove/smt/solver/lp/explanation.ts +46 -0
  173. package/src/prove/smt/solver/lp/gomory.ts +255 -0
  174. package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
  175. package/src/prove/smt/solver/lp/hnf.ts +281 -0
  176. package/src/prove/smt/solver/lp/int-cube.ts +295 -0
  177. package/src/prove/smt/solver/lp/int-solver.ts +514 -0
  178. package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
  179. package/src/prove/smt/solver/lp/lar-term.ts +62 -0
  180. package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
  181. package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
  182. package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
  183. package/src/prove/smt/solver/lp/nex.ts +120 -0
  184. package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
  185. package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
  186. package/src/prove/smt/solver/lp/nla-core.ts +968 -0
  187. package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
  188. package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
  189. package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
  190. package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
  191. package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
  192. package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
  193. package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
  194. package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
  195. package/src/prove/smt/solver/lp/nla-order.ts +307 -0
  196. package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
  197. package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
  198. package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
  199. package/src/prove/smt/solver/lp/nla-types.ts +124 -0
  200. package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
  201. package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
  202. package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
  203. package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
  204. package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
  205. package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
  206. package/src/prove/smt/solver/lp/pdd.ts +971 -0
  207. package/src/prove/smt/solver/lp/random-updater.ts +138 -0
  208. package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
  209. package/src/prove/smt/solver/lp/union-find.ts +96 -0
  210. package/src/prove/smt/solver/mam-compiler.ts +847 -0
  211. package/src/prove/smt/solver/mam-interpreter.ts +400 -0
  212. package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
  213. package/src/prove/smt/solver/model-checker.ts +347 -0
  214. package/src/prove/smt/solver/model-evaluator.ts +262 -0
  215. package/src/prove/smt/solver/model-finder.ts +155 -0
  216. package/src/prove/smt/solver/model-generator.ts +97 -0
  217. package/src/prove/smt/solver/model-macro-solver.ts +728 -0
  218. package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
  219. package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
  220. package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
  221. package/src/prove/smt/solver/nlsat/explain.ts +607 -0
  222. package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
  223. package/src/prove/smt/solver/nlsat/levelwise.ts +737 -0
  224. package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
  225. package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
  226. package/src/prove/smt/solver/nlsat/solver.ts +911 -0
  227. package/src/prove/smt/solver/nlsat/types.ts +43 -0
  228. package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
  229. package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
  230. package/src/prove/smt/solver/nnf.ts +469 -0
  231. package/src/prove/smt/solver/pattern-inference.ts +351 -0
  232. package/src/prove/smt/solver/poly-rewriter.ts +477 -0
  233. package/src/prove/smt/solver/propagate-values.ts +83 -0
  234. package/src/prove/smt/solver/proto-model.ts +551 -0
  235. package/src/prove/smt/solver/pull-quant.ts +139 -0
  236. package/src/prove/smt/solver/qe-lite-der.ts +526 -0
  237. package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
  238. package/src/prove/smt/solver/qe-lite.ts +381 -0
  239. package/src/prove/smt/solver/qi-queue.ts +362 -0
  240. package/src/prove/smt/solver/quant-tactics.ts +117 -0
  241. package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
  242. package/src/prove/smt/solver/quantifier-manager.ts +186 -0
  243. package/src/prove/smt/solver/random-gen.ts +10 -0
  244. package/src/prove/smt/solver/rational.ts +165 -0
  245. package/src/prove/smt/solver/ref-vector.ts +62 -0
  246. package/src/prove/smt/solver/relevancy.ts +247 -0
  247. package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
  248. package/src/prove/smt/solver/rewriter.ts +843 -0
  249. package/src/prove/smt/solver/rlimit.ts +79 -0
  250. package/src/prove/smt/solver/smtlib-parser.ts +526 -0
  251. package/src/prove/smt/solver/solver.ts +71 -0
  252. package/src/prove/smt/solver/sort.ts +35 -0
  253. package/src/prove/smt/solver/sticky-generations.ts +69 -0
  254. package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
  255. package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
  256. package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
  257. package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
  258. package/src/prove/smt/solver/theory-lra-model.ts +243 -0
  259. package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
  260. package/src/prove/smt/solver/theory-lra-state.ts +43 -0
  261. package/src/prove/smt/solver/theory-lra.ts +56 -0
  262. package/src/prove/smt/solver/var-subst.ts +258 -0
  263. package/src/prove/smt/solver/z3-license.txt +10 -0
  264. package/src/prove/smt/table.ts +170 -0
  265. package/src/prove/tlapm/tlapm.ts +96 -0
  266. package/src/prove/tlaps-module.ts +510 -0
  267. package/src/prove/verdict.ts +18 -0
  268. package/src/prove/zenon/LICENSE +32 -0
  269. package/src/prove/zenon/check/check.ts +105 -0
  270. package/src/prove/zenon/check/definitions.ts +144 -0
  271. package/src/prove/zenon/check/equality.ts +182 -0
  272. package/src/prove/zenon/check/functions.ts +62 -0
  273. package/src/prove/zenon/check/keys.ts +125 -0
  274. package/src/prove/zenon/check/propositional.ts +104 -0
  275. package/src/prove/zenon/check/records.ts +188 -0
  276. package/src/prove/zenon/check/relations.ts +121 -0
  277. package/src/prove/zenon/check/rewrites.ts +224 -0
  278. package/src/prove/zenon/check/sets.ts +302 -0
  279. package/src/prove/zenon/check/terms.ts +127 -0
  280. package/src/prove/zenon/check/tla.ts +126 -0
  281. package/src/prove/zenon/decide.ts +113 -0
  282. package/src/prove/zenon/encode.ts +379 -0
  283. package/src/prove/zenon/eqrel.ts +300 -0
  284. package/src/prove/zenon/equality-rules.ts +435 -0
  285. package/src/prove/zenon/expr.ts +551 -0
  286. package/src/prove/zenon/index-table.ts +350 -0
  287. package/src/prove/zenon/isar-case.ts +513 -0
  288. package/src/prove/zenon/isar.ts +1249 -0
  289. package/src/prove/zenon/limits.ts +15 -0
  290. package/src/prove/zenon/llproof.ts +173 -0
  291. package/src/prove/zenon/mltoll.ts +1566 -0
  292. package/src/prove/zenon/node.ts +297 -0
  293. package/src/prove/zenon/ocaml.ts +169 -0
  294. package/src/prove/zenon/parse.ts +247 -0
  295. package/src/prove/zenon/phrase.ts +191 -0
  296. package/src/prove/zenon/proof.ts +198 -0
  297. package/src/prove/zenon/propositional-rules.ts +387 -0
  298. package/src/prove/zenon/rules.ts +94 -0
  299. package/src/prove/zenon/search.ts +288 -0
  300. package/src/prove/zenon/tla/functions.ts +151 -0
  301. package/src/prove/zenon/tla/llproof.ts +480 -0
  302. package/src/prove/zenon/tla/records.ts +225 -0
  303. package/src/prove/zenon/tla/rewrites.ts +447 -0
  304. package/src/prove/zenon/tla/sets.ts +304 -0
  305. package/src/prove/zenon/tla/terms.ts +162 -0
  306. package/src/prove/zenon/tla/tla.ts +506 -0
  307. package/src/resolve.ts +1 -1
  308. package/src/run-cli.ts +283 -81
  309. package/src/sany-generator.ts +1 -1
  310. package/src/sany-report.ts +1 -1
  311. package/src/successors.ts +24 -5
  312. package/src/tlapm-cache.ts +236 -0
  313. package/src/tlc-random.ts +55 -32
  314. package/src/tlc-replay.ts +1 -1
  315. package/src/tlc-version.ts +8 -7
  316. package/src/values.ts +47 -4
  317. package/src/worker.ts +65 -0
  318. package/dist/parallel.cjs +0 -12
  319. package/dist/parallel.js +0 -12
  320. package/src/value-sources.ts +0 -29
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license tla-ts
3
+ *
4
+ * Copyright (c) Aiden Bai
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenessViolation:13,assertViolation:14,specEvaluationFailure:75,safetyEvaluationFailure:76,livenessEvaluationFailure:77,specParseError:150,configParseError:151,error:255},t=/* @__PURE__ */ new WeakMap,n=(e,n)=>(e instanceof Error&&!t.has(e)&&t.set(e,n),e),r=e=>t.get(e),i=t=>{try{return t()}catch(t){throw n(t,e.error)}},a=e=>{let t=i(e);return t&&{branches:t.branches,addInitialState:(e,n,r)=>i(()=>t.addInitialState(e,n,r)),addState:(e,n,r,a)=>i(()=>t.addState(e,n,r,a)),findViolation:()=>i(()=>t.findViolation()),getViolatedProperties:(e,n)=>i(()=>t.getViolatedProperties(e,n))}},o=e=>`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 ${e}\n: `,s=o(`java.lang.RuntimeException`),c=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`;var l=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},u=class extends l{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},d=class extends u{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},f=class extends d{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const p=(e,t=!1,n,r=[])=>new u(e.map(e=>`${e.location}\n\n${e.message}`).join(`
10
+
11
+ `),void 0,void 0,{errors:e,warnings:r,isFatal:t,parseError:n}),m=(e,t)=>p([{location:`In module ${t}`,message:`Cannot find source file for module ${e} imported in module ${t}.`}],!0),h=e=>`*** Warnings: ${e.length}\n\n${e.map(e=>`${e.location}\n\n${e.message}\n\n\n`).join(`
12
+ `)}`,g=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,_=(e,t)=>p([{location:g(t),message:e}]);var v=class extends l{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},y=class extends l{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const b=`This was a Java StackOverflowError. It was probably the result
13
+ of an incorrect recursive function definition that caused TLC to enter
14
+ an infinite loop when trying to compute the function or its application
15
+ to an element in its putative domain.`;var x=class extends y{constructor(){super(b)}},S=class extends y{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},C=class extends y{variable;constructor(e,t){super(e),this.variable=t}},w=class extends y{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},T=class extends y{state;constructor(e){super(`current state is not a legal state`),this.name=`TlaEvaluationError`,this.state=e}},E=class extends l{failure;exception;constructor(e,t={}){super(e),this.name=`TlaProofError`,this.failure=t.exception===void 0?t.failure??e:void 0,this.exception=t.exception??`Failure(${JSON.stringify(this.failure)})`}},D=class extends E{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},O=class extends l{constructor(e,t){super(e,t),this.name=`TlaProverError`}},k=class extends l{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},A=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},j=class extends l{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},M=class extends l{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},N=class extends l{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},P=class extends l{constructor(e){super(e),this.name=`SmtInvariantError`}},F=class extends l{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},I=class extends l{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},L=class extends l{constructor(e,t){super(e,t),this.name=`SmtParseError`}},R=class extends j{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const z=t=>r(t)??(t instanceof u?e.specParseError:t instanceof v?e.configParseError:t instanceof y?e.specEvaluationFailure:e.error);var B=class extends l{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},V=class extends l{constructor(e){super(e),this.name=`PcalRuntimeError`}},H=class extends l{constructor(e){super(`You have discovered a bug in pcal.trans.\nSend the following information and the\ninput file to the current maintainer(s).\n\n -- ${e}.`),this.name=`PcalBugError`}};const U=`node:worker_threads`,W=()=>typeof Worker==`function`||typeof process<`u`&&process.versions?.node!==void 0,G=async(e,t,n)=>{if(typeof Worker==`function`){let r=new Worker(e,{type:`module`});return r.addEventListener(`message`,e=>t(e.data)),r.addEventListener(`error`,n),r}let r=new(await(import(
16
+ /* @vite-ignore */
17
+ /* webpackIgnore: true */
18
+ U))).Worker(e);return r.on(`message`,t),r.on(`error`,n),{postMessage:(e,t)=>r.postMessage(e,t),terminate:()=>void r.terminate()}},K=async()=>typeof globalThis.postMessage==`function`?globalThis:(await import(
19
+ /* @vite-ignore */
20
+ /* webpackIgnore: true */
21
+ U)).parentPort;Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return o}});
package/dist/worker.js ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license tla-ts
3
+ *
4
+ * Copyright (c) Aiden Bai
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenessViolation:13,assertViolation:14,specEvaluationFailure:75,safetyEvaluationFailure:76,livenessEvaluationFailure:77,specParseError:150,configParseError:151,error:255},t=/* @__PURE__ */ new WeakMap,n=(e,n)=>(e instanceof Error&&!t.has(e)&&t.set(e,n),e),r=e=>t.get(e),i=t=>{try{return t()}catch(t){throw n(t,e.error)}},a=e=>{let t=i(e);return t&&{branches:t.branches,addInitialState:(e,n,r)=>i(()=>t.addInitialState(e,n,r)),addState:(e,n,r,a)=>i(()=>t.addState(e,n,r,a)),findViolation:()=>i(()=>t.findViolation()),getViolatedProperties:(e,n)=>i(()=>t.getViolatedProperties(e,n))}},o=e=>`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 ${e}\n: `,s=o(`java.lang.RuntimeException`),c=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`;var l=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},u=class extends l{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},d=class extends u{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},f=class extends d{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const p=(e,t=!1,n,r=[])=>new u(e.map(e=>`${e.location}\n\n${e.message}`).join(`
10
+
11
+ `),void 0,void 0,{errors:e,warnings:r,isFatal:t,parseError:n}),m=(e,t)=>p([{location:`In module ${t}`,message:`Cannot find source file for module ${e} imported in module ${t}.`}],!0),h=e=>`*** Warnings: ${e.length}\n\n${e.map(e=>`${e.location}\n\n${e.message}\n\n\n`).join(`
12
+ `)}`,g=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,_=(e,t)=>p([{location:g(t),message:e}]);var v=class extends l{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},y=class extends l{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const b=`This was a Java StackOverflowError. It was probably the result
13
+ of an incorrect recursive function definition that caused TLC to enter
14
+ an infinite loop when trying to compute the function or its application
15
+ to an element in its putative domain.`;var x=class extends y{constructor(){super(b)}},S=class extends y{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},C=class extends y{variable;constructor(e,t){super(e),this.variable=t}},w=class extends y{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},T=class extends y{state;constructor(e){super(`current state is not a legal state`),this.name=`TlaEvaluationError`,this.state=e}},E=class extends l{failure;exception;constructor(e,t={}){super(e),this.name=`TlaProofError`,this.failure=t.exception===void 0?t.failure??e:void 0,this.exception=t.exception??`Failure(${JSON.stringify(this.failure)})`}},D=class extends E{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},O=class extends l{constructor(e,t){super(e,t),this.name=`TlaProverError`}},k=class extends l{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},A=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},j=class extends l{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},M=class extends l{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},N=class extends l{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},P=class extends l{constructor(e){super(e),this.name=`SmtInvariantError`}},F=class extends l{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},I=class extends l{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},L=class extends l{constructor(e,t){super(e,t),this.name=`SmtParseError`}},R=class extends j{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const z=t=>r(t)??(t instanceof u?e.specParseError:t instanceof v?e.configParseError:t instanceof y?e.specEvaluationFailure:e.error);var B=class extends l{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},V=class extends l{constructor(e){super(e),this.name=`PcalRuntimeError`}},H=class extends l{constructor(e){super(`You have discovered a bug in pcal.trans.\nSend the following information and the\ninput file to the current maintainer(s).\n\n -- ${e}.`),this.name=`PcalBugError`}};const U=`node:worker_threads`,W=()=>typeof Worker==`function`||typeof process<`u`&&process.versions?.node!==void 0,G=async(e,t,n)=>{if(typeof Worker==`function`){let r=new Worker(e,{type:`module`});return r.addEventListener(`message`,e=>t(e.data)),r.addEventListener(`error`,n),r}let r=new(await(import(
16
+ /* @vite-ignore */
17
+ /* webpackIgnore: true */
18
+ U))).Worker(e);return r.on(`message`,t),r.on(`error`,n),{postMessage:(e,t)=>r.postMessage(e,t),terminate:()=>void r.terminate()}},K=async()=>typeof globalThis.postMessage==`function`?globalThis:(await import(
19
+ /* @vite-ignore */
20
+ /* webpackIgnore: true */
21
+ U)).parentPort;export{k as A,c as B,E as C,u as D,x as E,_ as F,r as H,g as I,h as L,s as M,m as N,C as O,p as P,z as R,w as S,d as T,n as U,e as V,a as W,T as _,H as a,R as b,I as c,P as d,L as f,y as g,l as h,F as i,D as j,j as k,b as l,v as m,W as n,B as o,M as p,G as r,V as s,K as t,N as u,S as v,O as w,f as x,A as y,o as z};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tla-ts",
3
- "version": "0.0.4-dev.0be9567",
3
+ "version": "0.0.4-dev.2a873ee",
4
4
  "description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
5
5
  "keywords": [
6
6
  "formal verification",
@@ -60,23 +60,32 @@
60
60
  "devDependencies": {
61
61
  "@types/node": "^22",
62
62
  "publint": "^0.3.0",
63
- "tsx": "^4.21.0",
64
63
  "typescript": "^7.0.2",
65
64
  "vite-plus": "latest"
66
65
  },
67
66
  "scripts": {
68
67
  "build": "NODE_ENV=production vp pack",
69
68
  "dev": "NODE_ENV=development vp pack --watch",
70
- "bench": "pnpm build && tsx scripts/benchmark.ts",
71
- "bench:corpus": "pnpm build && tsx scripts/benchmark-corpus.ts",
72
- "conformance": "tsx scripts/conformance.ts",
73
- "conformance:fetch": "tsx scripts/fetch-corpora.ts",
74
- "conformance:sany": "tsx scripts/proof-conformance.ts",
75
- "conformance:record": "tsx scripts/record-tlc.ts",
76
- "conformance:record-sany": "tsx scripts/record-sany.ts",
77
- "conformance:record-statechart": "tsx scripts/record-statechart.ts",
78
- "conformance:record-tlapm": "tsx scripts/record-tlapm.ts",
79
- "conformance:tlapm": "tsx scripts/tlapm-conformance.ts",
69
+ "bench": "pnpm build && bun scripts/run.ts benchmark",
70
+ "bench:corpus": "pnpm build && bun scripts/run.ts benchmark-corpus",
71
+ "bench:prove": "pnpm build && bun scripts/run.ts prove-benchmark",
72
+ "conformance": "bun scripts/run.ts conformance",
73
+ "conformance:fetch": "bun scripts/run.ts fetch-corpora",
74
+ "conformance:fingerprint": "bun scripts/run.ts fingerprint-conformance",
75
+ "conformance:isabelle": "bun scripts/run.ts isabelle-conformance",
76
+ "conformance:isabelle-encode": "bun scripts/run.ts isabelle-encode-conformance",
77
+ "conformance:sany": "bun scripts/run.ts proof-conformance",
78
+ "conformance:ptl": "bun scripts/run.ts ptl-conformance",
79
+ "conformance:smt": "bun scripts/run.ts smt-conformance",
80
+ "conformance:record": "bun scripts/run.ts record-tlc",
81
+ "conformance:record-sany": "bun scripts/run.ts record-sany",
82
+ "conformance:record-statechart": "bun scripts/run.ts record-statechart",
83
+ "conformance:record-proofs": "bun scripts/run.ts record-proofs",
84
+ "conformance:record-tlapm": "bun scripts/run.ts record-tlapm",
85
+ "conformance:smt-encode": "bun scripts/run.ts smt-encode-conformance",
86
+ "conformance:prove": "pnpm build && bun scripts/run.ts prove-conformance",
87
+ "conformance:tlapm": "bun scripts/run.ts tlapm-conformance",
88
+ "conformance:zenon": "bun scripts/run.ts zenon-conformance",
80
89
  "publint": "publint",
81
90
  "test": "vp test",
82
91
  "typecheck": "tsc --noEmit"
package/src/ast.ts CHANGED
@@ -1,4 +1,4 @@
1
- export interface LocalResolution {
1
+ interface LocalResolution {
2
2
  kind: "Local";
3
3
  }
4
4
 
@@ -230,7 +230,7 @@ export type ExceptPathStep =
230
230
  | { kind: "Field"; name: string }
231
231
  | { kind: "Index"; args: Expression[] };
232
232
 
233
- export interface ExceptUpdate {
233
+ interface ExceptUpdate {
234
234
  path: ExceptPathStep[];
235
235
  value: Expression;
236
236
  }
package/src/check.ts CHANGED
@@ -641,6 +641,7 @@ const getSpecification = (config: ModelConfig, environment: Environment): Specif
641
641
  state: undefined,
642
642
  next: undefined,
643
643
  cache: undefined,
644
+ isStreamed: false,
644
645
  },
645
646
  parent,
646
647
  },
@@ -1,4 +1,4 @@
1
- export interface OptionSpec {
1
+ interface OptionSpec {
2
2
  flag: string;
3
3
  isRequired?: boolean;
4
4
  isRepeatable?: boolean;
package/src/errors.ts CHANGED
@@ -39,7 +39,7 @@ export interface SanyError {
39
39
  // The errors SANY reports for a spec, and the warnings it prints before them. A fatal error stops it
40
40
  // before semantic analysis. SANY's parser prints its message for a module it rejects before the
41
41
  // report.
42
- export interface SanyReport {
42
+ interface SanyReport {
43
43
  errors: SanyError[];
44
44
  warnings: SanyError[];
45
45
  isFatal: boolean;
@@ -113,15 +113,6 @@ export const createMissingModuleError = (name: string, importer: string | undefi
113
113
  export const formatSanyWarnings = (warnings: SanyError[]) =>
114
114
  `*** Warnings: ${warnings.length}\n\n${warnings.map((warning) => `${warning.location}\n\n${warning.message}\n\n\n`).join("\n")}`;
115
115
 
116
- // SANY's message for a module its parser rejects, such as a "***Parse Error***" with the
117
- // productions it was in.
118
- export class TlaParseError extends TlaError {
119
- constructor(message: string) {
120
- super(message);
121
- this.name = "TlaParseError";
122
- }
123
- }
124
-
125
116
  export const formatRange = (range: SourceRange) =>
126
117
  `line ${range.start.line}, col ${range.start.column} to line ${range.end.line}, col ${range.end.column} of module ${range.module}`;
127
118
 
@@ -196,24 +187,6 @@ export class TlaModuleError extends TlaEvaluationError {
196
187
  }
197
188
  }
198
189
 
199
- // TLC reports a successor state that the next-state relation leaves incomplete as an error of its
200
- // own, not as an exception. It keeps the name TlaEvaluationError, and index.ts doesn't export it.
201
- export class TlaIncompleteStateError extends TlaEvaluationError {
202
- state: (Value | undefined)[];
203
- action: string | undefined;
204
- missing: string[];
205
-
206
- constructor(state: (Value | undefined)[], action: string | undefined, missing: string[]) {
207
- super(
208
- `Successor state is not completely specified by the next-state action. The following variable${missing.length > 1 ? "s are" : " is"} not defined: ${missing.join(", ")}.\n`,
209
- );
210
- this.name = "TlaEvaluationError";
211
- this.state = state;
212
- this.action = action;
213
- this.missing = missing;
214
- }
215
- }
216
-
217
190
  // TLC reports an initial state that the initial predicate leaves incomplete as an illegal state.
218
191
  export class TlaIllegalStateError extends TlaEvaluationError {
219
192
  state: (Value | undefined)[];
@@ -225,7 +198,7 @@ export class TlaIllegalStateError extends TlaEvaluationError {
225
198
  }
226
199
  }
227
200
 
228
- export interface TlapmReport {
201
+ interface TlapmReport {
229
202
  failure?: string;
230
203
  exception?: string;
231
204
  }
@@ -251,6 +224,39 @@ export class TlapmBugError extends TlaProofError {
251
224
  }
252
225
  }
253
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
+
254
260
  export class TlaUnsupportedError extends TlaError {
255
261
  constructor(message: string, cause?: unknown) {
256
262
  super(message, cause);
@@ -258,6 +264,59 @@ export class TlaUnsupportedError extends TlaError {
258
264
  }
259
265
  }
260
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
+
261
320
  // An exception that TLC's Java code throws and nothing catches, with the stack trace it prints, after
262
321
  // what the frames that the exception unwinds print about it.
263
322
  export class TlaJavaException extends TlaUnsupportedError {
package/src/evaluate.ts CHANGED
@@ -54,6 +54,7 @@ import {
54
54
  markLambdaFunction,
55
55
  isReducibleSet,
56
56
  isSetValue,
57
+ isSettledValue,
57
58
  MAXIMUM_INTEGER,
58
59
  MINIMUM_INTEGER,
59
60
  toFiniteFunction,
@@ -113,6 +114,9 @@ export interface Thunk {
113
114
  state: State | undefined;
114
115
  next: State | undefined;
115
116
  cache: Value | undefined;
117
+ // Whether the expression may build a set that streams until TLC caches it, so that the thunk
118
+ // caches only a settled value.
119
+ isStreamed: boolean;
116
120
  }
117
121
 
118
122
  type Binding = { kind: "Value"; value: Value } | Thunk | { kind: "Operator"; operator: Operator };
@@ -563,12 +567,12 @@ export const forEachBinding = (
563
567
  visit: (scope: Scope | undefined) => boolean,
564
568
  ) => forEachBoundElement(bounds, getBoundElements(bounds, context), context.scope, visit);
565
569
 
566
- export const getBoundsDomain = (bounds: Bound[], context: Context): Value => {
570
+ const getBoundsDomain = (bounds: Bound[], context: Context): Value => {
567
571
  const sets = bounds.map((bound) => evaluate(bound.set, context));
568
572
  return sets.length === 1 ? sets[0] : { kind: "ProductSet", factors: sets };
569
573
  };
570
574
 
571
- export const bindArgument = (bounds: Bound[], scope: Scope | undefined, argument: Value) => {
575
+ const bindArgument = (bounds: Bound[], scope: Scope | undefined, argument: Value) => {
572
576
  if (bounds.length === 1) return bindPattern(scope, bounds[0].pattern, argument);
573
577
  const components = getSequenceElements(argument) ?? [];
574
578
  return bounds.reduce<Scope | undefined>(
@@ -847,7 +851,7 @@ const forceThunk = (thunk: Thunk, context: Context) => {
847
851
  const isSameState = thunk.state === context.state && thunk.next === context.next;
848
852
  if (isSameState && thunk.cache !== undefined) return thunk.cache;
849
853
  const value = evaluate(thunk.expression, withScope(context, thunk.scope));
850
- if (isSameState) thunk.cache = value;
854
+ if (isSameState && (!thunk.isStreamed || isSettledValue(value))) thunk.cache = value;
851
855
  return value;
852
856
  };
853
857
 
@@ -968,6 +972,7 @@ const createThunk = (expression: Expression, context: Context): Thunk => ({
968
972
  state: context.state,
969
973
  next: context.next,
970
974
  cache: undefined,
975
+ isStreamed: false,
971
976
  });
972
977
 
973
978
  export const findGlobalName = (name: string, environment: Environment): GlobalName | undefined => {
@@ -1027,6 +1032,7 @@ export const bindOperatorArguments = (
1027
1032
  closure: Closure,
1028
1033
  args: Expression[],
1029
1034
  context: Context,
1035
+ binders?: ArgumentBinder[],
1030
1036
  ): Scope | undefined => {
1031
1037
  if (args.length !== closure.params.length) {
1032
1038
  throw new TlaEvaluationError(
@@ -1039,18 +1045,36 @@ export const bindOperatorArguments = (
1039
1045
  const binding: Binding =
1040
1046
  param.arity > 0
1041
1047
  ? { kind: "Operator", operator: evaluateOperatorArgument(args[index], context) }
1042
- : getArgumentBinder(args[index], context.environment)(context);
1048
+ : (binders?.[index] ?? getArgumentBinder(args[index], context.environment))(context);
1043
1049
  scope = { name: param.name, binding, parent: scope };
1044
1050
  }
1045
1051
  return scope;
1046
1052
  };
1047
1053
 
1048
- const callOperator = (operator: Operator, args: Expression[], context: Context) => {
1054
+ // The body a call site last called and its evaluator, as a site mostly calls one closure.
1055
+ interface CalledBody {
1056
+ body: Expression;
1057
+ evaluator: Evaluator;
1058
+ }
1059
+
1060
+ const callOperator = (
1061
+ operator: Operator,
1062
+ args: Expression[],
1063
+ context: Context,
1064
+ called: { entry: CalledBody | undefined },
1065
+ binders: ArgumentBinder[],
1066
+ ) => {
1049
1067
  if (operator.kind === "Closure") {
1050
- return evaluate(
1051
- operator.body,
1052
- withScope(context, bindOperatorArguments(operator, args, context)),
1053
- );
1068
+ const bodyContext = withScope(context, bindOperatorArguments(operator, args, context, binders));
1069
+ if (context.environment.callStack) return evaluate(operator.body, bodyContext);
1070
+ const entry =
1071
+ called.entry?.body === operator.body
1072
+ ? called.entry
1073
+ : (called.entry = {
1074
+ body: operator.body,
1075
+ evaluator: getEntryEvaluator(operator.body, context.environment),
1076
+ });
1077
+ return entry.evaluator(bodyContext);
1054
1078
  }
1055
1079
  if (operator.kind === "Operator") return operator.call(args.map((arg) => evaluate(arg, context)));
1056
1080
  if (operator.isLazy) return operator.evaluate(getLazyArguments(args, context), context);
@@ -1064,10 +1088,16 @@ const callOperator = (operator: Operator, args: Expression[], context: Context)
1064
1088
  );
1065
1089
  };
1066
1090
 
1091
+ // The LET definitions that a reference evaluates again, and those that cache only a settled value.
1092
+ interface ReevaluatedDefinitions {
1093
+ impure: ReadonlySet<Definition>;
1094
+ streamed: ReadonlySet<Definition>;
1095
+ }
1096
+
1067
1097
  export const bindDefinitions = (
1068
1098
  definitions: Definition[],
1069
1099
  context: Context,
1070
- reevaluated?: ReadonlySet<Definition>,
1100
+ reevaluated?: ReevaluatedDefinitions,
1071
1101
  ): Scope | undefined =>
1072
1102
  definitions.reduce<Scope | undefined>((scope, definition) => {
1073
1103
  const node: Scope = {
@@ -1089,10 +1119,11 @@ export const bindDefinitions = (
1089
1119
  state: context.state,
1090
1120
  next: context.next,
1091
1121
  cache: undefined,
1122
+ isStreamed: false,
1092
1123
  };
1093
1124
  return node;
1094
1125
  }
1095
- if (definition.params.length > 0 || reevaluated?.has(definition)) {
1126
+ if (definition.params.length > 0 || reevaluated?.impure.has(definition)) {
1096
1127
  node.binding = {
1097
1128
  kind: "Operator",
1098
1129
  operator: {
@@ -1112,6 +1143,7 @@ export const bindDefinitions = (
1112
1143
  state: context.state,
1113
1144
  next: context.next,
1114
1145
  cache: undefined,
1146
+ isStreamed: reevaluated?.streamed.has(definition) ?? false,
1115
1147
  };
1116
1148
  return node;
1117
1149
  }, context.scope);
@@ -1228,14 +1260,15 @@ const STREAMED_SET: Impurity = {
1228
1260
  // TLC's next-state generator does not bind LET definitions to values, so each reference to one
1229
1261
  // evaluates it again: one that calls an impure builtin repeats its effects, and a set one builds
1230
1262
  // with UNION or \cup starts out uncached.
1231
- export const getReevaluatedDefinitions = (definitions: Definition[], environment: Environment) =>
1232
- new Set(
1233
- definitions.filter(
1234
- (definition) =>
1235
- isImpureDefinition(definition, environment) ||
1236
- isImpureDefinition(definition, environment, STREAMED_SET),
1237
- ),
1238
- );
1263
+ export const getReevaluatedDefinitions = (
1264
+ definitions: Definition[],
1265
+ environment: Environment,
1266
+ ): ReevaluatedDefinitions => ({
1267
+ impure: new Set(definitions.filter((definition) => isImpureDefinition(definition, environment))),
1268
+ streamed: new Set(
1269
+ definitions.filter((definition) => isImpureDefinition(definition, environment, STREAMED_SET)),
1270
+ ),
1271
+ });
1239
1272
 
1240
1273
  export const isImpure = (environment: Environment) =>
1241
1274
  [...environment.definitions.values()].some((definition) =>
@@ -1519,7 +1552,7 @@ export const getEvaluator = (expression: Expression, environment: Environment):
1519
1552
 
1520
1553
  const entryEvaluators = new WeakMap<Expression, Evaluator>();
1521
1554
 
1522
- const getEntryEvaluator = (expression: Expression, environment: Environment) => {
1555
+ export const getEntryEvaluator = (expression: Expression, environment: Environment) => {
1523
1556
  if (environment.callStack) return getEvaluator(expression, environment);
1524
1557
  const cached = entryEvaluators.get(expression);
1525
1558
  if (cached) return cached;
@@ -1986,9 +2019,11 @@ const compileApply = (
1986
2019
  );
1987
2020
  };
1988
2021
  }
2022
+ const called = { entry: undefined as CalledBody | undefined };
2023
+ const binders = args.map((arg) => getArgumentBinder(arg, environment));
1989
2024
  return (context) => {
1990
2025
  const operator = resolveOperator(expression.operator, context);
1991
- if (operator) return callOperator(operator, args, context);
2026
+ if (operator) return callOperator(operator, args, context, called, binders);
1992
2027
  const definition = environment.definitions.get(expression.operator);
1993
2028
  if (definition?.kind === "Function") {
1994
2029
  throw new TlaEvaluationError(`${expression.operator} is a function; apply it with brackets`);
package/src/index.ts CHANGED
@@ -18,6 +18,16 @@ export {
18
18
  } from "./errors";
19
19
  export { check } from "./parallel";
20
20
  export { parseModule } from "./parser";
21
+ export { prove } from "./prove/prove";
22
+ export type {
23
+ ProofObligation,
24
+ ProofStatus,
25
+ ProveOptions,
26
+ ProveResult,
27
+ ProvedObligation,
28
+ TrivialObligation,
29
+ UnprovedObligation,
30
+ } from "./prove/prove";
21
31
  export type { Module } from "./ast";
22
32
  export { formatValue } from "./values";
23
33
  export type { Value } from "./values";
package/src/live-check.ts CHANGED
@@ -49,7 +49,7 @@ export interface LivenessChecker {
49
49
  getViolatedProperties: (path: Value[][], cycleStart: number) => string[];
50
50
  }
51
51
 
52
- export interface LiveGraph {
52
+ interface LiveGraph {
53
53
  getFingerprint: (successor: LiveSuccessor) => number;
54
54
  getSuccessors: (index: number, state: Value[]) => LiveSuccessor[];
55
55
  }