tla-ts 0.0.10-dev.cb7650c54 → 0.0.10-dev.d166e0ae9

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 (522) hide show
  1. package/dist/compile.cjs +3 -3
  2. package/dist/compile.js +1 -1
  3. package/dist/deciders.cjs +36 -36
  4. package/dist/deciders.js +53 -53
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.d.cts +14 -4
  7. package/dist/index.d.ts +14 -4
  8. package/dist/index.js +1 -1
  9. package/dist/parallel-worker.cjs +1 -1
  10. package/dist/parallel-worker.js +1 -1
  11. package/dist/prove-worker.cjs +1 -1
  12. package/dist/prove-worker.js +1 -1
  13. package/dist/prove.cjs +69 -69
  14. package/dist/prove.js +79 -79
  15. package/dist/run.cjs +42 -44
  16. package/dist/run.js +44 -46
  17. package/dist/tlapm.cjs +1 -1
  18. package/dist/tlapm.js +2 -2
  19. package/dist/transfer.cjs +46 -44
  20. package/dist/transfer.js +42 -40
  21. package/dist/worker.cjs +7 -7
  22. package/dist/worker.js +7 -7
  23. package/package.json +1 -1
  24. package/src/ast.ts +11 -1
  25. package/src/bags.ts +50 -29
  26. package/src/builtins.ts +4 -3
  27. package/src/check-failure.ts +9 -6
  28. package/src/check-trace.ts +116 -78
  29. package/src/check.ts +474 -209
  30. package/src/cli/runtime-invariants.ts +20 -56
  31. package/src/cli/tlc-arguments.ts +2 -2
  32. package/src/cli/tlc-output.ts +5 -5
  33. package/src/cli/tlc-usage.ts +0 -1
  34. package/src/cli/tlc.ts +29 -9
  35. package/src/cli/xml-exporter.ts +1 -1
  36. package/src/codegen.ts +34 -13
  37. package/src/coverage.ts +3 -0
  38. package/src/dependencies.ts +61 -13
  39. package/src/dfid.ts +22 -10
  40. package/src/environment.ts +96 -37
  41. package/src/errors.ts +7 -0
  42. package/src/evaluate.ts +152 -55
  43. package/src/exit-codes.ts +29 -13
  44. package/src/instances.ts +16 -6
  45. package/src/java-hash.ts +14 -0
  46. package/src/java-overrides.ts +2 -2
  47. package/src/levels.ts +186 -97
  48. package/src/liveness-checker.ts +172 -83
  49. package/src/liveness.ts +52 -11
  50. package/src/obligations/action.ts +0 -2
  51. package/src/obligations/anonymize.ts +0 -2
  52. package/src/obligations/equality.ts +0 -2
  53. package/src/obligations/expression.ts +0 -2
  54. package/src/obligations/format.ts +0 -2
  55. package/src/obligations/generate.ts +0 -2
  56. package/src/obligations/index.ts +1 -1
  57. package/src/obligations/levels.ts +0 -2
  58. package/src/obligations/module.ts +0 -2
  59. package/src/obligations/normalize.ts +1 -6
  60. package/src/obligations/operators.ts +0 -2
  61. package/src/obligations/printer.ts +5 -7
  62. package/src/obligations/proof.ts +0 -2
  63. package/src/obligations/regroup.ts +0 -2
  64. package/src/obligations/simplify.ts +0 -2
  65. package/src/obligations/source.ts +2 -0
  66. package/src/obligations/subexpression.ts +0 -2
  67. package/src/obligations/substitution.ts +0 -2
  68. package/src/obligations/temporal.ts +0 -2
  69. package/src/obligations/tuples.ts +0 -2
  70. package/src/parallel-worker.ts +8 -2
  71. package/src/parallel.ts +5 -0
  72. package/src/parser.ts +115 -145
  73. package/src/pretty-print.ts +1 -1
  74. package/src/prover/isabelle/encode.ts +0 -2
  75. package/src/prover/isabelle/isar/attrib.ts +4 -8
  76. package/src/prover/isabelle/isar/context.ts +0 -4
  77. package/src/prover/isabelle/isar/induct.ts +0 -4
  78. package/src/prover/isabelle/isar/method.ts +0 -2
  79. package/src/prover/isabelle/isar/proof.ts +0 -2
  80. package/src/prover/isabelle/isar/rule-cases.ts +8 -8
  81. package/src/prover/isabelle/isar/toplevel.ts +0 -4
  82. package/src/prover/isabelle/isar/type-check.ts +0 -2
  83. package/src/prover/isabelle/provers/blast/blast.ts +0 -2
  84. package/src/prover/isabelle/provers/blast/branch.ts +0 -2
  85. package/src/prover/isabelle/provers/blast/prove.ts +0 -2
  86. package/src/prover/isabelle/provers/blast/rules.ts +0 -2
  87. package/src/prover/isabelle/provers/blast/state.ts +0 -2
  88. package/src/prover/isabelle/provers/blast/term.ts +0 -2
  89. package/src/prover/isabelle/provers/clasimp.ts +1 -3
  90. package/src/prover/isabelle/provers/classical.ts +0 -2
  91. package/src/prover/isabelle/provers/hypsubst.ts +2 -4
  92. package/src/prover/isabelle/pure/bicompose.ts +0 -2
  93. package/src/prover/isabelle/pure/consts.ts +0 -2
  94. package/src/prover/isabelle/pure/conv.ts +0 -2
  95. package/src/prover/isabelle/pure/drule.ts +0 -2
  96. package/src/prover/isabelle/pure/envir.ts +0 -2
  97. package/src/prover/isabelle/pure/goal.ts +0 -2
  98. package/src/prover/isabelle/pure/logic.ts +0 -2
  99. package/src/prover/isabelle/pure/name.ts +0 -2
  100. package/src/prover/isabelle/pure/net.ts +0 -2
  101. package/src/prover/isabelle/pure/object-logic.ts +0 -2
  102. package/src/prover/isabelle/pure/pattern.ts +0 -2
  103. package/src/prover/isabelle/pure/raw-simplifier.ts +0 -2
  104. package/src/prover/isabelle/pure/rewriter.ts +3 -5
  105. package/src/prover/isabelle/pure/search.ts +0 -2
  106. package/src/prover/isabelle/pure/seq.ts +0 -2
  107. package/src/prover/isabelle/pure/simplifier.ts +0 -2
  108. package/src/prover/isabelle/pure/table.ts +0 -2
  109. package/src/prover/isabelle/pure/tactic.ts +0 -2
  110. package/src/prover/isabelle/pure/tactical.ts +0 -2
  111. package/src/prover/isabelle/pure/term-ord.ts +0 -2
  112. package/src/prover/isabelle/pure/term.ts +3 -5
  113. package/src/prover/isabelle/pure/thm.ts +0 -2
  114. package/src/prover/isabelle/pure/type.ts +0 -2
  115. package/src/prover/isabelle/pure/unify.ts +0 -2
  116. package/src/prover/isabelle/pure/variable.ts +0 -2
  117. package/src/prover/isabelle/tla/classical-setup.ts +0 -2
  118. package/src/prover/isabelle/tla/simpdata.ts +0 -2
  119. package/src/prover/isabelle/tools/intuitionistic.ts +0 -2
  120. package/src/prover/prep/md5.ts +26 -29
  121. package/src/prover/smt/rewrite.ts +2 -7
  122. package/src/prover/smt/simplify.ts +1 -1
  123. package/src/prover/smt/solver/ackermannize-bv-tactic.ts +0 -2
  124. package/src/prover/smt/solver/ackr-helper.ts +0 -3
  125. package/src/prover/smt/solver/ackr-model-converter.ts +0 -1
  126. package/src/prover/smt/solver/act-cache.ts +0 -1
  127. package/src/prover/smt/solver/add-bounds-tactic.ts +0 -1
  128. package/src/prover/smt/solver/aig-tactic.ts +0 -1
  129. package/src/prover/smt/solver/aig.ts +2 -3
  130. package/src/prover/smt/solver/arith-rewriter.ts +11 -4
  131. package/src/prover/smt/solver/arith-terms.ts +0 -2
  132. package/src/prover/smt/solver/array-decl-plugin.ts +0 -1
  133. package/src/prover/smt/solver/array-rewriter.ts +12 -3
  134. package/src/prover/smt/solver/asserted-formulas.ts +169 -59
  135. package/src/prover/smt/solver/ast-lt.ts +1 -2
  136. package/src/prover/smt/solver/ast-util.ts +0 -2
  137. package/src/prover/smt/solver/ast.ts +63 -15
  138. package/src/prover/smt/solver/auf-solver.ts +23 -13
  139. package/src/prover/smt/solver/bit-blast-tactic.ts +26 -3
  140. package/src/prover/smt/solver/bit-blaster.ts +0 -3
  141. package/src/prover/smt/solver/blast-term-ite.ts +47 -0
  142. package/src/prover/smt/solver/bound-manager.ts +0 -1
  143. package/src/prover/smt/solver/bound-simplifier.ts +11 -15
  144. package/src/prover/smt/solver/bv-bound-chk.ts +0 -2
  145. package/src/prover/smt/solver/bv-decl-plugin.ts +13 -11
  146. package/src/prover/smt/solver/bv-divrem-bounds.ts +0 -2
  147. package/src/prover/smt/solver/bv-rewriter.ts +1 -3
  148. package/src/prover/smt/solver/bv1-blast.ts +0 -2
  149. package/src/prover/smt/solver/bv2fpa-converter.ts +0 -1
  150. package/src/prover/smt/solver/bv2int-rewriter.ts +0 -1
  151. package/src/prover/smt/solver/bv2real-rewriter.ts +0 -1
  152. package/src/prover/smt/solver/card2bv.ts +35 -20
  153. package/src/prover/smt/solver/case-split-queue.ts +0 -2
  154. package/src/prover/smt/solver/cg-table.ts +0 -2
  155. package/src/prover/smt/solver/check-logic.ts +0 -1
  156. package/src/prover/smt/solver/clause.ts +0 -1
  157. package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -26
  158. package/src/prover/smt/solver/conflict-resolution.ts +0 -1
  159. package/src/prover/smt/solver/context.ts +67 -14
  160. package/src/prover/smt/solver/ctx-simplify.ts +1 -3
  161. package/src/prover/smt/solver/ctx-solver-simplify.ts +0 -2
  162. package/src/prover/smt/solver/datatype-decl-plugin.ts +15 -8
  163. package/src/prover/smt/solver/datatype-rewriter.ts +0 -1
  164. package/src/prover/smt/solver/demodulator.ts +0 -3
  165. package/src/prover/smt/solver/dependent-expr-state.ts +26 -18
  166. package/src/prover/smt/solver/der.ts +0 -1
  167. package/src/prover/smt/solver/diff-neq.ts +1 -3
  168. package/src/prover/smt/solver/distribute-forall.ts +0 -1
  169. package/src/prover/smt/solver/dom-simplify.ts +0 -2
  170. package/src/prover/smt/solver/dt2bv-tactic.ts +36 -22
  171. package/src/prover/smt/solver/dyn-ack.ts +0 -1
  172. package/src/prover/smt/solver/e-matching.ts +0 -1
  173. package/src/prover/smt/solver/elim-bounds.ts +89 -0
  174. package/src/prover/smt/solver/elim-small-bv-tactic.ts +0 -1
  175. package/src/prover/smt/solver/elim-term-ite-tactic.ts +48 -0
  176. package/src/prover/smt/solver/elim-uncnstr.ts +5 -10
  177. package/src/prover/smt/solver/enode.ts +0 -1
  178. package/src/prover/smt/solver/eq2bv-tactic.ts +0 -1
  179. package/src/prover/smt/solver/euf/arith-axioms.ts +0 -1
  180. package/src/prover/smt/solver/euf/arith-internalize.ts +1 -3
  181. package/src/prover/smt/solver/euf/arith-solver.ts +0 -1
  182. package/src/prover/smt/solver/euf/array-axioms.ts +0 -1
  183. package/src/prover/smt/solver/euf/array-internalize.ts +1 -3
  184. package/src/prover/smt/solver/euf/array-solver.ts +0 -2
  185. package/src/prover/smt/solver/euf/bv-ackerman.ts +0 -2
  186. package/src/prover/smt/solver/euf/bv-internalize.ts +1 -3
  187. package/src/prover/smt/solver/euf/bv-solver.ts +0 -2
  188. package/src/prover/smt/solver/euf/dt-solver.ts +0 -2
  189. package/src/prover/smt/solver/euf/egraph.ts +4 -12
  190. package/src/prover/smt/solver/euf/euf-solver.ts +1 -5
  191. package/src/prover/smt/solver/euf/fpa-solver.ts +0 -2
  192. package/src/prover/smt/solver/euf/mam.ts +1 -7
  193. package/src/prover/smt/solver/euf/q-ematch.ts +1 -4
  194. package/src/prover/smt/solver/euf/q-mbi.ts +0 -2
  195. package/src/prover/smt/solver/euf/q-model-fixer.ts +0 -3
  196. package/src/prover/smt/solver/euf/q-solver.ts +0 -2
  197. package/src/prover/smt/solver/euf/th-solver.ts +0 -9
  198. package/src/prover/smt/solver/euf/th-solvers.ts +0 -1
  199. package/src/prover/smt/solver/expr-ref.ts +0 -1
  200. package/src/prover/smt/solver/expr-safe-replace.ts +0 -1
  201. package/src/prover/smt/solver/expr2polynomial.ts +204 -80
  202. package/src/prover/smt/solver/factor.ts +36 -15
  203. package/src/prover/smt/solver/fd-solver.ts +148 -42
  204. package/src/prover/smt/solver/fingerprints.ts +0 -1
  205. package/src/prover/smt/solver/fix-dl-var.ts +1 -3
  206. package/src/prover/smt/solver/flat-literals.ts +0 -1
  207. package/src/prover/smt/solver/fm-tactic.ts +0 -1
  208. package/src/prover/smt/solver/fpa-decl-plugin.ts +0 -1
  209. package/src/prover/smt/solver/fpa-rewriter.ts +1 -3
  210. package/src/prover/smt/solver/fpa2bv-converter.ts +3 -2
  211. package/src/prover/smt/solver/fpa2bv-rewriter.ts +1 -1
  212. package/src/prover/smt/solver/fpa2bv-tactic.ts +0 -2
  213. package/src/prover/smt/solver/goal.ts +6 -4
  214. package/src/prover/smt/solver/goal2nlsat.ts +57 -32
  215. package/src/prover/smt/solver/guard-set.ts +0 -1
  216. package/src/prover/smt/solver/hash.ts +0 -1
  217. package/src/prover/smt/solver/hashtable.ts +4 -1
  218. package/src/prover/smt/solver/inf-eps.ts +1 -2
  219. package/src/prover/smt/solver/inj-axiom.ts +0 -1
  220. package/src/prover/smt/solver/internalizer.ts +1 -2
  221. package/src/prover/smt/solver/lackr.ts +0 -2
  222. package/src/prover/smt/solver/lbool.ts +0 -1
  223. package/src/prover/smt/solver/lia2card.ts +0 -1
  224. package/src/prover/smt/solver/lia2pb.ts +0 -1
  225. package/src/prover/smt/solver/literal.ts +0 -1
  226. package/src/prover/smt/solver/logic-tactics.ts +9 -6
  227. package/src/prover/smt/solver/lp/bound-propagator.ts +0 -1
  228. package/src/prover/smt/solver/lp/constraints.ts +0 -1
  229. package/src/prover/smt/solver/lp/containers.ts +7 -2
  230. package/src/prover/smt/solver/lp/core-solver.ts +0 -3
  231. package/src/prover/smt/solver/lp/cross-nested.ts +1 -4
  232. package/src/prover/smt/solver/lp/dep-intervals.ts +0 -3
  233. package/src/prover/smt/solver/lp/dependency.ts +0 -2
  234. package/src/prover/smt/solver/lp/dioph-eq.ts +0 -2
  235. package/src/prover/smt/solver/lp/explanation.ts +0 -1
  236. package/src/prover/smt/solver/lp/gomory.ts +0 -1
  237. package/src/prover/smt/solver/lp/hnf-cutter.ts +0 -1
  238. package/src/prover/smt/solver/lp/hnf.ts +0 -3
  239. package/src/prover/smt/solver/lp/int-cube.ts +0 -1
  240. package/src/prover/smt/solver/lp/int-solver.ts +0 -2
  241. package/src/prover/smt/solver/lp/lar-solver.ts +0 -1
  242. package/src/prover/smt/solver/lp/lar-term.ts +0 -1
  243. package/src/prover/smt/solver/lp/lp-settings.ts +5 -2
  244. package/src/prover/smt/solver/lp/maximize-term.ts +0 -3
  245. package/src/prover/smt/solver/lp/nex-creator.ts +3 -3
  246. package/src/prover/smt/solver/lp/nex.ts +2 -2
  247. package/src/prover/smt/solver/lp/nla-backoff.ts +0 -2
  248. package/src/prover/smt/solver/lp/nla-basics.ts +46 -3
  249. package/src/prover/smt/solver/lp/nla-core.ts +26 -7
  250. package/src/prover/smt/solver/lp/nla-divisions.ts +0 -2
  251. package/src/prover/smt/solver/lp/nla-emonics.ts +0 -1
  252. package/src/prover/smt/solver/lp/nla-factorization.ts +0 -1
  253. package/src/prover/smt/solver/lp/nla-grobner.ts +158 -82
  254. package/src/prover/smt/solver/lp/nla-horner.ts +0 -2
  255. package/src/prover/smt/solver/lp/nla-intervals.ts +0 -1
  256. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +0 -2
  257. package/src/prover/smt/solver/lp/nla-monotone.ts +0 -1
  258. package/src/prover/smt/solver/lp/nla-order.ts +0 -2
  259. package/src/prover/smt/solver/lp/nla-patcher.ts +0 -1
  260. package/src/prover/smt/solver/lp/nla-powers.ts +0 -1
  261. package/src/prover/smt/solver/lp/nla-tangents.ts +0 -2
  262. package/src/prover/smt/solver/lp/nla-throttle.ts +0 -1
  263. package/src/prover/smt/solver/lp/nla-transcendentals.ts +0 -2
  264. package/src/prover/smt/solver/lp/nla-types.ts +0 -2
  265. package/src/prover/smt/solver/lp/nla-var-eqs.ts +0 -1
  266. package/src/prover/smt/solver/lp/nra-solver.ts +138 -97
  267. package/src/prover/smt/solver/lp/numeric-pair.ts +0 -1
  268. package/src/prover/smt/solver/lp/pdd-interval.ts +6 -3
  269. package/src/prover/smt/solver/lp/pdd-simplifier.ts +60 -21
  270. package/src/prover/smt/solver/lp/pdd-solver.ts +72 -41
  271. package/src/prover/smt/solver/lp/pdd.ts +725 -290
  272. package/src/prover/smt/solver/lp/random-updater.ts +0 -2
  273. package/src/prover/smt/solver/lp/static-matrix.ts +0 -1
  274. package/src/prover/smt/solver/lp/union-find.ts +1 -2
  275. package/src/prover/smt/solver/macro-finder.ts +0 -3
  276. package/src/prover/smt/solver/mam-compiler.ts +1 -2
  277. package/src/prover/smt/solver/mam-interpreter.ts +0 -1
  278. package/src/prover/smt/solver/max-bv-sharing-tactic.ts +0 -2
  279. package/src/prover/smt/solver/max-cliques.ts +0 -2
  280. package/src/prover/smt/solver/maxcore.ts +3 -3
  281. package/src/prover/smt/solver/maximize-ac-sharing.ts +0 -1
  282. package/src/prover/smt/solver/maxlex.ts +0 -1
  283. package/src/prover/smt/solver/maxsmt-base.ts +1 -1
  284. package/src/prover/smt/solver/maxsmt.ts +0 -1
  285. package/src/prover/smt/solver/mbp/mbp-arith.ts +0 -1
  286. package/src/prover/smt/solver/mbp/mbp-basic-tg.ts +0 -1
  287. package/src/prover/smt/solver/mbp/mbp-plugin.ts +0 -2
  288. package/src/prover/smt/solver/mbp/mbp-qel.ts +0 -1
  289. package/src/prover/smt/solver/mbp/mbp-solve-plugin.ts +0 -1
  290. package/src/prover/smt/solver/mbp/mbp-term-graph.ts +0 -1
  291. package/src/prover/smt/solver/model-based-opt.ts +1 -2
  292. package/src/prover/smt/solver/model-checker.ts +1 -2
  293. package/src/prover/smt/solver/model-evaluator.ts +2 -1
  294. package/src/prover/smt/solver/model-finder.ts +0 -1
  295. package/src/prover/smt/solver/model-generator.ts +85 -44
  296. package/src/prover/smt/solver/model-macro-solver.ts +0 -1
  297. package/src/prover/smt/solver/model-printer.ts +0 -1
  298. package/src/prover/smt/solver/mpf.ts +2 -5
  299. package/src/prover/smt/solver/mus.ts +2 -4
  300. package/src/prover/smt/solver/muz/dl-context.ts +22 -46
  301. package/src/prover/smt/solver/muz/dl-mk-bit-blast.ts +0 -1
  302. package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -3
  303. package/src/prover/smt/solver/muz/dl-mk-elim-term-ite.ts +0 -2
  304. package/src/prover/smt/solver/muz/dl-mk-interp-tail-simplifier.ts +0 -2
  305. package/src/prover/smt/solver/muz/dl-mk-rule-inliner.ts +0 -1
  306. package/src/prover/smt/solver/muz/dl-mk-slice.ts +3 -4
  307. package/src/prover/smt/solver/muz/dl-mk-subsumption-checker.ts +0 -2
  308. package/src/prover/smt/solver/muz/dl-rule-set.ts +0 -1
  309. package/src/prover/smt/solver/muz/dl-rule-transformer.ts +0 -2
  310. package/src/prover/smt/solver/muz/dl-rule.ts +8 -11
  311. package/src/prover/smt/solver/muz/hnf.ts +2 -3
  312. package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +1 -3
  313. package/src/prover/smt/solver/muz/horn-tactic.ts +15 -4
  314. package/src/prover/smt/solver/muz/rule-properties.ts +22 -1
  315. package/src/prover/smt/solver/muz/spacer-context.ts +2 -5
  316. package/src/prover/smt/solver/muz/spacer-dl-interface.ts +0 -1
  317. package/src/prover/smt/solver/muz/spacer-generalizers.ts +0 -3
  318. package/src/prover/smt/solver/muz/spacer-manager.ts +0 -2
  319. package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -1
  320. package/src/prover/smt/solver/muz/spacer-prop-solver.ts +2 -3
  321. package/src/prover/smt/solver/muz/spacer-util.ts +0 -1
  322. package/src/prover/smt/solver/muz/substitution.ts +0 -2
  323. package/src/prover/smt/solver/nla2bv-tactic.ts +0 -1
  324. package/src/prover/smt/solver/nlqsat.ts +3 -3
  325. package/src/prover/smt/solver/nlsat/algebraic.ts +196 -94
  326. package/src/prover/smt/solver/nlsat/atoms.ts +52 -35
  327. package/src/prover/smt/solver/nlsat/evaluator.ts +0 -1
  328. package/src/prover/smt/solver/nlsat/explain.ts +375 -218
  329. package/src/prover/smt/solver/nlsat/interval-set.ts +0 -1
  330. package/src/prover/smt/solver/nlsat/levelwise.ts +460 -241
  331. package/src/prover/smt/solver/nlsat/mpbq.ts +0 -1
  332. package/src/prover/smt/solver/nlsat/polynomial.ts +2366 -683
  333. package/src/prover/smt/solver/nlsat/solver.ts +77 -75
  334. package/src/prover/smt/solver/nlsat/transcendental-eval.ts +2 -3
  335. package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -19
  336. package/src/prover/smt/solver/nlsat/types.ts +0 -2
  337. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -7
  338. package/src/prover/smt/solver/nlsat/upolynomial.ts +41 -20
  339. package/src/prover/smt/solver/nlsat-tactic.ts +1 -2
  340. package/src/prover/smt/solver/nnf.ts +6 -3
  341. package/src/prover/smt/solver/normalize-bounds.ts +0 -1
  342. package/src/prover/smt/solver/occf.ts +0 -1
  343. package/src/prover/smt/solver/opt-context.ts +22 -9
  344. package/src/prover/smt/solver/opt-nlsat.ts +29 -19
  345. package/src/prover/smt/solver/opt-pareto.ts +19 -2
  346. package/src/prover/smt/solver/opt-preprocess.ts +1 -2
  347. package/src/prover/smt/solver/opt-solver.ts +10 -7
  348. package/src/prover/smt/solver/opt-value.ts +0 -1
  349. package/src/prover/smt/solver/optsmt.ts +1 -3
  350. package/src/prover/smt/solver/parallel-tactic.ts +1 -3
  351. package/src/prover/smt/solver/pattern-inference.ts +0 -1
  352. package/src/prover/smt/solver/pb-rewriter.ts +1 -7
  353. package/src/prover/smt/solver/pb2bv-tactic.ts +0 -2
  354. package/src/prover/smt/solver/poly-rewriter.ts +75 -19
  355. package/src/prover/smt/solver/probes.ts +90 -27
  356. package/src/prover/smt/solver/propagate-values.ts +0 -1
  357. package/src/prover/smt/solver/proto-model.ts +8 -9
  358. package/src/prover/smt/solver/pull-quant.ts +0 -1
  359. package/src/prover/smt/solver/purify-arith.ts +0 -1
  360. package/src/prover/smt/solver/push-app-ite.ts +37 -0
  361. package/src/prover/smt/solver/qe-arith-plugin.ts +2 -6
  362. package/src/prover/smt/solver/qe-lite-der.ts +0 -1
  363. package/src/prover/smt/solver/qe-lite-fm.ts +0 -1
  364. package/src/prover/smt/solver/qe-lite.ts +2 -3
  365. package/src/prover/smt/solver/qe-mbp.ts +0 -1
  366. package/src/prover/smt/solver/qe.ts +3 -4
  367. package/src/prover/smt/solver/qel.ts +0 -1
  368. package/src/prover/smt/solver/qi-queue.ts +0 -1
  369. package/src/prover/smt/solver/qsat.ts +23 -9
  370. package/src/prover/smt/solver/quant-hoist.ts +0 -1
  371. package/src/prover/smt/solver/quant-tactics.ts +0 -1
  372. package/src/prover/smt/solver/quantifier-analyzer.ts +0 -1
  373. package/src/prover/smt/solver/quantifier-manager.ts +14 -10
  374. package/src/prover/smt/solver/quasi-macros.ts +0 -2
  375. package/src/prover/smt/solver/random-gen.ts +0 -1
  376. package/src/prover/smt/solver/rational.ts +0 -1
  377. package/src/prover/smt/solver/recfun-decl-plugin.ts +2 -2
  378. package/src/prover/smt/solver/recfun-rewriter.ts +0 -1
  379. package/src/prover/smt/solver/reduce-args.ts +0 -1
  380. package/src/prover/smt/solver/reduce-bv-size.ts +0 -1
  381. package/src/prover/smt/solver/ref-vector.ts +0 -1
  382. package/src/prover/smt/solver/relevancy.ts +0 -1
  383. package/src/prover/smt/solver/rewriter-tpl.ts +7 -7
  384. package/src/prover/smt/solver/rewriter.ts +31 -26
  385. package/src/prover/smt/solver/rlimit.ts +17 -1
  386. package/src/prover/smt/solver/sat/asymm-branch.ts +0 -2
  387. package/src/prover/smt/solver/sat/big.ts +0 -1
  388. package/src/prover/smt/solver/sat/clause-use-list.ts +0 -2
  389. package/src/prover/smt/solver/sat/clause.ts +0 -3
  390. package/src/prover/smt/solver/sat/cleaner.ts +0 -2
  391. package/src/prover/smt/solver/sat/config.ts +1 -4
  392. package/src/prover/smt/solver/sat/consequences.ts +0 -1
  393. package/src/prover/smt/solver/sat/elim-eqs.ts +0 -2
  394. package/src/prover/smt/solver/sat/goal2sat.ts +0 -3
  395. package/src/prover/smt/solver/sat/inc-sat-solver.ts +81 -29
  396. package/src/prover/smt/solver/sat/model-converter.ts +1 -3
  397. package/src/prover/smt/solver/sat/pb-constraint.ts +0 -3
  398. package/src/prover/smt/solver/sat/pb-solver.ts +1 -3
  399. package/src/prover/smt/solver/sat/probing.ts +0 -2
  400. package/src/prover/smt/solver/sat/sat-tactic.ts +17 -8
  401. package/src/prover/smt/solver/sat/sat2goal.ts +10 -9
  402. package/src/prover/smt/solver/sat/scc.ts +0 -1
  403. package/src/prover/smt/solver/sat/simplifier.ts +1 -4
  404. package/src/prover/smt/solver/sat/solver.ts +25 -49
  405. package/src/prover/smt/solver/sat/var-queue.ts +0 -2
  406. package/src/prover/smt/solver/sat/watch-list.ts +0 -3
  407. package/src/prover/smt/solver/search-tree.ts +0 -1
  408. package/src/prover/smt/solver/seq-axioms.ts +20 -36
  409. package/src/prover/smt/solver/seq-decl-plugin.ts +1 -2
  410. package/src/prover/smt/solver/seq-derive.ts +4 -9
  411. package/src/prover/smt/solver/seq-eq-approx.ts +0 -2
  412. package/src/prover/smt/solver/seq-eq-solver.ts +2 -3
  413. package/src/prover/smt/solver/seq-factory.ts +0 -1
  414. package/src/prover/smt/solver/seq-monadic.ts +7 -7
  415. package/src/prover/smt/solver/seq-range-predicate.ts +0 -2
  416. package/src/prover/smt/solver/seq-re-rewriter.ts +2 -2
  417. package/src/prover/smt/solver/seq-re-util.ts +1 -3
  418. package/src/prover/smt/solver/seq-regex-bisim.ts +1 -2
  419. package/src/prover/smt/solver/seq-regex-live.ts +2 -4
  420. package/src/prover/smt/solver/seq-rewriter.ts +31 -31
  421. package/src/prover/smt/solver/seq-skolem.ts +0 -24
  422. package/src/prover/smt/solver/seq-subset.ts +0 -1
  423. package/src/prover/smt/solver/seq-view-witness.ts +4 -6
  424. package/src/prover/smt/solver/smt-consequences.ts +1 -3
  425. package/src/prover/smt/solver/smt-kernel.ts +48 -9
  426. package/src/prover/smt/solver/smt-logics.ts +0 -1
  427. package/src/prover/smt/solver/smt-setup.ts +99 -15
  428. package/src/prover/smt/solver/smt2-printer.ts +0 -2
  429. package/src/prover/smt/solver/smtlib-parser.ts +589 -226
  430. package/src/prover/smt/solver/smtlib-script.ts +674 -197
  431. package/src/prover/smt/solver/solve-eqs.ts +36 -39
  432. package/src/prover/smt/solver/solver.ts +19 -5
  433. package/src/prover/smt/solver/static-features.ts +0 -2
  434. package/src/prover/smt/solver/sticky-generations.ts +0 -1
  435. package/src/prover/smt/solver/tactic.ts +332 -191
  436. package/src/prover/smt/solver/term-enumeration.ts +0 -1
  437. package/src/prover/smt/solver/theory-array.ts +0 -2
  438. package/src/prover/smt/solver/theory-bv.ts +13 -5
  439. package/src/prover/smt/solver/theory-char.ts +0 -1
  440. package/src/prover/smt/solver/theory-datatype.ts +0 -1
  441. package/src/prover/smt/solver/theory-finite-set.ts +2 -2
  442. package/src/prover/smt/solver/theory-fpa.ts +1 -2
  443. package/src/prover/smt/solver/theory-lra-axioms.ts +0 -1
  444. package/src/prover/smt/solver/theory-lra-bounds.ts +0 -1
  445. package/src/prover/smt/solver/theory-lra-final-check.ts +1 -1
  446. package/src/prover/smt/solver/theory-lra-internalize.ts +10 -1
  447. package/src/prover/smt/solver/theory-lra-model.ts +0 -1
  448. package/src/prover/smt/solver/theory-lra-propagate.ts +11 -4
  449. package/src/prover/smt/solver/theory-lra-state.ts +0 -1
  450. package/src/prover/smt/solver/theory-lra.ts +1 -2
  451. package/src/prover/smt/solver/theory-pb.ts +24 -9
  452. package/src/prover/smt/solver/theory-polymorphism.ts +3 -4
  453. package/src/prover/smt/solver/theory-recfun.ts +0 -1
  454. package/src/prover/smt/solver/theory-seq-regex.ts +0 -1
  455. package/src/prover/smt/solver/theory-seq-solve.ts +1 -3
  456. package/src/prover/smt/solver/theory-seq-state.ts +2 -23
  457. package/src/prover/smt/solver/theory-seq.ts +0 -1
  458. package/src/prover/smt/solver/theory.ts +0 -1
  459. package/src/prover/smt/solver/tseitin-cnf.ts +1 -2
  460. package/src/prover/smt/solver/var-subst.ts +0 -1
  461. package/src/prover/tlapm/cache.ts +8 -8
  462. package/src/prover/zenon/decide.ts +0 -2
  463. package/src/prover/zenon/encode.ts +0 -2
  464. package/src/prover/zenon/eqrel.ts +0 -2
  465. package/src/prover/zenon/equality-rules.ts +24 -2
  466. package/src/prover/zenon/expr.ts +21 -2
  467. package/src/prover/zenon/index-table.ts +7 -4
  468. package/src/prover/zenon/isar-case.ts +1 -3
  469. package/src/prover/zenon/isar.ts +2 -4
  470. package/src/prover/zenon/llproof.ts +0 -2
  471. package/src/prover/zenon/mltoll.ts +0 -2
  472. package/src/prover/zenon/node.ts +0 -2
  473. package/src/prover/zenon/parse.ts +0 -2
  474. package/src/prover/zenon/phrase.ts +1 -3
  475. package/src/prover/zenon/proof.ts +0 -2
  476. package/src/prover/zenon/propositional-rules.ts +0 -2
  477. package/src/prover/zenon/rules.ts +2 -3
  478. package/src/prover/zenon/search.ts +0 -2
  479. package/src/prover/zenon/tla/functions.ts +0 -2
  480. package/src/prover/zenon/tla/llproof.ts +0 -2
  481. package/src/prover/zenon/tla/records.ts +0 -2
  482. package/src/prover/zenon/tla/rewrites.ts +0 -2
  483. package/src/prover/zenon/tla/sets.ts +0 -2
  484. package/src/prover/zenon/tla/terms.ts +0 -2
  485. package/src/prover/zenon/tla/tla.ts +0 -2
  486. package/src/resolve.ts +1072 -253
  487. package/src/runtime.ts +11 -1
  488. package/src/sany/builtins.ts +10 -10
  489. package/src/sany/generation.ts +2 -13
  490. package/src/sany/generator-definitions.ts +3 -1
  491. package/src/sany/generator-expressions.ts +38 -30
  492. package/src/sany/generator-proofs.ts +6 -3
  493. package/src/sany/generator.ts +2 -1
  494. package/src/sany/levels.ts +0 -2
  495. package/src/sany/lexer.ts +3 -3
  496. package/src/sany/linter.ts +0 -2
  497. package/src/sany/modules.ts +4 -2
  498. package/src/sany/nodes.ts +1 -1
  499. package/src/sany/selectors.ts +11 -6
  500. package/src/sany/xml.ts +2 -3
  501. package/src/search.ts +262 -144
  502. package/src/simulate.ts +168 -102
  503. package/src/spec-description.ts +8 -6
  504. package/src/standard-definitions.ts +4 -0
  505. package/src/standard-modules.ts +56 -22
  506. package/src/state-graph.ts +0 -2
  507. package/src/subexpressions.ts +518 -123
  508. package/src/successors.ts +10 -3
  509. package/src/symmetry.ts +2 -1
  510. package/src/tlc/jar-data.ts +10 -0
  511. package/src/tlc/messages.ts +3 -3
  512. package/src/tlc/order.ts +14 -3
  513. package/src/tlc/random.ts +2 -1
  514. package/src/tlc/replay.ts +27 -14
  515. package/src/tlc/tlc-operators.ts +10 -8
  516. package/src/tlc/tlcext-operators.ts +87 -26
  517. package/src/tlc/trace-spec.ts +11 -25
  518. package/src/typed-tier.ts +44 -27
  519. package/src/typescript/types.ts +2 -2
  520. package/src/values.ts +135 -78
  521. package/src/prover/smt/solver/z3-license.txt +0 -10
  522. package/src/prover/zenon/LICENSE +0 -32
package/src/resolve.ts CHANGED
@@ -18,9 +18,13 @@ import {
18
18
  type Selector,
19
19
  type SourceLocation,
20
20
  type SourceRange,
21
+ type StepBody,
21
22
  type Theorem,
23
+ type UseOrHide,
22
24
  } from "./ast";
23
25
  import { formatRange, TlaSyntaxError, type SanyError } from "./errors";
26
+ import { parenthesizedRanges } from "./parser";
27
+ import { resolveSynonym } from "./tlc/jar-data";
24
28
 
25
29
  export type SymbolKind =
26
30
  | "Builtin"
@@ -49,6 +53,7 @@ interface Goal {
49
53
  statement: Expression | AssumeProve;
50
54
  isSuffices: boolean;
51
55
  isInProof: boolean;
56
+ keyword: string | undefined;
52
57
  }
53
58
 
54
59
  interface LocalName extends Binding {
@@ -56,7 +61,7 @@ interface LocalName extends Binding {
56
61
  parent: LocalName | undefined;
57
62
  goal?: Goal;
58
63
  isPending?: boolean;
59
- isNonFact?: boolean;
64
+ nonFactStep?: "Use" | "Hide" | "Instance" | "Define";
60
65
  }
61
66
 
62
67
  interface ModuleBinding extends Binding {
@@ -69,6 +74,7 @@ interface Unit {
69
74
  getInstance: (instance: Instance) => InstancedModule;
70
75
  definitions: Map<string, Definition>;
71
76
  getKey: (definition: Definition) => string;
77
+ isModuleKnown: (name: string, location: SourceLocation) => boolean;
72
78
  location: SourceLocation;
73
79
  self: Definition | undefined;
74
80
  facts: Set<string>;
@@ -84,8 +90,16 @@ interface Unit {
84
90
  isGenerated: boolean;
85
91
  }
86
92
 
87
- interface SelectionError {
93
+ export interface SelectionArguments {
94
+ operator: string;
95
+ range: SourceRange | undefined;
88
96
  args: Expression[];
97
+ params: number[];
98
+ }
99
+
100
+ interface SelectionError {
101
+ applications: SelectionArguments[];
102
+ nulls: NullSelection[];
89
103
  error: SanyError;
90
104
  }
91
105
 
@@ -99,8 +113,39 @@ type Reference = Expression & { kind: "Identifier" | "Apply" | "Subexpression" }
99
113
 
100
114
  export const LOCAL_RESOLUTION = { kind: "Local" } as const;
101
115
 
102
- export const selections = new WeakSet<Expression>();
116
+ export const SELECTION_NAME = "$subexpression";
117
+
118
+ export interface NullSelection {
119
+ node: Expression;
120
+ error: SanyError;
121
+ isEmpty: boolean;
122
+ }
123
+
124
+ interface SelectionArgument {
125
+ operator: string;
126
+ index: number;
127
+ range: SourceRange | undefined;
128
+ }
129
+
130
+ export const selections = new WeakMap<Expression, Expression>();
103
131
  export const selectionErrors = new WeakMap<Expression, SelectionError>();
132
+ export const operatorSelectionErrors = new WeakMap<Expression, SanyError>();
133
+ export const factReferences = new WeakMap<Fact[], Fact[]>();
134
+ export const selectionArguments = new WeakMap<Expression, SelectionArgument>();
135
+ export const nullSelections = new WeakMap<Expression, NullSelection[]>();
136
+ const unresolvedExpressions = new WeakSet<Expression>();
137
+ const emptyExpressions = new WeakSet<Expression>();
138
+
139
+ // SANY's failed selection is an operator application with no operands.
140
+ const isEmptyExpression = (expression: Expression): boolean =>
141
+ emptyExpressions.has(expression) || findNullError(nullSelections.get(expression)) !== undefined;
142
+
143
+ const findNullError = (nulls: NullSelection[] | undefined) =>
144
+ nulls?.find((selection) =>
145
+ selection.isEmpty
146
+ ? isEmptyExpression(selection.node)
147
+ : unresolvedExpressions.has(selection.node),
148
+ )?.error;
104
149
 
105
150
  const renamedArities = new WeakMap<Expression, number>();
106
151
 
@@ -111,13 +156,20 @@ const isKey = (name: string) => {
111
156
  return index > 0 && index < name.length - 1;
112
157
  };
113
158
 
114
- const CORE_SYMBOLS: Symbols = new Map(
115
- ["~>", "-+->", "\\cdot"].map((name) => [name, { key: name, arity: 2, kind: "Builtin" }]),
116
- );
159
+ const CORE_SYMBOLS: Symbols = new Map([
160
+ ...["~>", "-+->", "\\cdot", "\\X"].map((name): [string, ModuleSymbol] => [
161
+ name,
162
+ { key: name, arity: 2, kind: "Builtin" },
163
+ ]),
164
+ ["'", { key: "'", arity: 1, kind: "Builtin" }],
165
+ ]);
117
166
 
118
167
  export const isBefore = (left: SourceLocation, right: SourceLocation) =>
119
168
  left.line < right.line || (left.line === right.line && left.column < right.column);
120
169
 
170
+ export const compareLocations = (left: SourceLocation, right: SourceLocation) =>
171
+ isBefore(left, right) ? -1 : isBefore(right, left) ? 1 : 0;
172
+
121
173
  export const getArity = (definition: Definition) =>
122
174
  definition.kind === "Operator" ? definition.params.length : 0;
123
175
 
@@ -157,7 +209,7 @@ const isBindable = (name: string, current: Binding | undefined, added: Binding,
157
209
  if (current.kind === "Builtin") {
158
210
  unit.errors.push({
159
211
  location,
160
- message: `Symbol ${name} is a built-in operator, and cannot be redefined.`,
212
+ message: `Symbol ${resolveSynonym(name)} is a built-in operator, and cannot be redefined.`,
161
213
  });
162
214
  } else if (
163
215
  added.kind === "Parameter" ||
@@ -166,12 +218,12 @@ const isBindable = (name: string, current: Binding | undefined, added: Binding,
166
218
  ) {
167
219
  unit.errors.push({
168
220
  location,
169
- message: `Multiply-defined symbol '${name}': this definition or declaration conflicts \nwith the one at ${existing}.`,
221
+ message: `Multiply-defined symbol '${resolveSynonym(name)}': this definition or declaration conflicts \nwith the one at ${existing}.`,
170
222
  });
171
223
  } else {
172
224
  unit.warnings.push({
173
225
  location,
174
- message: `Multiple declarations or definitions for symbol ${name}. \nThis duplicates the one at ${existing}.`,
226
+ message: `Multiple declarations or definitions for symbol ${resolveSynonym(name)}. \nThis duplicates the one at ${existing}.`,
175
227
  });
176
228
  }
177
229
  return false;
@@ -233,23 +285,38 @@ const getVisibleDefinition = (name: string, unit: Unit) => {
233
285
  const isVisible =
234
286
  definition !== undefined &&
235
287
  (definition === unit.self
236
- ? definition.kind === "Function" || definition.isRecursive
237
- : definition.isRecursive || isBefore(definition.location, unit.location));
288
+ ? definition.isRecursive
289
+ : definition.isRecursive
290
+ ? getModuleBinding(name, unit, undefined) !== undefined
291
+ : isBefore(definition.location, unit.location));
238
292
  return isVisible ? definition : undefined;
239
293
  };
240
294
 
241
295
  const findSymbol = (name: string, unit: Unit): ModuleSymbol | undefined => {
242
296
  const definition = getVisibleDefinition(name, unit);
243
- return definition
244
- ? {
245
- key: unit.getKey(definition),
246
- arity: getArity(definition),
247
- params: getParamArities(definition),
248
- kind: "Definition",
249
- }
250
- : unit.imported.get(name);
297
+ if (definition) {
298
+ const declared = definition.isRecursive ? unit.bindings.get(name) : undefined;
299
+ return {
300
+ key: unit.getKey(definition),
301
+ arity: declared?.arity ?? getArity(definition),
302
+ params: declared?.params ?? getParamArities(definition),
303
+ kind: "Definition",
304
+ range: definition.location.range,
305
+ };
306
+ }
307
+ const binding = getModuleBinding(name, unit, undefined);
308
+ if (binding?.isPending) {
309
+ return { key: name, arity: binding.arity, params: binding.params, kind: binding.kind };
310
+ }
311
+ return binding ? unit.imported.get(name) : undefined;
251
312
  };
252
313
 
314
+ const isFact = (name: string, unit: Unit) =>
315
+ unit.facts.has(name) || unit.bindings.get(name)?.kind === "Theorem";
316
+
317
+ const getGoal = (name: string, unit: Unit) =>
318
+ unit.bindings.get(name)?.kind === "Theorem" ? unit.goals.get(name) : undefined;
319
+
253
320
  const findBinding = (name: string, scope: LocalName | undefined, unit: Unit): Binding | undefined =>
254
321
  lookupLocal(scope, name) ?? findSymbol(name, unit);
255
322
 
@@ -271,12 +338,22 @@ const getSpelledNameRange = (
271
338
  };
272
339
 
273
340
  const getFixity = (expression: Expression) => {
274
- if (expression.kind !== "Apply") return undefined;
341
+ if (expression.kind !== "Apply" || expression.argumentsRange) return undefined;
275
342
  if (expression.args.length === 2) return "infix";
276
343
  if (expression.args.length !== 1) return undefined;
277
- return isBefore(expression.location, expression.args[0].location) ? "prefix" : "postfix";
344
+ return expression.operator === "-." ? "prefix" : "postfix";
278
345
  };
279
346
 
347
+ const BUILTIN_LOCATION = "In module --TLA+ BUILTINS--";
348
+
349
+ const SELECTABLE_KINDS = new Set<SymbolKind>(["Definition", "Instance", "Theorem"]);
350
+
351
+ const reportUnselectable = (name: string, range: SourceRange, unit: Unit) =>
352
+ unit.errors.push({
353
+ location: formatRange(range),
354
+ message: `Cannot take subexpression of \`${resolveSynonym(name)}'.`,
355
+ });
356
+
280
357
  const isOperatorSymbol = (name: string) => !/^[\p{L}\d_]/u.test(name);
281
358
 
282
359
  const isStepName = (name: string) =>
@@ -388,6 +465,7 @@ export const getOperands = (expression: Expression): Expression[] | undefined =>
388
465
  case "Enabled":
389
466
  case "Always":
390
467
  case "Eventually":
468
+ case "Selection":
391
469
  return [expression.expression];
392
470
  case "BoxAction":
393
471
  case "AngleAction":
@@ -416,7 +494,7 @@ const isInScopeOfDeclaration = (assumeProve: AssumeProve, clause: number) =>
416
494
 
417
495
  const findLabel = (expression: Expression, name: string): LabelExpression | undefined => {
418
496
  if (expression.kind === "Label") return expression.name === name ? expression : undefined;
419
- if (expression.kind === "Lambda") return undefined;
497
+ if (expression.kind === "Lambda" || expression.kind === "Selection") return undefined;
420
498
  if (expression.kind === "Let") return findLabel(expression.body, name);
421
499
  return getChildren(expression).reduce<LabelExpression | undefined>(
422
500
  (found, child) => found ?? findLabel(child, name),
@@ -453,7 +531,6 @@ const checkSelection = (
453
531
  reference: Reference,
454
532
  selectors: Selector[],
455
533
  goal: Goal,
456
- scope: LocalName | undefined,
457
534
  unit: Unit,
458
535
  isFact: boolean,
459
536
  ) => {
@@ -462,6 +539,7 @@ const checkSelection = (
462
539
  (index === undefined ? undefined : reference.selectorRanges?.[index]) ??
463
540
  reference.location.range;
464
541
  if (range) unit.errors.push({ location: formatRange(range), message });
542
+ return undefined;
465
543
  };
466
544
  const isOutOfScope = goal.isSuffices === goal.isInProof;
467
545
  const statement = goal.statement;
@@ -470,6 +548,8 @@ const checkSelection = (
470
548
  isGoal: true,
471
549
  isSufficesOpen: goal.isSuffices,
472
550
  };
551
+ let params = 0;
552
+ let args = 0;
473
553
  for (const [offset, selector] of selectors.slice(1).entries()) {
474
554
  const index = offset + 1;
475
555
  const node = state.node;
@@ -479,9 +559,7 @@ const checkSelection = (
479
559
  node.kind !== "NewSymbol" &&
480
560
  node.kind !== "AssumeProve" &&
481
561
  getLabelBody(node).kind === "Let";
482
- return isLet
483
- ? undefined
484
- : report(index - 1, "A name selector here must be from a LET clause.");
562
+ return isLet ? node : report(index - 1, "A name selector here must be from a LET clause.");
485
563
  }
486
564
  const clauses =
487
565
  statement.kind === "AssumeProve"
@@ -519,10 +597,18 @@ const checkSelection = (
519
597
  state.isSufficesOpen = false;
520
598
  continue;
521
599
  }
522
- if (selector.kind !== "Operand") return;
523
- const operand = getOperandName(selector.operand);
600
+ if (selector.kind === "Colon") return node;
601
+ const operand =
602
+ selector.kind === "Operand"
603
+ ? getOperandName(selector.operand)
604
+ : selector.kind === "At"
605
+ ? "@"
606
+ : "!(...)";
607
+ const getPosition = (count: number) =>
608
+ selector.kind === "Operand" ? getOperandIndex(selector.operand, count) : -1;
609
+ const unexpectedNull = `An unexpected null node specified by '${operand}'.\nThis is probably due to a previous error.`;
524
610
  if (state.isSufficesOpen) {
525
- if (getOperandIndex(selector.operand, 1) !== 0) {
611
+ if (getPosition(1) !== 0) {
526
612
  return report(
527
613
  index,
528
614
  node.kind === "AssumeProve"
@@ -533,20 +619,37 @@ const checkSelection = (
533
619
  state.isSufficesOpen = false;
534
620
  continue;
535
621
  }
536
- if (node.kind === "NewSymbol") return;
622
+ if (node.kind === "NewSymbol") return node;
537
623
  if (node.kind !== "AssumeProve") {
538
624
  const expression = getLabelBody(node);
625
+ if (unresolvedExpressions.has(expression)) {
626
+ return report(
627
+ index,
628
+ "Subexpression selection failed, probably due to an error in the selected expression.",
629
+ );
630
+ }
539
631
  if (["Number", "Decimal", "String"].includes(expression.kind)) {
540
632
  return report(index, "Selecting subexpression of expression that has none.");
541
633
  }
542
- const kind =
543
- expression.kind === "Identifier"
544
- ? findBinding(expression.name, scope, unit)?.kind
545
- : undefined;
546
- if (kind === "Variable" || kind?.startsWith("New")) {
634
+ if (isEmptyExpression(expression)) {
547
635
  return report(index, `Choosing operand \`${operand}' of subexpression with no operands.`);
548
636
  }
549
- const sets = getBinder(expression)?.sets;
637
+ const binder = getBinder(expression);
638
+ if (binder && selector.kind !== "Operand") {
639
+ const count = selector.kind === "Bound" ? selector.args.length : 0;
640
+ if (selector.kind === "Bound" && count !== binder.names.length) {
641
+ return report(
642
+ index,
643
+ `Selector with ${count} argument(s) used for quantifier with ${binder.names.length} bound identifier(s).`,
644
+ );
645
+ }
646
+ params += binder.names.length;
647
+ args += count;
648
+ state.node = binder.body;
649
+ state.isGoal = false;
650
+ continue;
651
+ }
652
+ const sets = binder?.sets;
550
653
  const operands =
551
654
  expression.kind === "Identifier"
552
655
  ? []
@@ -554,18 +657,21 @@ const checkSelection = (
554
657
  ? sets.length > 0
555
658
  ? sets
556
659
  : undefined
557
- : expression.kind === "Except"
558
- ? undefined
559
- : getOperands(expression);
560
- if (!operands) return;
561
- const position = getOperandIndex(selector.operand, operands.length);
660
+ : getOperands(expression);
661
+ if (!operands) return node;
662
+ const isExcept = expression.kind === "Except";
663
+ const position = getPosition(isExcept ? expression.updates.length + 1 : operands.length);
562
664
  if (position === -1) return report(index, `Nonexistent operand specified by \`${operand}'.`);
665
+ if (isExcept && position > 0) {
666
+ return report(index, "Selecting subexpression of an EXCEPT not yet implemented.");
667
+ }
563
668
  state.node = operands[position];
564
669
  state.isGoal = false;
670
+ if (unresolvedExpressions.has(state.node)) return report(index, unexpectedNull);
565
671
  continue;
566
672
  }
567
673
  const clauses = [...node.assumptions, node.conclusion];
568
- const position = getOperandIndex(selector.operand, clauses.length);
674
+ const position = getPosition(clauses.length);
569
675
  if (position === -1) return report(index, `Nonexistent operand specified by \`${operand}'.`);
570
676
  if (isInScopeOfDeclaration(node, position) && (!state.isGoal || isOutOfScope)) {
571
677
  return report(index, `Accessing ASSUME/PROVE clause ${SCOPE_MESSAGE}`);
@@ -576,14 +682,24 @@ const checkSelection = (
576
682
  }
577
683
  state.node = clause;
578
684
  state.isGoal = false;
685
+ if (
686
+ clause.kind !== "NewSymbol" &&
687
+ clause.kind !== "AssumeProve" &&
688
+ unresolvedExpressions.has(clause)
689
+ ) {
690
+ return report(index, unexpectedNull);
691
+ }
579
692
  }
580
- if (isFact) return;
581
693
  if (state.node.kind === "AssumeProve") {
582
- report(undefined, "Selected ASSUME/PROVE instead of expression.");
694
+ return isFact ? state.node : report(undefined, "Selected ASSUME/PROVE instead of expression.");
583
695
  }
584
696
  if (state.node.kind === "NewSymbol") {
585
- report(undefined, "Selected a NEW declaration as an expression or operator.");
697
+ return isFact
698
+ ? state.node
699
+ : report(undefined, "Selected a NEW declaration as an expression or operator.");
586
700
  }
701
+ if (params !== args) return report(undefined, `Expected ${params} arguments but found ${args}.`);
702
+ return state.node;
587
703
  };
588
704
 
589
705
  const isLabelReported = (label: LabelExpression, unit: Unit) => {
@@ -659,10 +775,18 @@ const checkReference = (
659
775
  const first = selectors[0];
660
776
  const goal =
661
777
  selectors.length > 1 && first.kind === "Name"
662
- ? (lookupLocal(scope, first.name)?.goal ?? unit.goals.get(first.name))
778
+ ? (lookupLocal(scope, first.name)?.goal ?? getGoal(first.name, unit))
663
779
  : undefined;
664
- if (goal) checkSelection(expression, selectors, goal, scope, unit, isFact);
665
- return goal !== undefined;
780
+ return goal && { node: checkSelection(expression, selectors, goal, unit, isFact) };
781
+ };
782
+
783
+ const isInstanceName = (name: string, scope: LocalName | undefined, unit: Unit) => {
784
+ const binding = lookupLocal(scope, name) ?? getModuleBinding(name, unit, undefined);
785
+ if (binding) return binding.kind === "Instance";
786
+ return (
787
+ findInstance(name, scope, unit) !== undefined &&
788
+ [...unit.bindings.keys()].some((key) => key.startsWith(`${name}!`))
789
+ );
666
790
  };
667
791
 
668
792
  const getSymbolArity = (
@@ -677,16 +801,38 @@ const getSymbolArity = (
677
801
  if (renamed !== undefined) return renamed;
678
802
  if (isKey(name)) return expression.kind === "Apply" ? expression.args.length : 0;
679
803
  const local = lookupLocal(scope, name);
680
- if (local?.isNonFact) {
804
+ if (local?.nonFactStep) {
681
805
  unit.errors.push({
682
806
  location: formatRange(getSpelledNameRange(expression, name)),
683
807
  message: "Step number of non-expression step used as an expression.",
684
808
  });
685
809
  return undefined;
686
810
  }
811
+ const keyword = local?.goal?.keyword;
812
+ if (keyword) {
813
+ unit.errors.push({
814
+ location: formatRange(getSpelledNameRange(expression, name)),
815
+ message: `${keyword} proof step selected instead of expression.`,
816
+ });
817
+ return undefined;
818
+ }
687
819
  if (checkReference(expression, scope, unit, false) || (isStepName(name) && local)) {
688
820
  return expression.kind === "Apply" ? expression.args.length : 0;
689
821
  }
822
+ if (isInstanceName(name, scope, unit)) {
823
+ const range = getSpelledNameRange(expression, name);
824
+ unit.errors.push({
825
+ location: formatRange({
826
+ ...range,
827
+ start: {
828
+ line: range.end.line,
829
+ column: range.end.column - name.slice(name.lastIndexOf("!") + 1).length + 1,
830
+ },
831
+ }),
832
+ message: `Operator name ${name} is incomplete.`,
833
+ });
834
+ return undefined;
835
+ }
690
836
  if (local && expression.kind !== "OperatorReference") expression.resolution = LOCAL_RESOLUTION;
691
837
  if (local) return local.arity;
692
838
  const symbol = findSymbol(name, unit);
@@ -697,29 +843,55 @@ const getSymbolArity = (
697
843
  return symbol.arity;
698
844
  }
699
845
  const prefix = name.includes("!") ? name.slice(0, name.indexOf("!")) : "";
700
- const isSelected =
846
+ const selected =
847
+ prefix === "" ? undefined : (lookupLocal(scope, prefix) ?? findSymbol(prefix, unit));
848
+ if (selected && !SELECTABLE_KINDS.has(selected.kind)) {
849
+ reportUnselectable(
850
+ prefix,
851
+ (expression.kind !== "OperatorReference" && expression.selectorRanges?.[0]) ||
852
+ getSpelledNameRange(expression, name),
853
+ unit,
854
+ );
855
+ return undefined;
856
+ }
857
+ if (
858
+ expression.kind !== "OperatorReference" &&
701
859
  prefix !== "" &&
702
- (lookupLocal(scope, prefix) !== undefined ||
703
- findSymbol(prefix, unit) !== undefined ||
704
- unit.facts.has(prefix));
705
- if (isSelected) {
860
+ isPendingSelectionReported(
861
+ prefix,
862
+ expression.kind === "Apply" && expression.argumentCounts
863
+ ? expression.args.slice(0, expression.argumentCounts[0])
864
+ : [],
865
+ expression.selectorRanges?.[0],
866
+ (expression.kind === "Apply" ? expression.argumentRanges?.[0] : undefined) ?? location.range,
867
+ scope,
868
+ unit,
869
+ )
870
+ ) {
871
+ return undefined;
872
+ }
873
+ if (selected || (prefix !== "" && isFact(prefix, unit))) {
706
874
  return expression.kind === "Apply" ? expression.args.length : 0;
707
875
  }
708
- const spelling = (expression.kind === "Identifier" ? undefined : expression.spelling) ?? name;
709
- const range = formatRange(
710
- expression.kind === "Apply" && spelling === "-."
711
- ? getNameRange(location, "-")
712
- : getSpelledNameRange(expression, name),
713
- );
714
- if (!isOperatorSymbol(name) || isStepName(name)) {
715
- unit.errors.push({ location: range, message: `Unknown operator: \`${name}'.` });
876
+ const fixity = getFixity(expression);
877
+ const isOperatorApplication = expression.kind === "OperatorReference" || fixity !== undefined;
878
+ if (!isOperatorSymbol(name) || isStepName(name) || !isOperatorApplication) {
879
+ unit.errors.push({
880
+ location: formatRange(getSpelledNameRange(expression, name)),
881
+ message: `Unknown operator: \`${resolveSynonym(name)}'.`,
882
+ });
716
883
  return undefined;
717
884
  }
885
+ const spelling = expression.spelling ?? name;
718
886
  unit.errors.push({
719
- location: range,
887
+ location: formatRange(
888
+ fixity === "prefix" && spelling === "-."
889
+ ? getNameRange(location, "-")
890
+ : getSpelledNameRange(expression, name),
891
+ ),
720
892
  message: `Could not find declaration or definition of symbol '${spelling}'.`,
721
893
  });
722
- const fixity = getFixity(expression);
894
+ if (fixity) unresolvedExpressions.add(expression);
723
895
  if (fixity && location.range) {
724
896
  unit.errors.push({
725
897
  location: formatRange(location.range),
@@ -774,15 +946,30 @@ const resolveDefinition = (
774
946
  const isDeclared = current?.isPending === true && recursive.has(current);
775
947
  if (current?.isPending && !isDeclared) {
776
948
  report(
777
- `Recursive ${definition.kind === "Function" ? "function" : "operator"} ${name} defined at wrong LET/IN level.`,
949
+ `Recursive ${definition.kind === "Function" ? "function" : "operator"} ${resolveSynonym(name)} defined at wrong LET/IN level.`,
778
950
  );
779
951
  } else if (current && !isDeclared) {
780
952
  report(
781
953
  definition.kind === "Function"
782
954
  ? `Function name \`${name}' already defined or declared.`
783
- : `Operator ${name} already defined or declared.`,
955
+ : `Operator ${resolveSynonym(name)} already defined or declared.`,
956
+ );
957
+ } else if (current && definition.kind === "Function" && current.arity > 0) {
958
+ report(`Function ${resolveSynonym(name)} has operator arguments in its RECURSIVE declaration.`);
959
+ } else if (
960
+ current &&
961
+ definition.kind === "Operator" &&
962
+ // Deviation from SANY: Generator#processOperator compares only the last parameter's arity with the RECURSIVE declaration's.
963
+ (current.arity !== definition.params.length ||
964
+ definition.params.some((param) => param.arity > 0))
965
+ ) {
966
+ report(
967
+ `Definition of ${resolveSynonym(name)} has different arity than its RECURSIVE declaration.`,
784
968
  );
785
969
  }
970
+ if (current && isDeclared && definition.kind === "Operator") {
971
+ current.params = getParamArities(definition);
972
+ }
786
973
  if (definition.kind === "Function") {
787
974
  resolveExpression(
788
975
  definition.body,
@@ -793,8 +980,10 @@ const resolveDefinition = (
793
980
  definition.isSelfReferential = isReferenced(definition.body, name);
794
981
  } else resolveExpression(definition.body, inner, unit);
795
982
  if (current && isDeclared) {
796
- current.isPending = false;
797
- current.range = range;
983
+ if (definition.kind === "Operator" || current.arity === 0) {
984
+ current.isPending = false;
985
+ current.range = range;
986
+ }
798
987
  return false;
799
988
  }
800
989
  return definition.kind === "Function"
@@ -812,10 +1001,15 @@ const resolveDefinitions = (
812
1001
  scope: LocalName | undefined,
813
1002
  unit: Unit,
814
1003
  instances: Instance[] = [],
1004
+ declarations: Declaration[] = [],
815
1005
  ) => {
816
1006
  const recursive = new Set<Binding>();
817
1007
  const declared = definitions
818
- .filter((definition) => definition.isRecursive)
1008
+ .filter(
1009
+ (definition) =>
1010
+ definition.isRecursive &&
1011
+ declarations.every((declaration) => declaration.name !== definition.name),
1012
+ )
819
1013
  .reduce<LocalName | undefined>((parent, definition) => {
820
1014
  if (lookupLocal(parent, definition.name)?.isPending) return parent;
821
1015
  const local: LocalName = {
@@ -829,20 +1023,47 @@ const resolveDefinitions = (
829
1023
  recursive.add(local);
830
1024
  return local;
831
1025
  }, scope);
832
- const pending = unit.isGenerated ? [] : [...instances];
833
- const resolveInstances = (
1026
+ const declaredLocals = new Map<Declaration, LocalName | undefined>();
1027
+ const bindDeclaration = (parent: LocalName | undefined, declaration: Declaration) => {
1028
+ const binding: Binding = {
1029
+ kind: "Definition",
1030
+ arity: declaration.arity,
1031
+ params: Array(declaration.arity).fill(0),
1032
+ range: declaration.location.range,
1033
+ };
1034
+ const local: LocalName | undefined = isBindable(
1035
+ declaration.name,
1036
+ lookupLocal(parent, declaration.name) ??
1037
+ getModuleBinding(declaration.name, unit, binding.range),
1038
+ binding,
1039
+ unit,
1040
+ )
1041
+ ? { ...binding, name: declaration.name, parent, isPending: true }
1042
+ : undefined;
1043
+ if (local) recursive.add(local);
1044
+ declaredLocals.set(declaration, local);
1045
+ return local ?? parent;
1046
+ };
1047
+ const pending = [...(unit.isGenerated ? [] : instances), ...declarations].toSorted(
1048
+ (left, right) => compareLocations(left.location, right.location),
1049
+ );
1050
+ const resolvePending = (
834
1051
  current: LocalName | undefined,
835
- isDue: (instance: Instance) => boolean,
1052
+ isDue: (item: Instance | Declaration) => boolean,
836
1053
  ) => {
837
- const count = pending.findIndex((instance) => !isDue(instance));
1054
+ const count = pending.findIndex((item) => !isDue(item));
838
1055
  return pending
839
1056
  .splice(0, count === -1 ? pending.length : count)
840
- .reduce((parent, instance) => resolveLocalInstance(instance, parent, unit), current);
1057
+ .reduce(
1058
+ (parent, item) =>
1059
+ "kind" in item ? resolveLocalInstance(item, parent, unit) : bindDeclaration(parent, item),
1060
+ current,
1061
+ );
841
1062
  };
842
1063
  const resolved = definitions.reduce<LocalName | undefined>((previous, definition) => {
843
1064
  const current = isKey(definition.name)
844
1065
  ? previous
845
- : resolveInstances(previous, (instance) => !isBefore(definition.location, instance.location));
1066
+ : resolvePending(previous, (item) => !isBefore(definition.location, item.location));
846
1067
  const local: LocalName = {
847
1068
  name: definition.name,
848
1069
  arity: getArity(definition),
@@ -850,7 +1071,7 @@ const resolveDefinitions = (
850
1071
  range: definition.location.range,
851
1072
  parent: current,
852
1073
  };
853
- if (isInstantiated(definition)) return local;
1074
+ if (isInstantiated(definition)) return { ...local, params: getParamArities(definition) };
854
1075
  const isInstanced = instances.some((instance) => instance.location === definition.location);
855
1076
  const isGenerated = unit.isGenerated || definition.isLocal || isKey(definition.name);
856
1077
  const inner = isInstanced
@@ -862,7 +1083,17 @@ const resolveDefinitions = (
862
1083
  ? { ...local, params: getParamArities(definition) }
863
1084
  : current;
864
1085
  }, declared);
865
- return resolveInstances(resolved, () => true);
1086
+ const resolvedScope = resolvePending(resolved, () => true);
1087
+ declaredLocals.forEach((local, declaration) => {
1088
+ const range = declaration.location.range;
1089
+ if (range && !unit.isGenerated && (!local || local.isPending)) {
1090
+ unit.errors.push({
1091
+ location: formatRange(range),
1092
+ message: `Symbol ${resolveSynonym(declaration.name)} declared in RECURSIVE statement but not defined.`,
1093
+ });
1094
+ }
1095
+ });
1096
+ return resolvedScope;
866
1097
  };
867
1098
 
868
1099
  const findInstance = (name: string, scope: LocalName | undefined, unit: Unit) => {
@@ -871,7 +1102,9 @@ const findInstance = (name: string, scope: LocalName | undefined, unit: Unit) =>
871
1102
  prefix === name
872
1103
  ? undefined
873
1104
  : (lookupLocal(scope, prefix) ?? getModuleBinding(prefix, unit, undefined));
874
- return binding?.kind === "Instance" ? { name: prefix, arity: binding.arity } : undefined;
1105
+ return binding?.kind === "Instance"
1106
+ ? { name: prefix, arity: binding.arity, range: binding.range }
1107
+ : undefined;
875
1108
  };
876
1109
 
877
1110
  const isInstanceArityReported = (
@@ -879,16 +1112,22 @@ const isInstanceArityReported = (
879
1112
  scope: LocalName | undefined,
880
1113
  unit: Unit,
881
1114
  ) => {
882
- if (expression.kind !== "Identifier" && expression.kind !== "Apply") return false;
1115
+ if (!isReference(expression)) return false;
1116
+ const selectors = getSelectors(expression);
1117
+ const nameCount = selectors.findIndex((selector) => selector.kind !== "Name");
883
1118
  const instance = findInstance(
884
- expression.kind === "Identifier" ? expression.name : expression.operator,
1119
+ selectors
1120
+ .slice(0, nameCount === -1 ? selectors.length : nameCount)
1121
+ .flatMap((selector) => (selector.kind === "Name" ? [selector.name] : []))
1122
+ .join("!"),
885
1123
  scope,
886
1124
  unit,
887
1125
  );
888
- const count = expression.kind === "Apply" ? (expression.argumentCounts?.[0] ?? 0) : 0;
1126
+ const first = selectors[0];
1127
+ const count = first.kind === "Name" ? first.args.length : 0;
889
1128
  if (!instance || count === instance.arity) return false;
890
1129
  const range =
891
- (expression.kind === "Apply" ? expression.argumentRanges?.[0] : undefined) ??
1130
+ (expression.kind === "Identifier" ? undefined : expression.argumentRanges?.[0]) ??
892
1131
  expression.location.range;
893
1132
  if (range) {
894
1133
  unit.errors.push({
@@ -899,104 +1138,210 @@ const isInstanceArityReported = (
899
1138
  return true;
900
1139
  };
901
1140
 
902
- // Deviation from SANY: an operator whose parameters tla-ts does not know takes any argument.
1141
+ const isArgumentCountReported = (
1142
+ callee: Binding | undefined,
1143
+ name: string,
1144
+ count: number,
1145
+ range: SourceRange | undefined,
1146
+ unit: Unit,
1147
+ ) => {
1148
+ const params = callee?.kind === "Definition" ? callee.params : undefined;
1149
+ if (!callee || !params || params.length === callee.arity) return false;
1150
+ if (range && !unit.isGenerated) {
1151
+ unit.errors.push({
1152
+ location: formatRange(range),
1153
+ message: `Wrong number of arguments (${count}) given to operator '${resolveSynonym(name)}', \nwhich requires ${params.length} arguments.`,
1154
+ });
1155
+ }
1156
+ return true;
1157
+ };
1158
+
1159
+ const resolveExpressionArgument = (arg: Expression, scope: LocalName | undefined, unit: Unit) => {
1160
+ const range = arg.location.range;
1161
+ const report = (message: string) => {
1162
+ if (range) unit.errors.push({ location: formatRange(range), message });
1163
+ };
1164
+ const selectionError = operatorSelectionErrors.get(arg);
1165
+ // Deviation from SANY: SANY names its internal node kind here, where tla-ts words it as for a name.
1166
+ if (arg.kind === "Lambda" && arg.operator !== undefined) {
1167
+ report(`The operator ${resolveSynonym(arg.operator)} requires 1 arguments.`);
1168
+ } else if (selectionError) {
1169
+ unit.errors.push(selectionError);
1170
+ } else if (arg.kind === "Lambda" && range) {
1171
+ unresolvedExpressions.add(arg);
1172
+ report("LAMBDA expression used where an expression is required.");
1173
+ } else if (arg.kind === "OperatorReference") {
1174
+ const argArity = getSymbolArity(arg, arg.operator, scope, unit);
1175
+ if (argArity !== undefined) {
1176
+ report(`The operator ${resolveSynonym(arg.operator)} requires ${argArity} arguments.`);
1177
+ }
1178
+ } else resolveExpression(arg, scope, unit);
1179
+ };
1180
+
1181
+ const matchArgument = (
1182
+ arg: Expression,
1183
+ expected: number,
1184
+ index: number,
1185
+ operator: string,
1186
+ operatorRange: SourceRange | undefined,
1187
+ scope: LocalName | undefined,
1188
+ unit: Unit,
1189
+ ) => {
1190
+ const report = (range: SourceRange | undefined, message: string) => {
1191
+ if (range) unit.errors.push({ location: formatRange(range), message });
1192
+ };
1193
+ const reportOperatorArity = (name: string, arity: number) => {
1194
+ const definition =
1195
+ findInstance(operator, scope, unit)?.range ?? findBinding(operator, scope, unit)?.range;
1196
+ if (!definition) return;
1197
+ report(
1198
+ operatorRange,
1199
+ `Operator with incorrect arity passed as argument. \nOperator '${resolveSynonym(name)}' of arity ${arity} is argument number ${index + 1} (counting from 1) to operator \`${formatRange(definition)}', \nbut an operator of arity ${expected} was expected.`,
1200
+ );
1201
+ };
1202
+ const range = arg.location.range;
1203
+ if (expected === 0) {
1204
+ resolveExpressionArgument(arg, scope, unit);
1205
+ return true;
1206
+ }
1207
+ const parenthesized = parenthesizedRanges.get(arg);
1208
+ if (parenthesized) {
1209
+ report(
1210
+ parenthesized,
1211
+ `An expression appears as argument number ${index + 1} (counting from 1) to operator '${operator}', in a position an operator is required.`,
1212
+ );
1213
+ return false;
1214
+ }
1215
+ const reference = selections.get(arg) ?? arg;
1216
+ // SANY reads a reference that ends in arguments as an application, not as a selector's arguments.
1217
+ const selectors =
1218
+ reference.kind === "Subexpression" ||
1219
+ (reference.kind === "Apply" && reference.argumentCounts?.at(-1) === 0)
1220
+ ? getSelectors(reference)
1221
+ : [];
1222
+ const selectorIndex = selectors.findIndex(
1223
+ (selector) => "args" in selector && selector.args.length > 0,
1224
+ );
1225
+ if (selectorIndex !== -1 && isReference(reference)) {
1226
+ const selector = selectors[selectorIndex];
1227
+ report(
1228
+ reference.selectorRanges?.[selectorIndex],
1229
+ `Selector \`${selector.kind === "Name" ? selector.name : "!(...)"}' should not have argument(s).`,
1230
+ );
1231
+ return false;
1232
+ }
1233
+ if (arg.kind === "Lambda") {
1234
+ if (selections.has(arg)) resolveExpression(arg, scope, unit);
1235
+ else resolveLambda(arg, scope, unit);
1236
+ if (findNullError(nullSelections.get(arg))) return false;
1237
+ const isMatched = arg.params.length === expected;
1238
+ if (!isMatched && selections.has(arg)) {
1239
+ report(range, `Expected arity ${expected} but found operator of arity ${arg.params.length}.`);
1240
+ } else if (!isMatched && range && arg.operator === undefined) {
1241
+ report(
1242
+ operatorRange,
1243
+ `Lambda expression with arity ${arg.params.length} used as argument ${index + 1} of operator \`${operator}', \nbut an operator of arity ${expected} is required.`,
1244
+ );
1245
+ } else if (!isMatched && arg.operator !== undefined) {
1246
+ reportOperatorArity(arg.operator, arg.params.length);
1247
+ }
1248
+ return isMatched;
1249
+ }
1250
+ if (reference !== arg) {
1251
+ const failed = findNullError(nullSelections.get(arg));
1252
+ if (failed) unit.errors.push(failed);
1253
+ if (!failed) {
1254
+ report(reference.location.range, `Expected arity ${expected} but found operator of arity 0.`);
1255
+ }
1256
+ return false;
1257
+ }
1258
+ if (arg.kind === "Subexpression") {
1259
+ resolveExpression(arg, scope, unit);
1260
+ return false;
1261
+ }
1262
+ if (arg.kind !== "Identifier" && arg.kind !== "OperatorReference") {
1263
+ report(
1264
+ range,
1265
+ `An expression appears as argument number ${index + 1} (counting from 1) to operator '${operator}', in a position an operator is required.`,
1266
+ );
1267
+ return false;
1268
+ }
1269
+ const name = arg.kind === "Identifier" ? arg.name : arg.operator;
1270
+ const argParams = findBinding(name, scope, unit)?.params ?? [];
1271
+ const argArity = getSymbolArity(arg, name, scope, unit);
1272
+ if (arg.kind === "Identifier" && argArity !== undefined && argArity !== expected) {
1273
+ report(
1274
+ getSpelledNameRange(arg, name),
1275
+ `Expected arity ${expected} but found operator of arity ${argArity}.`,
1276
+ );
1277
+ }
1278
+ if (arg.kind === "OperatorReference" && argArity !== undefined && argArity !== expected) {
1279
+ reportOperatorArity(name, argArity);
1280
+ }
1281
+ // Deviation from SANY: OpDefNode#matchingOpArgOperand reads as many parameters as a RECURSIVE declaration gives and crashes when the definition has fewer.
1282
+ return argArity === expected && argParams.every((param) => param === 0);
1283
+ };
1284
+
903
1285
  const resolveApply = (
904
1286
  expression: Expression & { kind: "Apply" },
905
1287
  scope: LocalName | undefined,
906
1288
  unit: Unit,
907
1289
  ) => {
908
- if (isInstanceArityReported(expression, scope, unit)) return;
909
1290
  const operator = expression.operator;
910
1291
  const callee = findBinding(operator, scope, unit);
911
- const arity = getSymbolArity(expression, operator, scope, unit);
912
- if (arity === undefined) return;
913
- if (arity !== expression.args.length) {
1292
+ const arity = isInstanceArityReported(expression, scope, unit)
1293
+ ? undefined
1294
+ : getSymbolArity(expression, operator, scope, unit);
1295
+ if (arity !== undefined && arity !== expression.args.length) {
914
1296
  unit.errors.push({
915
1297
  location: formatRange(expression.argumentsRange ?? getSpelledNameRange(expression, operator)),
916
- message: `The operator ${operator} requires ${arity - (findInstance(operator, scope, unit)?.arity ?? 0)} arguments.`,
1298
+ message: `The operator ${resolveSynonym(operator)} requires ${arity - (findInstance(operator, scope, unit)?.arity ?? 0)} arguments.`,
917
1299
  });
1300
+ }
1301
+ if (arity !== expression.args.length) {
1302
+ emptyExpressions.add(expression);
918
1303
  return;
919
1304
  }
920
- const params = callee && (callee.kind === "Definition" ? callee.params : []);
1305
+ const params =
1306
+ callee && (callee.kind === "Definition" ? callee.params : expression.args.map(() => 0));
921
1307
  if (params === undefined) {
922
1308
  expression.args.forEach((arg) => resolveArgument(arg, scope, unit));
923
1309
  return;
924
1310
  }
925
- const report = (range: SourceRange | undefined, message: string) => {
926
- if (range) unit.errors.push({ location: formatRange(range), message });
927
- };
928
- expression.args
929
- .map((arg, index) => {
930
- const expected = params[index] ?? 0;
931
- const range = arg.location.range;
932
- if (expected === 0) {
933
- // Deviation from SANY: SANY fails here with an internal error; tla-ts words it as for a name.
934
- if (arg.kind === "Lambda" && arg.operator !== undefined) {
935
- report(range, `The operator ${arg.operator} requires 1 arguments.`);
936
- } else if (arg.kind === "Lambda" && range) {
937
- report(range, "LAMBDA expression used where an expression is required.");
938
- } else if (arg.kind === "OperatorReference") {
939
- const argArity = getSymbolArity(arg, arg.operator, scope, unit);
940
- if (argArity !== undefined) {
941
- report(range, `The operator ${arg.operator} requires ${argArity} arguments.`);
942
- }
943
- } else resolveExpression(arg, scope, unit);
944
- return true;
945
- }
946
- if (arg.kind === "Lambda") {
947
- resolveExpression(arg, scope, unit);
948
- const isMatched = arg.params.length === expected;
949
- if (!isMatched && selections.has(arg)) {
950
- report(
951
- range,
952
- `Expected arity ${expected} but found operator of arity ${arg.params.length}.`,
953
- );
954
- } else if (!isMatched && range && arg.operator === undefined) {
955
- report(
956
- expression.selectorRanges?.at(-1) ?? getSpelledNameRange(expression, operator),
957
- `Lambda expression with arity ${arg.params.length} used as argument ${index + 1} of operator \`${operator}', \nbut an operator of arity ${expected} is required.`,
958
- );
959
- }
960
- return isMatched;
961
- }
962
- if (arg.kind === "Subexpression") {
963
- resolveExpression(arg, scope, unit);
964
- return true;
965
- }
966
- if (arg.kind === "Apply" && arg.argumentCounts?.at(-1) === 0) {
967
- const selectorIndex = arg.argumentCounts.findIndex((count) => count > 0);
968
- report(
969
- arg.selectorRanges?.[selectorIndex],
970
- `Selector \`${arg.operator.split("!")[selectorIndex]}' should not have argument(s).`,
971
- );
972
- return false;
973
- }
974
- if (arg.kind !== "Identifier" && arg.kind !== "OperatorReference") {
975
- report(
976
- range,
977
- `An expression appears as argument number ${index + 1} (counting from 1) to operator '${operator}', in a position an operator is required.`,
978
- );
979
- return false;
980
- }
981
- const name = arg.kind === "Identifier" ? arg.name : arg.operator;
982
- const argParams = findBinding(name, scope, unit)?.params ?? [];
983
- const argArity = getSymbolArity(arg, name, scope, unit);
984
- if (arg.kind === "Identifier" && argArity !== undefined && argArity !== expected) {
985
- report(
986
- getSpelledNameRange(arg, name),
987
- `Expected arity ${expected} but found operator of arity ${argArity}.`,
988
- );
989
- }
990
- return argArity === expected && argParams.every((param) => param === 0);
991
- })
992
- .forEach((isMatched, index) => {
993
- if (!isMatched) {
994
- report(
995
- expression.location.range,
996
- `Argument number ${index + 1} to operator '${operator}' \nshould be a ${params[index]}-parameter operator.`,
997
- );
998
- }
999
- });
1311
+ const operatorRange =
1312
+ expression.selectorRanges?.at(-1) ?? getSpelledNameRange(expression, operator);
1313
+ const isSelection = operator === SELECTION_NAME;
1314
+ const matches = expression.args.slice(0, params.length).map((arg, index) => {
1315
+ const source = isSelection ? selectionArguments.get(arg) : undefined;
1316
+ return matchArgument(
1317
+ arg,
1318
+ params[index],
1319
+ source?.index ?? index,
1320
+ source?.operator ?? operator,
1321
+ source?.range ?? operatorRange,
1322
+ scope,
1323
+ isSelection ? { ...unit, isGenerated: false } : unit,
1324
+ );
1325
+ });
1326
+ if (
1327
+ isArgumentCountReported(
1328
+ callee,
1329
+ operator,
1330
+ expression.args.length,
1331
+ expression.location.range,
1332
+ unit,
1333
+ )
1334
+ ) {
1335
+ return;
1336
+ }
1337
+ matches.forEach((isMatched, index) => {
1338
+ if (!isMatched && expression.location.range) {
1339
+ unit.errors.push({
1340
+ location: formatRange(expression.location.range),
1341
+ message: `Argument number ${index + 1} to operator '${isSelection ? "LAMBDA" : operator}' \nshould be a ${params[index]}-parameter operator.`,
1342
+ });
1343
+ }
1344
+ });
1000
1345
  };
1001
1346
 
1002
1347
  const resolveArgument = (arg: Expression, scope: LocalName | undefined, unit: Unit) => {
@@ -1007,17 +1352,50 @@ const resolveArgument = (arg: Expression, scope: LocalName | undefined, unit: Un
1007
1352
  const isSelectionReported = (expression: Expression, scope: LocalName | undefined, unit: Unit) => {
1008
1353
  const failed = selectionErrors.get(expression);
1009
1354
  if (!failed) return false;
1010
- failed.args.forEach((arg) => resolveArgument(arg, scope, unit));
1011
- unit.errors.push(failed.error);
1355
+ failed.applications.forEach((application) =>
1356
+ application.args
1357
+ .slice(0, application.params.length)
1358
+ .forEach((arg, index) =>
1359
+ matchArgument(
1360
+ arg,
1361
+ application.params[index],
1362
+ index,
1363
+ application.operator,
1364
+ application.range,
1365
+ scope,
1366
+ unit,
1367
+ ),
1368
+ ),
1369
+ );
1370
+ unit.errors.push(findNullError(failed.nulls) ?? failed.error);
1012
1371
  return true;
1013
1372
  };
1014
1373
 
1374
+ const resolveLambda = (
1375
+ expression: Expression & { kind: "Lambda" },
1376
+ scope: LocalName | undefined,
1377
+ unit: Unit,
1378
+ ) =>
1379
+ resolveExpression(
1380
+ expression.body,
1381
+ bindNames(scope, expression.params, expression.paramRanges, unit),
1382
+ {
1383
+ ...unit,
1384
+ labelParams: [...unit.labelParams, ...expression.params],
1385
+ },
1386
+ );
1387
+
1015
1388
  const resolveExpression = (
1016
1389
  expression: Expression,
1017
1390
  scope: LocalName | undefined,
1018
1391
  unit: Unit,
1019
1392
  ): void => {
1020
1393
  if (selections.has(expression) && !unit.isGenerated) {
1394
+ const failed = findNullError(nullSelections.get(expression));
1395
+ if (failed) {
1396
+ unit.errors.push(failed);
1397
+ return;
1398
+ }
1021
1399
  resolveExpression(expression, scope, { ...unit, isGenerated: true });
1022
1400
  return;
1023
1401
  }
@@ -1031,18 +1409,43 @@ const resolveExpression = (
1031
1409
  case "Number":
1032
1410
  case "Decimal":
1033
1411
  case "String":
1412
+ return;
1034
1413
  case "ExceptAt":
1414
+ if (!unit.isInExcept && expression.location.range) {
1415
+ emptyExpressions.add(expression);
1416
+ unit.errors.push({
1417
+ location: formatRange(expression.location.range),
1418
+ message: "@ used where its meaning is not defined.",
1419
+ });
1420
+ }
1035
1421
  return;
1036
1422
  case "Identifier": {
1037
- if (isInstanceArityReported(expression, scope, unit)) return;
1038
1423
  const name = expression.name;
1039
- const arity = getSymbolArity(expression, name, scope, unit);
1040
- if (arity !== undefined && arity > 0) {
1424
+ const arity = isInstanceArityReported(expression, scope, unit)
1425
+ ? undefined
1426
+ : getSymbolArity(expression, name, scope, unit);
1427
+ if (arity === 0) {
1428
+ const binding = findBinding(name, scope, unit);
1429
+ const kind = binding?.kind;
1430
+ // SANY's selector chooses no operand of a variable, theorem, step or NEW symbol, unlike of a constant or definition.
1431
+ if (
1432
+ kind === "Variable" ||
1433
+ kind === "Theorem" ||
1434
+ kind?.startsWith("New") ||
1435
+ isFact(name, unit)
1436
+ ) {
1437
+ emptyExpressions.add(expression);
1438
+ }
1439
+ isArgumentCountReported(binding, name, 0, getSpelledNameRange(expression, name), unit);
1440
+ return;
1441
+ }
1442
+ if (arity !== undefined) {
1041
1443
  unit.errors.push({
1042
1444
  location: formatRange(getSpelledNameRange(expression, name)),
1043
- message: `The operator ${name} requires ${arity} arguments.`,
1445
+ message: `The operator ${resolveSynonym(name)} requires ${arity} arguments.`,
1044
1446
  });
1045
1447
  }
1448
+ emptyExpressions.add(expression);
1046
1449
  return;
1047
1450
  }
1048
1451
  case "OperatorReference":
@@ -1052,11 +1455,14 @@ const resolveExpression = (
1052
1455
  resolveApply(expression, scope, unit);
1053
1456
  return;
1054
1457
  case "Lambda":
1055
- resolveExpression(
1056
- expression.body,
1057
- bindNames(scope, expression.params, expression.paramRanges, unit),
1058
- bindLabelParams(expression.params),
1059
- );
1458
+ if (selections.has(expression)) resolveLambda(expression, scope, unit);
1459
+ else if (expression.location.range) {
1460
+ unresolvedExpressions.add(expression);
1461
+ unit.errors.push({
1462
+ location: formatRange(expression.location.range),
1463
+ message: "LAMBDA expression used where an expression is required.",
1464
+ });
1465
+ }
1060
1466
  return;
1061
1467
  case "And":
1062
1468
  case "Or":
@@ -1079,7 +1485,13 @@ const resolveExpression = (
1079
1485
  case "Let":
1080
1486
  resolveExpression(
1081
1487
  expression.body,
1082
- resolveDefinitions(expression.definitions, scope, unit, expression.instances),
1488
+ resolveDefinitions(
1489
+ expression.definitions,
1490
+ scope,
1491
+ unit,
1492
+ expression.instances,
1493
+ expression.recursive,
1494
+ ),
1083
1495
  unit,
1084
1496
  );
1085
1497
  return;
@@ -1169,34 +1581,286 @@ const resolveExpression = (
1169
1581
  resolveExpression(expression.body, scope, { ...unit, labelParams: [], labels: new Set() });
1170
1582
  checkLabel(expression, scope, unit);
1171
1583
  return;
1172
- case "Subexpression": {
1173
- if (isSelectionReported(expression, scope, unit)) return;
1174
- expression.selectors
1175
- .flatMap((selector) => ("args" in selector ? selector.args : []))
1176
- .forEach((arg) => resolveArgument(arg, scope, unit));
1177
- checkReference(expression, scope, unit, false);
1584
+ case "Subexpression":
1585
+ if (isSubexpressionReported(expression, scope, unit)) emptyExpressions.add(expression);
1586
+ return;
1587
+ case "Selection":
1588
+ return;
1589
+ }
1590
+ };
1591
+
1592
+ const isPendingSelectionReported = (
1593
+ name: string,
1594
+ args: Expression[],
1595
+ selectorRange: SourceRange | undefined,
1596
+ argumentsRange: SourceRange | undefined,
1597
+ scope: LocalName | undefined,
1598
+ unit: Unit,
1599
+ ) => {
1600
+ const pending = lookupLocal(scope, name) ?? getModuleBinding(name, unit, undefined);
1601
+ if (!pending?.isPending || !selectorRange || !argumentsRange) return false;
1602
+ if (args.length !== pending.arity) {
1603
+ unit.errors.push({
1604
+ location: formatRange(argumentsRange),
1605
+ message: `The operator ${name} requires ${pending.arity} arguments.`,
1606
+ });
1607
+ return true;
1608
+ }
1609
+ args.forEach((arg) => resolveExpression(arg, scope, unit));
1610
+ unit.errors.push({
1611
+ location: formatRange(selectorRange),
1612
+ message: `Subexpression of \`${name}' used inside the operator's definition.`,
1613
+ });
1614
+ return true;
1615
+ };
1616
+
1617
+ const isSubexpressionReported = (
1618
+ expression: Expression & { kind: "Subexpression" },
1619
+ scope: LocalName | undefined,
1620
+ unit: Unit,
1621
+ ) => {
1622
+ if (
1623
+ isInstanceArityReported(expression, scope, unit) ||
1624
+ isSelectionReported(expression, scope, unit)
1625
+ ) {
1626
+ return true;
1627
+ }
1628
+ const head = expression.selectors[0];
1629
+ const range = expression.selectorRanges?.[0];
1630
+ const nameCount = expression.selectors.findIndex((selector) => selector.kind !== "Name");
1631
+ const names = expression.selectors
1632
+ .slice(0, nameCount)
1633
+ .flatMap((selector) => (selector.kind === "Name" ? [selector.name] : []));
1634
+ const symbolIndex = names.findIndex(
1635
+ (_name, index) => index > 0 && findSymbol(names.slice(0, index + 1).join("!"), unit),
1636
+ );
1637
+ const isInstance =
1638
+ names.length > 1 &&
1639
+ (lookupLocal(scope, names[0]) ?? getModuleBinding(names[0], unit, undefined))?.kind ===
1640
+ "Instance";
1641
+ const lastRange = expression.selectorRanges?.[nameCount - 1];
1642
+ if (isInstance && symbolIndex === -1 && range && lastRange) {
1643
+ unit.errors.push({
1644
+ location: formatRange({ module: range.module, start: range.start, end: lastRange.end }),
1645
+ message: `Unknown operator: \`${resolveSynonym(names.join("!"))}'.`,
1646
+ });
1647
+ return true;
1648
+ }
1649
+ const name = names.slice(0, symbolIndex + 1).join("!");
1650
+ const symbol = symbolIndex > 0 ? findSymbol(name, unit) : undefined;
1651
+ const argumentCount = expression.selectors
1652
+ .slice(0, symbolIndex + 1)
1653
+ .flatMap((selector) => ("args" in selector ? selector.args : [])).length;
1654
+ const argumentRange = expression.argumentRanges?.[symbolIndex] ?? expression.location.range;
1655
+ if (symbol && symbol.arity !== argumentCount && argumentRange) {
1656
+ unit.errors.push({
1657
+ location: formatRange(argumentRange),
1658
+ message: `The operator ${resolveSynonym(name)} requires ${symbol.arity} arguments.`,
1659
+ });
1660
+ return true;
1661
+ }
1662
+ if (head.kind === "Name" && expression.selectors[1].kind !== "Name" && range) {
1663
+ const local = lookupLocal(scope, head.name);
1664
+ const binding = local ?? findSymbol(head.name, unit);
1665
+ if ((binding === undefined && !isFact(head.name, unit)) || binding?.kind === "Instance") {
1666
+ unit.errors.push({
1667
+ location: formatRange(range),
1668
+ message: `Unknown operator: \`${resolveSynonym(head.name)}'.`,
1669
+ });
1670
+ return true;
1671
+ }
1672
+ if (binding && (!SELECTABLE_KINDS.has(binding.kind) || local?.nonFactStep)) {
1673
+ reportUnselectable(head.name, range, unit);
1674
+ return true;
1178
1675
  }
1179
1676
  }
1677
+ if (
1678
+ head.kind === "Name" &&
1679
+ isPendingSelectionReported(
1680
+ head.name,
1681
+ head.args,
1682
+ range,
1683
+ expression.argumentRanges?.[0] ?? expression.location.range,
1684
+ scope,
1685
+ unit,
1686
+ )
1687
+ ) {
1688
+ return true;
1689
+ }
1690
+ expression.selectors
1691
+ .flatMap((selector) => ("args" in selector ? selector.args : []))
1692
+ .forEach((arg) => resolveArgument(arg, scope, unit));
1693
+ const selected = checkReference(expression, scope, unit, false);
1694
+ return selected ? selected.node === undefined : false;
1180
1695
  };
1181
1696
 
1182
- const checkFacts = (facts: Fact[], scope: LocalName | undefined, unit: Unit) =>
1183
- facts.forEach((fact) => {
1184
- if (
1185
- fact.kind === "ModuleFact" ||
1186
- isInstanceArityReported(fact, scope, unit) ||
1187
- checkReference(fact, scope, unit, true)
1188
- ) {
1189
- return;
1697
+ const reportUnknownModule = (fact: Fact & { kind: "ModuleFact" }, unit: Unit) => {
1698
+ const range = fact.location.range;
1699
+ if (unit.isModuleKnown(fact.name, fact.location) || !range) return;
1700
+ unit.errors.push({
1701
+ location: formatRange({
1702
+ ...range,
1703
+ start: { line: range.end.line, column: range.end.column - fact.name.length + 1 },
1704
+ }),
1705
+ message: `Module \`${fact.name}' used without being extended or instantiated.`,
1706
+ });
1707
+ };
1708
+
1709
+ const checkFact = (fact: Fact, reference: Fact, scope: LocalName | undefined, unit: Unit) => {
1710
+ if (fact.kind === "ModuleFact") {
1711
+ reportUnknownModule(fact, unit);
1712
+ return undefined;
1713
+ }
1714
+ if (fact.kind === "ExceptAt" && fact.location.range) {
1715
+ unit.errors.push({
1716
+ location: formatRange(fact.location.range),
1717
+ message: "Unknown operator: `@'.",
1718
+ });
1719
+ return BUILTIN_LOCATION;
1720
+ }
1721
+ const hidden = getHiddenExpressionLocation(fact, reference, scope, unit);
1722
+ if (selections.has(fact)) {
1723
+ resolveExpression(fact, scope, unit);
1724
+ return hidden;
1725
+ }
1726
+ if (isInstanceArityReported(fact, scope, unit)) return hidden;
1727
+ const selected = checkReference(fact, scope, unit, true);
1728
+ if (selected) {
1729
+ const kind = selected.node?.kind;
1730
+ if (kind === undefined) return BUILTIN_LOCATION;
1731
+ return kind === "AssumeProve" || kind === "NewSymbol"
1732
+ ? undefined
1733
+ : fact.location.range && formatRange(fact.location.range);
1734
+ }
1735
+ if (fact.kind === "Subexpression") {
1736
+ return isSubexpressionReported(fact, scope, unit) ? BUILTIN_LOCATION : hidden;
1737
+ }
1738
+ const name = fact.kind === "Identifier" ? fact.name : fact.kind === "Apply" ? fact.operator : "";
1739
+ if (fact.kind === "Identifier" && lookupLocal(scope, name)?.nonFactStep) {
1740
+ unit.errors.push({
1741
+ location: formatRange(getSpelledNameRange(fact, name)),
1742
+ message: "Step number of non-fact used as a fact",
1743
+ });
1744
+ return BUILTIN_LOCATION;
1745
+ }
1746
+ if (
1747
+ !isFact(name, unit) &&
1748
+ !lookupLocal(scope, name)?.goal &&
1749
+ !(fact.kind === "Identifier" && isInstanceName(name, scope, unit))
1750
+ ) {
1751
+ resolveExpression(fact, scope, unit);
1752
+ }
1753
+ return hidden;
1754
+ };
1755
+
1756
+ const isDefinitionEntry = (def: Fact, scope: LocalName | undefined, unit: Unit) => {
1757
+ if (def.kind === "ModuleFact") {
1758
+ reportUnknownModule(def, unit);
1759
+ return unit.isModuleKnown(def.name, def.location);
1760
+ }
1761
+ const range = def.location.range;
1762
+ const name =
1763
+ def.kind === "Identifier" ? def.name : def.kind === "OperatorReference" ? def.operator : "";
1764
+ if (name === "" || !range) return true;
1765
+ const local = lookupLocal(scope, name);
1766
+ const binding = local ?? findSymbol(name, unit) ?? getModuleBinding(name, unit, range);
1767
+ if (binding === undefined && isFact(name, unit)) return true;
1768
+ if (binding === undefined) {
1769
+ unit.errors.push({
1770
+ location: formatRange(range),
1771
+ message: `Unknown operator: \`${resolveSynonym(name)}'.`,
1772
+ });
1773
+ }
1774
+ if (local?.nonFactStep === "Define") return true;
1775
+ if (local?.nonFactStep) {
1776
+ unit.errors.push({
1777
+ location: formatRange(range),
1778
+ message: "DEF clause entry refers to a non-definition step.",
1779
+ });
1780
+ }
1781
+ if (binding && SELECTABLE_KINDS.has(binding.kind) && !isStepName(name)) return true;
1782
+ unit.errors.push({
1783
+ location: formatRange(range),
1784
+ message: "DEF clause entry should describe a defined operator.",
1785
+ });
1786
+ return false;
1787
+ };
1788
+
1789
+ const getHiddenExpressionLocation = (
1790
+ fact: Expression,
1791
+ reference: Fact,
1792
+ scope: LocalName | undefined,
1793
+ unit: Unit,
1794
+ ) => {
1795
+ const range = fact.location.range && formatRange(fact.location.range);
1796
+ if (selections.has(fact)) {
1797
+ return findNullError(nullSelections.get(fact))
1798
+ ? BUILTIN_LOCATION
1799
+ : reference.location.range && formatRange(reference.location.range);
1800
+ }
1801
+ if (selectionErrors.has(fact) || fact.kind === "ExceptAt") return BUILTIN_LOCATION;
1802
+ switch (fact.kind) {
1803
+ case "Number":
1804
+ case "String":
1805
+ case "Decimal":
1806
+ case "Let":
1807
+ case "Label":
1808
+ return undefined;
1809
+ case "Identifier":
1810
+ case "Apply":
1811
+ case "Subexpression": {
1812
+ const first = getSelectors(fact)[0];
1813
+ if (fact.kind === "Subexpression" || first.kind !== "Name") return undefined;
1814
+ const name = fact.kind === "Identifier" ? fact.name : fact.operator;
1815
+ const goal = lookupLocal(scope, first.name)?.goal ?? getGoal(first.name, unit);
1816
+ if (
1817
+ isFact(name, unit) ||
1818
+ goal ||
1819
+ (isStepName(name) && lookupLocal(scope, name)) ||
1820
+ (fact.kind === "Identifier" && isInstanceName(name, scope, unit))
1821
+ ) {
1822
+ return undefined;
1823
+ }
1824
+ const binding = findBinding(name, scope, unit);
1825
+ const count = fact.kind === "Apply" ? fact.args.length : 0;
1826
+ // Deviation from SANY: UseOrHideNode#factCheck crashes on a fact whose operator Generator#generateExpression could not resolve, where tla-ts reports it like a null node.
1827
+ return binding?.arity === count ? range : BUILTIN_LOCATION;
1190
1828
  }
1191
- const name =
1192
- fact.kind === "Identifier" ? fact.name : fact.kind === "Apply" ? fact.operator : "";
1193
- if (fact.kind === "Identifier" && lookupLocal(scope, name)?.isNonFact) {
1829
+ default:
1830
+ return range;
1831
+ }
1832
+ };
1833
+
1834
+ const checkUseOrHide = (
1835
+ statement: UseOrHide | Extract<Proof, { kind: "By" }>,
1836
+ scope: LocalName | undefined,
1837
+ unit: Unit,
1838
+ ) => {
1839
+ const references = factReferences.get(statement.facts) ?? statement.facts;
1840
+ const hidden = statement.facts.map((fact, index) =>
1841
+ checkFact(fact, references[index], scope, unit),
1842
+ );
1843
+ const factCount = statement.facts.filter(
1844
+ (fact) => fact.kind !== "ModuleFact" || unit.isModuleKnown(fact.name, fact.location),
1845
+ ).length;
1846
+ const defCount = statement.defs.filter((def) => isDefinitionEntry(def, scope, unit)).length;
1847
+ hidden.forEach((location) => {
1848
+ if (location && statement.kind === "Hide") {
1194
1849
  unit.errors.push({
1195
- location: formatRange(getSpelledNameRange(fact, name)),
1196
- message: "Step number of non-fact used as a fact",
1850
+ location,
1851
+ message:
1852
+ "The only expression allowed as a fact in a HIDE is \nthe name of a theorem, assumption, or step.",
1197
1853
  });
1198
- } else if (!unit.facts.has(name)) resolveExpression(fact, scope, unit);
1854
+ }
1199
1855
  });
1856
+ const range = statement.location.range;
1857
+ if (factCount + defCount === 0 && range) {
1858
+ unit.errors.push({
1859
+ location: formatRange(range),
1860
+ message: statement.kind === "By" ? "Empty BY" : "Empty USE or HIDE statement.",
1861
+ });
1862
+ }
1863
+ };
1200
1864
 
1201
1865
  const resolveNewSymbol = (symbol: NewSymbol, scope: LocalName | undefined, unit: Unit) => {
1202
1866
  if (symbol.set) resolveExpression(symbol.set, scope, unit);
@@ -1245,7 +1909,7 @@ const resolveStatement = (
1245
1909
 
1246
1910
  const resolveProof = (proof: Proof | undefined, scope: LocalName | undefined, outer: Unit) => {
1247
1911
  const unit = outer.hasLabelScope ? { ...outer, hasLabelScope: false } : outer;
1248
- if (proof?.kind === "By") checkFacts(proof.facts, scope, unit);
1912
+ if (proof?.kind === "By") checkUseOrHide(proof, scope, unit);
1249
1913
  if (proof?.kind !== "Steps") return;
1250
1914
  proof.steps.reduce((current, step) => resolveStep(step, current, unit), scope);
1251
1915
  };
@@ -1262,6 +1926,42 @@ const resolveLocalInstance = (instance: Instance, scope: LocalName | undefined,
1262
1926
  );
1263
1927
  };
1264
1928
 
1929
+ const getStepGoal = (body: StepBody, location: SourceLocation): Goal | undefined => {
1930
+ const createGoal = (keyword: string, statement: Expression) => ({
1931
+ statement,
1932
+ isSuffices: false,
1933
+ isInProof: false,
1934
+ keyword,
1935
+ });
1936
+ switch (body.kind) {
1937
+ case "Have":
1938
+ return createGoal("HAVE", { kind: "Tuple", elements: [body.expression], location });
1939
+ case "Case":
1940
+ return createGoal("CASE", { kind: "Tuple", elements: [body.expression], location });
1941
+ case "Witness":
1942
+ return createGoal("WITNESS", { kind: "Tuple", elements: body.expressions, location });
1943
+ case "Take":
1944
+ return createGoal("TAKE", { kind: "Tuple", elements: getBoundSets(body.bounds), location });
1945
+ case "Pick":
1946
+ return createGoal(
1947
+ "PICK",
1948
+ body.bounds.length > 0
1949
+ ? { kind: "Exists", bounds: body.bounds, body: body.body, location }
1950
+ : {
1951
+ kind: "UnboundedQuantifier",
1952
+ quantifier: "Exists",
1953
+ names: body.names,
1954
+ body: body.body,
1955
+ location,
1956
+ },
1957
+ );
1958
+ case "Qed":
1959
+ return createGoal("QED step", { kind: "Tuple", elements: [], location });
1960
+ default:
1961
+ return undefined;
1962
+ }
1963
+ };
1964
+
1265
1965
  const resolveStep = (
1266
1966
  step: ProofStep,
1267
1967
  scope: LocalName | undefined,
@@ -1272,12 +1972,16 @@ const resolveStep = (
1272
1972
  step.name === undefined
1273
1973
  ? unit
1274
1974
  : { ...unit, hasLabelScope: true, labelParams: [], labels: new Set<string>() };
1975
+ const goal = getStepGoal(body, step.location);
1275
1976
  const bindStep = (parent: LocalName | undefined): LocalName | undefined =>
1276
- step.name === undefined ? parent : { name: step.name, arity: 0, kind: "Theorem", parent };
1277
- const bindNonFactStep = (parent: LocalName | undefined): LocalName | undefined =>
1977
+ step.name === undefined ? parent : { name: step.name, arity: 0, kind: "Theorem", parent, goal };
1978
+ const bindNonFactStep = (
1979
+ parent: LocalName | undefined,
1980
+ nonFactStep: LocalName["nonFactStep"],
1981
+ ): LocalName | undefined =>
1278
1982
  step.name === undefined
1279
1983
  ? parent
1280
- : { name: step.name, arity: 0, kind: "Theorem", parent, isNonFact: true };
1984
+ : { name: step.name, arity: 0, kind: "Theorem", parent, nonFactStep };
1281
1985
  switch (body.kind) {
1282
1986
  case "Assert": {
1283
1987
  const assumed = resolveStatement(body.statement, scope, stepUnit);
@@ -1287,17 +1991,32 @@ const resolveStep = (
1287
1991
  resolveProof(step.proof, proofScope, unit);
1288
1992
  return body.isSuffices ? assumed : scope;
1289
1993
  }
1290
- const goal = { statement: body.statement, isSuffices: body.isSuffices, isInProof: true };
1291
- resolveProof(step.proof, { name, arity: 0, kind: "Theorem", parent: proofScope, goal }, unit);
1292
- goal.isInProof = false;
1293
- return { name, arity: 0, kind: "Theorem", parent: body.isSuffices ? assumed : scope, goal };
1994
+ const assertion = {
1995
+ statement: body.statement,
1996
+ isSuffices: body.isSuffices,
1997
+ isInProof: true,
1998
+ keyword: body.isSuffices && body.statement.kind !== "AssumeProve" ? "SUFFICES" : undefined,
1999
+ };
2000
+ resolveProof(
2001
+ step.proof,
2002
+ { name, arity: 0, kind: "Theorem", parent: proofScope, goal: assertion },
2003
+ unit,
2004
+ );
2005
+ assertion.isInProof = false;
2006
+ return {
2007
+ name,
2008
+ arity: 0,
2009
+ kind: "Theorem",
2010
+ parent: body.isSuffices ? assumed : scope,
2011
+ goal: assertion,
2012
+ };
1294
2013
  }
1295
2014
  case "Use":
1296
2015
  case "Hide":
1297
- checkFacts(body.facts, scope, unit);
1298
- return bindNonFactStep(scope);
2016
+ checkUseOrHide(body, scope, unit);
2017
+ return bindNonFactStep(scope, body.kind);
1299
2018
  case "Instance":
1300
- return bindNonFactStep(resolveLocalInstance(body, scope, stepUnit));
2019
+ return bindNonFactStep(resolveLocalInstance(body, scope, stepUnit), body.kind);
1301
2020
  case "Define":
1302
2021
  return bindNonFactStep(
1303
2022
  body.definitions.reduce(
@@ -1307,6 +2026,7 @@ const resolveStep = (
1307
2026
  : resolveDefinitions([definition], current, unit),
1308
2027
  scope,
1309
2028
  ),
2029
+ body.kind,
1310
2030
  );
1311
2031
  case "Have":
1312
2032
  case "Case":
@@ -1379,6 +2099,7 @@ export interface ModuleUnit {
1379
2099
  bound: Symbols;
1380
2100
  definitions: Map<string, Definition>;
1381
2101
  getKey: (definition: Definition) => string;
2102
+ isModuleKnown: (name: string, location: SourceLocation) => boolean;
1382
2103
  instanced: Map<Instance, Symbols>;
1383
2104
  facts: Set<string>;
1384
2105
  reports: ModuleReport[];
@@ -1417,18 +2138,74 @@ const checkSubstitutions = (
1417
2138
  (parent, param) => ({ name: param.name, arity: param.arity, kind: "Parameter", parent }),
1418
2139
  outer,
1419
2140
  );
2141
+ const reportArity = (declaration: Declaration, location: string) =>
2142
+ unit.errors.push({
2143
+ location,
2144
+ message: `An operator must be substituted for symbol '${resolveSynonym(declaration.name)}', and it must have arity ${declaration.arity}.`,
2145
+ });
1420
2146
  const resolveSubstitute = (declaration: Declaration, expression: Expression) => {
1421
- if (declaration.arity === 0 || expression.kind !== "Identifier") {
1422
- resolveExpression(expression, scope, unit);
2147
+ const range = expression.location.range;
2148
+ if (declaration.arity === 0) {
2149
+ resolveExpressionArgument(expression, scope, unit);
2150
+ return;
2151
+ }
2152
+ const parenthesized = parenthesizedRanges.get(expression);
2153
+ if (expression.kind === "Lambda" && !parenthesized) {
2154
+ resolveLambda(expression, scope, unit);
2155
+ if (expression.params.length !== declaration.arity && range) {
2156
+ reportArity(declaration, formatRange(range));
2157
+ }
2158
+ return;
2159
+ }
2160
+ if (expression.kind === "OperatorReference" && !parenthesized) {
2161
+ const arity = getSymbolArity(expression, expression.operator, scope, unit);
2162
+ if (arity === undefined) reportArity(declaration, BUILTIN_LOCATION);
2163
+ else if (arity !== declaration.arity && range) reportArity(declaration, formatRange(range));
2164
+ return;
2165
+ }
2166
+ if (expression.kind !== "Identifier" || parenthesized) {
2167
+ const errorRange = parenthesized ?? range;
2168
+ if (errorRange) {
2169
+ unit.errors.push({
2170
+ location: formatRange(errorRange),
2171
+ message: `Arity ${declaration.arity} operator (not an expression) is expected \nto substitute for CONSTANT '${resolveSynonym(declaration.name)}'.`,
2172
+ });
2173
+ }
2174
+ reportArity(declaration, BUILTIN_LOCATION);
1423
2175
  return;
1424
2176
  }
1425
2177
  const arity = getSymbolArity(expression, expression.name, scope, unit);
1426
2178
  if (arity !== undefined && arity !== declaration.arity) {
1427
- throw new TlaSyntaxError(
1428
- `An operator must be substituted for symbol '${declaration.name}', and it must have arity ${declaration.arity} in the instance of ${instance.module} at line ${instance.location.line}, column ${instance.location.column}`,
1429
- );
2179
+ unit.errors.push({
2180
+ location: formatRange(getSpelledNameRange(expression, expression.name)),
2181
+ message: `Expected arity ${declaration.arity} but found operator of arity ${arity}.`,
2182
+ });
1430
2183
  }
2184
+ if (arity !== declaration.arity) reportArity(declaration, BUILTIN_LOCATION);
1431
2185
  };
2186
+ const instanceRange = instance.location.range;
2187
+ const isFound = (declaration: Declaration) =>
2188
+ lookupLocal(scope, declaration.name) !== undefined ||
2189
+ findSymbol(declaration.name, unit) !== undefined;
2190
+ const implicit = declarations.filter(isFound).map((declaration) => {
2191
+ const expression: Expression & { kind: "Identifier" } = {
2192
+ kind: "Identifier",
2193
+ name: declaration.name,
2194
+ location: instance.location,
2195
+ };
2196
+ return { declaration, expression };
2197
+ });
2198
+ implicit
2199
+ .filter((item) => item.declaration.arity === 0)
2200
+ .forEach((item) => {
2201
+ const arity = getSymbolArity(item.expression, item.declaration.name, scope, unit);
2202
+ if (arity && instanceRange) {
2203
+ unit.errors.push({
2204
+ location: formatRange(instanceRange),
2205
+ message: `Wrong number of arguments (0) given to operator '${resolveSynonym(item.declaration.name)}', \nwhich requires ${arity} arguments.`,
2206
+ });
2207
+ }
2208
+ });
1432
2209
  const substitutions = new Map<string, Expression>();
1433
2210
  instance.substitutions.forEach((substitution) => {
1434
2211
  const name = substitution.name;
@@ -1451,30 +2228,29 @@ const checkSubstitutions = (
1451
2228
  });
1452
2229
  }
1453
2230
  });
1454
- const implicit = declarations.filter((declaration) => !substitutions.has(declaration.name));
1455
- const isMissing = (declaration: Declaration) =>
1456
- !lookupLocal(scope, declaration.name) && !findSymbol(declaration.name, unit);
1457
2231
  implicit
1458
- .filter((declaration) => !isMissing(declaration))
2232
+ .filter((item) => !substitutions.has(item.declaration.name))
2233
+ .forEach((item) => {
2234
+ const arity =
2235
+ item.declaration.arity === 0
2236
+ ? 0
2237
+ : getSymbolArity(item.expression, item.declaration.name, scope, unit);
2238
+ if (arity !== item.declaration.arity && instanceRange) {
2239
+ reportArity(item.declaration, formatRange(instanceRange));
2240
+ }
2241
+ substitutions.set(item.declaration.name, item.expression);
2242
+ });
2243
+ declarations
2244
+ .filter((declaration) => !substitutions.has(declaration.name))
1459
2245
  .forEach((declaration) => {
1460
- const expression: Expression = {
1461
- kind: "Identifier",
1462
- name: declaration.name,
1463
- location: instance.location,
1464
- };
1465
- resolveSubstitute(declaration, expression);
1466
- substitutions.set(declaration.name, expression);
2246
+ const declared = declaration.location.range;
2247
+ if (instanceRange && declared) {
2248
+ unit.errors.push({
2249
+ location: formatRange(instanceRange),
2250
+ message: `Substitution missing for symbol ${resolveSynonym(declaration.name)} declared at ${formatRange(declared)} \nand instantiated in module ${instancer}.`,
2251
+ });
2252
+ }
1467
2253
  });
1468
- implicit.filter(isMissing).forEach((declaration) => {
1469
- const range = instance.location.range;
1470
- const declared = declaration.location.range;
1471
- if (range && declared) {
1472
- unit.errors.push({
1473
- location: formatRange(range),
1474
- message: `Substitution missing for symbol ${declaration.name} declared at ${formatRange(declared)} \nand instantiated in module ${instancer}.`,
1475
- });
1476
- }
1477
- });
1478
2254
  return substitutions;
1479
2255
  };
1480
2256
 
@@ -1482,7 +2258,7 @@ const resolveInstance = (instance: Instance, scope: LocalName | undefined, unit:
1482
2258
  const instanced = unit.getInstance(instance);
1483
2259
  checkSubstitutions(instance, instanced.declarations, instanced.instancer, scope, unit);
1484
2260
  return [...instanced.symbols].reduce(
1485
- (parent, [name, symbol]) => bindName(parent, name, symbol, unit),
2261
+ (parent, entry) => bindName(parent, entry[0], entry[1], unit),
1486
2262
  scope,
1487
2263
  );
1488
2264
  };
@@ -1494,6 +2270,12 @@ export const resolveSubstitutions = (
1494
2270
  unit: ModuleUnit,
1495
2271
  ) => {
1496
2272
  const imported = createSymbols(module, unit.imported);
2273
+ const positions = new Map(
2274
+ [...module.constants, ...module.variables].map((declaration) => [
2275
+ declaration.name,
2276
+ declaration.location,
2277
+ ]),
2278
+ );
1497
2279
  const report: ModuleReport = { location: instance.location, errors: [], warnings: [] };
1498
2280
  unit.reports.push(report);
1499
2281
  return checkSubstitutions(instance, declarations, module.name, undefined, {
@@ -1501,12 +2283,16 @@ export const resolveSubstitutions = (
1501
2283
  getInstance: unit.getInstance,
1502
2284
  definitions: unit.definitions,
1503
2285
  getKey: unit.getKey,
2286
+ isModuleKnown: unit.isModuleKnown,
1504
2287
  location: instance.location,
1505
2288
  self: undefined,
1506
2289
  facts: new Set(),
1507
2290
  goals: new Map(),
1508
2291
  bindings: new Map(
1509
- [...imported].map(([name, symbol]) => [name, { ...symbol, position: MODULE_START }]),
2292
+ [...imported].map((entry) => [
2293
+ entry[0],
2294
+ { ...entry[1], position: positions.get(entry[0]) ?? MODULE_START },
2295
+ ]),
1510
2296
  ),
1511
2297
  errors: report.errors,
1512
2298
  warnings: report.warnings,
@@ -1536,13 +2322,7 @@ export const collectSemanticErrors = (units: SemanticUnit[], warnings: SanyError
1536
2322
  }
1537
2323
  };
1538
2324
  units
1539
- .toSorted((left, right) =>
1540
- isBefore(left.location, right.location)
1541
- ? -1
1542
- : isBefore(right.location, left.location)
1543
- ? 1
1544
- : 0,
1545
- )
2325
+ .toSorted((left, right) => compareLocations(left.location, right.location))
1546
2326
  .forEach((unit) => {
1547
2327
  const reported: SanyError[] = [];
1548
2328
  const warned: SanyError[] = [];
@@ -1562,21 +2342,27 @@ export const collectSemanticErrors = (units: SemanticUnit[], warnings: SanyError
1562
2342
 
1563
2343
  export const resolveModule = (module: Module, unit: ModuleUnit) => {
1564
2344
  const symbols = createSymbols(module, unit.imported);
1565
- const facts = new Set([
1566
- ...unit.facts,
1567
- ...[...module.theorems, ...module.assumptions].flatMap((fact) => fact.name ?? []),
1568
- ]);
1569
2345
  const goals = new Map(
1570
2346
  module.theorems.flatMap((theorem): [string, Goal][] =>
1571
2347
  theorem.name !== undefined && theorem.statement.kind === "AssumeProve"
1572
- ? [[theorem.name, { statement: theorem.statement, isSuffices: false, isInProof: false }]]
2348
+ ? [
2349
+ [
2350
+ theorem.name,
2351
+ {
2352
+ statement: theorem.statement,
2353
+ isSuffices: false,
2354
+ isInProof: false,
2355
+ keyword: undefined,
2356
+ },
2357
+ ],
2358
+ ]
1573
2359
  : [],
1574
2360
  ),
1575
2361
  );
1576
2362
  const bindings = new Map<string, ModuleBinding>(
1577
- [...CORE_SYMBOLS, ...unit.bound].map(([name, symbol]) => [
1578
- name,
1579
- { ...symbol, position: MODULE_START },
2363
+ [...CORE_SYMBOLS, ...unit.bound].map((entry) => [
2364
+ entry[0],
2365
+ { ...entry[1], position: MODULE_START },
1580
2366
  ]),
1581
2367
  );
1582
2368
  const recursive = new Set<Binding>();
@@ -1594,9 +2380,10 @@ export const resolveModule = (module: Module, unit: ModuleUnit) => {
1594
2380
  getInstance: unit.getInstance,
1595
2381
  definitions: unit.definitions,
1596
2382
  getKey: unit.getKey,
2383
+ isModuleKnown: unit.isModuleKnown,
1597
2384
  location,
1598
2385
  self,
1599
- facts,
2386
+ facts: unit.facts,
1600
2387
  goals,
1601
2388
  bindings,
1602
2389
  errors,
@@ -1621,6 +2408,37 @@ export const resolveModule = (module: Module, unit: ModuleUnit) => {
1621
2408
  );
1622
2409
  return collectSemanticErrors(
1623
2410
  [
2411
+ ...module.units.flatMap((item): SemanticUnit[] => {
2412
+ const section =
2413
+ item.kind === "Variables"
2414
+ ? { type: "A VARIABLE declaration", location: item.location }
2415
+ : item.kind === "Constants"
2416
+ ? { type: "A declaration", location: item.location }
2417
+ : item.kind === "Module"
2418
+ ? { type: "A MODULE ", location: item.module.location }
2419
+ : item.kind === "Theorem"
2420
+ ? { type: "A THEOREM", location: item.theorem.location }
2421
+ : item.kind === "Assumption"
2422
+ ? { type: "An ASSUME", location: item.assumption.location }
2423
+ : item.kind === "Use"
2424
+ ? { type: "A USE or HIDE", location: item.use.location }
2425
+ : undefined;
2426
+ const range = section?.location.range;
2427
+ if (!section || !range) return [];
2428
+ return [
2429
+ {
2430
+ location: section.location,
2431
+ check: (errors) => {
2432
+ if (declarations.some((declared) => declared.binding?.isPending)) {
2433
+ errors.push({
2434
+ location: formatRange(range),
2435
+ message: `${section.type} may not appear within a recursive definition section.`,
2436
+ });
2437
+ }
2438
+ },
2439
+ },
2440
+ ];
2441
+ }),
1624
2442
  ...unit.reports.map((report) => ({
1625
2443
  location: report.location,
1626
2444
  check: (errors: SanyError[], warnings: SanyError[]) => {
@@ -1637,6 +2455,7 @@ export const resolveModule = (module: Module, unit: ModuleUnit) => {
1637
2455
  const binding: ModuleBinding = {
1638
2456
  kind: "Definition",
1639
2457
  arity: declaration.arity,
2458
+ params: Array(declaration.arity).fill(0),
1640
2459
  range: declaration.location.range,
1641
2460
  position: declaration.location,
1642
2461
  isPending: true,
@@ -1702,7 +2521,7 @@ export const resolveModule = (module: Module, unit: ModuleUnit) => {
1702
2521
  ),
1703
2522
  ...module.uses.map((use) =>
1704
2523
  createCheck(use.location, undefined, false, (inner) =>
1705
- checkFacts(use.facts, undefined, inner),
2524
+ checkUseOrHide(use, undefined, inner),
1706
2525
  ),
1707
2526
  ),
1708
2527
  {
@@ -1713,7 +2532,7 @@ export const resolveModule = (module: Module, unit: ModuleUnit) => {
1713
2532
  if (range && (!item.binding || item.binding.isPending)) {
1714
2533
  errors.push({
1715
2534
  location: formatRange(range),
1716
- message: `Symbol ${item.declaration.name} declared in RECURSIVE statement but not defined.`,
2535
+ message: `Symbol ${resolveSynonym(item.declaration.name)} declared in RECURSIVE statement but not defined.`,
1717
2536
  });
1718
2537
  }
1719
2538
  }),