tla-ts 0.0.4-dev.0be9567 → 0.0.4-dev.22c041b
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 +77 -122
- 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
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
// A port of tlapm's obligation generation (Proof.Gen and Module.Gen): leaf proofs become obligations
|
|
2
|
+
// whose context is everything the proof may use at that point.
|
|
3
|
+
|
|
4
|
+
import { TlapmBugError, TlaProofError } from "../errors";
|
|
5
|
+
import { isEqualExpr } from "./equality";
|
|
6
|
+
import {
|
|
7
|
+
at,
|
|
8
|
+
exprifySequent,
|
|
9
|
+
getErrorNote,
|
|
10
|
+
getFact,
|
|
11
|
+
isBuiltinApply,
|
|
12
|
+
mapAccumulate,
|
|
13
|
+
type Expr,
|
|
14
|
+
type Hyp,
|
|
15
|
+
type Locus,
|
|
16
|
+
type Sequent,
|
|
17
|
+
type Time,
|
|
18
|
+
type Visibility,
|
|
19
|
+
type Warn,
|
|
20
|
+
} from "./expression";
|
|
21
|
+
import { bindTheoremName, getUnitHyps, type Mule } from "./module";
|
|
22
|
+
import type { OldMethod } from "./pragma";
|
|
23
|
+
import {
|
|
24
|
+
getStepName,
|
|
25
|
+
type Obligation,
|
|
26
|
+
type ObligationKind,
|
|
27
|
+
type Proof,
|
|
28
|
+
type Step,
|
|
29
|
+
type StepNumber,
|
|
30
|
+
type UseDef,
|
|
31
|
+
type Usable,
|
|
32
|
+
} from "./proof";
|
|
33
|
+
import { shiftExpr } from "./substitution";
|
|
34
|
+
import { getScopeTime } from "./temporal";
|
|
35
|
+
|
|
36
|
+
export const AT_NOWHERE: Expr = { kind: "At", isExcept: false };
|
|
37
|
+
|
|
38
|
+
const isAnonymous = (step: StepNumber | undefined) => step?.kind === "Named" && step.isAnonymous;
|
|
39
|
+
|
|
40
|
+
export const getTrue = (from: { location?: Locus }) =>
|
|
41
|
+
at({ kind: "Internal", builtin: "TRUE" }, from);
|
|
42
|
+
|
|
43
|
+
// Each visible fact of the sequent, shifted past the hypotheses after it.
|
|
44
|
+
const getAssumedFacts = (offset: number, sequent: Sequent) =>
|
|
45
|
+
sequent.context.flatMap((hyp, index) =>
|
|
46
|
+
hyp.kind === "Fact" && hyp.visibility === "Visible"
|
|
47
|
+
? [shiftExpr(offset + sequent.context.length - 1 - index, hyp.expression)]
|
|
48
|
+
: [],
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const getStepDefinition = (step: Step, body: Expr, time: Time): Hyp => {
|
|
52
|
+
if (!step.step) throw new TlapmBugError();
|
|
53
|
+
return {
|
|
54
|
+
kind: "Defn",
|
|
55
|
+
definition: { kind: "Operator", name: getStepName(step.step), body, location: step.location },
|
|
56
|
+
whereDefined: { kind: "Proof", time },
|
|
57
|
+
visibility: "Visible",
|
|
58
|
+
isLocal: true,
|
|
59
|
+
location: step.location,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// The proof of an assertion leaves the always scope when the assertion assumes a fact that holds
|
|
64
|
+
// only now.
|
|
65
|
+
export const proveAssertion = (context: Hyp[], sequent: Sequent, step: Step, time: Time) => {
|
|
66
|
+
const visibility: Visibility = isAnonymous(step.step) ? "Visible" : "Hidden";
|
|
67
|
+
const hyps = sequent.context.map((hyp): Hyp =>
|
|
68
|
+
hyp.kind === "Fact" ? { ...hyp, visibility } : hyp,
|
|
69
|
+
);
|
|
70
|
+
const body = at({ kind: "List", bullet: "Refs", items: getAssumedFacts(2, sequent) }, step);
|
|
71
|
+
const scopeTime = getScopeTime(sequent.context, time);
|
|
72
|
+
return {
|
|
73
|
+
context: [
|
|
74
|
+
...context,
|
|
75
|
+
...hyps,
|
|
76
|
+
getFact(getTrue(step), "Hidden", time, step.location),
|
|
77
|
+
getStepDefinition(step, body, scopeTime),
|
|
78
|
+
getFact(at({ kind: "Ix", index: 1 }, step), "Hidden", scopeTime, step.location),
|
|
79
|
+
],
|
|
80
|
+
active: shiftExpr(3, sequent.active),
|
|
81
|
+
time: scopeTime,
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const useAssertion = (
|
|
86
|
+
isSuffices: boolean,
|
|
87
|
+
context: Hyp[],
|
|
88
|
+
goal: Expr,
|
|
89
|
+
sequent: Sequent,
|
|
90
|
+
step: Step,
|
|
91
|
+
time: Time,
|
|
92
|
+
) => {
|
|
93
|
+
const visibility: Visibility = isSuffices || isAnonymous(step.step) ? "Visible" : "Hidden";
|
|
94
|
+
return {
|
|
95
|
+
context: [
|
|
96
|
+
...context,
|
|
97
|
+
getStepDefinition(step, at(exprifySequent(sequent), step), time),
|
|
98
|
+
getFact(at({ kind: "Ix", index: 1 }, step), visibility, time, step.location),
|
|
99
|
+
],
|
|
100
|
+
active: shiftExpr(2, goal),
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// A cited step or definition keeps the scope it was proved in, and any other fact takes the
|
|
105
|
+
// current one.
|
|
106
|
+
const getFactTime = (context: Hyp[], fact: Expr, time: Time): Time => {
|
|
107
|
+
if (fact.kind !== "Ix") return time;
|
|
108
|
+
const hyp = context[context.length - fact.index];
|
|
109
|
+
if (hyp?.kind === "Fact") return hyp.time;
|
|
110
|
+
return hyp?.kind === "Defn" && typeof hyp.whereDefined === "object"
|
|
111
|
+
? hyp.whereDefined.time
|
|
112
|
+
: "Always";
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const setDefinition = (visibility: Visibility, context: Hyp[], def: UseDef): Hyp[] => {
|
|
116
|
+
if (def.kind !== "Dx") throw new TlaProofError(`Unknown definition ${def.name}`);
|
|
117
|
+
const index = context.length - def.index;
|
|
118
|
+
const hyp = context[index];
|
|
119
|
+
if (!hyp) return context;
|
|
120
|
+
if (hyp.kind !== "Defn") throw new TlaProofError("Indicated point is not a definition");
|
|
121
|
+
return context.map((entry, position) => (position === index ? { ...hyp, visibility } : entry));
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const isDomainMatch = (fact: Expr, domain: Expr) =>
|
|
125
|
+
isBuiltinApply(fact, "Mem") &&
|
|
126
|
+
fact.args[0]?.kind === "Ix" &&
|
|
127
|
+
fact.args[0].index === 0 &&
|
|
128
|
+
isEqualExpr(domain, fact.args[1]);
|
|
129
|
+
|
|
130
|
+
const setExpression = (
|
|
131
|
+
onWarning: Warn,
|
|
132
|
+
visibility: Visibility,
|
|
133
|
+
fact: Expr,
|
|
134
|
+
context: Hyp[],
|
|
135
|
+
): Hyp[] => {
|
|
136
|
+
let isFound = false;
|
|
137
|
+
let current = fact;
|
|
138
|
+
const result = [...context];
|
|
139
|
+
for (let index = context.length - 1; index >= 0; index--) {
|
|
140
|
+
current = shiftExpr(-1, current);
|
|
141
|
+
const hyp = context[index];
|
|
142
|
+
if (hyp.kind === "Fact" && isEqualExpr(hyp.expression, current)) {
|
|
143
|
+
isFound = true;
|
|
144
|
+
result[index] = { ...hyp, visibility };
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (hyp.kind === "Fresh" && hyp.domain && isDomainMatch(current, hyp.domain)) {
|
|
148
|
+
isFound = true;
|
|
149
|
+
result[index] = { ...hyp, domainVisibility: visibility };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (!isFound) {
|
|
153
|
+
const message = "This expression does not appear in the context and cannot be hidden.";
|
|
154
|
+
onWarning(getErrorNote(fact.location, `${message}\n`));
|
|
155
|
+
throw new TlaProofError(message, { failure: "proof.Gen.set_expr" });
|
|
156
|
+
}
|
|
157
|
+
return result;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// The lines of tlapm's --toolbox and --line options, which select the proofs to generate.
|
|
161
|
+
export interface LineRange {
|
|
162
|
+
start: number;
|
|
163
|
+
end: number;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const obligate = (
|
|
167
|
+
sequent: Sequent,
|
|
168
|
+
from: { location?: Locus; method?: OldMethod },
|
|
169
|
+
kind: ObligationKind,
|
|
170
|
+
): Obligation => ({ sequent, location: from.location, kind, method: from.method });
|
|
171
|
+
|
|
172
|
+
interface ProofSummary {
|
|
173
|
+
total: number;
|
|
174
|
+
absent: Locus[];
|
|
175
|
+
omitted: Locus[];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const EMPTY_SUMMARY: ProofSummary = { total: 0, absent: [], omitted: [] };
|
|
179
|
+
|
|
180
|
+
const joinSummaries = (left: ProofSummary, right: ProofSummary): ProofSummary => ({
|
|
181
|
+
total: left.total + right.total,
|
|
182
|
+
absent: [...left.absent, ...right.absent],
|
|
183
|
+
omitted: [...left.omitted, ...right.omitted],
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const getStepSummary = (step: Step): ProofSummary => {
|
|
187
|
+
if (step.kind === "Use") return { ...EMPTY_SUMMARY, total: step.obligations?.length ?? 0 };
|
|
188
|
+
return "proof" in step ? getProofSummary(step.proof) : EMPTY_SUMMARY;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const getProofSummary = (proof: Proof): ProofSummary => {
|
|
192
|
+
if (proof.kind === "Steps") {
|
|
193
|
+
return [...proof.steps.map(getStepSummary), getProofSummary(proof.qed.proof)].reduce(
|
|
194
|
+
joinSummaries,
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
if (proof.kind !== "Omitted" || !proof.obligations || !proof.location)
|
|
198
|
+
return { ...EMPTY_SUMMARY, total: proof.obligations?.length ?? 0 };
|
|
199
|
+
return {
|
|
200
|
+
total: proof.obligations.length,
|
|
201
|
+
absent: proof.omission === "Implicit" ? [proof.location] : [],
|
|
202
|
+
omitted: proof.omission === "Explicit" ? [proof.location] : [],
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export interface TheoremSummary extends ProofSummary {
|
|
207
|
+
location: Locus | undefined;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export interface ModuleSummary extends ProofSummary {
|
|
211
|
+
theorems: TheoremSummary[];
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export const createGenerator = (inputFiles: Set<string>, lines: LineRange, onWarning: Warn) => {
|
|
215
|
+
const generate = (sequent: Sequent, proof: Proof, time: Time): Proof => {
|
|
216
|
+
const location = proof.location;
|
|
217
|
+
if (
|
|
218
|
+
!location ||
|
|
219
|
+
!inputFiles.has(location.file) ||
|
|
220
|
+
location.endLine < lines.start ||
|
|
221
|
+
location.startLine > lines.end
|
|
222
|
+
)
|
|
223
|
+
return proof;
|
|
224
|
+
switch (proof.kind) {
|
|
225
|
+
case "Obvious":
|
|
226
|
+
return { ...proof, obligations: [obligate(sequent, proof, { kind: "Main" })] };
|
|
227
|
+
case "Omitted":
|
|
228
|
+
return {
|
|
229
|
+
...proof,
|
|
230
|
+
obligations: [obligate(sequent, proof, { kind: "Omitted", omission: proof.omission })],
|
|
231
|
+
};
|
|
232
|
+
case "Error":
|
|
233
|
+
return {
|
|
234
|
+
...proof,
|
|
235
|
+
obligations: [obligate(sequent, proof, { kind: "Error", message: proof.message })],
|
|
236
|
+
};
|
|
237
|
+
case "By":
|
|
238
|
+
throw new TlaProofError("Proof.Gen.generate");
|
|
239
|
+
case "Steps": {
|
|
240
|
+
const [inner, steps] = mapAccumulate({ sequent, time }, proof.steps, (state, step) => {
|
|
241
|
+
const [next, generated, nextTime] = generateStep(state.sequent, step, state.time);
|
|
242
|
+
return [{ sequent: next, time: nextTime }, generated];
|
|
243
|
+
});
|
|
244
|
+
const qedProof = generate(inner.sequent, proof.qed.proof, inner.time);
|
|
245
|
+
return { ...proof, steps, qed: { ...proof.qed, proof: qedProof } };
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const generateStep = (sequent: Sequent, step: Step, time: Time): [Sequent, Step, Time] => {
|
|
251
|
+
switch (step.kind) {
|
|
252
|
+
case "Forget": {
|
|
253
|
+
const count = sequent.context.length;
|
|
254
|
+
const context = sequent.context.map((hyp, index): Hyp =>
|
|
255
|
+
hyp.kind === "Fact" && hyp.visibility === "Visible" && step.count + index < count
|
|
256
|
+
? { ...hyp, visibility: "Hidden" }
|
|
257
|
+
: hyp,
|
|
258
|
+
);
|
|
259
|
+
return [{ ...sequent, context }, step, time];
|
|
260
|
+
}
|
|
261
|
+
case "Use": {
|
|
262
|
+
const usable = step.usable;
|
|
263
|
+
if (usable.defs.length === 0 && usable.facts.length === 1) {
|
|
264
|
+
const fact = usable.facts[0];
|
|
265
|
+
const obligation = obligate({ ...sequent, active: fact }, step, { kind: "Support" });
|
|
266
|
+
return [
|
|
267
|
+
{
|
|
268
|
+
context: [
|
|
269
|
+
...sequent.context,
|
|
270
|
+
{
|
|
271
|
+
...getFact(
|
|
272
|
+
fact,
|
|
273
|
+
"Visible",
|
|
274
|
+
getFactTime(sequent.context, fact, time),
|
|
275
|
+
fact.location,
|
|
276
|
+
),
|
|
277
|
+
useLocation: step.useLocation,
|
|
278
|
+
},
|
|
279
|
+
],
|
|
280
|
+
active: shiftExpr(1, sequent.active),
|
|
281
|
+
},
|
|
282
|
+
{ ...step, obligations: [obligation] },
|
|
283
|
+
time,
|
|
284
|
+
];
|
|
285
|
+
}
|
|
286
|
+
if (usable.facts.length > 0)
|
|
287
|
+
throw new TlaProofError("Proof.Gen.gen_step: USE with facts and definitions");
|
|
288
|
+
const context = usable.defs.reduce(
|
|
289
|
+
(current, def) => setDefinition("Visible", current, def),
|
|
290
|
+
sequent.context,
|
|
291
|
+
);
|
|
292
|
+
return [{ ...sequent, context }, step, time];
|
|
293
|
+
}
|
|
294
|
+
case "Hide": {
|
|
295
|
+
const hidden = step.usable.defs.reduce(
|
|
296
|
+
(current, def) => setDefinition("Hidden", current, def),
|
|
297
|
+
sequent.context,
|
|
298
|
+
);
|
|
299
|
+
const context = step.usable.facts.reduceRight(
|
|
300
|
+
(current, fact) => setExpression(onWarning, "Hidden", fact, current),
|
|
301
|
+
hidden,
|
|
302
|
+
);
|
|
303
|
+
return [{ ...sequent, context }, step, time];
|
|
304
|
+
}
|
|
305
|
+
case "Define":
|
|
306
|
+
return [
|
|
307
|
+
{
|
|
308
|
+
context: [
|
|
309
|
+
...sequent.context,
|
|
310
|
+
...step.definitions.map((definition): Hyp => ({
|
|
311
|
+
kind: "Defn",
|
|
312
|
+
definition,
|
|
313
|
+
whereDefined: "User",
|
|
314
|
+
visibility: "Visible",
|
|
315
|
+
isLocal: true,
|
|
316
|
+
location: definition.location,
|
|
317
|
+
})),
|
|
318
|
+
],
|
|
319
|
+
active: shiftExpr(step.definitions.length, sequent.active),
|
|
320
|
+
},
|
|
321
|
+
step,
|
|
322
|
+
time,
|
|
323
|
+
];
|
|
324
|
+
case "Assert": {
|
|
325
|
+
const inner = proveAssertion(sequent.context, step.sequent, step, time);
|
|
326
|
+
const proof = generate(inner, step.proof, inner.time);
|
|
327
|
+
const generated: Step = { ...step, proof };
|
|
328
|
+
return [
|
|
329
|
+
useAssertion(false, sequent.context, sequent.active, step.sequent, generated, time),
|
|
330
|
+
generated,
|
|
331
|
+
time,
|
|
332
|
+
];
|
|
333
|
+
}
|
|
334
|
+
case "Suffices": {
|
|
335
|
+
const proof = generate(
|
|
336
|
+
useAssertion(true, sequent.context, sequent.active, step.sequent, step, time),
|
|
337
|
+
step.proof,
|
|
338
|
+
time,
|
|
339
|
+
);
|
|
340
|
+
const generated: Step = { ...step, proof };
|
|
341
|
+
const next = proveAssertion(sequent.context, step.sequent, generated, time);
|
|
342
|
+
return [next, generated, next.time];
|
|
343
|
+
}
|
|
344
|
+
default:
|
|
345
|
+
throw new TlaProofError("Proof.Gen.gen_step");
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const mutateOne = (
|
|
350
|
+
context: Hyp[],
|
|
351
|
+
mode: "Use" | "Hide",
|
|
352
|
+
usable: Usable,
|
|
353
|
+
location: Locus | undefined,
|
|
354
|
+
): [Hyp[], Obligation[]] => {
|
|
355
|
+
const step: StepNumber = { kind: "Unnamed", level: 0, id: 0 };
|
|
356
|
+
const [sequent, generated] = generateStep(
|
|
357
|
+
{ context, active: { ...AT_NOWHERE, location } },
|
|
358
|
+
mode === "Use"
|
|
359
|
+
? { kind: "Use", usable, isOnly: false, location, step, useLocation: location }
|
|
360
|
+
: { kind: "Hide", usable, location, step },
|
|
361
|
+
"Always",
|
|
362
|
+
);
|
|
363
|
+
return [sequent.context, generated.obligations ?? []];
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
// The definitions go first, then each fact on its own, shifting the facts after it.
|
|
367
|
+
const mutate = (
|
|
368
|
+
context: Hyp[],
|
|
369
|
+
mode: "Use" | "Hide",
|
|
370
|
+
usable: Usable,
|
|
371
|
+
location: Locus | undefined,
|
|
372
|
+
): [Hyp[], Obligation[]] => {
|
|
373
|
+
if (usable.defs.length === 0 && usable.facts.length === 0) return [context, []];
|
|
374
|
+
const isDefs = usable.defs.length > 0;
|
|
375
|
+
const [fact, ...facts] = usable.facts;
|
|
376
|
+
const [next, first] = mutateOne(
|
|
377
|
+
context,
|
|
378
|
+
mode,
|
|
379
|
+
isDefs ? { defs: usable.defs, facts: [] } : { defs: [], facts: [fact] },
|
|
380
|
+
location,
|
|
381
|
+
);
|
|
382
|
+
const rest = isDefs ? usable.facts : facts.map((inner) => shiftExpr(1, inner));
|
|
383
|
+
const [last, others] = mutate(next, mode, { defs: [], facts: rest }, location);
|
|
384
|
+
return [last, [...first, ...others]];
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
// collect: a QED's obligations come before its sibling steps', and a step's own before its proof's.
|
|
388
|
+
const collect = (proof: Proof): Obligation[] => {
|
|
389
|
+
const obligations: Obligation[] = [];
|
|
390
|
+
const visitProof = (item: Proof) => {
|
|
391
|
+
if (item.kind === "Steps") {
|
|
392
|
+
visitProof(item.qed.proof);
|
|
393
|
+
item.steps.forEach(visitStep);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (item.obligations) obligations.push(...item.obligations);
|
|
397
|
+
};
|
|
398
|
+
const visitStep = (step: Step) => {
|
|
399
|
+
if (step.kind === "Use" && step.obligations) obligations.push(...step.obligations);
|
|
400
|
+
if ("proof" in step) visitProof(step.proof);
|
|
401
|
+
};
|
|
402
|
+
visitProof(proof);
|
|
403
|
+
return obligations;
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
// Module.Gen.generate.
|
|
407
|
+
const generateModule = (
|
|
408
|
+
context: Hyp[],
|
|
409
|
+
module: Mule,
|
|
410
|
+
): { obligations: Obligation[]; summary: ModuleSummary } => {
|
|
411
|
+
const obligations: Obligation[] = [];
|
|
412
|
+
const theorems: TheoremSummary[] = [];
|
|
413
|
+
let summary = EMPTY_SUMMARY;
|
|
414
|
+
let current = context;
|
|
415
|
+
for (const unit of module.body) {
|
|
416
|
+
switch (unit.kind) {
|
|
417
|
+
case "Theorem": {
|
|
418
|
+
const binding = bindTheoremName(unit.name, unit.sequent, unit.location);
|
|
419
|
+
const named = [...current, ...binding.hyps];
|
|
420
|
+
const context = [...named, ...binding.sequent.context];
|
|
421
|
+
const proof = generate(
|
|
422
|
+
{ context, active: binding.sequent.active },
|
|
423
|
+
unit.proof,
|
|
424
|
+
getScopeTime(context, "Always"),
|
|
425
|
+
);
|
|
426
|
+
obligations.push(...collect(proof));
|
|
427
|
+
const theorem = getProofSummary(proof);
|
|
428
|
+
theorems.push({ ...theorem, location: unit.location });
|
|
429
|
+
summary = joinSummaries(summary, theorem);
|
|
430
|
+
const fact: Expr =
|
|
431
|
+
unit.name === undefined
|
|
432
|
+
? at(exprifySequent(unit.sequent), unit)
|
|
433
|
+
: { kind: "Ix", index: 1, location: unit.location };
|
|
434
|
+
current = [...named, getFact(fact, "Hidden", "Always", unit.location)];
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
case "Submod": {
|
|
438
|
+
const generated = generateModule(current, unit.module);
|
|
439
|
+
obligations.push(...generated.obligations);
|
|
440
|
+
summary = joinSummaries(summary, generated.summary);
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
case "Mutate": {
|
|
444
|
+
const [next, generated] = mutate(current, unit.mode, unit.usable, unit.location);
|
|
445
|
+
obligations.push(...generated);
|
|
446
|
+
current = next;
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
default:
|
|
450
|
+
current = [...current, ...getUnitHyps(unit)];
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return { obligations, summary: { ...summary, theorems } };
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
return generateModule;
|
|
457
|
+
};
|
|
@@ -1,37 +1,34 @@
|
|
|
1
1
|
// Generates the proof obligations tlapm prints for a module, in tlapm's order and layout.
|
|
2
2
|
|
|
3
|
-
import { TlaProofError, TlaSyntaxError, type SyntaxFailure } from "
|
|
4
|
-
import { createAnonymizer } from "./
|
|
3
|
+
import { TlaProofError, TlaSyntaxError, type SyntaxFailure } from "../errors";
|
|
4
|
+
import { createAnonymizer } from "./anonymize";
|
|
5
5
|
import {
|
|
6
6
|
getAtPrefix,
|
|
7
7
|
getErrorNote,
|
|
8
8
|
getLocusPosition,
|
|
9
9
|
getLocusPrefix,
|
|
10
10
|
type Locus,
|
|
11
|
-
type
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
type Warn,
|
|
12
|
+
type Sequent,
|
|
13
|
+
} from "./expression";
|
|
14
14
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
flatten,
|
|
18
|
-
generate,
|
|
19
|
-
getDependencies,
|
|
20
|
-
normalize,
|
|
21
|
-
STANDARD_MODULES,
|
|
15
|
+
createGenerator,
|
|
16
|
+
type LineRange,
|
|
22
17
|
type ModuleSummary,
|
|
23
|
-
type Mule,
|
|
24
18
|
type TheoremSummary,
|
|
25
|
-
|
|
26
|
-
} from "./
|
|
27
|
-
import {
|
|
28
|
-
import
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import
|
|
19
|
+
} from "./generate";
|
|
20
|
+
import { compareNames, flatten, getDependencies, STANDARD_MODULES, type Mule } from "./module";
|
|
21
|
+
import { expandInstance, normalize, type Pipeline } from "./normalize";
|
|
22
|
+
import { formatObligation } from "./printer";
|
|
23
|
+
import type { Counter, ObligationKind } from "./proof";
|
|
24
|
+
import type { OldMethod } from "./pragma";
|
|
25
|
+
import { createSimplifier } from "./simplify";
|
|
26
|
+
import { createSource } from "./source";
|
|
27
|
+
import { tokenize } from "../lexer";
|
|
28
|
+
import { parseTlapmModule } from "../parser";
|
|
29
|
+
import type { Module } from "../ast";
|
|
33
30
|
|
|
34
|
-
|
|
31
|
+
interface ObligationSource {
|
|
35
32
|
file: string;
|
|
36
33
|
source: string;
|
|
37
34
|
}
|
|
@@ -39,7 +36,11 @@ export interface ObligationSource {
|
|
|
39
36
|
export interface PrintedObligation {
|
|
40
37
|
id: number;
|
|
41
38
|
location: string;
|
|
39
|
+
locus: Locus | undefined;
|
|
42
40
|
text: string;
|
|
41
|
+
kind: ObligationKind;
|
|
42
|
+
sequent: Sequent;
|
|
43
|
+
method?: OldMethod;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
export interface ModuleObligations {
|
|
@@ -53,7 +54,7 @@ export const WHOLE_MODULE: LineRange = { start: 0, end: Infinity };
|
|
|
53
54
|
|
|
54
55
|
interface ObligationOptions {
|
|
55
56
|
lines?: LineRange;
|
|
56
|
-
onWarning?:
|
|
57
|
+
onWarning?: Warn;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
const MODULE_HEADER = /-{4,} *MODULE/;
|
|
@@ -87,7 +88,7 @@ const findTab = (source: string) => {
|
|
|
87
88
|
return { offset, line, column, end };
|
|
88
89
|
};
|
|
89
90
|
|
|
90
|
-
const
|
|
91
|
+
const catchSyntaxFailure = <Value>(read: () => Value): Value | SyntaxFailure => {
|
|
91
92
|
try {
|
|
92
93
|
return read();
|
|
93
94
|
} catch (error) {
|
|
@@ -100,9 +101,11 @@ const isSyntaxFailure = (value: unknown): value is SyntaxFailure =>
|
|
|
100
101
|
typeof value === "object" && value !== null && "reason" in value;
|
|
101
102
|
|
|
102
103
|
const parseSource = (source: string): Module | SyntaxFailure[] => {
|
|
103
|
-
const tab =
|
|
104
|
+
const tab = catchSyntaxFailure(() => findTab(source));
|
|
104
105
|
if (isSyntaxFailure(tab)) return [tab];
|
|
105
|
-
const parsed =
|
|
106
|
+
const parsed = catchSyntaxFailure(() =>
|
|
107
|
+
parseTlapmModule(tab ? source.slice(0, tab.offset) : source),
|
|
108
|
+
);
|
|
106
109
|
if (tab && (!isSyntaxFailure(parsed) || parsed.isEnd)) {
|
|
107
110
|
return [
|
|
108
111
|
{
|
|
@@ -122,8 +125,8 @@ const loadMule = (
|
|
|
122
125
|
input: ObligationSource,
|
|
123
126
|
counter: Counter,
|
|
124
127
|
isMain: boolean,
|
|
125
|
-
onWarning:
|
|
126
|
-
|
|
128
|
+
onWarning: Warn,
|
|
129
|
+
errorPrefix: string,
|
|
127
130
|
): Mule => {
|
|
128
131
|
if (!MODULE_HEADER.test(input.source)) throw new TlaProofError("No tokens in file");
|
|
129
132
|
const parsed = parseSource(input.source);
|
|
@@ -134,7 +137,7 @@ const loadMule = (
|
|
|
134
137
|
onWarning({ text: `${text}\n`, channel: "toolboxOnly" });
|
|
135
138
|
});
|
|
136
139
|
const message = `Could not parse ${JSON.stringify(input.file)} successfully.`;
|
|
137
|
-
onWarning({ text: `${
|
|
140
|
+
onWarning({ text: `${errorPrefix}Error: ${message}`, channel: "stderr" });
|
|
138
141
|
throw new TlaProofError(message, { failure: "Module.Parser.parse_file" });
|
|
139
142
|
}
|
|
140
143
|
const mule = createSource(input.file, input.source, counter, isMain).convertModule(parsed);
|
|
@@ -280,7 +283,7 @@ export const getObligations = (
|
|
|
280
283
|
(scope, definition) => expandInstance(pipeline, scope, definition),
|
|
281
284
|
onWarning,
|
|
282
285
|
),
|
|
283
|
-
|
|
286
|
+
simplify: createSimplifier(counter),
|
|
284
287
|
salts: { value: 0 },
|
|
285
288
|
latestModules: new Map(),
|
|
286
289
|
onWarning,
|
|
@@ -288,13 +291,14 @@ export const getObligations = (
|
|
|
288
291
|
const order = schedule(modules).map((module) =>
|
|
289
292
|
module.isStandard ? module : flatten(modules, module, new Set()),
|
|
290
293
|
);
|
|
294
|
+
const generateModule = createGenerator(new Set(mains.map((main) => main.file)), lines, onWarning);
|
|
291
295
|
// Instances see each module as flattened, and as normalized once its turn has come.
|
|
292
296
|
const normalized = new Map(order.map((module) => [module.name, module]));
|
|
293
297
|
return order.flatMap((module): ModuleObligations[] => {
|
|
294
298
|
if (module.isStandard) return [];
|
|
295
299
|
const result = normalize(pipeline, normalized, undefined, module);
|
|
296
300
|
if (!module.isImportant) return [];
|
|
297
|
-
const generated =
|
|
301
|
+
const generated = generateModule([], result);
|
|
298
302
|
// tlapm numbers the obligations, then drops the omitted ones and those outside the lines.
|
|
299
303
|
const obligations = generated.obligations.flatMap((obligation, index): PrintedObligation[] => {
|
|
300
304
|
const location = obligation.location;
|
|
@@ -307,7 +311,17 @@ export const getObligations = (
|
|
|
307
311
|
obligation.kind.kind === "Error"
|
|
308
312
|
? obligation.kind.message
|
|
309
313
|
: `${formatObligation(obligation.sequent)}\n`;
|
|
310
|
-
return [
|
|
314
|
+
return [
|
|
315
|
+
{
|
|
316
|
+
id: index + 1,
|
|
317
|
+
location: formatLocus(location),
|
|
318
|
+
locus: location,
|
|
319
|
+
text,
|
|
320
|
+
kind: obligation.kind,
|
|
321
|
+
sequent: obligation.sequent,
|
|
322
|
+
method: obligation.method,
|
|
323
|
+
},
|
|
324
|
+
];
|
|
311
325
|
});
|
|
312
326
|
return [
|
|
313
327
|
{ name: module.name, location: module.location, obligations, summary: generated.summary },
|