tla-ts 0.0.9 → 0.0.10-dev.28c823e4b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (390) hide show
  1. package/README.md +29 -1
  2. package/dist/compile.cjs +23 -0
  3. package/dist/compile.js +23 -0
  4. package/dist/deciders.cjs +28 -28
  5. package/dist/deciders.js +43 -43
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +106 -10
  8. package/dist/index.d.ts +106 -10
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +116 -36
  15. package/dist/prove.js +116 -36
  16. package/dist/run.cjs +143 -31
  17. package/dist/run.js +143 -31
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +129 -104
  21. package/dist/transfer.js +129 -104
  22. package/dist/worker.cjs +7 -7
  23. package/dist/worker.js +7 -7
  24. package/package.json +3 -1
  25. package/src/ast.ts +4 -23
  26. package/src/bags.ts +99 -102
  27. package/src/builtins.ts +40 -78
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +599 -388
  30. package/src/cli/options.ts +11 -6
  31. package/src/cli/run.ts +0 -2
  32. package/src/cli/runtime-invariants.ts +136 -0
  33. package/src/cli/shared.ts +18 -11
  34. package/src/cli/tlapm.ts +0 -12
  35. package/src/cli/tlc-arguments.ts +640 -0
  36. package/src/cli/tlc-usage.ts +361 -0
  37. package/src/cli/tlc.ts +538 -220
  38. package/src/cli/typescript.ts +23 -0
  39. package/src/cli/xml-exporter.ts +4 -16
  40. package/src/cli.ts +0 -1
  41. package/src/codegen.ts +191 -64
  42. package/src/config.ts +140 -109
  43. package/src/coverage.ts +837 -0
  44. package/src/dependencies.ts +6 -40
  45. package/src/dfid.ts +618 -0
  46. package/src/environment.ts +240 -118
  47. package/src/errors.ts +70 -55
  48. package/src/evaluate.ts +596 -339
  49. package/src/exit-codes.ts +37 -3
  50. package/src/fingerprints.ts +10 -10
  51. package/src/index.ts +3 -0
  52. package/src/instances.ts +79 -11
  53. package/src/java-overrides.ts +4 -19
  54. package/src/json-reader.ts +455 -0
  55. package/src/json.ts +255 -139
  56. package/src/levels.ts +8 -17
  57. package/src/lexer.ts +80 -100
  58. package/src/liveness-checker.ts +82 -119
  59. package/src/liveness.ts +112 -64
  60. package/src/obligations/action.ts +4 -28
  61. package/src/obligations/anonymize.ts +84 -80
  62. package/src/obligations/equality.ts +1 -1
  63. package/src/obligations/expression.ts +2 -19
  64. package/src/obligations/format.ts +1 -9
  65. package/src/obligations/generate.ts +1 -11
  66. package/src/obligations/index.ts +0 -11
  67. package/src/obligations/levels.ts +4 -8
  68. package/src/obligations/module.ts +1 -15
  69. package/src/obligations/normalize.ts +5 -24
  70. package/src/obligations/operators.ts +1 -2
  71. package/src/obligations/pragma.ts +1 -10
  72. package/src/obligations/printer.ts +47 -46
  73. package/src/obligations/proof.ts +1 -5
  74. package/src/obligations/regroup.ts +1 -4
  75. package/src/obligations/simplify.ts +3 -14
  76. package/src/obligations/source.ts +1 -21
  77. package/src/obligations/subexpression.ts +5 -11
  78. package/src/obligations/substitution.ts +1 -3
  79. package/src/obligations/temporal.ts +8 -14
  80. package/src/obligations/tuples.ts +3 -9
  81. package/src/parallel-worker.ts +29 -39
  82. package/src/parallel.ts +53 -44
  83. package/src/parser.ts +565 -282
  84. package/src/pcal/ast.ts +53 -86
  85. package/src/pcal/parse.ts +144 -219
  86. package/src/pcal/tokenize.ts +91 -131
  87. package/src/pcal/translate.ts +83 -130
  88. package/src/pcal/validate.ts +48 -68
  89. package/src/pretty-print.ts +7 -8
  90. package/src/prover/decide-pool.ts +5 -10
  91. package/src/prover/deciders.ts +0 -4
  92. package/src/prover/first-order.ts +0 -11
  93. package/src/prover/isabelle/decide.ts +0 -6
  94. package/src/prover/isabelle/encode.ts +11 -23
  95. package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
  96. package/src/prover/isabelle/isar/method.ts +25 -38
  97. package/src/prover/isabelle/isar/proof.ts +1 -10
  98. package/src/prover/isabelle/isar/statement.ts +1 -6
  99. package/src/prover/isabelle/isar/theory.ts +15 -26
  100. package/src/prover/isabelle/isar/type-check.ts +11 -25
  101. package/src/prover/isabelle/provers/blast/blast.ts +10 -41
  102. package/src/prover/isabelle/provers/blast/branch.ts +1 -32
  103. package/src/prover/isabelle/provers/blast/prove.ts +1 -35
  104. package/src/prover/isabelle/provers/blast/rules.ts +6 -44
  105. package/src/prover/isabelle/provers/blast/state.ts +2 -28
  106. package/src/prover/isabelle/provers/blast/term.ts +9 -36
  107. package/src/prover/isabelle/provers/clasimp.ts +1 -13
  108. package/src/prover/isabelle/provers/classical.ts +14 -42
  109. package/src/prover/isabelle/provers/hypsubst.ts +11 -25
  110. package/src/prover/isabelle/pure/bicompose.ts +16 -13
  111. package/src/prover/isabelle/pure/consts.ts +1 -7
  112. package/src/prover/isabelle/pure/conv.ts +1 -9
  113. package/src/prover/isabelle/pure/drule.ts +24 -40
  114. package/src/prover/isabelle/pure/envir.ts +3 -52
  115. package/src/prover/isabelle/pure/goal.ts +1 -7
  116. package/src/prover/isabelle/pure/interrupt.ts +0 -5
  117. package/src/prover/isabelle/pure/list.ts +0 -3
  118. package/src/prover/isabelle/pure/logic.ts +1 -14
  119. package/src/prover/isabelle/pure/name.ts +2 -9
  120. package/src/prover/isabelle/pure/net.ts +3 -59
  121. package/src/prover/isabelle/pure/object-logic.ts +3 -10
  122. package/src/prover/isabelle/pure/pattern.ts +2 -19
  123. package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
  124. package/src/prover/isabelle/pure/rewriter.ts +26 -58
  125. package/src/prover/isabelle/pure/search.ts +3 -10
  126. package/src/prover/isabelle/pure/seq.ts +1 -10
  127. package/src/prover/isabelle/pure/simplifier.ts +4 -12
  128. package/src/prover/isabelle/pure/table.ts +1 -31
  129. package/src/prover/isabelle/pure/tactic.ts +12 -22
  130. package/src/prover/isabelle/pure/tactical.ts +6 -12
  131. package/src/prover/isabelle/pure/term-ord.ts +2 -6
  132. package/src/prover/isabelle/pure/term.ts +2 -43
  133. package/src/prover/isabelle/pure/thm.ts +13 -36
  134. package/src/prover/isabelle/pure/type.ts +2 -15
  135. package/src/prover/isabelle/pure/unify.ts +20 -30
  136. package/src/prover/isabelle/pure/variable.ts +3 -7
  137. package/src/prover/isabelle/tla/classical-setup.ts +9 -19
  138. package/src/prover/isabelle/tla/context.ts +8 -16
  139. package/src/prover/isabelle/tla/logic.ts +4 -11
  140. package/src/prover/isabelle/tla/simpdata.ts +46 -34
  141. package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
  142. package/src/prover/ocaml.ts +0 -6
  143. package/src/prover/prep/action.ts +4 -36
  144. package/src/prover/prep/enabled-axioms.ts +12 -19
  145. package/src/prover/prep/fingerprint.ts +0 -16
  146. package/src/prover/prep/level-comparison.ts +8 -12
  147. package/src/prover/prep/md5.ts +0 -2
  148. package/src/prover/prep/methods.ts +9 -36
  149. package/src/prover/prep/normalize.ts +4 -28
  150. package/src/prover/prove-worker.ts +0 -2
  151. package/src/prover/prove.ts +0 -36
  152. package/src/prover/ptl/decide.ts +7 -12
  153. package/src/prover/ptl/encode.ts +14 -36
  154. package/src/prover/ptl/sat.ts +24 -32
  155. package/src/prover/ptl/tableau.ts +12 -26
  156. package/src/prover/smt/axioms.ts +0 -7
  157. package/src/prover/smt/context.ts +19 -26
  158. package/src/prover/smt/data.ts +51 -54
  159. package/src/prover/smt/encode.ts +14 -35
  160. package/src/prover/smt/extensionality.ts +0 -10
  161. package/src/prover/smt/flatten.ts +3 -22
  162. package/src/prover/smt/format.ts +5 -10
  163. package/src/prover/smt/instances.ts +0 -10
  164. package/src/prover/smt/rewrite.ts +66 -101
  165. package/src/prover/smt/solver/act-cache.ts +0 -15
  166. package/src/prover/smt/solver/arith-rewriter.ts +3 -48
  167. package/src/prover/smt/solver/array.ts +1 -3
  168. package/src/prover/smt/solver/asserted-formulas.ts +1 -43
  169. package/src/prover/smt/solver/ast-lt.ts +1 -11
  170. package/src/prover/smt/solver/ast-util.ts +1 -6
  171. package/src/prover/smt/solver/ast.ts +1 -143
  172. package/src/prover/smt/solver/auf-solver.ts +6 -39
  173. package/src/prover/smt/solver/case-split-queue.ts +1 -9
  174. package/src/prover/smt/solver/cg-table.ts +1 -18
  175. package/src/prover/smt/solver/clause.ts +1 -27
  176. package/src/prover/smt/solver/conflict-resolution.ts +0 -9
  177. package/src/prover/smt/solver/context.ts +4 -61
  178. package/src/prover/smt/solver/ctx-simplify.ts +14 -41
  179. package/src/prover/smt/solver/der.ts +2 -21
  180. package/src/prover/smt/solver/dyn-ack.ts +1 -11
  181. package/src/prover/smt/solver/e-matching.ts +3 -34
  182. package/src/prover/smt/solver/enode.ts +1 -21
  183. package/src/prover/smt/solver/expr-ref.ts +1 -5
  184. package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
  185. package/src/prover/smt/solver/fingerprints.ts +1 -12
  186. package/src/prover/smt/solver/flat-literals.ts +1 -9
  187. package/src/prover/smt/solver/goal.ts +2 -14
  188. package/src/prover/smt/solver/hash.ts +0 -8
  189. package/src/prover/smt/solver/hashtable.ts +1 -12
  190. package/src/prover/smt/solver/internalizer.ts +6 -98
  191. package/src/prover/smt/solver/lbool.ts +1 -2
  192. package/src/prover/smt/solver/literal.ts +0 -3
  193. package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
  194. package/src/prover/smt/solver/lp/constraints.ts +2 -8
  195. package/src/prover/smt/solver/lp/containers.ts +12 -30
  196. package/src/prover/smt/solver/lp/core-solver.ts +10 -31
  197. package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
  198. package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
  199. package/src/prover/smt/solver/lp/dependency.ts +1 -4
  200. package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
  201. package/src/prover/smt/solver/lp/explanation.ts +1 -6
  202. package/src/prover/smt/solver/lp/gomory.ts +9 -22
  203. package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
  204. package/src/prover/smt/solver/lp/hnf.ts +11 -26
  205. package/src/prover/smt/solver/lp/int-cube.ts +15 -36
  206. package/src/prover/smt/solver/lp/int-solver.ts +4 -34
  207. package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
  208. package/src/prover/smt/solver/lp/lar-term.ts +1 -5
  209. package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
  210. package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
  211. package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
  212. package/src/prover/smt/solver/lp/nex.ts +1 -6
  213. package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
  214. package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
  215. package/src/prover/smt/solver/lp/nla-core.ts +35 -130
  216. package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
  217. package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
  218. package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
  219. package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
  220. package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
  221. package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
  222. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
  223. package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
  224. package/src/prover/smt/solver/lp/nla-order.ts +2 -13
  225. package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
  226. package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
  227. package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
  228. package/src/prover/smt/solver/lp/nla-types.ts +1 -11
  229. package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
  230. package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
  231. package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
  232. package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
  233. package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
  234. package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
  235. package/src/prover/smt/solver/lp/pdd.ts +7 -70
  236. package/src/prover/smt/solver/lp/random-updater.ts +1 -8
  237. package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
  238. package/src/prover/smt/solver/lp/union-find.ts +1 -6
  239. package/src/prover/smt/solver/mam-compiler.ts +14 -56
  240. package/src/prover/smt/solver/mam-interpreter.ts +1 -21
  241. package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
  242. package/src/prover/smt/solver/model-checker.ts +2 -36
  243. package/src/prover/smt/solver/model-evaluator.ts +3 -29
  244. package/src/prover/smt/solver/model-finder.ts +3 -15
  245. package/src/prover/smt/solver/model-generator.ts +1 -12
  246. package/src/prover/smt/solver/model-macro-solver.ts +12 -69
  247. package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
  248. package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
  249. package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
  250. package/src/prover/smt/solver/nlsat/explain.ts +3 -47
  251. package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
  252. package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
  253. package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
  254. package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
  255. package/src/prover/smt/solver/nlsat/solver.ts +7 -67
  256. package/src/prover/smt/solver/nlsat/types.ts +1 -8
  257. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
  258. package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
  259. package/src/prover/smt/solver/nnf.ts +3 -38
  260. package/src/prover/smt/solver/pattern-inference.ts +2 -15
  261. package/src/prover/smt/solver/poly-rewriter.ts +3 -23
  262. package/src/prover/smt/solver/propagate-values.ts +1 -10
  263. package/src/prover/smt/solver/proto-model.ts +3 -48
  264. package/src/prover/smt/solver/pull-quant.ts +1 -12
  265. package/src/prover/smt/solver/qe-lite-der.ts +1 -29
  266. package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
  267. package/src/prover/smt/solver/qe-lite.ts +3 -33
  268. package/src/prover/smt/solver/qi-queue.ts +1 -16
  269. package/src/prover/smt/solver/quant-tactics.ts +5 -22
  270. package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
  271. package/src/prover/smt/solver/quantifier-manager.ts +1 -8
  272. package/src/prover/smt/solver/random-gen.ts +1 -2
  273. package/src/prover/smt/solver/rational.ts +1 -8
  274. package/src/prover/smt/solver/ref-vector.ts +1 -6
  275. package/src/prover/smt/solver/relevancy.ts +2 -15
  276. package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
  277. package/src/prover/smt/solver/rewriter.ts +3 -85
  278. package/src/prover/smt/solver/rlimit.ts +2 -20
  279. package/src/prover/smt/solver/smtlib-parser.ts +2 -37
  280. package/src/prover/smt/solver/solver.ts +23 -34
  281. package/src/prover/smt/solver/sort.ts +1 -5
  282. package/src/prover/smt/solver/sticky-generations.ts +0 -5
  283. package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
  284. package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
  285. package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
  286. package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
  287. package/src/prover/smt/solver/theory-lra-model.ts +4 -19
  288. package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
  289. package/src/prover/smt/solver/theory-lra-state.ts +3 -8
  290. package/src/prover/smt/solver/theory-lra.ts +1 -8
  291. package/src/prover/smt/solver/var-subst.ts +2 -26
  292. package/src/prover/smt/table.ts +0 -8
  293. package/src/prover/tlapm/cache.ts +20 -25
  294. package/src/prover/tlapm/ocaml-marshal.ts +19 -21
  295. package/src/prover/tlapm/tlapm.ts +12 -17
  296. package/src/prover/verdict.ts +0 -2
  297. package/src/prover/zenon/check/check.ts +0 -9
  298. package/src/prover/zenon/check/definitions.ts +5 -15
  299. package/src/prover/zenon/check/equality.ts +0 -8
  300. package/src/prover/zenon/check/functions.ts +0 -4
  301. package/src/prover/zenon/check/keys.ts +0 -7
  302. package/src/prover/zenon/check/propositional.ts +0 -3
  303. package/src/prover/zenon/check/records.ts +0 -5
  304. package/src/prover/zenon/check/relations.ts +0 -13
  305. package/src/prover/zenon/check/rewrites.ts +0 -6
  306. package/src/prover/zenon/check/sets.ts +0 -3
  307. package/src/prover/zenon/check/terms.ts +0 -17
  308. package/src/prover/zenon/check/tla.ts +0 -6
  309. package/src/prover/zenon/decide.ts +0 -12
  310. package/src/prover/zenon/encode.ts +1 -8
  311. package/src/prover/zenon/eqrel.ts +0 -13
  312. package/src/prover/zenon/equality-rules.ts +0 -4
  313. package/src/prover/zenon/expr.ts +1 -26
  314. package/src/prover/zenon/index-table.ts +17 -38
  315. package/src/prover/zenon/isar-case.ts +9 -19
  316. package/src/prover/zenon/isar.ts +1 -29
  317. package/src/prover/zenon/limits.ts +0 -4
  318. package/src/prover/zenon/llproof.ts +0 -9
  319. package/src/prover/zenon/mltoll.ts +54 -76
  320. package/src/prover/zenon/node.ts +1 -11
  321. package/src/prover/zenon/ocaml.ts +1 -17
  322. package/src/prover/zenon/parse.ts +2 -7
  323. package/src/prover/zenon/phrase.ts +1 -11
  324. package/src/prover/zenon/proof.ts +0 -9
  325. package/src/prover/zenon/propositional-rules.ts +0 -5
  326. package/src/prover/zenon/rules.ts +2 -6
  327. package/src/prover/zenon/search.ts +1 -17
  328. package/src/prover/zenon/tla/functions.ts +57 -29
  329. package/src/prover/zenon/tla/llproof.ts +63 -70
  330. package/src/prover/zenon/tla/records.ts +56 -27
  331. package/src/prover/zenon/tla/rewrites.ts +12 -19
  332. package/src/prover/zenon/tla/sets.ts +68 -39
  333. package/src/prover/zenon/tla/terms.ts +0 -6
  334. package/src/prover/zenon/tla/tla.ts +59 -58
  335. package/src/randomization.ts +81 -35
  336. package/src/resolve.ts +12 -112
  337. package/src/runtime.ts +22 -22
  338. package/src/sany/builtins.ts +2 -5
  339. package/src/sany/generator.ts +149 -252
  340. package/src/sany/levels.ts +6 -34
  341. package/src/sany/lexer.ts +41 -61
  342. package/src/sany/linter.ts +1 -9
  343. package/src/sany/modules.ts +1 -5
  344. package/src/sany/nodes.ts +0 -31
  345. package/src/sany/parse-error.ts +39 -117
  346. package/src/sany/report.ts +29 -63
  347. package/src/sany/selectors.ts +15 -39
  348. package/src/sany/source.ts +1 -17
  349. package/src/sany/xml.ts +13 -63
  350. package/src/search.ts +495 -155
  351. package/src/simulate.ts +685 -0
  352. package/src/spec-description.ts +176 -69
  353. package/src/standard-definitions.ts +0 -4
  354. package/src/standard-modules.ts +254 -69
  355. package/src/state-graph.ts +50 -24
  356. package/src/subexpressions.ts +69 -52
  357. package/src/substitution-levels.ts +2 -3
  358. package/src/successors.ts +263 -94
  359. package/src/symmetry.ts +33 -25
  360. package/src/tableau.ts +27 -24
  361. package/src/tlc/fingerprint.ts +183 -67
  362. package/src/tlc/jar-data.ts +112 -6
  363. package/src/tlc/messages.ts +110 -44
  364. package/src/tlc/order.ts +37 -60
  365. package/src/tlc/random.ts +33 -45
  366. package/src/tlc/replay.ts +549 -217
  367. package/src/tlc/summary.ts +36 -47
  368. package/src/tlc/tlc-operators.ts +76 -41
  369. package/src/tlc/tlcext-operators.ts +139 -122
  370. package/src/tlc/trace-spec.ts +269 -0
  371. package/src/tlc/value-stream.ts +139 -0
  372. package/src/tlc/version.ts +1 -4
  373. package/src/transfer.ts +22 -25
  374. package/src/typescript/actions.ts +481 -0
  375. package/src/typescript/collections.ts +600 -0
  376. package/src/typescript/compile.ts +65 -0
  377. package/src/typescript/context.ts +94 -0
  378. package/src/typescript/emit.ts +121 -0
  379. package/src/typescript/expressions.ts +496 -0
  380. package/src/typescript/formula.ts +152 -0
  381. package/src/typescript/functions.ts +284 -0
  382. package/src/typescript/model.ts +163 -0
  383. package/src/typescript/names.ts +114 -0
  384. package/src/typescript/program.ts +48 -0
  385. package/src/typescript/properties.ts +139 -0
  386. package/src/typescript/scope.ts +112 -0
  387. package/src/typescript/steps.ts +165 -0
  388. package/src/typescript/types.ts +171 -0
  389. package/src/values.ts +780 -337
  390. package/src/worker.ts +7 -8
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.28c823e4b",
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;
@@ -44,21 +42,14 @@ export interface IdentifierExpression {
44
42
  resolution?: LocalResolution;
45
43
  }
46
44
 
47
- // spelling holds the text of an operator written as a synonym, such as (+) for \oplus, which SANY
48
- // reports as written.
49
45
  export interface ApplyExpression {
50
46
  kind: "Apply";
51
47
  operator: string;
52
48
  spelling?: string;
53
49
  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
50
  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
51
  argumentsRange?: SourceRange;
60
52
  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
53
  argumentRanges?: (SourceRange | undefined)[];
63
54
  location: SourceLocation;
64
55
  resolution?: LocalResolution;
@@ -71,8 +62,6 @@ export interface OperatorReferenceExpression {
71
62
  location: SourceLocation;
72
63
  }
73
64
 
74
- // operator holds the operator, such as SUBSET, that an argument names, which tla-ts reads as a
75
- // LAMBDA.
76
65
  export interface LambdaExpression {
77
66
  kind: "Lambda";
78
67
  params: string[];
@@ -86,8 +75,6 @@ export interface JunctionExpression {
86
75
  kind: "And" | "Or";
87
76
  operands: Expression[];
88
77
  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.
91
78
  prefixEnds?: SourceLocation[];
92
79
  location: SourceLocation;
93
80
  }
@@ -127,6 +114,7 @@ export interface CaseExpression {
127
114
  kind: "Case";
128
115
  arms: CaseArm[];
129
116
  other: Expression | undefined;
117
+ otherRange?: SourceRange;
130
118
  location: SourceLocation;
131
119
  }
132
120
 
@@ -138,7 +126,6 @@ export interface LetExpression {
138
126
  location: SourceLocation;
139
127
  }
140
128
 
141
- // ranges holds the range of each name the pattern binds.
142
129
  export type BoundPattern =
143
130
  | { kind: "Name"; name: string; ranges?: SourceRange[] }
144
131
  | { kind: "Tuple"; names: string[]; ranges?: SourceRange[] };
@@ -254,8 +241,6 @@ export interface FunctionApplicationExpression {
254
241
  location: SourceLocation;
255
242
  }
256
243
 
257
- // SANY parses [e1, ..., en] as a function application without the function, and its semantic
258
- // checker rejects it.
259
244
  export interface BracketExpression {
260
245
  kind: "Bracket";
261
246
  args: Expression[];
@@ -301,6 +286,7 @@ export interface LabelExpression {
301
286
  name: string;
302
287
  params: string[];
303
288
  paramRanges?: SourceRange[];
289
+ head?: SourceRange;
304
290
  body: Expression;
305
291
  location: SourceLocation;
306
292
  }
@@ -369,6 +355,7 @@ export interface OperatorDefinition {
369
355
  params: OperatorParam[];
370
356
  body: Expression;
371
357
  bodyRange?: SourceRange;
358
+ head?: SourceRange;
372
359
  isLocal: boolean;
373
360
  isRecursive: boolean;
374
361
  location: SourceLocation;
@@ -381,7 +368,6 @@ export interface FunctionDefinition {
381
368
  body: Expression;
382
369
  isLocal: boolean;
383
370
  isRecursive: boolean;
384
- // Whether the body applies the function, which SANY makes a recursive function definition.
385
371
  isSelfReferential?: boolean;
386
372
  location: SourceLocation;
387
373
  }
@@ -438,7 +424,6 @@ export interface AssumeProve {
438
424
 
439
425
  export type Fact = Expression | { kind: "ModuleFact"; name: string; location: SourceLocation };
440
426
 
441
- // keyword is the range of the USE or HIDE token and any ONLY after it.
442
427
  export interface UseOrHide {
443
428
  kind: "Use" | "Hide";
444
429
  isOnly: boolean;
@@ -448,7 +433,6 @@ export interface UseOrHide {
448
433
  location: SourceLocation;
449
434
  }
450
435
 
451
- // keyword is the range of the BY, OBVIOUS, or OMITTED token.
452
436
  export type Proof =
453
437
  | { kind: "Obvious" | "Omitted"; keyword: SourceRange; location: SourceLocation }
454
438
  | {
@@ -490,8 +474,6 @@ export type StepBody =
490
474
  | { kind: "Assert"; isSuffices: boolean; statement: Expression | AssumeProve }
491
475
  | { kind: "Qed" };
492
476
 
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
477
  export interface ProofStep {
496
478
  name: string | undefined;
497
479
  token: string;
@@ -509,10 +491,9 @@ export interface Theorem {
509
491
  location: SourceLocation;
510
492
  }
511
493
 
512
- // The units of a module in source order, for consumers that need the order across kinds.
513
494
  export type ModuleUnit =
514
495
  | { kind: "Constants" | "Variables"; declarations: Declaration[]; location: SourceLocation }
515
- | { kind: "Recursive"; declarations: Declaration[] }
496
+ | { kind: "Recursive"; declarations: Declaration[]; location: SourceLocation }
516
497
  | { kind: "Definition"; definition: Definition }
517
498
  | { kind: "Instance"; instance: Instance }
518
499
  | { 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,67 +81,46 @@ 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
77
- // ClassCastException.
78
- const toCount = (value: Value, method: string) => {
88
+ const toCount = (value: Value) => {
79
89
  if (typeof value === "number") return value;
80
90
  const javaClass = `tlc2.value.impl.${getJavaClassName(value)}`;
81
- throw createJavaOverrideError(
82
- method,
91
+ throw new TlaEvaluationError(
83
92
  `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
93
  );
85
94
  };
86
95
 
87
- const addCounts = (left: Value, right: Value, method: string) => {
88
- const sum = toCount(left, method) + toCount(right, method);
96
+ const addCounts = (left: Value, right: Value) => {
97
+ const sum = toCount(left) + toCount(right);
89
98
  if (isOutOfRange(sum)) throw createOverflowError(`${left}+${right}`);
90
99
  return sum;
91
100
  };
92
101
 
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
- ) => {
102
+ // Deviation from TLC: Bags.java subtracts counts as Java ints, which wrap; this overflows like -.
103
+ const subtractCounts = (functionValue: FunctionValue, index: number, other: FunctionValue) => {
104
+ const count = toCount(functionValue.range[index]);
100
105
  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;
106
+ if (removed === undefined) return count;
107
+ const difference = count - toCount(removed);
108
+ if (isOutOfRange(difference)) throw createOverflowError(`${count}-${removed}`);
109
+ return difference;
103
110
  };
104
111
 
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
- );
112
+ // BagCup looks up a key of its second bag only among the keys of its first.
113
+ const addToBag = (pairs: [Value, Value][], key: Value, count: Value, end = pairs.length) => {
114
+ const existing = pairs.slice(0, end).find((pair) => isEqualLikeTlc(key, pair[0]));
115
+ if (existing) existing[1] = addCounts(existing[1], count);
116
+ else pairs.push([key, count]);
117
+ };
118
+
119
+ const getPairs = (functionValue: FunctionValue) =>
120
+ functionValue.domain.map((key, index): [Value, Value] => [key, functionValue.range[index]]);
119
121
 
120
122
  const EMPTY_BAG = createSortedFunction([], []);
121
123
 
122
- // SubBag compares the counts with the >= of Naturals, which Integers replaces when TLC loads it.
123
124
  export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Builtin[] => [
124
125
  defineConstant("EmptyBag", EMPTY_BAG),
125
126
  defineOperator("IsABag", 1, (args) => {
@@ -133,45 +134,34 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
133
134
  if (typeof count !== "number" || count <= 0) {
134
135
  throw createWrongValueError("BagCardinality", "a bag", bag);
135
136
  }
136
- return addCounts(total, count, BAG_CARDINALITY_SIGNATURE);
137
+ return addCounts(total, count);
137
138
  }, 0);
138
139
  }),
139
140
  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;
141
+ const count = getCount(args, "BagIn");
142
+ return count !== undefined && count > 0;
153
143
  }),
144
+ defineOperator("CopiesIn", 2, (args) => getCount(args, "CopiesIn") ?? 0),
154
145
  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);
146
+ const functions = [0, 1].map((index) => toFunction(getValue(args, index, "(+)")));
147
+ const left = getAddedBag(args, functions, 0);
148
+ const right = getAddedBag(args, functions, 1);
149
+ const pairs = getPairs(left);
150
+ right.domain.forEach((key, index) =>
151
+ addToBag(pairs, key, right.range[index], left.domain.length),
152
+ );
153
+ return createFunction(pairs);
168
154
  }),
169
155
  defineOperator("\\ominus", 2, (args) => {
170
- const left = getBagArgument(args, 0, "(-)");
171
- const right = getBagArgument(args, 1, "(-)");
156
+ const leftValue = getValue(args, 0, "(-)");
157
+ const rightValue = getValue(args, 1, "(-)");
158
+ const left = toFunction(leftValue);
159
+ const right = toFunction(rightValue);
160
+ if (!left) throw createModuleArgumentError("first", "(-)", "bag", leftValue);
161
+ if (!right) throw createModuleArgumentError("second", "(-)", "bag", rightValue);
172
162
  return createFunction(
173
163
  left.domain.flatMap((key, index): [Value, Value][] => {
174
- const count = subtractCounts(left, index, right, BAG_DIFF_SIGNATURE);
164
+ const count = subtractCounts(left, index, right);
175
165
  return count > 0 ? [[key, count]] : [];
176
166
  }),
177
167
  );
@@ -182,7 +172,7 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
182
172
  createWrongValueError("BagUnion", "a finite enumerable set", set),
183
173
  );
184
174
  if (elements.length < 2) return elements[0] ?? EMPTY_BAG;
185
- const bags = elements.map((element) => {
175
+ const getBag = (element: Value) => {
186
176
  const functionValue = toFunction(element);
187
177
  if (!functionValue) {
188
178
  throw new TlaModuleError(
@@ -190,43 +180,50 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
190
180
  );
191
181
  }
192
182
  return functionValue;
183
+ };
184
+ const pairs = getPairs(getBag(elements[0]));
185
+ elements.slice(1).forEach((element) => {
186
+ const functionValue = getBag(element);
187
+ functionValue.domain.forEach((key, index) =>
188
+ addToBag(pairs, key, functionValue.range[index]),
189
+ );
193
190
  });
194
- return mergeBags(bags, BAG_UNION_SIGNATURE);
191
+ return createFunction(pairs);
195
192
  }),
196
193
  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
- );
194
+ const leftValue = getValue(args, 0, "\\sqsubseteq");
195
+ const rightValue = getValue(args, 1, "\\sqsubseteq");
196
+ const left = toFunction(leftValue);
197
+ const right = toFunction(rightValue);
198
+ if (!left) throw createWrongValueError("\\sqsubseteq", FINITE_FUNCTION, leftValue);
199
+ if (!right) throw createWrongValueError("\\sqsubseteq", FINITE_FUNCTION, rightValue);
200
+ return left.domain.every((key, index) => {
201
+ const count = findCount(right, key);
202
+ return toCount(left.range[index]) <= (count === undefined ? 0 : toCount(count));
203
+ });
202
204
  }),
203
205
  defineHigherOrderOperator("BagOfAll", 2, (args) => {
204
206
  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
207
  const value = getValue(args, 1, "BagOfAll");
212
208
  const functionValue = toFunction(value);
213
209
  if (!functionValue) {
214
210
  throw createModuleArgumentError("second", "BagOfAll", "function with a finite domain", value);
215
211
  }
216
- return mergeBags(
217
- functionValue.domain.map((key, index) =>
218
- createSortedFunction([operator.call([key])], [functionValue.range[index]]),
219
- ),
220
- BAG_OF_ALL_SIGNATURE,
212
+ const pairs: [Value, Value][] = [];
213
+ functionValue.domain.forEach((key, index) =>
214
+ addToBag(pairs, operator.call([key]), functionValue.range[index]),
221
215
  );
216
+ return createFunction(pairs);
222
217
  }),
223
218
  defineOperator("SubBag", 1, (args) => {
224
219
  const value = getValue(args, 0, "SubBag");
225
220
  if (!isFunctionValue(value)) {
226
- throw new TlaEvaluationError(`DOMAIN expects a function but received ${formatValue(value)}`);
221
+ throw new TlaEvaluationError(
222
+ `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`,
223
+ );
227
224
  }
228
225
  const functionValue = toFiniteFunction(value);
229
- const range = createSet(functionValue.range).elements;
226
+ const range = toFiniteSet(createEnumeratedSet(functionValue.range)).elements;
230
227
  const invalid = range.find((count) => typeof count !== "number");
231
228
  // A count that isn't an integer fails the comparison.
232
229
  if (invalid !== undefined) builtins.get(">=")?.evaluateBinary?.(range[0], invalid);
@@ -242,7 +239,7 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
242
239
  (subBags, key, index) =>
243
240
  subBags.flatMap((entries) => [
244
241
  entries,
245
- ...Array.from({ length: counts[index] }, (_, copies): [Value, Value][] => [
242
+ ...Array.from({ length: counts[index] }, (_value, copies): [Value, Value][] => [
246
243
  ...entries,
247
244
  [key, copies + 1],
248
245
  ]),
@@ -261,7 +258,7 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
261
258
  defineOperator("SetToBag", 1, (args) => {
262
259
  const set = getValue(args, 0, "SetToBag");
263
260
  const elements = getFiniteElements(set, () =>
264
- createWrongValueError("BagToSet", "a function with a finite domain", set),
261
+ createWrongValueError("BagToSet", FINITE_FUNCTION, set),
265
262
  );
266
263
  return createSortedFunction(
267
264
  [...elements],