tla-ts 0.0.4 → 0.0.5-dev.cc59f31

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 (378) hide show
  1. package/README.md +37 -126
  2. package/dist/cli.cjs +1 -1
  3. package/dist/cli.js +1 -1
  4. package/dist/deciders.cjs +366 -0
  5. package/dist/deciders.js +366 -0
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +46 -12
  8. package/dist/index.d.ts +46 -12
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -4
  11. package/dist/parallel-worker.js +1 -4
  12. package/dist/prove-worker.cjs +9 -0
  13. package/dist/prove-worker.d.cts +9 -0
  14. package/dist/prove-worker.d.ts +9 -0
  15. package/dist/prove-worker.js +9 -0
  16. package/dist/prove.cjs +1006 -0
  17. package/dist/prove.js +1006 -0
  18. package/dist/run.cjs +45 -0
  19. package/dist/run.js +45 -0
  20. package/dist/tlapm.cjs +10 -0
  21. package/dist/tlapm.js +10 -0
  22. package/dist/transfer.cjs +76 -92
  23. package/dist/transfer.js +76 -92
  24. package/dist/worker.cjs +21 -0
  25. package/dist/worker.js +21 -0
  26. package/package.json +21 -12
  27. package/src/ast.ts +2 -2
  28. package/src/bags.ts +22 -23
  29. package/src/builtins.ts +16 -8
  30. package/src/check.ts +131 -1153
  31. package/src/{cli-options.ts → cli/options.ts} +54 -9
  32. package/src/cli/run.ts +63 -0
  33. package/src/cli/shared.ts +106 -0
  34. package/src/cli/tlapm.ts +374 -0
  35. package/src/{run-cli.ts → cli/tlc.ts} +115 -721
  36. package/src/cli/xml-exporter.ts +221 -0
  37. package/src/cli.ts +1 -1
  38. package/src/codegen.ts +43 -22
  39. package/src/config.ts +5 -5
  40. package/src/dependencies.ts +4 -6
  41. package/src/environment.ts +55 -60
  42. package/src/errors.ts +97 -35
  43. package/src/evaluate.ts +361 -181
  44. package/src/exit-codes.ts +1 -1
  45. package/src/fingerprints.ts +3 -3
  46. package/src/index.ts +10 -0
  47. package/src/instances.ts +56 -46
  48. package/src/java-overrides.ts +79 -41
  49. package/src/json.ts +31 -36
  50. package/src/levels.ts +10 -13
  51. package/src/{live-check.ts → liveness-checker.ts} +207 -141
  52. package/src/liveness.ts +38 -34
  53. package/src/{obligation-action.ts → obligations/action.ts} +248 -74
  54. package/src/{obligation-anon.ts → obligations/anonymize.ts} +55 -57
  55. package/src/obligations/equality.ts +260 -0
  56. package/src/obligations/expression.ts +618 -0
  57. package/src/{obligation-format.ts → obligations/format.ts} +7 -8
  58. package/src/obligations/generate.ts +457 -0
  59. package/src/{obligations.ts → obligations/index.ts} +46 -32
  60. package/src/{obligation-levels.ts → obligations/levels.ts} +44 -40
  61. package/src/obligations/module.ts +445 -0
  62. package/src/obligations/normalize.ts +554 -0
  63. package/src/obligations/operators.ts +176 -0
  64. package/src/obligations/pragma.ts +195 -0
  65. package/src/{obligation-printer.ts → obligations/printer.ts} +65 -230
  66. package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
  67. package/src/obligations/regroup.ts +100 -0
  68. package/src/{obligation-generate.ts → obligations/simplify.ts} +130 -536
  69. package/src/{obligation-source.ts → obligations/source.ts} +172 -216
  70. package/src/{obligation-deref.ts → obligations/subexpression.ts} +84 -115
  71. package/src/obligations/substitution.ts +261 -0
  72. package/src/obligations/temporal.ts +321 -0
  73. package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
  74. package/src/parallel-worker.ts +39 -51
  75. package/src/parallel.ts +39 -66
  76. package/src/parser.ts +67 -74
  77. package/src/{pcal-ast.ts → pcal/ast.ts} +2 -17
  78. package/src/{pcal-parse.ts → pcal/parse.ts} +28 -64
  79. package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +10 -39
  80. package/src/{pcal-translate.ts → pcal/translate.ts} +30 -109
  81. package/src/{pcal-validate.ts → pcal/validate.ts} +10 -20
  82. package/src/prover/decide-pool.ts +95 -0
  83. package/src/prover/deciders.ts +33 -0
  84. package/src/prover/first-order.ts +175 -0
  85. package/src/prover/isabelle/LICENSE +36 -0
  86. package/src/prover/isabelle/LICENSE-tlapm +26 -0
  87. package/src/prover/isabelle/decide.ts +44 -0
  88. package/src/prover/isabelle/encode.ts +445 -0
  89. package/src/prover/isabelle/isar/inner-syntax.ts +579 -0
  90. package/src/prover/isabelle/isar/method.ts +367 -0
  91. package/src/prover/isabelle/isar/proof.ts +28 -0
  92. package/src/prover/isabelle/isar/statement.ts +57 -0
  93. package/src/prover/isabelle/isar/theory.ts +192 -0
  94. package/src/prover/isabelle/isar/type-check.ts +278 -0
  95. package/src/prover/isabelle/provers/blast/blast.ts +258 -0
  96. package/src/prover/isabelle/provers/blast/branch.ts +322 -0
  97. package/src/prover/isabelle/provers/blast/prove.ts +347 -0
  98. package/src/prover/isabelle/provers/blast/rules.ts +330 -0
  99. package/src/prover/isabelle/provers/blast/state.ts +180 -0
  100. package/src/prover/isabelle/provers/blast/term.ts +546 -0
  101. package/src/prover/isabelle/provers/clasimp.ts +150 -0
  102. package/src/prover/isabelle/provers/classical.ts +389 -0
  103. package/src/prover/isabelle/provers/hypsubst.ts +433 -0
  104. package/src/prover/isabelle/pure/bicompose.ts +174 -0
  105. package/src/prover/isabelle/pure/consts.ts +32 -0
  106. package/src/prover/isabelle/pure/conv.ts +79 -0
  107. package/src/prover/isabelle/pure/drule.ts +264 -0
  108. package/src/prover/isabelle/pure/envir.ts +331 -0
  109. package/src/prover/isabelle/pure/goal.ts +53 -0
  110. package/src/prover/isabelle/pure/interrupt.ts +16 -0
  111. package/src/prover/isabelle/pure/list.ts +12 -0
  112. package/src/prover/isabelle/pure/logic.ts +330 -0
  113. package/src/prover/isabelle/pure/name.ts +98 -0
  114. package/src/prover/isabelle/pure/net.ts +215 -0
  115. package/src/prover/isabelle/pure/object-logic.ts +41 -0
  116. package/src/prover/isabelle/pure/pattern.ts +631 -0
  117. package/src/prover/isabelle/pure/raw-simplifier.ts +338 -0
  118. package/src/prover/isabelle/pure/rewriter.ts +602 -0
  119. package/src/prover/isabelle/pure/search.ts +68 -0
  120. package/src/prover/isabelle/pure/seq.ts +133 -0
  121. package/src/prover/isabelle/pure/simplifier.ts +106 -0
  122. package/src/prover/isabelle/pure/table.ts +201 -0
  123. package/src/prover/isabelle/pure/tactic.ts +168 -0
  124. package/src/prover/isabelle/pure/tactical.ts +264 -0
  125. package/src/prover/isabelle/pure/term-ord.ts +105 -0
  126. package/src/prover/isabelle/pure/term.ts +688 -0
  127. package/src/prover/isabelle/pure/thm.ts +783 -0
  128. package/src/prover/isabelle/pure/type.ts +121 -0
  129. package/src/prover/isabelle/pure/unify.ts +753 -0
  130. package/src/prover/isabelle/pure/variable.ts +25 -0
  131. package/src/prover/isabelle/tla/classical-setup.ts +101 -0
  132. package/src/prover/isabelle/tla/context.ts +74 -0
  133. package/src/prover/isabelle/tla/logic-data.ts +5 -0
  134. package/src/prover/isabelle/tla/logic.ts +215 -0
  135. package/src/prover/isabelle/tla/simpdata.ts +241 -0
  136. package/src/prover/isabelle/tools/intuitionistic.ts +132 -0
  137. package/src/prover/ocaml.ts +22 -0
  138. package/src/prover/prep/action.ts +508 -0
  139. package/src/prover/prep/enabled-axioms.ts +189 -0
  140. package/src/prover/prep/fingerprint.ts +388 -0
  141. package/src/prover/prep/level-comparison.ts +529 -0
  142. package/src/prover/prep/md5.ts +60 -0
  143. package/src/prover/prep/methods.ts +221 -0
  144. package/src/prover/prep/normalize.ts +309 -0
  145. package/src/prover/prove-worker.ts +22 -0
  146. package/src/prover/prove.ts +492 -0
  147. package/src/prover/ptl/decide.ts +68 -0
  148. package/src/prover/ptl/encode.ts +244 -0
  149. package/src/prover/ptl/sat.ts +151 -0
  150. package/src/prover/ptl/tableau.ts +276 -0
  151. package/src/prover/smt/axioms.ts +209 -0
  152. package/src/prover/smt/context.ts +108 -0
  153. package/src/prover/smt/data.ts +636 -0
  154. package/src/prover/smt/encode.ts +275 -0
  155. package/src/prover/smt/extensionality.ts +65 -0
  156. package/src/prover/smt/flatten.ts +112 -0
  157. package/src/prover/smt/format.ts +154 -0
  158. package/src/prover/smt/instances.ts +181 -0
  159. package/src/prover/smt/rewrite.ts +766 -0
  160. package/src/prover/smt/solver/act-cache.ts +265 -0
  161. package/src/prover/smt/solver/arith-rewriter.ts +962 -0
  162. package/src/prover/smt/solver/array.ts +22 -0
  163. package/src/prover/smt/solver/asserted-formulas.ts +469 -0
  164. package/src/prover/smt/solver/ast-lt.ts +157 -0
  165. package/src/prover/smt/solver/ast-util.ts +91 -0
  166. package/src/prover/smt/solver/ast.ts +1315 -0
  167. package/src/prover/smt/solver/auf-solver.ts +572 -0
  168. package/src/prover/smt/solver/case-split-queue.ts +178 -0
  169. package/src/prover/smt/solver/cg-table.ts +175 -0
  170. package/src/prover/smt/solver/clause.ts +276 -0
  171. package/src/prover/smt/solver/conflict-resolution.ts +343 -0
  172. package/src/prover/smt/solver/context.ts +1292 -0
  173. package/src/prover/smt/solver/ctx-simplify.ts +334 -0
  174. package/src/prover/smt/solver/der.ts +224 -0
  175. package/src/prover/smt/solver/dyn-ack.ts +141 -0
  176. package/src/prover/smt/solver/e-matching.ts +659 -0
  177. package/src/prover/smt/solver/enode.ts +259 -0
  178. package/src/prover/smt/solver/expr-ref.ts +21 -0
  179. package/src/prover/smt/solver/expr-safe-replace.ts +172 -0
  180. package/src/prover/smt/solver/fingerprints.ts +92 -0
  181. package/src/prover/smt/solver/flat-literals.ts +51 -0
  182. package/src/prover/smt/solver/goal.ts +138 -0
  183. package/src/prover/smt/solver/hash.ts +173 -0
  184. package/src/prover/smt/solver/hashtable.ts +166 -0
  185. package/src/prover/smt/solver/internalizer.ts +1381 -0
  186. package/src/prover/smt/solver/lbool.ts +5 -0
  187. package/src/prover/smt/solver/literal.ts +24 -0
  188. package/src/prover/smt/solver/lp/bound-propagator.ts +391 -0
  189. package/src/prover/smt/solver/lp/constraints.ts +78 -0
  190. package/src/prover/smt/solver/lp/containers.ts +296 -0
  191. package/src/prover/smt/solver/lp/core-solver.ts +504 -0
  192. package/src/prover/smt/solver/lp/cross-nested.ts +224 -0
  193. package/src/prover/smt/solver/lp/dep-intervals.ts +642 -0
  194. package/src/prover/smt/solver/lp/dependency.ts +51 -0
  195. package/src/prover/smt/solver/lp/dioph-eq.ts +1181 -0
  196. package/src/prover/smt/solver/lp/explanation.ts +46 -0
  197. package/src/prover/smt/solver/lp/gomory.ts +255 -0
  198. package/src/prover/smt/solver/lp/hnf-cutter.ts +125 -0
  199. package/src/prover/smt/solver/lp/hnf.ts +281 -0
  200. package/src/prover/smt/solver/lp/int-cube.ts +295 -0
  201. package/src/prover/smt/solver/lp/int-solver.ts +514 -0
  202. package/src/prover/smt/solver/lp/lar-solver.ts +816 -0
  203. package/src/prover/smt/solver/lp/lar-term.ts +62 -0
  204. package/src/prover/smt/solver/lp/lp-settings.ts +91 -0
  205. package/src/prover/smt/solver/lp/maximize-term.ts +347 -0
  206. package/src/prover/smt/solver/lp/nex-creator.ts +381 -0
  207. package/src/prover/smt/solver/lp/nex.ts +120 -0
  208. package/src/prover/smt/solver/lp/nla-backoff.ts +43 -0
  209. package/src/prover/smt/solver/lp/nla-basics.ts +398 -0
  210. package/src/prover/smt/solver/lp/nla-core.ts +968 -0
  211. package/src/prover/smt/solver/lp/nla-divisions.ts +332 -0
  212. package/src/prover/smt/solver/lp/nla-emonics.ts +373 -0
  213. package/src/prover/smt/solver/lp/nla-factorization.ts +30 -0
  214. package/src/prover/smt/solver/lp/nla-grobner.ts +904 -0
  215. package/src/prover/smt/solver/lp/nla-horner.ts +126 -0
  216. package/src/prover/smt/solver/lp/nla-intervals.ts +265 -0
  217. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +715 -0
  218. package/src/prover/smt/solver/lp/nla-monotone.ts +59 -0
  219. package/src/prover/smt/solver/lp/nla-order.ts +307 -0
  220. package/src/prover/smt/solver/lp/nla-patcher.ts +112 -0
  221. package/src/prover/smt/solver/lp/nla-tangents.ts +251 -0
  222. package/src/prover/smt/solver/lp/nla-throttle.ts +85 -0
  223. package/src/prover/smt/solver/lp/nla-types.ts +124 -0
  224. package/src/prover/smt/solver/lp/nla-var-eqs.ts +141 -0
  225. package/src/prover/smt/solver/lp/nra-solver.ts +440 -0
  226. package/src/prover/smt/solver/lp/numeric-pair.ts +65 -0
  227. package/src/prover/smt/solver/lp/pdd-interval.ts +31 -0
  228. package/src/prover/smt/solver/lp/pdd-simplifier.ts +184 -0
  229. package/src/prover/smt/solver/lp/pdd-solver.ts +408 -0
  230. package/src/prover/smt/solver/lp/pdd.ts +971 -0
  231. package/src/prover/smt/solver/lp/random-updater.ts +138 -0
  232. package/src/prover/smt/solver/lp/static-matrix.ts +246 -0
  233. package/src/prover/smt/solver/lp/union-find.ts +96 -0
  234. package/src/prover/smt/solver/mam-compiler.ts +847 -0
  235. package/src/prover/smt/solver/mam-interpreter.ts +400 -0
  236. package/src/prover/smt/solver/maximize-ac-sharing.ts +118 -0
  237. package/src/prover/smt/solver/model-checker.ts +347 -0
  238. package/src/prover/smt/solver/model-evaluator.ts +262 -0
  239. package/src/prover/smt/solver/model-finder.ts +155 -0
  240. package/src/prover/smt/solver/model-generator.ts +97 -0
  241. package/src/prover/smt/solver/model-macro-solver.ts +728 -0
  242. package/src/prover/smt/solver/nlsat/algebraic.ts +1161 -0
  243. package/src/prover/smt/solver/nlsat/atoms.ts +238 -0
  244. package/src/prover/smt/solver/nlsat/evaluator.ts +303 -0
  245. package/src/prover/smt/solver/nlsat/explain.ts +607 -0
  246. package/src/prover/smt/solver/nlsat/interval-set.ts +351 -0
  247. package/src/prover/smt/solver/nlsat/levelwise.ts +737 -0
  248. package/src/prover/smt/solver/nlsat/mpbq.ts +161 -0
  249. package/src/prover/smt/solver/nlsat/polynomial.ts +1722 -0
  250. package/src/prover/smt/solver/nlsat/solver.ts +911 -0
  251. package/src/prover/smt/solver/nlsat/types.ts +43 -0
  252. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
  253. package/src/prover/smt/solver/nlsat/upolynomial.ts +996 -0
  254. package/src/prover/smt/solver/nnf.ts +469 -0
  255. package/src/prover/smt/solver/pattern-inference.ts +351 -0
  256. package/src/prover/smt/solver/poly-rewriter.ts +477 -0
  257. package/src/prover/smt/solver/propagate-values.ts +83 -0
  258. package/src/prover/smt/solver/proto-model.ts +551 -0
  259. package/src/prover/smt/solver/pull-quant.ts +139 -0
  260. package/src/prover/smt/solver/qe-lite-der.ts +526 -0
  261. package/src/prover/smt/solver/qe-lite-fm.ts +576 -0
  262. package/src/prover/smt/solver/qe-lite.ts +381 -0
  263. package/src/prover/smt/solver/qi-queue.ts +362 -0
  264. package/src/prover/smt/solver/quant-tactics.ts +117 -0
  265. package/src/prover/smt/solver/quantifier-analyzer.ts +562 -0
  266. package/src/prover/smt/solver/quantifier-manager.ts +186 -0
  267. package/src/prover/smt/solver/random-gen.ts +10 -0
  268. package/src/prover/smt/solver/rational.ts +165 -0
  269. package/src/prover/smt/solver/ref-vector.ts +62 -0
  270. package/src/prover/smt/solver/relevancy.ts +247 -0
  271. package/src/prover/smt/solver/rewriter-tpl.ts +1159 -0
  272. package/src/prover/smt/solver/rewriter.ts +843 -0
  273. package/src/prover/smt/solver/rlimit.ts +79 -0
  274. package/src/prover/smt/solver/smtlib-parser.ts +526 -0
  275. package/src/prover/smt/solver/solver.ts +71 -0
  276. package/src/prover/smt/solver/sort.ts +35 -0
  277. package/src/prover/smt/solver/sticky-generations.ts +69 -0
  278. package/src/prover/smt/solver/theory-lra-axioms.ts +340 -0
  279. package/src/prover/smt/solver/theory-lra-bounds.ts +226 -0
  280. package/src/prover/smt/solver/theory-lra-final-check.ts +252 -0
  281. package/src/prover/smt/solver/theory-lra-internalize.ts +476 -0
  282. package/src/prover/smt/solver/theory-lra-model.ts +243 -0
  283. package/src/prover/smt/solver/theory-lra-propagate.ts +405 -0
  284. package/src/prover/smt/solver/theory-lra-state.ts +43 -0
  285. package/src/prover/smt/solver/theory-lra.ts +56 -0
  286. package/src/prover/smt/solver/var-subst.ts +258 -0
  287. package/src/prover/smt/solver/z3-license.txt +10 -0
  288. package/src/prover/smt/table.ts +170 -0
  289. package/src/prover/tlapm/cache.ts +236 -0
  290. package/src/prover/tlapm/ocaml-marshal.ts +166 -0
  291. package/src/prover/tlapm/tlapm.ts +96 -0
  292. package/src/prover/tlaps-module.ts +510 -0
  293. package/src/prover/verdict.ts +13 -0
  294. package/src/prover/zenon/LICENSE +32 -0
  295. package/src/prover/zenon/check/check.ts +105 -0
  296. package/src/prover/zenon/check/definitions.ts +144 -0
  297. package/src/prover/zenon/check/equality.ts +182 -0
  298. package/src/prover/zenon/check/functions.ts +62 -0
  299. package/src/prover/zenon/check/keys.ts +125 -0
  300. package/src/prover/zenon/check/propositional.ts +104 -0
  301. package/src/prover/zenon/check/records.ts +188 -0
  302. package/src/prover/zenon/check/relations.ts +121 -0
  303. package/src/prover/zenon/check/rewrites.ts +224 -0
  304. package/src/prover/zenon/check/sets.ts +302 -0
  305. package/src/prover/zenon/check/terms.ts +127 -0
  306. package/src/prover/zenon/check/tla.ts +126 -0
  307. package/src/prover/zenon/decide.ts +107 -0
  308. package/src/prover/zenon/encode.ts +378 -0
  309. package/src/prover/zenon/eqrel.ts +300 -0
  310. package/src/prover/zenon/equality-rules.ts +435 -0
  311. package/src/prover/zenon/expr.ts +551 -0
  312. package/src/prover/zenon/index-table.ts +350 -0
  313. package/src/prover/zenon/isar-case.ts +513 -0
  314. package/src/prover/zenon/isar.ts +1249 -0
  315. package/src/prover/zenon/limits.ts +15 -0
  316. package/src/prover/zenon/llproof.ts +173 -0
  317. package/src/prover/zenon/mltoll.ts +1566 -0
  318. package/src/prover/zenon/node.ts +297 -0
  319. package/src/prover/zenon/ocaml.ts +169 -0
  320. package/src/prover/zenon/parse.ts +247 -0
  321. package/src/prover/zenon/phrase.ts +191 -0
  322. package/src/prover/zenon/proof.ts +198 -0
  323. package/src/prover/zenon/propositional-rules.ts +387 -0
  324. package/src/prover/zenon/rules.ts +94 -0
  325. package/src/prover/zenon/search.ts +288 -0
  326. package/src/prover/zenon/tla/functions.ts +151 -0
  327. package/src/prover/zenon/tla/llproof.ts +480 -0
  328. package/src/prover/zenon/tla/records.ts +225 -0
  329. package/src/prover/zenon/tla/rewrites.ts +447 -0
  330. package/src/prover/zenon/tla/sets.ts +304 -0
  331. package/src/prover/zenon/tla/terms.ts +162 -0
  332. package/src/prover/zenon/tla/tla.ts +506 -0
  333. package/src/randomization.ts +19 -24
  334. package/src/resolve.ts +15 -22
  335. package/src/runtime.ts +8 -8
  336. package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
  337. package/src/{sany-generator.ts → sany/generator.ts} +38 -55
  338. package/src/{sany-levels.ts → sany/levels.ts} +45 -48
  339. package/src/{sany-lexer.ts → sany/lexer.ts} +2 -3
  340. package/src/{sany-linter.ts → sany/linter.ts} +1 -1
  341. package/src/{sany-modules.ts → sany/modules.ts} +2 -2
  342. package/src/{sany-nodes.ts → sany/nodes.ts} +2 -2
  343. package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
  344. package/src/{sany-report.ts → sany/report.ts} +16 -17
  345. package/src/{sany-selectors.ts → sany/selectors.ts} +3 -5
  346. package/src/{sany-source.ts → sany/source.ts} +6 -7
  347. package/src/{sany-xml.ts → sany/xml.ts} +5 -6
  348. package/src/search.ts +969 -0
  349. package/src/spec-description.ts +26 -20
  350. package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
  351. package/src/standard-modules.ts +21 -22
  352. package/src/state-graph.ts +9 -8
  353. package/src/substitution-levels.ts +2 -2
  354. package/src/successors.ts +39 -23
  355. package/src/symmetry.ts +1 -1
  356. package/src/tableau.ts +6 -7
  357. package/src/tlc/fingerprint.ts +214 -0
  358. package/src/{tlc-messages.ts → tlc/messages.ts} +119 -7
  359. package/src/{tlc-order.ts → tlc/order.ts} +7 -7
  360. package/src/{tlc-random.ts → tlc/random.ts} +3 -190
  361. package/src/{tlc-replay.ts → tlc/replay.ts} +40 -36
  362. package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
  363. package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +30 -25
  364. package/src/{tlc-version.ts → tlc/version.ts} +8 -7
  365. package/src/transfer.ts +32 -32
  366. package/src/values.ts +166 -111
  367. package/src/worker.ts +62 -0
  368. package/dist/parallel.cjs +0 -12
  369. package/dist/parallel.js +0 -12
  370. package/dist/run-cli.cjs +0 -55
  371. package/dist/run-cli.js +0 -55
  372. package/src/canonical.ts +0 -40
  373. package/src/obligation-expression.ts +0 -1060
  374. package/src/obligation-module.ts +0 -1042
  375. package/src/standard-ranges.ts +0 -116
  376. package/src/value-sources.ts +0 -29
  377. /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
  378. /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
package/src/resolve.ts CHANGED
@@ -36,7 +36,7 @@ export type SymbolKind =
36
36
 
37
37
  // range is where SANY reports the symbol, and two symbols at one range are one node to SANY. params
38
38
  // holds the arity of each parameter of a defined operator.
39
- export interface Binding {
39
+ interface Binding {
40
40
  kind: SymbolKind;
41
41
  arity: number;
42
42
  params?: number[];
@@ -74,14 +74,7 @@ interface ModuleBinding extends Binding {
74
74
  isPending?: boolean;
75
75
  }
76
76
 
77
- // errors and warnings collect what SANY reports while it goes on analyzing the unit, and bindings
78
- // holds the names the module binds. A label may appear where hasLabelScope holds, in a definition, a
79
- // named theorem, or a numbered step, except where isLabelForbidden holds, in the scope of a NEW in a
80
- // nested ASSUME, or where isInExcept holds, in the new value of an EXCEPT. labelParams holds the
81
- // names bound since the innermost definition, label, or step, which a label must take as parameters,
82
- // and labels the labels there. isGenerated holds in a definition tla-ts generates for a LET INSTANCE,
83
- // and in a subexpression that a name selects, which SANY analyzes where it is defined.
84
- // getInstance gives what an INSTANCE in a LET or a proof instantiates.
77
+ // What SANY reports while it goes on analyzing a unit of a module, and the scope it analyzes it in.
85
78
  interface Unit {
86
79
  imported: Symbols;
87
80
  getInstance: (instance: Instance) => InstancedModule;
@@ -94,11 +87,15 @@ interface Unit {
94
87
  bindings: Map<string, ModuleBinding>;
95
88
  errors: SanyError[];
96
89
  warnings: SanyError[];
90
+ // In a definition, a named theorem, or a numbered step.
97
91
  hasLabelScope: boolean;
92
+ // In the scope of a NEW in a nested ASSUME.
98
93
  isLabelForbidden: boolean;
99
94
  isInExcept: boolean;
95
+ // The names bound since the innermost definition, label, or step, which a label must take.
100
96
  labelParams: string[];
101
97
  labels: Set<string>;
98
+ // In a definition generated for a LET INSTANCE, or a subexpression analyzed where it is defined.
102
99
  isGenerated: boolean;
103
100
  }
104
101
 
@@ -168,10 +165,8 @@ const getModuleBinding = (name: string, unit: Unit, range: SourceRange | undefin
168
165
  const isSameRange = (left: SourceRange | undefined, right: SourceRange | undefined) =>
169
166
  left !== undefined && right !== undefined && formatRange(left) === formatRange(right);
170
167
 
171
- // SymbolTable.addSymbol binds a name nothing binds yet. It rejects a built-in operator, a parameter
172
- // or bound name already in use, and a symbol of another kind or arity than the one bound, and warns
173
- // of any other duplicate. tla-ts binds a symbol SANY never sees, such as one it generates. Tells
174
- // whether to bind the added symbol.
168
+ // SymbolTable.addSymbol: rejects redefining a built-in, a bound name, or a symbol of another kind
169
+ // or arity, and warns of any other duplicate. A symbol SANY never sees, such as a generated one, binds.
175
170
  const isBindable = (name: string, current: Binding | undefined, added: Binding, unit: Unit) => {
176
171
  if (current === undefined) return true;
177
172
  if (isSameRange(current.range, added.range)) return false;
@@ -1447,7 +1442,7 @@ const resolveTheorem = (theorem: Theorem, unit: Unit) => {
1447
1442
 
1448
1443
  // The declarations of the module an INSTANCE instantiates, the names the INSTANCE adds, and the
1449
1444
  // module that instantiates it.
1450
- export interface InstancedModule {
1445
+ interface InstancedModule {
1451
1446
  declarations: Declaration[];
1452
1447
  symbols: Symbols;
1453
1448
  instancer: string;
@@ -1461,18 +1456,16 @@ export interface ModuleReport {
1461
1456
  warnings: SanyError[];
1462
1457
  }
1463
1458
 
1464
- // bound holds the names in scope where the module starts: the built-in operators, the names of the
1465
- // module that encloses it, and those of the modules it extends. instanced holds the names each
1466
- // INSTANCE adds, getInstance what an INSTANCE in a LET or a proof instantiates, facts the theorems
1467
- // and assumptions the modules it extends or instantiates export, and warnings the warnings SANY
1468
- // reports for the spec.
1469
1459
  export interface ModuleUnit {
1470
1460
  imported: Symbols;
1471
1461
  getInstance: (instance: Instance) => InstancedModule;
1462
+ // The built-in operators and the names of the enclosing and extended modules.
1472
1463
  bound: Symbols;
1473
1464
  definitions: Map<string, Definition>;
1474
1465
  getKey: (definition: Definition) => string;
1466
+ // The names each INSTANCE adds.
1475
1467
  instanced: Map<Instance, Symbols>;
1468
+ // The theorems and assumptions the extended and instantiated modules export.
1476
1469
  facts: Set<string>;
1477
1470
  reports: ModuleReport[];
1478
1471
  warnings: SanyError[];
@@ -1631,7 +1624,7 @@ export const collectSemanticErrors = (
1631
1624
  warnings: SanyError[],
1632
1625
  ) => {
1633
1626
  const errors: SanyError[] = [];
1634
- const add = (list: SanyError[], item: SanyError) => {
1627
+ const addUnique = (list: SanyError[], item: SanyError) => {
1635
1628
  if (
1636
1629
  list.every(
1637
1630
  (existing) => existing.location !== item.location || existing.message !== item.message,
@@ -1659,8 +1652,8 @@ export const collectSemanticErrors = (
1659
1652
  }
1660
1653
  reported.push(...(error.sany?.errors ?? []));
1661
1654
  }
1662
- reported.forEach((item) => add(errors, item));
1663
- warned.forEach((item) => add(warnings, item));
1655
+ reported.forEach((item) => addUnique(errors, item));
1656
+ warned.forEach((item) => addUnique(warnings, item));
1664
1657
  });
1665
1658
  return errors;
1666
1659
  };
package/src/runtime.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { createJavaRandom, getTlcFingerprint, type JavaRandom } from "./tlc-random";
1
+ import { getTlcFingerprint } from "./tlc/fingerprint";
2
+ import { createJavaRandom, type JavaRandom } from "./tlc/random";
2
3
  import { createFunction, createRecord, type Value } from "./values";
3
- import type { TlcVersion } from "./tlc-version";
4
+ import type { TlcVersion } from "./tlc/version";
4
5
 
5
6
  export interface CheckerRuntime {
6
7
  getLevel: (state: (Value | undefined)[]) => number;
@@ -22,7 +23,6 @@ export interface CheckerRuntime {
22
23
  // TLC's -tool, under which the message of an error that TLC raises with a code holds the
23
24
  // code's markers, which AssertError compares with.
24
25
  isTool: boolean;
25
- // The TLC whose messages tla-ts reproduces.
26
26
  version: TlcVersion;
27
27
  seed: bigint;
28
28
  isSeen: (state: Value[]) => boolean;
@@ -46,8 +46,8 @@ export interface CheckerRuntime {
46
46
  // its Random with the fingerprint of each state it expands, XORed with the seed, so a state's
47
47
  // successors are the same whatever order the workers expand states in.
48
48
  export const createRuntime = (checkDeadlock: boolean, seed = 0n): CheckerRuntime => {
49
- const startup = createJavaRandom(seed);
50
- const worker = { random: createJavaRandom(seed), state: undefined as Value[] | undefined };
49
+ const startupRandom = createJavaRandom(seed);
50
+ const worker = { random: createJavaRandom(seed), seededState: undefined as Value[] | undefined };
51
51
  const phase = { isStartup: false };
52
52
  const runtime: CheckerRuntime = {
53
53
  getLevel: () => 0,
@@ -60,10 +60,10 @@ export const createRuntime = (checkDeadlock: boolean, seed = 0n): CheckerRuntime
60
60
  getFingerprint: getTlcFingerprint,
61
61
  getRandom: () => {
62
62
  const state = phase.isStartup ? undefined : runtime.getCurrentState();
63
- if (state === undefined) return startup;
64
- if (state !== worker.state) {
63
+ if (state === undefined) return startupRandom;
64
+ if (state !== worker.seededState) {
65
65
  worker.random.setSeed(runtime.getFingerprint(state) ^ BigInt.asUintN(64, seed));
66
- worker.state = state;
66
+ worker.seededState = state;
67
67
  }
68
68
  return worker.random;
69
69
  },
@@ -1,4 +1,4 @@
1
- import type { FormalParamNode, LevelFields, OpDefNode, SanyLocation } from "./sany-nodes";
1
+ import type { FormalParamNode, LevelFields, OpDefNode, SanyLocation } from "./nodes";
2
2
 
3
3
  // tla2sany.semantic.BuiltInOperators: name, arity, level, maximum argument levels and argument
4
4
  // weights. SANY leaves the levels of "." and \neg unset.
@@ -1,5 +1,5 @@
1
- import { TEMPORAL_LEVEL } from "./levels";
2
- import type { TlcVersion } from "./tlc-version";
1
+ import { TEMPORAL_LEVEL } from "../levels";
2
+ import type { TlcVersion } from "../tlc/version";
3
3
  import type {
4
4
  AssumeProve,
5
5
  Assumption,
@@ -18,18 +18,18 @@ import type {
18
18
  SourceLocation,
19
19
  Theorem,
20
20
  UseOrHide,
21
- } from "./ast";
22
- import { getChildren } from "./ast";
21
+ } from "../ast";
22
+ import { getChildren } from "../ast";
23
23
  import {
24
24
  TlaMissingModuleError,
25
25
  TlaSanyFatalError,
26
26
  TlaSyntaxError,
27
27
  TlaUnsupportedError,
28
- } from "./errors";
29
- import { parseSanyModule } from "./parser";
30
- import { BUILTIN_LOCATION, createBuiltins, createLevelFields } from "./sany-builtins";
31
- import { getSany174LexicalError } from "./sany-lexer";
32
- import { getSanyParseError } from "./sany-parse-error";
28
+ } from "../errors";
29
+ import { parseSanyModule } from "../parser";
30
+ import { BUILTIN_LOCATION, createBuiltins, createLevelFields } from "./builtins";
31
+ import { getSany174LexicalError } from "./lexer";
32
+ import { getSanyParseError } from "./parse-error";
33
33
  import {
34
34
  addSanyMessage,
35
35
  CONSTANT_DECL_KIND,
@@ -73,13 +73,13 @@ import {
73
73
  type TheoremNode,
74
74
  type ThmOrAssumpDefNode,
75
75
  type UseOrHideNode,
76
- } from "./sany-nodes";
76
+ } from "./nodes";
77
77
  import {
78
78
  createSelectorResolver,
79
79
  getSelectorItems,
80
80
  isGeneralId,
81
81
  type SelectorItem,
82
- } from "./sany-selectors";
82
+ } from "./selectors";
83
83
  import {
84
84
  createSourceFile,
85
85
  findNameTokens,
@@ -99,8 +99,8 @@ import {
99
99
  isToken,
100
100
  type SourceFile,
101
101
  type TokenSpan,
102
- } from "./sany-source";
103
- import { SANY_OPERATOR_SYNONYMS } from "./tlc-modules";
102
+ } from "./source";
103
+ import { SANY_OPERATOR_SYNONYMS } from "../tlc/jar-data";
104
104
 
105
105
  const SYNONYMS = new Map(
106
106
  SANY_OPERATOR_SYNONYMS.flatMap(([canonical, ...synonyms]) =>
@@ -161,7 +161,7 @@ export interface SanySpecification {
161
161
  messages: SanyMessage[];
162
162
  }
163
163
 
164
- export interface SanyGenerationOptions {
164
+ interface SanyGenerationOptions {
165
165
  // The name of the root module's file, which SANY requires to match the module's name.
166
166
  rootFileName?: string;
167
167
  // The path of the root module's file as SANY's caller gives it, which SANY names when it cannot
@@ -271,6 +271,15 @@ const isInternalInstance = (module: Module, name: string) => {
271
271
  return false;
272
272
  };
273
273
 
274
+ type LetUnit =
275
+ | { kind: "Recursive"; declarations: Declaration[] }
276
+ | { kind: "Instance"; instance: Instance }
277
+ | { kind: "Definition"; definition: Definition };
278
+
279
+ // The decimal digits of a numeral such as \hFF, which SANY keeps at any size.
280
+ const getNumeralDigits = (text: string) =>
281
+ BigInt(text.startsWith("\\") ? `0${text.slice(1).replace(/^h/i, "x")}` : text).toString();
282
+
274
283
  // An entry of SANY's LS stack: the labels of a definition, theorem or label and the parameters
275
284
  // bound within it around the expression being generated.
276
285
  interface LabelScope {
@@ -542,11 +551,8 @@ export const generateSanySpecification = (
542
551
  path.pop();
543
552
  order.push(name);
544
553
  };
545
- // SpecObj.loadSpec: SANY resolves the first name it finds unresolved searching from the root,
546
- // each module's extended modules before the modules they import, and the instantiated modules
547
- // only once it has resolved every extended module. SANY resolves a name in the context of the
548
- // module that names it, so a module another module loaded is unresolved until SANY reaches it
549
- // from this one.
554
+ // SpecObj.loadSpec: SANY resolves the first unresolved name it finds from the root, every
555
+ // extended module before any instantiated one, each in the context of the module that names it.
550
556
  const resolutions = new Set<string>();
551
557
  const isResolved = (importer: string, name: string) => resolutions.has(`${importer} ${name}`);
552
558
  const findUnresolved = (
@@ -1402,7 +1408,7 @@ export const generateSanySpecification = (
1402
1408
  return {
1403
1409
  ...createLevelFields(getId()),
1404
1410
  kind: "Numeral",
1405
- value: getNumeralValue(expression.text ?? String(expression.value)),
1411
+ value: getNumeralDigits(expression.text ?? String(expression.value)),
1406
1412
  location,
1407
1413
  };
1408
1414
  case "Decimal": {
@@ -1913,7 +1919,6 @@ export const generateSanySpecification = (
1913
1919
  if (node.operator.name === "$NonRecursiveFcnSpec") node.unbounded = undefined;
1914
1920
  };
1915
1921
 
1916
- // The module's operators declared in RECURSIVE statements.
1917
1922
  const recursiveDeclarations: OpDefNode[] = [];
1918
1923
  const processRecursive = (declarations: Declaration[]) => {
1919
1924
  if (state.unresolvedSum === 0) state.recursiveSectionCount++;
@@ -1985,12 +1990,13 @@ export const generateSanySpecification = (
1985
1990
  });
1986
1991
  // Generator.checkSubstitutionForCorrectArity, which SANY locates in its builtins for the
1987
1992
  // nullOpArg it substitutes after an error.
1988
- const checkArity = (target: OpDeclNode, expr: ExprOrOpArgNode) => {
1989
- const arity = expr.kind === "OpArg" ? getSymbolArity(expr.op) : 0;
1990
- const isNullOpArg = target.arity > 0 && expr.kind === "OpAppl" && expr.isNull === true;
1993
+ const checkArity = (target: OpDeclNode, substitute: ExprOrOpArgNode) => {
1994
+ const arity = substitute.kind === "OpArg" ? getSymbolArity(substitute.op) : 0;
1995
+ const isNullOpArg =
1996
+ target.arity > 0 && substitute.kind === "OpAppl" && substitute.isNull === true;
1991
1997
  if (arity !== target.arity && !isNullOpArg) {
1992
1998
  addError(
1993
- expr.location,
1999
+ substitute.location,
1994
2000
  `An operator must be substituted for symbol '${target.name}', and it must have arity ${target.arity}.`,
1995
2001
  );
1996
2002
  }
@@ -2012,11 +2018,11 @@ export const generateSanySpecification = (
2012
2018
  );
2013
2019
  return;
2014
2020
  }
2015
- const expr =
2021
+ const substitute =
2016
2022
  target.arity === 0
2017
2023
  ? generateExpression(substitution.expression)
2018
2024
  : generateOperatorArgument(substitution.expression, target);
2019
- checkArity(target, expr);
2025
+ checkArity(target, substitute);
2020
2026
  const existing = substs.find((subst) => subst.op.name === target.name);
2021
2027
  if (existing && !existing.isImplicit) {
2022
2028
  addError(
@@ -2024,9 +2030,9 @@ export const generateSanySpecification = (
2024
2030
  `Multiple substitutions for symbol '${target.name}' in substitution.`,
2025
2031
  );
2026
2032
  } else if (existing) {
2027
- existing.expr = expr;
2033
+ existing.expr = substitute;
2028
2034
  existing.isImplicit = false;
2029
- } else substs.push({ op: target, expr, isImplicit: false });
2035
+ } else substs.push({ op: target, expr: substitute, isImplicit: false });
2030
2036
  });
2031
2037
  // TLC 1.7.4's SANY checks the arity of only the substitutions that the INSTANCE writes.
2032
2038
  substs
@@ -2215,8 +2221,8 @@ export const generateSanySpecification = (
2215
2221
  return symbol;
2216
2222
  };
2217
2223
  const isOriginParameterFree = symbol.module === undefined || isParameterFree(symbol.module);
2218
- const node = !isInstanceeParameterFree
2219
- ? isOriginParameterFree
2224
+ const node =
2225
+ isInstanceeParameterFree || isOriginParameterFree
2220
2226
  ? isLocal
2221
2227
  ? copyFrom(symbol.module, symbol.body)
2222
2228
  : reuse()
@@ -2224,10 +2230,7 @@ export const generateSanySpecification = (
2224
2230
  currentModule,
2225
2231
  symbol.body &&
2226
2232
  createSubstIn("SubstIn", substs, symbol.body, instanceeModule, location),
2227
- )
2228
- : isLocal
2229
- ? copyFrom(symbol.module, symbol.body)
2230
- : reuse();
2233
+ );
2231
2234
  currentModule.definitions.push(node);
2232
2235
  setRecursionFields(node);
2233
2236
  });
@@ -3106,23 +3109,3 @@ export const generateSanySpecification = (
3106
3109
  });
3107
3110
  return { root: modules[modules.length - 1], modules, messages };
3108
3111
  };
3109
-
3110
- type LetUnit =
3111
- | { kind: "Recursive"; declarations: Declaration[] }
3112
- | { kind: "Instance"; instance: Instance }
3113
- | { kind: "Definition"; definition: Definition };
3114
-
3115
- const getNumeralValue = (text: string) => {
3116
- const lower = text.toLowerCase();
3117
- const radix = lower.startsWith("\\b")
3118
- ? 2
3119
- : lower.startsWith("\\o")
3120
- ? 8
3121
- : lower.startsWith("\\h")
3122
- ? 16
3123
- : 10;
3124
- const digits = radix === 10 ? lower : lower.slice(2);
3125
- return [...digits]
3126
- .reduce((value, digit) => value * BigInt(radix) + BigInt(parseInt(digit, radix)), 0n)
3127
- .toString();
3128
- };
@@ -1,4 +1,4 @@
1
- import { ACTION_LEVEL, CONSTANT_LEVEL, TEMPORAL_LEVEL, VARIABLE_LEVEL } from "./levels";
1
+ import { ACTION_LEVEL, CONSTANT_LEVEL, TEMPORAL_LEVEL, VARIABLE_LEVEL } from "../levels";
2
2
  import {
3
3
  addSanyMessage,
4
4
  CONSTANT_DECL_KIND,
@@ -25,7 +25,7 @@ import {
25
25
  type Subst,
26
26
  type SymbolNode,
27
27
  type ThmOrAssumpDefNode,
28
- } from "./sany-nodes";
28
+ } from "./nodes";
29
29
 
30
30
  // A port of the levelCheck methods of SANY's semantic nodes: the levels, weights and Leibniz flags
31
31
  // its XMLExporter writes, and the level errors it reports. Each check returns what SANY's returns,
@@ -50,16 +50,16 @@ const addAll = <Item>(target: Set<Item>, source: Iterable<Item>) => {
50
50
  for (const item of source) target.add(item);
51
51
  };
52
52
 
53
- const getArgLevelKey = (op: SymbolNode, index: number, param: SymbolNode) =>
54
- `${op.id}:${index}:${param.id}`;
53
+ const getArgLevelKey = (operator: SymbolNode, index: number, param: SymbolNode) =>
54
+ `${operator.id}:${index}:${param.id}`;
55
55
 
56
56
  const addArgLevelParam = (
57
57
  target: Map<string, ArgLevelParam>,
58
- op: SymbolNode,
58
+ operator: SymbolNode,
59
59
  index: number,
60
60
  param: SymbolNode,
61
61
  ) => {
62
- target.set(getArgLevelKey(op, index, param), { op, index, param });
62
+ target.set(getArgLevelKey(operator, index, param), { op: operator, index, param });
63
63
  };
64
64
 
65
65
  const addArgLevelParams = (
@@ -172,22 +172,22 @@ const getSubstitute = (symbol: SymbolNode, substs: Subst[]) =>
172
172
 
173
173
  // Subst.paramSet and Subst.allParamSet.
174
174
  const getSubstitutedParams = (param: SymbolNode, substs: Subst[], isAll: boolean) => {
175
- const expr = getSubstitute(param, substs);
176
- if (expr === undefined) return new Set([param]);
177
- return isAll ? expr.allParams : expr.levelParams;
175
+ const substitute = getSubstitute(param, substs);
176
+ if (substitute === undefined) return new Set([param]);
177
+ return isAll ? substitute.allParams : substitute.levelParams;
178
178
  };
179
179
 
180
180
  // Subst.getSubALPSet.
181
181
  const getSubstitutedArgLevelParams = (source: Map<string, ArgLevelParam>, substs: Subst[]) => {
182
182
  const result = new Map<string, ArgLevelParam>();
183
183
  source.forEach((argLevelParam, key) => {
184
- const expr = getSubstitute(argLevelParam.op, substs);
185
- if (expr === undefined) {
184
+ const substitute = getSubstitute(argLevelParam.op, substs);
185
+ if (substitute === undefined) {
186
186
  result.set(key, argLevelParam);
187
187
  return;
188
188
  }
189
- if (expr.kind !== "OpArg" || !isParam(expr.op)) return;
190
- const operator = expr.op;
189
+ if (substitute.kind !== "OpArg" || !isParam(substitute.op)) return;
190
+ const operator = substitute.op;
191
191
  getSubstitutedParams(argLevelParam.param, substs, false).forEach((param) =>
192
192
  addArgLevelParam(result, operator, argLevelParam.index, param),
193
193
  );
@@ -224,10 +224,10 @@ const getSubstitutedLevelConstraints = (
224
224
  );
225
225
  });
226
226
  body.argLevelParams.forEach((argLevelParam) => {
227
- const expr = getSubstitute(argLevelParam.op, substs);
228
- if (expr?.kind !== "OpArg" || expr.op.kind !== "OpDef") return;
229
- checkLevel(expr.op, iteration, check);
230
- const level = getMaxLevel(expr.op, argLevelParam.index);
227
+ const substitute = getSubstitute(argLevelParam.op, substs);
228
+ if (substitute?.kind !== "OpArg" || substitute.op.kind !== "OpDef") return;
229
+ checkLevel(substitute.op, iteration, check);
230
+ const level = getMaxLevel(substitute.op, argLevelParam.index);
231
231
  getSubstitutedParams(argLevelParam.param, substs, false).forEach((substituted) =>
232
232
  putLevelConstraint(result, substituted, level),
233
233
  );
@@ -244,22 +244,26 @@ const getSubstitutedArgLevelConstraints = (
244
244
  ) => {
245
245
  const result = new Map<string, ArgLevelConstraint>();
246
246
  body.argLevelConstraints.forEach((constraint) => {
247
- const expr = getSubstitute(constraint.param, substs);
248
- if (expr === undefined) {
247
+ const substitute = getSubstitute(constraint.param, substs);
248
+ if (substitute === undefined) {
249
249
  putArgLevelConstraint(result, constraint.param, constraint.position, constraint.level);
250
- } else if (expr.kind === "OpArg" && isParam(expr.op)) {
251
- putArgLevelConstraint(result, expr.op, constraint.position, constraint.level);
250
+ } else if (substitute.kind === "OpArg" && isParam(substitute.op)) {
251
+ putArgLevelConstraint(result, substitute.op, constraint.position, constraint.level);
252
252
  }
253
253
  });
254
254
  body.argLevelParams.forEach((argLevelParam) => {
255
- const paramExpr = getSubstitute(argLevelParam.param, substs);
256
- if (paramExpr === undefined) return;
257
- const opExpr = getSubstitute(argLevelParam.op, substs);
255
+ const paramSubstitute = getSubstitute(argLevelParam.param, substs);
256
+ if (paramSubstitute === undefined) return;
257
+ const operatorSubstitute = getSubstitute(argLevelParam.op, substs);
258
258
  const operator =
259
- opExpr === undefined ? argLevelParam.op : opExpr.kind === "OpArg" ? opExpr.op : undefined;
259
+ operatorSubstitute === undefined
260
+ ? argLevelParam.op
261
+ : operatorSubstitute.kind === "OpArg"
262
+ ? operatorSubstitute.op
263
+ : undefined;
260
264
  if (operator === undefined || !isParam(operator)) return;
261
- checkLevel(paramExpr, iteration, check);
262
- putArgLevelConstraint(result, operator, argLevelParam.index, paramExpr.level);
265
+ checkLevel(paramSubstitute, iteration, check);
266
+ putArgLevelConstraint(result, operator, argLevelParam.index, paramSubstitute.level);
263
267
  });
264
268
  return result;
265
269
  };
@@ -836,26 +840,6 @@ const checkTemporalProof = (proof: ProofNode | undefined, check: LevelCheck) =>
836
840
  });
837
841
  };
838
842
 
839
- // Subst.getSubLCSet, getSubALCSet and getSubALPSet for the body of an instantiation.
840
- const constrainSubstitution = (
841
- node: LevelFields,
842
- body: ConstraintSource,
843
- substs: Subst[],
844
- isConstant: boolean,
845
- iteration: number,
846
- check: LevelCheck,
847
- ) => {
848
- node.levelConstraints = getSubstitutedLevelConstraints(
849
- body,
850
- substs,
851
- isConstant,
852
- iteration,
853
- check,
854
- );
855
- node.argLevelConstraints = getSubstitutedArgLevelConstraints(body, substs, iteration, check);
856
- node.argLevelParams = getSubstitutedArgLevelParams(body.argLevelParams, substs);
857
- };
858
-
859
843
  // InstanceNode.levelCheck.
860
844
  const checkInstance = (node: InstanceNode, iteration: number, check: LevelCheck) => {
861
845
  if (node.levelChecked >= iteration) return node.levelCorrect;
@@ -1114,7 +1098,20 @@ const checkLevel = (node: SemanticNode, iteration: number, check: LevelCheck): b
1114
1098
  });
1115
1099
  }
1116
1100
  const isConstant = isConstantModule(node.instantiatedModule, check);
1117
- constrainSubstitution(node, body, node.substs, isConstant, iteration, check);
1101
+ node.levelConstraints = getSubstitutedLevelConstraints(
1102
+ body,
1103
+ node.substs,
1104
+ isConstant,
1105
+ iteration,
1106
+ check,
1107
+ );
1108
+ node.argLevelConstraints = getSubstitutedArgLevelConstraints(
1109
+ body,
1110
+ node.substs,
1111
+ iteration,
1112
+ check,
1113
+ );
1114
+ node.argLevelParams = getSubstitutedArgLevelParams(body.argLevelParams, node.substs);
1118
1115
  return node.levelCorrect;
1119
1116
  }
1120
1117
  case "Instance":
@@ -1,4 +1,4 @@
1
- import { TlaError } from "./errors";
1
+ import { TlaError } from "../errors";
2
2
 
3
3
  // An emulation of the token manager that JavaCC generates for SANY's grammar, javacc/tla+.jj: the
4
4
  // tokens it produces, their kinds in TLAplusParserConstants order, and their positions.
@@ -228,8 +228,7 @@ const KIND_INDEXES = new Map(
228
228
  KIND_NAMES.map((name, kind): [string, number] => [name, kind]).reverse(),
229
229
  );
230
230
 
231
- // The kind named name. The anonymous infix operators share the name "infix", which no caller
232
- // looks up.
231
+ // The anonymous infix operators share the name "infix", which no caller looks up.
233
232
  export const getKind = (name: string) => {
234
233
  const kind = KIND_INDEXES.get(name);
235
234
  if (kind === undefined) throw new TlaError(`Unknown SANY token kind ${name}`);
@@ -5,7 +5,7 @@ import {
5
5
  type OpApplNode,
6
6
  type SanyMessage,
7
7
  type SemanticNode,
8
- } from "./sany-nodes";
8
+ } from "./nodes";
9
9
 
10
10
  // A port of SANY's tla2sany.linter.Linter, which warns about a record field named like a
11
11
  // definition or declaration of the module.
@@ -1,5 +1,5 @@
1
- import type { TlcVersion } from "./tlc-version";
2
- import { REAL_TIME, REALS, TOOLBOX } from "./bundled-modules";
1
+ import type { TlcVersion } from "../tlc/version";
2
+ import { REAL_TIME, REALS, TOOLBOX } from "../bundled-modules";
3
3
 
4
4
  const BAGS = `----------------------------- MODULE Bags --------------------------------
5
5
  (**************************************************************************)
@@ -344,7 +344,7 @@ export type LevelNode = ExprOrOpArgNode | AssumeProveNode | NewSymbNode;
344
344
 
345
345
  export type ProofPartNode = ProofNode | DefStepNode;
346
346
 
347
- export type TopLevelNode = InstanceNode | AssumeNode | TheoremNode | UseOrHideNode;
347
+ type TopLevelNode = InstanceNode | AssumeNode | TheoremNode | UseOrHideNode;
348
348
 
349
349
  export type SemanticNode = SymbolNode | LevelNode | TopLevelNode | ProofPartNode;
350
350
 
@@ -362,7 +362,7 @@ interface HashtableEntry {
362
362
  value: SymbolNode;
363
363
  }
364
364
 
365
- export interface JavaHashtable {
365
+ interface JavaHashtable {
366
366
  buckets: HashtableEntry[][];
367
367
  count: number;
368
368
  threshold: number;
@@ -1,5 +1,5 @@
1
- import { createSanyLexer, escapeLexeme, getKind, type SanyToken } from "./sany-lexer";
2
- import { SANY_OPERATOR_SYNONYMS } from "./tlc-modules";
1
+ import { createSanyLexer, escapeLexeme, getKind, type SanyToken } from "./lexer";
2
+ import { SANY_OPERATOR_SYNONYMS } from "../tlc/jar-data";
3
3
 
4
4
  // The report SANY's parser, TLAplusParser, gives for a module it fails to parse. This interprets
5
5
  // the grammar of javacc/tla+.jj the way the code JavaCC generates from it runs: the productions,
@@ -1,21 +1,21 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { basename } from "node:path";
3
- import type { Module } from "./ast";
4
- import { TlaSyntaxError, PcalRuntimeError, TlaSanyFatalError } from "./errors";
5
- import { extractModule, parseSanyModule } from "./parser";
6
- import { createPcalParams } from "./pcal-ast";
7
- import { createPcalSession } from "./pcal-parse";
8
- import { validatePcalModule } from "./pcal-validate";
9
- import { generateSanySpecification, type SanySpecification } from "./sany-generator";
10
- import { checkModuleLevels } from "./sany-levels";
11
- import { getSany174LexicalError } from "./sany-lexer";
12
- import { lintSanyModule } from "./sany-linter";
13
- import { getSanyStandardModules } from "./sany-modules";
14
- import { formatSanyLocation, type SanyMessage } from "./sany-nodes";
15
- import { getUnboxedSource } from "./sany-source";
16
- import type { TlcVersion } from "./tlc-version";
3
+ import type { Module } from "../ast";
4
+ import { TlaSyntaxError, PcalRuntimeError, TlaSanyFatalError } from "../errors";
5
+ import { extractModule, parseSanyModule } from "../parser";
6
+ import { createPcalParams } from "../pcal/ast";
7
+ import { createPcalSession } from "../pcal/parse";
8
+ import { validatePcalModule } from "../pcal/validate";
9
+ import { generateSanySpecification, type SanySpecification } from "./generator";
10
+ import { checkModuleLevels } from "./levels";
11
+ import { getSany174LexicalError } from "./lexer";
12
+ import { lintSanyModule } from "./linter";
13
+ import { getSanyStandardModules } from "./modules";
14
+ import { formatSanyLocation, type SanyMessage } from "./nodes";
15
+ import { getUnboxedSource } from "./source";
16
+ import type { TlcVersion } from "../tlc/version";
17
17
 
18
- export interface SanyReport {
18
+ interface SanyReport {
19
19
  text: string;
20
20
  isFailed: boolean;
21
21
  // The specification SANY analyzes, which has errors when SANY rejects it.
@@ -35,7 +35,6 @@ export interface SanyReportOptions {
35
35
  // tla2sany.xml.XMLExporter runs SANY with its validAstSettings, which neither lint the modules
36
36
  // nor validate their PlusCal, and prints only SANY's errors.
37
37
  isXmlExport?: boolean;
38
- // The TLC whose SANY to reproduce.
39
38
  version?: TlcVersion;
40
39
  // The modules TLC adds to the root module's EXTENDS for its post conditions.
41
40
  rootExtendees?: string[];
@@ -119,7 +118,7 @@ export const getSanyModuleName = (text: string, version?: TlcVersion) =>
119
118
  // in the rest.
120
119
  export const getSanyReport = (
121
120
  rootPath: string,
122
- loadModule: (name: string) => string | undefined = () => undefined,
121
+ loadModule: (name: string) => string | undefined,
123
122
  options: SanyReportOptions = {},
124
123
  ): SanyReport => {
125
124
  const rootName = basename(rootPath, ".tla");