tla-ts 0.0.9 → 0.0.10-dev.b4a856304

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (390) hide show
  1. package/README.md +29 -1
  2. package/dist/compile.cjs +23 -0
  3. package/dist/compile.js +23 -0
  4. package/dist/deciders.cjs +28 -28
  5. package/dist/deciders.js +43 -43
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +72 -10
  8. package/dist/index.d.ts +72 -10
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +116 -36
  15. package/dist/prove.js +116 -36
  16. package/dist/run.cjs +143 -31
  17. package/dist/run.js +143 -31
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +128 -103
  21. package/dist/transfer.js +128 -103
  22. package/dist/worker.cjs +7 -7
  23. package/dist/worker.js +7 -7
  24. package/package.json +3 -1
  25. package/src/ast.ts +7 -21
  26. package/src/bags.ts +99 -99
  27. package/src/builtins.ts +44 -75
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +576 -300
  30. package/src/cli/options.ts +11 -6
  31. package/src/cli/run.ts +2 -2
  32. package/src/cli/runtime-invariants.ts +135 -0
  33. package/src/cli/shared.ts +20 -9
  34. package/src/cli/tlapm.ts +0 -12
  35. package/src/cli/tlc-arguments.ts +646 -0
  36. package/src/cli/tlc-usage.ts +362 -0
  37. package/src/cli/tlc.ts +538 -220
  38. package/src/cli/typescript.ts +23 -0
  39. package/src/cli/xml-exporter.ts +4 -16
  40. package/src/cli.ts +0 -1
  41. package/src/codegen.ts +191 -64
  42. package/src/config.ts +140 -109
  43. package/src/coverage.ts +837 -0
  44. package/src/dependencies.ts +6 -40
  45. package/src/dfid.ts +618 -0
  46. package/src/environment.ts +240 -118
  47. package/src/errors.ts +70 -55
  48. package/src/evaluate.ts +630 -297
  49. package/src/exit-codes.ts +37 -3
  50. package/src/fingerprints.ts +10 -10
  51. package/src/index.ts +3 -0
  52. package/src/instances.ts +79 -11
  53. package/src/java-overrides.ts +2 -12
  54. package/src/json-reader.ts +456 -0
  55. package/src/json.ts +262 -139
  56. package/src/levels.ts +2 -3
  57. package/src/lexer.ts +17 -26
  58. package/src/liveness-checker.ts +10 -18
  59. package/src/liveness.ts +121 -49
  60. package/src/obligations/action.ts +4 -28
  61. package/src/obligations/anonymize.ts +84 -80
  62. package/src/obligations/equality.ts +1 -1
  63. package/src/obligations/expression.ts +2 -19
  64. package/src/obligations/format.ts +1 -9
  65. package/src/obligations/generate.ts +1 -11
  66. package/src/obligations/index.ts +0 -11
  67. package/src/obligations/levels.ts +4 -8
  68. package/src/obligations/module.ts +1 -15
  69. package/src/obligations/normalize.ts +5 -24
  70. package/src/obligations/operators.ts +1 -2
  71. package/src/obligations/pragma.ts +1 -10
  72. package/src/obligations/printer.ts +47 -46
  73. package/src/obligations/proof.ts +1 -5
  74. package/src/obligations/regroup.ts +1 -4
  75. package/src/obligations/simplify.ts +3 -14
  76. package/src/obligations/source.ts +1 -21
  77. package/src/obligations/subexpression.ts +5 -11
  78. package/src/obligations/substitution.ts +1 -3
  79. package/src/obligations/temporal.ts +8 -14
  80. package/src/obligations/tuples.ts +3 -9
  81. package/src/parallel-worker.ts +29 -39
  82. package/src/parallel.ts +29 -13
  83. package/src/parser.ts +436 -90
  84. package/src/pcal/ast.ts +7 -28
  85. package/src/pcal/parse.ts +11 -39
  86. package/src/pcal/tokenize.ts +4 -20
  87. package/src/pcal/translate.ts +10 -42
  88. package/src/pcal/validate.ts +3 -21
  89. package/src/pretty-print.ts +1 -2
  90. package/src/prover/decide-pool.ts +5 -10
  91. package/src/prover/deciders.ts +0 -4
  92. package/src/prover/first-order.ts +0 -11
  93. package/src/prover/isabelle/decide.ts +0 -6
  94. package/src/prover/isabelle/encode.ts +11 -23
  95. package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
  96. package/src/prover/isabelle/isar/method.ts +25 -38
  97. package/src/prover/isabelle/isar/proof.ts +1 -10
  98. package/src/prover/isabelle/isar/statement.ts +1 -6
  99. package/src/prover/isabelle/isar/theory.ts +15 -26
  100. package/src/prover/isabelle/isar/type-check.ts +11 -25
  101. package/src/prover/isabelle/provers/blast/blast.ts +10 -41
  102. package/src/prover/isabelle/provers/blast/branch.ts +1 -32
  103. package/src/prover/isabelle/provers/blast/prove.ts +1 -35
  104. package/src/prover/isabelle/provers/blast/rules.ts +6 -44
  105. package/src/prover/isabelle/provers/blast/state.ts +2 -28
  106. package/src/prover/isabelle/provers/blast/term.ts +9 -36
  107. package/src/prover/isabelle/provers/clasimp.ts +1 -13
  108. package/src/prover/isabelle/provers/classical.ts +14 -42
  109. package/src/prover/isabelle/provers/hypsubst.ts +11 -25
  110. package/src/prover/isabelle/pure/bicompose.ts +16 -13
  111. package/src/prover/isabelle/pure/consts.ts +1 -7
  112. package/src/prover/isabelle/pure/conv.ts +1 -9
  113. package/src/prover/isabelle/pure/drule.ts +24 -40
  114. package/src/prover/isabelle/pure/envir.ts +3 -52
  115. package/src/prover/isabelle/pure/goal.ts +1 -7
  116. package/src/prover/isabelle/pure/interrupt.ts +0 -5
  117. package/src/prover/isabelle/pure/list.ts +0 -3
  118. package/src/prover/isabelle/pure/logic.ts +1 -14
  119. package/src/prover/isabelle/pure/name.ts +2 -9
  120. package/src/prover/isabelle/pure/net.ts +3 -59
  121. package/src/prover/isabelle/pure/object-logic.ts +3 -10
  122. package/src/prover/isabelle/pure/pattern.ts +2 -19
  123. package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
  124. package/src/prover/isabelle/pure/rewriter.ts +26 -58
  125. package/src/prover/isabelle/pure/search.ts +3 -10
  126. package/src/prover/isabelle/pure/seq.ts +1 -10
  127. package/src/prover/isabelle/pure/simplifier.ts +4 -12
  128. package/src/prover/isabelle/pure/table.ts +1 -31
  129. package/src/prover/isabelle/pure/tactic.ts +12 -22
  130. package/src/prover/isabelle/pure/tactical.ts +6 -12
  131. package/src/prover/isabelle/pure/term-ord.ts +2 -6
  132. package/src/prover/isabelle/pure/term.ts +2 -43
  133. package/src/prover/isabelle/pure/thm.ts +13 -36
  134. package/src/prover/isabelle/pure/type.ts +2 -15
  135. package/src/prover/isabelle/pure/unify.ts +20 -30
  136. package/src/prover/isabelle/pure/variable.ts +3 -7
  137. package/src/prover/isabelle/tla/classical-setup.ts +9 -19
  138. package/src/prover/isabelle/tla/context.ts +8 -16
  139. package/src/prover/isabelle/tla/logic.ts +4 -11
  140. package/src/prover/isabelle/tla/simpdata.ts +46 -34
  141. package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
  142. package/src/prover/ocaml.ts +0 -6
  143. package/src/prover/prep/action.ts +4 -36
  144. package/src/prover/prep/enabled-axioms.ts +12 -19
  145. package/src/prover/prep/fingerprint.ts +0 -16
  146. package/src/prover/prep/level-comparison.ts +8 -12
  147. package/src/prover/prep/md5.ts +0 -2
  148. package/src/prover/prep/methods.ts +9 -36
  149. package/src/prover/prep/normalize.ts +4 -28
  150. package/src/prover/prove-worker.ts +0 -2
  151. package/src/prover/prove.ts +0 -36
  152. package/src/prover/ptl/decide.ts +7 -12
  153. package/src/prover/ptl/encode.ts +14 -36
  154. package/src/prover/ptl/sat.ts +24 -32
  155. package/src/prover/ptl/tableau.ts +12 -26
  156. package/src/prover/smt/axioms.ts +0 -7
  157. package/src/prover/smt/context.ts +19 -26
  158. package/src/prover/smt/data.ts +51 -54
  159. package/src/prover/smt/encode.ts +14 -35
  160. package/src/prover/smt/extensionality.ts +0 -10
  161. package/src/prover/smt/flatten.ts +3 -22
  162. package/src/prover/smt/format.ts +5 -10
  163. package/src/prover/smt/instances.ts +0 -10
  164. package/src/prover/smt/rewrite.ts +66 -101
  165. package/src/prover/smt/solver/act-cache.ts +0 -15
  166. package/src/prover/smt/solver/arith-rewriter.ts +3 -48
  167. package/src/prover/smt/solver/array.ts +1 -3
  168. package/src/prover/smt/solver/asserted-formulas.ts +1 -43
  169. package/src/prover/smt/solver/ast-lt.ts +1 -11
  170. package/src/prover/smt/solver/ast-util.ts +1 -6
  171. package/src/prover/smt/solver/ast.ts +1 -143
  172. package/src/prover/smt/solver/auf-solver.ts +6 -39
  173. package/src/prover/smt/solver/case-split-queue.ts +1 -9
  174. package/src/prover/smt/solver/cg-table.ts +1 -18
  175. package/src/prover/smt/solver/clause.ts +1 -27
  176. package/src/prover/smt/solver/conflict-resolution.ts +0 -9
  177. package/src/prover/smt/solver/context.ts +4 -61
  178. package/src/prover/smt/solver/ctx-simplify.ts +14 -41
  179. package/src/prover/smt/solver/der.ts +2 -21
  180. package/src/prover/smt/solver/dyn-ack.ts +1 -11
  181. package/src/prover/smt/solver/e-matching.ts +3 -34
  182. package/src/prover/smt/solver/enode.ts +1 -21
  183. package/src/prover/smt/solver/expr-ref.ts +1 -5
  184. package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
  185. package/src/prover/smt/solver/fingerprints.ts +1 -12
  186. package/src/prover/smt/solver/flat-literals.ts +1 -9
  187. package/src/prover/smt/solver/goal.ts +2 -14
  188. package/src/prover/smt/solver/hash.ts +0 -8
  189. package/src/prover/smt/solver/hashtable.ts +1 -12
  190. package/src/prover/smt/solver/internalizer.ts +6 -98
  191. package/src/prover/smt/solver/lbool.ts +1 -2
  192. package/src/prover/smt/solver/literal.ts +0 -3
  193. package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
  194. package/src/prover/smt/solver/lp/constraints.ts +2 -8
  195. package/src/prover/smt/solver/lp/containers.ts +12 -30
  196. package/src/prover/smt/solver/lp/core-solver.ts +10 -31
  197. package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
  198. package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
  199. package/src/prover/smt/solver/lp/dependency.ts +1 -4
  200. package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
  201. package/src/prover/smt/solver/lp/explanation.ts +1 -6
  202. package/src/prover/smt/solver/lp/gomory.ts +9 -22
  203. package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
  204. package/src/prover/smt/solver/lp/hnf.ts +11 -26
  205. package/src/prover/smt/solver/lp/int-cube.ts +15 -36
  206. package/src/prover/smt/solver/lp/int-solver.ts +4 -34
  207. package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
  208. package/src/prover/smt/solver/lp/lar-term.ts +1 -5
  209. package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
  210. package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
  211. package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
  212. package/src/prover/smt/solver/lp/nex.ts +1 -6
  213. package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
  214. package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
  215. package/src/prover/smt/solver/lp/nla-core.ts +35 -130
  216. package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
  217. package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
  218. package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
  219. package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
  220. package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
  221. package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
  222. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
  223. package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
  224. package/src/prover/smt/solver/lp/nla-order.ts +2 -13
  225. package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
  226. package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
  227. package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
  228. package/src/prover/smt/solver/lp/nla-types.ts +1 -11
  229. package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
  230. package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
  231. package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
  232. package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
  233. package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
  234. package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
  235. package/src/prover/smt/solver/lp/pdd.ts +7 -70
  236. package/src/prover/smt/solver/lp/random-updater.ts +1 -8
  237. package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
  238. package/src/prover/smt/solver/lp/union-find.ts +1 -6
  239. package/src/prover/smt/solver/mam-compiler.ts +14 -56
  240. package/src/prover/smt/solver/mam-interpreter.ts +1 -21
  241. package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
  242. package/src/prover/smt/solver/model-checker.ts +2 -36
  243. package/src/prover/smt/solver/model-evaluator.ts +3 -29
  244. package/src/prover/smt/solver/model-finder.ts +3 -15
  245. package/src/prover/smt/solver/model-generator.ts +1 -12
  246. package/src/prover/smt/solver/model-macro-solver.ts +12 -69
  247. package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
  248. package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
  249. package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
  250. package/src/prover/smt/solver/nlsat/explain.ts +3 -47
  251. package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
  252. package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
  253. package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
  254. package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
  255. package/src/prover/smt/solver/nlsat/solver.ts +7 -67
  256. package/src/prover/smt/solver/nlsat/types.ts +1 -8
  257. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
  258. package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
  259. package/src/prover/smt/solver/nnf.ts +3 -38
  260. package/src/prover/smt/solver/pattern-inference.ts +2 -15
  261. package/src/prover/smt/solver/poly-rewriter.ts +3 -23
  262. package/src/prover/smt/solver/propagate-values.ts +1 -10
  263. package/src/prover/smt/solver/proto-model.ts +3 -48
  264. package/src/prover/smt/solver/pull-quant.ts +1 -12
  265. package/src/prover/smt/solver/qe-lite-der.ts +1 -29
  266. package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
  267. package/src/prover/smt/solver/qe-lite.ts +3 -33
  268. package/src/prover/smt/solver/qi-queue.ts +1 -16
  269. package/src/prover/smt/solver/quant-tactics.ts +5 -22
  270. package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
  271. package/src/prover/smt/solver/quantifier-manager.ts +1 -8
  272. package/src/prover/smt/solver/random-gen.ts +1 -2
  273. package/src/prover/smt/solver/rational.ts +1 -8
  274. package/src/prover/smt/solver/ref-vector.ts +1 -6
  275. package/src/prover/smt/solver/relevancy.ts +2 -15
  276. package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
  277. package/src/prover/smt/solver/rewriter.ts +3 -85
  278. package/src/prover/smt/solver/rlimit.ts +2 -20
  279. package/src/prover/smt/solver/smtlib-parser.ts +2 -37
  280. package/src/prover/smt/solver/solver.ts +23 -34
  281. package/src/prover/smt/solver/sort.ts +1 -5
  282. package/src/prover/smt/solver/sticky-generations.ts +0 -5
  283. package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
  284. package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
  285. package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
  286. package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
  287. package/src/prover/smt/solver/theory-lra-model.ts +4 -19
  288. package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
  289. package/src/prover/smt/solver/theory-lra-state.ts +3 -8
  290. package/src/prover/smt/solver/theory-lra.ts +1 -8
  291. package/src/prover/smt/solver/var-subst.ts +2 -26
  292. package/src/prover/smt/table.ts +0 -8
  293. package/src/prover/tlapm/cache.ts +20 -25
  294. package/src/prover/tlapm/ocaml-marshal.ts +19 -21
  295. package/src/prover/tlapm/tlapm.ts +12 -17
  296. package/src/prover/verdict.ts +0 -2
  297. package/src/prover/zenon/check/check.ts +0 -9
  298. package/src/prover/zenon/check/definitions.ts +5 -15
  299. package/src/prover/zenon/check/equality.ts +0 -8
  300. package/src/prover/zenon/check/functions.ts +0 -4
  301. package/src/prover/zenon/check/keys.ts +0 -7
  302. package/src/prover/zenon/check/propositional.ts +0 -3
  303. package/src/prover/zenon/check/records.ts +0 -5
  304. package/src/prover/zenon/check/relations.ts +0 -13
  305. package/src/prover/zenon/check/rewrites.ts +0 -6
  306. package/src/prover/zenon/check/sets.ts +0 -3
  307. package/src/prover/zenon/check/terms.ts +0 -17
  308. package/src/prover/zenon/check/tla.ts +0 -6
  309. package/src/prover/zenon/decide.ts +0 -12
  310. package/src/prover/zenon/encode.ts +1 -8
  311. package/src/prover/zenon/eqrel.ts +0 -13
  312. package/src/prover/zenon/equality-rules.ts +0 -4
  313. package/src/prover/zenon/expr.ts +1 -26
  314. package/src/prover/zenon/index-table.ts +17 -38
  315. package/src/prover/zenon/isar-case.ts +9 -19
  316. package/src/prover/zenon/isar.ts +1 -29
  317. package/src/prover/zenon/limits.ts +0 -4
  318. package/src/prover/zenon/llproof.ts +0 -9
  319. package/src/prover/zenon/mltoll.ts +54 -76
  320. package/src/prover/zenon/node.ts +1 -11
  321. package/src/prover/zenon/ocaml.ts +1 -17
  322. package/src/prover/zenon/parse.ts +2 -7
  323. package/src/prover/zenon/phrase.ts +1 -11
  324. package/src/prover/zenon/proof.ts +0 -9
  325. package/src/prover/zenon/propositional-rules.ts +0 -5
  326. package/src/prover/zenon/rules.ts +2 -6
  327. package/src/prover/zenon/search.ts +1 -17
  328. package/src/prover/zenon/tla/functions.ts +57 -29
  329. package/src/prover/zenon/tla/llproof.ts +63 -70
  330. package/src/prover/zenon/tla/records.ts +56 -27
  331. package/src/prover/zenon/tla/rewrites.ts +12 -19
  332. package/src/prover/zenon/tla/sets.ts +68 -39
  333. package/src/prover/zenon/tla/terms.ts +0 -6
  334. package/src/prover/zenon/tla/tla.ts +59 -58
  335. package/src/randomization.ts +84 -35
  336. package/src/resolve.ts +18 -60
  337. package/src/runtime.ts +11 -4
  338. package/src/sany/builtins.ts +3 -4
  339. package/src/sany/generator.ts +119 -169
  340. package/src/sany/levels.ts +6 -30
  341. package/src/sany/lexer.ts +7 -23
  342. package/src/sany/linter.ts +1 -8
  343. package/src/sany/modules.ts +1 -5
  344. package/src/sany/nodes.ts +0 -31
  345. package/src/sany/parse-error.ts +39 -117
  346. package/src/sany/report.ts +29 -63
  347. package/src/sany/selectors.ts +15 -39
  348. package/src/sany/source.ts +1 -17
  349. package/src/sany/xml.ts +13 -63
  350. package/src/search.ts +494 -154
  351. package/src/simulate.ts +694 -0
  352. package/src/spec-description.ts +166 -48
  353. package/src/standard-definitions.ts +2 -3
  354. package/src/standard-modules.ts +264 -68
  355. package/src/state-graph.ts +51 -18
  356. package/src/subexpressions.ts +31 -5
  357. package/src/substitution-levels.ts +2 -3
  358. package/src/successors.ts +267 -77
  359. package/src/symmetry.ts +31 -8
  360. package/src/tableau.ts +27 -24
  361. package/src/tlc/fingerprint.ts +183 -61
  362. package/src/tlc/jar-data.ts +113 -6
  363. package/src/tlc/messages.ts +122 -37
  364. package/src/tlc/order.ts +33 -38
  365. package/src/tlc/random.ts +16 -16
  366. package/src/tlc/replay.ts +563 -211
  367. package/src/tlc/summary.ts +2 -4
  368. package/src/tlc/tlc-operators.ts +81 -36
  369. package/src/tlc/tlcext-operators.ts +138 -117
  370. package/src/tlc/trace-spec.ts +273 -0
  371. package/src/tlc/value-stream.ts +143 -0
  372. package/src/tlc/version.ts +2 -4
  373. package/src/transfer.ts +22 -25
  374. package/src/typescript/actions.ts +481 -0
  375. package/src/typescript/collections.ts +600 -0
  376. package/src/typescript/compile.ts +65 -0
  377. package/src/typescript/context.ts +94 -0
  378. package/src/typescript/emit.ts +121 -0
  379. package/src/typescript/expressions.ts +496 -0
  380. package/src/typescript/formula.ts +152 -0
  381. package/src/typescript/functions.ts +284 -0
  382. package/src/typescript/model.ts +163 -0
  383. package/src/typescript/names.ts +114 -0
  384. package/src/typescript/program.ts +48 -0
  385. package/src/typescript/properties.ts +139 -0
  386. package/src/typescript/scope.ts +112 -0
  387. package/src/typescript/steps.ts +165 -0
  388. package/src/typescript/types.ts +171 -0
  389. package/src/values.ts +826 -276
  390. package/src/worker.ts +7 -8
package/dist/worker.cjs CHANGED
@@ -6,19 +6,19 @@
6
6
  * This source code is licensed under the MIT license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
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=o(`tlc2.tool.EvalException`),l=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`;var u=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},d=class extends u{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},f=class extends d{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},p=class extends f{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const m=(e,t=!1,n,r=[])=>new d(e.map(e=>`${e.location}\n\n${e.message}`).join(`
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=new Map([...[...Array.from({length:24},(e,t)=>2222+t),2272,2273,2274,2280,2281,...Array.from({length:7},(e,t)=>5001+t)].map(t=>[t,e.configParseError]),[2253,e.livenessEvaluationFailure],[2109,e.specEvaluationFailure],[2115,e.specEvaluationFailure],[2103,e.specEvaluationFailure],[2147,e.specEvaluationFailure],[2111,e.safetyEvaluationFailure],[2146,e.safetyEvaluationFailure],[2107,e.safetyViolation],[2110,e.safetyViolation],[2112,e.livenessViolation],[2113,e.livenessViolation],[2116,e.livenessViolation],[2108,e.livenessViolation],[2114,e.deadlock],[2104,e.assumptionViolation],[2105,e.assumptionViolation],[2404,e.assumptionViolation],[2405,e.assumptionViolation],[2780,e.assumptionViolation],[2132,e.assertViolation],[2171,e.specParseError],[3002,e.specParseError]]),n=n=>t.get(n)??e.error,r=/* @__PURE__ */ new WeakMap,i=(e,t)=>(e instanceof Error&&!r.has(e)&&r.set(e,t),e),a=e=>r.get(e),o=t=>{try{return t()}catch(t){throw i(t,e.error)}},s=e=>{let t=o(e);return t&&{branches:t.branches,addInitialState:(e,n,r)=>o(()=>t.addInitialState(e,n,r)),addState:(e,n,r,i)=>o(()=>t.addState(e,n,r,i)),findViolation:()=>o(()=>t.findViolation()),getViolatedProperties:(e,n)=>o(()=>t.getViolatedProperties(e,n))}},c=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: `,l=c(`java.lang.RuntimeException`),ee=c(`tlc2.tool.EvalException`),u=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`||e instanceof SyntaxError&&e.message.endsWith(`: Stack overflow`);var d=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},f=class extends d{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},p=class extends f{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},m=class extends p{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const h=(e,t=!1,n,r=[])=>new f(e.map(e=>`${e.location}\n\n${e.message}`).join(`
10
10
 
11
- `),void 0,void 0,{errors:e,warnings:r,isFatal:t,parseError:n}),h=(e,t)=>m([{location:`In module ${t}`,message:`Cannot find source file for module ${e} imported in module ${t}.`}],!0),g=e=>`*** Warnings: ${e.length}\n\n${e.map(e=>`${e.location}\n\n${e.message}\n\n\n`).join(`
12
- `)}`,_=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,v=(e,t)=>m([{location:_(t),message:e}]);var y=class extends u{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},b=class extends u{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const x=`This was a Java StackOverflowError. It was probably the result
11
+ `),void 0,void 0,{errors:e,warnings:r,isFatal:t,parseError:n}),g=(e,t)=>h([{location:`In module ${t}`,message:`Cannot find source file for module ${e} imported in module ${t}.`}],!0),_=e=>`*** Warnings: ${e.length}\n\n${e.map(e=>`${e.location}\n\n${e.message}\n\n\n`).join(`
12
+ `)}`,v=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,y=(e,t)=>h([{location:v(t),message:e}]);var b=class extends d{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},x=class extends d{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const S=`This was a Java StackOverflowError. It was probably the result
13
13
  of an incorrect recursive function definition that caused TLC to enter
14
14
  an infinite loop when trying to compute the function or its application
15
- to an element in its putative domain.`;var S=class extends b{constructor(){super(x)}};const C=()=>n(new S,e.error);var w=class extends b{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},T=class extends b{variable;constructor(e,t){super(e),this.variable=t}},E=class extends b{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},D=class extends b{state;constructor(e){super(`current state is not a legal state`),this.name=`TlaEvaluationError`,this.state=e}},O=class extends u{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)})`}},k=class extends O{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},A=class extends u{constructor(e,t){super(e,t),this.name=`TlaProverError`}},j=class extends u{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},M=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},N=class extends u{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},P=class extends u{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},F=class extends u{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},I=class extends u{constructor(e){super(e),this.name=`SmtInvariantError`}},L=class extends u{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},R=class extends u{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},z=class extends u{constructor(e,t){super(e,t),this.name=`SmtParseError`}},B=class extends N{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const V=t=>r(t)??(t instanceof d?e.specParseError:t instanceof y?e.configParseError:t instanceof b?e.specEvaluationFailure:e.error);var H=class extends u{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},U=class extends u{constructor(e){super(e),this.name=`PcalRuntimeError`}},W=class extends u{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 G=`node:worker_threads`,K=()=>typeof Worker==`function`||typeof process<`u`&&process.versions?.node!==void 0,q=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(
15
+ to an element in its putative domain.`;var C=class extends x{constructor(){super(S)}};const w=()=>i(new C,e.error);var T=class extends x{},E=class extends x{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},D=class extends x{variable;constructor(e,t){super(e),this.variable=t}},O=class extends x{exitCode;constructor(t,n=e.error){super(t),this.exitCode=n}},k=class extends x{constructor(t){super(t),i(this,e.error)}},A=class extends T{constructor(){super(`PickSuccessor reached the end of standard input without an answer whether to extend the behavior.`)}},j=class extends x{constructor(t){super(`The directory ${t} holds no checkpoint to recover from.`),i(this,e.error)}},M=class extends x{},N=class extends x{};const P=`Too many possible next states for the last state in the trace.`;var F=class extends x{constructor(){super(P)}},I=class extends x{code;constructor(e,t){super(t),this.code=e}},L=class extends x{},R=class extends x{state;constructor(e){super(`current state is not a legal state`),this.state=e}},z=class extends d{failure;exception;locus;constructor(e,t={}){super(e),this.locus=t.locus,this.name=`TlaProofError`,this.failure=t.exception===void 0?t.failure??e:void 0,this.exception=t.exception??`Failure(${JSON.stringify(this.failure)})`}},B=class extends z{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e})}},V=class extends d{constructor(e,t){super(e,t),this.name=`TlaProverError`}},te=class extends d{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},H=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},U=class extends d{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},W=class extends d{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},G=class extends d{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},K=class extends d{constructor(e){super(e),this.name=`SmtInvariantError`}},q=class extends d{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},J=class extends d{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},Y=class extends d{constructor(e,t){super(e,t),this.name=`SmtParseError`}},X=class extends U{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const Z=t=>a(t)??(t instanceof f?e.specParseError:t instanceof b?e.configParseError:t instanceof x?e.specEvaluationFailure:e.error);var Q=class extends d{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},ne=class extends d{constructor(e){super(e),this.name=`PcalRuntimeError`}},re=class extends d{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`}},ie=class extends d{constructor(e,t){let n=t?.getSourceFile(),r=n?.getLineAndCharacterOfPosition(t?.getStart()??0);super(n===void 0||r===void 0?e:`${n.fileName}:${r.line+1}:${r.character+1} ${e}`),this.name=`TlaTypeScriptError`}};const $=`node:worker_threads`,ae=()=>typeof Worker==`function`||typeof process<`u`&&process.versions?.node!==void 0,oe=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
16
  /* @vite-ignore */
17
17
  /* webpackIgnore: true */
18
- G))).Worker(e);return r.on(`message`,t),r.on(`error`,n),{postMessage:(e,t)=>r.postMessage(e,t),terminate:()=>void r.terminate()}},J=async()=>typeof globalThis.postMessage==`function`?globalThis:(await import(
18
+ $))).Worker(e);return r.on(`message`,t),r.on(`error`,n),{postMessage:(e,t)=>r.postMessage(e,t),terminate:()=>void r.terminate()}},se=async()=>typeof globalThis.postMessage==`function`?globalThis:(await import(
19
19
  /* @vite-ignore */
20
20
  /* webpackIgnore: true */
21
- G)).parentPort,Y=()=>{let e=`Bun`in globalThis?import(
21
+ $)).parentPort,ce=()=>{let e=`Bun`in globalThis?import(
22
22
  /* @vite-ignore */
23
23
  /* webpackIgnore: true */
24
- `bun:jsc`):void 0;return async()=>{(await e)?.edenGC(),await new Promise(e=>typeof setImmediate==`function`?setImmediate(e):setTimeout(e,0))}};Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"G",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"K",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"q",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return _}});
24
+ `bun:jsc`):void 0;return async()=>{(await e)?.edenGC(),await new Promise(e=>typeof setImmediate==`function`?setImmediate(e):setTimeout(e,0))}};Object.defineProperty(exports,"$",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"G",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"J",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"K",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"Q",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"X",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"Y",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"Z",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"at",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"et",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(exports,"it",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return se}}),Object.defineProperty(exports,"nt",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return re}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,"q",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return ae}}),Object.defineProperty(exports,"rt",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return ce}}),Object.defineProperty(exports,"tt",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return T}});
package/dist/worker.js CHANGED
@@ -6,19 +6,19 @@
6
6
  * This source code is licensed under the MIT license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
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=o(`tlc2.tool.EvalException`),l=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`;var u=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},d=class extends u{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},f=class extends d{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},p=class extends f{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const m=(e,t=!1,n,r=[])=>new d(e.map(e=>`${e.location}\n\n${e.message}`).join(`
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=new Map([...[...Array.from({length:24},(e,t)=>2222+t),2272,2273,2274,2280,2281,...Array.from({length:7},(e,t)=>5001+t)].map(t=>[t,e.configParseError]),[2253,e.livenessEvaluationFailure],[2109,e.specEvaluationFailure],[2115,e.specEvaluationFailure],[2103,e.specEvaluationFailure],[2147,e.specEvaluationFailure],[2111,e.safetyEvaluationFailure],[2146,e.safetyEvaluationFailure],[2107,e.safetyViolation],[2110,e.safetyViolation],[2112,e.livenessViolation],[2113,e.livenessViolation],[2116,e.livenessViolation],[2108,e.livenessViolation],[2114,e.deadlock],[2104,e.assumptionViolation],[2105,e.assumptionViolation],[2404,e.assumptionViolation],[2405,e.assumptionViolation],[2780,e.assumptionViolation],[2132,e.assertViolation],[2171,e.specParseError],[3002,e.specParseError]]),n=n=>t.get(n)??e.error,r=/* @__PURE__ */ new WeakMap,i=(e,t)=>(e instanceof Error&&!r.has(e)&&r.set(e,t),e),a=e=>r.get(e),o=t=>{try{return t()}catch(t){throw i(t,e.error)}},s=e=>{let t=o(e);return t&&{branches:t.branches,addInitialState:(e,n,r)=>o(()=>t.addInitialState(e,n,r)),addState:(e,n,r,i)=>o(()=>t.addState(e,n,r,i)),findViolation:()=>o(()=>t.findViolation()),getViolatedProperties:(e,n)=>o(()=>t.getViolatedProperties(e,n))}},c=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: `,l=c(`java.lang.RuntimeException`),ee=c(`tlc2.tool.EvalException`),u=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`||e instanceof SyntaxError&&e.message.endsWith(`: Stack overflow`);var d=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},f=class extends d{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},p=class extends f{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},m=class extends p{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const h=(e,t=!1,n,r=[])=>new f(e.map(e=>`${e.location}\n\n${e.message}`).join(`
10
10
 
11
- `),void 0,void 0,{errors:e,warnings:r,isFatal:t,parseError:n}),h=(e,t)=>m([{location:`In module ${t}`,message:`Cannot find source file for module ${e} imported in module ${t}.`}],!0),g=e=>`*** Warnings: ${e.length}\n\n${e.map(e=>`${e.location}\n\n${e.message}\n\n\n`).join(`
12
- `)}`,_=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,v=(e,t)=>m([{location:_(t),message:e}]);var y=class extends u{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},b=class extends u{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const x=`This was a Java StackOverflowError. It was probably the result
11
+ `),void 0,void 0,{errors:e,warnings:r,isFatal:t,parseError:n}),g=(e,t)=>h([{location:`In module ${t}`,message:`Cannot find source file for module ${e} imported in module ${t}.`}],!0),_=e=>`*** Warnings: ${e.length}\n\n${e.map(e=>`${e.location}\n\n${e.message}\n\n\n`).join(`
12
+ `)}`,v=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,y=(e,t)=>h([{location:v(t),message:e}]);var b=class extends d{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},x=class extends d{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const S=`This was a Java StackOverflowError. It was probably the result
13
13
  of an incorrect recursive function definition that caused TLC to enter
14
14
  an infinite loop when trying to compute the function or its application
15
- to an element in its putative domain.`;var S=class extends b{constructor(){super(x)}};const C=()=>n(new S,e.error);var w=class extends b{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},T=class extends b{variable;constructor(e,t){super(e),this.variable=t}},E=class extends b{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},D=class extends b{state;constructor(e){super(`current state is not a legal state`),this.name=`TlaEvaluationError`,this.state=e}},O=class extends u{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)})`}},k=class extends O{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},A=class extends u{constructor(e,t){super(e,t),this.name=`TlaProverError`}},j=class extends u{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},M=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},N=class extends u{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},P=class extends u{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},F=class extends u{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},I=class extends u{constructor(e){super(e),this.name=`SmtInvariantError`}},L=class extends u{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},R=class extends u{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},z=class extends u{constructor(e,t){super(e,t),this.name=`SmtParseError`}},B=class extends N{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const V=t=>r(t)??(t instanceof d?e.specParseError:t instanceof y?e.configParseError:t instanceof b?e.specEvaluationFailure:e.error);var H=class extends u{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},U=class extends u{constructor(e){super(e),this.name=`PcalRuntimeError`}},W=class extends u{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 G=`node:worker_threads`,K=()=>typeof Worker==`function`||typeof process<`u`&&process.versions?.node!==void 0,q=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(
15
+ to an element in its putative domain.`;var C=class extends x{constructor(){super(S)}};const w=()=>i(new C,e.error);var T=class extends x{},E=class extends x{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},D=class extends x{variable;constructor(e,t){super(e),this.variable=t}},O=class extends x{exitCode;constructor(t,n=e.error){super(t),this.exitCode=n}},k=class extends x{constructor(t){super(t),i(this,e.error)}},A=class extends T{constructor(){super(`PickSuccessor reached the end of standard input without an answer whether to extend the behavior.`)}},j=class extends x{constructor(t){super(`The directory ${t} holds no checkpoint to recover from.`),i(this,e.error)}},M=class extends x{},N=class extends x{};const P=`Too many possible next states for the last state in the trace.`;var F=class extends x{constructor(){super(P)}},I=class extends x{code;constructor(e,t){super(t),this.code=e}},L=class extends x{},R=class extends x{state;constructor(e){super(`current state is not a legal state`),this.state=e}},z=class extends d{failure;exception;locus;constructor(e,t={}){super(e),this.locus=t.locus,this.name=`TlaProofError`,this.failure=t.exception===void 0?t.failure??e:void 0,this.exception=t.exception??`Failure(${JSON.stringify(this.failure)})`}},B=class extends z{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e})}},V=class extends d{constructor(e,t){super(e,t),this.name=`TlaProverError`}},te=class extends d{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},H=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},U=class extends d{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},W=class extends d{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},G=class extends d{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},K=class extends d{constructor(e){super(e),this.name=`SmtInvariantError`}},q=class extends d{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},J=class extends d{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},Y=class extends d{constructor(e,t){super(e,t),this.name=`SmtParseError`}},X=class extends U{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const Z=t=>a(t)??(t instanceof f?e.specParseError:t instanceof b?e.configParseError:t instanceof x?e.specEvaluationFailure:e.error);var Q=class extends d{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},ne=class extends d{constructor(e){super(e),this.name=`PcalRuntimeError`}},re=class extends d{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`}},ie=class extends d{constructor(e,t){let n=t?.getSourceFile(),r=n?.getLineAndCharacterOfPosition(t?.getStart()??0);super(n===void 0||r===void 0?e:`${n.fileName}:${r.line+1}:${r.character+1} ${e}`),this.name=`TlaTypeScriptError`}};const $=`node:worker_threads`,ae=()=>typeof Worker==`function`||typeof process<`u`&&process.versions?.node!==void 0,oe=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
16
  /* @vite-ignore */
17
17
  /* webpackIgnore: true */
18
- G))).Worker(e);return r.on(`message`,t),r.on(`error`,n),{postMessage:(e,t)=>r.postMessage(e,t),terminate:()=>void r.terminate()}},J=async()=>typeof globalThis.postMessage==`function`?globalThis:(await import(
18
+ $))).Worker(e);return r.on(`message`,t),r.on(`error`,n),{postMessage:(e,t)=>r.postMessage(e,t),terminate:()=>void r.terminate()}},se=async()=>typeof globalThis.postMessage==`function`?globalThis:(await import(
19
19
  /* @vite-ignore */
20
20
  /* webpackIgnore: true */
21
- G)).parentPort,Y=()=>{let e=`Bun`in globalThis?import(
21
+ $)).parentPort,ce=()=>{let e=`Bun`in globalThis?import(
22
22
  /* @vite-ignore */
23
23
  /* webpackIgnore: true */
24
- `bun:jsc`):void 0;return async()=>{(await e)?.edenGC(),await new Promise(e=>typeof setImmediate==`function`?setImmediate(e):setTimeout(e,0))}};export{N as A,g as B,E as C,S as D,f as E,h as F,r as G,o as H,m as I,n as K,v as L,k as M,c as N,d as O,s as P,C as R,p as S,A as T,l as U,V,e as W,b as _,L as a,M as b,U as c,F as d,I as f,u as g,y as h,q as i,j,T as k,R as l,P as m,J as n,W as o,z as p,a as q,K as r,H as s,Y as t,x as u,D as v,O as w,B as x,w as y,_ as z};
24
+ `bun:jsc`):void 0;return async()=>{(await e)?.edenGC(),await new Promise(e=>typeof setImmediate==`function`?setImmediate(e):setTimeout(e,0))}};export{c as $,z as A,U as B,E as C,m as D,j as E,f as F,l as G,te as H,F as I,y as J,g as K,ie as L,p as M,N,O,C as P,Z as Q,D as R,R as S,X as T,B as U,I as V,ee as W,v as X,w as Y,_ as Z,b as _,q as a,s as at,x as b,ne as c,G as d,u as et,K as f,M as g,P as h,oe as i,i as it,V as j,L as k,J as l,W as m,se as n,a as nt,re as o,Y as p,h as q,ae as r,n as rt,Q as s,ce as t,e as tt,S as u,A as v,H as w,k as x,d as y,T as z};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tla-ts",
3
- "version": "0.0.9",
3
+ "version": "0.0.10-dev.b4a856304",
4
4
  "description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
5
5
  "keywords": [
6
6
  "formal verification",
@@ -55,9 +55,11 @@
55
55
  "access": "public"
56
56
  },
57
57
  "dependencies": {
58
+ "@typescript/typescript6": "6.0.2",
58
59
  "fflate": "^0.8.3"
59
60
  },
60
61
  "devDependencies": {
62
+ "@engine262/engine262": "0.0.1-d553e7b52501fbc47eae981c8d0fa7a5c26d0171",
61
63
  "@types/node": "^22",
62
64
  "publint": "^0.3.0",
63
65
  "typescript": "^7.0.2",
package/src/ast.ts CHANGED
@@ -33,8 +33,6 @@ export interface StringExpression {
33
33
  location: SourceLocation;
34
34
  }
35
35
 
36
- // selectorRanges holds the range of each part of a name such as foo!lab, where SANY reports an
37
- // error in selecting that part. spelling holds the text of an operator written as a synonym.
38
36
  export interface IdentifierExpression {
39
37
  kind: "Identifier";
40
38
  name: string;
@@ -51,14 +49,9 @@ export interface ApplyExpression {
51
49
  operator: string;
52
50
  spelling?: string;
53
51
  args: Expression[];
54
- // The number of args each part of a name like F(x)!l(y) takes, when a part before the last takes
55
- // some.
56
52
  argumentCounts?: number[];
57
- // The range of the parenthesized arguments of a named operator, or of the whole name when its
58
- // last part takes none, where SANY reports their count.
59
53
  argumentsRange?: SourceRange;
60
54
  selectorRanges?: SourceRange[];
61
- // The range of the arguments of each part of a name like F(x)!l(y), for a part that takes some.
62
55
  argumentRanges?: (SourceRange | undefined)[];
63
56
  location: SourceLocation;
64
57
  resolution?: LocalResolution;
@@ -71,8 +64,6 @@ export interface OperatorReferenceExpression {
71
64
  location: SourceLocation;
72
65
  }
73
66
 
74
- // operator holds the operator, such as SUBSET, that an argument names, which tla-ts reads as a
75
- // LAMBDA.
76
67
  export interface LambdaExpression {
77
68
  kind: "Lambda";
78
69
  params: string[];
@@ -86,8 +77,8 @@ export interface JunctionExpression {
86
77
  kind: "And" | "Or";
87
78
  operands: Expression[];
88
79
  isBulleted?: boolean;
89
- // SANY parses an infix chain such as A /\ B /\ C as (A /\ B) /\ C, whose node of each prefix of
90
- // two or more operands ends after the parentheses of its last operand.
80
+ // SANY parses A /\ B /\ C as (A /\ B) /\ C, whose node of each prefix of two or more operands ends
81
+ // after the parentheses of its last operand.
91
82
  prefixEnds?: SourceLocation[];
92
83
  location: SourceLocation;
93
84
  }
@@ -127,6 +118,7 @@ export interface CaseExpression {
127
118
  kind: "Case";
128
119
  arms: CaseArm[];
129
120
  other: Expression | undefined;
121
+ otherRange?: SourceRange;
130
122
  location: SourceLocation;
131
123
  }
132
124
 
@@ -138,7 +130,6 @@ export interface LetExpression {
138
130
  location: SourceLocation;
139
131
  }
140
132
 
141
- // ranges holds the range of each name the pattern binds.
142
133
  export type BoundPattern =
143
134
  | { kind: "Name"; name: string; ranges?: SourceRange[] }
144
135
  | { kind: "Tuple"; names: string[]; ranges?: SourceRange[] };
@@ -254,8 +245,7 @@ export interface FunctionApplicationExpression {
254
245
  location: SourceLocation;
255
246
  }
256
247
 
257
- // SANY parses [e1, ..., en] as a function application without the function, and its semantic
258
- // checker rejects it.
248
+ // SANY parses [e1, ..., en] as a function application without the function, and rejects it.
259
249
  export interface BracketExpression {
260
250
  kind: "Bracket";
261
251
  args: Expression[];
@@ -301,6 +291,7 @@ export interface LabelExpression {
301
291
  name: string;
302
292
  params: string[];
303
293
  paramRanges?: SourceRange[];
294
+ head?: SourceRange;
304
295
  body: Expression;
305
296
  location: SourceLocation;
306
297
  }
@@ -369,6 +360,7 @@ export interface OperatorDefinition {
369
360
  params: OperatorParam[];
370
361
  body: Expression;
371
362
  bodyRange?: SourceRange;
363
+ head?: SourceRange;
372
364
  isLocal: boolean;
373
365
  isRecursive: boolean;
374
366
  location: SourceLocation;
@@ -381,7 +373,6 @@ export interface FunctionDefinition {
381
373
  body: Expression;
382
374
  isLocal: boolean;
383
375
  isRecursive: boolean;
384
- // Whether the body applies the function, which SANY makes a recursive function definition.
385
376
  isSelfReferential?: boolean;
386
377
  location: SourceLocation;
387
378
  }
@@ -438,7 +429,6 @@ export interface AssumeProve {
438
429
 
439
430
  export type Fact = Expression | { kind: "ModuleFact"; name: string; location: SourceLocation };
440
431
 
441
- // keyword is the range of the USE or HIDE token and any ONLY after it.
442
432
  export interface UseOrHide {
443
433
  kind: "Use" | "Hide";
444
434
  isOnly: boolean;
@@ -448,7 +438,6 @@ export interface UseOrHide {
448
438
  location: SourceLocation;
449
439
  }
450
440
 
451
- // keyword is the range of the BY, OBVIOUS, or OMITTED token.
452
441
  export type Proof =
453
442
  | { kind: "Obvious" | "Omitted"; keyword: SourceRange; location: SourceLocation }
454
443
  | {
@@ -490,8 +479,6 @@ export type StepBody =
490
479
  | { kind: "Assert"; isSuffices: boolean; statement: Expression | AssumeProve }
491
480
  | { kind: "Qed" };
492
481
 
493
- // head is the range of the step number and its statement, without the proof, and statement is the
494
- // range of the statement alone.
495
482
  export interface ProofStep {
496
483
  name: string | undefined;
497
484
  token: string;
@@ -509,10 +496,9 @@ export interface Theorem {
509
496
  location: SourceLocation;
510
497
  }
511
498
 
512
- // The units of a module in source order, for consumers that need the order across kinds.
513
499
  export type ModuleUnit =
514
500
  | { kind: "Constants" | "Variables"; declarations: Declaration[]; location: SourceLocation }
515
- | { kind: "Recursive"; declarations: Declaration[] }
501
+ | { kind: "Recursive"; declarations: Declaration[]; location: SourceLocation }
516
502
  | { kind: "Definition"; definition: Definition }
517
503
  | { kind: "Instance"; instance: Instance }
518
504
  | { kind: "Assumption"; assumption: Assumption }
package/src/bags.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
- createJavaOverrideError,
3
2
  createModuleArgumentError,
4
3
  createOverflowError,
5
4
  defineConstant,
6
5
  defineHigherOrderOperator,
7
6
  defineOperator,
8
7
  getJavaClassName,
8
+ getKindString,
9
9
  getOperator,
10
10
  getValue,
11
11
  isOutOfRange,
@@ -13,17 +13,18 @@ import {
13
13
  import { TlaEvaluationError, TlaModuleError } from "./errors";
14
14
  import type { Builtin, BuiltinArgument } from "./evaluate";
15
15
  import {
16
+ createEnumeratedSet,
16
17
  createFunction,
17
18
  createSet,
18
19
  createSortedFunction,
19
20
  formatValue,
20
21
  getDomain,
21
22
  isEnumerable,
23
+ isEqualLikeTlc,
22
24
  isFunctionValue,
23
25
  isSetValue,
24
26
  toFiniteFunction,
25
27
  toFiniteSet,
26
- valuesEqual,
27
28
  type FunctionValue,
28
29
  type Value,
29
30
  } from "./values";
@@ -35,18 +36,39 @@ const createWrongValueError = (name: string, expected: string, value: Value) =>
35
36
 
36
37
  const toFunction = (value: Value) => (isFunctionValue(value) ? toFiniteFunction(value) : undefined);
37
38
 
39
+ const FINITE_FUNCTION = "a function with a finite domain";
40
+
38
41
  const getFunction = (args: BuiltinArgument[], index: number, name: string) => {
39
42
  const value = getValue(args, index, name);
40
43
  const functionValue = toFunction(value);
41
- if (!functionValue) throw createWrongValueError(name, "a function with a finite domain", value);
44
+ if (!functionValue) throw createWrongValueError(name, FINITE_FUNCTION, value);
42
45
  return functionValue;
43
46
  };
44
47
 
45
- const getBagArgument = (args: BuiltinArgument[], index: number, name: string) => {
46
- const value = getValue(args, index, name);
47
- const functionValue = toFunction(value);
48
- if (!functionValue)
49
- throw createModuleArgumentError(index === 0 ? "first" : "second", name, "bag", value);
48
+ const getCount = (args: BuiltinArgument[], name: string) => {
49
+ const bag = getValue(args, 1, name);
50
+ const functionValue = toFunction(bag);
51
+ const count = functionValue && findCount(functionValue, getValue(args, 0, name));
52
+ if (!functionValue || (count !== undefined && typeof count !== "number")) {
53
+ throw createModuleArgumentError("second", name, "bag", bag);
54
+ }
55
+ return count;
56
+ };
57
+
58
+ const getAddedBag = (
59
+ args: BuiltinArgument[],
60
+ functions: (FunctionValue | undefined)[],
61
+ index: number,
62
+ ) => {
63
+ const functionValue = functions[index];
64
+ if (!functionValue || !isBag(functionValue)) {
65
+ throw createModuleArgumentError(
66
+ index === 0 ? "first" : "second",
67
+ "(+)",
68
+ "bag",
69
+ getValue(args, index, "(+)"),
70
+ );
71
+ }
50
72
  return functionValue;
51
73
  };
52
74
 
@@ -59,63 +81,45 @@ const isBag = (functionValue: FunctionValue) =>
59
81
  functionValue.range.every((count) => typeof count === "number" && count > 0);
60
82
 
61
83
  const findCount = (functionValue: FunctionValue, element: Value) => {
62
- const position = functionValue.domain.findIndex((key) => valuesEqual(key, element));
84
+ const position = functionValue.domain.findIndex((key) => isEqualLikeTlc(element, key));
63
85
  return position === -1 ? undefined : functionValue.range[position];
64
86
  };
65
87
 
66
- const getBagsSignature = (name: string, result: string, arity: number) =>
67
- `public static ${result} tlc2.module.Bags.${name}(${Array.from({ length: arity }, () => "tlc2.value.impl.Value").join(",")})`;
68
-
69
- const BAG_DIFF_SIGNATURE = getBagsSignature("BagDiff", "tlc2.value.impl.Value", 2);
70
- const SQ_SUBSETEQ_SIGNATURE = getBagsSignature("SqSubseteq", "tlc2.value.IBoolValue", 2);
71
- const BAG_UNION_SIGNATURE = getBagsSignature("BagUnion", "tlc2.value.impl.Value", 1);
72
- const BAG_OF_ALL_SIGNATURE = getBagsSignature("BagOfAll", "tlc2.value.impl.Value", 2);
73
- const BAG_CUP_SIGNATURE = getBagsSignature("BagCup", "tlc2.value.impl.Value", 2);
74
- const BAG_CARDINALITY_SIGNATURE = getBagsSignature("BagCardinality", "tlc2.value.impl.IntValue", 1);
75
-
76
- // Bags.java casts each count to IntValue, so a count that isn't an integer fails with Java's
88
+ // Bags.java casts each count to IntValue, so a count that isn't an integer fails with a
77
89
  // ClassCastException.
78
- const toCount = (value: Value, method: string) => {
90
+ const toCount = (value: Value) => {
79
91
  if (typeof value === "number") return value;
80
92
  const javaClass = `tlc2.value.impl.${getJavaClassName(value)}`;
81
- throw createJavaOverrideError(
82
- method,
93
+ throw new TlaEvaluationError(
83
94
  `class ${javaClass} cannot be cast to class tlc2.value.impl.IntValue (${javaClass} and tlc2.value.impl.IntValue are in unnamed module of loader 'app')`,
84
95
  );
85
96
  };
86
97
 
87
- const addCounts = (left: Value, right: Value, method: string) => {
88
- const sum = toCount(left, method) + toCount(right, method);
98
+ const addCounts = (left: Value, right: Value) => {
99
+ const sum = toCount(left) + toCount(right);
89
100
  if (isOutOfRange(sum)) throw createOverflowError(`${left}+${right}`);
90
101
  return sum;
91
102
  };
92
103
 
93
- // TLC subtracts counts as Java ints, which wrap on overflow.
94
- const subtractCounts = (
95
- functionValue: FunctionValue,
96
- index: number,
97
- other: FunctionValue,
98
- method: string,
99
- ) => {
104
+ // Bags.java subtracts counts as Java ints, which wrap, where the - of the TLA+ definition overflows.
105
+ const subtractCounts = (functionValue: FunctionValue, index: number, other: FunctionValue) => {
106
+ const count = toCount(functionValue.range[index]);
100
107
  const removed = findCount(other, functionValue.domain[index]);
101
- const count = toCount(functionValue.range[index], method);
102
- return removed === undefined ? count : (count - toCount(removed, method)) | 0;
108
+ if (removed === undefined) return count;
109
+ const difference = count - toCount(removed);
110
+ if (isOutOfRange(difference)) throw createOverflowError(`${count}-${removed}`);
111
+ return difference;
103
112
  };
104
113
 
105
- const mergeBags = (bags: FunctionValue[], method: string) =>
106
- createFunction(
107
- bags.reduce<[Value, Value][]>((pairs, bag) => {
108
- bag.domain.forEach((key, index) => {
109
- const existing = pairs.find((pair) => valuesEqual(pair[0], key));
110
- if (existing) {
111
- existing[1] = addCounts(existing[1], bag.range[index], method);
112
- return;
113
- }
114
- pairs.push([key, bag.range[index]]);
115
- });
116
- return pairs;
117
- }, []),
118
- );
114
+ // BagCup looks up a key of its second bag only among the keys of its first.
115
+ const addToBag = (pairs: [Value, Value][], key: Value, count: Value, end = pairs.length) => {
116
+ const existing = pairs.slice(0, end).find((pair) => isEqualLikeTlc(key, pair[0]));
117
+ if (existing) existing[1] = addCounts(existing[1], count);
118
+ else pairs.push([key, count]);
119
+ };
120
+
121
+ const getPairs = (functionValue: FunctionValue) =>
122
+ functionValue.domain.map((key, index): [Value, Value] => [key, functionValue.range[index]]);
119
123
 
120
124
  const EMPTY_BAG = createSortedFunction([], []);
121
125
 
@@ -133,45 +137,34 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
133
137
  if (typeof count !== "number" || count <= 0) {
134
138
  throw createWrongValueError("BagCardinality", "a bag", bag);
135
139
  }
136
- return addCounts(total, count, BAG_CARDINALITY_SIGNATURE);
140
+ return addCounts(total, count);
137
141
  }, 0);
138
142
  }),
139
143
  defineOperator("BagIn", 2, (args) => {
140
- const bag = getValue(args, 1, "BagIn");
141
- const count = findCount(getFunction(args, 1, "BagIn"), getValue(args, 0, "BagIn"));
142
- if (count === undefined) return false;
143
- if (typeof count !== "number") throw createModuleArgumentError("second", "BagIn", "bag", bag);
144
- return count > 0;
145
- }),
146
- defineOperator("CopiesIn", 2, (args) => {
147
- const bag = getValue(args, 1, "CopiesIn");
148
- const count = findCount(getFunction(args, 1, "CopiesIn"), getValue(args, 0, "CopiesIn"));
149
- if (count === undefined) return 0;
150
- if (typeof count !== "number")
151
- throw createModuleArgumentError("second", "CopiesIn", "bag", bag);
152
- return count;
144
+ const count = getCount(args, "BagIn");
145
+ return count !== undefined && count > 0;
153
146
  }),
147
+ defineOperator("CopiesIn", 2, (args) => getCount(args, "CopiesIn") ?? 0),
154
148
  defineOperator("\\oplus", 2, (args) => {
155
- const bags = [0, 1].map((index) => {
156
- const functionValue = getBagArgument(args, index, "(+)");
157
- if (!isBag(functionValue)) {
158
- throw createModuleArgumentError(
159
- index === 0 ? "first" : "second",
160
- "(+)",
161
- "bag",
162
- getValue(args, index, "(+)"),
163
- );
164
- }
165
- return functionValue;
166
- });
167
- return mergeBags(bags, BAG_CUP_SIGNATURE);
149
+ const functions = [0, 1].map((index) => toFunction(getValue(args, index, "(+)")));
150
+ const left = getAddedBag(args, functions, 0);
151
+ const right = getAddedBag(args, functions, 1);
152
+ const pairs = getPairs(left);
153
+ right.domain.forEach((key, index) =>
154
+ addToBag(pairs, key, right.range[index], left.domain.length),
155
+ );
156
+ return createFunction(pairs);
168
157
  }),
169
158
  defineOperator("\\ominus", 2, (args) => {
170
- const left = getBagArgument(args, 0, "(-)");
171
- const right = getBagArgument(args, 1, "(-)");
159
+ const leftValue = getValue(args, 0, "(-)");
160
+ const rightValue = getValue(args, 1, "(-)");
161
+ const left = toFunction(leftValue);
162
+ const right = toFunction(rightValue);
163
+ if (!left) throw createModuleArgumentError("first", "(-)", "bag", leftValue);
164
+ if (!right) throw createModuleArgumentError("second", "(-)", "bag", rightValue);
172
165
  return createFunction(
173
166
  left.domain.flatMap((key, index): [Value, Value][] => {
174
- const count = subtractCounts(left, index, right, BAG_DIFF_SIGNATURE);
167
+ const count = subtractCounts(left, index, right);
175
168
  return count > 0 ? [[key, count]] : [];
176
169
  }),
177
170
  );
@@ -182,7 +175,7 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
182
175
  createWrongValueError("BagUnion", "a finite enumerable set", set),
183
176
  );
184
177
  if (elements.length < 2) return elements[0] ?? EMPTY_BAG;
185
- const bags = elements.map((element) => {
178
+ const getBag = (element: Value) => {
186
179
  const functionValue = toFunction(element);
187
180
  if (!functionValue) {
188
181
  throw new TlaModuleError(
@@ -190,43 +183,50 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
190
183
  );
191
184
  }
192
185
  return functionValue;
186
+ };
187
+ const pairs = getPairs(getBag(elements[0]));
188
+ elements.slice(1).forEach((element) => {
189
+ const functionValue = getBag(element);
190
+ functionValue.domain.forEach((key, index) =>
191
+ addToBag(pairs, key, functionValue.range[index]),
192
+ );
193
193
  });
194
- return mergeBags(bags, BAG_UNION_SIGNATURE);
194
+ return createFunction(pairs);
195
195
  }),
196
196
  defineOperator("\\sqsubseteq", 2, (args) => {
197
- const left = getFunction(args, 0, "\\sqsubseteq");
198
- const right = getFunction(args, 1, "\\sqsubseteq");
199
- return left.domain.every(
200
- (_, index) => subtractCounts(left, index, right, SQ_SUBSETEQ_SIGNATURE) <= 0,
201
- );
197
+ const leftValue = getValue(args, 0, "\\sqsubseteq");
198
+ const rightValue = getValue(args, 1, "\\sqsubseteq");
199
+ const left = toFunction(leftValue);
200
+ const right = toFunction(rightValue);
201
+ if (!left) throw createWrongValueError("\\sqsubseteq", FINITE_FUNCTION, leftValue);
202
+ if (!right) throw createWrongValueError("\\sqsubseteq", FINITE_FUNCTION, rightValue);
203
+ return left.domain.every((key, index) => {
204
+ const count = findCount(right, key);
205
+ return toCount(left.range[index]) <= (count === undefined ? 0 : toCount(count));
206
+ });
202
207
  }),
203
208
  defineHigherOrderOperator("BagOfAll", 2, (args) => {
204
209
  const operator = getOperator(args, 0, "BagOfAll");
205
- // TLC passes an operator whose body is a number or string literal to Bags.java as that literal.
206
- if (operator.literalBody !== undefined) {
207
- throw new TlaModuleError(
208
- `The first argument of BagOfAll should be an operator, but instead it is:\n${formatValue(operator.literalBody)}`,
209
- );
210
- }
211
210
  const value = getValue(args, 1, "BagOfAll");
212
211
  const functionValue = toFunction(value);
213
212
  if (!functionValue) {
214
213
  throw createModuleArgumentError("second", "BagOfAll", "function with a finite domain", value);
215
214
  }
216
- return mergeBags(
217
- functionValue.domain.map((key, index) =>
218
- createSortedFunction([operator.call([key])], [functionValue.range[index]]),
219
- ),
220
- BAG_OF_ALL_SIGNATURE,
215
+ const pairs: [Value, Value][] = [];
216
+ functionValue.domain.forEach((key, index) =>
217
+ addToBag(pairs, operator.call([key]), functionValue.range[index]),
221
218
  );
219
+ return createFunction(pairs);
222
220
  }),
223
221
  defineOperator("SubBag", 1, (args) => {
224
222
  const value = getValue(args, 0, "SubBag");
225
223
  if (!isFunctionValue(value)) {
226
- throw new TlaEvaluationError(`DOMAIN expects a function but received ${formatValue(value)}`);
224
+ throw new TlaEvaluationError(
225
+ `Attempted to apply the operator DOMAIN to a non-function\n(${getKindString(value)})\nline 106, col 58 to line 106, col 65 of module Bags`,
226
+ );
227
227
  }
228
228
  const functionValue = toFiniteFunction(value);
229
- const range = createSet(functionValue.range).elements;
229
+ const range = toFiniteSet(createEnumeratedSet(functionValue.range)).elements;
230
230
  const invalid = range.find((count) => typeof count !== "number");
231
231
  // A count that isn't an integer fails the comparison.
232
232
  if (invalid !== undefined) builtins.get(">=")?.evaluateBinary?.(range[0], invalid);
@@ -261,7 +261,7 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
261
261
  defineOperator("SetToBag", 1, (args) => {
262
262
  const set = getValue(args, 0, "SetToBag");
263
263
  const elements = getFiniteElements(set, () =>
264
- createWrongValueError("BagToSet", "a function with a finite domain", set),
264
+ createWrongValueError("BagToSet", FINITE_FUNCTION, set),
265
265
  );
266
266
  return createSortedFunction(
267
267
  [...elements],