tla-ts 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -1
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +28 -28
- package/dist/deciders.js +43 -43
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +72 -10
- package/dist/index.d.ts +72 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +116 -36
- package/dist/prove.js +116 -36
- package/dist/run.cjs +143 -31
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +128 -103
- package/dist/transfer.js +128 -103
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +7 -21
- package/src/bags.ts +99 -99
- package/src/builtins.ts +44 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check.ts +576 -300
- package/src/cli/options.ts +11 -6
- package/src/cli/run.ts +2 -2
- package/src/cli/runtime-invariants.ts +135 -0
- package/src/cli/shared.ts +20 -9
- package/src/cli/tlapm.ts +0 -12
- package/src/cli/tlc-arguments.ts +646 -0
- package/src/cli/tlc-usage.ts +362 -0
- package/src/cli/tlc.ts +538 -220
- package/src/cli/typescript.ts +23 -0
- package/src/cli/xml-exporter.ts +4 -16
- package/src/cli.ts +0 -1
- package/src/codegen.ts +191 -64
- package/src/config.ts +140 -109
- package/src/coverage.ts +837 -0
- package/src/dependencies.ts +6 -40
- package/src/dfid.ts +618 -0
- package/src/environment.ts +240 -118
- package/src/errors.ts +70 -55
- package/src/evaluate.ts +630 -297
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +10 -10
- package/src/index.ts +3 -0
- package/src/instances.ts +79 -11
- package/src/java-overrides.ts +2 -12
- package/src/json-reader.ts +456 -0
- package/src/json.ts +262 -139
- package/src/levels.ts +2 -3
- package/src/lexer.ts +17 -26
- package/src/liveness-checker.ts +10 -18
- package/src/liveness.ts +121 -49
- package/src/obligations/action.ts +4 -28
- package/src/obligations/anonymize.ts +84 -80
- package/src/obligations/equality.ts +1 -1
- package/src/obligations/expression.ts +2 -19
- package/src/obligations/format.ts +1 -9
- package/src/obligations/generate.ts +1 -11
- package/src/obligations/index.ts +0 -11
- package/src/obligations/levels.ts +4 -8
- package/src/obligations/module.ts +1 -15
- package/src/obligations/normalize.ts +5 -24
- package/src/obligations/operators.ts +1 -2
- package/src/obligations/pragma.ts +1 -10
- package/src/obligations/printer.ts +47 -46
- package/src/obligations/proof.ts +1 -5
- package/src/obligations/regroup.ts +1 -4
- package/src/obligations/simplify.ts +3 -14
- package/src/obligations/source.ts +1 -21
- package/src/obligations/subexpression.ts +5 -11
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +8 -14
- package/src/obligations/tuples.ts +3 -9
- package/src/parallel-worker.ts +29 -39
- package/src/parallel.ts +29 -13
- package/src/parser.ts +436 -90
- package/src/pcal/ast.ts +7 -28
- package/src/pcal/parse.ts +11 -39
- package/src/pcal/tokenize.ts +4 -20
- package/src/pcal/translate.ts +10 -42
- package/src/pcal/validate.ts +3 -21
- package/src/pretty-print.ts +1 -2
- package/src/prover/decide-pool.ts +5 -10
- package/src/prover/deciders.ts +0 -4
- package/src/prover/first-order.ts +0 -11
- package/src/prover/isabelle/decide.ts +0 -6
- package/src/prover/isabelle/encode.ts +11 -23
- package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
- package/src/prover/isabelle/isar/method.ts +25 -38
- package/src/prover/isabelle/isar/proof.ts +1 -10
- package/src/prover/isabelle/isar/statement.ts +1 -6
- package/src/prover/isabelle/isar/theory.ts +15 -26
- package/src/prover/isabelle/isar/type-check.ts +11 -25
- package/src/prover/isabelle/provers/blast/blast.ts +10 -41
- package/src/prover/isabelle/provers/blast/branch.ts +1 -32
- package/src/prover/isabelle/provers/blast/prove.ts +1 -35
- package/src/prover/isabelle/provers/blast/rules.ts +6 -44
- package/src/prover/isabelle/provers/blast/state.ts +2 -28
- package/src/prover/isabelle/provers/blast/term.ts +9 -36
- package/src/prover/isabelle/provers/clasimp.ts +1 -13
- package/src/prover/isabelle/provers/classical.ts +14 -42
- package/src/prover/isabelle/provers/hypsubst.ts +11 -25
- package/src/prover/isabelle/pure/bicompose.ts +16 -13
- package/src/prover/isabelle/pure/consts.ts +1 -7
- package/src/prover/isabelle/pure/conv.ts +1 -9
- package/src/prover/isabelle/pure/drule.ts +24 -40
- package/src/prover/isabelle/pure/envir.ts +3 -52
- package/src/prover/isabelle/pure/goal.ts +1 -7
- package/src/prover/isabelle/pure/interrupt.ts +0 -5
- package/src/prover/isabelle/pure/list.ts +0 -3
- package/src/prover/isabelle/pure/logic.ts +1 -14
- package/src/prover/isabelle/pure/name.ts +2 -9
- package/src/prover/isabelle/pure/net.ts +3 -59
- package/src/prover/isabelle/pure/object-logic.ts +3 -10
- package/src/prover/isabelle/pure/pattern.ts +2 -19
- package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
- package/src/prover/isabelle/pure/rewriter.ts +26 -58
- package/src/prover/isabelle/pure/search.ts +3 -10
- package/src/prover/isabelle/pure/seq.ts +1 -10
- package/src/prover/isabelle/pure/simplifier.ts +4 -12
- package/src/prover/isabelle/pure/table.ts +1 -31
- package/src/prover/isabelle/pure/tactic.ts +12 -22
- package/src/prover/isabelle/pure/tactical.ts +6 -12
- package/src/prover/isabelle/pure/term-ord.ts +2 -6
- package/src/prover/isabelle/pure/term.ts +2 -43
- package/src/prover/isabelle/pure/thm.ts +13 -36
- package/src/prover/isabelle/pure/type.ts +2 -15
- package/src/prover/isabelle/pure/unify.ts +20 -30
- package/src/prover/isabelle/pure/variable.ts +3 -7
- package/src/prover/isabelle/tla/classical-setup.ts +9 -19
- package/src/prover/isabelle/tla/context.ts +8 -16
- package/src/prover/isabelle/tla/logic.ts +4 -11
- package/src/prover/isabelle/tla/simpdata.ts +46 -34
- package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
- package/src/prover/ocaml.ts +0 -6
- package/src/prover/prep/action.ts +4 -36
- package/src/prover/prep/enabled-axioms.ts +12 -19
- package/src/prover/prep/fingerprint.ts +0 -16
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +9 -36
- package/src/prover/prep/normalize.ts +4 -28
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +0 -36
- package/src/prover/ptl/decide.ts +7 -12
- package/src/prover/ptl/encode.ts +14 -36
- package/src/prover/ptl/sat.ts +24 -32
- package/src/prover/ptl/tableau.ts +12 -26
- package/src/prover/smt/axioms.ts +0 -7
- package/src/prover/smt/context.ts +19 -26
- package/src/prover/smt/data.ts +51 -54
- package/src/prover/smt/encode.ts +14 -35
- package/src/prover/smt/extensionality.ts +0 -10
- package/src/prover/smt/flatten.ts +3 -22
- package/src/prover/smt/format.ts +5 -10
- package/src/prover/smt/instances.ts +0 -10
- package/src/prover/smt/rewrite.ts +66 -101
- package/src/prover/smt/solver/act-cache.ts +0 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -48
- package/src/prover/smt/solver/array.ts +1 -3
- package/src/prover/smt/solver/asserted-formulas.ts +1 -43
- package/src/prover/smt/solver/ast-lt.ts +1 -11
- package/src/prover/smt/solver/ast-util.ts +1 -6
- package/src/prover/smt/solver/ast.ts +1 -143
- package/src/prover/smt/solver/auf-solver.ts +6 -39
- package/src/prover/smt/solver/case-split-queue.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +1 -18
- package/src/prover/smt/solver/clause.ts +1 -27
- package/src/prover/smt/solver/conflict-resolution.ts +0 -9
- package/src/prover/smt/solver/context.ts +4 -61
- package/src/prover/smt/solver/ctx-simplify.ts +14 -41
- package/src/prover/smt/solver/der.ts +2 -21
- package/src/prover/smt/solver/dyn-ack.ts +1 -11
- package/src/prover/smt/solver/e-matching.ts +3 -34
- package/src/prover/smt/solver/enode.ts +1 -21
- package/src/prover/smt/solver/expr-ref.ts +1 -5
- package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
- package/src/prover/smt/solver/fingerprints.ts +1 -12
- package/src/prover/smt/solver/flat-literals.ts +1 -9
- package/src/prover/smt/solver/goal.ts +2 -14
- package/src/prover/smt/solver/hash.ts +0 -8
- package/src/prover/smt/solver/hashtable.ts +1 -12
- package/src/prover/smt/solver/internalizer.ts +6 -98
- package/src/prover/smt/solver/lbool.ts +1 -2
- package/src/prover/smt/solver/literal.ts +0 -3
- package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
- package/src/prover/smt/solver/lp/constraints.ts +2 -8
- package/src/prover/smt/solver/lp/containers.ts +12 -30
- package/src/prover/smt/solver/lp/core-solver.ts +10 -31
- package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
- package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
- package/src/prover/smt/solver/lp/dependency.ts +1 -4
- package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
- package/src/prover/smt/solver/lp/explanation.ts +1 -6
- package/src/prover/smt/solver/lp/gomory.ts +9 -22
- package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
- package/src/prover/smt/solver/lp/hnf.ts +11 -26
- package/src/prover/smt/solver/lp/int-cube.ts +15 -36
- package/src/prover/smt/solver/lp/int-solver.ts +4 -34
- package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
- package/src/prover/smt/solver/lp/lar-term.ts +1 -5
- package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
- package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
- package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
- package/src/prover/smt/solver/lp/nex.ts +1 -6
- package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
- package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
- package/src/prover/smt/solver/lp/nla-core.ts +35 -130
- package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
- package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
- package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
- package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
- package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
- package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
- package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
- package/src/prover/smt/solver/lp/nla-order.ts +2 -13
- package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
- package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
- package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
- package/src/prover/smt/solver/lp/nla-types.ts +1 -11
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
- package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
- package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
- package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
- package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
- package/src/prover/smt/solver/lp/pdd.ts +7 -70
- package/src/prover/smt/solver/lp/random-updater.ts +1 -8
- package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
- package/src/prover/smt/solver/lp/union-find.ts +1 -6
- package/src/prover/smt/solver/mam-compiler.ts +14 -56
- package/src/prover/smt/solver/mam-interpreter.ts +1 -21
- package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
- package/src/prover/smt/solver/model-checker.ts +2 -36
- package/src/prover/smt/solver/model-evaluator.ts +3 -29
- package/src/prover/smt/solver/model-finder.ts +3 -15
- package/src/prover/smt/solver/model-generator.ts +1 -12
- package/src/prover/smt/solver/model-macro-solver.ts +12 -69
- package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
- package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
- package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
- package/src/prover/smt/solver/nlsat/explain.ts +3 -47
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
- package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
- package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
- package/src/prover/smt/solver/nlsat/solver.ts +7 -67
- package/src/prover/smt/solver/nlsat/types.ts +1 -8
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
- package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
- package/src/prover/smt/solver/nnf.ts +3 -38
- package/src/prover/smt/solver/pattern-inference.ts +2 -15
- package/src/prover/smt/solver/poly-rewriter.ts +3 -23
- package/src/prover/smt/solver/propagate-values.ts +1 -10
- package/src/prover/smt/solver/proto-model.ts +3 -48
- package/src/prover/smt/solver/pull-quant.ts +1 -12
- package/src/prover/smt/solver/qe-lite-der.ts +1 -29
- package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
- package/src/prover/smt/solver/qe-lite.ts +3 -33
- package/src/prover/smt/solver/qi-queue.ts +1 -16
- package/src/prover/smt/solver/quant-tactics.ts +5 -22
- package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
- package/src/prover/smt/solver/quantifier-manager.ts +1 -8
- package/src/prover/smt/solver/random-gen.ts +1 -2
- package/src/prover/smt/solver/rational.ts +1 -8
- package/src/prover/smt/solver/ref-vector.ts +1 -6
- package/src/prover/smt/solver/relevancy.ts +2 -15
- package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
- package/src/prover/smt/solver/rewriter.ts +3 -85
- package/src/prover/smt/solver/rlimit.ts +2 -20
- package/src/prover/smt/solver/smtlib-parser.ts +2 -37
- package/src/prover/smt/solver/solver.ts +23 -34
- package/src/prover/smt/solver/sort.ts +1 -5
- package/src/prover/smt/solver/sticky-generations.ts +0 -5
- package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
- package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
- package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
- package/src/prover/smt/solver/theory-lra-model.ts +4 -19
- package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
- package/src/prover/smt/solver/theory-lra-state.ts +3 -8
- package/src/prover/smt/solver/theory-lra.ts +1 -8
- package/src/prover/smt/solver/var-subst.ts +2 -26
- package/src/prover/smt/table.ts +0 -8
- package/src/prover/tlapm/cache.ts +20 -25
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +12 -17
- package/src/prover/verdict.ts +0 -2
- package/src/prover/zenon/check/check.ts +0 -9
- package/src/prover/zenon/check/definitions.ts +5 -15
- package/src/prover/zenon/check/equality.ts +0 -8
- package/src/prover/zenon/check/functions.ts +0 -4
- package/src/prover/zenon/check/keys.ts +0 -7
- package/src/prover/zenon/check/propositional.ts +0 -3
- package/src/prover/zenon/check/records.ts +0 -5
- package/src/prover/zenon/check/relations.ts +0 -13
- package/src/prover/zenon/check/rewrites.ts +0 -6
- package/src/prover/zenon/check/sets.ts +0 -3
- package/src/prover/zenon/check/terms.ts +0 -17
- package/src/prover/zenon/check/tla.ts +0 -6
- package/src/prover/zenon/decide.ts +0 -12
- package/src/prover/zenon/encode.ts +1 -8
- package/src/prover/zenon/eqrel.ts +0 -13
- package/src/prover/zenon/equality-rules.ts +0 -4
- package/src/prover/zenon/expr.ts +1 -26
- package/src/prover/zenon/index-table.ts +17 -38
- package/src/prover/zenon/isar-case.ts +9 -19
- package/src/prover/zenon/isar.ts +1 -29
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +0 -9
- package/src/prover/zenon/mltoll.ts +54 -76
- package/src/prover/zenon/node.ts +1 -11
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +2 -7
- package/src/prover/zenon/phrase.ts +1 -11
- package/src/prover/zenon/proof.ts +0 -9
- package/src/prover/zenon/propositional-rules.ts +0 -5
- package/src/prover/zenon/rules.ts +2 -6
- package/src/prover/zenon/search.ts +1 -17
- package/src/prover/zenon/tla/functions.ts +57 -29
- package/src/prover/zenon/tla/llproof.ts +63 -70
- package/src/prover/zenon/tla/records.ts +56 -27
- package/src/prover/zenon/tla/rewrites.ts +12 -19
- package/src/prover/zenon/tla/sets.ts +68 -39
- package/src/prover/zenon/tla/terms.ts +0 -6
- package/src/prover/zenon/tla/tla.ts +59 -58
- package/src/randomization.ts +84 -35
- package/src/resolve.ts +18 -60
- package/src/runtime.ts +11 -4
- package/src/sany/builtins.ts +3 -4
- package/src/sany/generator.ts +119 -169
- package/src/sany/levels.ts +6 -30
- package/src/sany/lexer.ts +7 -23
- package/src/sany/linter.ts +1 -8
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +0 -31
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +29 -63
- package/src/sany/selectors.ts +15 -39
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +13 -63
- package/src/search.ts +494 -154
- package/src/simulate.ts +694 -0
- package/src/spec-description.ts +166 -48
- package/src/standard-definitions.ts +2 -3
- package/src/standard-modules.ts +264 -68
- package/src/state-graph.ts +51 -18
- package/src/subexpressions.ts +31 -5
- package/src/substitution-levels.ts +2 -3
- package/src/successors.ts +267 -77
- package/src/symmetry.ts +31 -8
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -61
- package/src/tlc/jar-data.ts +113 -6
- package/src/tlc/messages.ts +122 -37
- package/src/tlc/order.ts +33 -38
- package/src/tlc/random.ts +16 -16
- package/src/tlc/replay.ts +563 -211
- package/src/tlc/summary.ts +2 -4
- package/src/tlc/tlc-operators.ts +81 -36
- package/src/tlc/tlcext-operators.ts +138 -117
- package/src/tlc/trace-spec.ts +273 -0
- package/src/tlc/value-stream.ts +143 -0
- package/src/tlc/version.ts +2 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +481 -0
- package/src/typescript/collections.ts +600 -0
- package/src/typescript/compile.ts +65 -0
- package/src/typescript/context.ts +94 -0
- package/src/typescript/emit.ts +121 -0
- package/src/typescript/expressions.ts +496 -0
- package/src/typescript/formula.ts +152 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +163 -0
- package/src/typescript/names.ts +114 -0
- package/src/typescript/program.ts +48 -0
- package/src/typescript/properties.ts +139 -0
- package/src/typescript/scope.ts +112 -0
- package/src/typescript/steps.ts +165 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +826 -276
- package/src/worker.ts +7 -8
package/src/pcal/translate.ts
CHANGED
|
@@ -31,7 +31,6 @@ import {
|
|
|
31
31
|
type PcalWhile,
|
|
32
32
|
} from "./ast";
|
|
33
33
|
|
|
34
|
-
// PcalSymTab's symbol types, which index PCAL_SYMBOL_TYPE_NAMES.
|
|
35
34
|
const PCAL_SYMBOL = {
|
|
36
35
|
global: 0,
|
|
37
36
|
label: 1,
|
|
@@ -69,7 +68,7 @@ interface PcalSymbol {
|
|
|
69
68
|
useThis: string;
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
//
|
|
71
|
+
// initialPC is the first label, which a body with no statements lacks.
|
|
73
72
|
interface PcalProcedureEntry {
|
|
74
73
|
name: string;
|
|
75
74
|
params: PcalPVarDecl[];
|
|
@@ -128,8 +127,6 @@ const useThisVar = (table: PcalSymbolTable, id: string, context: string) => {
|
|
|
128
127
|
return PCAL_VARIABLE_SYMBOLS.has(symbol.type) ? symbol.useThis : id;
|
|
129
128
|
};
|
|
130
129
|
|
|
131
|
-
// The PcalSymTab constructor: collects the algorithm's variables, labels, procedures and processes,
|
|
132
|
-
// reporting every redefinition at once.
|
|
133
130
|
const createPcalSymbolTable = (ast: PcalAlgorithm) => {
|
|
134
131
|
const table: PcalSymbolTable = {
|
|
135
132
|
symbols: [],
|
|
@@ -249,8 +246,6 @@ const createPcalSymbolTable = (ast: PcalAlgorithm) => {
|
|
|
249
246
|
return table;
|
|
250
247
|
};
|
|
251
248
|
|
|
252
|
-
// PcalSymTab.Disambiguate: renames each symbol whose name another symbol already uses, by
|
|
253
|
-
// appending "_", then the letters of its context, then its type. Returns whether it renamed any.
|
|
254
249
|
const disambiguatePcalSymbols = (table: PcalSymbolTable) => {
|
|
255
250
|
const isAmbiguous = (id: string) =>
|
|
256
251
|
table.symbols.filter((symbol) => symbol.useThis === id).length > 1;
|
|
@@ -269,7 +264,6 @@ const disambiguatePcalSymbols = (table: PcalSymbolTable) => {
|
|
|
269
264
|
return renamed.isAny;
|
|
270
265
|
};
|
|
271
266
|
|
|
272
|
-
// PcalSymTab.CheckForDefaultInitValue.
|
|
273
267
|
const checkForDefaultInitValue = (table: PcalSymbolTable) => {
|
|
274
268
|
const uses = table.symbols
|
|
275
269
|
.filter((symbol) => symbol.id === "defaultInitValue")
|
|
@@ -279,8 +273,6 @@ const checkForDefaultInitValue = (table: PcalSymbolTable) => {
|
|
|
279
273
|
}
|
|
280
274
|
};
|
|
281
275
|
|
|
282
|
-
// PcalFixIDs.Fix: replaces every identifier with the name PcalSymTab.Disambiguate chose for it, and
|
|
283
|
-
// closes each process's set of called procedures over the procedures they call.
|
|
284
276
|
const fixPcalIds = (ast: PcalAlgorithm, table: PcalSymbolTable, log: (line: string) => void) => {
|
|
285
277
|
const fixExpr = (expr: PcalExpr, context: string) => {
|
|
286
278
|
const names: string[] = [];
|
|
@@ -425,8 +417,8 @@ const fixPcalIds = (ast: PcalAlgorithm, table: PcalSymbolTable, log: (line: stri
|
|
|
425
417
|
process.name = useThis(table, PCAL_SYMBOL.process, process.name, "");
|
|
426
418
|
};
|
|
427
419
|
|
|
428
|
-
//
|
|
429
|
-
//
|
|
420
|
+
// A process calling an unknown procedure stops the fixing of the remaining processes with an
|
|
421
|
+
// error message, but not the translation.
|
|
430
422
|
const fixMultiprocess = (procedures: PcalProcedure[], processes: PcalProcess[]) => {
|
|
431
423
|
procedures.forEach(fixProcedure);
|
|
432
424
|
const procedureNames = procedures.map((procedure) => procedure.name);
|
|
@@ -473,13 +465,11 @@ const fixPcalIds = (ast: PcalAlgorithm, table: PcalSymbolTable, log: (line: stri
|
|
|
473
465
|
}
|
|
474
466
|
};
|
|
475
467
|
|
|
476
|
-
// PcalTranslate's token constructors, which leave the column 0.
|
|
477
468
|
const stringToken = (string: string) => createPcalToken(string, 0, PCAL_TOKEN.string);
|
|
478
469
|
const addedToken = (string: string) => createPcalToken(string, 0, PCAL_TOKEN.added);
|
|
479
470
|
const builtInToken = (string: string) => createPcalToken(string, 0, PCAL_TOKEN.builtin);
|
|
480
471
|
const identToken = (string: string) => createPcalToken(string, 0, PCAL_TOKEN.ident);
|
|
481
472
|
|
|
482
|
-
// PcalTranslate.TokVectorToExpr: copies the tokens onto one line, spaces columns apart.
|
|
483
473
|
const tokensToExpr = (tokens: PcalToken[], spaces: number) => {
|
|
484
474
|
const line: PcalToken[] = [];
|
|
485
475
|
tokens.forEach((token) => {
|
|
@@ -491,8 +481,6 @@ const tokensToExpr = (tokens: PcalToken[], spaces: number) => {
|
|
|
491
481
|
return createNormalizedPcalExpr([line]);
|
|
492
482
|
};
|
|
493
483
|
|
|
494
|
-
// PcalTranslate.MakeNewStackTopExprPretty: lays out a pushed stack frame one field per line with
|
|
495
|
-
// the "|->" aligned.
|
|
496
484
|
const prettifyStackTopExpr = (expr: PcalExpr) =>
|
|
497
485
|
expr.tokens.forEach((line, lineIndex) => {
|
|
498
486
|
const cursor = { column: lineIndex === 0 || lineIndex === expr.tokens.length - 1 ? 1 : 6 };
|
|
@@ -522,7 +510,6 @@ const prettifyStackTopExpr = (expr: PcalExpr) =>
|
|
|
522
510
|
});
|
|
523
511
|
});
|
|
524
512
|
|
|
525
|
-
// A new AST.SingleAssign and AST.Assign, whose line and column default to 0.
|
|
526
513
|
const createSingleAssign = (
|
|
527
514
|
variable: string,
|
|
528
515
|
sub: PcalExpr,
|
|
@@ -553,7 +540,7 @@ const makeAssign = (variable: string, expr: PcalExpr, line = 0, col = 0) =>
|
|
|
553
540
|
col,
|
|
554
541
|
);
|
|
555
542
|
|
|
556
|
-
// PcalTranslate.IsTRUE
|
|
543
|
+
// PcalTranslate.IsTRUE indexes the first line of an expression without checking it has one.
|
|
557
544
|
const isTrue = (expr: PcalExpr) => {
|
|
558
545
|
if (expr.tokens.length > 1) return false;
|
|
559
546
|
const line = getElement(expr.tokens, 0);
|
|
@@ -575,7 +562,6 @@ const checkPC = (label: string): PcalWhen => ({
|
|
|
575
562
|
const updatePC = (next: string | undefined) =>
|
|
576
563
|
makeAssign("pc", createNormalizedPcalExpr([[stringToken(next ?? "null")]]));
|
|
577
564
|
|
|
578
|
-
// `Head(stack).field`.
|
|
579
565
|
const getStackHeadTokens = (field: string) => [
|
|
580
566
|
identToken("Head"),
|
|
581
567
|
builtInToken("("),
|
|
@@ -585,7 +571,6 @@ const getStackHeadTokens = (field: string) => [
|
|
|
585
571
|
identToken(field),
|
|
586
572
|
];
|
|
587
573
|
|
|
588
|
-
// `Tail(stack)`.
|
|
589
574
|
const getStackTailTokens = () => [
|
|
590
575
|
identToken("Tail"),
|
|
591
576
|
builtInToken("("),
|
|
@@ -596,8 +581,6 @@ const getStackTailTokens = () => [
|
|
|
596
581
|
const createStackHeadExpr = (field: string) =>
|
|
597
582
|
createNormalizedPcalExpr([getStackHeadTokens(field)]);
|
|
598
583
|
|
|
599
|
-
// The `<< [ procedure |-> "name", pc |-> ..., var |-> var ] >> \o ...` that ExplodeCall and
|
|
600
|
-
// ExplodeCallReturn push onto the stack.
|
|
601
584
|
const createStackPushExpr = (
|
|
602
585
|
procedure: string,
|
|
603
586
|
pcTokens: PcalToken[],
|
|
@@ -627,8 +610,6 @@ const createStackPushExpr = (
|
|
|
627
610
|
return expr;
|
|
628
611
|
};
|
|
629
612
|
|
|
630
|
-
// The statements a call explodes into after its stack push: the parameters' and the procedure
|
|
631
|
-
// variables' initial values and the jump to the procedure's first label.
|
|
632
613
|
const createCallStmts = (
|
|
633
614
|
assign: PcalAssign,
|
|
634
615
|
entry: PcalProcedureEntry,
|
|
@@ -655,23 +636,19 @@ const createCallStmts = (
|
|
|
655
636
|
];
|
|
656
637
|
};
|
|
657
638
|
|
|
658
|
-
// CopyAndExplodeLastStmt's triple: the statements with their last one exploded, the labeled
|
|
659
|
-
// statements the explosion split off, and whether control falls off the end needing a pc update.
|
|
660
639
|
interface PcalExplodedStmts {
|
|
661
640
|
stmts: PcalStmt[];
|
|
662
641
|
labeledStmts: PcalLabeledStmt[];
|
|
663
642
|
needsGoto: boolean;
|
|
664
643
|
}
|
|
665
644
|
|
|
666
|
-
//
|
|
667
|
-
//
|
|
668
|
-
// original AST are exploded in place, as the Java does, so the original AST changes too.
|
|
645
|
+
// Statement lists nested in the original AST are exploded in place, as the Java does, so the
|
|
646
|
+
// original AST changes too.
|
|
669
647
|
const explodePcalAlgorithm = (
|
|
670
648
|
ast: PcalAlgorithm,
|
|
671
649
|
table: PcalSymbolTable,
|
|
672
650
|
omitPC: boolean,
|
|
673
651
|
): PcalAlgorithm => {
|
|
674
|
-
// The procedure being exploded, which a return comes from.
|
|
675
652
|
const context: { procedure: string | undefined } = { procedure: undefined };
|
|
676
653
|
|
|
677
654
|
const explodeCall = (call: PcalCall, next: string) => {
|
|
@@ -752,8 +729,6 @@ const explodePcalAlgorithm = (
|
|
|
752
729
|
return createCallStmts(assign, toEntry, stmt);
|
|
753
730
|
};
|
|
754
731
|
|
|
755
|
-
// PcalTranslate.CopyAndExplodeLastStmt: explodes the last statement of stmts in place, recursing
|
|
756
|
-
// into the branches of a trailing if, either or with.
|
|
757
732
|
const copyAndExplodeLastStmt = (stmts: PcalStmt[], next: string): PcalExplodedStmts => {
|
|
758
733
|
if (stmts.length === 0) return { stmts: [], labeledStmts: [], needsGoto: !omitPC };
|
|
759
734
|
const result: PcalExplodedStmts = { stmts, labeledStmts: [], needsGoto: false };
|
|
@@ -877,8 +852,6 @@ const explodePcalAlgorithm = (
|
|
|
877
852
|
explodeLabeledStmt(labeledStmt, index < seq.length - 1 ? seq[index + 1].label : next),
|
|
878
853
|
);
|
|
879
854
|
|
|
880
|
-
// PcalTranslate.ExplodeWhile: the loop's label tests the condition, running the unlabeled body
|
|
881
|
-
// or the statements after the loop.
|
|
882
855
|
const explodeWhile = (labeledStmt: PcalLabeledStmt, loop: PcalWhile, next: string) => {
|
|
883
856
|
const unlabDoNext = loop.labDo.length === 0 ? labeledStmt.label : loop.labDo[0].label;
|
|
884
857
|
const explodedBody = copyAndExplodeLastStmtWithGoto([...loop.unlabDo], unlabDoNext);
|
|
@@ -1024,10 +997,7 @@ const explodePcalAlgorithm = (
|
|
|
1024
997
|
};
|
|
1025
998
|
};
|
|
1026
999
|
|
|
1027
|
-
//
|
|
1028
|
-
// there are variables, and GenAssign's sorting of multiple assignments and its checks that each
|
|
1029
|
-
// variable is declared and assigned at most once per step. Changed counts the assignments to each
|
|
1030
|
-
// variable along the paths through a labeled statement.
|
|
1000
|
+
// Only the parts of PcalTLAGen.generate that change the AST or throw.
|
|
1031
1001
|
const checkPcalTlaGen = (explodedAst: PcalAlgorithm, omitPC: boolean) => {
|
|
1032
1002
|
const vars = omitPC ? [] : ["pc"];
|
|
1033
1003
|
vars.push(...explodedAst.decls.map((decl) => decl.var));
|
|
@@ -1041,7 +1011,7 @@ const checkPcalTlaGen = (explodedAst: PcalAlgorithm, omitPC: boolean) => {
|
|
|
1041
1011
|
}
|
|
1042
1012
|
if (vars.length === 0) throw new PcalError("The algorithm has no variables.");
|
|
1043
1013
|
|
|
1044
|
-
// Changed.Set
|
|
1014
|
+
// Changed.Set counts only the first of duplicate variable names.
|
|
1045
1015
|
const setChanged = (changed: number[], variable: string) => {
|
|
1046
1016
|
const index = vars.indexOf(variable);
|
|
1047
1017
|
if (index === -1) return 0;
|
|
@@ -1063,7 +1033,6 @@ const checkPcalTlaGen = (explodedAst: PcalAlgorithm, omitPC: boolean) => {
|
|
|
1063
1033
|
const genAssign = (assign: PcalAssign, changed: number[]) => {
|
|
1064
1034
|
const thisChanged = [...changed];
|
|
1065
1035
|
assign.ass = sortSass(assign.ass);
|
|
1066
|
-
// The sort puts the assignments to each variable next to each other.
|
|
1067
1036
|
new Set(assign.ass.map((single) => single.lhs.var)).forEach((variable) => {
|
|
1068
1037
|
const group = assign.ass.filter((single) => single.lhs.var === variable);
|
|
1069
1038
|
if (!vars.includes(variable)) {
|
|
@@ -1134,9 +1103,8 @@ const checkPcalTlaGen = (explodedAst: PcalAlgorithm, omitPC: boolean) => {
|
|
|
1134
1103
|
).forEach(genBody);
|
|
1135
1104
|
};
|
|
1136
1105
|
|
|
1137
|
-
//
|
|
1138
|
-
//
|
|
1139
|
-
// PcalTLAGen makes while generating the TLA+ translation, which SANY discards.
|
|
1106
|
+
// What removeNameConflicts and translate do to the AST, and the errors they report, without the
|
|
1107
|
+
// TLA+ translation, which SANY discards.
|
|
1140
1108
|
export const translatePcalAlgorithm = (
|
|
1141
1109
|
ast: PcalAlgorithm,
|
|
1142
1110
|
omitPC: boolean,
|
package/src/pcal/validate.ts
CHANGED
|
@@ -11,7 +11,6 @@ import { createPcalCharReader } from "./tokenize";
|
|
|
11
11
|
import { translatePcalAlgorithm } from "./translate";
|
|
12
12
|
import type { TlcVersion } from "../tlc/version";
|
|
13
13
|
|
|
14
|
-
// Validator.ValidationResult.
|
|
15
14
|
type PcalValidationResult =
|
|
16
15
|
| "NO_PLUSCAL_EXISTS"
|
|
17
16
|
| "NO_TRANSLATION_EXISTS"
|
|
@@ -29,15 +28,14 @@ const CHECKSUM_PATTERN = new RegExp(
|
|
|
29
28
|
`\\\\\\* BEGIN TRANSLATION${SPACE}+\\(${SPACE}*([cC][hH]([eE][cC])?[kK][sS][uU][mM]\\([pP]([lL][uU][sS])?[cC][aA][lL]\\))${SPACE}*(=${SPACE}*"(?<pcal>[0-9A-Fa-f]*)"|\\\\in${SPACE}*STRING)${SPACE}*\\/\\\\${SPACE}*([cC][hH]([eE][cC])?[kK][sS][uU][mM]\\([tT][lL][aA]\\+?\\))${SPACE}*(=${SPACE}*"(?<tla>[0-9A-Fa-f]*)"|\\\\in${SPACE}*STRING)${SPACE}*\\)`,
|
|
30
29
|
);
|
|
31
30
|
|
|
32
|
-
//
|
|
33
|
-
//
|
|
31
|
+
// CRC32 in Long.toHexString's unpadded lowercase hex. Only a spec with PlusCal needs node:zlib,
|
|
32
|
+
// so it loads then rather than at startup.
|
|
34
33
|
const getChecksum = (text: string) =>
|
|
35
34
|
process.getBuiltinModule("node:zlib").crc32(Buffer.from(text, "utf8")).toString(16);
|
|
36
35
|
|
|
37
36
|
const reportUnrecoverableError = (session: PcalSession, message: string) =>
|
|
38
37
|
session.log(`\nUnrecoverable error:\n -- ${message}.\n`);
|
|
39
38
|
|
|
40
|
-
// PcalDebug.reportError: an UnrecoverablePositionedException names its statement's position.
|
|
41
39
|
const reportPcalError = (session: PcalSession, error: PcalError) =>
|
|
42
40
|
reportUnrecoverableError(
|
|
43
41
|
session,
|
|
@@ -57,7 +55,6 @@ const removeTabs = (lines: string[]) =>
|
|
|
57
55
|
)} `,
|
|
58
56
|
);
|
|
59
57
|
|
|
60
|
-
// trans.findTokenPair: the first line from start with first followed by second after spaces.
|
|
61
58
|
const findTokenPair = (lines: string[], start: number, first: string, second: string) => {
|
|
62
59
|
for (let index = Math.max(start, 0); index < lines.length; index++) {
|
|
63
60
|
const line = lines[index];
|
|
@@ -75,8 +72,6 @@ interface PcalSearchLocation {
|
|
|
75
72
|
column: number;
|
|
76
73
|
}
|
|
77
74
|
|
|
78
|
-
// ParseAlgorithm.GotoNextNonSpace: moves the location to the next character that isn't a space,
|
|
79
|
-
// returning its line, or "" past the last line.
|
|
80
75
|
const gotoNextNonSpace = (lines: string[], location: PcalSearchLocation) => {
|
|
81
76
|
while (location.line < lines.length) {
|
|
82
77
|
const line = lines[location.line];
|
|
@@ -88,8 +83,6 @@ const gotoNextNonSpace = (lines: string[], location: PcalSearchLocation) => {
|
|
|
88
83
|
return "";
|
|
89
84
|
};
|
|
90
85
|
|
|
91
|
-
// ParseAlgorithm.NextSpaceCol and NextDelimiterCol: the first delimiter from column on, or the
|
|
92
|
-
// end of the line.
|
|
93
86
|
const getNextDelimiter = (line: string, column: number, delimiters: string) => {
|
|
94
87
|
const index = Array.from(line.slice(column)).findIndex((char) => delimiters.includes(char));
|
|
95
88
|
return index === -1 ? line.length : column + line.slice(column, column + index).length;
|
|
@@ -97,8 +90,6 @@ const getNextDelimiter = (line: string, column: number, delimiters: string) => {
|
|
|
97
90
|
|
|
98
91
|
const isIdChar = (char: string) => /^[\p{L}\p{Nd}_]$/u.test(char);
|
|
99
92
|
|
|
100
|
-
// ParseAlgorithm.FindToken: moves the location past the next occurrence of token that starts a
|
|
101
|
-
// word and isn't followed by a letter or "_".
|
|
102
93
|
const findToken = (lines: string[], location: PcalSearchLocation, token: string) => {
|
|
103
94
|
while (location.line < lines.length) {
|
|
104
95
|
const line = gotoNextNonSpace(lines, location);
|
|
@@ -114,12 +105,10 @@ const findToken = (lines: string[], location: PcalSearchLocation, token: string)
|
|
|
114
105
|
return false;
|
|
115
106
|
};
|
|
116
107
|
|
|
117
|
-
// trans.CommandLineError.
|
|
118
108
|
const reportCommandLineError = (session: PcalSession, message: string) =>
|
|
119
109
|
reportUnrecoverableError(session, `Command-line error: ${message}`);
|
|
120
110
|
|
|
121
|
-
//
|
|
122
|
-
// translator's options for the rest of SANY's run.
|
|
111
|
+
// These options set the translator's options for the rest of SANY's run.
|
|
123
112
|
const processOptionArguments = (session: PcalSession, args: string[]) => {
|
|
124
113
|
const params = session.params;
|
|
125
114
|
const fairness = { isFirst: true, isExplicitNof: false };
|
|
@@ -208,7 +197,6 @@ const processOptionArguments = (session: PcalSession, args: string[]) => {
|
|
|
208
197
|
reportCommandLineError(session, "Version number must follow `-version' option");
|
|
209
198
|
return;
|
|
210
199
|
}
|
|
211
|
-
// PcalParams.ProcessVersion.
|
|
212
200
|
const version = getPcalVersionNumber(argument);
|
|
213
201
|
if (version < 0 || version > PCAL_VERSION_WEIGHT) {
|
|
214
202
|
reportUnrecoverableError(
|
|
@@ -248,7 +236,6 @@ const processOptionArguments = (session: PcalSession, args: string[]) => {
|
|
|
248
236
|
}
|
|
249
237
|
};
|
|
250
238
|
|
|
251
|
-
// ParseAlgorithm.ProcessOptions: the location is just past "PlusCal".
|
|
252
239
|
const processOptions = (session: PcalSession, lines: string[], location: PcalSearchLocation) => {
|
|
253
240
|
gotoNextNonSpace(lines, location);
|
|
254
241
|
location.column += "options".length;
|
|
@@ -277,9 +264,6 @@ const processOptions = (session: PcalSession, lines: string[], location: PcalSea
|
|
|
277
264
|
processOptionArguments(session, args);
|
|
278
265
|
};
|
|
279
266
|
|
|
280
|
-
// ParseAlgorithm.uncomment: blanks out the comment delimiters and nested comments from the
|
|
281
|
-
// algorithm's start to the "*)" that ends the comment it is in, dropping the rest of that line,
|
|
282
|
-
// and returns the error it throws for a line that ends in a string.
|
|
283
267
|
const uncomment = (lines: string[], startLine: number, startColumn: number) => {
|
|
284
268
|
const scan = { depth: 0, isDone: false, isInString: false };
|
|
285
269
|
for (let index = startLine; !scan.isDone && index < lines.length; index++) {
|
|
@@ -338,8 +322,6 @@ const throwIndexOutOfBounds = (index: number, size: number): never => {
|
|
|
338
322
|
);
|
|
339
323
|
};
|
|
340
324
|
|
|
341
|
-
// Validator.validate: checks the PlusCal algorithm of the module whose lines are given, from its
|
|
342
|
-
// first to its last, against the checksums its translation records.
|
|
343
325
|
export const validatePcalModule = (
|
|
344
326
|
session: PcalSession,
|
|
345
327
|
specificationText: string[],
|
package/src/pretty-print.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
// A port of TLC's tlc2.pprint package
|
|
2
|
-
// lines of at most 80 columns. TLC prints the original text whenever the parse fails.
|
|
1
|
+
// A port of TLC's tlc2.pprint package. TLC prints the original text whenever the parse fails.
|
|
3
2
|
|
|
4
3
|
import { skipWhile } from "./lexer";
|
|
5
4
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// Worker threads that decide the obligations prove sends them, the earliest obligation first.
|
|
2
|
-
|
|
3
1
|
import { TlaProverError } from "../errors";
|
|
4
2
|
import { spawnWorker, type WorkerHandle } from "../worker";
|
|
5
3
|
import type { DecideOptions, Decision } from "./verdict";
|
|
@@ -10,8 +8,6 @@ export interface DecideRequest {
|
|
|
10
8
|
timeLimitMs: number;
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
// A backend's decision, or the message of the TlaProverError it threw, which prove turns into a
|
|
14
|
-
// result.
|
|
15
11
|
export type DecideResponse = Decision | { error: string };
|
|
16
12
|
|
|
17
13
|
interface PendingDecision {
|
|
@@ -28,7 +24,6 @@ export interface DecidePool {
|
|
|
28
24
|
options: DecideOptions,
|
|
29
25
|
priority: number,
|
|
30
26
|
) => Promise<Decision>;
|
|
31
|
-
// Rejects every decision not yet made with reason, and stops the workers.
|
|
32
27
|
terminate: (reason: unknown) => void;
|
|
33
28
|
}
|
|
34
29
|
|
|
@@ -37,7 +32,7 @@ export const createDecidePool = async (workerCount: number): Promise<DecidePool>
|
|
|
37
32
|
const queue: PendingDecision[] = [];
|
|
38
33
|
const running = new Map<number, PendingDecision>();
|
|
39
34
|
const idle: number[] = [];
|
|
40
|
-
|
|
35
|
+
let failure: { reason: unknown } | undefined;
|
|
41
36
|
const dispatch = () => {
|
|
42
37
|
while (idle.length > 0 && queue.length > 0) {
|
|
43
38
|
const earliest = queue.reduce(
|
|
@@ -60,15 +55,15 @@ export const createDecidePool = async (workerCount: number): Promise<DecidePool>
|
|
|
60
55
|
dispatch();
|
|
61
56
|
};
|
|
62
57
|
const terminate = (reason: unknown) => {
|
|
63
|
-
if (
|
|
64
|
-
|
|
58
|
+
if (failure) return;
|
|
59
|
+
failure = { reason };
|
|
65
60
|
[...queue.splice(0), ...running.values()].forEach((decision) => decision.reject(reason));
|
|
66
61
|
running.clear();
|
|
67
62
|
workers.forEach((worker) => worker.terminate());
|
|
68
63
|
};
|
|
69
64
|
workers.push(
|
|
70
65
|
...(await Promise.all(
|
|
71
|
-
Array.from({ length: workerCount }, (
|
|
66
|
+
Array.from({ length: workerCount }, (_value, index) =>
|
|
72
67
|
spawnWorker(
|
|
73
68
|
new URL("./prove-worker.js", import.meta.url),
|
|
74
69
|
(message) => onResponse(index, message),
|
|
@@ -81,7 +76,7 @@ export const createDecidePool = async (workerCount: number): Promise<DecidePool>
|
|
|
81
76
|
return {
|
|
82
77
|
decide: (prover, text, options, priority) =>
|
|
83
78
|
new Promise((resolve, reject) => {
|
|
84
|
-
if (
|
|
79
|
+
if (failure) return reject(failure.reason);
|
|
85
80
|
queue.push({
|
|
86
81
|
request: { prover, text, timeLimitMs: options.timeLimitMs },
|
|
87
82
|
priority,
|
package/src/prover/deciders.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// How each of tla-ts's backends decides the text tlapm would send its prover, by the prover of the
|
|
2
|
-
// method that selects it.
|
|
3
|
-
|
|
4
1
|
import { SmtParseError, TlaProverError } from "../errors";
|
|
5
2
|
import { decideIsabelle } from "./isabelle/decide";
|
|
6
3
|
import { decidePtl } from "./ptl/decide";
|
|
@@ -8,7 +5,6 @@ import { decideSmt } from "./smt/solver/solver";
|
|
|
8
5
|
import type { DecideOptions, Decision, Verdict } from "./verdict";
|
|
9
6
|
import { decideZenon } from "./zenon/decide";
|
|
10
7
|
|
|
11
|
-
// Z3 rejects malformed input with an error, and tlapm counts that as a failure.
|
|
12
8
|
const decideZ3 = (text: string, options: DecideOptions) => {
|
|
13
9
|
try {
|
|
14
10
|
return decideSmt(text, options);
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// What backend/zenon.ml and backend/isabelle.ml share in printing an obligation that Backend.Prep
|
|
2
|
-
// has shipped.
|
|
3
|
-
|
|
4
1
|
import { TlapmBugError, TlaProverError, TlaUnsupportedError } from "../errors";
|
|
5
2
|
import { popNames, type Context } from "../obligations/printer";
|
|
6
3
|
import { shiftExpr } from "../obligations/substitution";
|
|
@@ -35,7 +32,6 @@ const CHARACTER_NAMES: Record<string, string> = {
|
|
|
35
32
|
"~": "tild_",
|
|
36
33
|
};
|
|
37
34
|
|
|
38
|
-
// isabelle_tlaplus_keys, then Isabelle_keywords.v, then other_keys.
|
|
39
35
|
const FORBIDDEN = new Set(
|
|
40
36
|
[
|
|
41
37
|
"All Append Bijections Case CaseArm CaseOther Char Choice EnumFuncSet Ex Fcn FuncSet INTER Id",
|
|
@@ -90,7 +86,6 @@ const getCharacterName = (character: string) => {
|
|
|
90
86
|
return name;
|
|
91
87
|
};
|
|
92
88
|
|
|
93
|
-
// Tla_parser.pickle: renames an identifier that some backend would reject.
|
|
94
89
|
export const pickle = (name: string) => {
|
|
95
90
|
const characters = [...name];
|
|
96
91
|
const isPlain =
|
|
@@ -102,7 +97,6 @@ export const pickle = (name: string) => {
|
|
|
102
97
|
return `a_${characters.map((character) => getCharacterName(character) ?? character).join("")}a`;
|
|
103
98
|
};
|
|
104
99
|
|
|
105
|
-
// The temporal operators neither backend has a counterpart for, by the name tlapm reports.
|
|
106
100
|
const TEMPORAL_OPERATORS: Partial<Record<Builtin, [string, number]>> = {
|
|
107
101
|
Leadsto: ["Leadsto", 2],
|
|
108
102
|
ENABLED: ["ENABLED", 1],
|
|
@@ -113,7 +107,6 @@ const TEMPORAL_OPERATORS: Partial<Record<Builtin, [string, number]>> = {
|
|
|
113
107
|
Diamond: ["<>", 1],
|
|
114
108
|
};
|
|
115
109
|
|
|
116
|
-
// Why a backend can't print an application of builtin, which it reports as where.
|
|
117
110
|
export const getUnprintableError = (builtin: Builtin, arity: number, where: string) => {
|
|
118
111
|
const isFrontend = builtin === "Prime" || builtin === "StrongPrime" || builtin === "UNCHANGED";
|
|
119
112
|
if (isFrontend && arity === 1) return new TlapmBugError();
|
|
@@ -128,8 +121,6 @@ interface SplitQuantifier {
|
|
|
128
121
|
inner: Expr;
|
|
129
122
|
}
|
|
130
123
|
|
|
131
|
-
// A quantifier's first bound binds around a quantifier over the others, which move under it. A
|
|
132
|
-
// ditto after the first bound copies its domain.
|
|
133
124
|
export const splitFirstBound = (
|
|
134
125
|
quantifier: "Forall" | "Exists",
|
|
135
126
|
bounds: Bound[],
|
|
@@ -161,8 +152,6 @@ export const splitFirstBound = (
|
|
|
161
152
|
};
|
|
162
153
|
};
|
|
163
154
|
|
|
164
|
-
// tlapm prints a fact to a formatter that drops its output first, to omit an unsupported one: the
|
|
165
|
-
// fact's print, or the error that omits it once the names it bound are out of scope.
|
|
166
155
|
export const printFact = <Printed>(context: Context, print: () => Printed) => {
|
|
167
156
|
const depth = context.stack.length;
|
|
168
157
|
try {
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// Decides a theory tlapm writes for Isabelle, as tlapm's Isabelle backend runs it: use_thy on the
|
|
2
|
-
// heap of Isabelle/TLA+ succeeds or fails.
|
|
3
|
-
|
|
4
1
|
import { isStackOverflow, TlaIsabelleError } from "../../errors";
|
|
5
2
|
import type { DecideOptions, Verdict } from "../verdict";
|
|
6
3
|
import { parseProofText, terminalProof } from "./isar/method";
|
|
@@ -28,7 +25,6 @@ export const decideIsabelle = (text: string, options: DecideOptions): Exclude<Ve
|
|
|
28
25
|
initGoal(statement),
|
|
29
26
|
),
|
|
30
27
|
);
|
|
31
|
-
// Proof.conclude_goal: the theorem must be the statement, from its assumptions only.
|
|
32
28
|
return result !== undefined &&
|
|
33
29
|
result.tpairs.length === 0 &&
|
|
34
30
|
aconv(result.prop, protect(statement.conclusion)) &&
|
|
@@ -36,8 +32,6 @@ export const decideIsabelle = (text: string, options: DecideOptions): Exclude<Ve
|
|
|
36
32
|
? "unsat"
|
|
37
33
|
: "unknown";
|
|
38
34
|
} catch (error) {
|
|
39
|
-
// Poly/ML grows its stack instead, until Isabelle runs out of memory, which tlapm counts as a
|
|
40
|
-
// failure.
|
|
41
35
|
if (error instanceof TlaIsabelleError || isStackOverflow(error)) return "unknown";
|
|
42
36
|
throw error;
|
|
43
37
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// Ported from tlapm's src/backend/isabelle.ml (BSD licensed, see LICENSE-tlapm).
|
|
2
|
-
// An obligation as the Isabelle/TLA+ theory tlapm writes for Isabelle to prove with a tactic.
|
|
3
2
|
|
|
4
3
|
import { TlapmBugError, TlaProverError, TlaUnsupportedError } from "../../errors";
|
|
5
4
|
import { createContext, getBoundName, popNames, pushName } from "../../obligations/printer";
|
|
@@ -79,7 +78,6 @@ const NONFIX: Partial<Record<Builtin, [string, number]>> = {
|
|
|
79
78
|
ToString: ["ToString", 1],
|
|
80
79
|
};
|
|
81
80
|
|
|
82
|
-
// thy_header's tdoms_table: the operators the theory declares, with their arities.
|
|
83
81
|
const DECLARED: [string, number][] = [
|
|
84
82
|
["Real", 0],
|
|
85
83
|
["/", 2],
|
|
@@ -105,7 +103,6 @@ const getSuccessors = (integer: string) => {
|
|
|
105
103
|
return `${"succ[".repeat(count)}0${"]".repeat(count)}`;
|
|
106
104
|
};
|
|
107
105
|
|
|
108
|
-
// thy_header.
|
|
109
106
|
const getTheoryHeader = (name: string, isVerbose: boolean) => [
|
|
110
107
|
"(* automatically generated -- do not edit manually *)",
|
|
111
108
|
`theory ${name} imports Constant Zenon begin`,
|
|
@@ -113,23 +110,20 @@ const getTheoryHeader = (name: string, isVerbose: boolean) => [
|
|
|
113
110
|
HEADER,
|
|
114
111
|
];
|
|
115
112
|
|
|
116
|
-
// pp_print_expr on an obligation after Backend.Prep has shipped it.
|
|
117
113
|
const printLemma = (sequent: Sequent) => {
|
|
118
114
|
const context = createContext();
|
|
119
115
|
const adjoin = (name: string) => pushName(context, pickle(name));
|
|
120
116
|
const bump = () => pushName(context, "");
|
|
121
117
|
|
|
122
|
-
// A binder's name binds in what prints inside it.
|
|
123
118
|
const withBound = (name: string, print: (bound: string) => string) => {
|
|
124
119
|
const printed = print(adjoin(name));
|
|
125
120
|
popNames(context, 1);
|
|
126
121
|
return printed;
|
|
127
122
|
};
|
|
128
123
|
|
|
129
|
-
// pp_print_expr: every expression, apart from the obligation's sequent, prints in parentheses.
|
|
130
124
|
const printExpr = (expression: Expr) => `(${formatExpr(expression)})`;
|
|
131
|
-
const
|
|
132
|
-
const
|
|
125
|
+
const printDelimited = (args: Expr[]) => args.map(printExpr).join(", ");
|
|
126
|
+
const printNonfix = (name: string, args: Expr[]) => `(${name} (${printDelimited(args)}))`;
|
|
133
127
|
|
|
134
128
|
const printInternal = (builtin: Builtin, args: Expr[]): string => {
|
|
135
129
|
const atom = ATOMS[builtin];
|
|
@@ -140,9 +134,8 @@ const printLemma = (sequent: Sequent) => {
|
|
|
140
134
|
if (binary !== undefined && args.length === 2)
|
|
141
135
|
return `(${printExpr(args[0])} ${binary} ${printExpr(args[1])})`;
|
|
142
136
|
const operator = NONFIX[builtin];
|
|
143
|
-
if (operator && operator[1] === args.length) return
|
|
137
|
+
if (operator && operator[1] === args.length) return printNonfix(operator[0], args);
|
|
144
138
|
if (builtin === "Unprimable" && args.length === 1) return printExpr(args[0]);
|
|
145
|
-
// tlapm prints an irregular expression as the hash of its TLA+ text, but never makes one.
|
|
146
139
|
if (builtin === "Irregular" && args.length === 1) throw new TlaUnsupportedError("Irregular");
|
|
147
140
|
throw getUnprintableError(builtin, args.length, "Backend.Isabelle.pp_apply");
|
|
148
141
|
};
|
|
@@ -152,11 +145,11 @@ const printLemma = (sequent: Sequent) => {
|
|
|
152
145
|
case "Ix": {
|
|
153
146
|
const name = getBoundName(context, operator.index);
|
|
154
147
|
if (operator.index <= 0 || name === undefined) throw new TlapmBugError();
|
|
155
|
-
return args.length === 0 ? name : `(${name} (${
|
|
148
|
+
return args.length === 0 ? name : `(${name} (${printDelimited(args)}))`;
|
|
156
149
|
}
|
|
157
150
|
case "Opaque": {
|
|
158
151
|
const name = pickle(operator.name);
|
|
159
|
-
return args.length === 0 ? `(${name} :: c)` : `(${name} (${
|
|
152
|
+
return args.length === 0 ? `(${name} :: c)` : `(${name} (${printDelimited(args)}) :: c)`;
|
|
160
153
|
}
|
|
161
154
|
case "Internal":
|
|
162
155
|
return printInternal(operator.builtin, args);
|
|
@@ -186,7 +179,6 @@ const printLemma = (sequent: Sequent) => {
|
|
|
186
179
|
);
|
|
187
180
|
};
|
|
188
181
|
|
|
189
|
-
// pp_print_sequent_inner: a sequent inside an expression, as a meta-level implication.
|
|
190
182
|
const printNestedSequent = (sequent: Sequent): string => {
|
|
191
183
|
if (sequent.context.length === 0) return printExpr(sequent.active);
|
|
192
184
|
const hyp = sequent.context[0];
|
|
@@ -279,7 +271,7 @@ const printLemma = (sequent: Sequent) => {
|
|
|
279
271
|
);
|
|
280
272
|
}
|
|
281
273
|
case "SetEnum":
|
|
282
|
-
return `{${
|
|
274
|
+
return `{${printDelimited(expression.elements)}}`;
|
|
283
275
|
case "Fcn": {
|
|
284
276
|
const bound = expression.bounds[0];
|
|
285
277
|
if (expression.bounds.length !== 1)
|
|
@@ -296,7 +288,7 @@ const printLemma = (sequent: Sequent) => {
|
|
|
296
288
|
const printedFunction = printExpr(expression.function);
|
|
297
289
|
return expression.args.length === 1
|
|
298
290
|
? `fapply (${printedFunction}, ${printExpr(expression.args[0])})`
|
|
299
|
-
: `fapply (${printedFunction}, <<${
|
|
291
|
+
: `fapply (${printedFunction}, <<${printDelimited(expression.args)}>>)`;
|
|
300
292
|
}
|
|
301
293
|
case "Arrow":
|
|
302
294
|
return `[${printExpr(expression.domain)} \\<rightarrow> ${printExpr(expression.range)}]`;
|
|
@@ -318,11 +310,11 @@ const printLemma = (sequent: Sequent) => {
|
|
|
318
310
|
case "Dot":
|
|
319
311
|
return `fapply (${printExpr(expression.expression)}, (''${expression.field}''))`;
|
|
320
312
|
case "Tuple":
|
|
321
|
-
return `<<${
|
|
313
|
+
return `<<${printDelimited(expression.elements)}>>`;
|
|
322
314
|
case "Product":
|
|
323
315
|
return expression.factors.length === 2
|
|
324
316
|
? `(${printExpr(expression.factors[0])} \\<times> ${printExpr(expression.factors[1])})`
|
|
325
|
-
: `Product(\\<langle>${
|
|
317
|
+
: `Product(\\<langle>${printDelimited(expression.factors)}\\<rangle>)`;
|
|
326
318
|
case "Sub":
|
|
327
319
|
case "Tsub": {
|
|
328
320
|
const suffix = expression.kind === "Sub" ? "sub" : "tsub";
|
|
@@ -332,8 +324,8 @@ const printLemma = (sequent: Sequent) => {
|
|
|
332
324
|
case "Fair":
|
|
333
325
|
return `${cook(expression.fairness === "Weak" ? "a'wf" : "a'sf")}(${printExpr(expression.subscript)},${printExpr(expression.action)})`;
|
|
334
326
|
case "Case": {
|
|
335
|
-
const conditions =
|
|
336
|
-
const bodies =
|
|
327
|
+
const conditions = printDelimited(expression.arms.map((arm) => arm.condition));
|
|
328
|
+
const bodies = printDelimited(expression.arms.map((arm) => arm.body));
|
|
337
329
|
return expression.other
|
|
338
330
|
? `CaseOther(<<${conditions}>>,<<${bodies}>>,${printExpr(expression.other)})`
|
|
339
331
|
: `Case(<<${conditions}>>,<<${bodies}>>)`;
|
|
@@ -348,8 +340,6 @@ const printLemma = (sequent: Sequent) => {
|
|
|
348
340
|
}
|
|
349
341
|
};
|
|
350
342
|
|
|
351
|
-
// pp_print_sequent_outer: the obligation's sequent as the lines of a lemma's fixes, assumes and
|
|
352
|
-
// shows. A pragma's definition ends it with an empty line in place of the goal.
|
|
353
343
|
const printSequent = (sequent: Sequent) => {
|
|
354
344
|
const lines: string[] = [];
|
|
355
345
|
for (const hyp of sequent.context) {
|
|
@@ -405,7 +395,6 @@ const printLemma = (sequent: Sequent) => {
|
|
|
405
395
|
}
|
|
406
396
|
};
|
|
407
397
|
|
|
408
|
-
// thy_temp: the theory tlapm writes for Isabelle to prove obligation id.
|
|
409
398
|
export const encodeIsabelle = (id: number, sequent: Sequent, tactic: string): string => {
|
|
410
399
|
const lemma = printLemma(sequent);
|
|
411
400
|
return [
|
|
@@ -427,7 +416,6 @@ interface IsabelleProof {
|
|
|
427
416
|
tactic: string;
|
|
428
417
|
}
|
|
429
418
|
|
|
430
|
-
// Isabelle.thy_init, thy_write and thy_close.
|
|
431
419
|
export const encodeIsabelleTheory = (name: string, proofs: IsabelleProof[]) =>
|
|
432
420
|
[
|
|
433
421
|
...getTheoryHeader(name, true),
|