tla-ts 0.0.4-dev.fa107ef → 0.0.5-dev.cc59f31
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 +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 +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 +21 -22
- 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 +154 -105
- 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,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
interface OptionSpec {
|
|
2
2
|
flag: string;
|
|
3
|
-
isRequired?: boolean;
|
|
4
3
|
isRepeatable?: boolean;
|
|
5
4
|
// How many of the arguments after the flag the option takes, when that depends on them.
|
|
6
5
|
getArity?: (rest: string[]) => number;
|
|
7
6
|
}
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
interface ParsedOption {
|
|
10
9
|
name: string;
|
|
11
10
|
values: string[];
|
|
12
11
|
}
|
|
@@ -20,11 +19,6 @@ export interface ParsedArgs {
|
|
|
20
19
|
get: (name: string) => string[] | undefined;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
const formatOption = (spec: OptionSpec) => {
|
|
24
|
-
const text = spec.isRequired ? spec.flag : `[${spec.flag}]`;
|
|
25
|
-
return spec.isRepeatable ? `${text}...` : text;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
22
|
// Each <name> in a flag such as "--toolbox <start> <end>" is one value the option takes, and
|
|
29
23
|
// {options} in the usage stands for the options.
|
|
30
24
|
export const defineCommand = (usage: string, specs: OptionSpec[]) => {
|
|
@@ -60,5 +54,56 @@ export const defineCommand = (usage: string, specs: OptionSpec[]) => {
|
|
|
60
54
|
get: (name) => options.findLast((option) => option.name === name)?.values,
|
|
61
55
|
};
|
|
62
56
|
};
|
|
63
|
-
return {
|
|
57
|
+
return {
|
|
58
|
+
usage: usage.replace(
|
|
59
|
+
"{options}",
|
|
60
|
+
specs.map((spec) => `[${spec.flag}]${spec.isRepeatable ? "..." : ""}`).join(" "),
|
|
61
|
+
),
|
|
62
|
+
parse,
|
|
63
|
+
};
|
|
64
64
|
};
|
|
65
|
+
|
|
66
|
+
export const CHECK_COMMAND = defineCommand("tla-ts <Spec.tla|Spec.cfg|glob>... {options}", [
|
|
67
|
+
{ flag: "-config <Spec.cfg>" },
|
|
68
|
+
{ flag: "-deadlock" },
|
|
69
|
+
// Like TLC, -dump takes a format only when the next argument starts with dot and a file follows.
|
|
70
|
+
{
|
|
71
|
+
flag: "-dump [<format>] <file>",
|
|
72
|
+
getArity: (rest) => (rest.length > 1 && rest[0].startsWith("dot") ? 2 : 1),
|
|
73
|
+
},
|
|
74
|
+
{ flag: "-fp <num>" },
|
|
75
|
+
{ flag: "-lncheck <final|default>" },
|
|
76
|
+
{ flag: "-metadir <directory>" },
|
|
77
|
+
{ flag: "-nowarning" },
|
|
78
|
+
{ flag: "-seed <num>" },
|
|
79
|
+
{ flag: "-tool" },
|
|
80
|
+
{ flag: "-workers <count|auto>" },
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
export const TLAPM_COMMAND = defineCommand("tla-ts tlapm {options} <Module.tla|glob>...", [
|
|
84
|
+
{ flag: "-N" },
|
|
85
|
+
{ flag: "--summary" },
|
|
86
|
+
{ flag: "--strict" },
|
|
87
|
+
{ flag: "--toolbox <start> <end>" },
|
|
88
|
+
{ flag: "--line <num>" },
|
|
89
|
+
{ flag: "--printallobs" },
|
|
90
|
+
{ flag: "--threads <num>" },
|
|
91
|
+
{ flag: "--version" },
|
|
92
|
+
{ flag: "-I <directory>", isRepeatable: true },
|
|
93
|
+
{ flag: "-k" },
|
|
94
|
+
{ flag: "--noproving" },
|
|
95
|
+
{ flag: "--nofp" },
|
|
96
|
+
{ flag: "--nofpl <start> <end>" },
|
|
97
|
+
{ flag: "--safefp" },
|
|
98
|
+
{ flag: "--cleanfp" },
|
|
99
|
+
{ flag: "--usefp <file>" },
|
|
100
|
+
{ flag: "--cache-dir <directory>" },
|
|
101
|
+
]);
|
|
102
|
+
|
|
103
|
+
export const USAGE = [
|
|
104
|
+
`Usage: ${CHECK_COMMAND.usage}`,
|
|
105
|
+
` ${TLAPM_COMMAND.usage}`,
|
|
106
|
+
" tla-ts [<JVM option>]... tlc2.TLC <TLC option>... <Spec>",
|
|
107
|
+
" (-cp tla2tools.jar or -Dtla-ts.tlc=1.7.4 picks the TLC to reproduce)",
|
|
108
|
+
" tla-ts [<JVM option>]... tla2sany.xml.XMLExporter [-I <directory>]... [-o] [-t] [-r] [-u] <Module.tla>",
|
|
109
|
+
].join("\n");
|
package/src/cli/run.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { delimiter } from "node:path";
|
|
2
|
+
import { getTlcVersion } from "../tlc/version";
|
|
3
|
+
import { getToolsJar, reportErrors, type JavaProperties } from "./shared";
|
|
4
|
+
import { runTlapm } from "./tlapm";
|
|
5
|
+
import { checkSpecs } from "./tlc";
|
|
6
|
+
import { exportXml, exportXml174 } from "./xml-exporter";
|
|
7
|
+
|
|
8
|
+
// Tools that run TLC with Java, such as pstack's statechart skill, can run tla-ts in place of java,
|
|
9
|
+
// as in `tla-ts -DTLA-Library=lib -cp tla2tools.jar tlc2.TLC Spec`. Other JVM options are ignored.
|
|
10
|
+
const JAVA_MAIN_CLASSES = ["tlc2.TLC", "tla2sany.xml.XMLExporter"];
|
|
11
|
+
|
|
12
|
+
const TLA_LIBRARY_PROPERTY = "-DTLA-Library=";
|
|
13
|
+
|
|
14
|
+
const TEMPORARY_DIRECTORY_PROPERTY = "-Djava.io.tmpdir=";
|
|
15
|
+
|
|
16
|
+
const TLC_VERSION_PROPERTY = "-Dtla-ts.tlc=";
|
|
17
|
+
|
|
18
|
+
const getJavaLaunch = (args: string[]) => {
|
|
19
|
+
const java: JavaProperties = { libraries: [] };
|
|
20
|
+
for (let index = 0; index < args.length; index++) {
|
|
21
|
+
const arg = args[index];
|
|
22
|
+
if (arg === "-cp" || arg === "-classpath" || arg === "--class-path") {
|
|
23
|
+
index++;
|
|
24
|
+
java.classPath = args[index];
|
|
25
|
+
} else if (arg === "-jar") {
|
|
26
|
+
java.classPath = args[index + 1];
|
|
27
|
+
return { mainClass: "tlc2.TLC", args: args.slice(index + 2), java };
|
|
28
|
+
} else if (arg.startsWith(TLA_LIBRARY_PROPERTY)) {
|
|
29
|
+
java.libraries.push(...arg.slice(TLA_LIBRARY_PROPERTY.length).split(delimiter));
|
|
30
|
+
} else if (arg.startsWith(TEMPORARY_DIRECTORY_PROPERTY)) {
|
|
31
|
+
java.temporaryDirectory = arg.slice(TEMPORARY_DIRECTORY_PROPERTY.length);
|
|
32
|
+
} else if (arg.startsWith(TLC_VERSION_PROPERTY)) {
|
|
33
|
+
java.tlcVersion = arg.slice(TLC_VERSION_PROPERTY.length) === "1.7.4" ? "1.7.4" : "master";
|
|
34
|
+
} else if (!arg.startsWith("-D") && !arg.startsWith("-X")) {
|
|
35
|
+
const isLaunch = index > 0 || JAVA_MAIN_CLASSES.includes(arg);
|
|
36
|
+
return isLaunch ? { mainClass: arg, args: args.slice(index + 1), java } : undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const run = async (args: string[]) => {
|
|
43
|
+
if (args[0] === "tlapm") return reportErrors(() => runTlapm(args.slice(1)));
|
|
44
|
+
const launch = getJavaLaunch(args);
|
|
45
|
+
if (launch === undefined) return checkSpecs(args, { libraries: [] });
|
|
46
|
+
launch.java.tlcVersion ??= await getTlcVersion(getToolsJar(launch.java));
|
|
47
|
+
if (launch.mainClass === "tlc2.TLC") return checkSpecs(launch.args, launch.java);
|
|
48
|
+
if (launch.mainClass === "tla2sany.xml.XMLExporter") {
|
|
49
|
+
return reportErrors(() =>
|
|
50
|
+
launch.java.tlcVersion === "1.7.4"
|
|
51
|
+
? exportXml174(launch.args, getToolsJar(launch.java))
|
|
52
|
+
: exportXml(launch.args),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
console.error(
|
|
56
|
+
`Error: tla-ts runs the Java classes ${JAVA_MAIN_CLASSES.join(" and ")}, not ${launch.mainClass}.`,
|
|
57
|
+
);
|
|
58
|
+
return 1;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const runCli = async () => {
|
|
62
|
+
process.exitCode = await run(process.argv.slice(2));
|
|
63
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { existsSync, globSync, readFileSync } from "node:fs";
|
|
2
|
+
import { delimiter, isAbsolute, join, resolve } from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { getErrorExitCode, TlaConfigError, TlaError, TlaEvaluationError } from "../errors";
|
|
5
|
+
import { SANY_174_STANDARD_MODULES } from "../sany/modules";
|
|
6
|
+
import type { TlcVersion } from "../tlc/version";
|
|
7
|
+
import {
|
|
8
|
+
createMessagePrinter,
|
|
9
|
+
formatInnerMessage,
|
|
10
|
+
getCodedMessage,
|
|
11
|
+
MESSAGE_CODE,
|
|
12
|
+
MESSAGE_LEVEL,
|
|
13
|
+
type MessagePrinter,
|
|
14
|
+
} from "../tlc/messages";
|
|
15
|
+
|
|
16
|
+
const GLOB_CHARACTERS = /[*?[{]/;
|
|
17
|
+
|
|
18
|
+
interface InputPath {
|
|
19
|
+
path: string;
|
|
20
|
+
isGlobbed: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const getInputPaths = (paths: string[]): InputPath[] =>
|
|
24
|
+
paths.flatMap((arg): InputPath[] =>
|
|
25
|
+
GLOB_CHARACTERS.test(arg)
|
|
26
|
+
? globSync(arg)
|
|
27
|
+
.sort()
|
|
28
|
+
.map((path) => ({ path, isGlobbed: true }))
|
|
29
|
+
: [{ path: arg, isGlobbed: false }],
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
// Like TLC, tla-ts finds a module in the directory of the spec, then in each library directory.
|
|
33
|
+
export const findModuleFile = (directories: string[], name: string) =>
|
|
34
|
+
directories.map((directory) => join(directory, `${name}.tla`)).find(existsSync);
|
|
35
|
+
|
|
36
|
+
export const createModuleLoader = (directories: string[]) => (name: string) => {
|
|
37
|
+
const path = findModuleFile(directories, name);
|
|
38
|
+
return path === undefined ? undefined : readFileSync(path, "utf8");
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// SimpleFilenameToStream: SANY names the file of a module it can't find, and where it looked.
|
|
42
|
+
export const printMissingFile = (userDirectory: string, fileName: string, directories: string[]) =>
|
|
43
|
+
console.error(
|
|
44
|
+
`File does not exist: ${userDirectory}/${fileName} while looking in these directories: ${userDirectory}, ${directories.join(", ")}, classpath:/tla2sany/StandardModules, classpath:/`,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
export const getStandardModulesUrl = (jar: string) =>
|
|
48
|
+
`jar:file:${pathToFileURL(resolve(jar)).pathname}!/tla2sany/StandardModules/`;
|
|
49
|
+
|
|
50
|
+
// TLC prints an error it raises with that error's message code. tla-ts names the others, such as a
|
|
51
|
+
// module SANY rejects.
|
|
52
|
+
export const printError = (error: TlaError, printer: MessagePrinter) => {
|
|
53
|
+
if (error instanceof TlaConfigError || error instanceof TlaEvaluationError) {
|
|
54
|
+
const coded = getCodedMessage(error.message);
|
|
55
|
+
const code = coded && !coded.isEvalException ? coded.code : MESSAGE_CODE.general;
|
|
56
|
+
return printer.print(
|
|
57
|
+
code,
|
|
58
|
+
MESSAGE_LEVEL.error,
|
|
59
|
+
formatInnerMessage(code, error.message, printer.isTool),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
console.error(`${error.name}: ${error.message}`);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const reportErrors = async (
|
|
66
|
+
run: () => number | Promise<number>,
|
|
67
|
+
printer = createMessagePrinter(false),
|
|
68
|
+
) => {
|
|
69
|
+
try {
|
|
70
|
+
return await run();
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (!(error instanceof TlaError)) throw error;
|
|
73
|
+
printError(error, printer);
|
|
74
|
+
return getErrorExitCode(error);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// TLC 1.7.4's FileUtil.createNamedInputStream names the last file SimpleFilenameToStream looked
|
|
79
|
+
// for, and the directories it looked in, the jar's standard modules last.
|
|
80
|
+
export const printMissingFile174 = (path: string, libraries: string[], jar: string | undefined) =>
|
|
81
|
+
console.error(
|
|
82
|
+
`File does not exist: ${isAbsolute(path) ? path : `${process.cwd()}/${path}`} while looking in these directories: ${[...libraries, ...(jar === undefined ? [] : [getStandardModulesUrl(jar)])].join(", ")}`,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// SimpleFilenameToStream ends a library directory with a separator.
|
|
86
|
+
export const toLibraryPath = (directory: string) =>
|
|
87
|
+
directory.endsWith("/") ? directory : `${directory}/`;
|
|
88
|
+
|
|
89
|
+
// TLC 1.7.4's SANY reports each module it can't find as it looks for it.
|
|
90
|
+
export const reportMissingModules174 =
|
|
91
|
+
(loadModule: (name: string) => string | undefined, onMissing: (fileName: string) => void) =>
|
|
92
|
+
(name: string) => {
|
|
93
|
+
const text = loadModule(name);
|
|
94
|
+
if (text === undefined && !SANY_174_STANDARD_MODULES.has(name)) onMissing(`${name}.tla`);
|
|
95
|
+
return text;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export interface JavaProperties {
|
|
99
|
+
libraries: string[];
|
|
100
|
+
classPath?: string;
|
|
101
|
+
temporaryDirectory?: string;
|
|
102
|
+
tlcVersion?: TlcVersion;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const getToolsJar = (java: JavaProperties) =>
|
|
106
|
+
java.classPath?.split(delimiter).find((entry) => entry.endsWith(".jar"));
|
package/src/cli/tlapm.ts
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { availableParallelism } from "node:os";
|
|
4
|
+
import { TlaProofError } from "../errors";
|
|
5
|
+
import { EXIT_STATUS } from "../exit-codes";
|
|
6
|
+
import type { LineRange } from "../obligations/generate";
|
|
7
|
+
import { getAtPrefix, getLocusText } from "../obligations/expression";
|
|
8
|
+
import {
|
|
9
|
+
formatSummary,
|
|
10
|
+
getObligations,
|
|
11
|
+
WHOLE_MODULE,
|
|
12
|
+
type ModuleObligations,
|
|
13
|
+
type PrintedObligation,
|
|
14
|
+
} from "../obligations";
|
|
15
|
+
import { format, renderDoc } from "../obligations/format";
|
|
16
|
+
import { printSequent } from "../obligations/printer";
|
|
17
|
+
import {
|
|
18
|
+
encodeProofTheory,
|
|
19
|
+
formatNormalized,
|
|
20
|
+
proveObligations,
|
|
21
|
+
type ProofAttempt,
|
|
22
|
+
} from "../prover/prove";
|
|
23
|
+
import { TLAPS_MODULE } from "../prover/tlaps-module";
|
|
24
|
+
import { getTlapmPaths } from "../prover/tlapm/tlapm";
|
|
25
|
+
import {
|
|
26
|
+
getKnownResults,
|
|
27
|
+
loadFingerprints,
|
|
28
|
+
saveHistory,
|
|
29
|
+
type FingerprintTable,
|
|
30
|
+
} from "../prover/tlapm/cache";
|
|
31
|
+
import { formatTlcDate } from "../tlc/messages";
|
|
32
|
+
import { TLAPM_COMMAND, USAGE, type ParsedArgs } from "./options";
|
|
33
|
+
import { getInputPaths } from "./shared";
|
|
34
|
+
|
|
35
|
+
const TLAPM_INTEGER_OPTIONS = new Set(["--toolbox", "--line", "--threads", "--nofpl"]);
|
|
36
|
+
|
|
37
|
+
// tlapm searches the current directory, then its standard library at lib/tlapm/stdlib beside
|
|
38
|
+
// bin/tlapm, then each -I directory, the last given first.
|
|
39
|
+
const getLibraryDirectories = (parsed: ParsedArgs) => [
|
|
40
|
+
".",
|
|
41
|
+
...getTlapmPaths()
|
|
42
|
+
.map((path) => join(dirname(dirname(realpathSync(path))), "lib/tlapm/stdlib"))
|
|
43
|
+
.filter((path) => existsSync(path))
|
|
44
|
+
.slice(0, 1),
|
|
45
|
+
...parsed.options.flatMap((option) => (option.name === "-I" ? option.values : [])).toReversed(),
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
// A message of tlapm's toolbox protocol, which it writes to stderr.
|
|
49
|
+
const printToolboxMessage = (fields: string[]) =>
|
|
50
|
+
console.error(`@!!BEGIN\n${fields.map((field) => `@!!${field}\n`).join("")}@!!END\n`);
|
|
51
|
+
|
|
52
|
+
const printObligationMessage = (obligation: PrintedObligation, status: string, fields: string[]) =>
|
|
53
|
+
printToolboxMessage([
|
|
54
|
+
"type:obligation",
|
|
55
|
+
`id:${obligation.id}`,
|
|
56
|
+
`loc:${obligation.location}`,
|
|
57
|
+
`status:${status}`,
|
|
58
|
+
...fields,
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
const TLAPM_VERSION = "9ed0376";
|
|
62
|
+
|
|
63
|
+
const quoteShellArgument = (arg: string) =>
|
|
64
|
+
/^[+,\-./0-9:=@A-Z_a-z]+$/.test(arg) ? arg : `'${arg.replaceAll("'", "'\\''")}'`;
|
|
65
|
+
|
|
66
|
+
// The most severe first.
|
|
67
|
+
const STRICT_EXIT_STATUS = { failed: 10, incomplete: 11, emptyTarget: 12 };
|
|
68
|
+
|
|
69
|
+
const checkStrictly = (module: ModuleObligations, isTargeted: boolean, isSummary: boolean) => {
|
|
70
|
+
const summary = module.summary;
|
|
71
|
+
if (!isSummary) {
|
|
72
|
+
summary.absent.forEach((locus) => console.error(`Missing proof at ${getLocusText(locus)}`));
|
|
73
|
+
summary.omitted.forEach((locus) => console.error(`Omitted proof at ${getLocusText(locus)}`));
|
|
74
|
+
}
|
|
75
|
+
const isIncomplete = summary.absent.length + summary.omitted.length > 0;
|
|
76
|
+
if (isIncomplete) {
|
|
77
|
+
console.error(
|
|
78
|
+
`${getAtPrefix(module.location)}[ERROR]: Proof incomplete in module ${JSON.stringify(module.name)}: ${summary.absent.length} missing, ${summary.omitted.length} omitted proof step(s).`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
const isEmpty = isTargeted && module.obligations.length === 0;
|
|
82
|
+
if (isEmpty) {
|
|
83
|
+
console.error(
|
|
84
|
+
`${getAtPrefix(module.location)}[ERROR]: No proof obligation found for the selected target.`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return [
|
|
88
|
+
...(isIncomplete ? [STRICT_EXIT_STATUS.incomplete] : []),
|
|
89
|
+
...(isEmpty ? [STRICT_EXIT_STATUS.emptyTarget] : []),
|
|
90
|
+
];
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const TLAPM_FAILURE_STATUS = 3;
|
|
94
|
+
|
|
95
|
+
const UNPROVED_ENDING = [
|
|
96
|
+
' tlapm ending abnormally with Failure("backend errors: there are unproved obligations")',
|
|
97
|
+
'Raised at Stdlib.failwith in file "stdlib.ml", line 29, characters 17-33',
|
|
98
|
+
'Called from Tlapm_lib.process_module in file "src/tlapm_lib.ml", lines 492-493, characters 12-37',
|
|
99
|
+
'Called from Tlapm_lib.main.f in file "src/tlapm_lib.ml", line 640, characters 23-43',
|
|
100
|
+
'Called from Stdlib__List.fold_left in file "list.ml", line 125, characters 24-34',
|
|
101
|
+
'Called from Tlapm_lib.main in file "src/tlapm_lib.ml", line 643, characters 13-40',
|
|
102
|
+
'Called from Tlapm_lib.init in file "src/tlapm_lib.ml", line 659, characters 8-59',
|
|
103
|
+
"",
|
|
104
|
+
].join("\n");
|
|
105
|
+
|
|
106
|
+
const generateObligations = (generate: () => ModuleObligations[]) => {
|
|
107
|
+
try {
|
|
108
|
+
return generate();
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (!(error instanceof TlaProofError)) throw error;
|
|
111
|
+
console.error(` tlapm ending abnormally with ${error.exception}\n`);
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// Toolbox.print_res_aux.
|
|
117
|
+
const printAttempt = (obligation: PrintedObligation, attempt: ProofAttempt) => {
|
|
118
|
+
const timeLimitMs = attempt.method.timeLimitMs;
|
|
119
|
+
const used =
|
|
120
|
+
attempt.timeUsedMs === undefined
|
|
121
|
+
? ""
|
|
122
|
+
: `; time-used: ${(attempt.timeUsedMs / 1000).toFixed(1)} (${Math.round((100 * attempt.timeUsedMs) / timeLimitMs)}%)`;
|
|
123
|
+
const times =
|
|
124
|
+
timeLimitMs === 0
|
|
125
|
+
? ""
|
|
126
|
+
: `time-limit: ${timeLimitMs === Infinity ? "inf" : Number((timeLimitMs / 1000).toPrecision(6))}${used}`;
|
|
127
|
+
const method = [attempt.method.tactic, times].filter(Boolean).join("; ");
|
|
128
|
+
const isSmt = attempt.method.prover === "smt" || attempt.method.prover === "z3";
|
|
129
|
+
const note =
|
|
130
|
+
isSmt && attempt.reason === "false" && attempt.verdict
|
|
131
|
+
? `(* SMT failed with status = ${attempt.verdict}\n *)\n`
|
|
132
|
+
: "";
|
|
133
|
+
printObligationMessage(obligation, attempt.isProved ? "proved" : "failed", [
|
|
134
|
+
`prover:${attempt.method.prover}`,
|
|
135
|
+
...(method === "" ? [] : [`meth:${method}`]),
|
|
136
|
+
...(attempt.reason === undefined ? [] : [`reason:${attempt.reason}`]),
|
|
137
|
+
`already:${attempt.isReused}`,
|
|
138
|
+
...(attempt.isProved
|
|
139
|
+
? []
|
|
140
|
+
: [
|
|
141
|
+
`obl:${attempt.isReused ? "" : `\n${note}`}${formatNormalized(obligation, attempt.isReused)}`,
|
|
142
|
+
]),
|
|
143
|
+
]);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// Method.Fail, for an error obligation or one no method was tried on.
|
|
147
|
+
const printFailedObligation = (obligation: PrintedObligation, reason: string) =>
|
|
148
|
+
printObligationMessage(obligation, "failed", [
|
|
149
|
+
"prover:fail",
|
|
150
|
+
"meth:time-limit: inf",
|
|
151
|
+
`reason:${reason}`,
|
|
152
|
+
"already:false",
|
|
153
|
+
`obl:${obligation.text}`,
|
|
154
|
+
]);
|
|
155
|
+
|
|
156
|
+
interface ProvingSettings {
|
|
157
|
+
isToolbox: boolean;
|
|
158
|
+
isProving: boolean;
|
|
159
|
+
workers: number;
|
|
160
|
+
isFingerprinted: (obligation: PrintedObligation) => boolean;
|
|
161
|
+
fingerprints: FingerprintTable;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Tlapm_lib.process_obs. Returns whether some obligation failed.
|
|
165
|
+
const proveModule = async (
|
|
166
|
+
module: ModuleObligations,
|
|
167
|
+
theoryPath: string,
|
|
168
|
+
fingerprintsPath: string,
|
|
169
|
+
settings: ProvingSettings,
|
|
170
|
+
) => {
|
|
171
|
+
const knownResults = getKnownResults(settings.fingerprints);
|
|
172
|
+
const reports = await proveObligations(module.obligations, {
|
|
173
|
+
workers: settings.workers,
|
|
174
|
+
results: knownResults.results,
|
|
175
|
+
isFingerprinted: settings.isFingerprinted,
|
|
176
|
+
isProving: settings.isProving,
|
|
177
|
+
onReport: (report, obligation) => {
|
|
178
|
+
if (!settings.isToolbox) return;
|
|
179
|
+
if (report.obligation.status === "trivial")
|
|
180
|
+
return printObligationMessage(obligation, "trivial", ["prover:tlapm", "already:false"]);
|
|
181
|
+
if (obligation.kind.kind === "Error") return printFailedObligation(obligation, "user error");
|
|
182
|
+
report.attempts.forEach((attempt) => printAttempt(obligation, attempt));
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
writeFileSync(theoryPath, encodeProofTheory(module.name, reports, module.obligations));
|
|
186
|
+
console.log(`(* created new ${JSON.stringify(theoryPath)} *)`);
|
|
187
|
+
knownResults.save(fingerprintsPath);
|
|
188
|
+
console.log(`(* fingerprints written in ${JSON.stringify(fingerprintsPath)} *)`);
|
|
189
|
+
if (!settings.isProving) return false;
|
|
190
|
+
const unproved = reports.flatMap((report, index) =>
|
|
191
|
+
"reason" in report.obligation ? [{ report, obligation: module.obligations[index] }] : [],
|
|
192
|
+
);
|
|
193
|
+
if (settings.isToolbox) {
|
|
194
|
+
unproved
|
|
195
|
+
.filter(
|
|
196
|
+
(entry) => entry.report.attempts.length === 0 && entry.obligation.kind.kind !== "Error",
|
|
197
|
+
)
|
|
198
|
+
.forEach((entry) => printFailedObligation(entry.obligation, "unexpected error"));
|
|
199
|
+
}
|
|
200
|
+
unproved
|
|
201
|
+
.toReversed()
|
|
202
|
+
.forEach((entry) =>
|
|
203
|
+
console.error(
|
|
204
|
+
`${getAtPrefix(entry.obligation.locus)}${renderDoc(format("[ERROR]: @[<v2>Could not prove or check:@,%a@]", printSequent(entry.obligation.sequent)), 35)}`,
|
|
205
|
+
),
|
|
206
|
+
);
|
|
207
|
+
const total = `${module.obligations.length} obligation${module.obligations.length > 1 ? "s" : ""}`;
|
|
208
|
+
console.error(
|
|
209
|
+
unproved.length === 0
|
|
210
|
+
? `${getAtPrefix(module.location)}[INFO]: All ${total} proved.`
|
|
211
|
+
: `${getAtPrefix(module.location)}[ERROR]: ${unproved.length}/${total} failed.\nThere were backend errors processing module \`${JSON.stringify(module.name)}\`.`,
|
|
212
|
+
);
|
|
213
|
+
return unproved.length > 0;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export const runTlapm = async (args: string[]) => {
|
|
217
|
+
const parsed = TLAPM_COMMAND.parse(args);
|
|
218
|
+
const isProcessing = !parsed.has("-N") && !parsed.has("--summary");
|
|
219
|
+
const unsupported =
|
|
220
|
+
parsed.unknown[0] ??
|
|
221
|
+
(isProcessing && parsed.has("--printallobs") ? "--printallobs" : undefined);
|
|
222
|
+
if (unsupported !== undefined) {
|
|
223
|
+
console.error(`Error: tla-ts tlapm does not support the tlapm option ${unsupported}.`);
|
|
224
|
+
return 1;
|
|
225
|
+
}
|
|
226
|
+
if (parsed.incomplete) {
|
|
227
|
+
console.error(`Error: option '${parsed.incomplete.name}' needs an argument.`);
|
|
228
|
+
return 1;
|
|
229
|
+
}
|
|
230
|
+
const nonInteger = parsed.options.find(
|
|
231
|
+
(option) =>
|
|
232
|
+
TLAPM_INTEGER_OPTIONS.has(option.name) &&
|
|
233
|
+
option.values.some((value) => !/^-?\d+$/.test(value)),
|
|
234
|
+
);
|
|
235
|
+
if (nonInteger) {
|
|
236
|
+
console.error(`Error: option '${nonInteger.name}' expects an integer.`);
|
|
237
|
+
return 1;
|
|
238
|
+
}
|
|
239
|
+
if (parsed.has("--version")) {
|
|
240
|
+
console.log(TLAPM_VERSION);
|
|
241
|
+
return EXIT_STATUS.success;
|
|
242
|
+
}
|
|
243
|
+
const files = getInputPaths(parsed.positionals).map((input) => input.path);
|
|
244
|
+
const modulePaths = files.map((path) => (path.endsWith(".tla") ? path : `${path}.tla`));
|
|
245
|
+
if (modulePaths.length === 0) {
|
|
246
|
+
console.error(USAGE);
|
|
247
|
+
return 1;
|
|
248
|
+
}
|
|
249
|
+
const isToolbox = parsed.has("--toolbox") || parsed.has("--line");
|
|
250
|
+
if (isToolbox) {
|
|
251
|
+
console.log(
|
|
252
|
+
`\n\\* TLAPM version ${TLAPM_VERSION}\n\\* launched at ${formatTlcDate(new Date())} with command line:\n\\* ${["tla-ts", "tlapm", ...args].map(quoteShellArgument).join(" ")}\n`,
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
// Like tlapm, the last of --toolbox and --line wins, and a 0 means the whole module.
|
|
256
|
+
const lines = parsed.options.reduce<LineRange>((range, option) => {
|
|
257
|
+
const [start, end] = option.values.map(Number);
|
|
258
|
+
if (option.name === "--toolbox") return { start, end: end === 0 ? Infinity : end };
|
|
259
|
+
if (option.name === "--line") return start === 0 ? WHOLE_MODULE : { start, end: start };
|
|
260
|
+
return range;
|
|
261
|
+
}, WHOLE_MODULE);
|
|
262
|
+
// tlapm also searches each module's directory. Without tlapm, TLAPS is tla-ts's copy.
|
|
263
|
+
const directories = modulePaths.reduce(
|
|
264
|
+
(found, path) => (found.includes(dirname(path)) ? found : [dirname(path), ...found]),
|
|
265
|
+
getLibraryDirectories(parsed),
|
|
266
|
+
);
|
|
267
|
+
const moduleNames = new Set<string>();
|
|
268
|
+
const modules = generateObligations(() => {
|
|
269
|
+
const missingIndex = modulePaths.findIndex((path) => !existsSync(path));
|
|
270
|
+
if (missingIndex !== -1) {
|
|
271
|
+
const missing = files[missingIndex];
|
|
272
|
+
console.error(`File "<unknown>":\nError: File ${JSON.stringify(missing)} not found`);
|
|
273
|
+
throw new TlaProofError(`File ${missing} not found`, { failure: "Module.Parser.parse_file" });
|
|
274
|
+
}
|
|
275
|
+
return getObligations(
|
|
276
|
+
modulePaths.map((path) => ({ file: `./${path}`, source: readFileSync(path, "utf8") })),
|
|
277
|
+
(name) => {
|
|
278
|
+
moduleNames.add(name);
|
|
279
|
+
// tlapm names a file by joining its search directory and the name, as in ./Module.tla.
|
|
280
|
+
const file = directories
|
|
281
|
+
.map((directory) => `${directory}/${name}.tla`)
|
|
282
|
+
.find((path) => existsSync(path));
|
|
283
|
+
if (file !== undefined) return { file, source: readFileSync(file, "utf8") };
|
|
284
|
+
return name === "TLAPS" ? { file: "TLAPS.tla", source: TLAPS_MODULE } : undefined;
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
lines,
|
|
288
|
+
onWarning: (warning) => {
|
|
289
|
+
if (warning.channel === "stdout") return console.log(warning.text);
|
|
290
|
+
const isToolboxMessage =
|
|
291
|
+
warning.channel === "toolbox" || warning.channel === "toolboxOnly";
|
|
292
|
+
if (isToolbox && isToolboxMessage)
|
|
293
|
+
return printToolboxMessage(["type:warning", `msg:${warning.text}`]);
|
|
294
|
+
if (warning.channel !== "toolboxOnly") console.error(warning.text);
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
);
|
|
298
|
+
});
|
|
299
|
+
if (!modules) return TLAPM_FAILURE_STATUS;
|
|
300
|
+
const cacheDirectory =
|
|
301
|
+
parsed.get("--cache-dir")?.[0] ?? process.env.TLAPM_CACHE_DIR ?? ".tlacache";
|
|
302
|
+
const forgottenLines = parsed.get("--nofpl")?.map(Number) ?? [0, 0];
|
|
303
|
+
const settings: ProvingSettings = {
|
|
304
|
+
isToolbox,
|
|
305
|
+
isProving: !parsed.has("--noproving"),
|
|
306
|
+
workers: Math.max(1, Number(parsed.get("--threads")?.[0] ?? availableParallelism())),
|
|
307
|
+
isFingerprinted: (obligation) =>
|
|
308
|
+
!parsed.has("--nofp") &&
|
|
309
|
+
!(
|
|
310
|
+
obligation.locus &&
|
|
311
|
+
obligation.locus.startLine >= forgottenLines[0] &&
|
|
312
|
+
obligation.locus.endLine <= forgottenLines[1]
|
|
313
|
+
),
|
|
314
|
+
fingerprints: new Map(),
|
|
315
|
+
};
|
|
316
|
+
const statuses: number[] = [];
|
|
317
|
+
for (const [index, module] of modules.entries()) {
|
|
318
|
+
// Tlapm_lib.mkdir_tlaps.
|
|
319
|
+
const directory = `${cacheDirectory}/${module.name}.tlaps`;
|
|
320
|
+
const fingerprintsPath = `${directory}/fingerprints`;
|
|
321
|
+
const loadedPath = parsed.get("--usefp")?.[0] ?? fingerprintsPath;
|
|
322
|
+
mkdirSync(directory, { recursive: true });
|
|
323
|
+
if (parsed.has("--cleanfp") && existsSync(fingerprintsPath)) {
|
|
324
|
+
rmSync(fingerprintsPath);
|
|
325
|
+
console.log(`(* fingerprints file ${JSON.stringify(fingerprintsPath)} removed *)`);
|
|
326
|
+
}
|
|
327
|
+
if (!parsed.has("--cleanfp") && existsSync(loadedPath) && module.summary.total !== 0) {
|
|
328
|
+
console.log(
|
|
329
|
+
parsed.has("--nofp")
|
|
330
|
+
? `(* will not use fingerprints (because of option \`--nofp\`), but will now load fingerprints from the file \`${loadedPath}\`, in order to overwrite with the new fingerprints, and then save the results at the end. *)`
|
|
331
|
+
: `(* loading fingerprints in ${JSON.stringify(loadedPath)} *)`,
|
|
332
|
+
);
|
|
333
|
+
loadFingerprints(settings.fingerprints, loadedPath, parsed.has("--safefp"));
|
|
334
|
+
}
|
|
335
|
+
if (parsed.has("--summary")) console.log(formatSummary(module));
|
|
336
|
+
if (isToolbox) {
|
|
337
|
+
module.obligations.forEach((obligation) =>
|
|
338
|
+
printObligationMessage(
|
|
339
|
+
obligation,
|
|
340
|
+
"to be proved",
|
|
341
|
+
parsed.has("--printallobs") ? [`obl:${obligation.text}`] : [],
|
|
342
|
+
),
|
|
343
|
+
);
|
|
344
|
+
printToolboxMessage(["type:obligationsnumber", `count:${module.obligations.length}`]);
|
|
345
|
+
}
|
|
346
|
+
if (parsed.has("--strict"))
|
|
347
|
+
statuses.push(
|
|
348
|
+
...checkStrictly(module, lines.start > 0 || lines.end < Infinity, parsed.has("--summary")),
|
|
349
|
+
);
|
|
350
|
+
if (!isProcessing) continue;
|
|
351
|
+
// tlapm's history holds the source of each module read so far.
|
|
352
|
+
saveHistory(
|
|
353
|
+
fingerprintsPath,
|
|
354
|
+
[...moduleNames, ...modules.slice(0, index + 1).map((innerModule) => innerModule.name)].map(
|
|
355
|
+
(name) => `${name}.tla`,
|
|
356
|
+
),
|
|
357
|
+
);
|
|
358
|
+
const isFailed = await proveModule(
|
|
359
|
+
module,
|
|
360
|
+
`${directory}/${module.name}.thy`,
|
|
361
|
+
fingerprintsPath,
|
|
362
|
+
settings,
|
|
363
|
+
);
|
|
364
|
+
if (isFailed && parsed.has("--strict")) statuses.push(STRICT_EXIT_STATUS.failed);
|
|
365
|
+
if (isFailed && !parsed.has("--strict") && !isToolbox) {
|
|
366
|
+
console.error(UNPROVED_ENDING);
|
|
367
|
+
return TLAPM_FAILURE_STATUS;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return (
|
|
371
|
+
Object.values(STRICT_EXIT_STATUS).find((status) => statuses.includes(status)) ??
|
|
372
|
+
EXIT_STATUS.success
|
|
373
|
+
);
|
|
374
|
+
};
|