tla-ts 0.0.9 → 0.0.10-dev.b4a856304
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 +29 -1
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +28 -28
- package/dist/deciders.js +43 -43
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +72 -10
- package/dist/index.d.ts +72 -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 +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +128 -103
- package/dist/transfer.js +128 -103
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +7 -21
- package/src/bags.ts +99 -99
- package/src/builtins.ts +44 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check.ts +576 -300
- package/src/cli/options.ts +11 -6
- package/src/cli/run.ts +2 -2
- package/src/cli/runtime-invariants.ts +135 -0
- package/src/cli/shared.ts +20 -9
- package/src/cli/tlapm.ts +0 -12
- package/src/cli/tlc-arguments.ts +646 -0
- package/src/cli/tlc-usage.ts +362 -0
- package/src/cli/tlc.ts +538 -220
- package/src/cli/typescript.ts +23 -0
- 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 +240 -118
- package/src/errors.ts +70 -55
- package/src/evaluate.ts +630 -297
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +10 -10
- package/src/index.ts +3 -0
- package/src/instances.ts +79 -11
- package/src/java-overrides.ts +2 -12
- package/src/json-reader.ts +456 -0
- package/src/json.ts +262 -139
- package/src/levels.ts +2 -3
- package/src/lexer.ts +17 -26
- package/src/liveness-checker.ts +10 -18
- package/src/liveness.ts +121 -49
- 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 +29 -39
- package/src/parallel.ts +29 -13
- package/src/parser.ts +436 -90
- package/src/pcal/ast.ts +7 -28
- package/src/pcal/parse.ts +11 -39
- package/src/pcal/tokenize.ts +4 -20
- package/src/pcal/translate.ts +10 -42
- package/src/pcal/validate.ts +3 -21
- package/src/pretty-print.ts +1 -2
- 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 +23 -34
- 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 +84 -35
- package/src/resolve.ts +18 -60
- package/src/runtime.ts +11 -4
- package/src/sany/builtins.ts +3 -4
- package/src/sany/generator.ts +119 -169
- package/src/sany/levels.ts +6 -30
- package/src/sany/lexer.ts +7 -23
- package/src/sany/linter.ts +1 -8
- 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 +494 -154
- package/src/simulate.ts +694 -0
- package/src/spec-description.ts +166 -48
- package/src/standard-definitions.ts +2 -3
- package/src/standard-modules.ts +264 -68
- package/src/state-graph.ts +51 -18
- package/src/subexpressions.ts +31 -5
- package/src/substitution-levels.ts +2 -3
- package/src/successors.ts +267 -77
- package/src/symmetry.ts +31 -8
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -61
- package/src/tlc/jar-data.ts +113 -6
- package/src/tlc/messages.ts +122 -37
- package/src/tlc/order.ts +33 -38
- package/src/tlc/random.ts +16 -16
- package/src/tlc/replay.ts +563 -211
- package/src/tlc/summary.ts +2 -4
- package/src/tlc/tlc-operators.ts +81 -36
- package/src/tlc/tlcext-operators.ts +138 -117
- package/src/tlc/trace-spec.ts +273 -0
- package/src/tlc/value-stream.ts +143 -0
- package/src/tlc/version.ts +2 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +481 -0
- package/src/typescript/collections.ts +600 -0
- package/src/typescript/compile.ts +65 -0
- package/src/typescript/context.ts +94 -0
- package/src/typescript/emit.ts +121 -0
- package/src/typescript/expressions.ts +496 -0
- package/src/typescript/formula.ts +152 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +163 -0
- package/src/typescript/names.ts +114 -0
- package/src/typescript/program.ts +48 -0
- package/src/typescript/properties.ts +139 -0
- package/src/typescript/scope.ts +112 -0
- package/src/typescript/steps.ts +165 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +826 -276
- 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,33 @@ 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
|
+
// SANY resolves a top-level INSTANCE to an inner module only when the module's first top-level
|
|
251
|
+
// INSTANCE follows the inner module, and otherwise looks for a file. It looks for a file for an
|
|
252
|
+
// INSTANCE in a LET or a proof step too, where tla-ts takes an inner module defined before it.
|
|
253
|
+
const isInternalInstance = (module: Module, instance: Instance) => {
|
|
266
254
|
const seen = new Set<string>();
|
|
267
255
|
for (const unit of module.units) {
|
|
268
256
|
if (unit.kind === "Module") seen.add(unit.module.name);
|
|
269
|
-
if (unit.kind === "Instance" && unit.instance.module ===
|
|
257
|
+
if (unit.kind === "Instance" && unit.instance.module === instance.module) {
|
|
258
|
+
return seen.has(instance.module);
|
|
259
|
+
}
|
|
270
260
|
}
|
|
271
|
-
return
|
|
261
|
+
return module.modules.some(
|
|
262
|
+
(inner) => inner.name === instance.module && isBefore(inner.location, instance.location),
|
|
263
|
+
);
|
|
272
264
|
};
|
|
273
265
|
|
|
274
266
|
type LetUnit =
|
|
@@ -276,26 +268,21 @@ type LetUnit =
|
|
|
276
268
|
| { kind: "Instance"; instance: Instance }
|
|
277
269
|
| { kind: "Definition"; definition: Definition };
|
|
278
270
|
|
|
279
|
-
// The decimal digits of a numeral such as \hFF, which SANY keeps at any size.
|
|
280
271
|
const getNumeralDigits = (text: string) =>
|
|
281
272
|
BigInt(text.startsWith("\\") ? `0${text.slice(1).replace(/^h/i, "x")}` : text).toString();
|
|
282
273
|
|
|
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
274
|
interface LabelScope {
|
|
286
275
|
labels: Map<string, LabelNode>;
|
|
287
276
|
params: FormalParamNode[][];
|
|
288
277
|
}
|
|
289
278
|
|
|
290
|
-
//
|
|
291
|
-
// the file that names each one. SANY looks at a module's own EXTENDS and INSTANCEs before those of
|
|
292
|
-
// its inner modules.
|
|
279
|
+
// SANY looks at a module's own EXTENDS and INSTANCEs before those of its inner modules.
|
|
293
280
|
const getDependencies = (module: Module) => {
|
|
294
281
|
const extendees: string[] = [];
|
|
295
282
|
const instancees: string[] = [];
|
|
296
283
|
const importers = new Map<string, string>();
|
|
297
|
-
//
|
|
298
|
-
//
|
|
284
|
+
// A module knows the inner modules defined before it in its enclosing modules and those of the
|
|
285
|
+
// modules it extends, but not itself.
|
|
299
286
|
const visit = (current: Module, context: Map<string, Module>) => {
|
|
300
287
|
const isRoot = current === module;
|
|
301
288
|
const addImports = (names: string[], imports: string[]) =>
|
|
@@ -308,20 +295,24 @@ const getDependencies = (module: Module) => {
|
|
|
308
295
|
const instances = current.units.flatMap((unit) => {
|
|
309
296
|
if (unit.kind === "Instance") return [unit.instance];
|
|
310
297
|
if (unit.kind === "Definition") return getLetInstances(unit.definition.body);
|
|
311
|
-
if (unit.kind === "Theorem" && isRoot)
|
|
298
|
+
if (unit.kind === "Theorem" && isRoot) {
|
|
299
|
+
return [
|
|
300
|
+
...getStatementInstances(unit.theorem.statement),
|
|
301
|
+
...getProofInstances(unit.theorem.proof),
|
|
302
|
+
];
|
|
303
|
+
}
|
|
312
304
|
if (unit.kind === "Assumption" && isRoot) return getLetInstances(unit.assumption.expression);
|
|
313
305
|
return [];
|
|
314
306
|
});
|
|
315
307
|
addImports(
|
|
316
308
|
instances
|
|
317
|
-
.
|
|
318
|
-
.
|
|
309
|
+
.filter((instance) => isExternal(instance.module) && !isInternalInstance(current, instance))
|
|
310
|
+
.map((instance) => instance.module),
|
|
319
311
|
instancees,
|
|
320
312
|
);
|
|
321
313
|
const peers = new Map(context);
|
|
322
314
|
current.modules.forEach((inner) => {
|
|
323
315
|
const innerContext = new Map(peers);
|
|
324
|
-
// ParseUnit.handleExtensions.
|
|
325
316
|
const extenders = new Set<Module>();
|
|
326
317
|
const addExtendedInnerModules = (extender: Module) => {
|
|
327
318
|
if (extenders.has(extender)) return;
|
|
@@ -346,7 +337,6 @@ const getDependencies = (module: Module) => {
|
|
|
346
337
|
return { extendees, instancees, importers };
|
|
347
338
|
};
|
|
348
339
|
|
|
349
|
-
// The expressions that can name an operator, as Generator.generateExprOrOpArg tells them apart.
|
|
350
340
|
const OPERATOR_ARGUMENT_KINDS = new Set<Expression["kind"]>([
|
|
351
341
|
"Identifier",
|
|
352
342
|
"Subexpression",
|
|
@@ -360,15 +350,12 @@ const isOperatorArgument = (argument: Expression) => {
|
|
|
360
350
|
return OPERATOR_ARGUMENT_KINDS.has(argument.kind) || (items !== undefined && isGeneralId(items));
|
|
361
351
|
};
|
|
362
352
|
|
|
363
|
-
// The parts of a DEF clause entry that isn't a name, as Generator.genIdToSelector reads them.
|
|
364
353
|
interface DefEntryParts {
|
|
365
354
|
hasChildlessFirstChild: boolean | undefined;
|
|
366
355
|
last: TokenSpan;
|
|
367
|
-
// The kind of SANY's syntax node for the last part, or for a token its text.
|
|
368
356
|
lastKind: string | undefined;
|
|
369
357
|
}
|
|
370
358
|
|
|
371
|
-
// The kind of the syntax node SANY's parser builds for an expression of each kind.
|
|
372
359
|
const SYNTAX_KINDS = new Map<Expression["kind"], string>([
|
|
373
360
|
["Identifier", "N_GeneralId"],
|
|
374
361
|
["Subexpression", "N_GeneralId"],
|
|
@@ -403,8 +390,6 @@ const SYNTAX_KINDS = new Map<Expression["kind"], string>([
|
|
|
403
390
|
["StrongFairness", "N_FairnessExpr"],
|
|
404
391
|
]);
|
|
405
392
|
|
|
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
393
|
const NESTED_FIRST_CHILD_KINDS = new Set([
|
|
409
394
|
"N_GeneralId",
|
|
410
395
|
"N_OpApplication",
|
|
@@ -417,8 +402,7 @@ const NESTED_FIRST_CHILD_KINDS = new Set([
|
|
|
417
402
|
|
|
418
403
|
const POSTFIX_OPERATOR_TEXTS = new Set(["'", "^+", "^*", "^#"]);
|
|
419
404
|
|
|
420
|
-
// SANY's
|
|
421
|
-
// a prefix operator other than ~ and -. as a LAMBDA.
|
|
405
|
+
// SANY's parser reads a prefix operator other than ~ and -. as a LAMBDA.
|
|
422
406
|
const getOperatorNodeKind = (
|
|
423
407
|
expression: Expression & { kind: "OperatorReference" | "Lambda" },
|
|
424
408
|
text: string,
|
|
@@ -429,8 +413,6 @@ const getOperatorNodeKind = (
|
|
|
429
413
|
: "N_GenInfixOp";
|
|
430
414
|
};
|
|
431
415
|
|
|
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
416
|
export const generateSanySpecification = (
|
|
435
417
|
rootSource: string,
|
|
436
418
|
loadModule: (name: string) => string | undefined,
|
|
@@ -444,12 +426,8 @@ export const generateSanySpecification = (
|
|
|
444
426
|
// TLC 1.7.4's SANY numbers its first node 0, and the master builds create one before.
|
|
445
427
|
const counter = { value: options.version === "1.7.4" ? -1 : 0 };
|
|
446
428
|
const getId = () => ++counter.value;
|
|
447
|
-
// The UID of the nullOAN of the Generator of the module being generated.
|
|
448
429
|
const nullApplication = { id: 0 };
|
|
449
430
|
|
|
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.
|
|
453
431
|
const addSymbol = (table: SymbolTable, symbol: SymbolNode) => {
|
|
454
432
|
const binding = resolveSymbol(table, symbol.name);
|
|
455
433
|
if (binding === symbol) return;
|
|
@@ -482,10 +460,8 @@ export const generateSanySpecification = (
|
|
|
482
460
|
);
|
|
483
461
|
}
|
|
484
462
|
};
|
|
485
|
-
//
|
|
486
|
-
//
|
|
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.
|
|
463
|
+
// Context's static initializer creates the builtins and SANY.frontEndInitialize creates them
|
|
464
|
+
// again; TLC 1.7.4's SANY creates them only once.
|
|
489
465
|
if (options.version !== "1.7.4") createBuiltins(getId);
|
|
490
466
|
const builtins = createBuiltins(getId);
|
|
491
467
|
getId();
|
|
@@ -499,9 +475,8 @@ export const generateSanySpecification = (
|
|
|
499
475
|
new TlaSanyFatalError(`Could not parse module ${name} from file ${file}`, name, parseError);
|
|
500
476
|
const lexicalError = options.version === "1.7.4" ? getSany174LexicalError(text) : undefined;
|
|
501
477
|
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.
|
|
478
|
+
// HACK: the parser's errors are not SANY's, so a module that fails to parse gets the report of
|
|
479
|
+
// SANY's parser, or the parser's own where SANY's parser would accept the module.
|
|
505
480
|
try {
|
|
506
481
|
return parseSanyModule(getUnboxedSource(text));
|
|
507
482
|
} catch (error) {
|
|
@@ -533,7 +508,6 @@ export const generateSanySpecification = (
|
|
|
533
508
|
const visiting = new Set<string>();
|
|
534
509
|
const path: string[] = [];
|
|
535
510
|
const calculateDependencies = (name: string, text: string | undefined, importer?: string) => {
|
|
536
|
-
// SpecObj.nonCircularityTest.
|
|
537
511
|
const cycleStart = path.indexOf(name);
|
|
538
512
|
if (cycleStart !== -1) {
|
|
539
513
|
throw new TlaSanyFatalError(
|
|
@@ -551,8 +525,8 @@ export const generateSanySpecification = (
|
|
|
551
525
|
path.pop();
|
|
552
526
|
order.push(name);
|
|
553
527
|
};
|
|
554
|
-
//
|
|
555
|
-
//
|
|
528
|
+
// SANY resolves the first unresolved name from the root, every extended module before any
|
|
529
|
+
// instantiated one, each in the context of the module that names it.
|
|
556
530
|
const resolutions = new Set<string>();
|
|
557
531
|
const isResolved = (importer: string, name: string) => resolutions.has(`${importer} ${name}`);
|
|
558
532
|
const findUnresolved = (
|
|
@@ -590,8 +564,7 @@ export const generateSanySpecification = (
|
|
|
590
564
|
}
|
|
591
565
|
};
|
|
592
566
|
const rootName = options.rootFileName ?? parseSource("", rootSource).name;
|
|
593
|
-
//
|
|
594
|
-
// module's own extendees, before those of its inner modules.
|
|
567
|
+
// The post conditions' modules join the root module's own extendees, before its inner modules'.
|
|
595
568
|
const getModuleDependencies = (name: string, module: Module) => {
|
|
596
569
|
const dependencies = getDependencies(module);
|
|
597
570
|
if (name !== rootName || options.rootExtendees === undefined) return dependencies;
|
|
@@ -620,12 +593,9 @@ export const generateSanySpecification = (
|
|
|
620
593
|
const exceptStack: OpApplNode[] = [];
|
|
621
594
|
const exceptSpecStack: OpApplNode[] = [];
|
|
622
595
|
const labelScopes: LabelScope[] = [];
|
|
623
|
-
// The contexts in which SANY's $$InAssume marks the scope of an ordinary ASSUME's assumptions.
|
|
624
596
|
const assumeContexts = new WeakSet<Context>();
|
|
625
597
|
const pushLabelScope = () => labelScopes.push({ labels: new Map(), params: [] });
|
|
626
598
|
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
599
|
const assumeProveState: AssumeProveState = {
|
|
630
600
|
depth: 0,
|
|
631
601
|
isDeclared: [],
|
|
@@ -760,8 +730,7 @@ export const generateSanySpecification = (
|
|
|
760
730
|
location,
|
|
761
731
|
});
|
|
762
732
|
|
|
763
|
-
//
|
|
764
|
-
// syntax tree node, so its location is that of the builtins.
|
|
733
|
+
// nullOAN has no syntax tree node, so SANY locates it at the builtins.
|
|
765
734
|
const createNullNode = (): OpApplNode => ({
|
|
766
735
|
...createOpAppl(getBuiltin("$Nop"), [], BUILTIN_LOCATION, {}, nullApplication.id),
|
|
767
736
|
isNull: true,
|
|
@@ -804,9 +773,8 @@ export const generateSanySpecification = (
|
|
|
804
773
|
return symbol;
|
|
805
774
|
};
|
|
806
775
|
|
|
807
|
-
//
|
|
808
|
-
//
|
|
809
|
-
// must be given an operator of its arity that takes no operators.
|
|
776
|
+
// A definition's parameter count differs from its arity only where its RECURSIVE declaration
|
|
777
|
+
// gives another.
|
|
810
778
|
const matchArguments = (
|
|
811
779
|
operator: SymbolNode,
|
|
812
780
|
operands: ExprOrOpArgNode[],
|
|
@@ -902,8 +870,6 @@ export const generateSanySpecification = (
|
|
|
902
870
|
},
|
|
903
871
|
});
|
|
904
872
|
|
|
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
873
|
const locateSelectorItems = (items: SelectorItem[], span: TokenSpan) => {
|
|
908
874
|
const cursor = { value: span.start };
|
|
909
875
|
return items.map((item): SelectorItem => {
|
|
@@ -958,8 +924,7 @@ export const generateSanySpecification = (
|
|
|
958
924
|
if (recursive) recursive.node.operator = getBuiltin("$RecursiveFcnSpec");
|
|
959
925
|
};
|
|
960
926
|
|
|
961
|
-
//
|
|
962
|
-
// \A x, y \in S into a bound per name that shares the set, and SANY keeps one group.
|
|
927
|
+
// tla-ts expands \A x, y \in S into a bound per name that shares the set; SANY keeps one group.
|
|
963
928
|
const getBoundGroups = (bounds: Bound[]) =>
|
|
964
929
|
bounds.reduce<Bound[][]>((groups, bound) => {
|
|
965
930
|
const last = groups[groups.length - 1];
|
|
@@ -973,8 +938,7 @@ export const generateSanySpecification = (
|
|
|
973
938
|
return groups;
|
|
974
939
|
}, []);
|
|
975
940
|
|
|
976
|
-
//
|
|
977
|
-
// each named at its token between the end of the previous group and its set.
|
|
941
|
+
// SANY generates every bounding set before it declares the symbols.
|
|
978
942
|
const generateBounds = (bounds: Bound[], searchStart: number) =>
|
|
979
943
|
generateBoundsWithRanges(
|
|
980
944
|
bounds,
|
|
@@ -982,7 +946,6 @@ export const generateSanySpecification = (
|
|
|
982
946
|
getBoundGroups(bounds).map((group) => generateExpression(group[0].set)),
|
|
983
947
|
);
|
|
984
948
|
|
|
985
|
-
// Generator.pushFormalParams: a label in the expression has to name the parameters it binds.
|
|
986
949
|
const generateWithParams = (params: FormalParamNode[], expression: Expression) => {
|
|
987
950
|
const scope = labelScopes.at(-1);
|
|
988
951
|
scope?.params.push(params);
|
|
@@ -1009,8 +972,7 @@ export const generateSanySpecification = (
|
|
|
1009
972
|
});
|
|
1010
973
|
};
|
|
1011
974
|
|
|
1012
|
-
// tla-ts desugars an operator symbol
|
|
1013
|
-
// without a range.
|
|
975
|
+
// tla-ts desugars an operator symbol argument, such as SUBSET or -., into a LAMBDA naming it.
|
|
1014
976
|
const getOperatorArgumentName = (argument: Expression) =>
|
|
1015
977
|
argument.kind === "OperatorReference"
|
|
1016
978
|
? argument.operator
|
|
@@ -1018,14 +980,13 @@ export const generateSanySpecification = (
|
|
|
1018
980
|
? argument.body.operator
|
|
1019
981
|
: file.tokens[getTokenIndex(file, argument.location)].text;
|
|
1020
982
|
|
|
1021
|
-
// Generator.generateOpArg: after an error, SANY gives its nullOpArg.
|
|
1022
983
|
const generateOperatorArgument = (
|
|
1023
984
|
argument: Expression,
|
|
1024
985
|
target: OpDeclNode,
|
|
1025
986
|
): OpArgNode | OpApplNode => {
|
|
1026
987
|
const location = getLocation(argument);
|
|
1027
988
|
if (argument.kind === "Lambda") {
|
|
1028
|
-
if (argument.location.range !== undefined)
|
|
989
|
+
if (argument.location.range !== undefined && argument.operator === undefined)
|
|
1029
990
|
return createOpArg(generateLambda(argument), location);
|
|
1030
991
|
return createOpArg(resolveName(getOperatorArgumentName(argument), location), location);
|
|
1031
992
|
}
|
|
@@ -1046,8 +1007,6 @@ export const generateSanySpecification = (
|
|
|
1046
1007
|
);
|
|
1047
1008
|
};
|
|
1048
1009
|
|
|
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
1010
|
const generateArgument = (
|
|
1052
1011
|
operator: SymbolNode,
|
|
1053
1012
|
index: number,
|
|
@@ -1075,14 +1034,17 @@ export const generateSanySpecification = (
|
|
|
1075
1034
|
argument.kind === "Subexpression" ||
|
|
1076
1035
|
argument.kind === "Apply"
|
|
1077
1036
|
) {
|
|
1078
|
-
// The selector names the operator, or reports why not and gives SANY's nullOAN.
|
|
1079
1037
|
const node = generateSelector(argument, expectedArity, false, false);
|
|
1080
1038
|
if (node.kind === "OpArg" || node.kind === "OpAppl") return node;
|
|
1081
1039
|
throw new TlaSyntaxError(
|
|
1082
1040
|
`Expected an operator argument at ${formatSanyLocation(location)}`,
|
|
1083
1041
|
);
|
|
1084
1042
|
}
|
|
1085
|
-
if (
|
|
1043
|
+
if (
|
|
1044
|
+
argument.kind === "Lambda" &&
|
|
1045
|
+
argument.location.range !== undefined &&
|
|
1046
|
+
argument.operator === undefined
|
|
1047
|
+
) {
|
|
1086
1048
|
const lambda = generateLambda(argument);
|
|
1087
1049
|
const arity = getSymbolArity(lambda);
|
|
1088
1050
|
if (arity === expectedArity) return createOpArg(lambda, location);
|
|
@@ -1246,8 +1208,7 @@ export const generateSanySpecification = (
|
|
|
1246
1208
|
column: file.tokens[index].column,
|
|
1247
1209
|
});
|
|
1248
1210
|
|
|
1249
|
-
// The
|
|
1250
|
-
// names, each with (_, ...) for its arguments.
|
|
1211
|
+
// The syntax tree of a LET leaves out its RECURSIVE declarations, so read them from the tokens.
|
|
1251
1212
|
const getRecursiveDeclarations = (start: number) => {
|
|
1252
1213
|
const declarations: Declaration[] = [];
|
|
1253
1214
|
let index = start;
|
|
@@ -1274,7 +1235,6 @@ export const generateSanySpecification = (
|
|
|
1274
1235
|
return declarations;
|
|
1275
1236
|
};
|
|
1276
1237
|
|
|
1277
|
-
// The units of a LET in source order, with its RECURSIVE statements found among its tokens.
|
|
1278
1238
|
const getLetUnits = (expression: Expression & { kind: "Let" }) => {
|
|
1279
1239
|
const units = [
|
|
1280
1240
|
...expression.definitions.map((definition) => ({
|
|
@@ -1370,7 +1330,6 @@ export const generateSanySpecification = (
|
|
|
1370
1330
|
});
|
|
1371
1331
|
};
|
|
1372
1332
|
|
|
1373
|
-
// An infix, prefix or postfix operator that no symbol defines, with the token SANY names it by.
|
|
1374
1333
|
const getUnresolvedOperator = (expression: Expression & { kind: "Apply" }) => {
|
|
1375
1334
|
if (
|
|
1376
1335
|
isIdentifier(expression.operator) ||
|
|
@@ -1595,6 +1554,28 @@ export const generateSanySpecification = (
|
|
|
1595
1554
|
// SANY leaves the whole application null, without generating its arguments.
|
|
1596
1555
|
if (isAbsent(functionNode)) return functionNode;
|
|
1597
1556
|
checkRecursion(functionNode);
|
|
1557
|
+
const operator = functionNode.kind === "OpAppl" ? functionNode.operator : undefined;
|
|
1558
|
+
const body =
|
|
1559
|
+
operator?.kind === "OpDef" && operator.defKind === "UserDefined"
|
|
1560
|
+
? operator.body
|
|
1561
|
+
: undefined;
|
|
1562
|
+
if (
|
|
1563
|
+
body?.kind === "OpAppl" &&
|
|
1564
|
+
(body.operator.name === "$NonRecursiveFcnSpec" ||
|
|
1565
|
+
body.operator.name === "$RecursiveFcnSpec")
|
|
1566
|
+
) {
|
|
1567
|
+
const paramCount = (body.bounded ?? []).reduce(
|
|
1568
|
+
(count, params, index) => count + (body.tupleOrs?.[index] ? 1 : params.length),
|
|
1569
|
+
0,
|
|
1570
|
+
);
|
|
1571
|
+
if (expression.args.length >= 2 && paramCount !== expression.args.length) {
|
|
1572
|
+
addError(
|
|
1573
|
+
location,
|
|
1574
|
+
`Function '${operator?.name}' is defined with ${paramCount} parameters, but is applied to ${expression.args.length} arguments.`,
|
|
1575
|
+
);
|
|
1576
|
+
return createNullNode();
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1598
1579
|
const argument =
|
|
1599
1580
|
expression.args.length === 1
|
|
1600
1581
|
? generateExpression(expression.args[0])
|
|
@@ -1669,8 +1650,7 @@ export const generateSanySpecification = (
|
|
|
1669
1650
|
addError(location, "Label not in definition or proof step.");
|
|
1670
1651
|
return createNullNode();
|
|
1671
1652
|
}
|
|
1672
|
-
//
|
|
1673
|
-
// ASSUME/PROVE.
|
|
1653
|
+
// No label may lie in the scope of a declaration of a nested ASSUME/PROVE.
|
|
1674
1654
|
if (assumeProveState.isDeclared.slice(2, assumeProveState.depth + 1).some(Boolean)) {
|
|
1675
1655
|
addError(location, "Label not allowed within scope of declaration in nested ASSUME/PROVE.");
|
|
1676
1656
|
return createNullNode();
|
|
@@ -1705,7 +1685,6 @@ export const generateSanySpecification = (
|
|
|
1705
1685
|
isAssumeProve: false,
|
|
1706
1686
|
location,
|
|
1707
1687
|
};
|
|
1708
|
-
// Generator.formalParamsEqual: a label names each parameter bound around it once.
|
|
1709
1688
|
const named = new Set<FormalParamNode>();
|
|
1710
1689
|
params.forEach((param) => {
|
|
1711
1690
|
if (named.has(param)) {
|
|
@@ -1732,8 +1711,6 @@ export const generateSanySpecification = (
|
|
|
1732
1711
|
return label;
|
|
1733
1712
|
};
|
|
1734
1713
|
|
|
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
1714
|
const getParams = (
|
|
1738
1715
|
definition: OperatorDefinition | Instance,
|
|
1739
1716
|
span: TokenSpan,
|
|
@@ -1746,8 +1723,10 @@ export const generateSanySpecification = (
|
|
|
1746
1723
|
: findNameOrKeyword(cursor.value, param.name);
|
|
1747
1724
|
const paramSpan = getOperatorSpan(index, param.arity);
|
|
1748
1725
|
cursor.value = paramSpan.end + 1;
|
|
1726
|
+
// SANY keeps the spelling of a prefix parameter, so ~ _ does not redefine \lnot.
|
|
1727
|
+
const isPrefix = param.arity === 1 && isToken(file, index + 1, "_");
|
|
1749
1728
|
return createFormalParam(
|
|
1750
|
-
resolveSynonym(param.name),
|
|
1729
|
+
isPrefix ? (file.tokens[index].spelling ?? param.name) : resolveSynonym(param.name),
|
|
1751
1730
|
param.arity,
|
|
1752
1731
|
getSpanLocation(file, paramSpan),
|
|
1753
1732
|
isAdded,
|
|
@@ -1755,7 +1734,6 @@ export const generateSanySpecification = (
|
|
|
1755
1734
|
});
|
|
1756
1735
|
};
|
|
1757
1736
|
|
|
1758
|
-
// The span of a definition or instance, with the LOCAL before it.
|
|
1759
1737
|
const getDefinitionSpan = (definition: { location: SourceLocation; isLocal?: boolean }) => {
|
|
1760
1738
|
const span = getUnitSpan(definition.location);
|
|
1761
1739
|
return definition.isLocal &&
|
|
@@ -1777,10 +1755,8 @@ export const generateSanySpecification = (
|
|
|
1777
1755
|
const params = getParams(definition, paramsSpan, true);
|
|
1778
1756
|
const existing = resolveSymbol(symbolTable, name);
|
|
1779
1757
|
if (existing?.kind === "OpDef" && existing.inRecursive && !existing.isDefined) {
|
|
1780
|
-
// SANY compares only the arity of the last parameter.
|
|
1781
1758
|
const isMatching =
|
|
1782
|
-
existing.params?.length === params.length &&
|
|
1783
|
-
(params.length === 0 || params[params.length - 1].arity === 0);
|
|
1759
|
+
existing.params?.length === params.length && params.every((param) => param.arity === 0);
|
|
1784
1760
|
if (existing.letInLevel !== state.curLevel) {
|
|
1785
1761
|
addError(location, `Recursive operator ${name} defined at wrong LET/IN level.`);
|
|
1786
1762
|
} else {
|
|
@@ -1858,7 +1834,7 @@ export const generateSanySpecification = (
|
|
|
1858
1834
|
const context = createContext();
|
|
1859
1835
|
const nameIndex = definition.isLocal ? span.start + 1 : span.start;
|
|
1860
1836
|
const bounds = withContext(context, () => generateBounds(definition.bounds, nameIndex + 1));
|
|
1861
|
-
const existing = resolveSymbol(symbolTable, definition.name);
|
|
1837
|
+
const existing = withContext(context, () => resolveSymbol(symbolTable, definition.name));
|
|
1862
1838
|
const recursionParam = withContext(context, () =>
|
|
1863
1839
|
createFormalParam(definition.name, 0, location, existing === undefined),
|
|
1864
1840
|
);
|
|
@@ -1882,8 +1858,6 @@ export const generateSanySpecification = (
|
|
|
1882
1858
|
addError(location, `Function name \`${definition.name}' already defined or declared.`);
|
|
1883
1859
|
}
|
|
1884
1860
|
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
1861
|
const definitionNode =
|
|
1888
1862
|
existing === undefined
|
|
1889
1863
|
? createOpDef({
|
|
@@ -1962,16 +1936,14 @@ export const generateSanySpecification = (
|
|
|
1962
1936
|
state.unresolvedSum -= state.unresolvedCount[state.curLevel];
|
|
1963
1937
|
};
|
|
1964
1938
|
|
|
1965
|
-
//
|
|
1966
|
-
//
|
|
1967
|
-
// instantiated module's Hashtable, then the explicit WITH substitutions.
|
|
1939
|
+
// Implicit substitutions in the order of the instantiated module's Hashtable, then the explicit
|
|
1940
|
+
// WITH substitutions.
|
|
1968
1941
|
const processSubstitutions = (
|
|
1969
1942
|
instance: Instance,
|
|
1970
1943
|
instanceeContext: Context,
|
|
1971
1944
|
location: SanyLocation,
|
|
1972
1945
|
) => {
|
|
1973
|
-
// The SubstInNode processSubst creates
|
|
1974
|
-
// templates use.
|
|
1946
|
+
// The SubstInNode processSubst creates, which only the substitutions' templates use.
|
|
1975
1947
|
getId();
|
|
1976
1948
|
const declarations = getHashtableValues(instanceeContext.table).filter(
|
|
1977
1949
|
(symbol): symbol is OpDeclNode => symbol.kind === "OpDecl",
|
|
@@ -1982,6 +1954,7 @@ export const generateSanySpecification = (
|
|
|
1982
1954
|
const isExpression =
|
|
1983
1955
|
declaration.declKind === VARIABLE_DECL_KIND ||
|
|
1984
1956
|
(declaration.declKind === CONSTANT_DECL_KIND && declaration.arity === 0);
|
|
1957
|
+
if (isExpression) matchArguments(symbol, [], location);
|
|
1985
1958
|
return [
|
|
1986
1959
|
{
|
|
1987
1960
|
op: declaration,
|
|
@@ -1990,13 +1963,10 @@ export const generateSanySpecification = (
|
|
|
1990
1963
|
},
|
|
1991
1964
|
];
|
|
1992
1965
|
});
|
|
1993
|
-
//
|
|
1994
|
-
// nullOpArg it substitutes after an error.
|
|
1966
|
+
// SANY locates an arity error at its builtins for the nullOpArg it substitutes after an error.
|
|
1995
1967
|
const checkArity = (target: OpDeclNode, substitute: ExprOrOpArgNode) => {
|
|
1996
1968
|
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) {
|
|
1969
|
+
if (arity !== target.arity) {
|
|
2000
1970
|
addError(
|
|
2001
1971
|
substitute.location,
|
|
2002
1972
|
`An operator must be substituted for symbol '${target.name}', and it must have arity ${target.arity}.`,
|
|
@@ -2004,7 +1974,6 @@ export const generateSanySpecification = (
|
|
|
2004
1974
|
}
|
|
2005
1975
|
};
|
|
2006
1976
|
const span = getDefinitionSpan(instance);
|
|
2007
|
-
// The targets follow WITH, after the parameters of a definition that instantiates.
|
|
2008
1977
|
const cursor = { value: findToken(file, span.start, span.end, "WITH") + 1 };
|
|
2009
1978
|
instance.substitutions.forEach((substitution) => {
|
|
2010
1979
|
const targetIndex = findToken(file, cursor.value, span.end, substitution.name);
|
|
@@ -2040,7 +2009,6 @@ export const generateSanySpecification = (
|
|
|
2040
2009
|
substs
|
|
2041
2010
|
.filter((subst) => subst.isImplicit && options.version !== "1.7.4")
|
|
2042
2011
|
.forEach((subst) => checkArity(subst.op, subst.expr));
|
|
2043
|
-
// SubstInNode.matchAll.
|
|
2044
2012
|
declarations
|
|
2045
2013
|
.filter((declaration) => !substs.some((subst) => subst.op.name === declaration.name))
|
|
2046
2014
|
.forEach((declaration) =>
|
|
@@ -2186,8 +2154,8 @@ export const generateSanySpecification = (
|
|
|
2186
2154
|
if (options.version !== "1.7.4") definitions?.push(moduleDefinition);
|
|
2187
2155
|
};
|
|
2188
2156
|
|
|
2189
|
-
//
|
|
2190
|
-
//
|
|
2157
|
+
// An INSTANCE proof step is located at the step's body and adds no theorem definitions or
|
|
2158
|
+
// instance to the module.
|
|
2191
2159
|
const generateInstance = (
|
|
2192
2160
|
instance: Instance,
|
|
2193
2161
|
isTopLevel = true,
|
|
@@ -2236,8 +2204,8 @@ export const generateSanySpecification = (
|
|
|
2236
2204
|
currentModule.definitions.push(node);
|
|
2237
2205
|
setRecursionFields(node);
|
|
2238
2206
|
});
|
|
2239
|
-
// SANY reuses a theorem of a parameter-free module without adding it to the symbol table
|
|
2240
|
-
//
|
|
2207
|
+
// SANY reuses a theorem of a parameter-free module without adding it to the symbol table when
|
|
2208
|
+
// the instantiated module has parameters.
|
|
2241
2209
|
getHashtableValues(instanceeContext.table).forEach((symbol) => {
|
|
2242
2210
|
if (symbol.kind !== "ThmOrAssumpDef" || symbol.isLocal) return;
|
|
2243
2211
|
const copyFrom = (module: ModuleNode, body: LevelNode) => {
|
|
@@ -2285,7 +2253,6 @@ export const generateSanySpecification = (
|
|
|
2285
2253
|
return instanceNode;
|
|
2286
2254
|
};
|
|
2287
2255
|
|
|
2288
|
-
// SANY leaves out a module it can't resolve, after reporting it at the module's name.
|
|
2289
2256
|
const getFactModules = (fact: Fact & { kind: "ModuleFact" }) => {
|
|
2290
2257
|
const module =
|
|
2291
2258
|
resolveModule(fact.name) ?? (fact.name === currentModule.name ? currentModule : undefined);
|
|
@@ -2297,8 +2264,6 @@ export const generateSanySpecification = (
|
|
|
2297
2264
|
return [];
|
|
2298
2265
|
};
|
|
2299
2266
|
|
|
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
2267
|
const generateFacts = (facts: Fact[]) =>
|
|
2303
2268
|
facts.flatMap((fact): FactNode[] => {
|
|
2304
2269
|
if (fact.kind === "ModuleFact") return getFactModules(fact);
|
|
@@ -2313,30 +2278,27 @@ export const generateSanySpecification = (
|
|
|
2313
2278
|
isToken(file, span.start, "(") && getMatchingIndex(file, span.start) === span.end;
|
|
2314
2279
|
const getOperandSpan = (expression: Expression) =>
|
|
2315
2280
|
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
2281
|
const getApplicationKind = (expression: Expression & { kind: "Apply" }, span: TokenSpan) => {
|
|
2318
2282
|
if (getOperandSpan(expression.args[0]).start === span.start) {
|
|
2319
2283
|
return expression.args.length === 2 ? "N_InfixExpr" : "N_PostfixExpr";
|
|
2320
2284
|
}
|
|
2321
2285
|
return file.tokens[span.start].kind === "Identifier" ? "N_OpApplication" : "N_PrefixExpr";
|
|
2322
2286
|
};
|
|
2323
|
-
// The kind of SANY's syntax node for an expression, or for a token its text.
|
|
2324
2287
|
const getSyntaxKind = (expression: Expression, span: TokenSpan) => {
|
|
2325
2288
|
if (isParenthesized(span)) return "N_ParenExpr";
|
|
2326
2289
|
if (expression.kind === "String") return getTokenSource(file, span.start);
|
|
2327
2290
|
if (expression.kind === "Apply") return getApplicationKind(expression, span);
|
|
2328
2291
|
return SYNTAX_KINDS.get(expression.kind);
|
|
2329
2292
|
};
|
|
2330
|
-
//
|
|
2331
|
-
// Generator.genIdToSelector takes for an empty prefix of a name. A string is a token itself.
|
|
2293
|
+
// Generator.genIdToSelector takes a childless first child for an empty prefix of a name.
|
|
2332
2294
|
const hasChildlessFirstChild = (expression: Expression, span: TokenSpan) => {
|
|
2333
2295
|
if (expression.kind === "String" && !isParenthesized(span)) return false;
|
|
2334
2296
|
if (expression.kind === "Identifier" && !expression.name.includes("!")) return true;
|
|
2335
2297
|
const kind = getSyntaxKind(expression, span);
|
|
2336
2298
|
return kind === undefined || NESTED_FIRST_CHILD_KINDS.has(kind) ? undefined : true;
|
|
2337
2299
|
};
|
|
2338
|
-
// Generator.genIdToSelector reads
|
|
2339
|
-
//
|
|
2300
|
+
// Generator.genIdToSelector reads a DEF entry that isn't a name as one: its first child as the
|
|
2301
|
+
// prefix and its second as the last part.
|
|
2340
2302
|
const getDefEntryParts = (
|
|
2341
2303
|
expression: Expression,
|
|
2342
2304
|
span: TokenSpan,
|
|
@@ -2425,8 +2387,7 @@ export const generateSanySpecification = (
|
|
|
2425
2387
|
}
|
|
2426
2388
|
return undefined;
|
|
2427
2389
|
};
|
|
2428
|
-
//
|
|
2429
|
-
// a name, or false where SANY's reading of the entry isn't modeled.
|
|
2390
|
+
// False where SANY's reading of the entry isn't modeled.
|
|
2430
2391
|
const reportDefEntry = (expression: Expression) => {
|
|
2431
2392
|
const span = getParenthesizedSpan(file, getExpressionSpan(file, expression));
|
|
2432
2393
|
const isName =
|
|
@@ -2462,7 +2423,7 @@ export const generateSanySpecification = (
|
|
|
2462
2423
|
false,
|
|
2463
2424
|
true,
|
|
2464
2425
|
);
|
|
2465
|
-
// SANY rejects
|
|
2426
|
+
// SANY rejects a proof step name in a DEF clause and leaves out an entry it rejects.
|
|
2466
2427
|
// Errors.addMessage drops the message when selectorToNode already reported it.
|
|
2467
2428
|
const isDefinition =
|
|
2468
2429
|
symbol.kind === "OpDef" ||
|
|
@@ -2474,8 +2435,7 @@ export const generateSanySpecification = (
|
|
|
2474
2435
|
return [symbol];
|
|
2475
2436
|
});
|
|
2476
2437
|
|
|
2477
|
-
// SANY
|
|
2478
|
-
// reads the facts.
|
|
2438
|
+
// SANY rejects a BY, USE or HIDE with nothing after its keyword before it reads the facts.
|
|
2479
2439
|
const checkKeywordOnly = (
|
|
2480
2440
|
statement: UseOrHide | Extract<Proof, { kind: "By" }>,
|
|
2481
2441
|
location: SanyLocation,
|
|
@@ -2490,7 +2450,7 @@ export const generateSanySpecification = (
|
|
|
2490
2450
|
const facts = generateFacts(use.facts);
|
|
2491
2451
|
const defs = generateDefs(use.defs);
|
|
2492
2452
|
if (facts.length + defs.length === 0) addError(location, "Empty USE or HIDE statement.");
|
|
2493
|
-
//
|
|
2453
|
+
// A HIDE cites facts by name only.
|
|
2494
2454
|
if (use.kind === "Hide") {
|
|
2495
2455
|
facts
|
|
2496
2456
|
.filter((fact) => fact.kind === "OpAppl" && fact.operator.kind !== "ThmOrAssumpDef")
|
|
@@ -2512,7 +2472,7 @@ export const generateSanySpecification = (
|
|
|
2512
2472
|
};
|
|
2513
2473
|
};
|
|
2514
2474
|
|
|
2515
|
-
//
|
|
2475
|
+
// SANY generates the set before it declares the symbol.
|
|
2516
2476
|
const generateNewSymbol = (symbol: NewSymbol): NewSymbNode => {
|
|
2517
2477
|
const span = getUnitSpan(symbol.location);
|
|
2518
2478
|
const set = symbol.set && generateExpression(symbol.set);
|
|
@@ -2539,7 +2499,6 @@ export const generateSanySpecification = (
|
|
|
2539
2499
|
};
|
|
2540
2500
|
};
|
|
2541
2501
|
|
|
2542
|
-
// generateAssumeProve: an ASSUME/PROVE nested in another one has a context of its own.
|
|
2543
2502
|
const generateAssumeProve = (
|
|
2544
2503
|
assumeProve: AssumeProve,
|
|
2545
2504
|
depth: number,
|
|
@@ -2564,7 +2523,7 @@ export const generateSanySpecification = (
|
|
|
2564
2523
|
: "ASSUME matched by []PROVE instead of PROVE",
|
|
2565
2524
|
);
|
|
2566
2525
|
}
|
|
2567
|
-
// SANY
|
|
2526
|
+
// SANY numbers the AssumeProveNode before it generates its clauses.
|
|
2568
2527
|
const id = getId();
|
|
2569
2528
|
if (depth > 1) symbolTable.contexts.push(createContext());
|
|
2570
2529
|
if (isBoxed && symbolTable.contexts.some((context) => assumeContexts.has(context))) {
|
|
@@ -2620,8 +2579,7 @@ export const generateSanySpecification = (
|
|
|
2620
2579
|
return node;
|
|
2621
2580
|
};
|
|
2622
2581
|
|
|
2623
|
-
// SANY
|
|
2624
|
-
// generates what it asserts.
|
|
2582
|
+
// SANY numbers the ThmOrAssumpDefNode before it generates what it asserts.
|
|
2625
2583
|
const createTheoremDefinition = (
|
|
2626
2584
|
id: number,
|
|
2627
2585
|
name: string,
|
|
@@ -2653,7 +2611,7 @@ export const generateSanySpecification = (
|
|
|
2653
2611
|
if (proof.kind === "By") checkKeywordOnly(proof, location);
|
|
2654
2612
|
const facts = proof.kind === "By" ? generateFacts(proof.facts) : [];
|
|
2655
2613
|
const defs = proof.kind === "By" ? generateDefs(proof.defs) : [];
|
|
2656
|
-
// SANY
|
|
2614
|
+
// The UseOrHideNode SANY makes of a BY proof's facts and definitions.
|
|
2657
2615
|
if (proof.kind === "By") getId();
|
|
2658
2616
|
if (proof.kind === "By" && facts.length + defs.length === 0) addError(location, "Empty BY");
|
|
2659
2617
|
return {
|
|
@@ -2711,7 +2669,6 @@ export const generateSanySpecification = (
|
|
|
2711
2669
|
return undefined;
|
|
2712
2670
|
};
|
|
2713
2671
|
|
|
2714
|
-
// An expression SANY parses as N_InfixExpr: a binary operator between its operands.
|
|
2715
2672
|
const isInfixExpression = (expression: Expression) => {
|
|
2716
2673
|
if ((expression.kind === "And" || expression.kind === "Or") && !expression.isBulleted)
|
|
2717
2674
|
return true;
|
|
@@ -2721,20 +2678,16 @@ export const generateSanySpecification = (
|
|
|
2721
2678
|
return left.start === start && !isToken(file, left.end + 1, "(");
|
|
2722
2679
|
};
|
|
2723
2680
|
|
|
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
2681
|
const generateProof = (proof: Proof): LeafProofNode | NonLeafProofNode => {
|
|
2727
2682
|
if (proof.kind !== "Steps") return generateLeafProof(proof);
|
|
2728
2683
|
const proofContext = createContext();
|
|
2729
2684
|
symbolTable.contexts.push(proofContext);
|
|
2730
2685
|
const instances: InstanceNode[] = [];
|
|
2731
2686
|
const sufficesContexts: Context[] = [];
|
|
2732
|
-
// An assertion step @ = e continues the
|
|
2733
|
-
// side the @ stands for.
|
|
2687
|
+
// An assertion step @ = e continues the step before it, whose right side the @ stands for.
|
|
2734
2688
|
const infixStep: { previousRight: ExprOrOpArgNode | undefined } = {
|
|
2735
2689
|
previousRight: undefined,
|
|
2736
2690
|
};
|
|
2737
|
-
// A DEFINE, USE, HIDE or INSTANCE step.
|
|
2738
2691
|
const generateOtherStep = (
|
|
2739
2692
|
body: ProofStep["body"],
|
|
2740
2693
|
stepSpan: TokenSpan,
|
|
@@ -2772,13 +2725,19 @@ export const generateSanySpecification = (
|
|
|
2772
2725
|
const headSpan = getRangeSpan(file, step.head);
|
|
2773
2726
|
const bodySpan = { start: headSpan.start + 1, end: headSpan.end };
|
|
2774
2727
|
const body = step.body;
|
|
2728
|
+
if (step.name !== undefined && /^<[*+]>/.test(step.token)) {
|
|
2729
|
+
addError(
|
|
2730
|
+
getTokenLocation(file, stepSpan.start),
|
|
2731
|
+
"<*> and <+> cannot be used for a named step.",
|
|
2732
|
+
);
|
|
2733
|
+
}
|
|
2775
2734
|
if (step.name !== undefined) pushLabelScope();
|
|
2776
2735
|
const definitionId = step.name === undefined ? undefined : getId();
|
|
2777
2736
|
if (body.kind !== "Assert") infixStep.previousRight = undefined;
|
|
2778
2737
|
const otherStep = generateOtherStep(body, stepSpan, bodySpan);
|
|
2779
2738
|
if (otherStep !== undefined) {
|
|
2780
|
-
// SANY puts a
|
|
2781
|
-
//
|
|
2739
|
+
// SANY puts a definition for a named step that asserts nothing in the symbol table, for a DEF
|
|
2740
|
+
// clause to name.
|
|
2782
2741
|
if (step.name !== undefined) {
|
|
2783
2742
|
addSymbol(
|
|
2784
2743
|
symbolTable,
|
|
@@ -2883,8 +2842,6 @@ export const generateSanySpecification = (
|
|
|
2883
2842
|
};
|
|
2884
2843
|
};
|
|
2885
2844
|
|
|
2886
|
-
// processTheorem: a theorem's ASSUME/PROVE has a context of its own, which its proof sees and
|
|
2887
|
-
// its definition does not.
|
|
2888
2845
|
const processTheorem = (theorem: Theorem) => {
|
|
2889
2846
|
const location = getSpanLocation(file, getUnitSpan(theorem.location));
|
|
2890
2847
|
const statement = theorem.statement;
|
|
@@ -2948,8 +2905,6 @@ export const generateSanySpecification = (
|
|
|
2948
2905
|
currentModule.topLevel.push(node);
|
|
2949
2906
|
};
|
|
2950
2907
|
|
|
2951
|
-
// A declared operator or operator parameter is located with its arguments: F(_, _), _ + _,
|
|
2952
|
-
// -. _ or _ ^+.
|
|
2953
2908
|
const getOperatorSpan = (start: number, arity: number) => {
|
|
2954
2909
|
if (arity === 0) return { start, end: start };
|
|
2955
2910
|
if (isToken(file, start, "_")) {
|
|
@@ -2964,8 +2919,8 @@ export const generateSanySpecification = (
|
|
|
2964
2919
|
|
|
2965
2920
|
const createDeclaration = (declaration: Declaration, declKind: number): OpDeclNode => {
|
|
2966
2921
|
const span = getDeclarationSpan(declaration);
|
|
2967
|
-
// Generator.processParameters makes
|
|
2968
|
-
//
|
|
2922
|
+
// Generator.processParameters makes this check of a constant too, of its syntax node's name,
|
|
2923
|
+
// which is never @.
|
|
2969
2924
|
if (declaration.name === "@" && declKind === VARIABLE_DECL_KIND) {
|
|
2970
2925
|
addError(getSpanLocation(file, span), "Attempted to declare '@' as a variable.");
|
|
2971
2926
|
}
|
|
@@ -2988,8 +2943,8 @@ export const generateSanySpecification = (
|
|
|
2988
2943
|
return node;
|
|
2989
2944
|
};
|
|
2990
2945
|
|
|
2991
|
-
//
|
|
2992
|
-
//
|
|
2946
|
+
// The extended module's symbols join in the order they joined it, apart from LOCAL ones and
|
|
2947
|
+
// those already present.
|
|
2993
2948
|
ast.extends.forEach((name) => {
|
|
2994
2949
|
const extendee = getModule(name);
|
|
2995
2950
|
currentModule.extendees.push(extendee);
|
|
@@ -3024,8 +2979,6 @@ export const generateSanySpecification = (
|
|
|
3024
2979
|
currentModule.topLevel.push(...extendee.topLevel);
|
|
3025
2980
|
});
|
|
3026
2981
|
|
|
3027
|
-
// Generator.checkIfInRecursiveSection: only definitions and instances may come between a
|
|
3028
|
-
// RECURSIVE declaration and the definition of what it declares.
|
|
3029
2982
|
const checkRecursiveSection = (location: SourceLocation, type: string) => {
|
|
3030
2983
|
if (state.unresolvedSum === 0) return;
|
|
3031
2984
|
addError(
|
|
@@ -3075,8 +3028,6 @@ export const generateSanySpecification = (
|
|
|
3075
3028
|
checkRecursiveSection(unit.module.location, "A MODULE ");
|
|
3076
3029
|
const innerTable = { contexts: [...symbolTable.contexts, createContext()] };
|
|
3077
3030
|
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
3031
|
const binding = resolveModule(inner.name);
|
|
3081
3032
|
if (binding === undefined) addToContext(getTopContext(symbolTable), inner);
|
|
3082
3033
|
else if (binding !== inner) {
|
|
@@ -3099,8 +3050,7 @@ export const generateSanySpecification = (
|
|
|
3099
3050
|
nullApplication.id = Array.from({ length: 4 }, getId)[1];
|
|
3100
3051
|
const entry = getSource(name, undefined);
|
|
3101
3052
|
const context = createContext();
|
|
3102
|
-
//
|
|
3103
|
-
// symbols runs from the last builtin to the first.
|
|
3053
|
+
// SANY's global context lists its builtins from the last to the first.
|
|
3104
3054
|
builtins.toReversed().forEach((builtin) => addToContext(context, builtin));
|
|
3105
3055
|
const module = generateModule(entry.module, entry.file, undefined, {
|
|
3106
3056
|
contexts: [context],
|