tla-ts 0.0.3 → 0.0.4-dev.2a873ee

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 (370) hide show
  1. package/README.md +46 -115
  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 +194 -8
  8. package/dist/index.d.ts +194 -8
  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 +996 -0
  17. package/dist/prove.js +996 -0
  18. package/dist/run-cli.cjs +37 -20
  19. package/dist/run-cli.js +37 -20
  20. package/dist/tlapm.cjs +10 -0
  21. package/dist/tlapm.js +10 -0
  22. package/dist/transfer.cjs +1387 -18
  23. package/dist/transfer.js +1387 -18
  24. package/dist/worker.cjs +21 -0
  25. package/dist/worker.js +21 -0
  26. package/package.json +24 -11
  27. package/src/ast.ts +149 -8
  28. package/src/bags.ts +4 -7
  29. package/src/builtins.ts +29 -11
  30. package/src/bundled-modules.ts +3 -3
  31. package/src/canonical.ts +4 -3
  32. package/src/check.ts +1540 -235
  33. package/src/cli-options.ts +12 -6
  34. package/src/cli.ts +8 -1
  35. package/src/codegen.ts +98 -39
  36. package/src/config.ts +254 -181
  37. package/src/dependencies.ts +2 -2
  38. package/src/environment.ts +540 -140
  39. package/src/errors.ts +284 -4
  40. package/src/evaluate.ts +1043 -293
  41. package/src/exit-codes.ts +22 -43
  42. package/src/fingerprints.ts +46 -11
  43. package/src/index.ts +11 -0
  44. package/src/instances.ts +19 -16
  45. package/src/java-overrides.ts +104 -25
  46. package/src/levels.ts +191 -45
  47. package/src/lexer.ts +127 -30
  48. package/src/live-check.ts +867 -0
  49. package/src/liveness.ts +218 -572
  50. package/src/{obligation-action.ts → obligations/action.ts} +247 -69
  51. package/src/{obligation-anon.ts → obligations/anon.ts} +49 -47
  52. package/src/obligations/ctx.ts +64 -0
  53. package/src/{obligation-deref.ts → obligations/deref.ts} +51 -92
  54. package/src/{obligation-expression.ts → obligations/expression.ts} +117 -57
  55. package/src/{obligation-format.ts → obligations/format.ts} +7 -8
  56. package/src/{obligation-generate.ts → obligations/generate.ts} +170 -192
  57. package/src/{obligations.ts → obligations/index.ts} +32 -16
  58. package/src/{obligation-levels.ts → obligations/levels.ts} +26 -28
  59. package/src/{obligation-module.ts → obligations/module.ts} +113 -121
  60. package/src/obligations/pickle.ts +98 -0
  61. package/src/obligations/pragma.ts +189 -0
  62. package/src/{obligation-printer.ts → obligations/printer.ts} +22 -80
  63. package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
  64. package/src/{obligation-source.ts → obligations/source.ts} +156 -99
  65. package/src/obligations/temporal.ts +321 -0
  66. package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
  67. package/src/ocaml-marshal.ts +166 -0
  68. package/src/parallel-worker.ts +169 -224
  69. package/src/parallel.ts +140 -81
  70. package/src/parser.ts +456 -147
  71. package/src/pcal-ast.ts +770 -0
  72. package/src/pcal-parse.ts +1523 -0
  73. package/src/pcal-tokenize.ts +516 -0
  74. package/src/pcal-translate.ts +1230 -0
  75. package/src/pcal-validate.ts +454 -0
  76. package/src/prove/decide-pool.ts +95 -0
  77. package/src/prove/deciders.ts +33 -0
  78. package/src/prove/first-order.ts +78 -0
  79. package/src/prove/isabelle/LICENSE +36 -0
  80. package/src/prove/isabelle/LICENSE-tlapm +26 -0
  81. package/src/prove/isabelle/decide.ts +47 -0
  82. package/src/prove/isabelle/encode.ts +446 -0
  83. package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
  84. package/src/prove/isabelle/isar/method.ts +367 -0
  85. package/src/prove/isabelle/isar/proof.ts +28 -0
  86. package/src/prove/isabelle/isar/statement.ts +57 -0
  87. package/src/prove/isabelle/isar/theory.ts +192 -0
  88. package/src/prove/isabelle/isar/type-check.ts +278 -0
  89. package/src/prove/isabelle/provers/blast/blast.ts +258 -0
  90. package/src/prove/isabelle/provers/blast/branch.ts +322 -0
  91. package/src/prove/isabelle/provers/blast/prove.ts +347 -0
  92. package/src/prove/isabelle/provers/blast/rules.ts +330 -0
  93. package/src/prove/isabelle/provers/blast/state.ts +180 -0
  94. package/src/prove/isabelle/provers/blast/term.ts +546 -0
  95. package/src/prove/isabelle/provers/clasimp.ts +150 -0
  96. package/src/prove/isabelle/provers/classical.ts +389 -0
  97. package/src/prove/isabelle/provers/hypsubst.ts +433 -0
  98. package/src/prove/isabelle/pure/bicompose.ts +174 -0
  99. package/src/prove/isabelle/pure/consts.ts +32 -0
  100. package/src/prove/isabelle/pure/conv.ts +79 -0
  101. package/src/prove/isabelle/pure/drule.ts +264 -0
  102. package/src/prove/isabelle/pure/envir.ts +331 -0
  103. package/src/prove/isabelle/pure/goal.ts +53 -0
  104. package/src/prove/isabelle/pure/interrupt.ts +16 -0
  105. package/src/prove/isabelle/pure/list.ts +12 -0
  106. package/src/prove/isabelle/pure/logic.ts +330 -0
  107. package/src/prove/isabelle/pure/name.ts +98 -0
  108. package/src/prove/isabelle/pure/net.ts +215 -0
  109. package/src/prove/isabelle/pure/object-logic.ts +41 -0
  110. package/src/prove/isabelle/pure/pattern.ts +631 -0
  111. package/src/prove/isabelle/pure/raw-simplifier.ts +338 -0
  112. package/src/prove/isabelle/pure/rewriter.ts +602 -0
  113. package/src/prove/isabelle/pure/search.ts +68 -0
  114. package/src/prove/isabelle/pure/seq.ts +133 -0
  115. package/src/prove/isabelle/pure/simplifier.ts +106 -0
  116. package/src/prove/isabelle/pure/table.ts +201 -0
  117. package/src/prove/isabelle/pure/tactic.ts +168 -0
  118. package/src/prove/isabelle/pure/tactical.ts +264 -0
  119. package/src/prove/isabelle/pure/term-ord.ts +105 -0
  120. package/src/prove/isabelle/pure/term.ts +688 -0
  121. package/src/prove/isabelle/pure/thm.ts +783 -0
  122. package/src/prove/isabelle/pure/type.ts +121 -0
  123. package/src/prove/isabelle/pure/unify.ts +753 -0
  124. package/src/prove/isabelle/pure/variable.ts +25 -0
  125. package/src/prove/isabelle/tla/classical-setup.ts +101 -0
  126. package/src/prove/isabelle/tla/context.ts +74 -0
  127. package/src/prove/isabelle/tla/logic-data.ts +5 -0
  128. package/src/prove/isabelle/tla/logic.ts +215 -0
  129. package/src/prove/isabelle/tla/simpdata.ts +241 -0
  130. package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
  131. package/src/prove/ocaml.ts +22 -0
  132. package/src/prove/prep/action.ts +508 -0
  133. package/src/prove/prep/defs.ts +33 -0
  134. package/src/prove/prep/elab.ts +156 -0
  135. package/src/prove/prep/enabled-axioms.ts +189 -0
  136. package/src/prove/prep/enabled.ts +43 -0
  137. package/src/prove/prep/fingerprint.ts +388 -0
  138. package/src/prove/prep/flatten.ts +70 -0
  139. package/src/prove/prep/level-comparison.ts +529 -0
  140. package/src/prove/prep/md5.ts +67 -0
  141. package/src/prove/prep/pragma.ts +221 -0
  142. package/src/prove/prep/trivial.ts +22 -0
  143. package/src/prove/prove-worker.ts +22 -0
  144. package/src/prove/prove.ts +498 -0
  145. package/src/prove/ptl/decide.ts +68 -0
  146. package/src/prove/ptl/encode.ts +255 -0
  147. package/src/prove/ptl/sat.ts +151 -0
  148. package/src/prove/ptl/tableau.ts +276 -0
  149. package/src/prove/smt/axiomatize.ts +69 -0
  150. package/src/prove/smt/axioms.ts +209 -0
  151. package/src/prove/smt/context.ts +108 -0
  152. package/src/prove/smt/data.ts +636 -0
  153. package/src/prove/smt/encode.ts +164 -0
  154. package/src/prove/smt/extensionality.ts +65 -0
  155. package/src/prove/smt/flatten.ts +112 -0
  156. package/src/prove/smt/format.ts +154 -0
  157. package/src/prove/smt/instances.ts +181 -0
  158. package/src/prove/smt/rewrite.ts +772 -0
  159. package/src/prove/smt/simplify.ts +57 -0
  160. package/src/prove/smt/solver/act-cache.ts +265 -0
  161. package/src/prove/smt/solver/arith-rewriter.ts +962 -0
  162. package/src/prove/smt/solver/array.ts +22 -0
  163. package/src/prove/smt/solver/asserted-formulas.ts +469 -0
  164. package/src/prove/smt/solver/ast-lt.ts +157 -0
  165. package/src/prove/smt/solver/ast-util.ts +91 -0
  166. package/src/prove/smt/solver/ast.ts +1315 -0
  167. package/src/prove/smt/solver/auf-solver.ts +572 -0
  168. package/src/prove/smt/solver/case-split-queue.ts +178 -0
  169. package/src/prove/smt/solver/cg-table.ts +175 -0
  170. package/src/prove/smt/solver/clause.ts +276 -0
  171. package/src/prove/smt/solver/conflict-resolution.ts +343 -0
  172. package/src/prove/smt/solver/context.ts +1292 -0
  173. package/src/prove/smt/solver/ctx-simplify.ts +334 -0
  174. package/src/prove/smt/solver/der.ts +224 -0
  175. package/src/prove/smt/solver/dyn-ack.ts +141 -0
  176. package/src/prove/smt/solver/e-matching.ts +659 -0
  177. package/src/prove/smt/solver/enode.ts +259 -0
  178. package/src/prove/smt/solver/expr-ref.ts +21 -0
  179. package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
  180. package/src/prove/smt/solver/fingerprints.ts +92 -0
  181. package/src/prove/smt/solver/flat-literals.ts +51 -0
  182. package/src/prove/smt/solver/goal.ts +138 -0
  183. package/src/prove/smt/solver/hash.ts +173 -0
  184. package/src/prove/smt/solver/hashtable.ts +166 -0
  185. package/src/prove/smt/solver/internalizer.ts +1381 -0
  186. package/src/prove/smt/solver/lbool.ts +5 -0
  187. package/src/prove/smt/solver/literal.ts +24 -0
  188. package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
  189. package/src/prove/smt/solver/lp/constraints.ts +78 -0
  190. package/src/prove/smt/solver/lp/containers.ts +296 -0
  191. package/src/prove/smt/solver/lp/core-solver.ts +504 -0
  192. package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
  193. package/src/prove/smt/solver/lp/dep-intervals.ts +642 -0
  194. package/src/prove/smt/solver/lp/dependency.ts +51 -0
  195. package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
  196. package/src/prove/smt/solver/lp/explanation.ts +46 -0
  197. package/src/prove/smt/solver/lp/gomory.ts +255 -0
  198. package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
  199. package/src/prove/smt/solver/lp/hnf.ts +281 -0
  200. package/src/prove/smt/solver/lp/int-cube.ts +295 -0
  201. package/src/prove/smt/solver/lp/int-solver.ts +514 -0
  202. package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
  203. package/src/prove/smt/solver/lp/lar-term.ts +62 -0
  204. package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
  205. package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
  206. package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
  207. package/src/prove/smt/solver/lp/nex.ts +120 -0
  208. package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
  209. package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
  210. package/src/prove/smt/solver/lp/nla-core.ts +968 -0
  211. package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
  212. package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
  213. package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
  214. package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
  215. package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
  216. package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
  217. package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
  218. package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
  219. package/src/prove/smt/solver/lp/nla-order.ts +307 -0
  220. package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
  221. package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
  222. package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
  223. package/src/prove/smt/solver/lp/nla-types.ts +124 -0
  224. package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
  225. package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
  226. package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
  227. package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
  228. package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
  229. package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
  230. package/src/prove/smt/solver/lp/pdd.ts +971 -0
  231. package/src/prove/smt/solver/lp/random-updater.ts +138 -0
  232. package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
  233. package/src/prove/smt/solver/lp/union-find.ts +96 -0
  234. package/src/prove/smt/solver/mam-compiler.ts +847 -0
  235. package/src/prove/smt/solver/mam-interpreter.ts +400 -0
  236. package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
  237. package/src/prove/smt/solver/model-checker.ts +347 -0
  238. package/src/prove/smt/solver/model-evaluator.ts +262 -0
  239. package/src/prove/smt/solver/model-finder.ts +155 -0
  240. package/src/prove/smt/solver/model-generator.ts +97 -0
  241. package/src/prove/smt/solver/model-macro-solver.ts +728 -0
  242. package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
  243. package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
  244. package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
  245. package/src/prove/smt/solver/nlsat/explain.ts +607 -0
  246. package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
  247. package/src/prove/smt/solver/nlsat/levelwise.ts +737 -0
  248. package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
  249. package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
  250. package/src/prove/smt/solver/nlsat/solver.ts +911 -0
  251. package/src/prove/smt/solver/nlsat/types.ts +43 -0
  252. package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
  253. package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
  254. package/src/prove/smt/solver/nnf.ts +469 -0
  255. package/src/prove/smt/solver/pattern-inference.ts +351 -0
  256. package/src/prove/smt/solver/poly-rewriter.ts +477 -0
  257. package/src/prove/smt/solver/propagate-values.ts +83 -0
  258. package/src/prove/smt/solver/proto-model.ts +551 -0
  259. package/src/prove/smt/solver/pull-quant.ts +139 -0
  260. package/src/prove/smt/solver/qe-lite-der.ts +526 -0
  261. package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
  262. package/src/prove/smt/solver/qe-lite.ts +381 -0
  263. package/src/prove/smt/solver/qi-queue.ts +362 -0
  264. package/src/prove/smt/solver/quant-tactics.ts +117 -0
  265. package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
  266. package/src/prove/smt/solver/quantifier-manager.ts +186 -0
  267. package/src/prove/smt/solver/random-gen.ts +10 -0
  268. package/src/prove/smt/solver/rational.ts +165 -0
  269. package/src/prove/smt/solver/ref-vector.ts +62 -0
  270. package/src/prove/smt/solver/relevancy.ts +247 -0
  271. package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
  272. package/src/prove/smt/solver/rewriter.ts +843 -0
  273. package/src/prove/smt/solver/rlimit.ts +79 -0
  274. package/src/prove/smt/solver/smtlib-parser.ts +526 -0
  275. package/src/prove/smt/solver/solver.ts +71 -0
  276. package/src/prove/smt/solver/sort.ts +35 -0
  277. package/src/prove/smt/solver/sticky-generations.ts +69 -0
  278. package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
  279. package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
  280. package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
  281. package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
  282. package/src/prove/smt/solver/theory-lra-model.ts +243 -0
  283. package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
  284. package/src/prove/smt/solver/theory-lra-state.ts +43 -0
  285. package/src/prove/smt/solver/theory-lra.ts +56 -0
  286. package/src/prove/smt/solver/var-subst.ts +258 -0
  287. package/src/prove/smt/solver/z3-license.txt +10 -0
  288. package/src/prove/smt/table.ts +170 -0
  289. package/src/prove/tlapm/tlapm.ts +96 -0
  290. package/src/prove/tlaps-module.ts +510 -0
  291. package/src/prove/verdict.ts +18 -0
  292. package/src/prove/zenon/LICENSE +32 -0
  293. package/src/prove/zenon/check/check.ts +105 -0
  294. package/src/prove/zenon/check/definitions.ts +144 -0
  295. package/src/prove/zenon/check/equality.ts +182 -0
  296. package/src/prove/zenon/check/functions.ts +62 -0
  297. package/src/prove/zenon/check/keys.ts +125 -0
  298. package/src/prove/zenon/check/propositional.ts +104 -0
  299. package/src/prove/zenon/check/records.ts +188 -0
  300. package/src/prove/zenon/check/relations.ts +121 -0
  301. package/src/prove/zenon/check/rewrites.ts +224 -0
  302. package/src/prove/zenon/check/sets.ts +302 -0
  303. package/src/prove/zenon/check/terms.ts +127 -0
  304. package/src/prove/zenon/check/tla.ts +126 -0
  305. package/src/prove/zenon/decide.ts +113 -0
  306. package/src/prove/zenon/encode.ts +379 -0
  307. package/src/prove/zenon/eqrel.ts +300 -0
  308. package/src/prove/zenon/equality-rules.ts +435 -0
  309. package/src/prove/zenon/expr.ts +551 -0
  310. package/src/prove/zenon/index-table.ts +350 -0
  311. package/src/prove/zenon/isar-case.ts +513 -0
  312. package/src/prove/zenon/isar.ts +1249 -0
  313. package/src/prove/zenon/limits.ts +15 -0
  314. package/src/prove/zenon/llproof.ts +173 -0
  315. package/src/prove/zenon/mltoll.ts +1566 -0
  316. package/src/prove/zenon/node.ts +297 -0
  317. package/src/prove/zenon/ocaml.ts +169 -0
  318. package/src/prove/zenon/parse.ts +247 -0
  319. package/src/prove/zenon/phrase.ts +191 -0
  320. package/src/prove/zenon/proof.ts +198 -0
  321. package/src/prove/zenon/propositional-rules.ts +387 -0
  322. package/src/prove/zenon/rules.ts +94 -0
  323. package/src/prove/zenon/search.ts +288 -0
  324. package/src/prove/zenon/tla/functions.ts +151 -0
  325. package/src/prove/zenon/tla/llproof.ts +480 -0
  326. package/src/prove/zenon/tla/records.ts +225 -0
  327. package/src/prove/zenon/tla/rewrites.ts +447 -0
  328. package/src/prove/zenon/tla/sets.ts +304 -0
  329. package/src/prove/zenon/tla/terms.ts +162 -0
  330. package/src/prove/zenon/tla/tla.ts +506 -0
  331. package/src/randomization.ts +24 -7
  332. package/src/resolve.ts +1481 -426
  333. package/src/run-cli.ts +1483 -212
  334. package/src/runtime.ts +19 -1
  335. package/src/sany-builtins.ts +147 -0
  336. package/src/sany-generator.ts +3128 -0
  337. package/src/sany-levels.ts +1208 -0
  338. package/src/sany-lexer.ts +545 -0
  339. package/src/sany-linter.ts +122 -0
  340. package/src/sany-modules.ts +1398 -0
  341. package/src/sany-nodes.ts +463 -0
  342. package/src/sany-parse-error.ts +2161 -0
  343. package/src/sany-report.ts +356 -0
  344. package/src/sany-selectors.ts +738 -0
  345. package/src/sany-source.ts +248 -0
  346. package/src/sany-xml.ts +1017 -0
  347. package/src/spec-description.ts +42 -11
  348. package/src/standard-modules.ts +203 -148
  349. package/src/standard-ranges.ts +116 -0
  350. package/src/state-graph.ts +180 -0
  351. package/src/subexpressions.ts +231 -171
  352. package/src/substitution-levels.ts +38 -17
  353. package/src/successors.ts +241 -110
  354. package/src/symmetry.ts +194 -54
  355. package/src/tableau.ts +54 -25
  356. package/src/tlapm-cache.ts +236 -0
  357. package/src/tlc-ext.ts +42 -29
  358. package/src/tlc-messages.ts +329 -0
  359. package/src/tlc-module.ts +52 -43
  360. package/src/tlc-modules.ts +4 -0
  361. package/src/tlc-order.ts +78 -10
  362. package/src/tlc-random.ts +84 -33
  363. package/src/tlc-replay.ts +655 -0
  364. package/src/tlc-summary.ts +20 -5
  365. package/src/tlc-version.ts +19 -0
  366. package/src/transfer.ts +15 -3
  367. package/src/values.ts +787 -190
  368. package/src/worker.ts +65 -0
  369. package/dist/parallel.cjs +0 -12
  370. package/dist/parallel.js +0 -12
@@ -14,10 +14,11 @@ import type {
14
14
  SourceLocation,
15
15
  SourceRange,
16
16
  UseOrHide,
17
- } from "./ast";
18
- import { TlaProofError, TlaUnsupportedError } from "./errors";
17
+ } from "../ast";
18
+ import { TlaProofError, TlaUnsupportedError } from "../errors";
19
19
  import {
20
20
  at,
21
+ getFact,
21
22
  type Bound,
22
23
  type Builtin,
23
24
  type Defn,
@@ -27,18 +28,18 @@ import {
27
28
  type Locus,
28
29
  type Selector,
29
30
  type Sequent,
30
- } from "./obligation-expression";
31
- import type { ModuleUnit, Mule } from "./obligation-module";
31
+ } from "./expression";
32
+ import type { ModuleUnit, Mule } from "./module";
33
+ import { readNewMethod, readOldMethod } from "./pragma";
32
34
  import {
33
35
  expandChoose,
34
36
  expandFcn,
35
37
  expandQuant,
36
38
  expandSetOf,
37
- expandSetSt,
38
39
  getUnbounded,
39
40
  type TuplyBound,
40
- } from "./obligation-tuples";
41
- import { lookupOperator, type Fixity, type Operator } from "./obligation-printer";
41
+ } from "./tuples";
42
+ import { lookupOperator, type Fixity, type Operator } from "./printer";
42
43
  import {
43
44
  getUnique,
44
45
  type Counter,
@@ -47,7 +48,7 @@ import {
47
48
  type StepNumber,
48
49
  type UseDef,
49
50
  type Usable,
50
- } from "./obligation-proof";
51
+ } from "./proof";
51
52
 
52
53
  const BUILTINS: Record<string, Builtin> = {
53
54
  "=>": "Implies",
@@ -80,9 +81,7 @@ const BUILTINS: Record<string, Builtin> = {
80
81
  STRING: "STRING",
81
82
  };
82
83
 
83
- // Optable maps each spelling to its canonical name, and a prefix minus is the operator -.
84
- const getCanonicalName = (name: string, isPrefix = false) =>
85
- isPrefix && name === "-" ? "-." : lookupOperator(name).name;
84
+ const getCanonicalName = (name: string) => lookupOperator(name).name;
86
85
 
87
86
  const STEP_PATTERN = /^<(\d+|\*|\+)>([A-Za-z0-9_]*)\.*$/;
88
87
 
@@ -202,6 +201,9 @@ const regroup = (expression: Extract<Expression, { kind: "Apply" }>): Expression
202
201
 
203
202
  const TUPLY_FAILURE = "use instead the class`E_visit.iter_concrete`";
204
203
 
204
+ const isDitto = (bounds: QuantifierExpression["bounds"], index: number) =>
205
+ index > 0 && bounds[index - 1].set === bounds[index].set;
206
+
205
207
  export const createSource = (file: string, text: string, counter: Counter, isExpanded: boolean) => {
206
208
  const lines = text.split("\n");
207
209
 
@@ -231,24 +233,32 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
231
233
  return locus;
232
234
  };
233
235
 
234
- const getNameLocus = (name: string, location: SourceLocation): Locus => ({
236
+ const getMethod = (range: SourceRange | undefined) =>
237
+ range && readOldMethod(lines, { line: range.end.line - 1, column: range.end.column });
238
+
239
+ // A method pragma belongs to the node it follows, whose locus then takes it in.
240
+ const withMethod = (range: SourceRange) => {
241
+ const method = getMethod(range);
242
+ const location = getRangeLocus(range);
243
+ return method ? { location: withPragma(location), method } : { location };
244
+ };
245
+
246
+ // Module.Parser's with_meth, which wraps the expression a method follows.
247
+ const withExpressionMethod = (expression: Expr, range: SourceRange | undefined): Expr => {
248
+ const method = getMethod(range);
249
+ return method ? at({ kind: "With", expression, method }, expression) : expression;
250
+ };
251
+
252
+ const getPointLocus = (location: SourceLocation, length: number): Locus => ({
235
253
  file,
236
254
  startLine: location.line,
237
255
  startColumn: location.column,
238
256
  endLine: location.line,
239
- endColumn: location.column + name.length,
257
+ endColumn: location.column + length,
240
258
  });
241
259
 
242
260
  const getLocus = (location: SourceLocation): Locus =>
243
- location.range
244
- ? getRangeLocus(location.range)
245
- : {
246
- file,
247
- startLine: location.line,
248
- startColumn: location.column,
249
- endLine: location.line,
250
- endColumn: location.column + 1,
251
- };
261
+ location.range ? getRangeLocus(location.range) : getPointLocus(location, 1);
252
262
 
253
263
  const getOperator = (name: string, location: Locus | undefined): Expr => {
254
264
  const canonical = getCanonicalName(name);
@@ -304,11 +314,10 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
304
314
  bounds.map((bound, index) => {
305
315
  if (bound.pattern.kind === "Tuple")
306
316
  throw new TlaProofError("Unexpected tuple declaration", { failure: TUPLY_FAILURE });
307
- const isDitto = index > 0 && bounds[index - 1].set === bound.set;
308
317
  return {
309
318
  name: bound.pattern.name,
310
319
  level: "Constant",
311
- domain: isDitto
320
+ domain: isDitto(bounds, index)
312
321
  ? { kind: "Ditto" }
313
322
  : { kind: "Domain", expression: convertExpression(bound.set, isExcept) },
314
323
  };
@@ -322,18 +331,17 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
322
331
  const domain = convertExpression(bound.set, isExcept);
323
332
  if (bound.pattern.kind === "Tuple")
324
333
  return { kind: "Tuple", names: bound.pattern.names, domain };
325
- const isDitto = index > 0 && bounds[index - 1].set === bound.set;
326
334
  return {
327
335
  kind: "Name",
328
336
  name: bound.pattern.name,
329
- domain: isDitto ? { kind: "Ditto" } : { kind: "Domain", expression: domain },
337
+ domain: isDitto(bounds, index) ? { kind: "Ditto" } : { kind: "Domain", expression: domain },
330
338
  };
331
339
  });
332
340
 
333
- const expandTuples = (expand: () => Expr, location: Locus) => {
341
+ const expandTuples = (expanded: Expr, location: Locus) => {
334
342
  if (!isExpanded)
335
343
  throw new TlaProofError("Unexpected tuple declaration", { failure: TUPLY_FAILURE });
336
- return at(expand(), { location });
344
+ return at(expanded, { location });
337
345
  };
338
346
 
339
347
  const hasTuple = (bounds: QuantifierExpression["bounds"]) =>
@@ -376,8 +384,14 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
376
384
  const [integer, fraction] = expression.text.split(".");
377
385
  return at({ kind: "Num", integer, fraction }, { location });
378
386
  }
379
- case "String":
380
- return at({ kind: "String", value: expression.value }, { location });
387
+ case "String": {
388
+ // tlapm's lexer keeps a string's escapes as written. The location ends at the closing
389
+ // quote.
390
+ const written = /"((?:[^"\\]|\\.)*)"$/.exec(
391
+ (lines[location.endLine - 1] ?? "").slice(0, location.endColumn - 1),
392
+ );
393
+ return at({ kind: "String", value: written?.[1] ?? expression.value }, { location });
394
+ }
381
395
  case "Identifier":
382
396
  return getName(expression.name, [], location);
383
397
  case "Apply": {
@@ -470,9 +484,14 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
470
484
  case "Forall":
471
485
  case "Exists":
472
486
  if (hasTuple(expression.bounds)) {
473
- const bounds = getTuplyBounds(expression.bounds, isExcept);
474
- const body = recurse(expression.body);
475
- return expandTuples(() => expandQuant(expression.kind, bounds, body), location);
487
+ return expandTuples(
488
+ expandQuant(
489
+ expression.kind,
490
+ getTuplyBounds(expression.bounds, isExcept),
491
+ recurse(expression.body),
492
+ ),
493
+ location,
494
+ );
476
495
  }
477
496
  return at(
478
497
  {
@@ -495,10 +514,14 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
495
514
  }
496
515
  case "Choose":
497
516
  if (expression.pattern.kind === "Tuple") {
498
- const names = expression.pattern.names;
499
- const domain = expression.set && recurse(expression.set);
500
- const body = recurse(expression.body);
501
- return expandTuples(() => expandChoose(names, domain, body), location);
517
+ return expandTuples(
518
+ expandChoose(
519
+ { kind: "Choose", domain: expression.set && recurse(expression.set) },
520
+ expression.pattern.names,
521
+ recurse(expression.body),
522
+ ),
523
+ location,
524
+ );
502
525
  }
503
526
  return at(
504
527
  {
@@ -513,10 +536,14 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
513
536
  return at({ kind: "SetEnum", elements: expression.elements.map(recurse) }, { location });
514
537
  case "SetFilter":
515
538
  if (expression.bound.pattern.kind === "Tuple") {
516
- const names = expression.bound.pattern.names;
517
- const domain = recurse(expression.bound.set);
518
- const body = recurse(expression.predicate);
519
- return expandTuples(() => expandSetSt(names, domain, body), location);
539
+ return expandTuples(
540
+ expandChoose(
541
+ { kind: "SetSt", domain: recurse(expression.bound.set) },
542
+ expression.bound.pattern.names,
543
+ recurse(expression.predicate),
544
+ ),
545
+ location,
546
+ );
520
547
  }
521
548
  return at(
522
549
  {
@@ -529,9 +556,13 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
529
556
  );
530
557
  case "SetMap":
531
558
  if (hasTuple(expression.bounds)) {
532
- const element = recurse(expression.expression);
533
- const bounds = getTuplyBounds(expression.bounds, isExcept);
534
- return expandTuples(() => expandSetOf(element, bounds), location);
559
+ return expandTuples(
560
+ expandSetOf(
561
+ recurse(expression.expression),
562
+ getTuplyBounds(expression.bounds, isExcept),
563
+ ),
564
+ location,
565
+ );
535
566
  }
536
567
  return at(
537
568
  {
@@ -556,9 +587,10 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
556
587
  );
557
588
  case "FunctionConstruction":
558
589
  if (hasTuple(expression.bounds)) {
559
- const bounds = getTuplyBounds(expression.bounds, isExcept);
560
- const body = recurse(expression.body);
561
- return expandTuples(() => expandFcn(bounds, body), location);
590
+ return expandTuples(
591
+ expandFcn(getTuplyBounds(expression.bounds, isExcept), recurse(expression.body)),
592
+ location,
593
+ );
562
594
  }
563
595
  return at(
564
596
  {
@@ -609,6 +641,8 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
609
641
  );
610
642
  case "ExceptAt":
611
643
  return at({ kind: "At", isExcept }, { location });
644
+ case "Bracket":
645
+ throw new TlaProofError("Unexpected [ without a function or subscript");
612
646
  case "FunctionApplication":
613
647
  return at(
614
648
  {
@@ -743,17 +777,17 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
743
777
  location,
744
778
  };
745
779
  }
746
- const name = getCanonicalName(
747
- definition.name,
748
- definition.kind === "Operator" && definition.params.length === 1 && definition.name === "-",
749
- );
780
+ // A prefix minus is the operator -.
781
+ const name =
782
+ definition.kind === "Operator" && definition.params.length === 1 && definition.name === "-"
783
+ ? "-."
784
+ : getCanonicalName(definition.name);
750
785
  const body = convertExpression(definition.body, isExcept);
751
786
  if (definition.kind === "Function" && hasTuple(definition.bounds)) {
752
- const bounds = getTuplyBounds(definition.bounds, isExcept);
753
787
  return {
754
788
  kind: "Operator",
755
789
  name,
756
- body: expandTuples(() => expandFcn(bounds, body), location),
790
+ body: expandTuples(expandFcn(getTuplyBounds(definition.bounds, isExcept), body), location),
757
791
  location,
758
792
  };
759
793
  }
@@ -766,24 +800,28 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
766
800
  location,
767
801
  };
768
802
  }
769
- if (definition.params.length === 0) return { kind: "Operator", name, body, location };
770
- return {
771
- kind: "Operator",
772
- name,
773
- body: at(
774
- {
775
- kind: "Lambda",
776
- params: definition.params.map((param) => ({
777
- name: getCanonicalName(param.name),
778
- shape: param.arity,
779
- ...(param.location && { location: getNameLocus(param.name, param.location) }),
780
- })),
781
- body,
782
- },
783
- { location },
784
- ),
785
- location,
786
- };
803
+ const operatorBody =
804
+ definition.params.length === 0
805
+ ? body
806
+ : at(
807
+ {
808
+ kind: "Lambda",
809
+ params: definition.params.map((param) => ({
810
+ name: getCanonicalName(param.name),
811
+ shape: param.arity,
812
+ ...(param.location && {
813
+ location: getPointLocus(param.location, param.name.length),
814
+ }),
815
+ })),
816
+ body,
817
+ },
818
+ { location },
819
+ );
820
+ const end = definition.location.range?.end;
821
+ const methods = end && readNewMethod(lines, { line: end.line - 1, column: end.column });
822
+ return methods
823
+ ? { kind: "Bpragma", name, body: operatorBody, methods, location }
824
+ : { kind: "Operator", name, body: operatorBody, location };
787
825
  };
788
826
 
789
827
  const convertNewSymbol = (symbol: NewSymbol): Hyp => {
@@ -800,23 +838,21 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
800
838
  };
801
839
  };
802
840
 
841
+ // Anonymization judges the time of each assumption once it resolves the names in it.
803
842
  const convertSequent = (statement: Expression | AssumeProve): Sequent => {
804
843
  if (statement.kind !== "AssumeProve")
805
844
  return { context: [], active: convertExpression(statement, false) };
806
845
  return {
807
846
  context: statement.assumptions.map((assumption): Hyp => {
808
847
  if (assumption.kind === "NewSymbol") return convertNewSymbol(assumption);
809
- if (assumption.kind === "AssumeProve") {
810
- const location = getLocus(assumption.location);
811
- return {
812
- kind: "Fact",
813
- expression: at({ kind: "Sequent", sequent: convertSequent(assumption) }, { location }),
814
- visibility: "Visible",
815
- location,
816
- };
817
- }
818
- const expression = convertFactLabel(assumption);
819
- return { kind: "Fact", expression, visibility: "Visible", location: expression.location };
848
+ const expression =
849
+ assumption.kind === "AssumeProve"
850
+ ? at(
851
+ { kind: "Sequent", sequent: convertSequent(assumption) },
852
+ { location: getLocus(assumption.location) },
853
+ )
854
+ : convertFactLabel(assumption);
855
+ return getFact(expression, "Visible", "Now", expression.location);
820
856
  }),
821
857
  active: convertExpression(statement.conclusion, false),
822
858
  };
@@ -862,12 +898,10 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
862
898
  defs: use.defs.map(convertDef),
863
899
  });
864
900
 
865
- const getStepNumber = (token: RegExpExecArray | null, level: number): StepNumber => {
866
- const label = token ? token[2] : "";
867
- return label === ""
868
- ? { kind: "Unnamed", level, id: getUnique(counter) }
869
- : { kind: "Named", level, label, isAnonymous: false };
870
- };
901
+ const getStepNumber = (token: RegExpExecArray | null, level: number): StepNumber =>
902
+ token?.[2]
903
+ ? { kind: "Named", level, label: token[2], isAnonymous: false }
904
+ : { kind: "Unnamed", level, id: getUnique(counter) };
871
905
 
872
906
  // to_proof: a missing proof is implicitly omitted where the enclosing step is.
873
907
  const convertProof = (
@@ -878,7 +912,7 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
878
912
  if (!proof) return { kind: "Omitted", omission: "Implicit", location: enclosing };
879
913
  switch (proof.kind) {
880
914
  case "Obvious":
881
- return { kind: "Obvious", location: withPragma(getRangeLocus(proof.keyword)) };
915
+ return { kind: "Obvious", ...withMethod(proof.keyword) };
882
916
  case "Omitted":
883
917
  return {
884
918
  kind: "Omitted",
@@ -892,6 +926,7 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
892
926
  isOnly: proof.isOnly,
893
927
  location: getRangeLocus(proof.keyword),
894
928
  step: { kind: "Unnamed", level, id: 0 },
929
+ method: getMethod(proof.location.range),
895
930
  };
896
931
  case "Steps": {
897
932
  // A <*> first step takes the enclosing level only after PROOF, and the top level
@@ -934,7 +969,11 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
934
969
  const proof = convertProof(step.proof, level + 1, head);
935
970
  return { ...make(proof), location: mergeLoci(head, proof.location), step: number };
936
971
  };
937
- const plain = (converted: Step): Step => ({ ...converted, location: head, step: number });
972
+ const withStepMethod = (converted: Step): Step => ({
973
+ ...converted,
974
+ ...withMethod(step.head),
975
+ step: number,
976
+ });
938
977
  switch (body.kind) {
939
978
  case "Use":
940
979
  case "Hide": {
@@ -944,26 +983,38 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
944
983
  );
945
984
  const usable = convertUsable(body);
946
985
  return body.kind === "Use"
947
- ? { kind: "Use", usable, isOnly: body.isOnly, location, step: number }
986
+ ? {
987
+ kind: "Use",
988
+ usable,
989
+ isOnly: body.isOnly,
990
+ location,
991
+ step: number,
992
+ method: getMethod(body.location.range),
993
+ }
948
994
  : { kind: "Hide", usable, location, step: number };
949
995
  }
950
996
  case "Instance":
951
997
  throw new TlaProofError("Unexpected keyword INSTANCE");
952
998
  case "Define":
953
- return plain({
999
+ return {
954
1000
  kind: "Define",
955
1001
  definitions: body.definitions.map((definition) => convertDefinition(definition)),
956
- });
1002
+ location: head,
1003
+ step: number,
1004
+ };
957
1005
  case "Have":
958
- return plain({ kind: "Have", expression: convertExpression(body.expression, false) });
1006
+ return withStepMethod({
1007
+ kind: "Have",
1008
+ expression: convertExpression(body.expression, false),
1009
+ });
959
1010
  case "Take":
960
- return plain({
1011
+ return withStepMethod({
961
1012
  kind: "Take",
962
1013
  bounds:
963
1014
  body.names.length > 0 ? getUnbounded(body.names) : convertBounds(body.bounds, false),
964
1015
  });
965
1016
  case "Witness":
966
- return plain({
1017
+ return withStepMethod({
967
1018
  kind: "Witness",
968
1019
  expressions: body.expressions.map((expression) => convertExpression(expression, false)),
969
1020
  });
@@ -1046,17 +1097,24 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
1046
1097
  return {
1047
1098
  kind: "Axiom",
1048
1099
  name: unit.assumption.name,
1049
- expression: convertExpression(unit.assumption.expression, false),
1100
+ expression: withExpressionMethod(
1101
+ convertExpression(unit.assumption.expression, false),
1102
+ unit.assumption.location.range,
1103
+ ),
1050
1104
  location: getLocus(unit.assumption.location),
1051
1105
  };
1052
1106
  case "Theorem": {
1053
1107
  const theorem = unit.theorem;
1054
1108
  const location = getLocus(theorem.location);
1055
1109
  const end = withPragma(location);
1110
+ const sequent = convertSequent(theorem.statement);
1056
1111
  return {
1057
1112
  kind: "Theorem",
1058
1113
  name: theorem.name,
1059
- sequent: convertSequent(theorem.statement),
1114
+ sequent: {
1115
+ ...sequent,
1116
+ active: withExpressionMethod(sequent.active, theorem.statement.location.range),
1117
+ },
1060
1118
  axiomCount: 0,
1061
1119
  proof: convertProof(theorem.proof, 0, {
1062
1120
  ...end,
@@ -1070,7 +1128,6 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
1070
1128
  return {
1071
1129
  kind: "Mutate",
1072
1130
  mode: unit.use.kind,
1073
- isSuppressed: false,
1074
1131
  usable: convertUsable(unit.use),
1075
1132
  location: getUseLocus(unit.use),
1076
1133
  };