tla-ts 0.0.9-dev.8298a52 → 0.0.10-dev.28c823e4b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/compile.cjs +3 -3
- package/dist/compile.js +3 -3
- package/dist/deciders.cjs +28 -28
- package/dist/deciders.js +52 -52
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +105 -10
- package/dist/index.d.ts +105 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +116 -36
- package/dist/prove.js +116 -36
- package/dist/run.cjs +143 -31
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +1 -1
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +129 -104
- package/dist/transfer.js +129 -104
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +4 -23
- package/src/bags.ts +99 -102
- package/src/builtins.ts +40 -78
- package/src/bundled-modules.ts +1 -8
- package/src/check.ts +564 -366
- package/src/cli/options.ts +10 -5
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +136 -0
- package/src/cli/shared.ts +18 -11
- package/src/cli/tlapm.ts +0 -12
- package/src/cli/tlc-arguments.ts +640 -0
- package/src/cli/tlc-usage.ts +361 -0
- package/src/cli/tlc.ts +525 -216
- package/src/cli/typescript.ts +0 -3
- package/src/cli/xml-exporter.ts +4 -16
- package/src/cli.ts +0 -1
- package/src/codegen.ts +191 -64
- package/src/config.ts +140 -109
- package/src/coverage.ts +837 -0
- package/src/dependencies.ts +6 -40
- package/src/dfid.ts +618 -0
- package/src/environment.ts +237 -119
- package/src/errors.ts +56 -56
- package/src/evaluate.ts +543 -341
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +10 -10
- package/src/index.ts +3 -0
- package/src/instances.ts +38 -31
- package/src/java-overrides.ts +4 -19
- package/src/json-reader.ts +455 -0
- package/src/json.ts +255 -139
- package/src/levels.ts +8 -17
- package/src/lexer.ts +80 -100
- package/src/liveness-checker.ts +77 -117
- package/src/liveness.ts +106 -62
- package/src/obligations/action.ts +4 -28
- package/src/obligations/anonymize.ts +84 -80
- package/src/obligations/equality.ts +1 -1
- package/src/obligations/expression.ts +2 -19
- package/src/obligations/format.ts +1 -9
- package/src/obligations/generate.ts +1 -11
- package/src/obligations/index.ts +0 -11
- package/src/obligations/levels.ts +4 -8
- package/src/obligations/module.ts +1 -15
- package/src/obligations/normalize.ts +5 -24
- package/src/obligations/operators.ts +1 -2
- package/src/obligations/pragma.ts +1 -10
- package/src/obligations/printer.ts +47 -46
- package/src/obligations/proof.ts +1 -5
- package/src/obligations/regroup.ts +1 -4
- package/src/obligations/simplify.ts +3 -14
- package/src/obligations/source.ts +1 -21
- package/src/obligations/subexpression.ts +5 -11
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +8 -14
- package/src/obligations/tuples.ts +3 -9
- package/src/parallel-worker.ts +24 -33
- package/src/parallel.ts +48 -40
- package/src/parser.ts +565 -282
- package/src/pcal/ast.ts +53 -86
- package/src/pcal/parse.ts +144 -219
- package/src/pcal/tokenize.ts +91 -131
- package/src/pcal/translate.ts +83 -130
- package/src/pcal/validate.ts +48 -68
- package/src/pretty-print.ts +7 -8
- package/src/prover/decide-pool.ts +5 -10
- package/src/prover/deciders.ts +0 -4
- package/src/prover/first-order.ts +0 -11
- package/src/prover/isabelle/decide.ts +0 -6
- package/src/prover/isabelle/encode.ts +11 -23
- package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
- package/src/prover/isabelle/isar/method.ts +25 -38
- package/src/prover/isabelle/isar/proof.ts +1 -10
- package/src/prover/isabelle/isar/statement.ts +1 -6
- package/src/prover/isabelle/isar/theory.ts +15 -26
- package/src/prover/isabelle/isar/type-check.ts +11 -25
- package/src/prover/isabelle/provers/blast/blast.ts +10 -41
- package/src/prover/isabelle/provers/blast/branch.ts +1 -32
- package/src/prover/isabelle/provers/blast/prove.ts +1 -35
- package/src/prover/isabelle/provers/blast/rules.ts +6 -44
- package/src/prover/isabelle/provers/blast/state.ts +2 -28
- package/src/prover/isabelle/provers/blast/term.ts +9 -36
- package/src/prover/isabelle/provers/clasimp.ts +1 -13
- package/src/prover/isabelle/provers/classical.ts +14 -42
- package/src/prover/isabelle/provers/hypsubst.ts +11 -25
- package/src/prover/isabelle/pure/bicompose.ts +16 -13
- package/src/prover/isabelle/pure/consts.ts +1 -7
- package/src/prover/isabelle/pure/conv.ts +1 -9
- package/src/prover/isabelle/pure/drule.ts +24 -40
- package/src/prover/isabelle/pure/envir.ts +3 -52
- package/src/prover/isabelle/pure/goal.ts +1 -7
- package/src/prover/isabelle/pure/interrupt.ts +0 -5
- package/src/prover/isabelle/pure/list.ts +0 -3
- package/src/prover/isabelle/pure/logic.ts +1 -14
- package/src/prover/isabelle/pure/name.ts +2 -9
- package/src/prover/isabelle/pure/net.ts +3 -59
- package/src/prover/isabelle/pure/object-logic.ts +3 -10
- package/src/prover/isabelle/pure/pattern.ts +2 -19
- package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
- package/src/prover/isabelle/pure/rewriter.ts +26 -58
- package/src/prover/isabelle/pure/search.ts +3 -10
- package/src/prover/isabelle/pure/seq.ts +1 -10
- package/src/prover/isabelle/pure/simplifier.ts +4 -12
- package/src/prover/isabelle/pure/table.ts +1 -31
- package/src/prover/isabelle/pure/tactic.ts +12 -22
- package/src/prover/isabelle/pure/tactical.ts +6 -12
- package/src/prover/isabelle/pure/term-ord.ts +2 -6
- package/src/prover/isabelle/pure/term.ts +2 -43
- package/src/prover/isabelle/pure/thm.ts +13 -36
- package/src/prover/isabelle/pure/type.ts +2 -15
- package/src/prover/isabelle/pure/unify.ts +20 -30
- package/src/prover/isabelle/pure/variable.ts +3 -7
- package/src/prover/isabelle/tla/classical-setup.ts +9 -19
- package/src/prover/isabelle/tla/context.ts +8 -16
- package/src/prover/isabelle/tla/logic.ts +4 -11
- package/src/prover/isabelle/tla/simpdata.ts +46 -34
- package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
- package/src/prover/ocaml.ts +0 -6
- package/src/prover/prep/action.ts +4 -36
- package/src/prover/prep/enabled-axioms.ts +12 -19
- package/src/prover/prep/fingerprint.ts +0 -16
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +9 -36
- package/src/prover/prep/normalize.ts +4 -28
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +0 -36
- package/src/prover/ptl/decide.ts +7 -12
- package/src/prover/ptl/encode.ts +14 -36
- package/src/prover/ptl/sat.ts +24 -32
- package/src/prover/ptl/tableau.ts +12 -26
- package/src/prover/smt/axioms.ts +0 -7
- package/src/prover/smt/context.ts +19 -26
- package/src/prover/smt/data.ts +51 -54
- package/src/prover/smt/encode.ts +14 -35
- package/src/prover/smt/extensionality.ts +0 -10
- package/src/prover/smt/flatten.ts +3 -22
- package/src/prover/smt/format.ts +5 -10
- package/src/prover/smt/instances.ts +0 -10
- package/src/prover/smt/rewrite.ts +66 -101
- package/src/prover/smt/solver/act-cache.ts +0 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -48
- package/src/prover/smt/solver/array.ts +1 -3
- package/src/prover/smt/solver/asserted-formulas.ts +1 -43
- package/src/prover/smt/solver/ast-lt.ts +1 -11
- package/src/prover/smt/solver/ast-util.ts +1 -6
- package/src/prover/smt/solver/ast.ts +1 -143
- package/src/prover/smt/solver/auf-solver.ts +6 -39
- package/src/prover/smt/solver/case-split-queue.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +1 -18
- package/src/prover/smt/solver/clause.ts +1 -27
- package/src/prover/smt/solver/conflict-resolution.ts +0 -9
- package/src/prover/smt/solver/context.ts +4 -61
- package/src/prover/smt/solver/ctx-simplify.ts +14 -41
- package/src/prover/smt/solver/der.ts +2 -21
- package/src/prover/smt/solver/dyn-ack.ts +1 -11
- package/src/prover/smt/solver/e-matching.ts +3 -34
- package/src/prover/smt/solver/enode.ts +1 -21
- package/src/prover/smt/solver/expr-ref.ts +1 -5
- package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
- package/src/prover/smt/solver/fingerprints.ts +1 -12
- package/src/prover/smt/solver/flat-literals.ts +1 -9
- package/src/prover/smt/solver/goal.ts +2 -14
- package/src/prover/smt/solver/hash.ts +0 -8
- package/src/prover/smt/solver/hashtable.ts +1 -12
- package/src/prover/smt/solver/internalizer.ts +6 -98
- package/src/prover/smt/solver/lbool.ts +1 -2
- package/src/prover/smt/solver/literal.ts +0 -3
- package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
- package/src/prover/smt/solver/lp/constraints.ts +2 -8
- package/src/prover/smt/solver/lp/containers.ts +12 -30
- package/src/prover/smt/solver/lp/core-solver.ts +10 -31
- package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
- package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
- package/src/prover/smt/solver/lp/dependency.ts +1 -4
- package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
- package/src/prover/smt/solver/lp/explanation.ts +1 -6
- package/src/prover/smt/solver/lp/gomory.ts +9 -22
- package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
- package/src/prover/smt/solver/lp/hnf.ts +11 -26
- package/src/prover/smt/solver/lp/int-cube.ts +15 -36
- package/src/prover/smt/solver/lp/int-solver.ts +4 -34
- package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
- package/src/prover/smt/solver/lp/lar-term.ts +1 -5
- package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
- package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
- package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
- package/src/prover/smt/solver/lp/nex.ts +1 -6
- package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
- package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
- package/src/prover/smt/solver/lp/nla-core.ts +35 -130
- package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
- package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
- package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
- package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
- package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
- package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
- package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
- package/src/prover/smt/solver/lp/nla-order.ts +2 -13
- package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
- package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
- package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
- package/src/prover/smt/solver/lp/nla-types.ts +1 -11
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
- package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
- package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
- package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
- package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
- package/src/prover/smt/solver/lp/pdd.ts +7 -70
- package/src/prover/smt/solver/lp/random-updater.ts +1 -8
- package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
- package/src/prover/smt/solver/lp/union-find.ts +1 -6
- package/src/prover/smt/solver/mam-compiler.ts +14 -56
- package/src/prover/smt/solver/mam-interpreter.ts +1 -21
- package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
- package/src/prover/smt/solver/model-checker.ts +2 -36
- package/src/prover/smt/solver/model-evaluator.ts +3 -29
- package/src/prover/smt/solver/model-finder.ts +3 -15
- package/src/prover/smt/solver/model-generator.ts +1 -12
- package/src/prover/smt/solver/model-macro-solver.ts +12 -69
- package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
- package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
- package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
- package/src/prover/smt/solver/nlsat/explain.ts +3 -47
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
- package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
- package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
- package/src/prover/smt/solver/nlsat/solver.ts +7 -67
- package/src/prover/smt/solver/nlsat/types.ts +1 -8
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
- package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
- package/src/prover/smt/solver/nnf.ts +3 -38
- package/src/prover/smt/solver/pattern-inference.ts +2 -15
- package/src/prover/smt/solver/poly-rewriter.ts +3 -23
- package/src/prover/smt/solver/propagate-values.ts +1 -10
- package/src/prover/smt/solver/proto-model.ts +3 -48
- package/src/prover/smt/solver/pull-quant.ts +1 -12
- package/src/prover/smt/solver/qe-lite-der.ts +1 -29
- package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
- package/src/prover/smt/solver/qe-lite.ts +3 -33
- package/src/prover/smt/solver/qi-queue.ts +1 -16
- package/src/prover/smt/solver/quant-tactics.ts +5 -22
- package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
- package/src/prover/smt/solver/quantifier-manager.ts +1 -8
- package/src/prover/smt/solver/random-gen.ts +1 -2
- package/src/prover/smt/solver/rational.ts +1 -8
- package/src/prover/smt/solver/ref-vector.ts +1 -6
- package/src/prover/smt/solver/relevancy.ts +2 -15
- package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
- package/src/prover/smt/solver/rewriter.ts +3 -85
- package/src/prover/smt/solver/rlimit.ts +2 -20
- package/src/prover/smt/solver/smtlib-parser.ts +2 -37
- package/src/prover/smt/solver/solver.ts +1 -16
- package/src/prover/smt/solver/sort.ts +1 -5
- package/src/prover/smt/solver/sticky-generations.ts +0 -5
- package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
- package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
- package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
- package/src/prover/smt/solver/theory-lra-model.ts +4 -19
- package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
- package/src/prover/smt/solver/theory-lra-state.ts +3 -8
- package/src/prover/smt/solver/theory-lra.ts +1 -8
- package/src/prover/smt/solver/var-subst.ts +2 -26
- package/src/prover/smt/table.ts +0 -8
- package/src/prover/tlapm/cache.ts +20 -25
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +12 -17
- package/src/prover/verdict.ts +0 -2
- package/src/prover/zenon/check/check.ts +0 -9
- package/src/prover/zenon/check/definitions.ts +5 -15
- package/src/prover/zenon/check/equality.ts +0 -8
- package/src/prover/zenon/check/functions.ts +0 -4
- package/src/prover/zenon/check/keys.ts +0 -7
- package/src/prover/zenon/check/propositional.ts +0 -3
- package/src/prover/zenon/check/records.ts +0 -5
- package/src/prover/zenon/check/relations.ts +0 -13
- package/src/prover/zenon/check/rewrites.ts +0 -6
- package/src/prover/zenon/check/sets.ts +0 -3
- package/src/prover/zenon/check/terms.ts +0 -17
- package/src/prover/zenon/check/tla.ts +0 -6
- package/src/prover/zenon/decide.ts +0 -12
- package/src/prover/zenon/encode.ts +1 -8
- package/src/prover/zenon/eqrel.ts +0 -13
- package/src/prover/zenon/equality-rules.ts +0 -4
- package/src/prover/zenon/expr.ts +1 -26
- package/src/prover/zenon/index-table.ts +17 -38
- package/src/prover/zenon/isar-case.ts +9 -19
- package/src/prover/zenon/isar.ts +1 -29
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +0 -9
- package/src/prover/zenon/mltoll.ts +54 -76
- package/src/prover/zenon/node.ts +1 -11
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +2 -7
- package/src/prover/zenon/phrase.ts +1 -11
- package/src/prover/zenon/proof.ts +0 -9
- package/src/prover/zenon/propositional-rules.ts +0 -5
- package/src/prover/zenon/rules.ts +2 -6
- package/src/prover/zenon/search.ts +1 -17
- package/src/prover/zenon/tla/functions.ts +57 -29
- package/src/prover/zenon/tla/llproof.ts +63 -70
- package/src/prover/zenon/tla/records.ts +56 -27
- package/src/prover/zenon/tla/rewrites.ts +12 -19
- package/src/prover/zenon/tla/sets.ts +68 -39
- package/src/prover/zenon/tla/terms.ts +0 -6
- package/src/prover/zenon/tla/tla.ts +59 -58
- package/src/randomization.ts +81 -35
- package/src/resolve.ts +12 -112
- package/src/runtime.ts +22 -22
- package/src/sany/builtins.ts +2 -5
- package/src/sany/generator.ts +149 -252
- package/src/sany/levels.ts +6 -34
- package/src/sany/lexer.ts +41 -61
- package/src/sany/linter.ts +1 -9
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +0 -31
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +29 -63
- package/src/sany/selectors.ts +15 -39
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +13 -63
- package/src/search.ts +495 -155
- package/src/simulate.ts +685 -0
- package/src/spec-description.ts +176 -69
- package/src/standard-definitions.ts +0 -4
- package/src/standard-modules.ts +254 -69
- package/src/state-graph.ts +50 -24
- package/src/subexpressions.ts +69 -52
- package/src/substitution-levels.ts +2 -3
- package/src/successors.ts +260 -91
- package/src/symmetry.ts +33 -25
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -67
- package/src/tlc/jar-data.ts +112 -6
- package/src/tlc/messages.ts +110 -44
- package/src/tlc/order.ts +37 -60
- package/src/tlc/random.ts +33 -45
- package/src/tlc/replay.ts +549 -217
- package/src/tlc/summary.ts +36 -47
- package/src/tlc/tlc-operators.ts +76 -41
- package/src/tlc/tlcext-operators.ts +139 -122
- package/src/tlc/trace-spec.ts +269 -0
- package/src/tlc/value-stream.ts +139 -0
- package/src/tlc/version.ts +1 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +8 -21
- package/src/typescript/collections.ts +0 -15
- package/src/typescript/compile.ts +0 -5
- package/src/typescript/context.ts +0 -12
- package/src/typescript/emit.ts +0 -1
- package/src/typescript/expressions.ts +0 -12
- package/src/typescript/formula.ts +4 -12
- package/src/typescript/functions.ts +6 -17
- package/src/typescript/model.ts +10 -11
- package/src/typescript/names.ts +0 -2
- package/src/typescript/program.ts +0 -3
- package/src/typescript/properties.ts +6 -8
- package/src/typescript/scope.ts +0 -5
- package/src/typescript/steps.ts +0 -10
- package/src/typescript/types.ts +1 -8
- package/src/values.ts +749 -330
- package/src/worker.ts +7 -8
package/src/sany/generator.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
TlaUnsupportedError,
|
|
28
28
|
} from "../errors";
|
|
29
29
|
import { parseSanyModule } from "../parser";
|
|
30
|
+
import { isBefore } from "../resolve";
|
|
30
31
|
import { BUILTIN_LOCATION, createBuiltins, createLevelFields } from "./builtins";
|
|
31
32
|
import { getSany174LexicalError } from "./lexer";
|
|
32
33
|
import { getSanyParseError } from "./parse-error";
|
|
@@ -108,27 +109,19 @@ const SYNONYMS = new Map(
|
|
|
108
109
|
),
|
|
109
110
|
);
|
|
110
111
|
|
|
111
|
-
// tla2sany.parser.Operators.resolveSynonym, applied to each part of a name like I!\cup.
|
|
112
112
|
const resolveSynonym = (name: string) =>
|
|
113
113
|
name
|
|
114
114
|
.split("!")
|
|
115
115
|
.map((part) => SYNONYMS.get(part) ?? (part === "~" ? "\\lnot" : part))
|
|
116
116
|
.join("!");
|
|
117
117
|
|
|
118
|
-
// The fields of SANY's AssumeProveNode that tell whether a reference to a clause lies in the scope
|
|
119
|
-
// of a declaration in the clauses before it. See AssumeProveNode.java.
|
|
120
118
|
interface AssumeProveScope {
|
|
121
|
-
// AssumeProveNode.inScopeOfDecl: whether any of the first i clauses is a NEW.
|
|
122
119
|
isDeclaredBefore: boolean[];
|
|
123
|
-
// Whether the ASSUME/PROVE is the statement of a named theorem or step, whose suffices and
|
|
124
|
-
// inProof fields decide where its declarations are visible.
|
|
125
120
|
hasGoal: boolean;
|
|
126
121
|
isSuffices: boolean;
|
|
127
122
|
isInProof: boolean;
|
|
128
123
|
}
|
|
129
124
|
|
|
130
|
-
// Where the generator is among nested ASSUME/PROVEs: the depth, whether each level declares a
|
|
131
|
-
// symbol, and the goal and clause a label lies in.
|
|
132
125
|
interface AssumeProveState {
|
|
133
126
|
depth: number;
|
|
134
127
|
isDeclared: boolean[];
|
|
@@ -149,10 +142,8 @@ const NEW_SYMBOL_KINDS = {
|
|
|
149
142
|
Temporal: { declKind: 28, level: 3 },
|
|
150
143
|
};
|
|
151
144
|
|
|
152
|
-
// Whether SANY names an operator by an identifier rather than by a symbol.
|
|
153
145
|
const isIdentifier = (name: string) => /^[A-Za-z0-9_]+$/.test(name);
|
|
154
146
|
|
|
155
|
-
// Whether an operator name selects through an instance, as M!Op does, unlike the infix !!.
|
|
156
147
|
const isSelector = (name: string) => name !== "!!" && name.includes("!");
|
|
157
148
|
|
|
158
149
|
export interface SanySpecification {
|
|
@@ -162,21 +153,12 @@ export interface SanySpecification {
|
|
|
162
153
|
}
|
|
163
154
|
|
|
164
155
|
interface SanyGenerationOptions {
|
|
165
|
-
// The name of the root module's file, which SANY requires to match the module's name.
|
|
166
156
|
rootFileName?: string;
|
|
167
|
-
// The path of the root module's file as SANY's caller gives it, which SANY names when it cannot
|
|
168
|
-
// parse the file, rather than the file name it gives the other modules.
|
|
169
157
|
rootFilePath?: string;
|
|
170
|
-
// Called before SANY parses the file of each module, and before it analyzes each external
|
|
171
|
-
// module, in its order.
|
|
172
158
|
onParse?: (name: string) => void;
|
|
173
159
|
onAnalyze?: (name: string) => void;
|
|
174
|
-
// Called after each external module, in the order SANY analyzes them.
|
|
175
160
|
onModule?: (module: ModuleNode, messages: SanyMessage[]) => void;
|
|
176
|
-
// The TLC whose SANY to reproduce, which decides how SANY numbers the nodes it creates.
|
|
177
161
|
version?: TlcVersion;
|
|
178
|
-
// The modules TLC adds to the root module's EXTENDS for its post conditions, which SANY loads
|
|
179
|
-
// after the ones the root module itself extends.
|
|
180
162
|
rootExtendees?: string[];
|
|
181
163
|
}
|
|
182
164
|
|
|
@@ -197,8 +179,6 @@ interface OpApplBinding {
|
|
|
197
179
|
ranges?: ExprNode[];
|
|
198
180
|
}
|
|
199
181
|
|
|
200
|
-
// A module name that SpecObj.loadSpec has yet to resolve, with the module that imports it and the
|
|
201
|
-
// module of that file whose EXTENDS or INSTANCE names it.
|
|
202
182
|
interface UnresolvedName {
|
|
203
183
|
name: string;
|
|
204
184
|
importer: string;
|
|
@@ -215,7 +195,6 @@ const resolveSymbol = (table: SymbolTable, name: string) => {
|
|
|
215
195
|
return undefined;
|
|
216
196
|
};
|
|
217
197
|
|
|
218
|
-
// SANY's kind of a symbol, which a symbol that takes another's name must share.
|
|
219
198
|
const getSymbolKind = (symbol: SymbolNode) =>
|
|
220
199
|
symbol.kind === "OpDecl"
|
|
221
200
|
? `${symbol.kind}${symbol.declKind}`
|
|
@@ -223,12 +202,9 @@ const getSymbolKind = (symbol: SymbolNode) =>
|
|
|
223
202
|
? symbol.defKind
|
|
224
203
|
: symbol.kind;
|
|
225
204
|
|
|
226
|
-
// Context.kindOfNode.
|
|
227
205
|
const getKindName = (symbol: SymbolNode) =>
|
|
228
206
|
symbol.kind === "OpDef" || symbol.kind === "FormalParam" ? "definition" : "declaration";
|
|
229
207
|
|
|
230
|
-
// SymbolNode.sameOriginallyDefinedInModule: two symbols are the same definition of a module without
|
|
231
|
-
// parameters.
|
|
232
208
|
const isSameOrigin = (symbol: SymbolNode, other: SymbolNode) => {
|
|
233
209
|
if (symbol.kind === "OpDef" && other.kind === "OpDef") {
|
|
234
210
|
const source = symbol.source ?? symbol;
|
|
@@ -251,7 +227,6 @@ const getLetInstances = (expression: Expression): Instance[] => [
|
|
|
251
227
|
...getChildren(expression).flatMap(getLetInstances),
|
|
252
228
|
];
|
|
253
229
|
|
|
254
|
-
// The LET instances of a theorem or assumption's statement.
|
|
255
230
|
const getStatementInstances = (statement: Expression | AssumeProve): Instance[] =>
|
|
256
231
|
statement.kind === "AssumeProve"
|
|
257
232
|
? [...statement.assumptions, statement.conclusion].flatMap((part) =>
|
|
@@ -259,16 +234,30 @@ const getStatementInstances = (statement: Expression | AssumeProve): Instance[]
|
|
|
259
234
|
)
|
|
260
235
|
: getLetInstances(statement);
|
|
261
236
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
237
|
+
const getProofInstances = (proof: Proof | undefined): Instance[] =>
|
|
238
|
+
proof?.kind !== "Steps"
|
|
239
|
+
? []
|
|
240
|
+
: proof.steps.flatMap((step) => [
|
|
241
|
+
...(step.body.kind === "Instance" ? [step.body] : []),
|
|
242
|
+
...(step.body.kind === "Define"
|
|
243
|
+
? step.body.definitions.flatMap((definition) =>
|
|
244
|
+
definition.kind === "Instance" ? [definition] : [],
|
|
245
|
+
)
|
|
246
|
+
: []),
|
|
247
|
+
...getProofInstances(step.proof),
|
|
248
|
+
]);
|
|
249
|
+
|
|
250
|
+
const isInternalInstance = (module: Module, instance: Instance) => {
|
|
266
251
|
const seen = new Set<string>();
|
|
267
252
|
for (const unit of module.units) {
|
|
268
253
|
if (unit.kind === "Module") seen.add(unit.module.name);
|
|
269
|
-
if (unit.kind === "Instance" && unit.instance.module ===
|
|
254
|
+
if (unit.kind === "Instance" && unit.instance.module === instance.module) {
|
|
255
|
+
return seen.has(instance.module);
|
|
256
|
+
}
|
|
270
257
|
}
|
|
271
|
-
return
|
|
258
|
+
return module.modules.some(
|
|
259
|
+
(inner) => inner.name === instance.module && isBefore(inner.location, instance.location),
|
|
260
|
+
);
|
|
272
261
|
};
|
|
273
262
|
|
|
274
263
|
type LetUnit =
|
|
@@ -276,26 +265,18 @@ type LetUnit =
|
|
|
276
265
|
| { kind: "Instance"; instance: Instance }
|
|
277
266
|
| { kind: "Definition"; definition: Definition };
|
|
278
267
|
|
|
279
|
-
// The decimal digits of a numeral such as \hFF, which SANY keeps at any size.
|
|
280
268
|
const getNumeralDigits = (text: string) =>
|
|
281
269
|
BigInt(text.startsWith("\\") ? `0${text.slice(1).replace(/^h/i, "x")}` : text).toString();
|
|
282
270
|
|
|
283
|
-
// An entry of SANY's LS stack: the labels of a definition, theorem or label and the parameters
|
|
284
|
-
// bound within it around the expression being generated.
|
|
285
271
|
interface LabelScope {
|
|
286
272
|
labels: Map<string, LabelNode>;
|
|
287
273
|
params: FormalParamNode[][];
|
|
288
274
|
}
|
|
289
275
|
|
|
290
|
-
// The modules a file extends and instantiates, as SANY's ParseUnit collects them, and the module of
|
|
291
|
-
// the file that names each one. SANY looks at a module's own EXTENDS and INSTANCEs before those of
|
|
292
|
-
// its inner modules.
|
|
293
276
|
const getDependencies = (module: Module) => {
|
|
294
277
|
const extendees: string[] = [];
|
|
295
278
|
const instancees: string[] = [];
|
|
296
279
|
const importers = new Map<string, string>();
|
|
297
|
-
// ParseUnit.calculateContextWithinParseUnit: a module knows the inner modules defined before it in
|
|
298
|
-
// the modules enclosing it and the inner modules of the modules it extends, but not itself.
|
|
299
280
|
const visit = (current: Module, context: Map<string, Module>) => {
|
|
300
281
|
const isRoot = current === module;
|
|
301
282
|
const addImports = (names: string[], imports: string[]) =>
|
|
@@ -308,20 +289,24 @@ const getDependencies = (module: Module) => {
|
|
|
308
289
|
const instances = current.units.flatMap((unit) => {
|
|
309
290
|
if (unit.kind === "Instance") return [unit.instance];
|
|
310
291
|
if (unit.kind === "Definition") return getLetInstances(unit.definition.body);
|
|
311
|
-
if (unit.kind === "Theorem" && isRoot)
|
|
292
|
+
if (unit.kind === "Theorem" && isRoot) {
|
|
293
|
+
return [
|
|
294
|
+
...getStatementInstances(unit.theorem.statement),
|
|
295
|
+
...getProofInstances(unit.theorem.proof),
|
|
296
|
+
];
|
|
297
|
+
}
|
|
312
298
|
if (unit.kind === "Assumption" && isRoot) return getLetInstances(unit.assumption.expression);
|
|
313
299
|
return [];
|
|
314
300
|
});
|
|
315
301
|
addImports(
|
|
316
302
|
instances
|
|
317
|
-
.
|
|
318
|
-
.
|
|
303
|
+
.filter((instance) => isExternal(instance.module) && !isInternalInstance(current, instance))
|
|
304
|
+
.map((instance) => instance.module),
|
|
319
305
|
instancees,
|
|
320
306
|
);
|
|
321
307
|
const peers = new Map(context);
|
|
322
308
|
current.modules.forEach((inner) => {
|
|
323
309
|
const innerContext = new Map(peers);
|
|
324
|
-
// ParseUnit.handleExtensions.
|
|
325
310
|
const extenders = new Set<Module>();
|
|
326
311
|
const addExtendedInnerModules = (extender: Module) => {
|
|
327
312
|
if (extenders.has(extender)) return;
|
|
@@ -346,7 +331,6 @@ const getDependencies = (module: Module) => {
|
|
|
346
331
|
return { extendees, instancees, importers };
|
|
347
332
|
};
|
|
348
333
|
|
|
349
|
-
// The expressions that can name an operator, as Generator.generateExprOrOpArg tells them apart.
|
|
350
334
|
const OPERATOR_ARGUMENT_KINDS = new Set<Expression["kind"]>([
|
|
351
335
|
"Identifier",
|
|
352
336
|
"Subexpression",
|
|
@@ -354,21 +338,17 @@ const OPERATOR_ARGUMENT_KINDS = new Set<Expression["kind"]>([
|
|
|
354
338
|
"Lambda",
|
|
355
339
|
]);
|
|
356
340
|
|
|
357
|
-
// A name such as K(1)!C, whose last part takes no arguments, is a GeneralId too.
|
|
358
341
|
const isOperatorArgument = (argument: Expression) => {
|
|
359
342
|
const items = argument.kind === "Apply" ? getSelectorItems(argument) : undefined;
|
|
360
343
|
return OPERATOR_ARGUMENT_KINDS.has(argument.kind) || (items !== undefined && isGeneralId(items));
|
|
361
344
|
};
|
|
362
345
|
|
|
363
|
-
// The parts of a DEF clause entry that isn't a name, as Generator.genIdToSelector reads them.
|
|
364
346
|
interface DefEntryParts {
|
|
365
347
|
hasChildlessFirstChild: boolean | undefined;
|
|
366
348
|
last: TokenSpan;
|
|
367
|
-
// The kind of SANY's syntax node for the last part, or for a token its text.
|
|
368
349
|
lastKind: string | undefined;
|
|
369
350
|
}
|
|
370
351
|
|
|
371
|
-
// The kind of the syntax node SANY's parser builds for an expression of each kind.
|
|
372
352
|
const SYNTAX_KINDS = new Map<Expression["kind"], string>([
|
|
373
353
|
["Identifier", "N_GeneralId"],
|
|
374
354
|
["Subexpression", "N_GeneralId"],
|
|
@@ -403,8 +383,6 @@ const SYNTAX_KINDS = new Map<Expression["kind"], string>([
|
|
|
403
383
|
["StrongFairness", "N_FairnessExpr"],
|
|
404
384
|
]);
|
|
405
385
|
|
|
406
|
-
// The syntax nodes whose first child is a node with children of its own. The first child of any
|
|
407
|
-
// other is a token, or a node without children.
|
|
408
386
|
const NESTED_FIRST_CHILD_KINDS = new Set([
|
|
409
387
|
"N_GeneralId",
|
|
410
388
|
"N_OpApplication",
|
|
@@ -417,8 +395,6 @@ const NESTED_FIRST_CHILD_KINDS = new Set([
|
|
|
417
395
|
|
|
418
396
|
const POSTFIX_OPERATOR_TEXTS = new Set(["'", "^+", "^*", "^#"]);
|
|
419
397
|
|
|
420
|
-
// SANY's syntax node for an operator that appears where an expression is required. The parser reads
|
|
421
|
-
// a prefix operator other than ~ and -. as a LAMBDA.
|
|
422
398
|
const getOperatorNodeKind = (
|
|
423
399
|
expression: Expression & { kind: "OperatorReference" | "Lambda" },
|
|
424
400
|
text: string,
|
|
@@ -429,8 +405,6 @@ const getOperatorNodeKind = (
|
|
|
429
405
|
: "N_GenInfixOp";
|
|
430
406
|
};
|
|
431
407
|
|
|
432
|
-
// Builds the semantic graph SANY builds for a specification and its modules, in the order SANY
|
|
433
|
-
// analyzes them: a module after the modules it extends and instantiates.
|
|
434
408
|
export const generateSanySpecification = (
|
|
435
409
|
rootSource: string,
|
|
436
410
|
loadModule: (name: string) => string | undefined,
|
|
@@ -441,15 +415,10 @@ export const generateSanySpecification = (
|
|
|
441
415
|
addSanyMessage(messages, { location, text, isWarning: false });
|
|
442
416
|
const addWarning = (location: SanyLocation | undefined, text: string) =>
|
|
443
417
|
addSanyMessage(messages, { location, text, isWarning: true });
|
|
444
|
-
|
|
445
|
-
const
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
const nullApplication = { id: 0 };
|
|
449
|
-
|
|
450
|
-
// SymbolTable.addSymbol: a symbol joins the innermost context unless its name is taken, which is
|
|
451
|
-
// an error unless the symbols agree in kind and arity, and then a warning unless they are the
|
|
452
|
-
// same definition of a module without parameters.
|
|
418
|
+
let lastId = options.version === "1.7.4" ? -1 : 0;
|
|
419
|
+
const getId = () => ++lastId;
|
|
420
|
+
let nullApplicationId = 0;
|
|
421
|
+
|
|
453
422
|
const addSymbol = (table: SymbolTable, symbol: SymbolNode) => {
|
|
454
423
|
const binding = resolveSymbol(table, symbol.name);
|
|
455
424
|
if (binding === symbol) return;
|
|
@@ -461,7 +430,6 @@ export const generateSanySpecification = (
|
|
|
461
430
|
symbol.kind === "FormalParam" ||
|
|
462
431
|
getSymbolKind(binding) !== getSymbolKind(symbol) ||
|
|
463
432
|
getSymbolArity(binding) !== getSymbolArity(symbol);
|
|
464
|
-
// TLC 1.7.4's SANY reports a conflict before the redefinition of a built-in operator.
|
|
465
433
|
const isBuiltIn = binding.kind === "OpDef" && binding.defKind === "BuiltIn";
|
|
466
434
|
if (isBuiltIn && !(isConflict && options.version === "1.7.4")) {
|
|
467
435
|
addError(
|
|
@@ -482,10 +450,7 @@ export const generateSanySpecification = (
|
|
|
482
450
|
);
|
|
483
451
|
}
|
|
484
452
|
};
|
|
485
|
-
// SANY
|
|
486
|
-
// Context's static initializer creates the builtins, SANY.frontEndInitialize creates them again
|
|
487
|
-
// for the specification, and the Generator class creates its InAssumeDummyNode. TLC 1.7.4's SANY
|
|
488
|
-
// creates the builtins only for the specification.
|
|
453
|
+
// SANY creates the builtins twice, in Context's static initializer and in frontEndInitialize.
|
|
489
454
|
if (options.version !== "1.7.4") createBuiltins(getId);
|
|
490
455
|
const builtins = createBuiltins(getId);
|
|
491
456
|
getId();
|
|
@@ -499,9 +464,8 @@ export const generateSanySpecification = (
|
|
|
499
464
|
new TlaSanyFatalError(`Could not parse module ${name} from file ${file}`, name, parseError);
|
|
500
465
|
const lexicalError = options.version === "1.7.4" ? getSany174LexicalError(text) : undefined;
|
|
501
466
|
if (lexicalError !== undefined) throw getParseFailure(lexicalError);
|
|
502
|
-
// HACK: the parser's errors are not SANY's, so a module that fails to parse gets the report
|
|
503
|
-
//
|
|
504
|
-
// such as for an error SANY finds after parsing.
|
|
467
|
+
// HACK: the parser's errors are not SANY's, so a module that fails to parse gets the report of
|
|
468
|
+
// SANY's parser, or the parser's own where SANY's parser would accept the module.
|
|
505
469
|
try {
|
|
506
470
|
return parseSanyModule(getUnboxedSource(text));
|
|
507
471
|
} catch (error) {
|
|
@@ -533,7 +497,6 @@ export const generateSanySpecification = (
|
|
|
533
497
|
const visiting = new Set<string>();
|
|
534
498
|
const path: string[] = [];
|
|
535
499
|
const calculateDependencies = (name: string, text: string | undefined, importer?: string) => {
|
|
536
|
-
// SpecObj.nonCircularityTest.
|
|
537
500
|
const cycleStart = path.indexOf(name);
|
|
538
501
|
if (cycleStart !== -1) {
|
|
539
502
|
throw new TlaSanyFatalError(
|
|
@@ -551,8 +514,6 @@ export const generateSanySpecification = (
|
|
|
551
514
|
path.pop();
|
|
552
515
|
order.push(name);
|
|
553
516
|
};
|
|
554
|
-
// SpecObj.loadSpec: SANY resolves the first unresolved name it finds from the root, every
|
|
555
|
-
// extended module before any instantiated one, each in the context of the module that names it.
|
|
556
517
|
const resolutions = new Set<string>();
|
|
557
518
|
const isResolved = (importer: string, name: string) => resolutions.has(`${importer} ${name}`);
|
|
558
519
|
const findUnresolved = (
|
|
@@ -590,8 +551,6 @@ export const generateSanySpecification = (
|
|
|
590
551
|
}
|
|
591
552
|
};
|
|
592
553
|
const rootName = options.rootFileName ?? parseSource("", rootSource).name;
|
|
593
|
-
// ParameterizedSpecObj.findOrCreateParsedUnit adds the post conditions' modules to the root
|
|
594
|
-
// module's own extendees, before those of its inner modules.
|
|
595
554
|
const getModuleDependencies = (name: string, module: Module) => {
|
|
596
555
|
const dependencies = getDependencies(module);
|
|
597
556
|
if (name !== rootName || options.rootExtendees === undefined) return dependencies;
|
|
@@ -620,12 +579,9 @@ export const generateSanySpecification = (
|
|
|
620
579
|
const exceptStack: OpApplNode[] = [];
|
|
621
580
|
const exceptSpecStack: OpApplNode[] = [];
|
|
622
581
|
const labelScopes: LabelScope[] = [];
|
|
623
|
-
// The contexts in which SANY's $$InAssume marks the scope of an ordinary ASSUME's assumptions.
|
|
624
582
|
const assumeContexts = new WeakSet<Context>();
|
|
625
583
|
const pushLabelScope = () => labelScopes.push({ labels: new Map(), params: [] });
|
|
626
584
|
const popLabels = () => labelScopes.pop()?.labels ?? new Map<string, LabelNode>();
|
|
627
|
-
// Generator.assumeProveDepth, inScopeOfAPDecl, currentGoal and currentGoalClause: where the
|
|
628
|
-
// node being generated lies among the ASSUME/PROVEs of a theorem or step.
|
|
629
585
|
const assumeProveState: AssumeProveState = {
|
|
630
586
|
depth: 0,
|
|
631
587
|
isDeclared: [],
|
|
@@ -760,10 +716,8 @@ export const generateSanySpecification = (
|
|
|
760
716
|
location,
|
|
761
717
|
});
|
|
762
718
|
|
|
763
|
-
// Generator.nullOAN, which SANY returns where it reported an error and carries on. It has no
|
|
764
|
-
// syntax tree node, so its location is that of the builtins.
|
|
765
719
|
const createNullNode = (): OpApplNode => ({
|
|
766
|
-
...createOpAppl(getBuiltin("$Nop"), [], BUILTIN_LOCATION, {},
|
|
720
|
+
...createOpAppl(getBuiltin("$Nop"), [], BUILTIN_LOCATION, {}, nullApplicationId),
|
|
767
721
|
isNull: true,
|
|
768
722
|
});
|
|
769
723
|
|
|
@@ -787,10 +741,10 @@ export const generateSanySpecification = (
|
|
|
787
741
|
location,
|
|
788
742
|
});
|
|
789
743
|
|
|
790
|
-
const createOpArg = (
|
|
744
|
+
const createOpArg = (operator: SymbolNode, location: SanyLocation): OpArgNode => ({
|
|
791
745
|
...createLevelFields(getId()),
|
|
792
746
|
kind: "OpArg",
|
|
793
|
-
op,
|
|
747
|
+
op: operator,
|
|
794
748
|
location,
|
|
795
749
|
});
|
|
796
750
|
|
|
@@ -804,9 +758,6 @@ export const generateSanySpecification = (
|
|
|
804
758
|
return symbol;
|
|
805
759
|
};
|
|
806
760
|
|
|
807
|
-
// OpDefNode.match: a definition takes as many arguments as it has parameters, which differs
|
|
808
|
-
// from its arity only where its RECURSIVE declaration has another, and an operator it takes
|
|
809
|
-
// must be given an operator of its arity that takes no operators.
|
|
810
761
|
const matchArguments = (
|
|
811
762
|
operator: SymbolNode,
|
|
812
763
|
operands: ExprOrOpArgNode[],
|
|
@@ -902,24 +853,22 @@ export const generateSanySpecification = (
|
|
|
902
853
|
},
|
|
903
854
|
});
|
|
904
855
|
|
|
905
|
-
// The parts of a selector at the tokens of the expression that SANY locates them at, from the
|
|
906
|
-
// name or selector itself to its parenthesized arguments.
|
|
907
856
|
const locateSelectorItems = (items: SelectorItem[], span: TokenSpan) => {
|
|
908
|
-
|
|
857
|
+
let cursor = span.start;
|
|
909
858
|
return items.map((item): SelectorItem => {
|
|
910
859
|
const text = item.op === "Name" ? item.name : item.op === "Null" ? "(" : String(item.op);
|
|
911
|
-
const index = findToken(file, cursor
|
|
860
|
+
const index = findToken(file, cursor, span.end, text);
|
|
912
861
|
if (index === -1) return item;
|
|
913
862
|
if (item.op === "Null") {
|
|
914
863
|
const close = getMatchingIndex(file, index);
|
|
915
|
-
cursor
|
|
864
|
+
cursor = close + 1;
|
|
916
865
|
return { ...item, location: getSpanLocation(file, { start: index, end: close }) };
|
|
917
866
|
}
|
|
918
|
-
cursor
|
|
867
|
+
cursor = index + 1;
|
|
919
868
|
const location = getTokenLocation(file, index);
|
|
920
869
|
if (item.args === undefined || !isToken(file, index + 1, "(")) return { ...item, location };
|
|
921
870
|
const close = getMatchingIndex(file, index + 1);
|
|
922
|
-
cursor
|
|
871
|
+
cursor = close + 1;
|
|
923
872
|
return {
|
|
924
873
|
...item,
|
|
925
874
|
location,
|
|
@@ -958,8 +907,6 @@ export const generateSanySpecification = (
|
|
|
958
907
|
if (recursive) recursive.node.operator = getBuiltin("$RecursiveFcnSpec");
|
|
959
908
|
};
|
|
960
909
|
|
|
961
|
-
// The bound groups of a quantifier, set filter, set map or function: tla-ts expands
|
|
962
|
-
// \A x, y \in S into a bound per name that shares the set, and SANY keeps one group.
|
|
963
910
|
const getBoundGroups = (bounds: Bound[]) =>
|
|
964
911
|
bounds.reduce<Bound[][]>((groups, bound) => {
|
|
965
912
|
const last = groups[groups.length - 1];
|
|
@@ -973,8 +920,6 @@ export const generateSanySpecification = (
|
|
|
973
920
|
return groups;
|
|
974
921
|
}, []);
|
|
975
922
|
|
|
976
|
-
// processQuantBoundArgs: SANY generates every bounding set before it declares the symbols,
|
|
977
|
-
// each named at its token between the end of the previous group and its set.
|
|
978
923
|
const generateBounds = (bounds: Bound[], searchStart: number) =>
|
|
979
924
|
generateBoundsWithRanges(
|
|
980
925
|
bounds,
|
|
@@ -982,7 +927,6 @@ export const generateSanySpecification = (
|
|
|
982
927
|
getBoundGroups(bounds).map((group) => generateExpression(group[0].set)),
|
|
983
928
|
);
|
|
984
929
|
|
|
985
|
-
// Generator.pushFormalParams: a label in the expression has to name the parameters it binds.
|
|
986
930
|
const generateWithParams = (params: FormalParamNode[], expression: Expression) => {
|
|
987
931
|
const scope = labelScopes.at(-1);
|
|
988
932
|
scope?.params.push(params);
|
|
@@ -991,6 +935,19 @@ export const generateSanySpecification = (
|
|
|
991
935
|
return node;
|
|
992
936
|
};
|
|
993
937
|
|
|
938
|
+
const generateBoundApplication = (
|
|
939
|
+
name: string,
|
|
940
|
+
bounds: Bound[],
|
|
941
|
+
searchStart: number,
|
|
942
|
+
body: Expression,
|
|
943
|
+
location: SanyLocation,
|
|
944
|
+
) =>
|
|
945
|
+
withContext(createContext(), () => {
|
|
946
|
+
const symbols = generateBounds(bounds, searchStart);
|
|
947
|
+
const operand = generateWithParams(symbols.bounded.flat(), body);
|
|
948
|
+
return applyBuiltin(name, [operand], location, symbols);
|
|
949
|
+
});
|
|
950
|
+
|
|
994
951
|
const generateLambda = (expression: Expression & { kind: "Lambda" }): OpDefNode => {
|
|
995
952
|
const span = getExpressionSpan(file, expression);
|
|
996
953
|
const nameIndexes = findNameTokens(file, span.start, span.end, expression.params);
|
|
@@ -1009,8 +966,6 @@ export const generateSanySpecification = (
|
|
|
1009
966
|
});
|
|
1010
967
|
};
|
|
1011
968
|
|
|
1012
|
-
// tla-ts desugars an operator symbol passed as an argument, such as SUBSET or -., into a LAMBDA
|
|
1013
|
-
// without a range.
|
|
1014
969
|
const getOperatorArgumentName = (argument: Expression) =>
|
|
1015
970
|
argument.kind === "OperatorReference"
|
|
1016
971
|
? argument.operator
|
|
@@ -1018,14 +973,13 @@ export const generateSanySpecification = (
|
|
|
1018
973
|
? argument.body.operator
|
|
1019
974
|
: file.tokens[getTokenIndex(file, argument.location)].text;
|
|
1020
975
|
|
|
1021
|
-
// Generator.generateOpArg: after an error, SANY gives its nullOpArg.
|
|
1022
976
|
const generateOperatorArgument = (
|
|
1023
977
|
argument: Expression,
|
|
1024
978
|
target: OpDeclNode,
|
|
1025
979
|
): OpArgNode | OpApplNode => {
|
|
1026
980
|
const location = getLocation(argument);
|
|
1027
981
|
if (argument.kind === "Lambda") {
|
|
1028
|
-
if (argument.location.range !== undefined)
|
|
982
|
+
if (argument.location.range !== undefined && argument.operator === undefined)
|
|
1029
983
|
return createOpArg(generateLambda(argument), location);
|
|
1030
984
|
return createOpArg(resolveName(getOperatorArgumentName(argument), location), location);
|
|
1031
985
|
}
|
|
@@ -1046,8 +1000,6 @@ export const generateSanySpecification = (
|
|
|
1046
1000
|
);
|
|
1047
1001
|
};
|
|
1048
1002
|
|
|
1049
|
-
// generateExprOrOpArg: an argument is an operator where the parameter takes arguments. SANY
|
|
1050
|
-
// reports an argument that doesn't fit at the operator's name and carries on.
|
|
1051
1003
|
const generateArgument = (
|
|
1052
1004
|
operator: SymbolNode,
|
|
1053
1005
|
index: number,
|
|
@@ -1075,14 +1027,17 @@ export const generateSanySpecification = (
|
|
|
1075
1027
|
argument.kind === "Subexpression" ||
|
|
1076
1028
|
argument.kind === "Apply"
|
|
1077
1029
|
) {
|
|
1078
|
-
// The selector names the operator, or reports why not and gives SANY's nullOAN.
|
|
1079
1030
|
const node = generateSelector(argument, expectedArity, false, false);
|
|
1080
1031
|
if (node.kind === "OpArg" || node.kind === "OpAppl") return node;
|
|
1081
1032
|
throw new TlaSyntaxError(
|
|
1082
1033
|
`Expected an operator argument at ${formatSanyLocation(location)}`,
|
|
1083
1034
|
);
|
|
1084
1035
|
}
|
|
1085
|
-
if (
|
|
1036
|
+
if (
|
|
1037
|
+
argument.kind === "Lambda" &&
|
|
1038
|
+
argument.location.range !== undefined &&
|
|
1039
|
+
argument.operator === undefined
|
|
1040
|
+
) {
|
|
1086
1041
|
const lambda = generateLambda(argument);
|
|
1087
1042
|
const arity = getSymbolArity(lambda);
|
|
1088
1043
|
if (arity === expectedArity) return createOpArg(lambda, location);
|
|
@@ -1107,7 +1062,6 @@ export const generateSanySpecification = (
|
|
|
1107
1062
|
return createNullNode();
|
|
1108
1063
|
};
|
|
1109
1064
|
|
|
1110
|
-
// A /\ B /\ C nests as ((A /\ B) /\ C) in SANY; tla-ts flattens it.
|
|
1111
1065
|
const generateJunction = (expression: Expression & { kind: "And" | "Or" }) => {
|
|
1112
1066
|
const location = getLocation(expression);
|
|
1113
1067
|
if (expression.isBulleted) {
|
|
@@ -1172,21 +1126,21 @@ export const generateSanySpecification = (
|
|
|
1172
1126
|
const operands: ExprOrOpArgNode[] = [generateExpression(expression.function)];
|
|
1173
1127
|
const exceptNode = applyBuiltin("$Except", operands, location);
|
|
1174
1128
|
const functionSpan = getExpressionSpan(file, expression.function);
|
|
1175
|
-
|
|
1129
|
+
let cursor = findToken(file, functionSpan.end + 1, span.end, "EXCEPT") + 1;
|
|
1176
1130
|
expression.updates.forEach((update) => {
|
|
1177
|
-
const bang = findToken(file, cursor
|
|
1131
|
+
const bang = findToken(file, cursor, span.end, "!");
|
|
1178
1132
|
const valueSpan = getParenthesizedSpan(file, getExpressionSpan(file, update.value));
|
|
1179
1133
|
const specLocation = getSpanLocation(file, { start: bang, end: valueSpan.end });
|
|
1180
|
-
|
|
1134
|
+
let pathCursor = bang + 1;
|
|
1181
1135
|
const components = update.path.map((step): ExprNode => {
|
|
1182
1136
|
if (step.kind === "Field") {
|
|
1183
|
-
const nameIndex = findNameOrKeyword(pathCursor
|
|
1184
|
-
pathCursor
|
|
1137
|
+
const nameIndex = findNameOrKeyword(pathCursor, step.name);
|
|
1138
|
+
pathCursor = nameIndex + 1;
|
|
1185
1139
|
return createString(step.name, getTokenLocation(file, nameIndex));
|
|
1186
1140
|
}
|
|
1187
|
-
const open = findToken(file, pathCursor
|
|
1141
|
+
const open = findToken(file, pathCursor, span.end, "[");
|
|
1188
1142
|
const close = getMatchingIndex(file, open);
|
|
1189
|
-
pathCursor
|
|
1143
|
+
pathCursor = close + 1;
|
|
1190
1144
|
if (step.args.length === 1) return generateExpression(step.args[0]);
|
|
1191
1145
|
return applyBuiltin(
|
|
1192
1146
|
"$Tuple",
|
|
@@ -1202,7 +1156,7 @@ export const generateSanySpecification = (
|
|
|
1202
1156
|
exceptSpecStack.pop();
|
|
1203
1157
|
exceptStack.pop();
|
|
1204
1158
|
operands.push(pair);
|
|
1205
|
-
cursor
|
|
1159
|
+
cursor = valueSpan.end + 1;
|
|
1206
1160
|
});
|
|
1207
1161
|
return exceptNode;
|
|
1208
1162
|
};
|
|
@@ -1219,11 +1173,11 @@ export const generateSanySpecification = (
|
|
|
1219
1173
|
expression: Expression & { kind: "Record" | "RecordSet" },
|
|
1220
1174
|
) => {
|
|
1221
1175
|
const span = getExpressionSpan(file, expression);
|
|
1222
|
-
|
|
1176
|
+
let cursor = span.start + 1;
|
|
1223
1177
|
const pairs = expression.fields.map((field, fieldIndex) => {
|
|
1224
|
-
const nameIndex = findNameOrKeyword(cursor
|
|
1178
|
+
const nameIndex = findNameOrKeyword(cursor, field.name);
|
|
1225
1179
|
const valueSpan = getParenthesizedSpan(file, getExpressionSpan(file, field.value));
|
|
1226
|
-
cursor
|
|
1180
|
+
cursor = valueSpan.end + 1;
|
|
1227
1181
|
if (expression.fields.slice(0, fieldIndex).some((other) => other.name === field.name)) {
|
|
1228
1182
|
addError(getTokenLocation(file, nameIndex), "Non-unique fields in constructor.");
|
|
1229
1183
|
}
|
|
@@ -1246,8 +1200,6 @@ export const generateSanySpecification = (
|
|
|
1246
1200
|
column: file.tokens[index].column,
|
|
1247
1201
|
});
|
|
1248
1202
|
|
|
1249
|
-
// The declarations of a RECURSIVE statement, which the syntax tree of a LET leaves out:
|
|
1250
|
-
// names, each with (_, ...) for its arguments.
|
|
1251
1203
|
const getRecursiveDeclarations = (start: number) => {
|
|
1252
1204
|
const declarations: Declaration[] = [];
|
|
1253
1205
|
let index = start;
|
|
@@ -1274,7 +1226,6 @@ export const generateSanySpecification = (
|
|
|
1274
1226
|
return declarations;
|
|
1275
1227
|
};
|
|
1276
1228
|
|
|
1277
|
-
// The units of a LET in source order, with its RECURSIVE statements found among its tokens.
|
|
1278
1229
|
const getLetUnits = (expression: Expression & { kind: "Let" }) => {
|
|
1279
1230
|
const units = [
|
|
1280
1231
|
...expression.definitions.map((definition) => ({
|
|
@@ -1343,7 +1294,6 @@ export const generateSanySpecification = (
|
|
|
1343
1294
|
const names = pattern.kind === "Name" ? [pattern.name] : pattern.names;
|
|
1344
1295
|
if (expression.set === undefined) {
|
|
1345
1296
|
const indexes = findNameTokens(file, span.start, span.end, names);
|
|
1346
|
-
// SANY locates the symbol of CHOOSE x : P at the CHOOSE keyword.
|
|
1347
1297
|
const params = names.map((name, index) =>
|
|
1348
1298
|
createFormalParam(
|
|
1349
1299
|
name,
|
|
@@ -1370,7 +1320,6 @@ export const generateSanySpecification = (
|
|
|
1370
1320
|
});
|
|
1371
1321
|
};
|
|
1372
1322
|
|
|
1373
|
-
// An infix, prefix or postfix operator that no symbol defines, with the token SANY names it by.
|
|
1374
1323
|
const getUnresolvedOperator = (expression: Expression & { kind: "Apply" }) => {
|
|
1375
1324
|
if (
|
|
1376
1325
|
isIdentifier(expression.operator) ||
|
|
@@ -1383,7 +1332,6 @@ export const generateSanySpecification = (
|
|
|
1383
1332
|
return undefined;
|
|
1384
1333
|
}
|
|
1385
1334
|
const span = getExpressionSpan(file, expression);
|
|
1386
|
-
// SANY reports an operator applied like a function, as in op(a, b), as an unknown operator.
|
|
1387
1335
|
if (
|
|
1388
1336
|
file.tokens[span.start].text === expression.operator &&
|
|
1389
1337
|
isToken(file, span.start + 1, "(")
|
|
@@ -1496,19 +1444,14 @@ export const generateSanySpecification = (
|
|
|
1496
1444
|
case "Let":
|
|
1497
1445
|
return generateLet(expression);
|
|
1498
1446
|
case "Forall":
|
|
1499
|
-
case "Exists":
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
location,
|
|
1508
|
-
bounds,
|
|
1509
|
-
);
|
|
1510
|
-
});
|
|
1511
|
-
}
|
|
1447
|
+
case "Exists":
|
|
1448
|
+
return generateBoundApplication(
|
|
1449
|
+
expression.kind === "Forall" ? "$BoundedForall" : "$BoundedExists",
|
|
1450
|
+
expression.bounds,
|
|
1451
|
+
getExpressionSpan(file, expression).start,
|
|
1452
|
+
expression.body,
|
|
1453
|
+
location,
|
|
1454
|
+
);
|
|
1512
1455
|
case "UnboundedQuantifier": {
|
|
1513
1456
|
const span = getExpressionSpan(file, expression);
|
|
1514
1457
|
const bodySpan = getExpressionSpan(file, expression.body);
|
|
@@ -1547,22 +1490,22 @@ export const generateSanySpecification = (
|
|
|
1547
1490
|
return applyBuiltin("$SubsetOf", [body], location, bounds);
|
|
1548
1491
|
});
|
|
1549
1492
|
}
|
|
1550
|
-
case "SetMap":
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
case "FunctionConstruction":
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1493
|
+
case "SetMap":
|
|
1494
|
+
return generateBoundApplication(
|
|
1495
|
+
"$SetOfAll",
|
|
1496
|
+
expression.bounds,
|
|
1497
|
+
getExpressionSpan(file, expression.expression).end + 1,
|
|
1498
|
+
expression.expression,
|
|
1499
|
+
location,
|
|
1500
|
+
);
|
|
1501
|
+
case "FunctionConstruction":
|
|
1502
|
+
return generateBoundApplication(
|
|
1503
|
+
"$FcnConstructor",
|
|
1504
|
+
expression.bounds,
|
|
1505
|
+
getExpressionSpan(file, expression).start,
|
|
1506
|
+
expression.body,
|
|
1507
|
+
location,
|
|
1508
|
+
);
|
|
1566
1509
|
case "FunctionSet":
|
|
1567
1510
|
return applyBuiltin(
|
|
1568
1511
|
"$SetOfFcns",
|
|
@@ -1592,9 +1535,30 @@ export const generateSanySpecification = (
|
|
|
1592
1535
|
}
|
|
1593
1536
|
case "FunctionApplication": {
|
|
1594
1537
|
const functionNode = generateExpression(expression.function);
|
|
1595
|
-
// SANY leaves the whole application null, without generating its arguments.
|
|
1596
1538
|
if (isAbsent(functionNode)) return functionNode;
|
|
1597
1539
|
checkRecursion(functionNode);
|
|
1540
|
+
const operator = functionNode.kind === "OpAppl" ? functionNode.operator : undefined;
|
|
1541
|
+
const body =
|
|
1542
|
+
operator?.kind === "OpDef" && operator.defKind === "UserDefined"
|
|
1543
|
+
? operator.body
|
|
1544
|
+
: undefined;
|
|
1545
|
+
if (
|
|
1546
|
+
body?.kind === "OpAppl" &&
|
|
1547
|
+
(body.operator.name === "$NonRecursiveFcnSpec" ||
|
|
1548
|
+
body.operator.name === "$RecursiveFcnSpec")
|
|
1549
|
+
) {
|
|
1550
|
+
const paramCount = (body.bounded ?? []).reduce(
|
|
1551
|
+
(count, params, index) => count + (body.tupleOrs?.[index] ? 1 : params.length),
|
|
1552
|
+
0,
|
|
1553
|
+
);
|
|
1554
|
+
if (expression.args.length >= 2 && paramCount !== expression.args.length) {
|
|
1555
|
+
addError(
|
|
1556
|
+
location,
|
|
1557
|
+
`Function '${operator?.name}' is defined with ${paramCount} parameters, but is applied to ${expression.args.length} arguments.`,
|
|
1558
|
+
);
|
|
1559
|
+
return createNullNode();
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1598
1562
|
const argument =
|
|
1599
1563
|
expression.args.length === 1
|
|
1600
1564
|
? generateExpression(expression.args[0])
|
|
@@ -1643,14 +1607,14 @@ export const generateSanySpecification = (
|
|
|
1643
1607
|
ranges: ExprNode[],
|
|
1644
1608
|
): BoundSymbols => {
|
|
1645
1609
|
const groups = getBoundGroups(bounds);
|
|
1646
|
-
|
|
1610
|
+
let cursor = searchStart;
|
|
1647
1611
|
const bounded = groups.map((group) => {
|
|
1648
1612
|
const setSpan = getExpressionSpan(file, group[0].set);
|
|
1649
1613
|
const names = group.flatMap((bound) =>
|
|
1650
1614
|
bound.pattern.kind === "Name" ? [bound.pattern.name] : bound.pattern.names,
|
|
1651
1615
|
);
|
|
1652
|
-
const indexes = findNameTokens(file, cursor
|
|
1653
|
-
cursor
|
|
1616
|
+
const indexes = findNameTokens(file, cursor, setSpan.start, names);
|
|
1617
|
+
cursor = setSpan.end + 1;
|
|
1654
1618
|
return names.map((name, index) =>
|
|
1655
1619
|
createFormalParam(name, 0, getTokenLocation(file, indexes[index]), true),
|
|
1656
1620
|
);
|
|
@@ -1669,8 +1633,6 @@ export const generateSanySpecification = (
|
|
|
1669
1633
|
addError(location, "Label not in definition or proof step.");
|
|
1670
1634
|
return createNullNode();
|
|
1671
1635
|
}
|
|
1672
|
-
// Generator.noLabelsAllowed: no label lies in the scope of a declaration of a nested
|
|
1673
|
-
// ASSUME/PROVE.
|
|
1674
1636
|
if (assumeProveState.isDeclared.slice(2, assumeProveState.depth + 1).some(Boolean)) {
|
|
1675
1637
|
addError(location, "Label not allowed within scope of declaration in nested ASSUME/PROVE.");
|
|
1676
1638
|
return createNullNode();
|
|
@@ -1705,7 +1667,6 @@ export const generateSanySpecification = (
|
|
|
1705
1667
|
isAssumeProve: false,
|
|
1706
1668
|
location,
|
|
1707
1669
|
};
|
|
1708
|
-
// Generator.formalParamsEqual: a label names each parameter bound around it once.
|
|
1709
1670
|
const named = new Set<FormalParamNode>();
|
|
1710
1671
|
params.forEach((param) => {
|
|
1711
1672
|
if (named.has(param)) {
|
|
@@ -1732,22 +1693,21 @@ export const generateSanySpecification = (
|
|
|
1732
1693
|
return label;
|
|
1733
1694
|
};
|
|
1734
1695
|
|
|
1735
|
-
// The parameters of a definition's left-hand side, located as SANY locates them: a name, or a
|
|
1736
|
-
// name with its underscores like Op(_, _).
|
|
1737
1696
|
const getParams = (
|
|
1738
1697
|
definition: OperatorDefinition | Instance,
|
|
1739
1698
|
span: TokenSpan,
|
|
1740
1699
|
isAdded: boolean,
|
|
1741
1700
|
) => {
|
|
1742
|
-
|
|
1701
|
+
let cursor = span.start;
|
|
1743
1702
|
return definition.params.map((param) => {
|
|
1744
1703
|
const index = param.location
|
|
1745
1704
|
? getTokenIndex(file, param.location)
|
|
1746
|
-
: findNameOrKeyword(cursor
|
|
1705
|
+
: findNameOrKeyword(cursor, param.name);
|
|
1747
1706
|
const paramSpan = getOperatorSpan(index, param.arity);
|
|
1748
|
-
cursor
|
|
1707
|
+
cursor = paramSpan.end + 1;
|
|
1708
|
+
const isPrefix = param.arity === 1 && isToken(file, index + 1, "_");
|
|
1749
1709
|
return createFormalParam(
|
|
1750
|
-
resolveSynonym(param.name),
|
|
1710
|
+
isPrefix ? (file.tokens[index].spelling ?? param.name) : resolveSynonym(param.name),
|
|
1751
1711
|
param.arity,
|
|
1752
1712
|
getSpanLocation(file, paramSpan),
|
|
1753
1713
|
isAdded,
|
|
@@ -1755,7 +1715,6 @@ export const generateSanySpecification = (
|
|
|
1755
1715
|
});
|
|
1756
1716
|
};
|
|
1757
1717
|
|
|
1758
|
-
// The span of a definition or instance, with the LOCAL before it.
|
|
1759
1718
|
const getDefinitionSpan = (definition: { location: SourceLocation; isLocal?: boolean }) => {
|
|
1760
1719
|
const span = getUnitSpan(definition.location);
|
|
1761
1720
|
return definition.isLocal &&
|
|
@@ -1777,10 +1736,8 @@ export const generateSanySpecification = (
|
|
|
1777
1736
|
const params = getParams(definition, paramsSpan, true);
|
|
1778
1737
|
const existing = resolveSymbol(symbolTable, name);
|
|
1779
1738
|
if (existing?.kind === "OpDef" && existing.inRecursive && !existing.isDefined) {
|
|
1780
|
-
// SANY compares only the arity of the last parameter.
|
|
1781
1739
|
const isMatching =
|
|
1782
|
-
existing.params?.length === params.length &&
|
|
1783
|
-
(params.length === 0 || params[params.length - 1].arity === 0);
|
|
1740
|
+
existing.params?.length === params.length && params.every((param) => param.arity === 0);
|
|
1784
1741
|
if (existing.letInLevel !== state.curLevel) {
|
|
1785
1742
|
addError(location, `Recursive operator ${name} defined at wrong LET/IN level.`);
|
|
1786
1743
|
} else {
|
|
@@ -1790,7 +1747,6 @@ export const generateSanySpecification = (
|
|
|
1790
1747
|
`Definition of ${existing.name} has different arity than its RECURSIVE declaration.`,
|
|
1791
1748
|
);
|
|
1792
1749
|
}
|
|
1793
|
-
// SANY sets the parameters before it analyzes the body.
|
|
1794
1750
|
existing.params = params;
|
|
1795
1751
|
}
|
|
1796
1752
|
} else if (existing !== undefined) {
|
|
@@ -1858,7 +1814,7 @@ export const generateSanySpecification = (
|
|
|
1858
1814
|
const context = createContext();
|
|
1859
1815
|
const nameIndex = definition.isLocal ? span.start + 1 : span.start;
|
|
1860
1816
|
const bounds = withContext(context, () => generateBounds(definition.bounds, nameIndex + 1));
|
|
1861
|
-
const existing = resolveSymbol(symbolTable, definition.name);
|
|
1817
|
+
const existing = withContext(context, () => resolveSymbol(symbolTable, definition.name));
|
|
1862
1818
|
const recursionParam = withContext(context, () =>
|
|
1863
1819
|
createFormalParam(definition.name, 0, location, existing === undefined),
|
|
1864
1820
|
);
|
|
@@ -1882,8 +1838,6 @@ export const generateSanySpecification = (
|
|
|
1882
1838
|
addError(location, `Function name \`${definition.name}' already defined or declared.`);
|
|
1883
1839
|
}
|
|
1884
1840
|
const preComments = getPreComments(file, span.start);
|
|
1885
|
-
// Generator.processFunction's OpDefNode: a new one, or the one the name already has, though
|
|
1886
|
-
// defined, unless that is declared RECURSIVE at another level.
|
|
1887
1841
|
const definitionNode =
|
|
1888
1842
|
existing === undefined
|
|
1889
1843
|
? createOpDef({
|
|
@@ -1897,7 +1851,6 @@ export const generateSanySpecification = (
|
|
|
1897
1851
|
: existing.kind === "OpDef" && (isRecursive || !isPendingRecursive)
|
|
1898
1852
|
? existing
|
|
1899
1853
|
: undefined;
|
|
1900
|
-
// A function whose RECURSIVE declaration has parameters stays undefined.
|
|
1901
1854
|
if (isRecursive) {
|
|
1902
1855
|
if (existing.arity === 0) endOpDefNode(existing, node, location, preComments);
|
|
1903
1856
|
} else if (existing === undefined && definitionNode !== undefined) {
|
|
@@ -1910,7 +1863,6 @@ export const generateSanySpecification = (
|
|
|
1910
1863
|
}
|
|
1911
1864
|
functions.unshift({ name: definition.name, node });
|
|
1912
1865
|
pushLabelScope();
|
|
1913
|
-
// The bound identifiers are bound in the body only of a function with an OpDefNode.
|
|
1914
1866
|
const generateBody = () => generateWithParams(bounds.bounded.flat(), definition.body);
|
|
1915
1867
|
const body =
|
|
1916
1868
|
definitionNode === undefined ? generateBody() : withContext(context, generateBody);
|
|
@@ -1962,16 +1914,12 @@ export const generateSanySpecification = (
|
|
|
1962
1914
|
state.unresolvedSum -= state.unresolvedCount[state.curLevel];
|
|
1963
1915
|
};
|
|
1964
1916
|
|
|
1965
|
-
// SubstInNode's constructor and processSubst: an implicit substitution for each declaration of
|
|
1966
|
-
// the instantiated module whose name the instantiating module can resolve, in the order of the
|
|
1967
|
-
// instantiated module's Hashtable, then the explicit WITH substitutions.
|
|
1968
1917
|
const processSubstitutions = (
|
|
1969
1918
|
instance: Instance,
|
|
1970
1919
|
instanceeContext: Context,
|
|
1971
1920
|
location: SanyLocation,
|
|
1972
1921
|
) => {
|
|
1973
|
-
// The SubstInNode processSubst creates
|
|
1974
|
-
// templates use.
|
|
1922
|
+
// The SubstInNode processSubst creates, which only the substitutions' templates use.
|
|
1975
1923
|
getId();
|
|
1976
1924
|
const declarations = getHashtableValues(instanceeContext.table).filter(
|
|
1977
1925
|
(symbol): symbol is OpDeclNode => symbol.kind === "OpDecl",
|
|
@@ -1982,6 +1930,7 @@ export const generateSanySpecification = (
|
|
|
1982
1930
|
const isExpression =
|
|
1983
1931
|
declaration.declKind === VARIABLE_DECL_KIND ||
|
|
1984
1932
|
(declaration.declKind === CONSTANT_DECL_KIND && declaration.arity === 0);
|
|
1933
|
+
if (isExpression) matchArguments(symbol, [], location);
|
|
1985
1934
|
return [
|
|
1986
1935
|
{
|
|
1987
1936
|
op: declaration,
|
|
@@ -1990,13 +1939,9 @@ export const generateSanySpecification = (
|
|
|
1990
1939
|
},
|
|
1991
1940
|
];
|
|
1992
1941
|
});
|
|
1993
|
-
// Generator.checkSubstitutionForCorrectArity, which SANY locates in its builtins for the
|
|
1994
|
-
// nullOpArg it substitutes after an error.
|
|
1995
1942
|
const checkArity = (target: OpDeclNode, substitute: ExprOrOpArgNode) => {
|
|
1996
1943
|
const arity = substitute.kind === "OpArg" ? getSymbolArity(substitute.op) : 0;
|
|
1997
|
-
|
|
1998
|
-
target.arity > 0 && substitute.kind === "OpAppl" && substitute.isNull === true;
|
|
1999
|
-
if (arity !== target.arity && !isNullOpArg) {
|
|
1944
|
+
if (arity !== target.arity) {
|
|
2000
1945
|
addError(
|
|
2001
1946
|
substitute.location,
|
|
2002
1947
|
`An operator must be substituted for symbol '${target.name}', and it must have arity ${target.arity}.`,
|
|
@@ -2004,13 +1949,11 @@ export const generateSanySpecification = (
|
|
|
2004
1949
|
}
|
|
2005
1950
|
};
|
|
2006
1951
|
const span = getDefinitionSpan(instance);
|
|
2007
|
-
|
|
2008
|
-
const cursor = { value: findToken(file, span.start, span.end, "WITH") + 1 };
|
|
1952
|
+
let cursor = findToken(file, span.start, span.end, "WITH") + 1;
|
|
2009
1953
|
instance.substitutions.forEach((substitution) => {
|
|
2010
|
-
const targetIndex = findToken(file, cursor
|
|
2011
|
-
// The next target follows this substitution's expression, which may name it too.
|
|
1954
|
+
const targetIndex = findToken(file, cursor, span.end, substitution.name);
|
|
2012
1955
|
if (targetIndex !== -1) {
|
|
2013
|
-
cursor
|
|
1956
|
+
cursor = getExpressionSpan(file, substitution.expression).end + 1;
|
|
2014
1957
|
}
|
|
2015
1958
|
const target = getContextSymbol(instanceeContext, resolveSynonym(substitution.name));
|
|
2016
1959
|
if (target?.kind !== "OpDecl") {
|
|
@@ -2036,11 +1979,9 @@ export const generateSanySpecification = (
|
|
|
2036
1979
|
existing.isImplicit = false;
|
|
2037
1980
|
} else substs.push({ op: target, expr: substitute, isImplicit: false });
|
|
2038
1981
|
});
|
|
2039
|
-
// TLC 1.7.4's SANY checks the arity of only the substitutions that the INSTANCE writes.
|
|
2040
1982
|
substs
|
|
2041
1983
|
.filter((subst) => subst.isImplicit && options.version !== "1.7.4")
|
|
2042
1984
|
.forEach((subst) => checkArity(subst.op, subst.expr));
|
|
2043
|
-
// SubstInNode.matchAll.
|
|
2044
1985
|
declarations
|
|
2045
1986
|
.filter((declaration) => !substs.some((subst) => subst.op.name === declaration.name))
|
|
2046
1987
|
.forEach((declaration) =>
|
|
@@ -2182,12 +2123,9 @@ export const generateSanySpecification = (
|
|
|
2182
2123
|
preComments,
|
|
2183
2124
|
});
|
|
2184
2125
|
addSymbol(symbolTable, moduleDefinition);
|
|
2185
|
-
// TLC 1.7.4's SANY leaves the definition out of the definitions of a LET.
|
|
2186
2126
|
if (options.version !== "1.7.4") definitions?.push(moduleDefinition);
|
|
2187
2127
|
};
|
|
2188
2128
|
|
|
2189
|
-
// generateInstance: an INSTANCE step of a proof is located at the step's body and adds no
|
|
2190
|
-
// theorem definitions or instance to the module.
|
|
2191
2129
|
const generateInstance = (
|
|
2192
2130
|
instance: Instance,
|
|
2193
2131
|
isTopLevel = true,
|
|
@@ -2236,8 +2174,6 @@ export const generateSanySpecification = (
|
|
|
2236
2174
|
currentModule.definitions.push(node);
|
|
2237
2175
|
setRecursionFields(node);
|
|
2238
2176
|
});
|
|
2239
|
-
// SANY reuses a theorem of a parameter-free module without adding it to the symbol table
|
|
2240
|
-
// when the instantiated module has parameters.
|
|
2241
2177
|
getHashtableValues(instanceeContext.table).forEach((symbol) => {
|
|
2242
2178
|
if (symbol.kind !== "ThmOrAssumpDef" || symbol.isLocal) return;
|
|
2243
2179
|
const copyFrom = (module: ModuleNode, body: LevelNode) => {
|
|
@@ -2285,7 +2221,6 @@ export const generateSanySpecification = (
|
|
|
2285
2221
|
return instanceNode;
|
|
2286
2222
|
};
|
|
2287
2223
|
|
|
2288
|
-
// SANY leaves out a module it can't resolve, after reporting it at the module's name.
|
|
2289
2224
|
const getFactModules = (fact: Fact & { kind: "ModuleFact" }) => {
|
|
2290
2225
|
const module =
|
|
2291
2226
|
resolveModule(fact.name) ?? (fact.name === currentModule.name ? currentModule : undefined);
|
|
@@ -2297,8 +2232,6 @@ export const generateSanySpecification = (
|
|
|
2297
2232
|
return [];
|
|
2298
2233
|
};
|
|
2299
2234
|
|
|
2300
|
-
// A fact is a module, or an expression such as the name of a theorem; a DEF names a defined
|
|
2301
|
-
// operator, theorem or assumption, or a module.
|
|
2302
2235
|
const generateFacts = (facts: Fact[]) =>
|
|
2303
2236
|
facts.flatMap((fact): FactNode[] => {
|
|
2304
2237
|
if (fact.kind === "ModuleFact") return getFactModules(fact);
|
|
@@ -2313,30 +2246,24 @@ export const generateSanySpecification = (
|
|
|
2313
2246
|
isToken(file, span.start, "(") && getMatchingIndex(file, span.start) === span.end;
|
|
2314
2247
|
const getOperandSpan = (expression: Expression) =>
|
|
2315
2248
|
getParenthesizedSpan(file, getExpressionSpan(file, expression));
|
|
2316
|
-
// How SANY's parser shapes an application: as a prefix, infix or postfix operator's, or a name's.
|
|
2317
2249
|
const getApplicationKind = (expression: Expression & { kind: "Apply" }, span: TokenSpan) => {
|
|
2318
2250
|
if (getOperandSpan(expression.args[0]).start === span.start) {
|
|
2319
2251
|
return expression.args.length === 2 ? "N_InfixExpr" : "N_PostfixExpr";
|
|
2320
2252
|
}
|
|
2321
2253
|
return file.tokens[span.start].kind === "Identifier" ? "N_OpApplication" : "N_PrefixExpr";
|
|
2322
2254
|
};
|
|
2323
|
-
// The kind of SANY's syntax node for an expression, or for a token its text.
|
|
2324
2255
|
const getSyntaxKind = (expression: Expression, span: TokenSpan) => {
|
|
2325
2256
|
if (isParenthesized(span)) return "N_ParenExpr";
|
|
2326
2257
|
if (expression.kind === "String") return getTokenSource(file, span.start);
|
|
2327
2258
|
if (expression.kind === "Apply") return getApplicationKind(expression, span);
|
|
2328
2259
|
return SYNTAX_KINDS.get(expression.kind);
|
|
2329
2260
|
};
|
|
2330
|
-
// Whether the first child of an expression's syntax node is a node without children, which
|
|
2331
|
-
// Generator.genIdToSelector takes for an empty prefix of a name. A string is a token itself.
|
|
2332
2261
|
const hasChildlessFirstChild = (expression: Expression, span: TokenSpan) => {
|
|
2333
2262
|
if (expression.kind === "String" && !isParenthesized(span)) return false;
|
|
2334
2263
|
if (expression.kind === "Identifier" && !expression.name.includes("!")) return true;
|
|
2335
2264
|
const kind = getSyntaxKind(expression, span);
|
|
2336
2265
|
return kind === undefined || NESTED_FIRST_CHILD_KINDS.has(kind) ? undefined : true;
|
|
2337
2266
|
};
|
|
2338
|
-
// Generator.genIdToSelector reads the syntax node of a DEF clause entry that isn't a name as
|
|
2339
|
-
// a name: its first child as the name's prefix and its second as the name's last part.
|
|
2340
2267
|
const getDefEntryParts = (
|
|
2341
2268
|
expression: Expression,
|
|
2342
2269
|
span: TokenSpan,
|
|
@@ -2425,8 +2352,6 @@ export const generateSanySpecification = (
|
|
|
2425
2352
|
}
|
|
2426
2353
|
return undefined;
|
|
2427
2354
|
};
|
|
2428
|
-
// The errors of Generator.genIdToSelector and selectorToNode for a DEF clause entry that isn't
|
|
2429
|
-
// a name, or false where SANY's reading of the entry isn't modeled.
|
|
2430
2355
|
const reportDefEntry = (expression: Expression) => {
|
|
2431
2356
|
const span = getParenthesizedSpan(file, getExpressionSpan(file, expression));
|
|
2432
2357
|
const isName =
|
|
@@ -2462,8 +2387,6 @@ export const generateSanySpecification = (
|
|
|
2462
2387
|
false,
|
|
2463
2388
|
true,
|
|
2464
2389
|
);
|
|
2465
|
-
// SANY rejects the name of a proof step in a DEF clause, and leaves out an entry it rejects.
|
|
2466
|
-
// Errors.addMessage drops the message when selectorToNode already reported it.
|
|
2467
2390
|
const isDefinition =
|
|
2468
2391
|
symbol.kind === "OpDef" ||
|
|
2469
2392
|
(symbol.kind === "ThmOrAssumpDef" && !symbol.name.startsWith("<"));
|
|
@@ -2474,8 +2397,6 @@ export const generateSanySpecification = (
|
|
|
2474
2397
|
return [symbol];
|
|
2475
2398
|
});
|
|
2476
2399
|
|
|
2477
|
-
// SANY's generateUseOrHide rejects a BY, USE, or HIDE with nothing after its keyword before it
|
|
2478
|
-
// reads the facts.
|
|
2479
2400
|
const checkKeywordOnly = (
|
|
2480
2401
|
statement: UseOrHide | Extract<Proof, { kind: "By" }>,
|
|
2481
2402
|
location: SanyLocation,
|
|
@@ -2490,7 +2411,6 @@ export const generateSanySpecification = (
|
|
|
2490
2411
|
const facts = generateFacts(use.facts);
|
|
2491
2412
|
const defs = generateDefs(use.defs);
|
|
2492
2413
|
if (facts.length + defs.length === 0) addError(location, "Empty USE or HIDE statement.");
|
|
2493
|
-
// UseOrHideNode.factCheck, after SANY generates the node: a HIDE cites facts by name only.
|
|
2494
2414
|
if (use.kind === "Hide") {
|
|
2495
2415
|
facts
|
|
2496
2416
|
.filter((fact) => fact.kind === "OpAppl" && fact.operator.kind !== "ThmOrAssumpDef")
|
|
@@ -2512,7 +2432,6 @@ export const generateSanySpecification = (
|
|
|
2512
2432
|
};
|
|
2513
2433
|
};
|
|
2514
2434
|
|
|
2515
|
-
// generateNewSymb: the set is generated before the symbol is declared.
|
|
2516
2435
|
const generateNewSymbol = (symbol: NewSymbol): NewSymbNode => {
|
|
2517
2436
|
const span = getUnitSpan(symbol.location);
|
|
2518
2437
|
const set = symbol.set && generateExpression(symbol.set);
|
|
@@ -2539,7 +2458,6 @@ export const generateSanySpecification = (
|
|
|
2539
2458
|
};
|
|
2540
2459
|
};
|
|
2541
2460
|
|
|
2542
|
-
// generateAssumeProve: an ASSUME/PROVE nested in another one has a context of its own.
|
|
2543
2461
|
const generateAssumeProve = (
|
|
2544
2462
|
assumeProve: AssumeProve,
|
|
2545
2463
|
depth: number,
|
|
@@ -2564,7 +2482,7 @@ export const generateSanySpecification = (
|
|
|
2564
2482
|
: "ASSUME matched by []PROVE instead of PROVE",
|
|
2565
2483
|
);
|
|
2566
2484
|
}
|
|
2567
|
-
// SANY
|
|
2485
|
+
// SANY numbers the AssumeProveNode before it generates its clauses.
|
|
2568
2486
|
const id = getId();
|
|
2569
2487
|
if (depth > 1) symbolTable.contexts.push(createContext());
|
|
2570
2488
|
if (isBoxed && symbolTable.contexts.some((context) => assumeContexts.has(context))) {
|
|
@@ -2620,8 +2538,6 @@ export const generateSanySpecification = (
|
|
|
2620
2538
|
return node;
|
|
2621
2539
|
};
|
|
2622
2540
|
|
|
2623
|
-
// SANY creates the ThmOrAssumpDefNode of a named theorem or proof step, numbering it, before it
|
|
2624
|
-
// generates what it asserts.
|
|
2625
2541
|
const createTheoremDefinition = (
|
|
2626
2542
|
id: number,
|
|
2627
2543
|
name: string,
|
|
@@ -2653,7 +2569,7 @@ export const generateSanySpecification = (
|
|
|
2653
2569
|
if (proof.kind === "By") checkKeywordOnly(proof, location);
|
|
2654
2570
|
const facts = proof.kind === "By" ? generateFacts(proof.facts) : [];
|
|
2655
2571
|
const defs = proof.kind === "By" ? generateDefs(proof.defs) : [];
|
|
2656
|
-
// SANY
|
|
2572
|
+
// The UseOrHideNode SANY makes of a BY proof's facts and definitions.
|
|
2657
2573
|
if (proof.kind === "By") getId();
|
|
2658
2574
|
if (proof.kind === "By" && facts.length + defs.length === 0) addError(location, "Empty BY");
|
|
2659
2575
|
return {
|
|
@@ -2711,7 +2627,6 @@ export const generateSanySpecification = (
|
|
|
2711
2627
|
return undefined;
|
|
2712
2628
|
};
|
|
2713
2629
|
|
|
2714
|
-
// An expression SANY parses as N_InfixExpr: a binary operator between its operands.
|
|
2715
2630
|
const isInfixExpression = (expression: Expression) => {
|
|
2716
2631
|
if ((expression.kind === "And" || expression.kind === "Or") && !expression.isBulleted)
|
|
2717
2632
|
return true;
|
|
@@ -2721,20 +2636,13 @@ export const generateSanySpecification = (
|
|
|
2721
2636
|
return left.start === start && !isToken(file, left.end + 1, "(");
|
|
2722
2637
|
};
|
|
2723
2638
|
|
|
2724
|
-
// generateProof: a proof's steps share a context, into which the step names, the symbols of
|
|
2725
|
-
// a TAKE or PICK, and the NEW symbols of a SUFFICES ASSUME go.
|
|
2726
2639
|
const generateProof = (proof: Proof): LeafProofNode | NonLeafProofNode => {
|
|
2727
2640
|
if (proof.kind !== "Steps") return generateLeafProof(proof);
|
|
2728
2641
|
const proofContext = createContext();
|
|
2729
2642
|
symbolTable.contexts.push(proofContext);
|
|
2730
2643
|
const instances: InstanceNode[] = [];
|
|
2731
2644
|
const sufficesContexts: Context[] = [];
|
|
2732
|
-
|
|
2733
|
-
// side the @ stands for.
|
|
2734
|
-
const infixStep: { previousRight: ExprOrOpArgNode | undefined } = {
|
|
2735
|
-
previousRight: undefined,
|
|
2736
|
-
};
|
|
2737
|
-
// A DEFINE, USE, HIDE or INSTANCE step.
|
|
2645
|
+
let previousRight: ExprOrOpArgNode | undefined;
|
|
2738
2646
|
const generateOtherStep = (
|
|
2739
2647
|
body: ProofStep["body"],
|
|
2740
2648
|
stepSpan: TokenSpan,
|
|
@@ -2772,13 +2680,17 @@ export const generateSanySpecification = (
|
|
|
2772
2680
|
const headSpan = getRangeSpan(file, step.head);
|
|
2773
2681
|
const bodySpan = { start: headSpan.start + 1, end: headSpan.end };
|
|
2774
2682
|
const body = step.body;
|
|
2683
|
+
if (step.name !== undefined && /^<[*+]>/.test(step.token)) {
|
|
2684
|
+
addError(
|
|
2685
|
+
getTokenLocation(file, stepSpan.start),
|
|
2686
|
+
"<*> and <+> cannot be used for a named step.",
|
|
2687
|
+
);
|
|
2688
|
+
}
|
|
2775
2689
|
if (step.name !== undefined) pushLabelScope();
|
|
2776
2690
|
const definitionId = step.name === undefined ? undefined : getId();
|
|
2777
|
-
if (body.kind !== "Assert")
|
|
2691
|
+
if (body.kind !== "Assert") previousRight = undefined;
|
|
2778
2692
|
const otherStep = generateOtherStep(body, stepSpan, bodySpan);
|
|
2779
2693
|
if (otherStep !== undefined) {
|
|
2780
|
-
// SANY puts a NumberedProofStep definition for a named step that asserts nothing in the
|
|
2781
|
-
// symbol table, for a DEF clause to name.
|
|
2782
2694
|
if (step.name !== undefined) {
|
|
2783
2695
|
addSymbol(
|
|
2784
2696
|
symbolTable,
|
|
@@ -2794,7 +2706,7 @@ export const generateSanySpecification = (
|
|
|
2794
2706
|
return otherStep;
|
|
2795
2707
|
}
|
|
2796
2708
|
const isAssumeProve = body.kind === "Assert" && body.statement.kind === "AssumeProve";
|
|
2797
|
-
if (isAssumeProve)
|
|
2709
|
+
if (isAssumeProve) previousRight = undefined;
|
|
2798
2710
|
const isSuffices = body.kind === "Assert" && body.isSuffices;
|
|
2799
2711
|
const assumeContext = createContext();
|
|
2800
2712
|
const generateAssertion = (statement: Expression | AssumeProve): LevelNode => {
|
|
@@ -2813,7 +2725,6 @@ export const generateSanySpecification = (
|
|
|
2813
2725
|
const expression = generateExpression(statement);
|
|
2814
2726
|
return applyBuiltin("$Suffices", [expression], getSpanLocation(file, bodySpan));
|
|
2815
2727
|
}
|
|
2816
|
-
const previousRight = infixStep.previousRight;
|
|
2817
2728
|
const isAtStep =
|
|
2818
2729
|
previousRight !== undefined &&
|
|
2819
2730
|
statement.kind === "Apply" &&
|
|
@@ -2829,7 +2740,7 @@ export const generateSanySpecification = (
|
|
|
2829
2740
|
)
|
|
2830
2741
|
: generateExpression(statement);
|
|
2831
2742
|
const right = expression.kind === "OpAppl" ? expression.operands[1] : undefined;
|
|
2832
|
-
|
|
2743
|
+
previousRight = isInfixExpression(statement) ? right : undefined;
|
|
2833
2744
|
return expression;
|
|
2834
2745
|
};
|
|
2835
2746
|
const generated =
|
|
@@ -2883,8 +2794,6 @@ export const generateSanySpecification = (
|
|
|
2883
2794
|
};
|
|
2884
2795
|
};
|
|
2885
2796
|
|
|
2886
|
-
// processTheorem: a theorem's ASSUME/PROVE has a context of its own, which its proof sees and
|
|
2887
|
-
// its definition does not.
|
|
2888
2797
|
const processTheorem = (theorem: Theorem) => {
|
|
2889
2798
|
const location = getSpanLocation(file, getUnitSpan(theorem.location));
|
|
2890
2799
|
const statement = theorem.statement;
|
|
@@ -2948,8 +2857,6 @@ export const generateSanySpecification = (
|
|
|
2948
2857
|
currentModule.topLevel.push(node);
|
|
2949
2858
|
};
|
|
2950
2859
|
|
|
2951
|
-
// A declared operator or operator parameter is located with its arguments: F(_, _), _ + _,
|
|
2952
|
-
// -. _ or _ ^+.
|
|
2953
2860
|
const getOperatorSpan = (start: number, arity: number) => {
|
|
2954
2861
|
if (arity === 0) return { start, end: start };
|
|
2955
2862
|
if (isToken(file, start, "_")) {
|
|
@@ -2964,8 +2871,6 @@ export const generateSanySpecification = (
|
|
|
2964
2871
|
|
|
2965
2872
|
const createDeclaration = (declaration: Declaration, declKind: number): OpDeclNode => {
|
|
2966
2873
|
const span = getDeclarationSpan(declaration);
|
|
2967
|
-
// Generator.processParameters makes the same check of a constant, of the name of its
|
|
2968
|
-
// declaration's syntax node, which is never @.
|
|
2969
2874
|
if (declaration.name === "@" && declKind === VARIABLE_DECL_KIND) {
|
|
2970
2875
|
addError(getSpanLocation(file, span), "Attempted to declare '@' as a variable.");
|
|
2971
2876
|
}
|
|
@@ -2988,8 +2893,6 @@ export const generateSanySpecification = (
|
|
|
2988
2893
|
return node;
|
|
2989
2894
|
};
|
|
2990
2895
|
|
|
2991
|
-
// processExtendsList: the extended module's symbols join this module's context in the order
|
|
2992
|
-
// they joined the extended module's, apart from LOCAL ones and those already present.
|
|
2993
2896
|
ast.extends.forEach((name) => {
|
|
2994
2897
|
const extendee = getModule(name);
|
|
2995
2898
|
currentModule.extendees.push(extendee);
|
|
@@ -3024,8 +2927,6 @@ export const generateSanySpecification = (
|
|
|
3024
2927
|
currentModule.topLevel.push(...extendee.topLevel);
|
|
3025
2928
|
});
|
|
3026
2929
|
|
|
3027
|
-
// Generator.checkIfInRecursiveSection: only definitions and instances may come between a
|
|
3028
|
-
// RECURSIVE declaration and the definition of what it declares.
|
|
3029
2930
|
const checkRecursiveSection = (location: SourceLocation, type: string) => {
|
|
3030
2931
|
if (state.unresolvedSum === 0) return;
|
|
3031
2932
|
addError(
|
|
@@ -3075,8 +2976,6 @@ export const generateSanySpecification = (
|
|
|
3075
2976
|
checkRecursiveSection(unit.module.location, "A MODULE ");
|
|
3076
2977
|
const innerTable = { contexts: [...symbolTable.contexts, createContext()] };
|
|
3077
2978
|
const inner = generateModule(unit.module, file, currentModule, innerTable);
|
|
3078
|
-
// SymbolTable.addModule: an inner module's name must not be taken by another module,
|
|
3079
|
-
// inner or external.
|
|
3080
2979
|
const binding = resolveModule(inner.name);
|
|
3081
2980
|
if (binding === undefined) addToContext(getTopContext(symbolTable), inner);
|
|
3082
2981
|
else if (binding !== inner) {
|
|
@@ -3096,11 +2995,9 @@ export const generateSanySpecification = (
|
|
|
3096
2995
|
const modules = order.map((name) => {
|
|
3097
2996
|
options.onAnalyze?.(name);
|
|
3098
2997
|
// Each module's Generator creates its nullODN, nullOAN, nullOpArg and nullLabelNode.
|
|
3099
|
-
|
|
2998
|
+
nullApplicationId = Array.from({ length: 4 }, getId)[1];
|
|
3100
2999
|
const entry = getSource(name, undefined);
|
|
3101
3000
|
const context = createContext();
|
|
3102
|
-
// A module's context starts as a copy of SANY's global context of builtins, whose list of
|
|
3103
|
-
// symbols runs from the last builtin to the first.
|
|
3104
3001
|
builtins.toReversed().forEach((builtin) => addToContext(context, builtin));
|
|
3105
3002
|
const module = generateModule(entry.module, entry.file, undefined, {
|
|
3106
3003
|
contexts: [context],
|