tla-ts 0.0.4-dev.a0009b7 → 0.0.4-dev.b254db0

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 (313) hide show
  1. package/README.md +33 -143
  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 +37 -1
  6. package/dist/index.d.ts +37 -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/check.ts +1 -0
  26. package/src/codegen.ts +26 -7
  27. package/src/errors.ts +86 -0
  28. package/src/evaluate.ts +63 -20
  29. package/src/index.ts +10 -0
  30. package/src/{obligation-action.ts → obligations/action.ts} +265 -55
  31. package/src/{obligation-anon.ts → obligations/anon.ts} +47 -37
  32. package/src/obligations/ctx.ts +64 -0
  33. package/src/{obligation-deref.ts → obligations/deref.ts} +38 -61
  34. package/src/{obligation-expression.ts → obligations/expression.ts} +78 -45
  35. package/src/{obligation-format.ts → obligations/format.ts} +7 -8
  36. package/src/{obligation-generate.ts → obligations/generate.ts} +147 -74
  37. package/src/{obligations.ts → obligations/index.ts} +29 -13
  38. package/src/{obligation-levels.ts → obligations/levels.ts} +14 -5
  39. package/src/{obligation-module.ts → obligations/module.ts} +56 -33
  40. package/src/obligations/pickle.ts +98 -0
  41. package/src/obligations/pragma.ts +189 -0
  42. package/src/{obligation-printer.ts → obligations/printer.ts} +22 -80
  43. package/src/{obligation-proof.ts → obligations/proof.ts} +7 -1
  44. package/src/{obligation-source.ts → obligations/source.ts} +159 -97
  45. package/src/obligations/temporal.ts +319 -0
  46. package/src/{obligation-tuples.ts → obligations/tuples.ts} +1 -1
  47. package/src/ocaml-marshal.ts +166 -0
  48. package/src/parallel-worker.ts +2 -18
  49. package/src/parallel.ts +10 -43
  50. package/src/prove/decide-pool.ts +100 -0
  51. package/src/prove/deciders.ts +33 -0
  52. package/src/prove/isabelle/LICENSE +36 -0
  53. package/src/prove/isabelle/LICENSE-tlapm +26 -0
  54. package/src/prove/isabelle/decide.ts +47 -0
  55. package/src/prove/isabelle/encode.ts +503 -0
  56. package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
  57. package/src/prove/isabelle/isar/method.ts +367 -0
  58. package/src/prove/isabelle/isar/proof.ts +28 -0
  59. package/src/prove/isabelle/isar/statement.ts +57 -0
  60. package/src/prove/isabelle/isar/theory.ts +192 -0
  61. package/src/prove/isabelle/isar/type-check.ts +278 -0
  62. package/src/prove/isabelle/provers/blast/blast.ts +258 -0
  63. package/src/prove/isabelle/provers/blast/branch.ts +322 -0
  64. package/src/prove/isabelle/provers/blast/prove.ts +347 -0
  65. package/src/prove/isabelle/provers/blast/rules.ts +330 -0
  66. package/src/prove/isabelle/provers/blast/state.ts +180 -0
  67. package/src/prove/isabelle/provers/blast/term.ts +547 -0
  68. package/src/prove/isabelle/provers/clasimp.ts +150 -0
  69. package/src/prove/isabelle/provers/classical.ts +389 -0
  70. package/src/prove/isabelle/provers/hypsubst.ts +441 -0
  71. package/src/prove/isabelle/pure/bicompose.ts +174 -0
  72. package/src/prove/isabelle/pure/consts.ts +32 -0
  73. package/src/prove/isabelle/pure/conv.ts +79 -0
  74. package/src/prove/isabelle/pure/drule.ts +264 -0
  75. package/src/prove/isabelle/pure/envir.ts +363 -0
  76. package/src/prove/isabelle/pure/goal.ts +53 -0
  77. package/src/prove/isabelle/pure/interrupt.ts +16 -0
  78. package/src/prove/isabelle/pure/list.ts +12 -0
  79. package/src/prove/isabelle/pure/logic.ts +402 -0
  80. package/src/prove/isabelle/pure/name.ts +110 -0
  81. package/src/prove/isabelle/pure/net.ts +262 -0
  82. package/src/prove/isabelle/pure/object-logic.ts +41 -0
  83. package/src/prove/isabelle/pure/pattern.ts +650 -0
  84. package/src/prove/isabelle/pure/raw-simplifier.ts +353 -0
  85. package/src/prove/isabelle/pure/rewriter.ts +602 -0
  86. package/src/prove/isabelle/pure/search.ts +68 -0
  87. package/src/prove/isabelle/pure/seq.ts +156 -0
  88. package/src/prove/isabelle/pure/simplifier.ts +112 -0
  89. package/src/prove/isabelle/pure/table.ts +208 -0
  90. package/src/prove/isabelle/pure/tactic.ts +276 -0
  91. package/src/prove/isabelle/pure/tactical.ts +347 -0
  92. package/src/prove/isabelle/pure/term-ord.ts +159 -0
  93. package/src/prove/isabelle/pure/term.ts +808 -0
  94. package/src/prove/isabelle/pure/thm.ts +806 -0
  95. package/src/prove/isabelle/pure/type.ts +133 -0
  96. package/src/prove/isabelle/pure/unify.ts +753 -0
  97. package/src/prove/isabelle/pure/variable.ts +25 -0
  98. package/src/prove/isabelle/tla/classical-setup.ts +101 -0
  99. package/src/prove/isabelle/tla/context.ts +74 -0
  100. package/src/prove/isabelle/tla/logic-data.ts +5 -0
  101. package/src/prove/isabelle/tla/logic.ts +215 -0
  102. package/src/prove/isabelle/tla/simpdata.ts +241 -0
  103. package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
  104. package/src/prove/ocaml.ts +22 -0
  105. package/src/prove/prep/action.ts +521 -0
  106. package/src/prove/prep/defs.ts +33 -0
  107. package/src/prove/prep/elab.ts +156 -0
  108. package/src/prove/prep/enabled-axioms.ts +189 -0
  109. package/src/prove/prep/enabled.ts +43 -0
  110. package/src/prove/prep/fingerprint.ts +388 -0
  111. package/src/prove/prep/flatten.ts +70 -0
  112. package/src/prove/prep/level-comparison.ts +557 -0
  113. package/src/prove/prep/md5.ts +67 -0
  114. package/src/prove/prep/pragma.ts +221 -0
  115. package/src/prove/prep/trivial.ts +22 -0
  116. package/src/prove/prove-worker.ts +25 -0
  117. package/src/prove/prove.ts +505 -0
  118. package/src/prove/ptl/decide.ts +68 -0
  119. package/src/prove/ptl/encode.ts +256 -0
  120. package/src/prove/ptl/sat.ts +151 -0
  121. package/src/prove/ptl/tableau.ts +276 -0
  122. package/src/prove/smt/axiomatize.ts +69 -0
  123. package/src/prove/smt/axioms.ts +222 -0
  124. package/src/prove/smt/context.ts +108 -0
  125. package/src/prove/smt/data.ts +636 -0
  126. package/src/prove/smt/encode.ts +166 -0
  127. package/src/prove/smt/extensionality.ts +65 -0
  128. package/src/prove/smt/flatten.ts +112 -0
  129. package/src/prove/smt/format.ts +154 -0
  130. package/src/prove/smt/instances.ts +182 -0
  131. package/src/prove/smt/rewrite.ts +773 -0
  132. package/src/prove/smt/simplify.ts +57 -0
  133. package/src/prove/smt/solver/act-cache.ts +265 -0
  134. package/src/prove/smt/solver/arith-rewriter.ts +962 -0
  135. package/src/prove/smt/solver/array.ts +22 -0
  136. package/src/prove/smt/solver/asserted-formulas.ts +469 -0
  137. package/src/prove/smt/solver/ast-lt.ts +157 -0
  138. package/src/prove/smt/solver/ast-util.ts +147 -0
  139. package/src/prove/smt/solver/ast.ts +1315 -0
  140. package/src/prove/smt/solver/auf-solver.ts +572 -0
  141. package/src/prove/smt/solver/case-split-queue.ts +178 -0
  142. package/src/prove/smt/solver/cg-table.ts +175 -0
  143. package/src/prove/smt/solver/clause.ts +276 -0
  144. package/src/prove/smt/solver/conflict-resolution.ts +343 -0
  145. package/src/prove/smt/solver/context.ts +1292 -0
  146. package/src/prove/smt/solver/ctx-simplify.ts +334 -0
  147. package/src/prove/smt/solver/der.ts +224 -0
  148. package/src/prove/smt/solver/dyn-ack.ts +141 -0
  149. package/src/prove/smt/solver/e-matching.ts +659 -0
  150. package/src/prove/smt/solver/enode.ts +259 -0
  151. package/src/prove/smt/solver/expr-ref.ts +21 -0
  152. package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
  153. package/src/prove/smt/solver/fingerprints.ts +92 -0
  154. package/src/prove/smt/solver/flat-literals.ts +51 -0
  155. package/src/prove/smt/solver/goal.ts +138 -0
  156. package/src/prove/smt/solver/hash.ts +173 -0
  157. package/src/prove/smt/solver/hashtable.ts +166 -0
  158. package/src/prove/smt/solver/internalizer.ts +1381 -0
  159. package/src/prove/smt/solver/lbool.ts +5 -0
  160. package/src/prove/smt/solver/literal.ts +24 -0
  161. package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
  162. package/src/prove/smt/solver/lp/constraints.ts +78 -0
  163. package/src/prove/smt/solver/lp/containers.ts +296 -0
  164. package/src/prove/smt/solver/lp/core-solver.ts +504 -0
  165. package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
  166. package/src/prove/smt/solver/lp/dep-intervals.ts +656 -0
  167. package/src/prove/smt/solver/lp/dependency.ts +51 -0
  168. package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
  169. package/src/prove/smt/solver/lp/explanation.ts +46 -0
  170. package/src/prove/smt/solver/lp/gomory.ts +255 -0
  171. package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
  172. package/src/prove/smt/solver/lp/hnf.ts +281 -0
  173. package/src/prove/smt/solver/lp/int-cube.ts +295 -0
  174. package/src/prove/smt/solver/lp/int-solver.ts +514 -0
  175. package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
  176. package/src/prove/smt/solver/lp/lar-term.ts +62 -0
  177. package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
  178. package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
  179. package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
  180. package/src/prove/smt/solver/lp/nex.ts +120 -0
  181. package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
  182. package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
  183. package/src/prove/smt/solver/lp/nla-core.ts +968 -0
  184. package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
  185. package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
  186. package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
  187. package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
  188. package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
  189. package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
  190. package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
  191. package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
  192. package/src/prove/smt/solver/lp/nla-order.ts +307 -0
  193. package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
  194. package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
  195. package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
  196. package/src/prove/smt/solver/lp/nla-types.ts +124 -0
  197. package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
  198. package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
  199. package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
  200. package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
  201. package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
  202. package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
  203. package/src/prove/smt/solver/lp/pdd.ts +971 -0
  204. package/src/prove/smt/solver/lp/random-updater.ts +138 -0
  205. package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
  206. package/src/prove/smt/solver/lp/union-find.ts +96 -0
  207. package/src/prove/smt/solver/mam-compiler.ts +847 -0
  208. package/src/prove/smt/solver/mam-interpreter.ts +400 -0
  209. package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
  210. package/src/prove/smt/solver/model-checker.ts +347 -0
  211. package/src/prove/smt/solver/model-evaluator.ts +262 -0
  212. package/src/prove/smt/solver/model-finder.ts +155 -0
  213. package/src/prove/smt/solver/model-generator.ts +97 -0
  214. package/src/prove/smt/solver/model-macro-solver.ts +728 -0
  215. package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
  216. package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
  217. package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
  218. package/src/prove/smt/solver/nlsat/explain.ts +607 -0
  219. package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
  220. package/src/prove/smt/solver/nlsat/levelwise.ts +740 -0
  221. package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
  222. package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
  223. package/src/prove/smt/solver/nlsat/solver.ts +911 -0
  224. package/src/prove/smt/solver/nlsat/types.ts +43 -0
  225. package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
  226. package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
  227. package/src/prove/smt/solver/nnf.ts +469 -0
  228. package/src/prove/smt/solver/pattern-inference.ts +351 -0
  229. package/src/prove/smt/solver/poly-rewriter.ts +477 -0
  230. package/src/prove/smt/solver/propagate-values.ts +83 -0
  231. package/src/prove/smt/solver/proto-model.ts +551 -0
  232. package/src/prove/smt/solver/pull-quant.ts +139 -0
  233. package/src/prove/smt/solver/qe-lite-der.ts +526 -0
  234. package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
  235. package/src/prove/smt/solver/qe-lite.ts +381 -0
  236. package/src/prove/smt/solver/qi-queue.ts +362 -0
  237. package/src/prove/smt/solver/quant-tactics.ts +117 -0
  238. package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
  239. package/src/prove/smt/solver/quantifier-manager.ts +186 -0
  240. package/src/prove/smt/solver/random-gen.ts +10 -0
  241. package/src/prove/smt/solver/rational.ts +165 -0
  242. package/src/prove/smt/solver/ref-vector.ts +62 -0
  243. package/src/prove/smt/solver/relevancy.ts +247 -0
  244. package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
  245. package/src/prove/smt/solver/rewriter.ts +843 -0
  246. package/src/prove/smt/solver/rlimit.ts +79 -0
  247. package/src/prove/smt/solver/smtlib-parser.ts +526 -0
  248. package/src/prove/smt/solver/solver.ts +71 -0
  249. package/src/prove/smt/solver/sort.ts +35 -0
  250. package/src/prove/smt/solver/sticky-generations.ts +69 -0
  251. package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
  252. package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
  253. package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
  254. package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
  255. package/src/prove/smt/solver/theory-lra-model.ts +243 -0
  256. package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
  257. package/src/prove/smt/solver/theory-lra-state.ts +43 -0
  258. package/src/prove/smt/solver/theory-lra.ts +56 -0
  259. package/src/prove/smt/solver/var-subst.ts +258 -0
  260. package/src/prove/smt/solver/z3-license.txt +10 -0
  261. package/src/prove/smt/table.ts +170 -0
  262. package/src/prove/tlapm/tlapm.ts +96 -0
  263. package/src/prove/tlaps-module.ts +510 -0
  264. package/src/prove/verdict.ts +18 -0
  265. package/src/prove/zenon/LICENSE +32 -0
  266. package/src/prove/zenon/check/check.ts +105 -0
  267. package/src/prove/zenon/check/definitions.ts +144 -0
  268. package/src/prove/zenon/check/equality.ts +182 -0
  269. package/src/prove/zenon/check/functions.ts +62 -0
  270. package/src/prove/zenon/check/keys.ts +125 -0
  271. package/src/prove/zenon/check/propositional.ts +104 -0
  272. package/src/prove/zenon/check/records.ts +188 -0
  273. package/src/prove/zenon/check/relations.ts +121 -0
  274. package/src/prove/zenon/check/rewrites.ts +224 -0
  275. package/src/prove/zenon/check/sets.ts +302 -0
  276. package/src/prove/zenon/check/terms.ts +127 -0
  277. package/src/prove/zenon/check/tla.ts +126 -0
  278. package/src/prove/zenon/decide.ts +113 -0
  279. package/src/prove/zenon/encode.ts +437 -0
  280. package/src/prove/zenon/eqrel.ts +300 -0
  281. package/src/prove/zenon/equality-rules.ts +435 -0
  282. package/src/prove/zenon/expr.ts +551 -0
  283. package/src/prove/zenon/index-table.ts +350 -0
  284. package/src/prove/zenon/isar-case.ts +513 -0
  285. package/src/prove/zenon/isar.ts +1249 -0
  286. package/src/prove/zenon/limits.ts +15 -0
  287. package/src/prove/zenon/llproof.ts +173 -0
  288. package/src/prove/zenon/mltoll.ts +1566 -0
  289. package/src/prove/zenon/node.ts +297 -0
  290. package/src/prove/zenon/ocaml.ts +169 -0
  291. package/src/prove/zenon/parse.ts +247 -0
  292. package/src/prove/zenon/phrase.ts +191 -0
  293. package/src/prove/zenon/proof.ts +198 -0
  294. package/src/prove/zenon/propositional-rules.ts +387 -0
  295. package/src/prove/zenon/rules.ts +94 -0
  296. package/src/prove/zenon/search.ts +288 -0
  297. package/src/prove/zenon/tla/functions.ts +151 -0
  298. package/src/prove/zenon/tla/llproof.ts +480 -0
  299. package/src/prove/zenon/tla/records.ts +225 -0
  300. package/src/prove/zenon/tla/rewrites.ts +447 -0
  301. package/src/prove/zenon/tla/sets.ts +304 -0
  302. package/src/prove/zenon/tla/terms.ts +181 -0
  303. package/src/prove/zenon/tla/tla.ts +506 -0
  304. package/src/run-cli.ts +334 -75
  305. package/src/standard-modules.ts +5 -2
  306. package/src/successors.ts +24 -5
  307. package/src/tlapm-cache.ts +236 -0
  308. package/src/tlc-random.ts +55 -32
  309. package/src/tlc-version.ts +8 -7
  310. package/src/values.ts +97 -47
  311. package/src/worker.ts +65 -0
  312. package/dist/parallel.cjs +0 -12
  313. package/dist/parallel.js +0 -12
@@ -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.a0009b7",
3
+ "version": "0.0.4-dev.b254db0",
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/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
  },
package/src/codegen.ts CHANGED
@@ -177,7 +177,7 @@ const generateQuantifier = (
177
177
  }, test);
178
178
  const parameters = outer.map((local) => `, ${local}`).join("");
179
179
  generator.helpers.push(
180
- `function ${name}(context, state, next${parameters}) { let primed; ${declarations.join(" ")} ${loops} return ${isForall}; }`,
180
+ `function ${name}(context, state, next${parameters}) { let primed; let applied; ${declarations.join(" ")} ${loops} return ${isForall}; }`,
181
181
  );
182
182
  return `${name}(${frame.context}, ${frame.state}, ${frame.isPrimed ? "undefined" : frame.next}${parameters})`;
183
183
  };
@@ -247,6 +247,23 @@ const isConstructionFree = (
247
247
  }
248
248
  };
249
249
 
250
+ // Whether the generated code evaluates an expression only in the context its frame names. A primed
251
+ // expression doesn't, since it shares the generated function's primed context.
252
+ const isReadOnly = (expression: Expression): boolean => {
253
+ switch (expression.kind) {
254
+ case "Identifier":
255
+ case "Number":
256
+ case "String":
257
+ return true;
258
+ case "FieldAccess":
259
+ return isReadOnly(expression.record);
260
+ case "FunctionApplication":
261
+ return [expression.function, ...expression.args].every(isReadOnly);
262
+ default:
263
+ return false;
264
+ }
265
+ };
266
+
250
267
  const generateExpression = (generator: Generator, expression: Expression, frame: Frame): string => {
251
268
  const generate = (node: Expression, nodeFrame = frame) =>
252
269
  generateExpression(generator, node, nodeFrame);
@@ -287,17 +304,19 @@ const generateExpression = (generator: Generator, expression: Expression, frame:
287
304
  case "FunctionApplication": {
288
305
  keepLazy(expression.function);
289
306
  // The interpreter evaluates a function that may construct one with EvalControl.KeepLazy.
307
+ const keepLazyFrame = { ...frame, context: `keepLazyContext(${frame.context})` };
290
308
  const evaluatedFunction = isConstructionFree(
291
309
  expression.function,
292
310
  frame,
293
311
  generator.environment,
294
312
  )
295
313
  ? generate(expression.function)
296
- : generateDelegate(generator, expression.function, {
297
- ...frame,
298
- context: `keepLazyContext(${frame.context})`,
299
- });
300
- const functionCode = `expectFunction(${evaluatedFunction}, ${addReference(generator, expression)})`;
314
+ : isReadOnly(expression.function)
315
+ ? generate(expression.function, keepLazyFrame)
316
+ : generateDelegate(generator, expression.function, keepLazyFrame);
317
+ // Tool#evalAppl checks that it applies a function before it evaluates the argument. The check
318
+ // is written out, as calling expectFunction for each application costs more.
319
+ const functionCode = `(applied = ${evaluatedFunction}, typeof applied === "object" && (applied.kind === "Function" || applied.kind === "LazyFunction") ? applied : expectFunction(applied, ${addReference(generator, expression)}))`;
301
320
  const describeMissing = getMissingArgumentDescriber(generator.environment.runtime.version);
302
321
  const error = describeMissing ? `, ${addReference(generator, describeMissing)}` : "";
303
322
  if (expression.args.length === 1)
@@ -370,7 +389,7 @@ export const generateEvaluator = (
370
389
  };
371
390
  const body = generateExpression(generator, expression, frame);
372
391
  const referenceNames = generator.references.map((_, index) => `reference${index}`);
373
- const source = `${generator.helpers.join("\n")}\nreturn (context) => { const state = context.state; const next = context.next; let primed; return ${body}; };`;
392
+ const source = `${generator.helpers.join("\n")}\nreturn (context) => { const state = context.state; const next = context.next; let primed; let applied; return ${body}; };`;
374
393
  runtime.value ??= createRuntime();
375
394
  const helpers = runtime.value;
376
395
  const helperNames = Object.keys(helpers);
package/src/errors.ts CHANGED
@@ -251,6 +251,39 @@ export class TlapmBugError extends TlaProofError {
251
251
  }
252
252
  }
253
253
 
254
+ // A backend can't take an obligation, which tlapm reports as not tried.
255
+ export class TlaProverError extends TlaError {
256
+ constructor(message: string, cause?: unknown) {
257
+ super(message, cause);
258
+ this.name = "TlaProverError";
259
+ }
260
+ }
261
+
262
+ // Zenon gives up on a .znn file the way the OCaml Zenon raises an exception and prints no proof.
263
+ export class TlaZenonError extends TlaError {
264
+ constructor(message: string, cause?: unknown) {
265
+ super(message, cause);
266
+ this.name = "TlaZenonError";
267
+ }
268
+ }
269
+
270
+ // The exceptions Isabelle raises: ERROR for a rejected theory or a failed proof, TERM, TYPE and THM
271
+ // for an ill-formed term, type or theorem, and Interrupt when the time limit runs out.
272
+ export type IsabelleException = "ERROR" | "TERM" | "TYPE" | "THM" | "Interrupt";
273
+
274
+ // Isabelle's tactics raise and handle these as control flow, often millions of times per proof, and
275
+ // decideIsabelle answers "unknown" for any that escape. So unlike an Error, it skips the stack trace.
276
+ export class TlaIsabelleError {
277
+ readonly name = "TlaIsabelleError";
278
+ readonly exception: IsabelleException;
279
+ readonly message: string;
280
+
281
+ constructor(exception: IsabelleException, message: string) {
282
+ this.exception = exception;
283
+ this.message = message;
284
+ }
285
+ }
286
+
254
287
  export class TlaUnsupportedError extends TlaError {
255
288
  constructor(message: string, cause?: unknown) {
256
289
  super(message, cause);
@@ -258,6 +291,59 @@ export class TlaUnsupportedError extends TlaError {
258
291
  }
259
292
  }
260
293
 
294
+ // The SMT solver met input outside the SMT-LIB subset that tlapm emits, or a numeral too large for
295
+ // its exact arithmetic. The solver answers unknown.
296
+ export class SmtUnsupportedError extends TlaError {
297
+ constructor(message: string, cause?: unknown) {
298
+ super(message, cause);
299
+ this.name = "SmtUnsupportedError";
300
+ }
301
+ }
302
+
303
+ // The SMT solver ran past its time limit, or its signal aborted, in the middle of a rewrite. The
304
+ // solver answers unknown.
305
+ export class SmtCanceledError extends TlaError {
306
+ constructor() {
307
+ super("the SMT solver was canceled");
308
+ this.name = "SmtCanceledError";
309
+ }
310
+ }
311
+
312
+ // The SMT solver broke one of its own invariants, a bug in the port rather than in the input. It
313
+ // keeps its name, and index.ts doesn't export it.
314
+ export class SmtInvariantError extends TlaError {
315
+ constructor(message: string) {
316
+ super(message);
317
+ this.name = "SmtInvariantError";
318
+ }
319
+ }
320
+
321
+ // nlsat reached a case Z3 leaves unimplemented, where Z3 exits the process. nra answers unknown
322
+ // instead. index.ts doesn't export it.
323
+ export class NlsatUnsupportedError extends TlaError {
324
+ constructor(reason: string) {
325
+ super(`nlsat does not implement ${reason}`);
326
+ this.name = "NlsatUnsupportedError";
327
+ }
328
+ }
329
+
330
+ // mem_out: the pdd manager needed a node past its limit outside an operation. Grobner catches it
331
+ // and gives up on the round. index.ts doesn't export it.
332
+ export class PddMemoryOutError extends TlaError {
333
+ constructor() {
334
+ super("the pdd manager ran out of nodes");
335
+ this.name = "PddMemoryOutError";
336
+ }
337
+ }
338
+
339
+ // The SMT-LIB input is malformed: a syntax error, an undeclared symbol, or an ill-sorted application.
340
+ export class SmtParseError extends TlaError {
341
+ constructor(message: string, cause?: unknown) {
342
+ super(message, cause);
343
+ this.name = "SmtParseError";
344
+ }
345
+ }
346
+
261
347
  // An exception that TLC's Java code throws and nothing catches, with the stack trace it prints, after
262
348
  // what the frames that the exception unwinds print about it.
263
349
  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 };
@@ -380,7 +384,15 @@ export const expectFunction = (value: Value, application: Expression) => {
380
384
  };
381
385
 
382
386
  export const toKeepLazyContext = (context: Context): Context =>
383
- context.isKeepLazy ? context : { ...context, isKeepLazy: true };
387
+ context.isKeepLazy
388
+ ? context
389
+ : {
390
+ environment: context.environment,
391
+ scope: context.scope,
392
+ state: context.state,
393
+ next: context.next,
394
+ isKeepLazy: true,
395
+ };
384
396
 
385
397
  const withScope = (context: Context, scope: Scope | undefined): Context => ({
386
398
  environment: context.environment,
@@ -839,7 +851,7 @@ const forceThunk = (thunk: Thunk, context: Context) => {
839
851
  const isSameState = thunk.state === context.state && thunk.next === context.next;
840
852
  if (isSameState && thunk.cache !== undefined) return thunk.cache;
841
853
  const value = evaluate(thunk.expression, withScope(context, thunk.scope));
842
- if (isSameState) thunk.cache = value;
854
+ if (isSameState && (!thunk.isStreamed || isSettledValue(value))) thunk.cache = value;
843
855
  return value;
844
856
  };
845
857
 
@@ -960,6 +972,7 @@ const createThunk = (expression: Expression, context: Context): Thunk => ({
960
972
  state: context.state,
961
973
  next: context.next,
962
974
  cache: undefined,
975
+ isStreamed: false,
963
976
  });
964
977
 
965
978
  export const findGlobalName = (name: string, environment: Environment): GlobalName | undefined => {
@@ -1019,6 +1032,7 @@ export const bindOperatorArguments = (
1019
1032
  closure: Closure,
1020
1033
  args: Expression[],
1021
1034
  context: Context,
1035
+ binders?: ArgumentBinder[],
1022
1036
  ): Scope | undefined => {
1023
1037
  if (args.length !== closure.params.length) {
1024
1038
  throw new TlaEvaluationError(
@@ -1031,18 +1045,36 @@ export const bindOperatorArguments = (
1031
1045
  const binding: Binding =
1032
1046
  param.arity > 0
1033
1047
  ? { kind: "Operator", operator: evaluateOperatorArgument(args[index], context) }
1034
- : getArgumentBinder(args[index], context.environment)(context);
1048
+ : (binders?.[index] ?? getArgumentBinder(args[index], context.environment))(context);
1035
1049
  scope = { name: param.name, binding, parent: scope };
1036
1050
  }
1037
1051
  return scope;
1038
1052
  };
1039
1053
 
1040
- 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
+ ) => {
1041
1067
  if (operator.kind === "Closure") {
1042
- return evaluate(
1043
- operator.body,
1044
- withScope(context, bindOperatorArguments(operator, args, context)),
1045
- );
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);
1046
1078
  }
1047
1079
  if (operator.kind === "Operator") return operator.call(args.map((arg) => evaluate(arg, context)));
1048
1080
  if (operator.isLazy) return operator.evaluate(getLazyArguments(args, context), context);
@@ -1056,10 +1088,16 @@ const callOperator = (operator: Operator, args: Expression[], context: Context)
1056
1088
  );
1057
1089
  };
1058
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
+
1059
1097
  export const bindDefinitions = (
1060
1098
  definitions: Definition[],
1061
1099
  context: Context,
1062
- reevaluated?: ReadonlySet<Definition>,
1100
+ reevaluated?: ReevaluatedDefinitions,
1063
1101
  ): Scope | undefined =>
1064
1102
  definitions.reduce<Scope | undefined>((scope, definition) => {
1065
1103
  const node: Scope = {
@@ -1081,10 +1119,11 @@ export const bindDefinitions = (
1081
1119
  state: context.state,
1082
1120
  next: context.next,
1083
1121
  cache: undefined,
1122
+ isStreamed: false,
1084
1123
  };
1085
1124
  return node;
1086
1125
  }
1087
- if (definition.params.length > 0 || reevaluated?.has(definition)) {
1126
+ if (definition.params.length > 0 || reevaluated?.impure.has(definition)) {
1088
1127
  node.binding = {
1089
1128
  kind: "Operator",
1090
1129
  operator: {
@@ -1104,6 +1143,7 @@ export const bindDefinitions = (
1104
1143
  state: context.state,
1105
1144
  next: context.next,
1106
1145
  cache: undefined,
1146
+ isStreamed: reevaluated?.streamed.has(definition) ?? false,
1107
1147
  };
1108
1148
  return node;
1109
1149
  }, context.scope);
@@ -1220,14 +1260,15 @@ const STREAMED_SET: Impurity = {
1220
1260
  // TLC's next-state generator does not bind LET definitions to values, so each reference to one
1221
1261
  // evaluates it again: one that calls an impure builtin repeats its effects, and a set one builds
1222
1262
  // with UNION or \cup starts out uncached.
1223
- export const getReevaluatedDefinitions = (definitions: Definition[], environment: Environment) =>
1224
- new Set(
1225
- definitions.filter(
1226
- (definition) =>
1227
- isImpureDefinition(definition, environment) ||
1228
- isImpureDefinition(definition, environment, STREAMED_SET),
1229
- ),
1230
- );
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
+ });
1231
1272
 
1232
1273
  export const isImpure = (environment: Environment) =>
1233
1274
  [...environment.definitions.values()].some((definition) =>
@@ -1511,7 +1552,7 @@ export const getEvaluator = (expression: Expression, environment: Environment):
1511
1552
 
1512
1553
  const entryEvaluators = new WeakMap<Expression, Evaluator>();
1513
1554
 
1514
- const getEntryEvaluator = (expression: Expression, environment: Environment) => {
1555
+ export const getEntryEvaluator = (expression: Expression, environment: Environment) => {
1515
1556
  if (environment.callStack) return getEvaluator(expression, environment);
1516
1557
  const cached = entryEvaluators.get(expression);
1517
1558
  if (cached) return cached;
@@ -1978,9 +2019,11 @@ const compileApply = (
1978
2019
  );
1979
2020
  };
1980
2021
  }
2022
+ const called = { entry: undefined as CalledBody | undefined };
2023
+ const binders = args.map((arg) => getArgumentBinder(arg, environment));
1981
2024
  return (context) => {
1982
2025
  const operator = resolveOperator(expression.operator, context);
1983
- if (operator) return callOperator(operator, args, context);
2026
+ if (operator) return callOperator(operator, args, context, called, binders);
1984
2027
  const definition = environment.definitions.get(expression.operator);
1985
2028
  if (definition?.kind === "Function") {
1986
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";