tla-ts 0.0.4 → 0.0.5
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 +46 -12
- package/dist/index.d.ts +46 -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 +43 -22
- 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 +361 -181
- 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} +207 -141
- 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 +21 -22
- package/src/state-graph.ts +9 -8
- package/src/substitution-levels.ts +2 -2
- package/src/successors.ts +39 -23
- 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 +166 -111
- 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
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
// A port of tlapm's Module.Elab: normalization anonymizes a module unit by unit and expands each
|
|
2
|
+
// instance into the units of the module it instantiates.
|
|
3
|
+
|
|
4
|
+
import { TlaProofError, TlapmBugError } from "../errors";
|
|
5
|
+
import { lambdify } from "./action";
|
|
6
|
+
import type { Anonymizer } from "./anonymize";
|
|
7
|
+
import { isEqualHyp } from "./equality";
|
|
8
|
+
import {
|
|
9
|
+
adjoinAll,
|
|
10
|
+
at,
|
|
11
|
+
exprifySequent,
|
|
12
|
+
findNamed,
|
|
13
|
+
getAtPrefix,
|
|
14
|
+
getFact,
|
|
15
|
+
getFresh,
|
|
16
|
+
getLocationText,
|
|
17
|
+
getLocusPrefix,
|
|
18
|
+
getScopeHyps,
|
|
19
|
+
mapAccumulate,
|
|
20
|
+
type Defn,
|
|
21
|
+
type Expr,
|
|
22
|
+
type InstanceDefinition,
|
|
23
|
+
type Locus,
|
|
24
|
+
type Scope,
|
|
25
|
+
type Sequent,
|
|
26
|
+
type Warn,
|
|
27
|
+
} from "./expression";
|
|
28
|
+
import {
|
|
29
|
+
bindTheoremName,
|
|
30
|
+
compareNames,
|
|
31
|
+
getHypSize,
|
|
32
|
+
getUnitHyps,
|
|
33
|
+
substituteUnits,
|
|
34
|
+
type ModuleUnit,
|
|
35
|
+
type Mule,
|
|
36
|
+
} from "./module";
|
|
37
|
+
import { getUnique, type Counter, type Proof } from "./proof";
|
|
38
|
+
import type { createSimplifier } from "./simplify";
|
|
39
|
+
import {
|
|
40
|
+
consAll,
|
|
41
|
+
consSubstitution,
|
|
42
|
+
shift,
|
|
43
|
+
shiftExpr,
|
|
44
|
+
substituteExpr,
|
|
45
|
+
substituteHyp,
|
|
46
|
+
substituteSequent,
|
|
47
|
+
type Substitution,
|
|
48
|
+
} from "./substitution";
|
|
49
|
+
import { getScopeTime } from "./temporal";
|
|
50
|
+
|
|
51
|
+
// latestModules is the module context of the latest anonymization of an axiom, theorem or USE,
|
|
52
|
+
// which tlapm's anonymizer keeps using for the instances inside later definitions.
|
|
53
|
+
export interface Pipeline {
|
|
54
|
+
anonymizer: Anonymizer;
|
|
55
|
+
simplify: ReturnType<typeof createSimplifier>;
|
|
56
|
+
salts: Counter;
|
|
57
|
+
latestModules: Map<string, Mule>;
|
|
58
|
+
onWarning: Warn;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const lambdifyTheorem = (
|
|
62
|
+
pipeline: Pipeline,
|
|
63
|
+
scope: Scope | undefined,
|
|
64
|
+
name: string | undefined,
|
|
65
|
+
sequent: Sequent,
|
|
66
|
+
) => {
|
|
67
|
+
try {
|
|
68
|
+
const lambdified = lambdify(pipeline.anonymizer, pipeline.onWarning, scope, {
|
|
69
|
+
kind: "Sequent",
|
|
70
|
+
sequent,
|
|
71
|
+
});
|
|
72
|
+
if (lambdified.kind !== "Sequent") throw new TlapmBugError();
|
|
73
|
+
return lambdified.sequent;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (!(error instanceof TlaProofError) || error.failure === undefined) throw error;
|
|
76
|
+
const location = sequent.active.location;
|
|
77
|
+
const message = `${error.failure}\nCould not instantiate the theorem ${name === undefined ? "" : `named: ${name}, `}at: ${getLocationText(location)}`;
|
|
78
|
+
pipeline.onWarning({ text: `${getAtPrefix(location)}[ERROR]${message}`, channel: "stdout" });
|
|
79
|
+
pipeline.onWarning({ text: message, channel: "toolboxOnly" });
|
|
80
|
+
return { context: [], active: at({ kind: "Internal", builtin: "TRUE" }, sequent.active) };
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const lambdifyUnit = (pipeline: Pipeline, scope: Scope | undefined, unit: ModuleUnit) => {
|
|
85
|
+
if (unit.kind === "Theorem") {
|
|
86
|
+
return { ...unit, sequent: lambdifyTheorem(pipeline, scope, unit.name, unit.sequent) };
|
|
87
|
+
}
|
|
88
|
+
if (unit.kind !== "Definition") return unit;
|
|
89
|
+
const definition = unit.definition;
|
|
90
|
+
if (definition.kind !== "Operator" && definition.kind !== "Bpragma") return unit;
|
|
91
|
+
const body = lambdify(pipeline.anonymizer, pipeline.onWarning, scope, definition.body);
|
|
92
|
+
return { ...unit, definition: { ...definition, body } };
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// lambdify_enabled_cdot: the ENABLED and \cdot of each definition and theorem statement bind
|
|
96
|
+
// their variables before instantiation substitutes for them. A theorem that cannot be lambdified
|
|
97
|
+
// states TRUE.
|
|
98
|
+
const lambdifyUnits = (
|
|
99
|
+
pipeline: Pipeline,
|
|
100
|
+
scope: Scope | undefined,
|
|
101
|
+
units: ModuleUnit[],
|
|
102
|
+
): [Scope | undefined, ModuleUnit[]] =>
|
|
103
|
+
mapAccumulate(scope, units, (current, unit): [Scope | undefined, ModuleUnit] => {
|
|
104
|
+
if (unit.kind === "Submod") {
|
|
105
|
+
const [inner, body] = lambdifyUnits(pipeline, current, unit.module.body);
|
|
106
|
+
return [inner, { ...unit, module: { ...unit.module, body } }];
|
|
107
|
+
}
|
|
108
|
+
const lambdified = lambdifyUnit(pipeline, current, unit);
|
|
109
|
+
return [adjoinAll(current, getUnitHyps(lambdified)), lambdified];
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// apply_subst: each parameter declaration of the instancee gives way to its substitute.
|
|
113
|
+
const applyParameters = (units: ModuleUnit[], substitutes: Map<string, Expr>) => {
|
|
114
|
+
const body: ModuleUnit[] = [];
|
|
115
|
+
let size = 0;
|
|
116
|
+
let rest = units;
|
|
117
|
+
while (rest.length > 0) {
|
|
118
|
+
const [unit, ...tail] = rest;
|
|
119
|
+
const split =
|
|
120
|
+
unit.kind === "Constants"
|
|
121
|
+
? {
|
|
122
|
+
name: unit.declarations[0].name,
|
|
123
|
+
remaining: { ...unit, declarations: unit.declarations.slice(1) },
|
|
124
|
+
}
|
|
125
|
+
: unit.kind === "Variables"
|
|
126
|
+
? { name: unit.names[0], remaining: { ...unit, names: unit.names.slice(1) } }
|
|
127
|
+
: undefined;
|
|
128
|
+
if (split) {
|
|
129
|
+
const substitute = substitutes.get(split.name);
|
|
130
|
+
if (!substitute) throw new TlaProofError(`Parameter ${split.name} has no substitute`);
|
|
131
|
+
const isEmpty = getHypSize(split.remaining) === 0;
|
|
132
|
+
rest = substituteUnits(
|
|
133
|
+
consSubstitution(shiftExpr(size, substitute), shift(0)),
|
|
134
|
+
isEmpty ? tail : [split.remaining, ...tail],
|
|
135
|
+
);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
body.push(unit);
|
|
139
|
+
size += getHypSize(unit);
|
|
140
|
+
rest = tail;
|
|
141
|
+
}
|
|
142
|
+
return body;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// resub_for: references to the instancee's own units become applications to the instance
|
|
146
|
+
// arguments, which the definitions now bind themselves.
|
|
147
|
+
const getLocalSubstitution = (
|
|
148
|
+
count: number,
|
|
149
|
+
argumentCount: number,
|
|
150
|
+
location: Locus | undefined,
|
|
151
|
+
): Substitution => {
|
|
152
|
+
const args = Array.from({ length: argumentCount }, (_item, index) =>
|
|
153
|
+
at({ kind: "Ix", index: argumentCount - index }, { location }),
|
|
154
|
+
);
|
|
155
|
+
const parameters = Array.from({ length: argumentCount }, (_item, index) =>
|
|
156
|
+
at({ kind: "Ix", index: index + 1 }, { location }),
|
|
157
|
+
);
|
|
158
|
+
const locals = Array.from({ length: count }, (_item, index): Expr => {
|
|
159
|
+
const operator = at({ kind: "Ix", index: index + argumentCount + 1 }, { location });
|
|
160
|
+
return argumentCount > 0 ? at({ kind: "Apply", operator, args }, { location }) : operator;
|
|
161
|
+
});
|
|
162
|
+
return consAll([...locals, ...parameters].reverse(), shift(count + argumentCount));
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const addParameters = (expression: Expr, args: string[]): Expr => {
|
|
166
|
+
const params = args.map((name) => ({ name, shape: 0 }));
|
|
167
|
+
if (expression.kind === "Lambda")
|
|
168
|
+
return { ...expression, params: [...params, ...expression.params] };
|
|
169
|
+
return args.length === 0
|
|
170
|
+
? expression
|
|
171
|
+
: at({ kind: "Lambda", params, body: expression }, expression);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// localize: names the instancee's units under the instance name, salting its local definitions, and
|
|
175
|
+
// abstracts each over the instance arguments.
|
|
176
|
+
const localize = (
|
|
177
|
+
pipeline: Pipeline,
|
|
178
|
+
units: ModuleUnit[],
|
|
179
|
+
prefix: string,
|
|
180
|
+
instance: InstanceDefinition,
|
|
181
|
+
isLocal: boolean,
|
|
182
|
+
location: Locus | undefined,
|
|
183
|
+
) => {
|
|
184
|
+
const getLocalizedName = (name: string) => (prefix === "" ? name : `${prefix}!${name}`);
|
|
185
|
+
const argumentCount = instance.args.length;
|
|
186
|
+
const body: ModuleUnit[] = [];
|
|
187
|
+
let size = 0;
|
|
188
|
+
let rest = units;
|
|
189
|
+
let isComplained = argumentCount === 0;
|
|
190
|
+
const complain = (text: string) => {
|
|
191
|
+
if (isComplained) return;
|
|
192
|
+
isComplained = true;
|
|
193
|
+
pipeline.onWarning({ text, channel: "stderr" });
|
|
194
|
+
};
|
|
195
|
+
while (rest.length > 0) {
|
|
196
|
+
const [unit, ...tail] = rest;
|
|
197
|
+
rest = tail;
|
|
198
|
+
const localized = (expression: Expr) =>
|
|
199
|
+
addParameters(
|
|
200
|
+
substituteExpr(getLocalSubstitution(size, argumentCount, location), expression),
|
|
201
|
+
instance.args,
|
|
202
|
+
);
|
|
203
|
+
switch (unit.kind) {
|
|
204
|
+
case "Definition": {
|
|
205
|
+
const definition = unit.definition;
|
|
206
|
+
if (definition.kind !== "Operator" && definition.kind !== "Bpragma") {
|
|
207
|
+
throw new TlaProofError("Module.Elab.localize");
|
|
208
|
+
}
|
|
209
|
+
const name = unit.isLocal
|
|
210
|
+
? `${definition.name}$${getUnique(pipeline.salts)}`
|
|
211
|
+
: definition.name;
|
|
212
|
+
body.push({
|
|
213
|
+
...unit,
|
|
214
|
+
definition: {
|
|
215
|
+
...definition,
|
|
216
|
+
name: getLocalizedName(name),
|
|
217
|
+
body: localized(definition.body),
|
|
218
|
+
},
|
|
219
|
+
whereDefined: unit.isLocal ? "Builtin" : unit.whereDefined,
|
|
220
|
+
isLocal: unit.isLocal || isLocal,
|
|
221
|
+
});
|
|
222
|
+
size += 1;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
case "Axiom": {
|
|
226
|
+
complain(
|
|
227
|
+
`${getLocusPrefix(location)}Instancing produces parametric axioms.\nSuch axioms will be forcibly hidden and cannot be cited.\n(This warning appears at-most once per INSTANCE declaration.)`,
|
|
228
|
+
);
|
|
229
|
+
const axiom: ModuleUnit = {
|
|
230
|
+
...unit,
|
|
231
|
+
name: unit.name === undefined ? undefined : getLocalizedName(unit.name),
|
|
232
|
+
expression: localized(unit.expression),
|
|
233
|
+
};
|
|
234
|
+
body.push(axiom);
|
|
235
|
+
size += getHypSize(axiom);
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
case "Theorem": {
|
|
239
|
+
complain(
|
|
240
|
+
`${getAtPrefix(location)}Warning: Instancing produces parametric theorems.\nSuch theorems will be forcibly hidden and cannot be cited.\n(This warning appears at-most once per INSTANCE declaration.)`,
|
|
241
|
+
);
|
|
242
|
+
const expression = localized(at(exprifySequent(unit.sequent), unit));
|
|
243
|
+
body.push({
|
|
244
|
+
...unit,
|
|
245
|
+
name: unit.name === undefined ? undefined : getLocalizedName(unit.name),
|
|
246
|
+
sequent:
|
|
247
|
+
expression.kind === "Sequent"
|
|
248
|
+
? expression.sequent
|
|
249
|
+
: { context: [], active: expression },
|
|
250
|
+
proof: { kind: "Omitted", omission: "Elsewhere", location: unit.location },
|
|
251
|
+
});
|
|
252
|
+
size += 1;
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
case "Mutate":
|
|
256
|
+
if (unit.mode === "Use") rest = substituteUnits(shift(-unit.usable.facts.length), rest);
|
|
257
|
+
continue;
|
|
258
|
+
case "Submod":
|
|
259
|
+
continue;
|
|
260
|
+
default:
|
|
261
|
+
throw new TlaProofError("Module.Elab.localize");
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return body;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// localize_axioms: an axiom becomes a hypothesis of each theorem after it, and a named one also a
|
|
268
|
+
// definition.
|
|
269
|
+
const localizeAxioms = (units: ModuleUnit[]) => {
|
|
270
|
+
const body: ModuleUnit[] = [];
|
|
271
|
+
let rest = units;
|
|
272
|
+
while (rest.length > 0) {
|
|
273
|
+
const [unit, ...tail] = rest;
|
|
274
|
+
if (unit.kind !== "Axiom") {
|
|
275
|
+
body.push(unit);
|
|
276
|
+
rest = tail;
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
const location = unit.location;
|
|
280
|
+
if (unit.name !== undefined) {
|
|
281
|
+
body.push({
|
|
282
|
+
kind: "Definition",
|
|
283
|
+
definition: { kind: "Operator", name: unit.name, body: unit.expression, location },
|
|
284
|
+
whereDefined: { kind: "Proof", time: "Always" },
|
|
285
|
+
visibility: "Visible",
|
|
286
|
+
isLocal: false,
|
|
287
|
+
location,
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
const hyp = getFact(
|
|
291
|
+
unit.name === undefined ? shiftExpr(1, unit.expression) : at({ kind: "Ix", index: 2 }, unit),
|
|
292
|
+
"Visible",
|
|
293
|
+
"Always",
|
|
294
|
+
location,
|
|
295
|
+
);
|
|
296
|
+
let distance = 0;
|
|
297
|
+
const inserted = tail.map((next): ModuleUnit => {
|
|
298
|
+
const size = distance;
|
|
299
|
+
distance += getHypSize(next);
|
|
300
|
+
if (next.kind !== "Theorem") return next;
|
|
301
|
+
const sequent = substituteSequent(shift(1), next.sequent);
|
|
302
|
+
return {
|
|
303
|
+
...next,
|
|
304
|
+
sequent: { ...sequent, context: [substituteHyp(shift(size), hyp), ...sequent.context] },
|
|
305
|
+
axiomCount: next.axiomCount + 1,
|
|
306
|
+
};
|
|
307
|
+
});
|
|
308
|
+
rest = substituteUnits(shift(-1), inserted);
|
|
309
|
+
}
|
|
310
|
+
return body;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const getParameters = (module: Mule) =>
|
|
314
|
+
new Set(
|
|
315
|
+
module.body.flatMap((unit) =>
|
|
316
|
+
unit.kind === "Constants"
|
|
317
|
+
? unit.declarations.map((declaration) => declaration.name)
|
|
318
|
+
: unit.kind === "Variables"
|
|
319
|
+
? unit.names
|
|
320
|
+
: [],
|
|
321
|
+
),
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
// Module.Elab.instantiate: the units of an instantiated module, in the context of the instance.
|
|
325
|
+
const instantiate = (
|
|
326
|
+
pipeline: Pipeline,
|
|
327
|
+
modules: Map<string, Mule>,
|
|
328
|
+
scope: Scope | undefined,
|
|
329
|
+
instance: InstanceDefinition,
|
|
330
|
+
isLocal: boolean,
|
|
331
|
+
prefix: string,
|
|
332
|
+
location: Locus | undefined,
|
|
333
|
+
) => {
|
|
334
|
+
const module = modules.get(instance.module);
|
|
335
|
+
if (!module) throw new TlaProofError(`Module "${instance.module}" unknown`);
|
|
336
|
+
const parameters = getParameters(module);
|
|
337
|
+
for (const substitution of instance.substitutions) {
|
|
338
|
+
if (!parameters.has(substitution.name)) {
|
|
339
|
+
throw new TlaProofError(
|
|
340
|
+
`Parameter ${substitution.name} occurs in the statement \`INSTANCE ${instance.module} WITH\`, and is not declared in the module ${instance.module}`,
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const instanceScope = adjoinAll(
|
|
345
|
+
scope,
|
|
346
|
+
instance.args.map((name) => getFresh(name, "Unknown")),
|
|
347
|
+
);
|
|
348
|
+
const substitutes = new Map(
|
|
349
|
+
instance.substitutions.map((entry) => [entry.name, entry.expression]),
|
|
350
|
+
);
|
|
351
|
+
for (const name of [...parameters].sort(compareNames)) {
|
|
352
|
+
if (substitutes.has(name)) continue;
|
|
353
|
+
if (!findNamed(instanceScope, name)) {
|
|
354
|
+
throw new TlaProofError(
|
|
355
|
+
`Required parameter ${name} for module ${instance.module} could not be inferred.`,
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
substitutes.set(name, at({ kind: "Opaque", name }, { location }));
|
|
359
|
+
}
|
|
360
|
+
const anonymized = new Map(
|
|
361
|
+
[...substitutes].map(([name, expression]) => [
|
|
362
|
+
name,
|
|
363
|
+
pipeline.anonymizer.expr(instanceScope, expression),
|
|
364
|
+
]),
|
|
365
|
+
);
|
|
366
|
+
const body = substituteUnits(
|
|
367
|
+
shift((instanceScope?.size ?? 0) - (module.depth ?? 0)),
|
|
368
|
+
module.body.map((unit): ModuleUnit =>
|
|
369
|
+
unit.kind === "Theorem"
|
|
370
|
+
? {
|
|
371
|
+
...unit,
|
|
372
|
+
proof: { kind: "Omitted", omission: "Implicit", location: unit.proof.location },
|
|
373
|
+
}
|
|
374
|
+
: unit,
|
|
375
|
+
),
|
|
376
|
+
);
|
|
377
|
+
const [, lambdified] = lambdifyUnits(pipeline, instanceScope, body);
|
|
378
|
+
return localizeAxioms(
|
|
379
|
+
localize(
|
|
380
|
+
pipeline,
|
|
381
|
+
applyParameters(lambdified, anonymized),
|
|
382
|
+
prefix,
|
|
383
|
+
instance,
|
|
384
|
+
isLocal,
|
|
385
|
+
location,
|
|
386
|
+
),
|
|
387
|
+
);
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
// make_defs: the definitions among the units an INSTANCE inside a LET or DEFINE stands for.
|
|
391
|
+
export const expandInstance = (
|
|
392
|
+
pipeline: Pipeline,
|
|
393
|
+
scope: Scope | undefined,
|
|
394
|
+
definition: Extract<Defn, { kind: "Instance" }>,
|
|
395
|
+
): Defn[] => {
|
|
396
|
+
const name = definition.instance.module;
|
|
397
|
+
if (!pipeline.latestModules.has(name)) {
|
|
398
|
+
pipeline.onWarning({
|
|
399
|
+
text: `${getLocusPrefix(definition.instance.location)}Module ${JSON.stringify(name)} unknown\n`,
|
|
400
|
+
channel: "toolbox",
|
|
401
|
+
});
|
|
402
|
+
throw new TlaProofError(`Module ${JSON.stringify(name)} unknown`, {
|
|
403
|
+
failure: "Module.Elab.anon#defns",
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
const units = instantiate(
|
|
407
|
+
pipeline,
|
|
408
|
+
pipeline.latestModules,
|
|
409
|
+
scope,
|
|
410
|
+
definition.instance,
|
|
411
|
+
true,
|
|
412
|
+
definition.name,
|
|
413
|
+
definition.location,
|
|
414
|
+
);
|
|
415
|
+
const definitions: Defn[] = [];
|
|
416
|
+
let rest = units;
|
|
417
|
+
while (rest.length > 0) {
|
|
418
|
+
const [unit, ...tail] = rest;
|
|
419
|
+
if (unit.kind !== "Definition") {
|
|
420
|
+
rest = substituteUnits(shift(-getHypSize(unit)), tail);
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
definitions.push(unit.definition);
|
|
424
|
+
rest = tail;
|
|
425
|
+
}
|
|
426
|
+
return definitions;
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
// Module.Elab.normalize: anonymizes each unit in the context of the ones before it, expands
|
|
430
|
+
// instances, merges repeated definitions, and simplifies the proofs of important modules. The
|
|
431
|
+
// result also joins the modules that later instances can name.
|
|
432
|
+
export const normalize = (
|
|
433
|
+
pipeline: Pipeline,
|
|
434
|
+
modules: Map<string, Mule>,
|
|
435
|
+
scope: Scope | undefined,
|
|
436
|
+
module: Mule,
|
|
437
|
+
): Mule => {
|
|
438
|
+
const body: ModuleUnit[] = [];
|
|
439
|
+
let current = scope;
|
|
440
|
+
const emit = (unit: ModuleUnit) => {
|
|
441
|
+
body.push(unit);
|
|
442
|
+
current = adjoinAll(current, getUnitHyps(unit));
|
|
443
|
+
};
|
|
444
|
+
const isRedundant = (name: string | undefined) =>
|
|
445
|
+
name !== undefined && findNamed(current, name) !== undefined;
|
|
446
|
+
// Instantiated units arrive anonymized.
|
|
447
|
+
const queue = module.body.map((unit) => ({ unit, isAnonymized: false }));
|
|
448
|
+
for (let index = 0; index < queue.length; index++) {
|
|
449
|
+
const unit = queue[index].unit;
|
|
450
|
+
const expand = (instance: InstanceDefinition, isLocal: boolean, prefix: string) => {
|
|
451
|
+
const units = instantiate(
|
|
452
|
+
pipeline,
|
|
453
|
+
modules,
|
|
454
|
+
current,
|
|
455
|
+
instance,
|
|
456
|
+
isLocal,
|
|
457
|
+
prefix,
|
|
458
|
+
unit.location,
|
|
459
|
+
);
|
|
460
|
+
queue.splice(index + 1, 0, ...units.map((inner) => ({ unit: inner, isAnonymized: true })));
|
|
461
|
+
};
|
|
462
|
+
switch (unit.kind) {
|
|
463
|
+
case "Anoninst":
|
|
464
|
+
expand(unit.instance, unit.isLocal, "");
|
|
465
|
+
continue;
|
|
466
|
+
case "Definition": {
|
|
467
|
+
const definition = unit.definition;
|
|
468
|
+
if (definition.kind === "Instance") {
|
|
469
|
+
expand(definition.instance, unit.isLocal, definition.name);
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
const anonymized =
|
|
473
|
+
definition.kind === "Recursive" || queue[index].isAnonymized
|
|
474
|
+
? definition
|
|
475
|
+
: pipeline.anonymizer.defn(current, definition);
|
|
476
|
+
const normalized: ModuleUnit = { ...unit, definition: anonymized };
|
|
477
|
+
if (definition.kind === "Recursive") {
|
|
478
|
+
emit(normalized);
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
const hyp = getUnitHyps(normalized)[0];
|
|
482
|
+
const found = findNamed(current, definition.name);
|
|
483
|
+
if (found?.hyp.kind === "Defn") {
|
|
484
|
+
const isMerged =
|
|
485
|
+
found.hyp.definition.kind === "Recursive" ||
|
|
486
|
+
isEqualHyp(substituteHyp(shift(found.depth + 1), found.hyp), hyp);
|
|
487
|
+
if (isMerged) {
|
|
488
|
+
const rest = queue.slice(index + 1);
|
|
489
|
+
const substituted = substituteUnits(
|
|
490
|
+
consSubstitution(at({ kind: "Ix", index: found.depth + 1 }, unit), shift(0)),
|
|
491
|
+
rest.map((entry) => entry.unit),
|
|
492
|
+
);
|
|
493
|
+
queue.splice(
|
|
494
|
+
index + 1,
|
|
495
|
+
rest.length,
|
|
496
|
+
...rest.map((entry, offset) => ({ ...entry, unit: substituted[offset] })),
|
|
497
|
+
);
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
emit(normalized);
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
case "Recursives":
|
|
505
|
+
case "Constants":
|
|
506
|
+
case "Variables":
|
|
507
|
+
emit(unit);
|
|
508
|
+
continue;
|
|
509
|
+
case "Axiom":
|
|
510
|
+
if (isRedundant(unit.name)) continue;
|
|
511
|
+
pipeline.latestModules = new Map(modules);
|
|
512
|
+
emit({ ...unit, expression: pipeline.anonymizer.expr(current, unit.expression) });
|
|
513
|
+
continue;
|
|
514
|
+
case "Theorem": {
|
|
515
|
+
const isDuplicate = isRedundant(unit.name);
|
|
516
|
+
const name = isDuplicate ? `(redundant)${unit.name}` : unit.name;
|
|
517
|
+
const proof: Proof = isDuplicate
|
|
518
|
+
? { kind: "Obvious", location: unit.proof.location }
|
|
519
|
+
: unit.proof;
|
|
520
|
+
pipeline.latestModules = new Map(modules);
|
|
521
|
+
const sequent = pipeline.anonymizer.sequent(current, unit.sequent);
|
|
522
|
+
const binding = bindTheoremName(name, sequent, unit.location);
|
|
523
|
+
const proofScope = adjoinAll(
|
|
524
|
+
adjoinAll(
|
|
525
|
+
current,
|
|
526
|
+
binding.hyps.map((hyp) => ({ ...hyp, isConstnessUnset: true })),
|
|
527
|
+
),
|
|
528
|
+
binding.sequent.context,
|
|
529
|
+
);
|
|
530
|
+
const anonymized = pipeline.anonymizer.proof(proofScope, proof);
|
|
531
|
+
const simplified = module.isImportant
|
|
532
|
+
? pipeline.simplify(
|
|
533
|
+
getScopeHyps(proofScope),
|
|
534
|
+
binding.sequent.active,
|
|
535
|
+
anonymized,
|
|
536
|
+
getScopeTime(binding.sequent.context, "Always"),
|
|
537
|
+
)
|
|
538
|
+
: anonymized;
|
|
539
|
+
emit({ ...unit, name, sequent, proof: simplified });
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
case "Mutate":
|
|
543
|
+
pipeline.latestModules = new Map(modules);
|
|
544
|
+
emit({ ...unit, usable: pipeline.anonymizer.usable(current, unit.usable) });
|
|
545
|
+
continue;
|
|
546
|
+
case "Submod":
|
|
547
|
+
emit({ ...unit, module: normalize(pipeline, modules, current, unit.module) });
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
const normalized = { ...module, body, depth: scope?.size ?? 0 };
|
|
552
|
+
modules.set(module.name, normalized);
|
|
553
|
+
return normalized;
|
|
554
|
+
};
|