tla-ts 0.0.4-dev.0be9567 → 0.0.4-dev.1a3acf6
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 +37 -126
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/deciders.cjs +366 -0
- package/dist/deciders.js +366 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +44 -12
- package/dist/index.d.ts +44 -12
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -4
- package/dist/parallel-worker.js +1 -4
- package/dist/prove-worker.cjs +9 -0
- package/dist/prove-worker.d.cts +9 -0
- package/dist/prove-worker.d.ts +9 -0
- package/dist/prove-worker.js +9 -0
- package/dist/prove.cjs +1006 -0
- package/dist/prove.js +1006 -0
- package/dist/run.cjs +45 -0
- package/dist/run.js +45 -0
- package/dist/tlapm.cjs +10 -0
- package/dist/tlapm.js +10 -0
- package/dist/transfer.cjs +76 -92
- package/dist/transfer.js +76 -92
- package/dist/worker.cjs +21 -0
- package/dist/worker.js +21 -0
- package/package.json +21 -12
- package/src/ast.ts +2 -2
- package/src/bags.ts +22 -23
- package/src/builtins.ts +16 -8
- package/src/check.ts +131 -1153
- package/src/{cli-options.ts → cli/options.ts} +54 -9
- package/src/cli/run.ts +63 -0
- package/src/cli/shared.ts +106 -0
- package/src/cli/tlapm.ts +374 -0
- package/src/{run-cli.ts → cli/tlc.ts} +115 -721
- package/src/cli/xml-exporter.ts +221 -0
- package/src/cli.ts +1 -1
- package/src/codegen.ts +17 -15
- package/src/config.ts +5 -5
- package/src/dependencies.ts +4 -6
- package/src/environment.ts +55 -60
- package/src/errors.ts +97 -35
- package/src/evaluate.ts +135 -120
- package/src/exit-codes.ts +1 -1
- package/src/fingerprints.ts +3 -3
- package/src/index.ts +10 -0
- package/src/instances.ts +56 -46
- package/src/java-overrides.ts +79 -41
- package/src/json.ts +31 -36
- package/src/levels.ts +10 -13
- package/src/{live-check.ts → liveness-checker.ts} +169 -142
- package/src/liveness.ts +38 -34
- package/src/{obligation-action.ts → obligations/action.ts} +248 -74
- package/src/{obligation-anon.ts → obligations/anonymize.ts} +55 -57
- package/src/obligations/equality.ts +260 -0
- package/src/obligations/expression.ts +618 -0
- package/src/{obligation-format.ts → obligations/format.ts} +7 -8
- package/src/obligations/generate.ts +457 -0
- package/src/{obligations.ts → obligations/index.ts} +46 -32
- package/src/{obligation-levels.ts → obligations/levels.ts} +44 -40
- package/src/obligations/module.ts +445 -0
- package/src/obligations/normalize.ts +554 -0
- package/src/obligations/operators.ts +176 -0
- package/src/obligations/pragma.ts +195 -0
- package/src/{obligation-printer.ts → obligations/printer.ts} +65 -230
- package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
- package/src/obligations/regroup.ts +100 -0
- package/src/{obligation-generate.ts → obligations/simplify.ts} +130 -536
- package/src/{obligation-source.ts → obligations/source.ts} +172 -216
- package/src/{obligation-deref.ts → obligations/subexpression.ts} +84 -115
- package/src/obligations/substitution.ts +261 -0
- package/src/obligations/temporal.ts +321 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
- package/src/parallel-worker.ts +39 -51
- package/src/parallel.ts +39 -66
- package/src/parser.ts +67 -74
- package/src/{pcal-ast.ts → pcal/ast.ts} +2 -17
- package/src/{pcal-parse.ts → pcal/parse.ts} +28 -64
- package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +10 -39
- package/src/{pcal-translate.ts → pcal/translate.ts} +30 -109
- package/src/{pcal-validate.ts → pcal/validate.ts} +10 -20
- package/src/prover/decide-pool.ts +95 -0
- package/src/prover/deciders.ts +33 -0
- package/src/prover/first-order.ts +175 -0
- package/src/prover/isabelle/LICENSE +36 -0
- package/src/prover/isabelle/LICENSE-tlapm +26 -0
- package/src/prover/isabelle/decide.ts +44 -0
- package/src/prover/isabelle/encode.ts +445 -0
- package/src/prover/isabelle/isar/inner-syntax.ts +579 -0
- package/src/prover/isabelle/isar/method.ts +367 -0
- package/src/prover/isabelle/isar/proof.ts +28 -0
- package/src/prover/isabelle/isar/statement.ts +57 -0
- package/src/prover/isabelle/isar/theory.ts +192 -0
- package/src/prover/isabelle/isar/type-check.ts +278 -0
- package/src/prover/isabelle/provers/blast/blast.ts +258 -0
- package/src/prover/isabelle/provers/blast/branch.ts +322 -0
- package/src/prover/isabelle/provers/blast/prove.ts +347 -0
- package/src/prover/isabelle/provers/blast/rules.ts +330 -0
- package/src/prover/isabelle/provers/blast/state.ts +180 -0
- package/src/prover/isabelle/provers/blast/term.ts +546 -0
- package/src/prover/isabelle/provers/clasimp.ts +150 -0
- package/src/prover/isabelle/provers/classical.ts +389 -0
- package/src/prover/isabelle/provers/hypsubst.ts +433 -0
- package/src/prover/isabelle/pure/bicompose.ts +174 -0
- package/src/prover/isabelle/pure/consts.ts +32 -0
- package/src/prover/isabelle/pure/conv.ts +79 -0
- package/src/prover/isabelle/pure/drule.ts +264 -0
- package/src/prover/isabelle/pure/envir.ts +331 -0
- package/src/prover/isabelle/pure/goal.ts +53 -0
- package/src/prover/isabelle/pure/interrupt.ts +16 -0
- package/src/prover/isabelle/pure/list.ts +12 -0
- package/src/prover/isabelle/pure/logic.ts +330 -0
- package/src/prover/isabelle/pure/name.ts +98 -0
- package/src/prover/isabelle/pure/net.ts +215 -0
- package/src/prover/isabelle/pure/object-logic.ts +41 -0
- package/src/prover/isabelle/pure/pattern.ts +631 -0
- package/src/prover/isabelle/pure/raw-simplifier.ts +338 -0
- package/src/prover/isabelle/pure/rewriter.ts +602 -0
- package/src/prover/isabelle/pure/search.ts +68 -0
- package/src/prover/isabelle/pure/seq.ts +133 -0
- package/src/prover/isabelle/pure/simplifier.ts +106 -0
- package/src/prover/isabelle/pure/table.ts +201 -0
- package/src/prover/isabelle/pure/tactic.ts +168 -0
- package/src/prover/isabelle/pure/tactical.ts +264 -0
- package/src/prover/isabelle/pure/term-ord.ts +105 -0
- package/src/prover/isabelle/pure/term.ts +688 -0
- package/src/prover/isabelle/pure/thm.ts +783 -0
- package/src/prover/isabelle/pure/type.ts +121 -0
- package/src/prover/isabelle/pure/unify.ts +753 -0
- package/src/prover/isabelle/pure/variable.ts +25 -0
- package/src/prover/isabelle/tla/classical-setup.ts +101 -0
- package/src/prover/isabelle/tla/context.ts +74 -0
- package/src/prover/isabelle/tla/logic-data.ts +5 -0
- package/src/prover/isabelle/tla/logic.ts +215 -0
- package/src/prover/isabelle/tla/simpdata.ts +241 -0
- package/src/prover/isabelle/tools/intuitionistic.ts +132 -0
- package/src/prover/ocaml.ts +22 -0
- package/src/prover/prep/action.ts +508 -0
- package/src/prover/prep/enabled-axioms.ts +189 -0
- package/src/prover/prep/fingerprint.ts +388 -0
- package/src/prover/prep/level-comparison.ts +529 -0
- package/src/prover/prep/md5.ts +60 -0
- package/src/prover/prep/methods.ts +221 -0
- package/src/prover/prep/normalize.ts +309 -0
- package/src/prover/prove-worker.ts +22 -0
- package/src/prover/prove.ts +492 -0
- package/src/prover/ptl/decide.ts +68 -0
- package/src/prover/ptl/encode.ts +244 -0
- package/src/prover/ptl/sat.ts +151 -0
- package/src/prover/ptl/tableau.ts +276 -0
- package/src/prover/smt/axioms.ts +209 -0
- package/src/prover/smt/context.ts +108 -0
- package/src/prover/smt/data.ts +636 -0
- package/src/prover/smt/encode.ts +275 -0
- package/src/prover/smt/extensionality.ts +65 -0
- package/src/prover/smt/flatten.ts +112 -0
- package/src/prover/smt/format.ts +154 -0
- package/src/prover/smt/instances.ts +181 -0
- package/src/prover/smt/rewrite.ts +766 -0
- package/src/prover/smt/solver/act-cache.ts +265 -0
- package/src/prover/smt/solver/arith-rewriter.ts +962 -0
- package/src/prover/smt/solver/array.ts +22 -0
- package/src/prover/smt/solver/asserted-formulas.ts +469 -0
- package/src/prover/smt/solver/ast-lt.ts +157 -0
- package/src/prover/smt/solver/ast-util.ts +91 -0
- package/src/prover/smt/solver/ast.ts +1315 -0
- package/src/prover/smt/solver/auf-solver.ts +572 -0
- package/src/prover/smt/solver/case-split-queue.ts +178 -0
- package/src/prover/smt/solver/cg-table.ts +175 -0
- package/src/prover/smt/solver/clause.ts +276 -0
- package/src/prover/smt/solver/conflict-resolution.ts +343 -0
- package/src/prover/smt/solver/context.ts +1292 -0
- package/src/prover/smt/solver/ctx-simplify.ts +334 -0
- package/src/prover/smt/solver/der.ts +224 -0
- package/src/prover/smt/solver/dyn-ack.ts +141 -0
- package/src/prover/smt/solver/e-matching.ts +659 -0
- package/src/prover/smt/solver/enode.ts +259 -0
- package/src/prover/smt/solver/expr-ref.ts +21 -0
- package/src/prover/smt/solver/expr-safe-replace.ts +172 -0
- package/src/prover/smt/solver/fingerprints.ts +92 -0
- package/src/prover/smt/solver/flat-literals.ts +51 -0
- package/src/prover/smt/solver/goal.ts +138 -0
- package/src/prover/smt/solver/hash.ts +173 -0
- package/src/prover/smt/solver/hashtable.ts +166 -0
- package/src/prover/smt/solver/internalizer.ts +1381 -0
- package/src/prover/smt/solver/lbool.ts +5 -0
- package/src/prover/smt/solver/literal.ts +24 -0
- package/src/prover/smt/solver/lp/bound-propagator.ts +391 -0
- package/src/prover/smt/solver/lp/constraints.ts +78 -0
- package/src/prover/smt/solver/lp/containers.ts +296 -0
- package/src/prover/smt/solver/lp/core-solver.ts +504 -0
- package/src/prover/smt/solver/lp/cross-nested.ts +224 -0
- package/src/prover/smt/solver/lp/dep-intervals.ts +642 -0
- package/src/prover/smt/solver/lp/dependency.ts +51 -0
- package/src/prover/smt/solver/lp/dioph-eq.ts +1181 -0
- package/src/prover/smt/solver/lp/explanation.ts +46 -0
- package/src/prover/smt/solver/lp/gomory.ts +255 -0
- package/src/prover/smt/solver/lp/hnf-cutter.ts +125 -0
- package/src/prover/smt/solver/lp/hnf.ts +281 -0
- package/src/prover/smt/solver/lp/int-cube.ts +295 -0
- package/src/prover/smt/solver/lp/int-solver.ts +514 -0
- package/src/prover/smt/solver/lp/lar-solver.ts +816 -0
- package/src/prover/smt/solver/lp/lar-term.ts +62 -0
- package/src/prover/smt/solver/lp/lp-settings.ts +91 -0
- package/src/prover/smt/solver/lp/maximize-term.ts +347 -0
- package/src/prover/smt/solver/lp/nex-creator.ts +381 -0
- package/src/prover/smt/solver/lp/nex.ts +120 -0
- package/src/prover/smt/solver/lp/nla-backoff.ts +43 -0
- package/src/prover/smt/solver/lp/nla-basics.ts +398 -0
- package/src/prover/smt/solver/lp/nla-core.ts +968 -0
- package/src/prover/smt/solver/lp/nla-divisions.ts +332 -0
- package/src/prover/smt/solver/lp/nla-emonics.ts +373 -0
- package/src/prover/smt/solver/lp/nla-factorization.ts +30 -0
- package/src/prover/smt/solver/lp/nla-grobner.ts +904 -0
- package/src/prover/smt/solver/lp/nla-horner.ts +126 -0
- package/src/prover/smt/solver/lp/nla-intervals.ts +265 -0
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +715 -0
- package/src/prover/smt/solver/lp/nla-monotone.ts +59 -0
- package/src/prover/smt/solver/lp/nla-order.ts +307 -0
- package/src/prover/smt/solver/lp/nla-patcher.ts +112 -0
- package/src/prover/smt/solver/lp/nla-tangents.ts +251 -0
- package/src/prover/smt/solver/lp/nla-throttle.ts +85 -0
- package/src/prover/smt/solver/lp/nla-types.ts +124 -0
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +141 -0
- package/src/prover/smt/solver/lp/nra-solver.ts +440 -0
- package/src/prover/smt/solver/lp/numeric-pair.ts +65 -0
- package/src/prover/smt/solver/lp/pdd-interval.ts +31 -0
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +184 -0
- package/src/prover/smt/solver/lp/pdd-solver.ts +408 -0
- package/src/prover/smt/solver/lp/pdd.ts +971 -0
- package/src/prover/smt/solver/lp/random-updater.ts +138 -0
- package/src/prover/smt/solver/lp/static-matrix.ts +246 -0
- package/src/prover/smt/solver/lp/union-find.ts +96 -0
- package/src/prover/smt/solver/mam-compiler.ts +847 -0
- package/src/prover/smt/solver/mam-interpreter.ts +400 -0
- package/src/prover/smt/solver/maximize-ac-sharing.ts +118 -0
- package/src/prover/smt/solver/model-checker.ts +347 -0
- package/src/prover/smt/solver/model-evaluator.ts +262 -0
- package/src/prover/smt/solver/model-finder.ts +155 -0
- package/src/prover/smt/solver/model-generator.ts +97 -0
- package/src/prover/smt/solver/model-macro-solver.ts +728 -0
- package/src/prover/smt/solver/nlsat/algebraic.ts +1161 -0
- package/src/prover/smt/solver/nlsat/atoms.ts +238 -0
- package/src/prover/smt/solver/nlsat/evaluator.ts +303 -0
- package/src/prover/smt/solver/nlsat/explain.ts +607 -0
- package/src/prover/smt/solver/nlsat/interval-set.ts +351 -0
- package/src/prover/smt/solver/nlsat/levelwise.ts +737 -0
- package/src/prover/smt/solver/nlsat/mpbq.ts +161 -0
- package/src/prover/smt/solver/nlsat/polynomial.ts +1722 -0
- package/src/prover/smt/solver/nlsat/solver.ts +911 -0
- package/src/prover/smt/solver/nlsat/types.ts +43 -0
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
- package/src/prover/smt/solver/nlsat/upolynomial.ts +996 -0
- package/src/prover/smt/solver/nnf.ts +469 -0
- package/src/prover/smt/solver/pattern-inference.ts +351 -0
- package/src/prover/smt/solver/poly-rewriter.ts +477 -0
- package/src/prover/smt/solver/propagate-values.ts +83 -0
- package/src/prover/smt/solver/proto-model.ts +551 -0
- package/src/prover/smt/solver/pull-quant.ts +139 -0
- package/src/prover/smt/solver/qe-lite-der.ts +526 -0
- package/src/prover/smt/solver/qe-lite-fm.ts +576 -0
- package/src/prover/smt/solver/qe-lite.ts +381 -0
- package/src/prover/smt/solver/qi-queue.ts +362 -0
- package/src/prover/smt/solver/quant-tactics.ts +117 -0
- package/src/prover/smt/solver/quantifier-analyzer.ts +562 -0
- package/src/prover/smt/solver/quantifier-manager.ts +186 -0
- package/src/prover/smt/solver/random-gen.ts +10 -0
- package/src/prover/smt/solver/rational.ts +165 -0
- package/src/prover/smt/solver/ref-vector.ts +62 -0
- package/src/prover/smt/solver/relevancy.ts +247 -0
- package/src/prover/smt/solver/rewriter-tpl.ts +1159 -0
- package/src/prover/smt/solver/rewriter.ts +843 -0
- package/src/prover/smt/solver/rlimit.ts +79 -0
- package/src/prover/smt/solver/smtlib-parser.ts +526 -0
- package/src/prover/smt/solver/solver.ts +71 -0
- package/src/prover/smt/solver/sort.ts +35 -0
- package/src/prover/smt/solver/sticky-generations.ts +69 -0
- package/src/prover/smt/solver/theory-lra-axioms.ts +340 -0
- package/src/prover/smt/solver/theory-lra-bounds.ts +226 -0
- package/src/prover/smt/solver/theory-lra-final-check.ts +252 -0
- package/src/prover/smt/solver/theory-lra-internalize.ts +476 -0
- package/src/prover/smt/solver/theory-lra-model.ts +243 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +405 -0
- package/src/prover/smt/solver/theory-lra-state.ts +43 -0
- package/src/prover/smt/solver/theory-lra.ts +56 -0
- package/src/prover/smt/solver/var-subst.ts +258 -0
- package/src/prover/smt/solver/z3-license.txt +10 -0
- package/src/prover/smt/table.ts +170 -0
- package/src/prover/tlapm/cache.ts +236 -0
- package/src/prover/tlapm/ocaml-marshal.ts +166 -0
- package/src/prover/tlapm/tlapm.ts +96 -0
- package/src/prover/tlaps-module.ts +510 -0
- package/src/prover/verdict.ts +13 -0
- package/src/prover/zenon/LICENSE +32 -0
- package/src/prover/zenon/check/check.ts +105 -0
- package/src/prover/zenon/check/definitions.ts +144 -0
- package/src/prover/zenon/check/equality.ts +182 -0
- package/src/prover/zenon/check/functions.ts +62 -0
- package/src/prover/zenon/check/keys.ts +125 -0
- package/src/prover/zenon/check/propositional.ts +104 -0
- package/src/prover/zenon/check/records.ts +188 -0
- package/src/prover/zenon/check/relations.ts +121 -0
- package/src/prover/zenon/check/rewrites.ts +224 -0
- package/src/prover/zenon/check/sets.ts +302 -0
- package/src/prover/zenon/check/terms.ts +127 -0
- package/src/prover/zenon/check/tla.ts +126 -0
- package/src/prover/zenon/decide.ts +107 -0
- package/src/prover/zenon/encode.ts +378 -0
- package/src/prover/zenon/eqrel.ts +300 -0
- package/src/prover/zenon/equality-rules.ts +435 -0
- package/src/prover/zenon/expr.ts +551 -0
- package/src/prover/zenon/index-table.ts +350 -0
- package/src/prover/zenon/isar-case.ts +513 -0
- package/src/prover/zenon/isar.ts +1249 -0
- package/src/prover/zenon/limits.ts +15 -0
- package/src/prover/zenon/llproof.ts +173 -0
- package/src/prover/zenon/mltoll.ts +1566 -0
- package/src/prover/zenon/node.ts +297 -0
- package/src/prover/zenon/ocaml.ts +169 -0
- package/src/prover/zenon/parse.ts +247 -0
- package/src/prover/zenon/phrase.ts +191 -0
- package/src/prover/zenon/proof.ts +198 -0
- package/src/prover/zenon/propositional-rules.ts +387 -0
- package/src/prover/zenon/rules.ts +94 -0
- package/src/prover/zenon/search.ts +288 -0
- package/src/prover/zenon/tla/functions.ts +151 -0
- package/src/prover/zenon/tla/llproof.ts +480 -0
- package/src/prover/zenon/tla/records.ts +225 -0
- package/src/prover/zenon/tla/rewrites.ts +447 -0
- package/src/prover/zenon/tla/sets.ts +304 -0
- package/src/prover/zenon/tla/terms.ts +162 -0
- package/src/prover/zenon/tla/tla.ts +506 -0
- package/src/randomization.ts +19 -24
- package/src/resolve.ts +15 -22
- package/src/runtime.ts +8 -8
- package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
- package/src/{sany-generator.ts → sany/generator.ts} +38 -55
- package/src/{sany-levels.ts → sany/levels.ts} +45 -48
- package/src/{sany-lexer.ts → sany/lexer.ts} +2 -3
- package/src/{sany-linter.ts → sany/linter.ts} +1 -1
- package/src/{sany-modules.ts → sany/modules.ts} +2 -2
- package/src/{sany-nodes.ts → sany/nodes.ts} +2 -2
- package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
- package/src/{sany-report.ts → sany/report.ts} +16 -17
- package/src/{sany-selectors.ts → sany/selectors.ts} +3 -5
- package/src/{sany-source.ts → sany/source.ts} +6 -7
- package/src/{sany-xml.ts → sany/xml.ts} +5 -6
- package/src/search.ts +969 -0
- package/src/spec-description.ts +26 -20
- package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
- package/src/standard-modules.ts +16 -20
- package/src/state-graph.ts +9 -8
- package/src/substitution-levels.ts +2 -2
- package/src/successors.ts +38 -22
- package/src/symmetry.ts +1 -1
- package/src/tableau.ts +6 -7
- package/src/tlc/fingerprint.ts +214 -0
- package/src/{tlc-messages.ts → tlc/messages.ts} +119 -7
- package/src/{tlc-order.ts → tlc/order.ts} +7 -7
- package/src/{tlc-random.ts → tlc/random.ts} +3 -190
- package/src/{tlc-replay.ts → tlc/replay.ts} +40 -36
- package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
- package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +30 -25
- package/src/{tlc-version.ts → tlc/version.ts} +8 -7
- package/src/transfer.ts +32 -32
- package/src/values.ts +119 -71
- package/src/worker.ts +62 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
- package/dist/run-cli.cjs +0 -55
- package/dist/run-cli.js +0 -55
- package/src/canonical.ts +0 -40
- package/src/obligation-expression.ts +0 -1060
- package/src/obligation-module.ts +0 -1042
- package/src/standard-ranges.ts +0 -116
- package/src/value-sources.ts +0 -29
- /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
- /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// level depends on.
|
|
1
|
+
// Expr.Levels: the level of an expression (0 constant, 1 state, 2 action, 3 temporal, 4 undefined),
|
|
2
|
+
// the weights of an operator's arguments, and the declared names the level depends on.
|
|
4
3
|
|
|
5
|
-
import { TlaProofError, TlapmBugError } from "
|
|
4
|
+
import { TlaProofError, TlapmBugError } from "../errors";
|
|
6
5
|
import {
|
|
7
6
|
adjoin,
|
|
7
|
+
adjoinAll,
|
|
8
8
|
getBoundedFresh,
|
|
9
|
+
getBoundFresh,
|
|
9
10
|
getFresh,
|
|
11
|
+
getLocalDefn,
|
|
12
|
+
getParamFresh,
|
|
10
13
|
getScopeAt,
|
|
14
|
+
isBuiltinApply,
|
|
11
15
|
mapAccumulate,
|
|
12
16
|
type Bound,
|
|
13
17
|
type Builtin,
|
|
14
18
|
type Expr,
|
|
15
19
|
type Level,
|
|
16
20
|
type Scope,
|
|
17
|
-
} from "./
|
|
21
|
+
} from "./expression";
|
|
18
22
|
|
|
19
23
|
interface LevelInfo {
|
|
20
24
|
level: number;
|
|
@@ -112,7 +116,7 @@ export const LEVEL_NUMBERS: Record<Level, number> = {
|
|
|
112
116
|
|
|
113
117
|
const union = (sets: Set<string>[]) => new Set(sets.flatMap((set) => [...set]));
|
|
114
118
|
|
|
115
|
-
const
|
|
119
|
+
const combineLevels = (infos: LevelInfo[]): LevelInfo => ({
|
|
116
120
|
level: Math.max(0, ...infos.map((info) => info.level)),
|
|
117
121
|
weights: [],
|
|
118
122
|
params: union(infos.map((info) => info.params)),
|
|
@@ -152,11 +156,10 @@ const getBoundsLevel = (scope: Scope | undefined, bounds: Bound[], body: Expr) =
|
|
|
152
156
|
const domains = bounds.flatMap((bound) =>
|
|
153
157
|
bound.domain.kind === "Domain" ? [getLevelInfo(scope, bound.domain.expression)] : [],
|
|
154
158
|
);
|
|
155
|
-
|
|
156
|
-
(
|
|
157
|
-
|
|
158
|
-
);
|
|
159
|
-
return combine([getLevelInfo(inner, body), ...domains]);
|
|
159
|
+
return combineLevels([
|
|
160
|
+
getLevelInfo(adjoinAll(scope, bounds.map(getBoundFresh)), body),
|
|
161
|
+
...domains,
|
|
162
|
+
]);
|
|
160
163
|
};
|
|
161
164
|
|
|
162
165
|
const applyOperator = (operator: LevelInfo, args: LevelInfo[]): LevelInfo => {
|
|
@@ -189,11 +192,10 @@ export const getLevelInfo = (scope: Scope | undefined, expression: Expr): LevelI
|
|
|
189
192
|
case "Num":
|
|
190
193
|
return getInfo(0);
|
|
191
194
|
case "Lambda": {
|
|
192
|
-
const
|
|
193
|
-
(
|
|
194
|
-
|
|
195
|
+
const body = getLevelInfo(
|
|
196
|
+
adjoinAll(scope, expression.params.map(getParamFresh)),
|
|
197
|
+
expression.body,
|
|
195
198
|
);
|
|
196
|
-
const body = getLevelInfo(inner, expression.body);
|
|
197
199
|
const names = new Set(expression.params.map((param) => param.name));
|
|
198
200
|
return {
|
|
199
201
|
level: body.level,
|
|
@@ -203,6 +205,11 @@ export const getLevelInfo = (scope: Scope | undefined, expression: Expr): LevelI
|
|
|
203
205
|
}
|
|
204
206
|
case "Apply": {
|
|
205
207
|
const operator = expression.operator;
|
|
208
|
+
// The action frontend commutes a prime onto an operator, and tlapm keeps the level that
|
|
209
|
+
// the application had.
|
|
210
|
+
if (isBuiltinApply(operator, "Prime") && operator.args.length === 1) {
|
|
211
|
+
return recurse({ ...expression, operator: operator.args[0] });
|
|
212
|
+
}
|
|
206
213
|
if (operator.kind === "Opaque") {
|
|
207
214
|
return applyOperator(getInfo(0, expression.args.length), expression.args.map(recurse));
|
|
208
215
|
}
|
|
@@ -246,26 +253,17 @@ export const getLevelInfo = (scope: Scope | undefined, expression: Expr): LevelI
|
|
|
246
253
|
case "Dot":
|
|
247
254
|
case "Parens":
|
|
248
255
|
return recurse(expression.expression);
|
|
249
|
-
case "Let":
|
|
250
|
-
|
|
251
|
-
(
|
|
252
|
-
|
|
253
|
-
kind: "Defn",
|
|
254
|
-
definition,
|
|
255
|
-
whereDefined: "User",
|
|
256
|
-
visibility: "Visible",
|
|
257
|
-
isLocal: true,
|
|
258
|
-
}),
|
|
259
|
-
scope,
|
|
256
|
+
case "Let":
|
|
257
|
+
return getLevelInfo(
|
|
258
|
+
adjoinAll(scope, expression.definitions.map(getLocalDefn)),
|
|
259
|
+
expression.body,
|
|
260
260
|
);
|
|
261
|
-
return getLevelInfo(inner, expression.body);
|
|
262
|
-
}
|
|
263
261
|
case "If":
|
|
264
|
-
return
|
|
262
|
+
return combineLevels(
|
|
265
263
|
[expression.condition, expression.consequent, expression.alternative].map(recurse),
|
|
266
264
|
);
|
|
267
265
|
case "List":
|
|
268
|
-
return
|
|
266
|
+
return combineLevels(expression.items.map(recurse));
|
|
269
267
|
case "Quant":
|
|
270
268
|
case "Fcn":
|
|
271
269
|
return getBoundsLevel(scope, expression.bounds, expression.body);
|
|
@@ -273,7 +271,10 @@ export const getLevelInfo = (scope: Scope | undefined, expression: Expr): LevelI
|
|
|
273
271
|
return getBoundsLevel(scope, expression.bounds, expression.element);
|
|
274
272
|
case "Tquant":
|
|
275
273
|
getLevelInfo(
|
|
276
|
-
|
|
274
|
+
adjoinAll(
|
|
275
|
+
scope,
|
|
276
|
+
expression.names.map((name) => ({ kind: "Flex", name })),
|
|
277
|
+
),
|
|
277
278
|
expression.body,
|
|
278
279
|
);
|
|
279
280
|
return getInfo(3);
|
|
@@ -283,25 +284,25 @@ export const getLevelInfo = (scope: Scope | undefined, expression: Expr): LevelI
|
|
|
283
284
|
const hyp = expression.domain
|
|
284
285
|
? getBoundedFresh(expression.name, expression.domain)
|
|
285
286
|
: getFresh(expression.name, "Constant");
|
|
286
|
-
return
|
|
287
|
+
return combineLevels([
|
|
287
288
|
getLevelInfo(adjoin(scope, hyp), expression.body),
|
|
288
289
|
...(domainLevel ? [domainLevel] : []),
|
|
289
290
|
]);
|
|
290
291
|
}
|
|
291
292
|
case "SetEnum":
|
|
292
293
|
case "Tuple":
|
|
293
|
-
return
|
|
294
|
+
return combineLevels(expression.elements.map(recurse));
|
|
294
295
|
case "Product":
|
|
295
|
-
return
|
|
296
|
+
return combineLevels(expression.factors.map(recurse));
|
|
296
297
|
case "FcnApp":
|
|
297
|
-
return
|
|
298
|
+
return combineLevels([expression.function, ...expression.args].map(recurse));
|
|
298
299
|
case "Arrow":
|
|
299
|
-
return
|
|
300
|
+
return combineLevels([recurse(expression.domain), recurse(expression.range)]);
|
|
300
301
|
case "Rect":
|
|
301
302
|
case "Record":
|
|
302
|
-
return
|
|
303
|
+
return combineLevels(expression.fields.map((field) => recurse(field.value)));
|
|
303
304
|
case "Except":
|
|
304
|
-
return
|
|
305
|
+
return combineLevels([
|
|
305
306
|
recurse(expression.function),
|
|
306
307
|
...expression.specs.flatMap((spec) => [
|
|
307
308
|
...spec.trail.flatMap((point) =>
|
|
@@ -311,14 +312,17 @@ export const getLevelInfo = (scope: Scope | undefined, expression: Expr): LevelI
|
|
|
311
312
|
]),
|
|
312
313
|
]);
|
|
313
314
|
case "Sub":
|
|
314
|
-
return {
|
|
315
|
+
return {
|
|
316
|
+
...combineLevels([recurse(expression.action), recurse(expression.subscript)]),
|
|
317
|
+
level: 2,
|
|
318
|
+
};
|
|
315
319
|
case "Tsub":
|
|
316
320
|
case "Fair":
|
|
317
321
|
recurse(expression.action);
|
|
318
322
|
recurse(expression.subscript);
|
|
319
323
|
return getInfo(3);
|
|
320
324
|
case "Case":
|
|
321
|
-
return
|
|
325
|
+
return combineLevels([
|
|
322
326
|
...expression.arms.flatMap((arm) => [recurse(arm.condition), recurse(arm.body)]),
|
|
323
327
|
...(expression.other ? [recurse(expression.other)] : []),
|
|
324
328
|
]);
|
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
// tlapm's module units, with the standard modules, flattening EXTENDS (Module.Flatten), the
|
|
2
|
+
// modules a module depends on (Module.Dep), and substitution in units (Module.Subst).
|
|
3
|
+
|
|
4
|
+
import { TlaProofError, TlapmBugError } from "../errors";
|
|
5
|
+
import {
|
|
6
|
+
at,
|
|
7
|
+
exprifySequent,
|
|
8
|
+
getFact,
|
|
9
|
+
getFresh,
|
|
10
|
+
mapAccumulate,
|
|
11
|
+
type Builtin,
|
|
12
|
+
type Defn,
|
|
13
|
+
type Expr,
|
|
14
|
+
type Hyp,
|
|
15
|
+
type InstanceDefinition,
|
|
16
|
+
type Locus,
|
|
17
|
+
type Sequent,
|
|
18
|
+
type Visibility,
|
|
19
|
+
type WhereDefined,
|
|
20
|
+
} from "./expression";
|
|
21
|
+
import type { Proof, Usable } from "./proof";
|
|
22
|
+
import {
|
|
23
|
+
bumpBy,
|
|
24
|
+
shift,
|
|
25
|
+
shiftExpr,
|
|
26
|
+
substituteDefn,
|
|
27
|
+
substituteExpr,
|
|
28
|
+
substituteExprs,
|
|
29
|
+
substituteSequent,
|
|
30
|
+
type Substitution,
|
|
31
|
+
} from "./substitution";
|
|
32
|
+
|
|
33
|
+
export type ModuleUnit = ModuleUnitCore & { location?: Locus };
|
|
34
|
+
|
|
35
|
+
type ModuleUnitCore =
|
|
36
|
+
| { kind: "Constants" | "Recursives"; declarations: { name: string; shape: number }[] }
|
|
37
|
+
| { kind: "Variables"; names: string[] }
|
|
38
|
+
| {
|
|
39
|
+
kind: "Definition";
|
|
40
|
+
definition: Defn;
|
|
41
|
+
whereDefined: WhereDefined;
|
|
42
|
+
visibility: Visibility;
|
|
43
|
+
isLocal: boolean;
|
|
44
|
+
}
|
|
45
|
+
| { kind: "Axiom"; name: string | undefined; expression: Expr }
|
|
46
|
+
| {
|
|
47
|
+
kind: "Theorem";
|
|
48
|
+
name: string | undefined;
|
|
49
|
+
sequent: Sequent;
|
|
50
|
+
axiomCount: number;
|
|
51
|
+
proof: Proof;
|
|
52
|
+
}
|
|
53
|
+
| { kind: "Submod"; module: Mule }
|
|
54
|
+
| { kind: "Mutate"; mode: "Use" | "Hide"; usable: Usable }
|
|
55
|
+
| { kind: "Anoninst"; instance: InstanceDefinition; isLocal: boolean };
|
|
56
|
+
|
|
57
|
+
// depth is the size of the context the module was normalized in, which instantiation shifts
|
|
58
|
+
// its body by.
|
|
59
|
+
export interface Mule {
|
|
60
|
+
name: string;
|
|
61
|
+
extendees: string[];
|
|
62
|
+
extendeeLocations?: Locus[];
|
|
63
|
+
body: ModuleUnit[];
|
|
64
|
+
isImportant: boolean;
|
|
65
|
+
isStandard?: boolean;
|
|
66
|
+
depth?: number;
|
|
67
|
+
location?: Locus;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const defineBuiltin = (arity: number, name: string, builtin: Builtin): ModuleUnit => ({
|
|
71
|
+
kind: "Definition",
|
|
72
|
+
definition: {
|
|
73
|
+
kind: "Operator",
|
|
74
|
+
name,
|
|
75
|
+
body:
|
|
76
|
+
arity === 0
|
|
77
|
+
? { kind: "Internal", builtin }
|
|
78
|
+
: {
|
|
79
|
+
kind: "Lambda",
|
|
80
|
+
params: Array.from({ length: arity }, (_item, index) => ({
|
|
81
|
+
name: `x${index + 1}`,
|
|
82
|
+
shape: 0,
|
|
83
|
+
})),
|
|
84
|
+
body: {
|
|
85
|
+
kind: "Apply",
|
|
86
|
+
operator: { kind: "Internal", builtin },
|
|
87
|
+
args: Array.from({ length: arity }, (_item, index) => ({
|
|
88
|
+
kind: "Ix",
|
|
89
|
+
index: arity - index,
|
|
90
|
+
})),
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
whereDefined: "Builtin",
|
|
95
|
+
visibility: "Visible",
|
|
96
|
+
isLocal: false,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const NATURALS: ModuleUnit[] = [
|
|
100
|
+
defineBuiltin(0, "Nat", "Nat"),
|
|
101
|
+
defineBuiltin(2, "+", "Plus"),
|
|
102
|
+
defineBuiltin(2, "-", "Minus"),
|
|
103
|
+
defineBuiltin(2, "*", "Times"),
|
|
104
|
+
defineBuiltin(2, "^", "Exp"),
|
|
105
|
+
defineBuiltin(2, "<", "Lt"),
|
|
106
|
+
defineBuiltin(2, ">", "Gt"),
|
|
107
|
+
defineBuiltin(2, "=<", "Lteq"),
|
|
108
|
+
defineBuiltin(2, ">=", "Gteq"),
|
|
109
|
+
defineBuiltin(2, "%", "Remainder"),
|
|
110
|
+
defineBuiltin(2, "\\div", "Quotient"),
|
|
111
|
+
defineBuiltin(2, "..", "Range"),
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
const INTEGERS = [...NATURALS, defineBuiltin(0, "Int", "Int"), defineBuiltin(1, "-.", "Uminus")];
|
|
115
|
+
|
|
116
|
+
const REALS = [
|
|
117
|
+
...INTEGERS,
|
|
118
|
+
defineBuiltin(0, "Real", "Real"),
|
|
119
|
+
defineBuiltin(2, "/", "Ratio"),
|
|
120
|
+
defineBuiltin(0, "Infinity", "Infinity"),
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
const SEQUENCES = [
|
|
124
|
+
defineBuiltin(1, "Seq", "Seq"),
|
|
125
|
+
defineBuiltin(1, "Len", "Len"),
|
|
126
|
+
defineBuiltin(2, "BSeq", "BSeq"),
|
|
127
|
+
defineBuiltin(2, "\\o", "Cat"),
|
|
128
|
+
defineBuiltin(2, "Append", "Append"),
|
|
129
|
+
defineBuiltin(1, "Head", "Head"),
|
|
130
|
+
defineBuiltin(1, "Tail", "Tail"),
|
|
131
|
+
defineBuiltin(3, "SubSeq", "SubSeq"),
|
|
132
|
+
defineBuiltin(2, "SelectSeq", "SelectSeq"),
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
const TLC = [
|
|
136
|
+
defineBuiltin(2, "Print", "Print"),
|
|
137
|
+
defineBuiltin(1, "PrintT", "PrintT"),
|
|
138
|
+
defineBuiltin(2, "Assert", "Assert"),
|
|
139
|
+
defineBuiltin(0, "JavaTime", "JavaTime"),
|
|
140
|
+
defineBuiltin(1, "TLCGet", "TLCGet"),
|
|
141
|
+
defineBuiltin(2, "TLCSet", "TLCSet"),
|
|
142
|
+
defineBuiltin(2, ":>", "OneArg"),
|
|
143
|
+
defineBuiltin(2, "@@", "Extend"),
|
|
144
|
+
defineBuiltin(1, "Permutations", "Permutations"),
|
|
145
|
+
defineBuiltin(2, "SortSeq", "SortSeq"),
|
|
146
|
+
defineBuiltin(1, "RandomElement", "RandomElement"),
|
|
147
|
+
defineBuiltin(0, "Any", "Any"),
|
|
148
|
+
defineBuiltin(1, "ToString", "ToString"),
|
|
149
|
+
];
|
|
150
|
+
|
|
151
|
+
const getStandardModule = (name: string, body: ModuleUnit[]): Mule => ({
|
|
152
|
+
name,
|
|
153
|
+
extendees: [],
|
|
154
|
+
body,
|
|
155
|
+
isImportant: false,
|
|
156
|
+
isStandard: true,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Module.Standard.initctx, apart from $TLAPM, whose Builtins! names no module of the corpora uses.
|
|
160
|
+
export const STANDARD_MODULES = new Map(
|
|
161
|
+
[
|
|
162
|
+
getStandardModule("Naturals", NATURALS),
|
|
163
|
+
getStandardModule("Integers", INTEGERS),
|
|
164
|
+
getStandardModule("Reals", REALS),
|
|
165
|
+
getStandardModule("Sequences", SEQUENCES),
|
|
166
|
+
getStandardModule("TLC", TLC),
|
|
167
|
+
].map((module) => [module.name, module]),
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
export const getUnitHyps = (unit: ModuleUnit): Hyp[] => {
|
|
171
|
+
const location = unit.location;
|
|
172
|
+
switch (unit.kind) {
|
|
173
|
+
case "Constants":
|
|
174
|
+
return unit.declarations.map((declaration) => ({
|
|
175
|
+
...getFresh(declaration.name, "Constant", declaration.shape),
|
|
176
|
+
location,
|
|
177
|
+
}));
|
|
178
|
+
case "Recursives":
|
|
179
|
+
return unit.declarations.map((declaration) => ({
|
|
180
|
+
kind: "Defn",
|
|
181
|
+
definition: {
|
|
182
|
+
kind: "Recursive",
|
|
183
|
+
name: declaration.name,
|
|
184
|
+
shape: declaration.shape,
|
|
185
|
+
location,
|
|
186
|
+
},
|
|
187
|
+
whereDefined: "User",
|
|
188
|
+
visibility: "Hidden",
|
|
189
|
+
isLocal: false,
|
|
190
|
+
location,
|
|
191
|
+
}));
|
|
192
|
+
case "Variables":
|
|
193
|
+
return unit.names.map((name) => ({ kind: "Flex", name, location }));
|
|
194
|
+
case "Definition":
|
|
195
|
+
return [
|
|
196
|
+
{
|
|
197
|
+
kind: "Defn",
|
|
198
|
+
definition: unit.definition,
|
|
199
|
+
whereDefined: unit.whereDefined,
|
|
200
|
+
visibility: unit.visibility,
|
|
201
|
+
isLocal: unit.isLocal,
|
|
202
|
+
location,
|
|
203
|
+
},
|
|
204
|
+
];
|
|
205
|
+
case "Axiom":
|
|
206
|
+
case "Theorem": {
|
|
207
|
+
const expression =
|
|
208
|
+
unit.kind === "Axiom"
|
|
209
|
+
? unit.expression
|
|
210
|
+
: at(
|
|
211
|
+
exprifySequent(
|
|
212
|
+
substituteSequent(shift(-unit.axiomCount), {
|
|
213
|
+
...unit.sequent,
|
|
214
|
+
context: unit.sequent.context.slice(unit.axiomCount),
|
|
215
|
+
}),
|
|
216
|
+
),
|
|
217
|
+
unit,
|
|
218
|
+
);
|
|
219
|
+
return unit.name === undefined
|
|
220
|
+
? [getFact(expression, "Hidden", "Always", location)]
|
|
221
|
+
: getNamedFact(unit.name, expression, location);
|
|
222
|
+
}
|
|
223
|
+
case "Mutate":
|
|
224
|
+
return unit.mode === "Use"
|
|
225
|
+
? unit.usable.facts.map((fact, index) =>
|
|
226
|
+
getFact(shiftExpr(index, fact), "Visible", "Always", location),
|
|
227
|
+
)
|
|
228
|
+
: [];
|
|
229
|
+
case "Submod":
|
|
230
|
+
case "Anoninst":
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
export const getHypSize = (unit: ModuleUnit) =>
|
|
236
|
+
unit.kind === "Axiom" || unit.kind === "Theorem"
|
|
237
|
+
? unit.name === undefined
|
|
238
|
+
? 1
|
|
239
|
+
: 2
|
|
240
|
+
: getUnitHyps(unit).length;
|
|
241
|
+
|
|
242
|
+
const getNamedFact = (name: string, expression: Expr, location: Locus | undefined): Hyp[] => [
|
|
243
|
+
{
|
|
244
|
+
kind: "Defn",
|
|
245
|
+
definition: { kind: "Operator", name, body: expression, location },
|
|
246
|
+
whereDefined: "User",
|
|
247
|
+
visibility: "Visible",
|
|
248
|
+
isLocal: false,
|
|
249
|
+
location,
|
|
250
|
+
},
|
|
251
|
+
getFact({ kind: "Ix", index: 1, location }, "Hidden", "Always", location),
|
|
252
|
+
];
|
|
253
|
+
|
|
254
|
+
// Module.Flatten.exports: what an extending module sees, with local definitions inlined like
|
|
255
|
+
// builtins and proofs omitted.
|
|
256
|
+
const getExports = (module: Mule): ModuleUnit[] =>
|
|
257
|
+
module.body.flatMap((unit): ModuleUnit[] => {
|
|
258
|
+
switch (unit.kind) {
|
|
259
|
+
case "Definition":
|
|
260
|
+
return [{ ...unit, whereDefined: unit.isLocal ? "Builtin" : unit.whereDefined }];
|
|
261
|
+
case "Mutate":
|
|
262
|
+
return [];
|
|
263
|
+
case "Theorem":
|
|
264
|
+
return [
|
|
265
|
+
{ ...unit, proof: { kind: "Omitted", omission: "Elsewhere", location: unit.location } },
|
|
266
|
+
];
|
|
267
|
+
case "Submod":
|
|
268
|
+
return [{ ...unit, module: { ...unit.module, body: getExports(unit.module) } }];
|
|
269
|
+
default:
|
|
270
|
+
return [unit];
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// tlapm recurses on a module that extends itself until the stack overflows.
|
|
275
|
+
export const flatten = (
|
|
276
|
+
modules: Map<string, Mule>,
|
|
277
|
+
module: Mule,
|
|
278
|
+
seen: Set<string>,
|
|
279
|
+
extending = new Set([module.name]),
|
|
280
|
+
): Mule => {
|
|
281
|
+
const extension: ModuleUnit[] = [];
|
|
282
|
+
for (const name of module.extendees) {
|
|
283
|
+
if (seen.has(name)) continue;
|
|
284
|
+
if (extending.has(name)) throw new TlapmBugError("Stack overflow");
|
|
285
|
+
const extended = modules.get(name);
|
|
286
|
+
if (!extended) throw new TlaProofError(`Module "${name}" unknown`);
|
|
287
|
+
extension.push(...getExports(flatten(modules, extended, seen, new Set([...extending, name]))));
|
|
288
|
+
seen.add(name);
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
...module,
|
|
292
|
+
body: [...extension, ...module.body].map((unit) =>
|
|
293
|
+
unit.kind === "Submod" ? { ...unit, module: flatten(modules, unit.module, new Set()) } : unit,
|
|
294
|
+
),
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
// Module.Dep.external_deps: the modules a module extends or instantiates, including those of its
|
|
299
|
+
// submodules.
|
|
300
|
+
export const getDependencies = (module: Mule) => {
|
|
301
|
+
const dependencies = new Map<string, Locus | undefined>();
|
|
302
|
+
const addDependency = (name: string, location: Locus | undefined) => {
|
|
303
|
+
if (!dependencies.has(name)) dependencies.set(name, location);
|
|
304
|
+
};
|
|
305
|
+
const addExtendees = (extending: Mule) =>
|
|
306
|
+
extending.extendees.forEach((name, index) =>
|
|
307
|
+
addDependency(name, extending.extendeeLocations?.[index]),
|
|
308
|
+
);
|
|
309
|
+
const locals = new Set<string>();
|
|
310
|
+
const submodules = new Map<string, Mule>();
|
|
311
|
+
// Every INSTANCE definition inside a value, such as one in a LET.
|
|
312
|
+
const addInstances = (value: unknown) => {
|
|
313
|
+
if (typeof value !== "object" || value === null) return;
|
|
314
|
+
if ("instance" in value && isInstanceDefinition(value.instance)) {
|
|
315
|
+
addDependency(value.instance.module, value.instance.location);
|
|
316
|
+
}
|
|
317
|
+
Object.values(value).forEach(addInstances);
|
|
318
|
+
};
|
|
319
|
+
// Leaves out the proofs of theorems.
|
|
320
|
+
const visit = (unit: ModuleUnit) => {
|
|
321
|
+
if (unit.kind !== "Submod") {
|
|
322
|
+
addInstances(unit.kind === "Theorem" ? unit.sequent : unit);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
locals.add(unit.module.name);
|
|
326
|
+
submodules.set(unit.module.name, unit.module);
|
|
327
|
+
addExtendees(unit.module);
|
|
328
|
+
unit.module.body.forEach(visit);
|
|
329
|
+
};
|
|
330
|
+
module.body.forEach(visit);
|
|
331
|
+
locals.forEach((name) => dependencies.delete(name));
|
|
332
|
+
addExtendees(module);
|
|
333
|
+
return {
|
|
334
|
+
dependencies: [...dependencies.keys()].sort(compareNames),
|
|
335
|
+
locations: dependencies,
|
|
336
|
+
submodules,
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const isInstanceDefinition = (value: unknown): value is InstanceDefinition =>
|
|
341
|
+
typeof value === "object" &&
|
|
342
|
+
value !== null &&
|
|
343
|
+
"module" in value &&
|
|
344
|
+
typeof value.module === "string" &&
|
|
345
|
+
"substitutions" in value;
|
|
346
|
+
|
|
347
|
+
export const compareNames = (left: string, right: string) =>
|
|
348
|
+
left < right ? -1 : left > right ? 1 : 0;
|
|
349
|
+
|
|
350
|
+
const substituteUsable = (substitution: Substitution, usable: Usable): Usable => ({
|
|
351
|
+
facts: substituteExprs(substitution, usable.facts),
|
|
352
|
+
defs: usable.defs.map((def) => {
|
|
353
|
+
if (def.kind === "Dvar") return def;
|
|
354
|
+
const substituted = substituteExpr(substitution, { kind: "Ix", index: def.index });
|
|
355
|
+
if (substituted.kind !== "Ix") throw new TlaProofError("substitution produced bad definition");
|
|
356
|
+
return { ...def, index: substituted.index };
|
|
357
|
+
}),
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
// Module.Subst.app_modunit. Instantiated theorems carry omitted proofs, which a substitution leaves
|
|
361
|
+
// alone.
|
|
362
|
+
const substituteUnit = (
|
|
363
|
+
substitution: Substitution,
|
|
364
|
+
unit: ModuleUnit,
|
|
365
|
+
): [Substitution, ModuleUnit] => {
|
|
366
|
+
switch (unit.kind) {
|
|
367
|
+
case "Constants":
|
|
368
|
+
case "Recursives":
|
|
369
|
+
return [bumpBy(unit.declarations.length, substitution), unit];
|
|
370
|
+
case "Variables":
|
|
371
|
+
return [bumpBy(unit.names.length, substitution), unit];
|
|
372
|
+
case "Definition":
|
|
373
|
+
return [
|
|
374
|
+
bumpBy(1, substitution),
|
|
375
|
+
{ ...unit, definition: substituteDefn(substitution, unit.definition) },
|
|
376
|
+
];
|
|
377
|
+
case "Axiom":
|
|
378
|
+
return [
|
|
379
|
+
bumpBy(getHypSize(unit), substitution),
|
|
380
|
+
{ ...unit, expression: substituteExpr(substitution, unit.expression) },
|
|
381
|
+
];
|
|
382
|
+
case "Theorem":
|
|
383
|
+
return [
|
|
384
|
+
bumpBy(getHypSize(unit), substitution),
|
|
385
|
+
{ ...unit, sequent: substituteSequent(substitution, unit.sequent) },
|
|
386
|
+
];
|
|
387
|
+
case "Submod":
|
|
388
|
+
return [
|
|
389
|
+
substitution,
|
|
390
|
+
{
|
|
391
|
+
...unit,
|
|
392
|
+
module: { ...unit.module, body: substituteUnits(substitution, unit.module.body) },
|
|
393
|
+
},
|
|
394
|
+
];
|
|
395
|
+
case "Mutate":
|
|
396
|
+
return [
|
|
397
|
+
unit.mode === "Hide" ? substitution : bumpBy(unit.usable.facts.length, substitution),
|
|
398
|
+
{ ...unit, usable: substituteUsable(substitution, unit.usable) },
|
|
399
|
+
];
|
|
400
|
+
case "Anoninst":
|
|
401
|
+
return [
|
|
402
|
+
substitution,
|
|
403
|
+
{
|
|
404
|
+
...unit,
|
|
405
|
+
instance: {
|
|
406
|
+
...unit.instance,
|
|
407
|
+
substitutions: unit.instance.substitutions.map((entry) => ({
|
|
408
|
+
name: entry.name,
|
|
409
|
+
expression: substituteExpr(substitution, entry.expression),
|
|
410
|
+
})),
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
];
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
export const substituteUnits = (substitution: Substitution, units: ModuleUnit[]) =>
|
|
418
|
+
mapAccumulate(substitution, units, substituteUnit)[1];
|
|
419
|
+
|
|
420
|
+
// A named theorem binds its name as a proof definition, which its statement shifts past.
|
|
421
|
+
export const bindTheoremName = (
|
|
422
|
+
name: string | undefined,
|
|
423
|
+
sequent: Sequent,
|
|
424
|
+
location: Locus | undefined,
|
|
425
|
+
): { hyps: Hyp[]; sequent: Sequent } =>
|
|
426
|
+
name === undefined
|
|
427
|
+
? { hyps: [], sequent }
|
|
428
|
+
: {
|
|
429
|
+
hyps: [
|
|
430
|
+
{
|
|
431
|
+
kind: "Defn",
|
|
432
|
+
definition: {
|
|
433
|
+
kind: "Operator",
|
|
434
|
+
name,
|
|
435
|
+
body: at(exprifySequent(sequent), { location }),
|
|
436
|
+
location,
|
|
437
|
+
},
|
|
438
|
+
whereDefined: { kind: "Proof", time: "Always" },
|
|
439
|
+
visibility: "Visible",
|
|
440
|
+
isLocal: false,
|
|
441
|
+
location,
|
|
442
|
+
},
|
|
443
|
+
],
|
|
444
|
+
sequent: substituteSequent(shift(1), sequent),
|
|
445
|
+
};
|