tla-ts 0.0.9-dev.8298a52 → 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 +7 -0
  2. package/dist/compile.cjs +3 -3
  3. package/dist/compile.js +3 -3
  4. package/dist/deciders.cjs +28 -28
  5. package/dist/deciders.js +52 -52
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +105 -10
  8. package/dist/index.d.ts +105 -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 +1 -1
  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 +1 -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 +564 -366
  30. package/src/cli/options.ts +10 -5
  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 +525 -216
  38. package/src/cli/typescript.ts +0 -3
  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 +237 -119
  47. package/src/errors.ts +56 -56
  48. package/src/evaluate.ts +543 -341
  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 +38 -31
  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 +77 -117
  59. package/src/liveness.ts +106 -62
  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 +24 -33
  82. package/src/parallel.ts +48 -40
  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 +1 -16
  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 +260 -91
  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 +8 -21
  375. package/src/typescript/collections.ts +0 -15
  376. package/src/typescript/compile.ts +0 -5
  377. package/src/typescript/context.ts +0 -12
  378. package/src/typescript/emit.ts +0 -1
  379. package/src/typescript/expressions.ts +0 -12
  380. package/src/typescript/formula.ts +4 -12
  381. package/src/typescript/functions.ts +6 -17
  382. package/src/typescript/model.ts +10 -11
  383. package/src/typescript/names.ts +0 -2
  384. package/src/typescript/program.ts +0 -3
  385. package/src/typescript/properties.ts +6 -8
  386. package/src/typescript/scope.ts +0 -5
  387. package/src/typescript/steps.ts +0 -10
  388. package/src/typescript/types.ts +1 -8
  389. package/src/values.ts +749 -330
  390. package/src/worker.ts +7 -8
@@ -9,7 +9,7 @@ import {
9
9
  type OperatorParam,
10
10
  type SourceLocation,
11
11
  } from "./ast";
12
- import { BUNDLED_MODULES } from "./bundled-modules";
12
+ import type { ModuleOperator } from "./check";
13
13
  import type { ConfigValue, ModelConfig } from "./config";
14
14
  import type { FileSystem } from "./json";
15
15
  import {
@@ -19,17 +19,23 @@ import {
19
19
  formatSanyWarnings,
20
20
  TlaConfigError,
21
21
  TlaEvaluationError,
22
+ TlaFeatureUnsupportedError,
22
23
  TlaModuleError,
23
24
  TlaSyntaxError,
25
+ UNEXPECTED_EXCEPTION,
24
26
  type SanyError,
25
27
  } from "./errors";
26
28
  import { EXIT_STATUS, setExitCode } from "./exit-codes";
27
29
  import {
30
+ bindOperatorArguments,
28
31
  createBigNumberError,
29
32
  createRealNumberError,
30
33
  evaluate,
31
34
  getDefinition,
32
35
  type Builtin,
36
+ type BuiltinArgument,
37
+ type Closure,
38
+ type Context,
33
39
  type Environment,
34
40
  } from "./evaluate";
35
41
  import {
@@ -60,10 +66,10 @@ import {
60
66
  } from "./resolve";
61
67
  import { createRuntime } from "./runtime";
62
68
  import { getSanyStandardModules } from "./sany/modules";
63
- import { USER_STANDARD_MODULES } from "./tlc/jar-data";
64
69
  import { getSanyParseError } from "./sany/parse-error";
65
70
  import {
66
71
  CORE_OPERATORS,
72
+ getJavaOverrides,
67
73
  getStandardModule,
68
74
  getTraceSpecArithmetic,
69
75
  STANDARD_DEPENDENCIES,
@@ -78,9 +84,9 @@ import { createTlcOrder, type TlcOrder } from "./tlc/order";
78
84
  import {
79
85
  isTlcInteger,
80
86
  createModelValue,
81
- createSet,
82
87
  formatValue,
83
88
  valuesEqual,
89
+ toFiniteSet,
84
90
  type Value,
85
91
  markNormalized,
86
92
  } from "./values";
@@ -89,34 +95,32 @@ import type { TlcVersion } from "./tlc/version";
89
95
  interface EnvironmentOptions {
90
96
  source: string;
91
97
  loadModule: ((name: string) => string | undefined) | undefined;
92
- // The TLC orders of the same spec, when the caller already reads them.
93
98
  order?: TlcOrder;
94
99
  loadClass?: (name: string) => Uint8Array | undefined;
95
100
  print: (text: string) => void;
96
101
  files: FileSystem;
97
102
  seed?: bigint;
98
- // Links the modules without a model, as SANY does, so a declared constant needs no value.
99
- isUnconfigured?: boolean;
100
103
  isTool?: boolean;
101
- // TLC loads Integers for the binary trace of its trace exploration spec, and Integers' Java
102
- // methods then compute the arithmetic of Naturals.
103
- isTraceRecorded?: boolean;
104
+ traceFile?: string;
104
105
  isSanyReported?: boolean;
105
106
  isWarningEnabled?: boolean;
106
107
  version?: TlcVersion;
108
+ moduleOperators?: ModuleOperator[];
107
109
  }
108
110
 
109
- interface Specification {
111
+ export interface ResolvedModuleOperator extends ModuleOperator {
112
+ key: string | undefined;
113
+ }
114
+
115
+ export interface Specification {
110
116
  environment: Environment;
111
117
  assumptions: Assumption[];
112
118
  variableLocations: SourceLocation[];
113
119
  instanceActions: Map<string, InstanceAction>;
114
- // The definitions TLC computes when it starts, in the order it computes them.
115
120
  startupDefinitions: Definition[];
116
- rootConstants: Declaration[];
117
- rootSymbols: Symbols;
118
- // The methods of the modules' classes, in the order TLC loads the classes.
119
121
  javaOverrides: JavaOverride[];
122
+ moduleOperators: ResolvedModuleOperator[];
123
+ rootName: string;
120
124
  }
121
125
 
122
126
  export interface InstanceAction {
@@ -124,13 +128,15 @@ export interface InstanceAction {
124
128
  location: SourceLocation;
125
129
  }
126
130
 
131
+ const ANNOTATED_OVERRIDE_MODULES = new Set(["IOUtils", "Json", "TLCExt"]);
132
+
127
133
  const toValue = (value: ConfigValue): Value => {
128
134
  switch (value.kind) {
129
135
  case "Number":
130
- // TLC fails with an unexpected exception on a configuration number too big for it.
136
+ // Deviation from TLC: ModelConfig#parseValue lets Integer.parseInt fail on a number too big, where tla-ts reports it as TLC reports such a number in a module.
131
137
  if (!isTlcInteger(value.value)) {
132
138
  throw setExitCode(
133
- new TlaModuleError(`Integer overflow: ${value.value} is outside TLC's 32-bit range`),
139
+ new TlaModuleError(`TLC can't handle a number this big.\n${value.value}`),
134
140
  EXIT_STATUS.error,
135
141
  );
136
142
  }
@@ -141,7 +147,25 @@ const toValue = (value: ConfigValue): Value => {
141
147
  case "ModelValue":
142
148
  return createModelValue(value.name);
143
149
  case "Set":
144
- return createSet(value.elements.map(toValue));
150
+ return toFiniteSet({ kind: "MixedSet", elements: value.elements.map(toValue) });
151
+ }
152
+ };
153
+
154
+ const toConstantValue = (value: ConfigValue) => {
155
+ try {
156
+ return toValue(value);
157
+ } catch (error) {
158
+ if (
159
+ !(error instanceof TlaEvaluationError) ||
160
+ error instanceof TlaModuleError ||
161
+ error instanceof TlaFeatureUnsupportedError
162
+ ) {
163
+ throw error;
164
+ }
165
+ throw setExitCode(
166
+ new TlaEvaluationError(`${UNEXPECTED_EXCEPTION}${error.message}`),
167
+ EXIT_STATUS.error,
168
+ );
145
169
  }
146
170
  };
147
171
 
@@ -157,8 +181,6 @@ interface LinkedModule {
157
181
  facts: Set<string>;
158
182
  }
159
183
 
160
- // errors and warnings collect what SANY reports for the module, and levelChecks the level checks of
161
- // the modules in its file, which SANY runs only when it reports no error.
162
184
  interface ModuleScope {
163
185
  id: string;
164
186
  symbols: Symbols;
@@ -178,8 +200,6 @@ const getDeclarations = (linked: LinkedModule): Declaration[] => [
178
200
  })),
179
201
  ];
180
202
 
181
- // Parses the module SANY reads from the file name.tla. A module SANY's parser rejects fails as it
182
- // does in TLC: SANY's message, then a fatal error that names the module.
183
203
  const parseModuleFile = (source: string, name: string, order: TlcOrder) => {
184
204
  try {
185
205
  return order.parseModule(source);
@@ -212,12 +232,9 @@ const getModuleRedefinition = (module: Module, existing: Module): SanyError | un
212
232
  message: `Multiply-defined module '${module.name}': this definition or declaration conflicts \nwith the one at ${formatRange(existing.location.range)}.`,
213
233
  };
214
234
 
215
- // Context.kindOfNode names a definition or a parameter a definition, and any other symbol a
216
- // declaration.
217
235
  const getNodeWord = (kind: SymbolKind) =>
218
236
  ["Builtin", "Definition", "Instance", "Parameter"].includes(kind) ? "definition" : "declaration";
219
237
 
220
- // The Java class of the node SANY binds a symbol to.
221
238
  const getNodeClass = (kind: SymbolKind) =>
222
239
  kind === "Theorem" ? "ThmOrAssumpDefNode" : getNodeWord(kind);
223
240
 
@@ -306,9 +323,9 @@ export const createEnvironment = (
306
323
  const root = order.parseModule(options.source);
307
324
  const definitions = new Map<string, Definition>();
308
325
  const parameterized = new Map<string, boolean>();
309
- // The definition each instance copy came from, and the instance parameters the copy adds.
310
326
  const copySources = new Map<string, { source: string; prefix: number }>();
311
327
  const substitutedDefinitions = new Set<Definition>();
328
+ const instanceParams = new Set<OperatorParam>();
312
329
  const builtins = new Map<string, Builtin>(
313
330
  CORE_OPERATORS.map((operator) => [operator.name, operator]),
314
331
  );
@@ -318,13 +335,10 @@ export const createEnvironment = (
318
335
  runtime.isTool = options.isTool ?? false;
319
336
  runtime.version = options.version ?? "master";
320
337
  const linkedModules = new Map<string, LinkedModule>();
321
- const nestedModules = new Map<string, LinkedModule>();
322
- // Each module by name, from the time its level checks run.
323
338
  const checkedModules = new Map<string, LinkedModule>();
324
339
  const linkOrder: LinkedModule[] = [];
325
340
  const dependencies = new Map<string, Set<string>>();
326
341
  const loading: Set<string>[] = [];
327
- // The top-level modules being linked, to report a cycle of EXTENDS or INSTANCE.
328
342
  const linking: string[] = [];
329
343
 
330
344
  const useModule = (name: string, used: Iterable<string>) =>
@@ -332,8 +346,8 @@ export const createEnvironment = (
332
346
  closure.add(name);
333
347
  [...used].forEach((dependency) => closure.add(dependency));
334
348
  });
335
- const copyCount = { value: 0 };
336
- const createName = (name: string) => `${name}#${copyCount.value++}`;
349
+ let copyCount = 0;
350
+ const createName = (name: string) => `${name}#${copyCount++}`;
337
351
  const instanceChecks: InstanceCheck[] = [];
338
352
  const warnings: SanyError[] = [];
339
353
  const checkInstance = createInstanceChecker((name) => {
@@ -360,8 +374,6 @@ export const createEnvironment = (
360
374
  if (cached) return cached;
361
375
  const standardModule = getStandardModule(name, options.print, runtime, options.files, builtins);
362
376
  if (!standardModule) return undefined;
363
- // TLC loads the modules a standard module instantiates too, and the Java methods of each
364
- // replace the operators of every module, as those of Integers replace those of Naturals.
365
377
  STANDARD_DEPENDENCIES.get(name)?.forEach(addStandardModule);
366
378
  const exported: Symbols = new Map();
367
379
  standardModule.extends.forEach((extended) =>
@@ -384,19 +396,18 @@ export const createEnvironment = (
384
396
  };
385
397
 
386
398
  const getStandardSymbols = (name: string) => {
387
- // SANY reads a module from the user's directories before its standard modules.
388
- if (USER_STANDARD_MODULES.has(name) && options.loadModule?.(name) !== undefined)
399
+ const dependencies = STANDARD_DEPENDENCIES.get(name) ?? [];
400
+ if (
401
+ name === "TLCExt" ||
402
+ [name, ...dependencies].some((module) => options.loadModule?.(module) !== undefined)
403
+ )
389
404
  return undefined;
390
405
  const symbols = addStandardModule(name);
391
- const dependencies = STANDARD_DEPENDENCIES.get(name) ?? [];
392
406
  if (symbols) useModule(name, dependencies);
393
- // TLC loads the Java class of each module a standard module uses, so one that uses Integers
394
- // overrides the arithmetic of Naturals.
395
407
  if (symbols && dependencies.includes("Integers")) addStandardModule("Integers");
396
408
  return symbols;
397
409
  };
398
410
 
399
- // Like TLC, reject a decimal or a big integer anywhere in a module, even where nothing evaluates it.
400
411
  const rejectModuleLiterals = (module: Module): Module => {
401
412
  rejectLiterals([
402
413
  ...module.definitions.flatMap((definition) =>
@@ -418,7 +429,7 @@ export const createEnvironment = (
418
429
  const loadModule = (name: string, importer: string) => {
419
430
  const source =
420
431
  options.loadModule?.(name) ??
421
- BUNDLED_MODULES.get(name) ??
432
+ getSanyStandardModules(runtime.version).get(name) ??
422
433
  extractModule(options.source, name);
423
434
  if (source === undefined) throw createMissingModuleError(name, importer);
424
435
  const module = parseModuleFile(source, name, order);
@@ -478,14 +489,49 @@ export const createEnvironment = (
478
489
  return cached;
479
490
  }
480
491
  const top = linkTopLevel(loadModule(name, importer));
481
- // TLC replaces each definition of a module that has a standard module's name with the Java
482
- // method of that name, so a user's Bags.tla keeps the definitions that Bags has no method for.
483
- const standardModule = getSanyStandardModules(runtime.version).has(name)
484
- ? getStandardModule(name, options.print, runtime, options.files, builtins)
485
- : undefined;
486
- standardModule?.operators.forEach((operator) => {
492
+ const replaced = new Map<string, Definition>();
493
+ const evaluateReplaced = (
494
+ operator: string,
495
+ args: BuiltinArgument[],
496
+ context: Context | undefined,
497
+ ) => {
498
+ const definition = replaced.get(operator);
499
+ const expressions = args.flatMap((arg) =>
500
+ typeof arg === "object" && arg.kind === "Operator" && arg.expression
501
+ ? [arg.expression]
502
+ : [],
503
+ );
504
+ if (definition?.kind !== "Operator" || !context || expressions.length !== args.length) {
505
+ throw new TlaEvaluationError(`No definition of ${operator} to fall back to`);
506
+ }
507
+ const closure: Closure = {
508
+ kind: "Closure",
509
+ name: definition.name,
510
+ params: definition.params,
511
+ body: definition.body,
512
+ scope: undefined,
513
+ };
514
+ return evaluate(definition.body, {
515
+ environment: context.environment,
516
+ scope: bindOperatorArguments(closure, expressions, context),
517
+ state: context.state,
518
+ next: context.next,
519
+ isKeepLazy: context.isKeepLazy,
520
+ });
521
+ };
522
+ getJavaOverrides(
523
+ name,
524
+ options.print,
525
+ runtime,
526
+ options.files,
527
+ builtins,
528
+ evaluateReplaced,
529
+ )?.forEach((operator) => {
487
530
  const symbol = top.linked.visible.get(operator.name);
488
- if (symbol?.kind !== "Definition" || symbol.arity !== operator.arity) return;
531
+ if (symbol?.kind !== "Definition") return;
532
+ if (symbol.arity !== operator.arity && ANNOTATED_OVERRIDE_MODULES.has(name)) return;
533
+ const definition = definitions.get(symbol.key);
534
+ if (definition) replaced.set(operator.name, definition);
489
535
  builtins.set(symbol.key, operator);
490
536
  definitions.delete(symbol.key);
491
537
  });
@@ -509,7 +555,7 @@ export const createEnvironment = (
509
555
  unit.facts.add(instance.name === undefined ? name : `${instance.name}!${name}`),
510
556
  );
511
557
  const declarations = getDeclarations(linked);
512
- const suffix = `#${copyCount.value++}`;
558
+ const suffix = `#${copyCount++}`;
513
559
  const renamed = new Map(instance.params.map((param) => [param.name, `${param.name}${suffix}`]));
514
560
  const substitutions = resolveSubstitutions(
515
561
  resolveInstanceSubexpressions(instance, module),
@@ -524,8 +570,16 @@ export const createEnvironment = (
524
570
  substitutions,
525
571
  location: instance.location,
526
572
  });
573
+ const params = instance.params.map((param) => ({ ...param, name: `${param.name}${suffix}` }));
574
+ params.forEach((param) => instanceParams.add(param));
575
+ const substitutionRange = instance.definitionRange
576
+ ? {
577
+ ...instance.definitionRange,
578
+ start: { line: instance.location.line, column: instance.location.column },
579
+ }
580
+ : instance.instanceRange;
527
581
  const instantiation = createInstantiation({
528
- params: instance.params.map((param) => ({ ...param, name: `${param.name}${suffix}` })),
582
+ params,
529
583
  substitutions: new Map(
530
584
  [...substitutions].map(([name, expression]) => [name, renameLocals(expression, renamed)]),
531
585
  ),
@@ -547,6 +601,13 @@ export const createEnvironment = (
547
601
  return key;
548
602
  },
549
603
  createName,
604
+ ...(declarations.length > 0 && {
605
+ frame: {
606
+ kind: "Identifier",
607
+ name: instance.name ?? instance.module,
608
+ location: { ...substitutionRange.start, range: substitutionRange },
609
+ },
610
+ }),
550
611
  });
551
612
  return getInstanceSymbols(instance, linked.exported, declarations, (key, name) => {
552
613
  const copy =
@@ -569,9 +630,6 @@ export const createEnvironment = (
569
630
  ]),
570
631
  );
571
632
 
572
- // The names an INSTANCE adds for the definitions of the module it instantiates, each with the key
573
- // that getKey gives it. SANY binds a copy of a definition that depends on the parameters at the
574
- // INSTANCE.
575
633
  const getInstanceSymbols = (
576
634
  instance: Instance,
577
635
  exported: Symbols,
@@ -638,7 +696,7 @@ export const createEnvironment = (
638
696
  });
639
697
 
640
698
  const createArgumentParams = (arity: number) =>
641
- Array.from({ length: arity }, (_, index) => ({ name: `argument${index}`, arity: 0 }));
699
+ Array.from({ length: arity }, (_value, index) => ({ name: `argument${index}`, arity: 0 }));
642
700
 
643
701
  const getSubstitutionBody = (
644
702
  replacement: Expression,
@@ -687,7 +745,7 @@ export const createEnvironment = (
687
745
  });
688
746
  }
689
747
  const linked = nested ?? getLinkedModule(instance.module, instancer);
690
- const suffix = `#${copyCount.value++}`;
748
+ const suffix = `#${copyCount++}`;
691
749
  const explicitSubstitutions = new Map(
692
750
  instance.substitutions.map((item) => [item.name, item.expression]),
693
751
  );
@@ -744,7 +802,6 @@ export const createEnvironment = (
744
802
  ),
745
803
  variables: new Set(linked.variables),
746
804
  getDefinition: (key) => definitions.get(key),
747
- // Each substitution is a local definition, which the copies read by name.
748
805
  getOuterDefinition: () => undefined,
749
806
  isParameterized: (key) => parameterized.get(key) === true,
750
807
  addDefinition: (_source, name, create) => {
@@ -800,12 +857,9 @@ export const createEnvironment = (
800
857
  ]),
801
858
  ...scope.symbols,
802
859
  ]);
803
- // Where an INSTANCE first made each name it adds visible.
804
860
  const importedAt = new Map<string, SourceLocation>();
805
861
  const extendsReport: ModuleReport = { location: MODULE_START, errors: [], warnings: [] };
806
862
  const reports = [extendsReport];
807
- // Context.mergeExtendContext keeps the first of the symbols the extended modules share by name,
808
- // and warns of two definitions or two declarations but rejects a definition and a declaration.
809
863
  const mergeExtended = (symbols: Symbols) =>
810
864
  symbols.forEach((symbol, name) => {
811
865
  const current = exported.get(name);
@@ -840,8 +894,12 @@ export const createEnvironment = (
840
894
  const modules = new Map<string, LinkedModule>();
841
895
  const extended: LinkedModule[] = [];
842
896
  const constants = [...parsed.constants];
843
- const variables = parsed.variables.map((variable) => variable.name);
844
- const variableLocations = parsed.variables.map((variable) => variable.location);
897
+ const declaredVariables = parsed.variables.filter(
898
+ (variable, index) =>
899
+ parsed.variables.findIndex((other) => other.name === variable.name) === index,
900
+ );
901
+ const variables = declaredVariables.map((variable) => variable.name);
902
+ const variableLocations = declaredVariables.map((variable) => variable.location);
845
903
  parsed.extends.forEach((name) => {
846
904
  const nested = scope.modules.get(name);
847
905
  const standardSymbols = nested ? undefined : getStandardSymbols(name);
@@ -851,12 +909,16 @@ export const createEnvironment = (
851
909
  }
852
910
  const linked = nested ?? getLinkedModule(name, parsed.name);
853
911
  constants.push(
854
- ...linked.constants.filter((constant) =>
855
- constants.every((existing) => existing.name !== constant.name),
912
+ ...linked.constants.filter(
913
+ (constant) =>
914
+ constants.every((existing) => existing.name !== constant.name) &&
915
+ !variables.includes(constant.name),
856
916
  ),
857
917
  );
858
918
  linked.variables.forEach((variable, index) => {
859
- if (variables.includes(variable)) return;
919
+ const isDeclared =
920
+ variables.includes(variable) || constants.some((constant) => constant.name === variable);
921
+ if (isDeclared) return;
860
922
  variables.push(variable);
861
923
  variableLocations.push(linked.variableLocations[index]);
862
924
  });
@@ -891,14 +953,12 @@ export const createEnvironment = (
891
953
  parsed === root ? definition.name : `${definition.name}${KEY_SEPARATOR}${scope.id}`;
892
954
  const instanced = new Map<Instance, Symbols>();
893
955
  const getVisibleModules = () => new Map([...scope.modules, ...modules]);
894
- const isInstancedAfterDefinition = (nested: Module) => {
895
- const first = parsed.instances.find((instance) => instance.module === nested.name);
896
- return first !== undefined && isBefore(nested.location, first.location);
897
- };
898
956
  const getLetModule = (instance: Instance) => {
899
957
  const ownModule = parsed.modules.find((nested) => nested.name === instance.module);
900
958
  if (!ownModule) return getVisibleModules().get(instance.module);
901
- return isInstancedAfterDefinition(ownModule) ? modules.get(ownModule.name) : undefined;
959
+ return isBefore(ownModule.location, instance.location)
960
+ ? modules.get(ownModule.name)
961
+ : undefined;
902
962
  };
903
963
  const getUnit = (module: Module): ModuleUnit => ({
904
964
  imported: visible,
@@ -931,7 +991,6 @@ export const createEnvironment = (
931
991
  reports,
932
992
  warnings: scope.warnings,
933
993
  });
934
- // SANY keeps the first of two symbols of a name.
935
994
  const getSymbolsBefore = (location: SourceLocation): Symbols =>
936
995
  [
937
996
  ...declarations
@@ -950,8 +1009,6 @@ export const createEnvironment = (
950
1009
  (symbols, [name, symbol]) => (symbols.has(name) ? symbols : symbols.set(name, symbol)),
951
1010
  new Map(visible),
952
1011
  );
953
- // Generator.generateModule reports the errors of a nested module and goes on, and then
954
- // SymbolTable.addModule reports a module already defined.
955
1012
  const linkNested = (nested: Module) => {
956
1013
  const visibleModules = getVisibleModules();
957
1014
  const existing = visibleModules.get(nested.name);
@@ -971,7 +1028,6 @@ export const createEnvironment = (
971
1028
  });
972
1029
  if (redefinition) report.errors.push(redefinition);
973
1030
  if (!existing) modules.set(nested.name, linked);
974
- if (!nestedModules.has(nested.name)) nestedModules.set(nested.name, linked);
975
1031
  };
976
1032
  [
977
1033
  ...parsed.instances.map((instance) => ({
@@ -1013,7 +1069,6 @@ export const createEnvironment = (
1013
1069
  parameterized.set(key, !isParameterFree);
1014
1070
  const symbol = getDefinitionSymbol(definition);
1015
1071
  const importedLocation = importedAt.get(definition.name);
1016
- // SANY binds the name of a fact to a fact the module imports before it.
1017
1072
  if (
1018
1073
  symbol.kind === "Theorem" &&
1019
1074
  visible.get(definition.name)?.kind === "Theorem" &&
@@ -1039,8 +1094,6 @@ export const createEnvironment = (
1039
1094
  ]),
1040
1095
  };
1041
1096
  if (!checkedModules.has(parsed.name)) checkedModules.set(parsed.name, linked);
1042
- // SANY checks the instances of a module with its definitions and theorems, so it reports their
1043
- // errors together.
1044
1097
  const checks = instanceChecks
1045
1098
  .splice(firstCheck)
1046
1099
  .map((check) => ({ location: check.location, check: () => checkInstance(check) }));
@@ -1062,12 +1115,37 @@ export const createEnvironment = (
1062
1115
  };
1063
1116
 
1064
1117
  const linkedRoot = linkTopLevel(root).linked;
1118
+ const traceFile = options.traceFile;
1119
+ const traceOperators: ModuleOperator[] =
1120
+ traceFile === undefined
1121
+ ? []
1122
+ : [
1123
+ {
1124
+ kind: "postcondition",
1125
+ module: "_TLCTrace",
1126
+ operator: "_TLCTraceSilent",
1127
+ constants: { _TLCTraceFile: traceFile },
1128
+ },
1129
+ ];
1130
+ const moduleOperators = [...(options.moduleOperators ?? []), ...traceOperators].map(
1131
+ (operator): ResolvedModuleOperator => {
1132
+ const symbol = getLinkedModule(operator.module, root.name).visible.get(operator.operator);
1133
+ return { ...operator, key: symbol?.kind === "Definition" ? symbol.key : undefined };
1134
+ },
1135
+ );
1136
+ linkOrder.push(...linkOrder.splice(linkOrder.indexOf(linkedRoot), 1));
1065
1137
  if (warnings.length > 0 && !options.isSanyReported) options.print(formatSanyWarnings(warnings));
1066
1138
  const getRootKey = (name: string) => linkedRoot.visible.get(name)?.key ?? name;
1067
1139
  linkedRoot.visible.forEach((symbol, name) => {
1068
1140
  const definition = definitions.get(symbol.key);
1069
1141
  if (definition && symbol.key !== name) definitions.set(name, definition);
1070
1142
  });
1143
+ moduleOperators.forEach((operator) => {
1144
+ const definition = operator.key === undefined ? undefined : definitions.get(operator.key);
1145
+ if (operator.kind !== "postcondition" && definition) {
1146
+ definitions.set(operator.operator, definition);
1147
+ }
1148
+ });
1071
1149
 
1072
1150
  const assumptions: Assumption[] = [];
1073
1151
  const addAssumptions = (linked: LinkedModule, visited: Set<LinkedModule>) => {
@@ -1080,17 +1158,29 @@ export const createEnvironment = (
1080
1158
  const declaredConstants = linkedRoot.constants.map((constant) => constant.name);
1081
1159
  const variables = linkedRoot.variables;
1082
1160
 
1083
- const getScopedKeys = (item: { name: string; module?: string }) => {
1161
+ const moduleSymbols = new Map([
1162
+ ...standardExports,
1163
+ ...[...linkedModules].map(([name, linked]): [string, Symbols] => [name, linked.visible]),
1164
+ [root.name, linkedRoot.visible],
1165
+ ]);
1166
+ const getScopedSymbol = (item: { name: string; module?: string }) => {
1167
+ const symbol = moduleSymbols.get(item.module ?? "")?.get(item.name);
1168
+ return symbol?.kind === "Definition" ? symbol : undefined;
1169
+ };
1170
+ const getSubstitutedKeys = (item: { name: string; module?: string }) => {
1084
1171
  if (item.module === undefined) return [item.name, getRootKey(item.name)];
1085
- if (item.module === root.name || declaredConstants.includes(item.name)) return [];
1086
- const linked = linkedModules.get(item.module) ?? nestedModules.get(item.module);
1087
- return [linked?.visible.get(item.name)?.key ?? item.name];
1172
+ const symbol = getScopedSymbol(item);
1173
+ return symbol ? [symbol.key] : [];
1088
1174
  };
1175
+ const getScopedKeys = (item: { name: string; module?: string }) =>
1176
+ item.module === root.name ? [] : getSubstitutedKeys(item);
1089
1177
  const getKeyArity = (key: string) => {
1090
1178
  const definition = definitions.get(key);
1091
1179
  return definition?.kind === "Operator"
1092
1180
  ? definition.params.length
1093
- : (linkedRoot.constants.find((constant) => constant.name === key)?.arity ?? 0);
1181
+ : (linkedRoot.constants.find((constant) => constant.name === key)?.arity ??
1182
+ builtins.get(key)?.arity ??
1183
+ 0);
1094
1184
  };
1095
1185
  const constants = new Map<string, Value>();
1096
1186
  const operatorKeys = new Set<string>();
@@ -1103,7 +1193,7 @@ export const createEnvironment = (
1103
1193
  config.constants
1104
1194
  .filter((assignment) => assignment.args === undefined)
1105
1195
  .forEach((assignment) => {
1106
- const value = toValue(assignment.value);
1196
+ const value = toConstantValue(assignment.value);
1107
1197
  markNormalized(value);
1108
1198
  getScopedKeys(assignment).forEach((key) => {
1109
1199
  const arity = getKeyArity(key);
@@ -1139,20 +1229,38 @@ export const createEnvironment = (
1139
1229
  });
1140
1230
  tables.forEach((table) =>
1141
1231
  getScopedKeys(table).forEach((key) =>
1142
- setOperator(
1143
- key,
1144
- createOperatorTable(table.name, getKeyArity(key) || table.rows[0][0].length, table.rows),
1145
- ),
1232
+ setOperator(key, createOperatorTable(table.name, getKeyArity(key), table.rows)),
1146
1233
  ),
1147
1234
  );
1148
1235
  const substitutions = new Map(
1149
1236
  config.substitutions.flatMap((substitution) =>
1150
- getScopedKeys(substitution).map((key): [string, string] => [
1237
+ getSubstitutedKeys(substitution).map((key): [string, string] => [
1151
1238
  key,
1152
1239
  getRootKey(substitution.target),
1153
1240
  ]),
1154
1241
  ),
1155
1242
  );
1243
+ [...substitutions.keys()].forEach((key) => constants.delete(key));
1244
+ const checkSubstitutionTarget = (name: string, target: string, arity: number | undefined) => {
1245
+ const targetKey = getRootKey(target);
1246
+ const definition = definitions.get(targetKey);
1247
+ const isDefined =
1248
+ definition !== undefined ||
1249
+ builtins.has(targetKey) ||
1250
+ constants.has(targetKey) ||
1251
+ declaredConstants.includes(target) ||
1252
+ variables.includes(target);
1253
+ if (!isDefined) {
1254
+ throw new TlaConfigError(
1255
+ `The configuration file substitutes for ${name} with the undefined identifier ${target}.`,
1256
+ );
1257
+ }
1258
+ if (definition?.kind === "Operator" && definition.params.length !== arity) {
1259
+ throw new TlaConfigError(
1260
+ `The configuration file substitutes for ${name} with ${target} of different number of arguments.`,
1261
+ );
1262
+ }
1263
+ };
1156
1264
  config.substitutions
1157
1265
  .filter((substitution) => substitution.module === undefined)
1158
1266
  .forEach((substitution) => {
@@ -1168,32 +1276,43 @@ export const createEnvironment = (
1168
1276
  `In the configuration file, the identifier ${target} appears\non the right-hand side of a <- after already appearing on the\nleft-hand side of one.`,
1169
1277
  );
1170
1278
  }
1171
- const targetKey = getRootKey(target);
1172
- const definition = definitions.get(targetKey);
1173
- const isDefined =
1174
- definition !== undefined ||
1175
- builtins.has(targetKey) ||
1176
- constants.has(targetKey) ||
1177
- declaredConstants.includes(target) ||
1178
- variables.includes(target);
1179
- if (!isDefined) {
1180
- throw new TlaConfigError(
1181
- `The configuration file substitutes for ${name} with the undefined identifier ${target}.`,
1182
- );
1183
- }
1184
- if (
1185
- definition?.kind === "Operator" &&
1186
- definition.params.length !==
1187
- (linkedRoot.constants.find((constant) => constant.name === name)?.arity ??
1188
- linkedRoot.visible.get(name)?.arity)
1189
- ) {
1279
+ checkSubstitutionTarget(
1280
+ name,
1281
+ target,
1282
+ linkedRoot.constants.find((constant) => constant.name === name)?.arity ??
1283
+ linkedRoot.visible.get(name)?.arity,
1284
+ );
1285
+ });
1286
+ const scopedSubstitutions = config.substitutions.filter(
1287
+ (substitution) => substitution.module !== undefined,
1288
+ );
1289
+ [...moduleSymbols.keys()].forEach((name) => {
1290
+ const inModule = scopedSubstitutions.filter((substitution) => substitution.module === name);
1291
+ inModule.forEach((substitution) => {
1292
+ const symbol = getScopedSymbol(substitution);
1293
+ if (!symbol) return;
1294
+ if (inModule.some((other) => other.name === substitution.target)) {
1190
1295
  throw new TlaConfigError(
1191
- `The configuration file substitutes for ${name} with ${target} of different number of arguments.`,
1296
+ `In the configuration file, the identifier ${substitution.target} appears\non the right-hand side of a <- after already appearing on the\nleft-hand side of one.`,
1192
1297
  );
1193
1298
  }
1299
+ checkSubstitutionTarget(substitution.name, substitution.target, symbol.arity);
1194
1300
  });
1195
- // TLC sets a module-scoped entry on the body of the module's definition, which every instance of
1196
- // the module shares.
1301
+ const missing = inModule.find((substitution) => !getScopedSymbol(substitution));
1302
+ if (missing) {
1303
+ throw new TlaConfigError(
1304
+ `In the configuration file, the identifier ${missing.name} does not appear in the specification.`,
1305
+ );
1306
+ }
1307
+ });
1308
+ const unknownModule = scopedSubstitutions.find(
1309
+ (substitution) => !moduleSymbols.has(substitution.module ?? ""),
1310
+ );
1311
+ if (unknownModule) {
1312
+ throw new TlaConfigError(
1313
+ `In the configuration file, the module name ${unknownModule.module} is not a module in the specification.`,
1314
+ );
1315
+ }
1197
1316
  const scopedKeys = new Set(
1198
1317
  [...config.constants, ...config.substitutions]
1199
1318
  .filter((item) => item.module !== undefined)
@@ -1224,11 +1343,16 @@ export const createEnvironment = (
1224
1343
  if (symbol.key === key && name !== key) definitions.set(name, alias);
1225
1344
  });
1226
1345
  });
1346
+ moduleOperators.forEach((operator) =>
1347
+ getLinkedModule(operator.module, root.name).constants.forEach((constant) => {
1348
+ const value = operator.constants?.[constant.name];
1349
+ if (value !== undefined) constants.set(constant.name, value);
1350
+ }),
1351
+ );
1227
1352
  const unassigned = declaredConstants.filter(
1228
1353
  (name) => !constants.has(name) && !substitutions.has(name) && !operatorKeys.has(name),
1229
1354
  );
1230
- if (unassigned.length > 0 && !options.isUnconfigured) {
1231
- // TLC reports the first constant it finds unassigned in SANY's order of declarations.
1355
+ if (unassigned.length > 0) {
1232
1356
  const name =
1233
1357
  order.getDeclarationOrder("constant").find((constant) => unassigned.includes(constant)) ??
1234
1358
  unassigned[0];
@@ -1237,7 +1361,7 @@ export const createEnvironment = (
1237
1361
  );
1238
1362
  }
1239
1363
 
1240
- if (options.isTraceRecorded) {
1364
+ if (traceFile !== undefined) {
1241
1365
  builtins.forEach((builtin, name) => {
1242
1366
  const replacement = getTraceSpecArithmetic(builtin);
1243
1367
  if (replacement) builtins.set(name, replacement);
@@ -1268,13 +1392,11 @@ export const createEnvironment = (
1268
1392
  facts,
1269
1393
  startupValues: Array.from({ length: facts.ids.size }, (): Value | undefined => undefined),
1270
1394
  substitutedDefinitions,
1395
+ instanceParams,
1271
1396
  evaluators: new WeakMap(),
1272
1397
  entryEvaluators: new WeakMap(),
1273
1398
  definitionEvaluators: new WeakMap(),
1274
1399
  };
1275
- // TLC evaluates a substitute at startup and rejects it only when that fails and the level bound it
1276
- // computes is above constant. The bound counts the operators that TLC's Java code overrides with
1277
- // a minimum level as state-level, so the analyzer takes them for variables.
1278
1400
  const analyzer = createLevelAnalyzer({
1279
1401
  constants: new Set(constants.keys()),
1280
1402
  variables: new Set([
@@ -1302,17 +1424,13 @@ export const createEnvironment = (
1302
1424
  ? getEvaluationError(definition.body)
1303
1425
  : undefined;
1304
1426
  if (error) {
1305
- // TLC's SpecProcessor adds the message of a TLCRuntimeException, not of an EvalException.
1306
1427
  const addendum = isEvalException(error) ? "" : ` - specifically: ${error.message}`;
1307
1428
  throw new TlaConfigError(
1308
1429
  `The configuration file substitutes constant ${name} with non-constant ${target}${addendum}`,
1309
1430
  );
1310
1431
  }
1311
1432
  });
1312
- // TLC 1.7.4 processes the whole spec before it creates its model checker, which TLCGet reads.
1313
1433
  if (runtime.version !== "1.7.4") runtime.isStarted = true;
1314
- // TLC computes the constant definitions of each module in the order SANY finishes the modules,
1315
- // except those of a module that an INSTANCE gives parameters to.
1316
1434
  const instantiated = new Set(
1317
1435
  linkOrder.flatMap((linked) => linked.module.instances.map((instance) => instance.module)),
1318
1436
  );
@@ -1334,8 +1452,8 @@ export const createEnvironment = (
1334
1452
  },
1335
1453
  ),
1336
1454
  ),
1337
- rootConstants: linkedRoot.constants,
1338
- rootSymbols: linkedRoot.visible,
1339
1455
  javaOverrides: linkOrder.flatMap((linked) => javaOverrides.get(linked.module.name) ?? []),
1456
+ moduleOperators,
1457
+ rootName: root.name,
1340
1458
  };
1341
1459
  };