tla-ts 0.0.10-dev.b4a856304 → 0.0.10-dev.c92e6a4ea
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 +2 -1
- package/dist/compile.cjs +6 -6
- package/dist/compile.js +10 -10
- package/dist/deciders.cjs +41 -37
- package/dist/deciders.js +57 -53
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +37 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +2683 -427
- package/dist/prove.js +2681 -425
- package/dist/run.cjs +45 -44
- package/dist/run.js +45 -44
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +44 -41
- package/dist/transfer.js +45 -42
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +41 -41
- package/src/bags.ts +2 -5
- package/src/builtins.ts +5 -21
- package/src/check-failure.ts +116 -0
- package/src/check-trace.ts +268 -0
- package/src/check.ts +578 -757
- package/src/cli/options.ts +6 -31
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +27 -62
- package/src/cli/shared.ts +1 -5
- package/src/cli/tlapm.ts +433 -70
- package/src/cli/tlc-arguments.ts +246 -240
- package/src/cli/tlc-output.ts +686 -0
- package/src/cli/tlc-usage.ts +3 -5
- package/src/cli/tlc.ts +59 -707
- package/src/cli/xml-exporter.ts +23 -33
- package/src/codegen.ts +5 -10
- package/src/coverage.ts +3 -10
- package/src/dependencies.ts +30 -14
- package/src/dfid.ts +16 -16
- package/src/environment-config.ts +315 -0
- package/src/environment.ts +73 -338
- package/src/errors.ts +33 -5
- package/src/evaluate.ts +34 -107
- package/src/exit-codes.ts +3 -0
- package/src/fingerprints.ts +65 -1
- package/src/instances.ts +47 -10
- package/src/java-hash.ts +7 -0
- package/src/java-overrides.ts +4 -9
- package/src/json-reader.ts +1 -2
- package/src/json.ts +8 -18
- package/src/levels.ts +46 -57
- package/src/lexer.ts +76 -85
- package/src/liveness-checker.ts +634 -306
- package/src/liveness.ts +104 -120
- package/src/obligations/action.ts +14 -17
- package/src/obligations/anonymize.ts +37 -16
- package/src/obligations/enabled-axioms.ts +218 -0
- package/src/obligations/equality.ts +1 -3
- package/src/obligations/expression.ts +36 -8
- package/src/obligations/format.ts +0 -2
- package/src/obligations/generate.ts +66 -54
- package/src/obligations/index.ts +38 -8
- package/src/obligations/levels.ts +24 -11
- package/src/obligations/module.ts +28 -41
- package/src/obligations/normalize.ts +26 -14
- package/src/obligations/operators.ts +0 -2
- package/src/obligations/pragma.ts +53 -16
- package/src/obligations/printer.ts +43 -13
- package/src/obligations/proof.ts +3 -2
- package/src/obligations/regroup.ts +0 -2
- package/src/obligations/simplify.ts +55 -50
- package/src/obligations/source.ts +118 -74
- package/src/obligations/subexpression.ts +45 -18
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +5 -7
- package/src/obligations/tuples.ts +0 -2
- package/src/parallel-worker.ts +17 -31
- package/src/parallel.ts +55 -80
- package/src/parser.ts +722 -385
- package/src/pcal/ast.ts +53 -65
- package/src/pcal/parse.ts +144 -191
- package/src/pcal/tokenize.ts +91 -115
- package/src/pcal/translate.ts +83 -98
- package/src/pcal/validate.ts +48 -50
- package/src/pretty-print.ts +7 -7
- package/src/prover/decide-pool.ts +3 -3
- package/src/prover/deciders.ts +12 -9
- package/src/prover/isabelle/decide.ts +3 -25
- package/src/prover/isabelle/encode.ts +72 -42
- package/src/prover/isabelle/isar/attrib.ts +250 -0
- package/src/prover/isabelle/isar/context.ts +335 -0
- package/src/prover/isabelle/isar/induct.ts +382 -0
- package/src/prover/isabelle/isar/inner-syntax.ts +158 -7
- package/src/prover/isabelle/isar/method.ts +509 -212
- package/src/prover/isabelle/isar/proof.ts +570 -14
- package/src/prover/isabelle/isar/rule-cases.ts +224 -0
- package/src/prover/isabelle/isar/theory.ts +487 -76
- package/src/prover/isabelle/isar/toplevel.ts +331 -0
- package/src/prover/isabelle/isar/type-check.ts +89 -14
- package/src/prover/isabelle/provers/blast/blast.ts +7 -65
- package/src/prover/isabelle/provers/blast/branch.ts +0 -2
- package/src/prover/isabelle/provers/blast/prove.ts +0 -2
- package/src/prover/isabelle/provers/blast/rules.ts +0 -2
- package/src/prover/isabelle/provers/blast/state.ts +0 -2
- package/src/prover/isabelle/provers/blast/term.ts +0 -2
- package/src/prover/isabelle/provers/clasimp.ts +0 -2
- package/src/prover/isabelle/provers/classical.ts +45 -20
- package/src/prover/isabelle/provers/hypsubst.ts +17 -28
- package/src/prover/isabelle/pure/bicompose.ts +9 -27
- package/src/prover/isabelle/pure/consts.ts +0 -2
- package/src/prover/isabelle/pure/conv.ts +2 -10
- package/src/prover/isabelle/pure/drule.ts +72 -6
- package/src/prover/isabelle/pure/envir.ts +0 -2
- package/src/prover/isabelle/pure/goal.ts +1 -3
- package/src/prover/isabelle/pure/logic.ts +1 -3
- package/src/prover/isabelle/pure/name.ts +0 -2
- package/src/prover/isabelle/pure/net.ts +0 -2
- package/src/prover/isabelle/pure/object-logic.ts +13 -7
- package/src/prover/isabelle/pure/pattern.ts +0 -2
- package/src/prover/isabelle/pure/raw-simplifier.ts +4 -15
- package/src/prover/isabelle/pure/rewriter.ts +6 -17
- package/src/prover/isabelle/pure/search.ts +0 -2
- package/src/prover/isabelle/pure/seq.ts +0 -2
- package/src/prover/isabelle/pure/simplifier.ts +26 -7
- package/src/prover/isabelle/pure/table.ts +2 -3
- package/src/prover/isabelle/pure/tactic.ts +0 -2
- package/src/prover/isabelle/pure/tactical.ts +42 -37
- package/src/prover/isabelle/pure/term-ord.ts +0 -2
- package/src/prover/isabelle/pure/term.ts +0 -2
- package/src/prover/isabelle/pure/thm.ts +14 -13
- package/src/prover/isabelle/pure/type.ts +0 -2
- package/src/prover/isabelle/pure/unify.ts +0 -2
- package/src/prover/isabelle/pure/variable.ts +0 -2
- package/src/prover/isabelle/tla/classical-setup.ts +18 -16
- package/src/prover/isabelle/tla/context.ts +58 -11
- package/src/prover/isabelle/tla/logic-data.ts +1 -1
- package/src/prover/isabelle/tla/logic.ts +49 -21
- package/src/prover/isabelle/tla/simpdata.ts +1 -12
- package/src/prover/isabelle/tools/intuitionistic.ts +28 -12
- package/src/prover/ocaml.ts +4 -1
- package/src/prover/prep/action.ts +30 -31
- package/src/prover/prep/enabled-axioms.ts +11 -2
- package/src/prover/prep/fingerprint.ts +2 -5
- package/src/prover/prep/methods.ts +181 -51
- package/src/prover/prep/normalize.ts +38 -9
- package/src/prover/prove.ts +395 -94
- package/src/prover/ptl/decide.ts +95 -50
- package/src/prover/ptl/encode.ts +2 -3
- package/src/prover/ptl/tableau.ts +28 -2
- package/src/prover/smt/arithmetic.ts +310 -0
- package/src/prover/smt/axioms.ts +12 -8
- package/src/prover/smt/context.ts +43 -8
- package/src/prover/smt/data.ts +498 -379
- package/src/prover/smt/encode.ts +148 -57
- package/src/prover/smt/extensionality.ts +5 -3
- package/src/prover/smt/flatten.ts +4 -6
- package/src/prover/smt/format.ts +28 -4
- package/src/prover/smt/instances.ts +7 -1
- package/src/prover/smt/layout.ts +91 -0
- package/src/prover/smt/rewrite.ts +1021 -618
- package/src/prover/smt/simplify.ts +441 -0
- package/src/prover/smt/solver/ackermannize-bv-tactic.ts +61 -0
- package/src/prover/smt/solver/ackr-helper.ts +179 -0
- package/src/prover/smt/solver/ackr-model-converter.ts +105 -0
- package/src/prover/smt/solver/act-cache.ts +0 -1
- package/src/prover/smt/solver/add-bounds-tactic.ts +59 -0
- package/src/prover/smt/solver/aig-tactic.ts +52 -0
- package/src/prover/smt/solver/aig.ts +889 -0
- package/src/prover/smt/solver/arith-rewriter.ts +613 -6
- package/src/prover/smt/solver/arith-terms.ts +121 -0
- package/src/prover/smt/solver/array-decl-plugin.ts +175 -0
- package/src/prover/smt/solver/array-rewriter.ts +309 -0
- package/src/prover/smt/solver/asserted-formulas.ts +87 -16
- package/src/prover/smt/solver/ast-lt.ts +166 -12
- package/src/prover/smt/solver/ast-util.ts +160 -2
- package/src/prover/smt/solver/ast.ts +1427 -41
- package/src/prover/smt/solver/auf-solver.ts +2 -6
- package/src/prover/smt/solver/bit-blast-tactic.ts +582 -0
- package/src/prover/smt/solver/bit-blaster.ts +871 -0
- package/src/prover/smt/solver/bound-manager.ts +196 -0
- package/src/prover/smt/solver/bound-simplifier.ts +600 -0
- package/src/prover/smt/solver/bv-bound-chk.ts +492 -0
- package/src/prover/smt/solver/bv-decl-plugin.ts +338 -0
- package/src/prover/smt/solver/bv-divrem-bounds.ts +95 -0
- package/src/prover/smt/solver/bv-rewriter.ts +1901 -0
- package/src/prover/smt/solver/bv1-blast.ts +214 -0
- package/src/prover/smt/solver/bv2fpa-converter.ts +174 -0
- package/src/prover/smt/solver/bv2int-rewriter.ts +544 -0
- package/src/prover/smt/solver/bv2real-rewriter.ts +533 -0
- package/src/prover/smt/solver/card2bv.ts +110 -0
- package/src/prover/smt/solver/case-split-queue.ts +0 -2
- package/src/prover/smt/solver/cg-table.ts +39 -25
- package/src/prover/smt/solver/check-logic.ts +330 -0
- package/src/prover/smt/solver/clause.ts +0 -1
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +278 -0
- package/src/prover/smt/solver/conflict-resolution.ts +78 -2
- package/src/prover/smt/solver/context.ts +516 -115
- package/src/prover/smt/solver/ctx-simplify.ts +20 -10
- package/src/prover/smt/solver/ctx-solver-simplify.ts +122 -0
- package/src/prover/smt/solver/datatype-decl-plugin.ts +572 -0
- package/src/prover/smt/solver/datatype-rewriter.ts +82 -0
- package/src/prover/smt/solver/demodulator.ts +786 -0
- package/src/prover/smt/solver/dependent-expr-state.ts +81 -0
- package/src/prover/smt/solver/der.ts +38 -10
- package/src/prover/smt/solver/diff-neq.ts +206 -0
- package/src/prover/smt/solver/distribute-forall.ts +57 -0
- package/src/prover/smt/solver/dom-simplify.ts +511 -0
- package/src/prover/smt/solver/dt2bv-tactic.ts +260 -0
- package/src/prover/smt/solver/dyn-ack.ts +0 -1
- package/src/prover/smt/solver/e-matching.ts +7 -8
- package/src/prover/smt/solver/elim-small-bv-tactic.ts +129 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +545 -0
- package/src/prover/smt/solver/enode.ts +100 -3
- package/src/prover/smt/solver/eq2bv-tactic.ts +218 -0
- package/src/prover/smt/solver/euf/arith-axioms.ts +403 -0
- package/src/prover/smt/solver/euf/arith-internalize.ts +653 -0
- package/src/prover/smt/solver/euf/arith-solver.ts +889 -0
- package/src/prover/smt/solver/euf/array-axioms.ts +527 -0
- package/src/prover/smt/solver/euf/array-internalize.ts +428 -0
- package/src/prover/smt/solver/euf/array-solver.ts +306 -0
- package/src/prover/smt/solver/euf/bv-ackerman.ts +162 -0
- package/src/prover/smt/solver/euf/bv-internalize.ts +748 -0
- package/src/prover/smt/solver/euf/bv-solver.ts +449 -0
- package/src/prover/smt/solver/euf/dt-solver.ts +618 -0
- package/src/prover/smt/solver/euf/egraph.ts +908 -0
- package/src/prover/smt/solver/euf/euf-solver.ts +1205 -0
- package/src/prover/smt/solver/euf/fpa-solver.ts +317 -0
- package/src/prover/smt/solver/euf/mam.ts +1050 -0
- package/src/prover/smt/solver/euf/q-ematch.ts +830 -0
- package/src/prover/smt/solver/euf/q-mbi.ts +587 -0
- package/src/prover/smt/solver/euf/q-model-fixer.ts +296 -0
- package/src/prover/smt/solver/euf/q-solver.ts +361 -0
- package/src/prover/smt/solver/euf/th-solver.ts +335 -0
- package/src/prover/smt/solver/euf/th-solvers.ts +30 -0
- package/src/prover/smt/solver/expr-ref.ts +0 -1
- package/src/prover/smt/solver/expr-safe-replace.ts +26 -2
- package/src/prover/smt/solver/expr2polynomial.ts +146 -0
- package/src/prover/smt/solver/factor.ts +141 -0
- package/src/prover/smt/solver/fd-solver.ts +265 -0
- package/src/prover/smt/solver/fingerprints.ts +15 -15
- package/src/prover/smt/solver/fix-dl-var.ts +148 -0
- package/src/prover/smt/solver/flat-literals.ts +0 -1
- package/src/prover/smt/solver/fm-tactic.ts +884 -0
- package/src/prover/smt/solver/fpa-decl-plugin.ts +618 -0
- package/src/prover/smt/solver/fpa-rewriter.ts +640 -0
- package/src/prover/smt/solver/fpa2bv-converter.ts +2249 -0
- package/src/prover/smt/solver/fpa2bv-rewriter.ts +348 -0
- package/src/prover/smt/solver/fpa2bv-tactic.ts +73 -0
- package/src/prover/smt/solver/goal.ts +175 -15
- package/src/prover/smt/solver/goal2nlsat.ts +189 -0
- package/src/prover/smt/solver/guard-set.ts +219 -0
- package/src/prover/smt/solver/hash.ts +0 -1
- package/src/prover/smt/solver/hashtable.ts +30 -16
- package/src/prover/smt/solver/inf-eps.ts +63 -0
- package/src/prover/smt/solver/inj-axiom.ts +101 -0
- package/src/prover/smt/solver/internalizer.ts +110 -38
- package/src/prover/smt/solver/lackr.ts +381 -0
- package/src/prover/smt/solver/lbool.ts +0 -1
- package/src/prover/smt/solver/lia2card.ts +268 -0
- package/src/prover/smt/solver/lia2pb.ts +154 -0
- package/src/prover/smt/solver/literal.ts +0 -1
- package/src/prover/smt/solver/logic-tactics.ts +345 -0
- package/src/prover/smt/solver/lp/bound-propagator.ts +0 -1
- package/src/prover/smt/solver/lp/constraints.ts +0 -1
- package/src/prover/smt/solver/lp/containers.ts +7 -2
- package/src/prover/smt/solver/lp/core-solver.ts +18 -3
- package/src/prover/smt/solver/lp/cross-nested.ts +1 -4
- package/src/prover/smt/solver/lp/dep-intervals.ts +0 -3
- package/src/prover/smt/solver/lp/dependency.ts +0 -2
- package/src/prover/smt/solver/lp/dioph-eq.ts +1 -10
- package/src/prover/smt/solver/lp/explanation.ts +0 -1
- package/src/prover/smt/solver/lp/gomory.ts +0 -1
- package/src/prover/smt/solver/lp/hnf-cutter.ts +1 -2
- package/src/prover/smt/solver/lp/hnf.ts +0 -3
- package/src/prover/smt/solver/lp/int-cube.ts +3 -4
- package/src/prover/smt/solver/lp/int-solver.ts +0 -2
- package/src/prover/smt/solver/lp/lar-solver.ts +40 -4
- package/src/prover/smt/solver/lp/lar-term.ts +0 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +0 -1
- package/src/prover/smt/solver/lp/maximize-term.ts +59 -10
- package/src/prover/smt/solver/lp/nex-creator.ts +3 -3
- package/src/prover/smt/solver/lp/nex.ts +2 -2
- package/src/prover/smt/solver/lp/nla-backoff.ts +0 -2
- package/src/prover/smt/solver/lp/nla-basics.ts +46 -3
- package/src/prover/smt/solver/lp/nla-core.ts +67 -16
- package/src/prover/smt/solver/lp/nla-divisions.ts +0 -2
- package/src/prover/smt/solver/lp/nla-emonics.ts +0 -1
- package/src/prover/smt/solver/lp/nla-factorization.ts +0 -1
- package/src/prover/smt/solver/lp/nla-grobner.ts +165 -83
- package/src/prover/smt/solver/lp/nla-horner.ts +0 -2
- package/src/prover/smt/solver/lp/nla-intervals.ts +0 -1
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +0 -2
- package/src/prover/smt/solver/lp/nla-monotone.ts +0 -1
- package/src/prover/smt/solver/lp/nla-order.ts +0 -2
- package/src/prover/smt/solver/lp/nla-patcher.ts +0 -1
- package/src/prover/smt/solver/lp/nla-powers.ts +220 -0
- package/src/prover/smt/solver/lp/nla-tangents.ts +0 -2
- package/src/prover/smt/solver/lp/nla-throttle.ts +0 -1
- package/src/prover/smt/solver/lp/nla-transcendentals.ts +324 -0
- package/src/prover/smt/solver/lp/nla-types.ts +0 -2
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +0 -1
- package/src/prover/smt/solver/lp/nra-solver.ts +122 -64
- package/src/prover/smt/solver/lp/numeric-pair.ts +0 -1
- package/src/prover/smt/solver/lp/pdd-interval.ts +6 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +60 -21
- package/src/prover/smt/solver/lp/pdd-solver.ts +72 -41
- package/src/prover/smt/solver/lp/pdd.ts +725 -289
- package/src/prover/smt/solver/lp/random-updater.ts +0 -2
- package/src/prover/smt/solver/lp/static-matrix.ts +0 -1
- package/src/prover/smt/solver/lp/union-find.ts +7 -2
- package/src/prover/smt/solver/macro-finder.ts +530 -0
- package/src/prover/smt/solver/mam-compiler.ts +122 -90
- package/src/prover/smt/solver/mam-interpreter.ts +0 -1
- package/src/prover/smt/solver/max-bv-sharing-tactic.ts +17 -0
- package/src/prover/smt/solver/max-cliques.ts +105 -0
- package/src/prover/smt/solver/maxcore.ts +309 -0
- package/src/prover/smt/solver/maximize-ac-sharing.ts +8 -6
- package/src/prover/smt/solver/maxlex.ts +115 -0
- package/src/prover/smt/solver/maxsmt-base.ts +105 -0
- package/src/prover/smt/solver/maxsmt.ts +92 -0
- package/src/prover/smt/solver/mbp/mbp-arith.ts +467 -0
- package/src/prover/smt/solver/mbp/mbp-basic-tg.ts +101 -0
- package/src/prover/smt/solver/mbp/mbp-plugin.ts +287 -0
- package/src/prover/smt/solver/mbp/mbp-qel.ts +48 -0
- package/src/prover/smt/solver/mbp/mbp-solve-plugin.ts +271 -0
- package/src/prover/smt/solver/mbp/mbp-term-graph.ts +606 -0
- package/src/prover/smt/solver/model-based-opt.ts +844 -0
- package/src/prover/smt/solver/model-checker.ts +18 -27
- package/src/prover/smt/solver/model-evaluator.ts +188 -12
- package/src/prover/smt/solver/model-finder.ts +12 -18
- package/src/prover/smt/solver/model-generator.ts +56 -29
- package/src/prover/smt/solver/model-macro-solver.ts +49 -46
- package/src/prover/smt/solver/model-printer.ts +214 -0
- package/src/prover/smt/solver/mpf.ts +711 -0
- package/src/prover/smt/solver/mus.ts +51 -0
- package/src/prover/smt/solver/muz/dl-context.ts +404 -0
- package/src/prover/smt/solver/muz/dl-mk-bit-blast.ts +97 -0
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +167 -0
- package/src/prover/smt/solver/muz/dl-mk-elim-term-ite.ts +125 -0
- package/src/prover/smt/solver/muz/dl-mk-interp-tail-simplifier.ts +299 -0
- package/src/prover/smt/solver/muz/dl-mk-rule-inliner.ts +455 -0
- package/src/prover/smt/solver/muz/dl-mk-slice.ts +340 -0
- package/src/prover/smt/solver/muz/dl-mk-subsumption-checker.ts +163 -0
- package/src/prover/smt/solver/muz/dl-rule-set.ts +273 -0
- package/src/prover/smt/solver/muz/dl-rule-transformer.ts +123 -0
- package/src/prover/smt/solver/muz/dl-rule.ts +496 -0
- package/src/prover/smt/solver/muz/hnf.ts +201 -0
- package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +176 -0
- package/src/prover/smt/solver/muz/horn-tactic.ts +201 -0
- package/src/prover/smt/solver/muz/rule-properties.ts +337 -0
- package/src/prover/smt/solver/muz/spacer-context.ts +1406 -0
- package/src/prover/smt/solver/muz/spacer-dl-interface.ts +52 -0
- package/src/prover/smt/solver/muz/spacer-generalizers.ts +241 -0
- package/src/prover/smt/solver/muz/spacer-manager.ts +127 -0
- package/src/prover/smt/solver/muz/spacer-pdr.ts +218 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +333 -0
- package/src/prover/smt/solver/muz/spacer-util.ts +282 -0
- package/src/prover/smt/solver/muz/substitution.ts +203 -0
- package/src/prover/smt/solver/nla2bv-tactic.ts +285 -0
- package/src/prover/smt/solver/nlqsat.ts +484 -0
- package/src/prover/smt/solver/nlsat/algebraic.ts +125 -12
- package/src/prover/smt/solver/nlsat/atoms.ts +20 -6
- package/src/prover/smt/solver/nlsat/evaluator.ts +0 -1
- package/src/prover/smt/solver/nlsat/explain.ts +63 -23
- package/src/prover/smt/solver/nlsat/interval-set.ts +1 -2
- package/src/prover/smt/solver/nlsat/levelwise.ts +3 -9
- package/src/prover/smt/solver/nlsat/mpbq.ts +45 -1
- package/src/prover/smt/solver/nlsat/polynomial.ts +13 -6
- package/src/prover/smt/solver/nlsat/solver.ts +236 -45
- package/src/prover/smt/solver/nlsat/transcendental-eval.ts +310 -0
- package/src/prover/smt/solver/nlsat/transcendentals.ts +367 -0
- package/src/prover/smt/solver/nlsat/types.ts +0 -2
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -4
- package/src/prover/smt/solver/nlsat/upolynomial.ts +0 -2
- package/src/prover/smt/solver/nlsat-tactic.ts +82 -0
- package/src/prover/smt/solver/nnf.ts +105 -23
- package/src/prover/smt/solver/normalize-bounds.ts +53 -0
- package/src/prover/smt/solver/occf.ts +97 -0
- package/src/prover/smt/solver/opt-context.ts +787 -0
- package/src/prover/smt/solver/opt-nlsat.ts +375 -0
- package/src/prover/smt/solver/opt-pareto.ts +282 -0
- package/src/prover/smt/solver/opt-preprocess.ts +101 -0
- package/src/prover/smt/solver/opt-solver.ts +308 -0
- package/src/prover/smt/solver/opt-value.ts +55 -0
- package/src/prover/smt/solver/optsmt.ts +692 -0
- package/src/prover/smt/solver/parallel-tactic.ts +299 -0
- package/src/prover/smt/solver/pattern-inference.ts +19 -11
- package/src/prover/smt/solver/pb-rewriter.ts +284 -0
- package/src/prover/smt/solver/pb2bv-tactic.ts +540 -0
- package/src/prover/smt/solver/poly-rewriter.ts +202 -57
- package/src/prover/smt/solver/probes.ts +512 -0
- package/src/prover/smt/solver/propagate-values.ts +37 -21
- package/src/prover/smt/solver/proto-model.ts +648 -19
- package/src/prover/smt/solver/pull-quant.ts +28 -12
- package/src/prover/smt/solver/purify-arith.ts +632 -0
- package/src/prover/smt/solver/qe-arith-plugin.ts +1098 -0
- package/src/prover/smt/solver/qe-lite-der.ts +2 -3
- package/src/prover/smt/solver/qe-lite-fm.ts +3 -4
- package/src/prover/smt/solver/qe-lite.ts +37 -17
- package/src/prover/smt/solver/qe-mbp.ts +270 -0
- package/src/prover/smt/solver/qe.ts +1498 -0
- package/src/prover/smt/solver/qel.ts +25 -0
- package/src/prover/smt/solver/qi-queue.ts +0 -1
- package/src/prover/smt/solver/qsat.ts +814 -0
- package/src/prover/smt/solver/quant-hoist.ts +196 -0
- package/src/prover/smt/solver/quant-tactics.ts +16 -56
- package/src/prover/smt/solver/quantifier-analyzer.ts +19 -20
- package/src/prover/smt/solver/quantifier-manager.ts +8 -16
- package/src/prover/smt/solver/quasi-macros.ts +243 -0
- package/src/prover/smt/solver/random-gen.ts +0 -1
- package/src/prover/smt/solver/rational.ts +45 -1
- package/src/prover/smt/solver/recfun-decl-plugin.ts +261 -0
- package/src/prover/smt/solver/recfun-rewriter.ts +107 -0
- package/src/prover/smt/solver/reduce-args.ts +225 -0
- package/src/prover/smt/solver/reduce-bv-size.ts +119 -0
- package/src/prover/smt/solver/ref-vector.ts +0 -1
- package/src/prover/smt/solver/relevancy.ts +1 -2
- package/src/prover/smt/solver/rewriter-tpl.ts +77 -10
- package/src/prover/smt/solver/rewriter.ts +475 -36
- package/src/prover/smt/solver/rlimit.ts +38 -2
- package/src/prover/smt/solver/sat/asymm-branch.ts +325 -0
- package/src/prover/smt/solver/sat/big.ts +177 -0
- package/src/prover/smt/solver/sat/clause-use-list.ts +71 -0
- package/src/prover/smt/solver/sat/clause.ts +203 -0
- package/src/prover/smt/solver/sat/cleaner.ts +94 -0
- package/src/prover/smt/solver/sat/config.ts +122 -0
- package/src/prover/smt/solver/sat/consequences.ts +203 -0
- package/src/prover/smt/solver/sat/elim-eqs.ts +142 -0
- package/src/prover/smt/solver/sat/goal2sat.ts +526 -0
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +378 -0
- package/src/prover/smt/solver/sat/model-converter.ts +136 -0
- package/src/prover/smt/solver/sat/pb-constraint.ts +261 -0
- package/src/prover/smt/solver/sat/pb-solver.ts +1577 -0
- package/src/prover/smt/solver/sat/probing.ts +170 -0
- package/src/prover/smt/solver/sat/sat-tactic.ts +43 -0
- package/src/prover/smt/solver/sat/sat2goal.ts +165 -0
- package/src/prover/smt/solver/sat/scc.ts +142 -0
- package/src/prover/smt/solver/sat/simplifier.ts +1618 -0
- package/src/prover/smt/solver/sat/solver.ts +2127 -0
- package/src/prover/smt/solver/sat/var-queue.ts +117 -0
- package/src/prover/smt/solver/sat/watch-list.ts +140 -0
- package/src/prover/smt/solver/search-tree.ts +284 -0
- package/src/prover/smt/solver/seq-axioms.ts +1010 -0
- package/src/prover/smt/solver/seq-decl-plugin.ts +819 -0
- package/src/prover/smt/solver/seq-derive.ts +1298 -0
- package/src/prover/smt/solver/seq-eq-approx.ts +236 -0
- package/src/prover/smt/solver/seq-eq-solver.ts +439 -0
- package/src/prover/smt/solver/seq-factory.ts +89 -0
- package/src/prover/smt/solver/seq-monadic.ts +728 -0
- package/src/prover/smt/solver/seq-range-predicate.ts +235 -0
- package/src/prover/smt/solver/seq-re-rewriter.ts +1170 -0
- package/src/prover/smt/solver/seq-re-util.ts +758 -0
- package/src/prover/smt/solver/seq-regex-bisim.ts +144 -0
- package/src/prover/smt/solver/seq-regex-live.ts +200 -0
- package/src/prover/smt/solver/seq-rewriter.ts +2402 -0
- package/src/prover/smt/solver/seq-skolem.ts +317 -0
- package/src/prover/smt/solver/seq-subset.ts +165 -0
- package/src/prover/smt/solver/seq-view-witness.ts +353 -0
- package/src/prover/smt/solver/smt-consequences.ts +297 -0
- package/src/prover/smt/solver/smt-kernel.ts +83 -0
- package/src/prover/smt/solver/smt-logics.ts +66 -0
- package/src/prover/smt/solver/smt-setup.ts +496 -0
- package/src/prover/smt/solver/smt2-printer.ts +765 -0
- package/src/prover/smt/solver/smtlib-parser.ts +3126 -316
- package/src/prover/smt/solver/smtlib-script.ts +1631 -0
- package/src/prover/smt/solver/solve-eqs.ts +929 -0
- package/src/prover/smt/solver/solver.ts +113 -22
- package/src/prover/smt/solver/static-features.ts +314 -0
- package/src/prover/smt/solver/sticky-generations.ts +0 -1
- package/src/prover/smt/solver/tactic.ts +1986 -0
- package/src/prover/smt/solver/term-enumeration.ts +205 -0
- package/src/prover/smt/solver/theory-array.ts +1240 -0
- package/src/prover/smt/solver/theory-bv.ts +1200 -0
- package/src/prover/smt/solver/theory-char.ts +355 -0
- package/src/prover/smt/solver/theory-datatype.ts +598 -0
- package/src/prover/smt/solver/theory-finite-set.ts +30 -0
- package/src/prover/smt/solver/theory-fpa.ts +389 -0
- package/src/prover/smt/solver/theory-lra-axioms.ts +53 -2
- package/src/prover/smt/solver/theory-lra-bounds.ts +31 -6
- package/src/prover/smt/solver/theory-lra-final-check.ts +56 -70
- package/src/prover/smt/solver/theory-lra-internalize.ts +94 -27
- package/src/prover/smt/solver/theory-lra-model.ts +20 -35
- package/src/prover/smt/solver/theory-lra-propagate.ts +24 -26
- package/src/prover/smt/solver/theory-lra-state.ts +6 -22
- package/src/prover/smt/solver/theory-lra.ts +188 -1
- package/src/prover/smt/solver/theory-pb.ts +934 -0
- package/src/prover/smt/solver/theory-polymorphism.ts +58 -0
- package/src/prover/smt/solver/theory-recfun.ts +307 -0
- package/src/prover/smt/solver/theory-seq-regex.ts +867 -0
- package/src/prover/smt/solver/theory-seq-solve.ts +1373 -0
- package/src/prover/smt/solver/theory-seq-state.ts +871 -0
- package/src/prover/smt/solver/theory-seq.ts +961 -0
- package/src/prover/smt/solver/theory.ts +189 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +485 -0
- package/src/prover/smt/solver/var-subst.ts +36 -14
- package/src/prover/smt/table.ts +3 -2
- package/src/prover/smt/types.ts +146 -0
- package/src/prover/tlapm/cache.ts +50 -19
- package/src/prover/tlapm/tlapm.ts +15 -9
- package/src/prover/tlapm-library.ts +3208 -0
- package/src/prover/verdict.ts +9 -0
- package/src/prover/zenon/check/check.ts +1 -2
- package/src/prover/zenon/check/records.ts +1 -1
- package/src/prover/zenon/check/relations.ts +2 -1
- package/src/prover/zenon/check/rewrites.ts +2 -15
- package/src/prover/zenon/check/sets.ts +40 -58
- package/src/prover/zenon/check/terms.ts +1 -2
- package/src/prover/zenon/decide.ts +10 -7
- package/src/prover/zenon/encode.ts +0 -2
- package/src/prover/zenon/eqrel.ts +2 -2
- package/src/prover/zenon/equality-rules.ts +24 -2
- package/src/prover/zenon/expr.ts +28 -2
- package/src/prover/zenon/index-table.ts +11 -21
- package/src/prover/zenon/isar-case.ts +0 -2
- package/src/prover/zenon/isar.ts +35 -37
- package/src/prover/zenon/llproof.ts +2 -13
- package/src/prover/zenon/mltoll.ts +12 -30
- package/src/prover/zenon/node.ts +20 -5
- package/src/prover/zenon/parse.ts +9 -8
- package/src/prover/zenon/phrase.ts +0 -2
- package/src/prover/zenon/proof.ts +0 -2
- package/src/prover/zenon/propositional-rules.ts +0 -2
- package/src/prover/zenon/rules.ts +2 -3
- package/src/prover/zenon/search.ts +11 -19
- package/src/prover/zenon/tla/functions.ts +2 -4
- package/src/prover/zenon/tla/llproof.ts +9 -13
- package/src/prover/zenon/tla/records.ts +1 -8
- package/src/prover/zenon/tla/rewrites.ts +0 -2
- package/src/prover/zenon/tla/sets.ts +22 -22
- package/src/prover/zenon/tla/terms.ts +0 -2
- package/src/prover/zenon/tla/tla.ts +7 -8
- package/src/randomization.ts +1 -4
- package/src/resolve.ts +67 -143
- package/src/runtime.ts +17 -18
- package/src/sany/builtins.ts +1 -3
- package/src/sany/generation.ts +394 -0
- package/src/sany/generator-def-entries.ts +210 -0
- package/src/sany/generator-definitions.ts +686 -0
- package/src/sany/generator-expressions.ts +1100 -0
- package/src/sany/generator-proofs.ts +662 -0
- package/src/sany/generator.ts +160 -2683
- package/src/sany/levels.ts +5 -11
- package/src/sany/lexer.ts +57 -60
- package/src/sany/linter.ts +0 -3
- package/src/sany/nodes.ts +6 -13
- package/src/sany/report.ts +3 -6
- package/src/sany/selectors.ts +35 -38
- package/src/sany/xml.ts +23 -55
- package/src/search.ts +244 -53
- package/src/simulate.ts +202 -184
- package/src/spec-description.ts +56 -82
- package/src/standard-definitions.ts +4 -3
- package/src/standard-modules.ts +17 -44
- package/src/state-graph.ts +3 -17
- package/src/subexpressions.ts +38 -47
- package/src/substitution-levels.ts +5 -4
- package/src/successors.ts +20 -43
- package/src/symmetry.ts +6 -21
- package/src/tableau.ts +2 -2
- package/src/tlc/fingerprint.ts +96 -30
- package/src/tlc/jar-data.ts +0 -1
- package/src/tlc/messages.ts +22 -36
- package/src/tlc/order.ts +36 -50
- package/src/tlc/random.ts +22 -34
- package/src/tlc/replay.ts +21 -48
- package/src/tlc/summary.ts +64 -58
- package/src/tlc/tlc-operators.ts +6 -17
- package/src/tlc/tlcext-operators.ts +70 -29
- package/src/tlc/trace-spec.ts +26 -51
- package/src/tlc/value-stream.ts +9 -13
- package/src/tlc/version.ts +0 -1
- package/src/typed-tier.ts +6535 -0
- package/src/typescript/actions.ts +2 -4
- package/src/typescript/collections.ts +34 -20
- package/src/typescript/compile.ts +1 -3
- package/src/typescript/formula.ts +5 -3
- package/src/typescript/model.ts +4 -5
- package/src/typescript/steps.ts +20 -18
- package/src/values.ts +136 -338
- package/src/prover/isabelle/isar/statement.ts +0 -52
- package/src/prover/smt/solver/z3-license.txt +0 -10
- package/src/prover/tlaps-module.ts +0 -510
- package/src/prover/zenon/LICENSE +0 -32
package/src/check.ts
CHANGED
|
@@ -9,10 +9,8 @@ import {
|
|
|
9
9
|
getCoverageReport,
|
|
10
10
|
type CoverageReport,
|
|
11
11
|
} from "./coverage";
|
|
12
|
-
import { createEnvironment } from "./environment";
|
|
13
12
|
import {
|
|
14
13
|
createStackOverflowError,
|
|
15
|
-
getErrorExitCode,
|
|
16
14
|
isStackOverflow,
|
|
17
15
|
TlaEvaluationError,
|
|
18
16
|
TlaIllegalStateError,
|
|
@@ -21,24 +19,36 @@ import {
|
|
|
21
19
|
TlaStackOverflowError,
|
|
22
20
|
UNEXPECTED_EVAL_EXCEPTION,
|
|
23
21
|
UNEXPECTED_EXCEPTION,
|
|
22
|
+
formatRange,
|
|
24
23
|
} from "./errors";
|
|
25
24
|
import {
|
|
26
|
-
createTracingEnvironment,
|
|
27
25
|
describeRange,
|
|
28
|
-
formatRange,
|
|
29
26
|
getDefinition,
|
|
30
|
-
isImpure,
|
|
31
27
|
type CallStack,
|
|
32
28
|
type Environment,
|
|
33
29
|
type FingerprintFailure,
|
|
34
30
|
} from "./evaluate";
|
|
31
|
+
import { EXIT_STATUS, setExitCode, withLivenessExitCode } from "./exit-codes";
|
|
32
|
+
import {
|
|
33
|
+
fingerprintReplayed,
|
|
34
|
+
getFailureExitCode,
|
|
35
|
+
getReplayFailure,
|
|
36
|
+
type FailureOptions,
|
|
37
|
+
} from "./check-failure";
|
|
38
|
+
import {
|
|
39
|
+
createTraceBuilder,
|
|
40
|
+
type Behavior,
|
|
41
|
+
type SearchPosition,
|
|
42
|
+
type TracedStep,
|
|
43
|
+
} from "./check-trace";
|
|
35
44
|
import {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
createStateTable,
|
|
46
|
+
findStateIndex,
|
|
47
|
+
getStateHash,
|
|
48
|
+
isSameState,
|
|
49
|
+
markSeenState,
|
|
50
|
+
type StateTable,
|
|
51
|
+
} from "./fingerprints";
|
|
42
52
|
import type { JavaOverride } from "./java-overrides";
|
|
43
53
|
import {
|
|
44
54
|
createLivenessChecker,
|
|
@@ -47,6 +57,7 @@ import {
|
|
|
47
57
|
type LiveSuccessor,
|
|
48
58
|
} from "./liveness-checker";
|
|
49
59
|
import {
|
|
60
|
+
createCheckEnvironment,
|
|
50
61
|
createMissingOperatorError,
|
|
51
62
|
createSearch,
|
|
52
63
|
getIncompleteSuccessorMessage,
|
|
@@ -58,11 +69,11 @@ import {
|
|
|
58
69
|
import {
|
|
59
70
|
getActionLabel,
|
|
60
71
|
getActionSignature,
|
|
61
|
-
|
|
62
|
-
getNextActions,
|
|
72
|
+
getSpecDescription,
|
|
63
73
|
getSpecificationValue,
|
|
64
74
|
toActionValue,
|
|
65
75
|
type SpecAction,
|
|
76
|
+
type SpecDescription,
|
|
66
77
|
} from "./spec-description";
|
|
67
78
|
import {
|
|
68
79
|
createStateWriter,
|
|
@@ -79,7 +90,6 @@ import {
|
|
|
79
90
|
type Successor,
|
|
80
91
|
} from "./successors";
|
|
81
92
|
import {
|
|
82
|
-
getCodedMessage,
|
|
83
93
|
getFailureMessage,
|
|
84
94
|
getWrappedException,
|
|
85
95
|
isEvalException,
|
|
@@ -90,9 +100,7 @@ import {
|
|
|
90
100
|
} from "./tlc/messages";
|
|
91
101
|
import { createTautologyError } from "./liveness";
|
|
92
102
|
import { KEY_SEPARATOR } from "./resolve";
|
|
93
|
-
import { setFingerprintPolynomial } from "./tlc/fingerprint";
|
|
94
103
|
import { writeTraceSpec } from "./tlc/trace-spec";
|
|
95
|
-
import { createTlcOrder } from "./tlc/order";
|
|
96
104
|
import {
|
|
97
105
|
getPrimedRanges,
|
|
98
106
|
replayInitialStates,
|
|
@@ -102,19 +110,15 @@ import {
|
|
|
102
110
|
import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc/summary";
|
|
103
111
|
import { createActionRecord, createCounterExample } from "./tlc/tlcext-operators";
|
|
104
112
|
import type { TlcVersion } from "./tlc/version";
|
|
113
|
+
import { runTypedSearch, type TypedResult } from "./typed-tier";
|
|
105
114
|
import {
|
|
106
|
-
combineHash,
|
|
107
115
|
createCanonicalizer,
|
|
108
116
|
createModelValue,
|
|
109
117
|
formatState,
|
|
110
118
|
getFingerprintError,
|
|
111
|
-
getHeldValues,
|
|
112
119
|
getModelValues,
|
|
113
|
-
getValueHash,
|
|
114
120
|
isSameValue,
|
|
115
121
|
markFingerprinted,
|
|
116
|
-
setStringOrder,
|
|
117
|
-
setValueOptions,
|
|
118
122
|
type Value,
|
|
119
123
|
} from "./values";
|
|
120
124
|
|
|
@@ -130,30 +134,32 @@ export interface CheckOptions {
|
|
|
130
134
|
makeDirectory?: (path: string) => void;
|
|
131
135
|
seed?: bigint;
|
|
132
136
|
workers?: number;
|
|
133
|
-
|
|
137
|
+
/** TLC's -lncheck: "final" checks liveness only on the complete graph, "off" never looks for a cycle. */
|
|
134
138
|
livenessCheck?: "default" | "final" | "off";
|
|
135
|
-
|
|
139
|
+
/** TLC's -fp: the index of the polynomial in TLC's FP64.Polys that fingerprints states. */
|
|
136
140
|
fingerprintPolynomial?: number;
|
|
137
|
-
|
|
141
|
+
/** False for TLC's -terse, which prints a lazy value, such as SUBSET S, without enumerating it. */
|
|
138
142
|
isLazyValueExpanded?: boolean;
|
|
139
|
-
|
|
143
|
+
/** TLC's -view: prints each state as the value of the configuration's VIEW. */
|
|
140
144
|
isViewPrinted?: boolean;
|
|
141
|
-
|
|
145
|
+
/** TLC's -maxSetSize: the most elements TLC enumerates into a set, or states into a list of them. */
|
|
142
146
|
maxSetSize?: number;
|
|
143
|
-
|
|
147
|
+
/** TLC's -dump: writes the reachable states, or with `dot` the state graph, through writeFile. */
|
|
144
148
|
dump?: StateDump;
|
|
145
|
-
|
|
149
|
+
/** TLC's -tool, which changes the messages of TLC's errors. */
|
|
146
150
|
isTool?: boolean;
|
|
147
|
-
|
|
151
|
+
/** TLC's -continue: reports each violation through onProgress and goes on. */
|
|
148
152
|
isContinued?: boolean;
|
|
153
|
+
/** Skips fingerprintDistance, which takes fingerprinting every state again after the search. */
|
|
154
|
+
isFingerprintDistanceSkipped?: boolean;
|
|
149
155
|
moduleOperators?: ModuleOperator[];
|
|
150
|
-
|
|
156
|
+
/** TLC's trace exploration spec, and the binary trace TLC records for it unless -noTEBin. */
|
|
151
157
|
traceSpec?: TraceSpecOptions;
|
|
152
|
-
|
|
158
|
+
/** Whether the caller printed SANY's report, its warnings included, before the check. */
|
|
153
159
|
isSanyReported?: boolean;
|
|
154
|
-
|
|
160
|
+
/** False for TLC's -nowarning, which changes how TLC computes some successors. */
|
|
155
161
|
isWarningEnabled?: boolean;
|
|
156
|
-
|
|
162
|
+
/** TLC's -coverage, in minutes. */
|
|
157
163
|
coverage?: number;
|
|
158
164
|
version?: TlcVersion;
|
|
159
165
|
onProgress?: (progress: CheckProgress) => void;
|
|
@@ -176,7 +182,6 @@ export interface InitialStatesProgress {
|
|
|
176
182
|
count: number;
|
|
177
183
|
}
|
|
178
184
|
|
|
179
|
-
// A check TLC reports as violated before it stops replaying the initial states.
|
|
180
185
|
export interface InitialStateViolation {
|
|
181
186
|
kind: "initial-state-violation";
|
|
182
187
|
status: "invariant-violation" | "liveness-violation";
|
|
@@ -184,7 +189,6 @@ export interface InitialStateViolation {
|
|
|
184
189
|
state: Record<string, Value>;
|
|
185
190
|
}
|
|
186
191
|
|
|
187
|
-
// A line the spec prints, or what TLC reports as it replays the initial states.
|
|
188
192
|
export type OutputLine = string | InitialStatesProgress | InitialStateViolation;
|
|
189
193
|
|
|
190
194
|
export type CheckProgress =
|
|
@@ -200,17 +204,16 @@ export type CheckProgress =
|
|
|
200
204
|
| {
|
|
201
205
|
kind: "liveness-started";
|
|
202
206
|
branches: number;
|
|
203
|
-
|
|
207
|
+
/** Whether TLC checks the complete state graph. */
|
|
204
208
|
isComplete: boolean;
|
|
209
|
+
/** How many states the graphs of all branches have together. */
|
|
205
210
|
states: number;
|
|
206
211
|
statistics: SearchStatistics;
|
|
207
212
|
}
|
|
208
213
|
| { kind: "liveness-finished" }
|
|
209
214
|
| { kind: "sequential-fallback"; string: string }
|
|
210
215
|
| { kind: "warning"; code: number; text: string }
|
|
211
|
-
// A violation that the search goes on past with -continue.
|
|
212
216
|
| { kind: "violation"; status: CheckStatus; violation: Violation }
|
|
213
|
-
// A method of the class named after a module, which TLC reports as it loads the class.
|
|
214
217
|
| ({ kind: "java-override" } & JavaOverride);
|
|
215
218
|
|
|
216
219
|
export interface SearchStatistics extends Pick<
|
|
@@ -230,30 +233,30 @@ export type CheckStatus =
|
|
|
230
233
|
|
|
231
234
|
export interface TraceStep {
|
|
232
235
|
action: string | undefined;
|
|
233
|
-
|
|
236
|
+
/** TLC's name, parameters and location for the action that took this step. */
|
|
234
237
|
label: string | undefined;
|
|
235
238
|
state: Record<string, Value>;
|
|
236
|
-
|
|
239
|
+
/** What the spec prints before this step as TLC rebuilds the trace, and before it for the first. */
|
|
237
240
|
output?: OutputLine[];
|
|
238
241
|
}
|
|
239
242
|
|
|
240
243
|
export interface Violation {
|
|
241
244
|
name: string;
|
|
242
|
-
|
|
245
|
+
/** Every temporal property that a liveness counterexample violates, in the configuration's order. */
|
|
243
246
|
properties?: string[];
|
|
244
247
|
trace: TraceStep[];
|
|
245
|
-
|
|
248
|
+
/** What the spec prints after the trace, as TLC finds the lasso's step back or rebuilds the trace. */
|
|
246
249
|
traceOutput?: OutputLine[];
|
|
247
|
-
|
|
250
|
+
/** What the postconditions print, which TLC checks after the lasso's step back. */
|
|
248
251
|
postconditionOutput?: OutputLine[];
|
|
249
252
|
loopStart: number | undefined;
|
|
250
253
|
loopLabel?: string;
|
|
251
254
|
message?: string;
|
|
252
255
|
counts?: string;
|
|
253
256
|
unwitnessed?: Postcondition;
|
|
254
|
-
|
|
257
|
+
/** A POSTCONDITION that is false or fails, which TLC checks as it prints the counterexample. */
|
|
255
258
|
postcondition?: Postcondition;
|
|
256
|
-
|
|
259
|
+
/** What TLC warns about after a counterexample, with its code. */
|
|
257
260
|
warning?: { code: number; text: string };
|
|
258
261
|
}
|
|
259
262
|
|
|
@@ -264,7 +267,7 @@ export interface Postcondition {
|
|
|
264
267
|
counts?: string;
|
|
265
268
|
}
|
|
266
269
|
|
|
267
|
-
|
|
270
|
+
/** An evaluation that failed during the search, with the behavior up to the state TLC was working on. */
|
|
268
271
|
export interface EvaluationFailure {
|
|
269
272
|
code: number;
|
|
270
273
|
message: string;
|
|
@@ -273,26 +276,20 @@ export interface EvaluationFailure {
|
|
|
273
276
|
traceOutput?: OutputLine[];
|
|
274
277
|
initialState: Record<string, Value> | undefined;
|
|
275
278
|
exitCode: number;
|
|
276
|
-
|
|
279
|
+
/** The expressions TLC was evaluating, outermost first, when its replay finds them. */
|
|
277
280
|
callStack: Expression[] | undefined;
|
|
278
|
-
|
|
281
|
+
/** Whether TLC prints the call stack before the error, as it does for a failed liveness check. */
|
|
279
282
|
isCallStackFirst?: boolean;
|
|
280
|
-
|
|
283
|
+
/** The FingerprintException the replay raises, which TLC reports in place of the call stack. */
|
|
281
284
|
fingerprint?: FingerprintFailure;
|
|
282
|
-
|
|
285
|
+
/** How TLC reports failing again as it prints the trace, since it can't fingerprint the state. */
|
|
283
286
|
traceFailure?: FailureMessage;
|
|
284
|
-
|
|
287
|
+
/** A POSTCONDITION that is false or fails after the trace, which TLC checks as it prints one. */
|
|
285
288
|
postcondition?: Postcondition;
|
|
286
|
-
|
|
289
|
+
/** Whether TLC stops before it prints the statistics, as it does for an illegal initial state. */
|
|
287
290
|
isWithoutStatistics?: boolean;
|
|
288
291
|
}
|
|
289
292
|
|
|
290
|
-
interface ReplayFailure {
|
|
291
|
-
callStack: Expression[];
|
|
292
|
-
fingerprint: FingerprintFailure | undefined;
|
|
293
|
-
replayError?: TlaEvaluationError;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
293
|
export interface InitialStates {
|
|
297
294
|
generated: number;
|
|
298
295
|
distinct: number;
|
|
@@ -306,17 +303,17 @@ export interface CheckResult {
|
|
|
306
303
|
distinctStates: number;
|
|
307
304
|
queuedStates: number;
|
|
308
305
|
depth: number;
|
|
309
|
-
|
|
306
|
+
/** Once TLC computed all the initial states without a violation or an error. */
|
|
310
307
|
initialStates: InitialStates | undefined;
|
|
311
|
-
|
|
308
|
+
/** How many expanded states found each number of new states, when TLC prints the outdegree. */
|
|
312
309
|
outDegrees: number[] | undefined;
|
|
313
|
-
|
|
310
|
+
/** The smallest distance between two fingerprints, when TLC estimates a collision from them. */
|
|
314
311
|
fingerprintDistance: bigint | undefined;
|
|
315
|
-
|
|
312
|
+
/** A temporal property TLC finds violated as it adds a deadlocked state, reported after. */
|
|
316
313
|
additionalViolation?: Violation;
|
|
317
|
-
|
|
314
|
+
/** Where TLC's worker fails to add the state to the behavior graph after it reports a violation. */
|
|
318
315
|
liveCallStack?: Expression[];
|
|
319
|
-
|
|
316
|
+
/** The outdegrees when TLC's workers stop on a violation that TLC 1.7.4 reports as a success. */
|
|
320
317
|
violationOutDegrees?: number[];
|
|
321
318
|
traceSpec?: string;
|
|
322
319
|
coverage?: CoverageReport;
|
|
@@ -326,28 +323,8 @@ interface CoveredAction extends SpecAction {
|
|
|
326
323
|
node: number;
|
|
327
324
|
}
|
|
328
325
|
|
|
329
|
-
interface
|
|
330
|
-
trace: TraceStep[];
|
|
331
|
-
traceOutput?: OutputLine[];
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
interface TraceOptions {
|
|
326
|
+
interface ReportedViolation extends Omit<Violation, "loopStart"> {
|
|
335
327
|
loopStart?: number;
|
|
336
|
-
known?: number;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
interface FailureOptions {
|
|
340
|
-
initialState?: Value[];
|
|
341
|
-
isInitial?: boolean;
|
|
342
|
-
outDegrees?: number[];
|
|
343
|
-
callStack?: Expression[];
|
|
344
|
-
fingerprint?: FingerprintFailure;
|
|
345
|
-
replayError?: TlaEvaluationError;
|
|
346
|
-
isNextState?: boolean;
|
|
347
|
-
isCallStackFirst?: boolean;
|
|
348
|
-
traceFailure?: FailureMessage;
|
|
349
|
-
// Whether TLC prints the call stack of adding the state to the behavior graph, not a replay.
|
|
350
|
-
isLiveCallStack?: boolean;
|
|
351
328
|
}
|
|
352
329
|
|
|
353
330
|
const appendTraceOutput = <Traced extends Behavior>(behavior: Traced, lines: OutputLine[]) => ({
|
|
@@ -355,32 +332,9 @@ const appendTraceOutput = <Traced extends Behavior>(behavior: Traced, lines: Out
|
|
|
355
332
|
traceOutput: [...(behavior.traceOutput ?? []), ...lines],
|
|
356
333
|
});
|
|
357
334
|
|
|
358
|
-
const INITIAL_RECOVERY_FAILURE = "Failed to recover the initial state from its fingerprint.";
|
|
359
|
-
const NEXT_RECOVERY_FAILURE = "Failed to recover the next state from its fingerprint.";
|
|
360
|
-
|
|
361
|
-
// Stops a replay where TLC stops it without a failure, as at a violated invariant.
|
|
362
335
|
const STOP_REPLAY = new Error("The replay stopped");
|
|
363
336
|
const STOP_WALK = new Error("The walk stopped");
|
|
364
337
|
|
|
365
|
-
// When TLC's replay of the initial states doesn't fail again, it exits with the error's code.
|
|
366
|
-
const getInitialExitCode = (error: TlaEvaluationError) => {
|
|
367
|
-
const coded = getCodedMessage(error.message);
|
|
368
|
-
return coded &&
|
|
369
|
-
!coded.isEvalException &&
|
|
370
|
-
getMessageExitStatus(coded.code) === EXIT_STATUS.configParseError
|
|
371
|
-
? EXIT_STATUS.configParseError
|
|
372
|
-
: getErrorExitCode(error);
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
// When the replay fails again, a standard module's EvalException decides the exit status, and
|
|
376
|
-
// any other failure exits as a nested expression failure. A heading or wrapping error defers.
|
|
377
|
-
const getReplayExitCode = (error: TlaEvaluationError): number => {
|
|
378
|
-
const inner = error.cause;
|
|
379
|
-
if (inner instanceof TlaEvaluationError) return getReplayExitCode(inner);
|
|
380
|
-
return error instanceof TlaModuleError ? error.exitCode : EXIT_STATUS.specEvaluationFailure;
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
// TLC finishes the -dump file whether or not the search finds a violation.
|
|
384
338
|
export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
385
339
|
const stateWriter =
|
|
386
340
|
options.dump && createStateWriter(options.dump, options.writeFile, options.version);
|
|
@@ -393,8 +347,6 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
|
393
347
|
}
|
|
394
348
|
};
|
|
395
349
|
|
|
396
|
-
// TLC checks liveness on the graph so far after 3 seconds and then every minute, once the graph
|
|
397
|
-
// has grown by a tenth and liveness checking has taken at most a fifth of the time.
|
|
398
350
|
const PERIODIC_START = 3000;
|
|
399
351
|
const PROGRESS_INTERVAL = 60_000;
|
|
400
352
|
const LIVENESS_GROWTH = 0.1;
|
|
@@ -406,45 +358,23 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
406
358
|
? parseConfig(options.config, options.version)
|
|
407
359
|
: options.config;
|
|
408
360
|
const onPrint = options.onPrint ?? console.log;
|
|
409
|
-
|
|
410
|
-
const capturedOutput = { lines: undefined as OutputLine[] | undefined };
|
|
361
|
+
let capturedLines: OutputLine[] | undefined;
|
|
411
362
|
const print = (text: string) => {
|
|
412
|
-
if (
|
|
363
|
+
if (capturedLines) capturedLines.push(text);
|
|
413
364
|
else onPrint(text);
|
|
414
365
|
};
|
|
415
366
|
const captureOutput = <Result>(rebuild: () => Result) => {
|
|
416
|
-
const outer =
|
|
367
|
+
const outer = capturedLines;
|
|
417
368
|
const lines: OutputLine[] = [];
|
|
418
|
-
|
|
369
|
+
capturedLines = lines;
|
|
419
370
|
try {
|
|
420
371
|
return { result: rebuild(), lines };
|
|
421
372
|
} finally {
|
|
422
|
-
|
|
373
|
+
capturedLines = outer;
|
|
423
374
|
}
|
|
424
375
|
};
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
setValueOptions(options);
|
|
428
|
-
setFingerprintPolynomial(options.fingerprintPolynomial ?? 0);
|
|
429
|
-
const specification = createEnvironment(config, {
|
|
430
|
-
source: options.source,
|
|
431
|
-
loadModule: options.loadModule,
|
|
432
|
-
order,
|
|
433
|
-
loadClass: options.loadClass,
|
|
434
|
-
print,
|
|
435
|
-
files: {
|
|
436
|
-
readFile: options.readFile,
|
|
437
|
-
writeFile: options.writeFile,
|
|
438
|
-
makeDirectory: options.makeDirectory,
|
|
439
|
-
},
|
|
440
|
-
seed: options.seed,
|
|
441
|
-
isTool: options.isTool,
|
|
442
|
-
traceFile: options.traceSpec?.traceFile,
|
|
443
|
-
isSanyReported: options.isSanyReported,
|
|
444
|
-
isWarningEnabled: options.isWarningEnabled,
|
|
445
|
-
version: options.version,
|
|
446
|
-
moduleOperators: options.moduleOperators,
|
|
447
|
-
});
|
|
376
|
+
const created = createCheckEnvironment(config, options, print);
|
|
377
|
+
const specification = created.specification;
|
|
448
378
|
reportStartup(specification, config, options.onProgress);
|
|
449
379
|
const coverage =
|
|
450
380
|
options.coverage === undefined
|
|
@@ -462,14 +392,13 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
462
392
|
const runtime = environment.runtime;
|
|
463
393
|
const is174 = runtime.version === "1.7.4";
|
|
464
394
|
runtime.pause = options.onPause ?? (() => {});
|
|
395
|
+
let description: SpecDescription | undefined;
|
|
396
|
+
const getDescription = () =>
|
|
397
|
+
(description ??= getSpecDescription(config, environment, specification.instanceActions));
|
|
465
398
|
runtime.getSpecification = () =>
|
|
466
|
-
getSpecificationValue(
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
specification.variableLocations,
|
|
470
|
-
specification.instanceActions,
|
|
471
|
-
);
|
|
472
|
-
const statistics = { depth: 0, initialStates: undefined as InitialStates | undefined };
|
|
399
|
+
getSpecificationValue(getDescription(), config, environment, specification.variableLocations);
|
|
400
|
+
let searchDepth = 0;
|
|
401
|
+
let computedInitialStates: InitialStates | undefined;
|
|
473
402
|
const getTraceSpec = (trace: TraceStep[], loopStart: number | undefined) =>
|
|
474
403
|
options.traceSpec &&
|
|
475
404
|
writeTraceSpec({
|
|
@@ -486,12 +415,20 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
486
415
|
key.startsWith(`${name}${KEY_SEPARATOR}`),
|
|
487
416
|
),
|
|
488
417
|
});
|
|
418
|
+
const getCoverage = () =>
|
|
419
|
+
coverage?.relations.some((relation) => relation.kind === "next")
|
|
420
|
+
? getCoverageReport(
|
|
421
|
+
coverage,
|
|
422
|
+
environment,
|
|
423
|
+
specification.variableLocations,
|
|
424
|
+
search?.getTlcOrder() ?? [],
|
|
425
|
+
)
|
|
426
|
+
: undefined;
|
|
489
427
|
const createResult = (
|
|
490
428
|
status: CheckStatus,
|
|
491
|
-
violation?:
|
|
429
|
+
violation?: ReportedViolation,
|
|
492
430
|
failure?: EvaluationFailure,
|
|
493
431
|
): CheckResult => {
|
|
494
|
-
// TLC writes the trace it printed, and a safety property's counterexample doesn't loop back.
|
|
495
432
|
const traceSpec = getTraceSpec(
|
|
496
433
|
violation?.trace ?? failure?.trace ?? [],
|
|
497
434
|
status === "property-violation" ? undefined : violation?.loopStart,
|
|
@@ -503,32 +440,22 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
503
440
|
generatedStates: runtime.generatedStates,
|
|
504
441
|
distinctStates: runtime.distinctStates,
|
|
505
442
|
queuedStates: runtime.queueSize,
|
|
506
|
-
depth: runtime.generatedStates === 0 ? 0 : Math.max(
|
|
507
|
-
initialStates:
|
|
443
|
+
depth: runtime.generatedStates === 0 ? 0 : Math.max(searchDepth, 1),
|
|
444
|
+
initialStates: computedInitialStates,
|
|
508
445
|
outDegrees: undefined,
|
|
509
446
|
fingerprintDistance: undefined,
|
|
510
|
-
coverage:
|
|
511
|
-
? getCoverageReport(
|
|
512
|
-
coverage,
|
|
513
|
-
environment,
|
|
514
|
-
specification.variableLocations,
|
|
515
|
-
search?.getTlcOrder() ?? [],
|
|
516
|
-
)
|
|
517
|
-
: undefined,
|
|
447
|
+
coverage: getCoverage(),
|
|
518
448
|
...(traceSpec !== undefined && { traceSpec }),
|
|
519
449
|
};
|
|
520
450
|
};
|
|
521
451
|
const outDegrees = Array.from({ length: OUT_DEGREE_BUCKETS }, () => 0);
|
|
522
|
-
|
|
523
|
-
const getOutDegreeBucket = () => Math.min(
|
|
524
|
-
// TLC counts the state it was expanding when an evaluation failed, except TLC 1.7.4.
|
|
452
|
+
let newStateCount = 0;
|
|
453
|
+
const getOutDegreeBucket = () => Math.min(newStateCount, OUT_DEGREE_BUCKETS - 1);
|
|
525
454
|
const getPartialOutDegrees = () =>
|
|
526
455
|
outDegrees.map((count, degree) => (degree === getOutDegreeBucket() ? count + 1 : count));
|
|
527
456
|
const getFailureOutDegrees = () => (is174 ? [...outDegrees] : getPartialOutDegrees());
|
|
528
|
-
// TLC 1.7.4 doesn't name the properties a counterexample violates, so it evaluates none of them.
|
|
529
457
|
const getViolatedProperties = (checker: LivenessChecker, path: Value[][], cycleStart: number) =>
|
|
530
458
|
is174 ? [] : checker.getViolatedProperties(path, cycleStart);
|
|
531
|
-
// A violation in a successor ends the expansion of a state before TLC counts it.
|
|
532
459
|
const withOutDegrees = (result: CheckResult, degrees = [...outDegrees]): CheckResult => ({
|
|
533
460
|
...result,
|
|
534
461
|
violationOutDegrees: degrees,
|
|
@@ -536,23 +463,30 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
536
463
|
const createSuccess = (): CheckResult => ({
|
|
537
464
|
...createResult("success"),
|
|
538
465
|
outDegrees: [...outDegrees],
|
|
539
|
-
fingerprintDistance:
|
|
540
|
-
|
|
541
|
-
runtime.generatedStates,
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
466
|
+
fingerprintDistance: options.isFingerprintDistanceSkipped
|
|
467
|
+
? undefined
|
|
468
|
+
: getFingerprintDistance(runtime.distinctStates, runtime.generatedStates, (visit) =>
|
|
469
|
+
visit(
|
|
470
|
+
search
|
|
471
|
+
? search.getStoredFingerprints(
|
|
472
|
+
exploredStates.length === 0 ? states : states.concat(exploredStates),
|
|
473
|
+
exploredStates.length === 0
|
|
474
|
+
? fingerprintStates
|
|
475
|
+
: fingerprintStates.concat(exploredFingerprintStates),
|
|
476
|
+
)
|
|
477
|
+
: BigInt64Array.from(states, runtime.getFingerprint),
|
|
478
|
+
),
|
|
479
|
+
),
|
|
547
480
|
});
|
|
548
481
|
|
|
549
482
|
const search = createSearch(
|
|
550
483
|
config,
|
|
551
484
|
environment,
|
|
552
485
|
specification.variableLocations,
|
|
553
|
-
() => order.getDeclarationOrder("variable"),
|
|
486
|
+
() => created.order.getDeclarationOrder("variable"),
|
|
554
487
|
options.onProgress,
|
|
555
488
|
specification.moduleOperators,
|
|
489
|
+
specification.runtimeInvariants,
|
|
556
490
|
);
|
|
557
491
|
const findViolatedAssumption = () =>
|
|
558
492
|
findAssumptionViolation(specification.assumptions, environment);
|
|
@@ -560,12 +494,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
560
494
|
runtime.isStarted = true;
|
|
561
495
|
const assumptionViolation = findViolatedAssumption();
|
|
562
496
|
if (assumptionViolation) return createResult("assumption-violation", assumptionViolation);
|
|
563
|
-
|
|
564
|
-
statistics.initialStates = { generated: 0, distinct: 0 };
|
|
497
|
+
computedInitialStates = { generated: 0, distinct: 0 };
|
|
565
498
|
options.onProgress?.({ kind: "initial-states-started" });
|
|
566
499
|
options.onProgress?.({
|
|
567
500
|
kind: "initial-states-computed",
|
|
568
|
-
initialStates:
|
|
501
|
+
initialStates: computedInitialStates,
|
|
569
502
|
});
|
|
570
503
|
return createSuccess();
|
|
571
504
|
}
|
|
@@ -573,17 +506,12 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
573
506
|
config.postconditions.length > 0 ||
|
|
574
507
|
config.possible.length > 0 ||
|
|
575
508
|
specification.moduleOperators.some((operator) => operator.kind === "postcondition");
|
|
576
|
-
|
|
577
|
-
const
|
|
578
|
-
TraceStep,
|
|
579
|
-
{ state: Record<string, Value>; action: SpecAction | undefined }
|
|
580
|
-
>();
|
|
581
|
-
const getStepState = (step: TraceStep) => traceSteps.get(step)?.state ?? step.state;
|
|
509
|
+
const tracedSteps = new WeakMap<TraceStep, TracedStep>();
|
|
510
|
+
const getStepState = (step: TraceStep) => tracedSteps.get(step)?.state ?? step.state;
|
|
582
511
|
const getStepAction = (step: TraceStep) => {
|
|
583
|
-
const action =
|
|
512
|
+
const action = tracedSteps.get(step)?.action;
|
|
584
513
|
return action ? toActionValue(action) : createActionRecord(step.action);
|
|
585
514
|
};
|
|
586
|
-
// TLC checks the postconditions on each trace it prints, so what they print follows the trace.
|
|
587
515
|
const checkTracePostconditions = (
|
|
588
516
|
trace: TraceStep[],
|
|
589
517
|
loop: { start: number; action: Value } | undefined,
|
|
@@ -603,7 +531,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
603
531
|
};
|
|
604
532
|
const reportViolation = (
|
|
605
533
|
status: CheckStatus,
|
|
606
|
-
violation:
|
|
534
|
+
violation: ReportedViolation,
|
|
607
535
|
getLoopAction?: () => Value,
|
|
608
536
|
) => {
|
|
609
537
|
const start = violation.loopStart;
|
|
@@ -618,15 +546,13 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
618
546
|
...(checked.postcondition && { postcondition: checked.postcondition }),
|
|
619
547
|
});
|
|
620
548
|
};
|
|
621
|
-
//
|
|
622
|
-
|
|
623
|
-
// status of the first violation, as -dfid and -simulate do.
|
|
624
|
-
const continued = { status: undefined as CheckStatus | undefined };
|
|
549
|
+
// Deviation from TLC: -continue ends with the status of the first violation, not a success.
|
|
550
|
+
let continuedStatus: CheckStatus | undefined;
|
|
625
551
|
const reportContinuedViolation = (
|
|
626
552
|
status: CheckStatus,
|
|
627
553
|
violation: Omit<Violation, "loopStart">,
|
|
628
554
|
) => {
|
|
629
|
-
|
|
555
|
+
continuedStatus ??= status;
|
|
630
556
|
options.onProgress?.({
|
|
631
557
|
kind: "violation",
|
|
632
558
|
status,
|
|
@@ -635,17 +561,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
635
561
|
};
|
|
636
562
|
const spec = search.spec;
|
|
637
563
|
const getFingerprintState = search.getFingerprintState;
|
|
638
|
-
const specNextActions = { value: undefined as SpecAction[] | undefined };
|
|
639
|
-
const getSpecNextActions = () =>
|
|
640
|
-
(specNextActions.value ??= getNextActions(config, environment, specification.instanceActions));
|
|
641
564
|
// Tool's constructor splits the next-state relation into actions before TLC checks anything.
|
|
642
|
-
|
|
643
|
-
runtime.getSuccessorAction = (state, next) =>
|
|
644
|
-
getSpecNextActions().find((action) =>
|
|
645
|
-
getSuccessors(action.expression, state, environment, action.scope).some((successor) =>
|
|
646
|
-
successor.state.every((value, index) => isSameValue(value, next[index])),
|
|
647
|
-
),
|
|
648
|
-
);
|
|
565
|
+
const nextActions = getDescription().actions;
|
|
649
566
|
const addCoverageRelations = (kind: "init" | "next", actions: SpecAction[]) =>
|
|
650
567
|
actions.map((action): CoveredAction => ({
|
|
651
568
|
...action,
|
|
@@ -659,11 +576,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
659
576
|
)
|
|
660
577
|
: -1,
|
|
661
578
|
}));
|
|
662
|
-
const coverageInits = addCoverageRelations(
|
|
663
|
-
|
|
664
|
-
coverage ? getInitActions(config, environment, specification.instanceActions) : [],
|
|
665
|
-
);
|
|
666
|
-
const coverageActions = addCoverageRelations("next", coverage ? getSpecNextActions() : []);
|
|
579
|
+
const coverageInits = addCoverageRelations("init", coverage ? getDescription().inits : []);
|
|
580
|
+
const coverageActions = addCoverageRelations("next", coverage ? nextActions : []);
|
|
667
581
|
if (coverage) buildCoverage(coverage, environment, getPrimedRanges(coverageActions, environment));
|
|
668
582
|
const walkCoveredSuccessors = (
|
|
669
583
|
action: CoveredAction,
|
|
@@ -680,7 +594,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
680
594
|
onState(successor);
|
|
681
595
|
},
|
|
682
596
|
(partial) => {
|
|
683
|
-
const missing = environment.variables.filter(
|
|
597
|
+
const missing = environment.variables.filter(
|
|
598
|
+
(_variable, index) => partial[index] === undefined,
|
|
599
|
+
);
|
|
684
600
|
throw new TlaIncompleteSuccessorError(
|
|
685
601
|
`Successor state is not completely specified by action ${action.name}. The following variables are not assigned: ${missing.join(", ")}`,
|
|
686
602
|
partial,
|
|
@@ -696,69 +612,39 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
696
612
|
);
|
|
697
613
|
return successors;
|
|
698
614
|
};
|
|
615
|
+
// TLC generates the successors of each action again, which its coverage counts.
|
|
616
|
+
const findSuccessorAction = (state: Value[], isMatch: (successor: Successor) => boolean) =>
|
|
617
|
+
coverage
|
|
618
|
+
? coverageActions.find((item) => getCoveredSuccessors(item, state).some(isMatch))
|
|
619
|
+
: nextActions.find((item) =>
|
|
620
|
+
getSuccessors(item.expression, state, environment, item.scope).some(isMatch),
|
|
621
|
+
);
|
|
622
|
+
runtime.getSuccessorAction = (state, next) =>
|
|
623
|
+
findSuccessorAction(state, (successor) =>
|
|
624
|
+
successor.state.every((value, index) => isSameValue(value, next[index])),
|
|
625
|
+
);
|
|
626
|
+
const rejectIncompleteInitialState = (partial: (Value | undefined)[]) => {
|
|
627
|
+
throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
|
|
628
|
+
};
|
|
699
629
|
const getCoveredInitialStates = () => {
|
|
700
630
|
const initialStates: Value[][] = [];
|
|
701
631
|
replayInitialStates(
|
|
702
632
|
coverageInits,
|
|
703
633
|
environment,
|
|
704
634
|
(state) => initialStates.push(state),
|
|
705
|
-
|
|
706
|
-
throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
|
|
707
|
-
},
|
|
635
|
+
rejectIncompleteInitialState,
|
|
708
636
|
);
|
|
709
637
|
return initialStates;
|
|
710
638
|
};
|
|
711
|
-
const getReplayFailure = (replay: (tracing: Environment) => void): ReplayFailure | undefined => {
|
|
712
|
-
const tracing = createTracingEnvironment(environment);
|
|
713
|
-
const callStack = tracing.callStack;
|
|
714
|
-
try {
|
|
715
|
-
replay(tracing);
|
|
716
|
-
return undefined;
|
|
717
|
-
} catch (error) {
|
|
718
|
-
// A replay that overflows the stack again has an empty call stack.
|
|
719
|
-
if (isStackOverflow(error)) return { callStack: [], fingerprint: undefined };
|
|
720
|
-
if (!(error instanceof TlaEvaluationError) || !callStack) return undefined;
|
|
721
|
-
return {
|
|
722
|
-
callStack: callStack.expressions,
|
|
723
|
-
fingerprint: callStack.fingerprint,
|
|
724
|
-
replayError: error,
|
|
725
|
-
};
|
|
726
|
-
}
|
|
727
|
-
};
|
|
728
|
-
// Outermost first: each value fails as it fingerprints a value it holds.
|
|
729
|
-
const findFailedSources = (value: Value, sources: CallStack["sources"]): Expression[] => {
|
|
730
|
-
if (typeof value !== "object") return [];
|
|
731
|
-
const source = sources.get(value);
|
|
732
|
-
const failed = getHeldValues(value).find((held) => getFingerprintError(held) !== undefined);
|
|
733
|
-
return [
|
|
734
|
-
...(source ? [source] : []),
|
|
735
|
-
...(failed === undefined ? [] : findFailedSources(failed, sources)),
|
|
736
|
-
];
|
|
737
|
-
};
|
|
738
|
-
// A value the replay built raises a FingerprintException when TLC fails to fingerprint it.
|
|
739
|
-
const fingerprintReplayed = (state: Value[], callStack: CallStack | undefined) => {
|
|
740
|
-
for (const value of getFingerprintState(state)) {
|
|
741
|
-
const error = getFingerprintError(value);
|
|
742
|
-
if (!error) continue;
|
|
743
|
-
const sources = callStack ? findFailedSources(value, callStack.sources) : [];
|
|
744
|
-
// TLC fingerprints a state outside any evaluation, so its call stack is empty.
|
|
745
|
-
if (callStack && sources.length > 0) {
|
|
746
|
-
callStack.expressions.length = 0;
|
|
747
|
-
callStack.isFrozen = true;
|
|
748
|
-
callStack.fingerprint = { sources, reason: error.message };
|
|
749
|
-
}
|
|
750
|
-
throw error;
|
|
751
|
-
}
|
|
752
|
-
state.forEach(markFingerprinted);
|
|
753
|
-
};
|
|
754
|
-
// TLC's set of states already holds the state that failed.
|
|
755
639
|
const createReplayedStates = () => {
|
|
756
|
-
const replayed =
|
|
640
|
+
const replayed = unstoredFingerprint ? [unstoredFingerprint] : [];
|
|
757
641
|
return (state: Value[], callStack: CallStack | undefined) => {
|
|
758
|
-
fingerprintReplayed(state, callStack);
|
|
642
|
+
fingerprintReplayed(state, getFingerprintState(state), callStack);
|
|
759
643
|
const fingerprintState = getFingerprintState(state);
|
|
644
|
+
const hash = getStateHash(fingerprintState);
|
|
760
645
|
const isSeen =
|
|
761
|
-
findStateIndex(
|
|
646
|
+
findStateIndex(seenStates, hash, fingerprintState) !== -1 ||
|
|
647
|
+
isExplored(hash, fingerprintState) ||
|
|
762
648
|
replayed.some((seen) => isSameState(seen, fingerprintState));
|
|
763
649
|
if (isSeen) return false;
|
|
764
650
|
replayed.push(fingerprintState);
|
|
@@ -766,57 +652,48 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
766
652
|
return true;
|
|
767
653
|
};
|
|
768
654
|
};
|
|
769
|
-
// TLC reports its progress again as it replays the initial states. After a FingerprintException
|
|
770
|
-
// or a StackOverflowError, it only counts the states left, then throws the error.
|
|
771
655
|
const replayInit = () => {
|
|
772
|
-
|
|
656
|
+
let replayedCount = 0;
|
|
773
657
|
const deferred: unknown[] = [];
|
|
774
658
|
const addReplayed = createReplayedStates();
|
|
775
|
-
return getReplayFailure((tracing) => {
|
|
776
|
-
replayInitialStates(
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
)
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
kind: "initial-state-violation",
|
|
797
|
-
...violation,
|
|
798
|
-
state: traced,
|
|
799
|
-
});
|
|
800
|
-
throw STOP_REPLAY;
|
|
801
|
-
}
|
|
802
|
-
} catch (error) {
|
|
803
|
-
const isFingerprintFailure =
|
|
804
|
-
error instanceof TlaEvaluationError && tracing.callStack?.fingerprint !== undefined;
|
|
805
|
-
if (!isFingerprintFailure && !isStackOverflow(error)) throw error;
|
|
806
|
-
deferred.push(error);
|
|
659
|
+
return getReplayFailure(environment, (tracing) => {
|
|
660
|
+
replayInitialStates(getDescription().inits, tracing, (state) => {
|
|
661
|
+
reportInitialStatesProgress(replayedCount, (progress) => capturedLines?.push(progress));
|
|
662
|
+
replayedCount++;
|
|
663
|
+
runtime.generatedStates = replayedCount;
|
|
664
|
+
if (deferred.length > 0) return;
|
|
665
|
+
try {
|
|
666
|
+
const addFingerprint = () => {
|
|
667
|
+
if (!addReplayed(state, tracing.callStack)) return;
|
|
668
|
+
runtime.queueSize++;
|
|
669
|
+
liveness?.addInitialState(states.length, state, tracing);
|
|
670
|
+
};
|
|
671
|
+
const violation = search.checkReplayedInitialState(state, tracing, addFingerprint);
|
|
672
|
+
if (violation) {
|
|
673
|
+
const traced = traces.toTrace([{ action: undefined, state }], []).trace[0].state;
|
|
674
|
+
capturedLines?.push({
|
|
675
|
+
kind: "initial-state-violation",
|
|
676
|
+
...violation,
|
|
677
|
+
state: traced,
|
|
678
|
+
});
|
|
679
|
+
throw STOP_REPLAY;
|
|
807
680
|
}
|
|
808
|
-
}
|
|
809
|
-
|
|
681
|
+
} catch (error) {
|
|
682
|
+
const isFingerprintFailure =
|
|
683
|
+
error instanceof TlaEvaluationError && tracing.callStack?.fingerprint !== undefined;
|
|
684
|
+
if (!isFingerprintFailure && !isStackOverflow(error)) throw error;
|
|
685
|
+
deferred.push(error);
|
|
686
|
+
}
|
|
687
|
+
});
|
|
810
688
|
if (deferred.length > 0) throw deferred[0];
|
|
811
689
|
});
|
|
812
690
|
};
|
|
813
|
-
// TLC's replay writes each successor in the model to the -dump state graph again.
|
|
814
691
|
const replayNext = (index: number) =>
|
|
815
|
-
getReplayFailure((tracing) => {
|
|
692
|
+
getReplayFailure(environment, (tracing) => {
|
|
816
693
|
const state = states[index];
|
|
817
694
|
const source = stateWriter && getGraphState(state, depths[index]);
|
|
818
695
|
const addReplayed = createReplayedStates();
|
|
819
|
-
replaySuccessors(
|
|
696
|
+
replaySuccessors(nextActions, state, tracing, (next, action) => {
|
|
820
697
|
const addFingerprint = () => {
|
|
821
698
|
const isUnseen = addReplayed(next, tracing.callStack);
|
|
822
699
|
if (source) {
|
|
@@ -834,9 +711,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
834
711
|
}
|
|
835
712
|
});
|
|
836
713
|
});
|
|
837
|
-
const isReducing = config.view !== undefined || config.symmetry !== undefined;
|
|
838
714
|
const tlcFingerprints: number[] = [];
|
|
839
|
-
// TLC warns about the liveness checker before it builds it.
|
|
840
715
|
if (search.properties.liveness.length > 0) {
|
|
841
716
|
options.onProgress?.({
|
|
842
717
|
kind: "liveness-initializing",
|
|
@@ -847,32 +722,47 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
847
722
|
const liveness = withLivenessExitCode(() =>
|
|
848
723
|
withUnexpectedException(() =>
|
|
849
724
|
createLivenessChecker(search.properties.liveness, spec.temporals, environment, {
|
|
850
|
-
getFingerprint: (
|
|
851
|
-
(tlcFingerprints[index] ??= Number(
|
|
725
|
+
getFingerprint: (successor) =>
|
|
726
|
+
(tlcFingerprints[successor.index] ??= Number(
|
|
727
|
+
BigInt.asIntN(32, runtime.getFingerprint(successor.state)),
|
|
728
|
+
)),
|
|
852
729
|
getSuccessors: (source, state) => {
|
|
853
730
|
const successors: LiveSuccessor[] = [];
|
|
854
731
|
if (spec.next === undefined) return successors;
|
|
855
|
-
// The constraints read the level of the state whose successors they check.
|
|
856
732
|
const livenessSource = current.livenessSource;
|
|
857
733
|
current.livenessSource = source;
|
|
734
|
+
const addSuccessor = (successor: Value[]) => {
|
|
735
|
+
canonicalizeState(successor);
|
|
736
|
+
const isInModel =
|
|
737
|
+
search.satisfiesConstraints(successor, state) &&
|
|
738
|
+
search.satisfiesActionConstraints(state, successor);
|
|
739
|
+
if (!isInModel) return;
|
|
740
|
+
const fingerprintState = getFingerprintState(successor);
|
|
741
|
+
const hash = getStateHash(fingerprintState);
|
|
742
|
+
const index = findStateIndex(seenStates, hash, fingerprintState);
|
|
743
|
+
successors.push({
|
|
744
|
+
index: index === -1 ? getPendingIndex(hash, fingerprintState) : index,
|
|
745
|
+
state: successor,
|
|
746
|
+
});
|
|
747
|
+
};
|
|
858
748
|
try {
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
749
|
+
// TLC's coverage counts the successors of each action the graph generates again.
|
|
750
|
+
if (coverage) {
|
|
751
|
+
coverageActions.forEach((action) =>
|
|
752
|
+
walkCoveredSuccessors(action, state, addSuccessor),
|
|
753
|
+
);
|
|
754
|
+
} else {
|
|
755
|
+
forEachSuccessor(
|
|
756
|
+
spec.next,
|
|
757
|
+
state,
|
|
758
|
+
environment,
|
|
759
|
+
(successor) => {
|
|
760
|
+
addSuccessor(successor.state);
|
|
761
|
+
return false;
|
|
762
|
+
},
|
|
763
|
+
spec.scope,
|
|
764
|
+
);
|
|
765
|
+
}
|
|
876
766
|
} finally {
|
|
877
767
|
current.livenessSource = livenessSource;
|
|
878
768
|
}
|
|
@@ -881,9 +771,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
881
771
|
}),
|
|
882
772
|
),
|
|
883
773
|
);
|
|
884
|
-
// ModelChecker rejects a temporal property whose negation has no solution.
|
|
885
774
|
if (liveness?.branches === 0) throw createTautologyError();
|
|
886
|
-
// TLC 1.7.4 creates its model checker, which TLCGet reads, once it has built the liveness checker.
|
|
887
775
|
runtime.isStarted = true;
|
|
888
776
|
const isCanonicalizedFirst = search.isSymmetric || liveness !== undefined;
|
|
889
777
|
|
|
@@ -892,219 +780,31 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
892
780
|
const parents: number[] = [];
|
|
893
781
|
const actions: (string | undefined)[] = [];
|
|
894
782
|
const depths: number[] = [];
|
|
895
|
-
|
|
896
|
-
const
|
|
783
|
+
const seenStates = createStateTable(fingerprintStates);
|
|
784
|
+
const exploredStates: Value[][] = [];
|
|
785
|
+
const exploredFingerprintStates: Value[][] = [];
|
|
786
|
+
let exploredTable: StateTable | undefined;
|
|
787
|
+
const isExplored = (hash: number, fingerprintState: Value[]) =>
|
|
788
|
+
exploredTable !== undefined && findStateIndex(exploredTable, hash, fingerprintState) !== -1;
|
|
789
|
+
const pendingFingerprintStates: Value[][] = [];
|
|
790
|
+
let pendingStates: StateTable | undefined;
|
|
791
|
+
const getPendingIndex = (hash: number, fingerprintState: Value[]) => {
|
|
792
|
+
pendingStates ??= createStateTable(pendingFingerprintStates);
|
|
793
|
+
const found = findStateIndex(pendingStates, hash, fingerprintState);
|
|
794
|
+
const position = found === -1 ? pendingFingerprintStates.length : found;
|
|
795
|
+
if (found === -1) {
|
|
796
|
+
markSeenState(pendingStates, hash, position);
|
|
797
|
+
pendingFingerprintStates.push(fingerprintState);
|
|
798
|
+
}
|
|
799
|
+
return -2 - position;
|
|
800
|
+
};
|
|
897
801
|
const canonicalizeState = createCanonicalizer();
|
|
898
802
|
|
|
899
803
|
const toRecord = search.toRecord;
|
|
900
|
-
const getAliasState = (
|
|
901
|
-
alias: string,
|
|
902
|
-
steps: Successor[],
|
|
903
|
-
position: number,
|
|
904
|
-
loopStart: number | undefined,
|
|
905
|
-
) => {
|
|
906
|
-
// TLC evaluates TLCGet("level") and Trace in an alias at the state's position in the trace. The
|
|
907
|
-
// search reads them again once the alias is evaluated, as it goes on with -continue.
|
|
908
|
-
const searchLevel = runtime.getLevel;
|
|
909
|
-
const searchBehavior = runtime.getBehavior;
|
|
910
|
-
runtime.getLevel = () => position + 1;
|
|
911
|
-
runtime.getBehavior = () => steps.slice(0, position + 1).map((step) => step.state);
|
|
912
|
-
try {
|
|
913
|
-
return evaluateAlias(
|
|
914
|
-
alias,
|
|
915
|
-
steps[position].state,
|
|
916
|
-
(steps[position + 1] ?? steps[loopStart ?? position]).state,
|
|
917
|
-
);
|
|
918
|
-
} finally {
|
|
919
|
-
runtime.getLevel = searchLevel;
|
|
920
|
-
runtime.getBehavior = searchBehavior;
|
|
921
|
-
}
|
|
922
|
-
};
|
|
923
|
-
const evaluateAlias = (alias: string, state: Value[], next: Value[] | undefined) =>
|
|
924
|
-
search.evaluateAlias(alias, state, next, options.isTool ?? false);
|
|
925
|
-
// TLC finds the action of a step as the first that takes it, evaluated as when the search
|
|
926
|
-
// expanded the previous state, by a held successor's values and otherwise by fingerprint.
|
|
927
|
-
const findStepAction = (index: number, previous: Value[], state: Value[], isHeld: boolean) => {
|
|
928
|
-
const actions = getSpecNextActions();
|
|
929
|
-
const expanding = { ...current };
|
|
930
|
-
Object.assign(current, {
|
|
931
|
-
index,
|
|
932
|
-
isExpanding: true,
|
|
933
|
-
candidate: undefined,
|
|
934
|
-
rebuilt: { state: previous, level: depths[index] },
|
|
935
|
-
});
|
|
936
|
-
const getKey = isHeld ? (values: Value[]) => values : getFingerprintState;
|
|
937
|
-
const key = getKey(state);
|
|
938
|
-
try {
|
|
939
|
-
return coverage
|
|
940
|
-
? coverageActions.find((item) =>
|
|
941
|
-
getCoveredSuccessors(item, previous).some((successor) =>
|
|
942
|
-
isSameState(getKey(successor.state), key),
|
|
943
|
-
),
|
|
944
|
-
)
|
|
945
|
-
: actions.find((item) =>
|
|
946
|
-
getSuccessors(item.expression, previous, environment, item.scope).some((successor) =>
|
|
947
|
-
isSameState(getKey(successor.state), key),
|
|
948
|
-
),
|
|
949
|
-
);
|
|
950
|
-
} finally {
|
|
951
|
-
Object.assign(current, expanding);
|
|
952
|
-
}
|
|
953
|
-
};
|
|
954
|
-
// TLC rebuilds the states it doesn't keep, all but the last `known`, from the initial predicate,
|
|
955
|
-
// finds the action of each later step, and then rebuilds the trace once more, unless it is a
|
|
956
|
-
// liveness counterexample or TLC is 1.7.4.
|
|
957
|
-
const toTrace = (
|
|
958
|
-
steps: Successor[],
|
|
959
|
-
path: number[],
|
|
960
|
-
traceOptions: TraceOptions = {},
|
|
961
|
-
): Behavior => {
|
|
962
|
-
const alias = config.alias;
|
|
963
|
-
const known = traceOptions.known ?? 1;
|
|
964
|
-
// Rebuilding the trace from the initial predicate can reset what TLCSet stored.
|
|
965
|
-
const initialOutput = steps.length > 1 ? captureOutput(getSpecInitialStates).lines : [];
|
|
966
|
-
// TLC finds the action that takes each step before it evaluates the alias.
|
|
967
|
-
const stepActions = steps.map((step, position) =>
|
|
968
|
-
position === 0 || step.action === "Stuttering"
|
|
969
|
-
? { result: undefined, lines: [] }
|
|
970
|
-
: captureOutput(() =>
|
|
971
|
-
findStepAction(
|
|
972
|
-
path[position - 1],
|
|
973
|
-
steps[position - 1].state,
|
|
974
|
-
step.state,
|
|
975
|
-
known === 2 && position === steps.length - 1,
|
|
976
|
-
),
|
|
977
|
-
),
|
|
978
|
-
);
|
|
979
|
-
const outputs = stepActions.map((step) => step.lines);
|
|
980
|
-
const loopStart = traceOptions.loopStart;
|
|
981
|
-
// TLC 1.7.4 rebuilds a lasso up to its cycle at once, then each cycle state as it prints it.
|
|
982
|
-
const rebuilt = is174 && loopStart !== undefined ? loopStart + 1 : steps.length - known;
|
|
983
|
-
// What the trace prints once comes from each time TLC rebuilds it, which coverage counts.
|
|
984
|
-
if (coverage && steps.length > 1) {
|
|
985
|
-
const isRebuiltAgain = known > 0 && !is174;
|
|
986
|
-
if (rebuilt > 0 && isRebuiltAgain) captureOutput(getSpecInitialStates);
|
|
987
|
-
if (isRebuiltAgain) {
|
|
988
|
-
steps.slice(1).forEach((step, position) => {
|
|
989
|
-
if (step.action === "Stuttering") return;
|
|
990
|
-
captureOutput(() =>
|
|
991
|
-
findStepAction(
|
|
992
|
-
path[position],
|
|
993
|
-
steps[position].state,
|
|
994
|
-
step.state,
|
|
995
|
-
known === 2 && position === steps.length - 2,
|
|
996
|
-
),
|
|
997
|
-
);
|
|
998
|
-
});
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
const prefixOutput = rebuilt > 0 ? [initialOutput, ...outputs.slice(1, rebuilt)].flat() : [];
|
|
1002
|
-
return {
|
|
1003
|
-
trace: steps.map((step, position) => {
|
|
1004
|
-
const action = stepActions[position].result;
|
|
1005
|
-
const traceStep: TraceStep = {
|
|
1006
|
-
action: step.action,
|
|
1007
|
-
label: action && getActionLabel(action, options.version),
|
|
1008
|
-
state:
|
|
1009
|
-
alias === undefined
|
|
1010
|
-
? toRecord(step.state)
|
|
1011
|
-
: getAliasState(alias, steps, position, loopStart),
|
|
1012
|
-
output: position === 0 ? prefixOutput : position < rebuilt ? [] : outputs[position],
|
|
1013
|
-
};
|
|
1014
|
-
if (alias !== undefined || action) {
|
|
1015
|
-
traceSteps.set(traceStep, { state: toRecord(step.state), action });
|
|
1016
|
-
}
|
|
1017
|
-
return traceStep;
|
|
1018
|
-
}),
|
|
1019
|
-
traceOutput: known > 0 && !is174 ? [initialOutput, ...outputs].flat() : [],
|
|
1020
|
-
};
|
|
1021
|
-
};
|
|
1022
804
|
const getSpecInitialStates = () => {
|
|
1023
805
|
if (coverage) return getCoveredInitialStates();
|
|
1024
806
|
return spec.init === undefined ? [] : getInitialStates(spec.init, environment, spec.scope);
|
|
1025
807
|
};
|
|
1026
|
-
// TLC rebuilds a successor action by action, up to the first that generates it. A trace keeps
|
|
1027
|
-
// what the spec prints as TLC rebuilds it, so finding its states prints nothing.
|
|
1028
|
-
const findTraceSuccessor = (state: Value[], isMatch: (successor: Successor) => boolean) =>
|
|
1029
|
-
captureOutput(() => {
|
|
1030
|
-
for (const action of getSpecNextActions()) {
|
|
1031
|
-
const successor = getSuccessors(action.expression, state, environment, action.scope).find(
|
|
1032
|
-
isMatch,
|
|
1033
|
-
);
|
|
1034
|
-
if (successor) return { ...successor, action: successor.action ?? action.name };
|
|
1035
|
-
}
|
|
1036
|
-
return undefined;
|
|
1037
|
-
}).result;
|
|
1038
|
-
const hasFingerprint = (state: Value[], index: number) =>
|
|
1039
|
-
isSameState(getFingerprintState(state), fingerprintStates[index]);
|
|
1040
|
-
const findSuccessorWithFingerprint = (state: Value[], index: number) =>
|
|
1041
|
-
findTraceSuccessor(state, (successor) => hasFingerprint(successor.state, index));
|
|
1042
|
-
const getPathStates = (path: number[], nextFailure: string) => {
|
|
1043
|
-
const initial = captureOutput(() =>
|
|
1044
|
-
isReducing || isImpure(environment)
|
|
1045
|
-
? getSpecInitialStates().find((state) => hasFingerprint(state, path[0]))
|
|
1046
|
-
: states[path[0]],
|
|
1047
|
-
).result;
|
|
1048
|
-
if (!initial) throw new TlaEvaluationError(INITIAL_RECOVERY_FAILURE);
|
|
1049
|
-
const steps: Successor[] = [{ state: initial, action: undefined }];
|
|
1050
|
-
for (let position = 1; position < path.length; position++) {
|
|
1051
|
-
const previous = steps[position - 1].state;
|
|
1052
|
-
if (path[position - 1] === path[position]) {
|
|
1053
|
-
steps.push({ state: previous, action: "Stuttering" });
|
|
1054
|
-
continue;
|
|
1055
|
-
}
|
|
1056
|
-
// TLC rebuilds each state at its level, which TLCGet reads.
|
|
1057
|
-
const rebuilt = current.rebuilt;
|
|
1058
|
-
current.rebuilt = { state: previous, level: depths[path[position - 1]] };
|
|
1059
|
-
const successor = findSuccessorWithFingerprint(previous, path[position]);
|
|
1060
|
-
current.rebuilt = rebuilt;
|
|
1061
|
-
if (!successor) throw new TlaEvaluationError(nextFailure);
|
|
1062
|
-
steps.push(successor);
|
|
1063
|
-
}
|
|
1064
|
-
return steps;
|
|
1065
|
-
};
|
|
1066
|
-
const getTrace = (index: number, lastSuccessor?: Successor) => {
|
|
1067
|
-
const path: number[] = [];
|
|
1068
|
-
for (let position = index; position !== -1; position = parents[position]) {
|
|
1069
|
-
path.unshift(position);
|
|
1070
|
-
}
|
|
1071
|
-
const steps =
|
|
1072
|
-
isReducing && path.length > 1
|
|
1073
|
-
? getPathStates(path, INITIAL_RECOVERY_FAILURE)
|
|
1074
|
-
: path.map((position) => ({ state: states[position], action: actions[position] }));
|
|
1075
|
-
if (!lastSuccessor) return toTrace(steps, path);
|
|
1076
|
-
const action = isReducing
|
|
1077
|
-
? findTraceSuccessor(states[index], (successor) =>
|
|
1078
|
-
isSameState(successor.state, lastSuccessor.state),
|
|
1079
|
-
)?.action
|
|
1080
|
-
: lastSuccessor.action;
|
|
1081
|
-
return toTrace([...steps, { state: lastSuccessor.state, action }], path, { known: 2 });
|
|
1082
|
-
};
|
|
1083
|
-
// TLC rebuilds a lone initial state, unlike TLC 1.7.4. TLCTrace#printTrace prints it without the
|
|
1084
|
-
// alias, where tla-ts applies the alias as it does to every other trace.
|
|
1085
|
-
const getStateTrace = (index: number): Behavior =>
|
|
1086
|
-
parents[index] === -1
|
|
1087
|
-
? {
|
|
1088
|
-
trace: [
|
|
1089
|
-
{
|
|
1090
|
-
action: undefined,
|
|
1091
|
-
label: undefined,
|
|
1092
|
-
state:
|
|
1093
|
-
config.alias === undefined
|
|
1094
|
-
? toRecord(states[index])
|
|
1095
|
-
: getAliasState(
|
|
1096
|
-
config.alias,
|
|
1097
|
-
[{ state: states[index], action: undefined }],
|
|
1098
|
-
0,
|
|
1099
|
-
undefined,
|
|
1100
|
-
),
|
|
1101
|
-
},
|
|
1102
|
-
],
|
|
1103
|
-
traceOutput: is174 ? [] : captureOutput(getSpecInitialStates).lines,
|
|
1104
|
-
}
|
|
1105
|
-
: getTrace(index);
|
|
1106
|
-
// TLC rebuilds the trace for the postcondition after a violation, but not after a failure.
|
|
1107
|
-
// TLC fails again to fingerprint the successor in the trace, as an unexpected exception.
|
|
1108
808
|
const isUnfingerprintable = (state: Value[]) => {
|
|
1109
809
|
try {
|
|
1110
810
|
return getFingerprintState(state).some((value) => getFingerprintError(value) !== undefined);
|
|
@@ -1113,35 +813,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1113
813
|
return true;
|
|
1114
814
|
}
|
|
1115
815
|
};
|
|
1116
|
-
const getFailedTrace = (index: number, successor: Successor): Behavior => ({
|
|
1117
|
-
trace: getTrace(index, successor).trace,
|
|
1118
|
-
});
|
|
1119
|
-
// TLC names the initial state it was checking unless a standard module's Java code failed.
|
|
1120
|
-
const getFailureExitCode = (error: TlaEvaluationError, failureOptions: FailureOptions) => {
|
|
1121
|
-
// TLC 1.7.4 exits with the result of replaying the initial states, which fails again only here.
|
|
1122
|
-
if (
|
|
1123
|
-
failureOptions.isInitial &&
|
|
1124
|
-
!failureOptions.callStack &&
|
|
1125
|
-
!failureOptions.fingerprint &&
|
|
1126
|
-
is174
|
|
1127
|
-
) {
|
|
1128
|
-
return EXIT_STATUS.success;
|
|
1129
|
-
}
|
|
1130
|
-
if (!failureOptions.callStack) {
|
|
1131
|
-
return failureOptions.isInitial ? getInitialExitCode(error) : getErrorExitCode(error);
|
|
1132
|
-
}
|
|
1133
|
-
if (failureOptions.isCallStackFirst) return getErrorExitCode(error);
|
|
1134
|
-
// Without a replay, TLC exits with the code of the error, as for any error it didn't expect.
|
|
1135
|
-
if (failureOptions.isLiveCallStack) {
|
|
1136
|
-
return (
|
|
1137
|
-
getExitCode(error) ?? (error instanceof TlaModuleError ? error.exitCode : EXIT_STATUS.error)
|
|
1138
|
-
);
|
|
1139
|
-
}
|
|
1140
|
-
// TLC exits with the code of a failed initial replay whatever the error, as for a fingerprint.
|
|
1141
|
-
return failureOptions.isInitial || failureOptions.fingerprint
|
|
1142
|
-
? EXIT_STATUS.specEvaluationFailure
|
|
1143
|
-
: getReplayExitCode(failureOptions.replayError ?? error);
|
|
1144
|
-
};
|
|
1145
816
|
const createFailureResult = (
|
|
1146
817
|
failed: unknown,
|
|
1147
818
|
behavior: Behavior,
|
|
@@ -1157,7 +828,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1157
828
|
const traceOutput = [...(behavior.traceOutput ?? []), ...(checked?.lines ?? [])];
|
|
1158
829
|
return {
|
|
1159
830
|
...createResult("error", undefined, {
|
|
1160
|
-
...getFailureMessage(
|
|
831
|
+
...getFailureMessage(
|
|
832
|
+
error,
|
|
833
|
+
failureOptions.phase !== undefined && failureOptions.phase !== "initial",
|
|
834
|
+
),
|
|
1161
835
|
...behavior,
|
|
1162
836
|
...(traceOutput.length > 0 && { traceOutput }),
|
|
1163
837
|
...(postcondition && { postcondition }),
|
|
@@ -1165,22 +839,21 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1165
839
|
failureOptions.initialState && !(error instanceof TlaModuleError)
|
|
1166
840
|
? toRecord(failureOptions.initialState)
|
|
1167
841
|
: undefined,
|
|
1168
|
-
exitCode: getFailureExitCode(error, failureOptions),
|
|
842
|
+
exitCode: getFailureExitCode(error, failureOptions, is174),
|
|
1169
843
|
callStack: failureOptions.callStack,
|
|
1170
|
-
...(failureOptions.
|
|
844
|
+
...(failureOptions.phase === "liveness" && { isCallStackFirst: true }),
|
|
1171
845
|
...(failureOptions.fingerprint && { fingerprint: failureOptions.fingerprint }),
|
|
1172
846
|
...(failureOptions.traceFailure && { traceFailure: failureOptions.traceFailure }),
|
|
1173
847
|
}),
|
|
1174
848
|
outDegrees: failureOptions.outDegrees,
|
|
1175
849
|
};
|
|
1176
850
|
};
|
|
1177
|
-
// TLC reports a partial successor with the trace to it, naming the action if there are several.
|
|
1178
851
|
const reportIncompleteSuccessor = (index: number, error: TlaIncompleteSuccessorError) => {
|
|
1179
852
|
runtime.generatedStates++;
|
|
1180
|
-
const actions = getSpecNextActions();
|
|
1181
853
|
const named =
|
|
1182
|
-
|
|
1183
|
-
|
|
854
|
+
nextActions.length === 1
|
|
855
|
+
? nextActions
|
|
856
|
+
: nextActions.filter((item) => item.name === error.action);
|
|
1184
857
|
const action =
|
|
1185
858
|
named.length === 1
|
|
1186
859
|
? named[0]
|
|
@@ -1192,12 +865,12 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1192
865
|
const message = getIncompleteSuccessorMessage(
|
|
1193
866
|
error.variables,
|
|
1194
867
|
error.action,
|
|
1195
|
-
|
|
868
|
+
nextActions.length,
|
|
1196
869
|
options.version,
|
|
1197
870
|
);
|
|
1198
871
|
const undefinedValue = createModelValue("null");
|
|
1199
872
|
const partial = error.state.map((value) => value ?? undefinedValue);
|
|
1200
|
-
const failure = createFailureResult(error, getStateTrace(index));
|
|
873
|
+
const failure = createFailureResult(error, traces.getStateTrace(index));
|
|
1201
874
|
return withOutDegrees({
|
|
1202
875
|
...failure,
|
|
1203
876
|
failure: failure.failure && {
|
|
@@ -1217,71 +890,16 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1217
890
|
},
|
|
1218
891
|
});
|
|
1219
892
|
};
|
|
1220
|
-
const getPathSteps = (path: number[], loopStart?: number) => {
|
|
1221
|
-
const steps = getPathStates(path, NEXT_RECOVERY_FAILURE);
|
|
1222
|
-
const lastState = steps[steps.length - 1].state;
|
|
1223
|
-
const isClosed =
|
|
1224
|
-
!isReducing ||
|
|
1225
|
-
loopStart === undefined ||
|
|
1226
|
-
loopStart === path.length - 1 ||
|
|
1227
|
-
findSuccessorWithFingerprint(lastState, path[loopStart]) !== undefined;
|
|
1228
|
-
if (!isClosed) throw new TlaEvaluationError(NEXT_RECOVERY_FAILURE);
|
|
1229
|
-
return steps;
|
|
1230
|
-
};
|
|
1231
|
-
const getStateHash = (state: Value[]) => {
|
|
1232
|
-
let hash = 0x811c9dc5;
|
|
1233
|
-
for (let index = 0; index < state.length; index++)
|
|
1234
|
-
hash = combineHash(hash, getValueHash(state[index]));
|
|
1235
|
-
return hash & 0x3fffffff;
|
|
1236
|
-
};
|
|
1237
|
-
// TLC fingerprints a state once it finds the state in the model.
|
|
1238
893
|
const fingerprintModelState = (state: Value[]) => {
|
|
1239
894
|
for (const value of state) {
|
|
1240
895
|
const error = getFingerprintError(value);
|
|
1241
896
|
if (error) throw error;
|
|
1242
897
|
}
|
|
1243
898
|
};
|
|
1244
|
-
|
|
1245
|
-
for (let position = 0; position < state.length; position++) {
|
|
1246
|
-
if (!isSameValue(stored[position], state[position])) return false;
|
|
1247
|
-
}
|
|
1248
|
-
return true;
|
|
1249
|
-
};
|
|
1250
|
-
const getSlot = (hash: number) => (Math.imul(hash, 0x9e3779b1) >>> seenStates.shift) << 1;
|
|
1251
|
-
const findStateIndex = (hash: number, state: Value[]) => {
|
|
1252
|
-
const mask = seenStates.slots.length - 1;
|
|
1253
|
-
for (let slot = getSlot(hash); ; slot = (slot + 2) & mask) {
|
|
1254
|
-
const entry = seenStates.slots[slot + 1];
|
|
1255
|
-
if (entry === 0) return -1;
|
|
1256
|
-
if (seenStates.slots[slot] === hash && isSameState(fingerprintStates[entry - 1], state)) {
|
|
1257
|
-
return entry - 1;
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
};
|
|
1261
|
-
const insertSeen = (hash: number, entry: number) => {
|
|
1262
|
-
const mask = seenStates.slots.length - 1;
|
|
1263
|
-
let slot = getSlot(hash);
|
|
1264
|
-
while (seenStates.slots[slot + 1] !== 0) slot = (slot + 2) & mask;
|
|
1265
|
-
seenStates.slots[slot] = hash;
|
|
1266
|
-
seenStates.slots[slot + 1] = entry;
|
|
1267
|
-
};
|
|
1268
|
-
const markSeen = (hash: number, index: number) => {
|
|
1269
|
-
seenStates.size++;
|
|
1270
|
-
if (seenStates.size * 4 > seenStates.slots.length) {
|
|
1271
|
-
const slots = seenStates.slots;
|
|
1272
|
-
seenStates.slots = new Int32Array(slots.length * 2);
|
|
1273
|
-
seenStates.shift--;
|
|
1274
|
-
for (let slot = 0; slot < slots.length; slot += 2) {
|
|
1275
|
-
if (slots[slot + 1] !== 0) insertSeen(slots[slot], slots[slot + 1]);
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
insertSeen(hash, index + 1);
|
|
1279
|
-
};
|
|
1280
|
-
// TLC adds a new successor to its states before it checks it, which the check stores after.
|
|
1281
|
-
const unstoredState = { fingerprint: undefined as Value[] | undefined };
|
|
899
|
+
let unstoredFingerprint: Value[] | undefined;
|
|
1282
900
|
const countDistinctState = (depth: number) => {
|
|
1283
|
-
runtime.distinctStates = states.length + 1;
|
|
1284
|
-
|
|
901
|
+
runtime.distinctStates = states.length + exploredStates.length + 1;
|
|
902
|
+
searchDepth = Math.max(searchDepth, depth);
|
|
1285
903
|
runtime.diameter = Math.max(runtime.diameter, depth);
|
|
1286
904
|
};
|
|
1287
905
|
const addState = (
|
|
@@ -1298,19 +916,50 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1298
916
|
depths.push(depth);
|
|
1299
917
|
};
|
|
1300
918
|
|
|
1301
|
-
const current = {
|
|
919
|
+
const current: SearchPosition = {
|
|
1302
920
|
index: -1,
|
|
1303
921
|
isExpanding: false,
|
|
1304
|
-
candidate: undefined
|
|
922
|
+
candidate: undefined,
|
|
1305
923
|
candidateLevel: 0,
|
|
1306
924
|
livenessSource: -1,
|
|
1307
|
-
rebuilt: undefined
|
|
925
|
+
rebuilt: undefined,
|
|
1308
926
|
};
|
|
927
|
+
const traces = createTraceBuilder({
|
|
928
|
+
config,
|
|
929
|
+
options,
|
|
930
|
+
environment,
|
|
931
|
+
search,
|
|
932
|
+
nextActions,
|
|
933
|
+
current,
|
|
934
|
+
states,
|
|
935
|
+
fingerprintStates,
|
|
936
|
+
parents,
|
|
937
|
+
actions,
|
|
938
|
+
depths,
|
|
939
|
+
tracedSteps,
|
|
940
|
+
captureOutput,
|
|
941
|
+
getInitialStates: getSpecInitialStates,
|
|
942
|
+
findSuccessorAction,
|
|
943
|
+
});
|
|
1309
944
|
const getPath = (index: number): Value[][] =>
|
|
1310
945
|
index === -1 ? [] : [...getPath(parents[index]), states[index]];
|
|
946
|
+
// TLC adds a successor's fingerprint to its set before it checks the invariants of the successor.
|
|
1311
947
|
runtime.isSeen = (state) => {
|
|
1312
948
|
const fingerprintState = getFingerprintState(state);
|
|
1313
|
-
|
|
949
|
+
const hash = getStateHash(fingerprintState);
|
|
950
|
+
return (
|
|
951
|
+
findStateIndex(seenStates, hash, fingerprintState) !== -1 ||
|
|
952
|
+
isExplored(hash, fingerprintState) ||
|
|
953
|
+
(unstoredFingerprint !== undefined && isSameState(unstoredFingerprint, fingerprintState))
|
|
954
|
+
);
|
|
955
|
+
};
|
|
956
|
+
runtime.markExplored = (state) => {
|
|
957
|
+
const fingerprintState = getFingerprintState(state);
|
|
958
|
+
exploredTable ??= createStateTable(exploredFingerprintStates);
|
|
959
|
+
markSeenState(exploredTable, getStateHash(fingerprintState), exploredStates.length);
|
|
960
|
+
exploredStates.push(state);
|
|
961
|
+
exploredFingerprintStates.push(fingerprintState);
|
|
962
|
+
runtime.distinctStates++;
|
|
1314
963
|
};
|
|
1315
964
|
runtime.getBehavior = (state) => {
|
|
1316
965
|
const index = state === current.candidate ? -1 : states.indexOf(state);
|
|
@@ -1322,7 +971,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1322
971
|
};
|
|
1323
972
|
runtime.getLevel = (state) => {
|
|
1324
973
|
const source = current.livenessSource;
|
|
1325
|
-
// TLC 1.7.4 reads the level of the state its worker explores, whichever state it evaluates.
|
|
1326
974
|
if (is174) {
|
|
1327
975
|
const explored = source !== -1 ? source : current.isExpanding ? current.index : -1;
|
|
1328
976
|
return explored === -1 ? 0 : depths[explored];
|
|
@@ -1347,7 +995,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1347
995
|
formatState(
|
|
1348
996
|
config.alias === undefined
|
|
1349
997
|
? toRecord(state)
|
|
1350
|
-
: evaluateAlias(config.alias, state, undefined),
|
|
998
|
+
: search.evaluateAlias(config.alias, state, undefined, options.isTool ?? false),
|
|
1351
999
|
),
|
|
1352
1000
|
getText: () => formatState(toRecord(state)),
|
|
1353
1001
|
});
|
|
@@ -1366,9 +1014,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1366
1014
|
fingerprintModelState(fingerprintState);
|
|
1367
1015
|
state.forEach(markFingerprinted);
|
|
1368
1016
|
}
|
|
1369
|
-
const isSeen = isInModel && findStateIndex(hash, fingerprintState) !== -1;
|
|
1017
|
+
const isSeen = isInModel && findStateIndex(seenStates, hash, fingerprintState) !== -1;
|
|
1370
1018
|
if (isSeen) return undefined;
|
|
1371
|
-
|
|
1019
|
+
unstoredFingerprint = isInModel ? fingerprintState : undefined;
|
|
1372
1020
|
if (isInModel) {
|
|
1373
1021
|
countDistinctState(1);
|
|
1374
1022
|
runtime.queueSize++;
|
|
@@ -1379,7 +1027,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1379
1027
|
search.getViolatedInvariants(state).forEach((invariant) =>
|
|
1380
1028
|
reportContinuedViolation("invariant-violation", {
|
|
1381
1029
|
name: invariant.name,
|
|
1382
|
-
...toTrace([{ action: undefined, state }], []),
|
|
1030
|
+
...traces.toTrace([{ action: undefined, state }], []),
|
|
1383
1031
|
}),
|
|
1384
1032
|
);
|
|
1385
1033
|
}
|
|
@@ -1387,21 +1035,44 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1387
1035
|
if (violated) {
|
|
1388
1036
|
return reportViolation("invariant-violation", {
|
|
1389
1037
|
name: violated.name,
|
|
1390
|
-
...toTrace([{ action: undefined, state }], []),
|
|
1038
|
+
...traces.toTrace([{ action: undefined, state }], []),
|
|
1391
1039
|
});
|
|
1392
1040
|
}
|
|
1393
1041
|
const failedPredicate = search.findFailedInitialPredicate(state);
|
|
1394
1042
|
if (failedPredicate) {
|
|
1395
1043
|
return reportViolation("liveness-violation", {
|
|
1396
1044
|
name: failedPredicate.name,
|
|
1397
|
-
...toTrace([{ action: undefined, state }], []),
|
|
1045
|
+
...traces.toTrace([{ action: undefined, state }], []),
|
|
1398
1046
|
});
|
|
1399
1047
|
}
|
|
1400
1048
|
if (!isInModel) return undefined;
|
|
1401
|
-
|
|
1049
|
+
markSeenState(seenStates, hash, states.length);
|
|
1402
1050
|
addState(state, fingerprintState, -1, undefined);
|
|
1403
1051
|
return undefined;
|
|
1404
1052
|
};
|
|
1053
|
+
// Looks a successor up, where the constraints keep it in the model, as the search does before it
|
|
1054
|
+
// checks the successor.
|
|
1055
|
+
const lookUpSuccessor = (state: Value[], successor: Successor) => {
|
|
1056
|
+
const fingerprintState = getFingerprintState(successor.state);
|
|
1057
|
+
const hash = getStateHash(fingerprintState);
|
|
1058
|
+
const foundIndex = findStateIndex(seenStates, hash, fingerprintState);
|
|
1059
|
+
const isStateInModel = search.satisfiesConstraints(successor.state, state);
|
|
1060
|
+
if (isStateInModel) search.trackStatePossible(successor.state);
|
|
1061
|
+
const isInModel = isStateInModel && search.satisfiesActionConstraints(state, successor.state);
|
|
1062
|
+
if (isInModel) {
|
|
1063
|
+
search.trackActionPossible(state, successor.state);
|
|
1064
|
+
fingerprintModelState(fingerprintState);
|
|
1065
|
+
successor.state.forEach(markFingerprinted);
|
|
1066
|
+
}
|
|
1067
|
+
const existing = isInModel ? foundIndex : -1;
|
|
1068
|
+
return {
|
|
1069
|
+
fingerprintState,
|
|
1070
|
+
hash,
|
|
1071
|
+
isInModel,
|
|
1072
|
+
existing,
|
|
1073
|
+
isSeen: existing !== -1 || (isInModel && isExplored(hash, fingerprintState)),
|
|
1074
|
+
};
|
|
1075
|
+
};
|
|
1405
1076
|
const visitSuccessor = (
|
|
1406
1077
|
index: number,
|
|
1407
1078
|
successor: Successor,
|
|
@@ -1414,27 +1085,16 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1414
1085
|
current.candidate = successor.state;
|
|
1415
1086
|
current.candidateLevel = depths[index] + 1;
|
|
1416
1087
|
if (isCanonicalizedFirst) canonicalizeState(successor.state);
|
|
1417
|
-
const
|
|
1418
|
-
|
|
1419
|
-
const foundIndex = findStateIndex(hash, fingerprintState);
|
|
1420
|
-
const isStateInModel = search.satisfiesConstraints(successor.state, state);
|
|
1421
|
-
if (isStateInModel) search.trackStatePossible(successor.state);
|
|
1422
|
-
const isInModel = isStateInModel && search.satisfiesActionConstraints(state, successor.state);
|
|
1423
|
-
if (isInModel) {
|
|
1424
|
-
search.trackActionPossible(state, successor.state);
|
|
1425
|
-
fingerprintModelState(fingerprintState);
|
|
1426
|
-
successor.state.forEach(markFingerprinted);
|
|
1427
|
-
}
|
|
1428
|
-
const existing = isInModel ? foundIndex : -1;
|
|
1429
|
-
if (source && isInModel) {
|
|
1088
|
+
const found = lookUpSuccessor(state, successor);
|
|
1089
|
+
if (source && found.isInModel) {
|
|
1430
1090
|
stateWriter?.writeSuccessor(
|
|
1431
1091
|
source,
|
|
1432
1092
|
getGraphState(successor.state, depths[index] + 1),
|
|
1433
|
-
|
|
1093
|
+
found.isSeen,
|
|
1434
1094
|
action && getGraphAction(action),
|
|
1435
1095
|
);
|
|
1436
1096
|
}
|
|
1437
|
-
if (source && !isInModel && options.dump?.constrained) {
|
|
1097
|
+
if (source && !found.isInModel && options.dump?.constrained) {
|
|
1438
1098
|
const excluded = getGraphState(successor.state, depths[index] + 1);
|
|
1439
1099
|
search
|
|
1440
1100
|
.getExcludingConstraints(state, successor.state)
|
|
@@ -1447,36 +1107,39 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1447
1107
|
),
|
|
1448
1108
|
);
|
|
1449
1109
|
}
|
|
1450
|
-
if (existing !== -1 && liveness) {
|
|
1451
|
-
const stored = states[existing];
|
|
1110
|
+
if (found.existing !== -1 && liveness) {
|
|
1111
|
+
const stored = states[found.existing];
|
|
1452
1112
|
const isStored = stored.every((value, position) => value === successor.state[position]);
|
|
1453
|
-
liveSuccessors.push({ index: existing, state: isStored ? stored : successor.state });
|
|
1113
|
+
liveSuccessors.push({ index: found.existing, state: isStored ? stored : successor.state });
|
|
1114
|
+
}
|
|
1115
|
+
if (found.isSeen && found.existing === -1 && liveness) {
|
|
1116
|
+
liveSuccessors.push({
|
|
1117
|
+
index: getPendingIndex(found.hash, found.fingerprintState),
|
|
1118
|
+
state: successor.state,
|
|
1119
|
+
});
|
|
1454
1120
|
}
|
|
1455
|
-
const isNew = isInModel &&
|
|
1456
|
-
// TLC adds a new state to the behavior graph's successors before it checks the invariants.
|
|
1121
|
+
const isNew = found.isInModel && !found.isSeen;
|
|
1457
1122
|
if (isNew && liveness) liveSuccessors.push({ index: states.length, state: successor.state });
|
|
1458
|
-
|
|
1123
|
+
unstoredFingerprint = isNew ? found.fingerprintState : undefined;
|
|
1459
1124
|
if (isNew) {
|
|
1460
1125
|
countDistinctState(depths[index] + 1);
|
|
1461
|
-
|
|
1462
|
-
if (coverage) coverage.secondary[
|
|
1126
|
+
newStateCount++;
|
|
1127
|
+
if (coverage) coverage.secondary[coveredNode]++;
|
|
1463
1128
|
}
|
|
1464
|
-
if (
|
|
1129
|
+
if (!found.isSeen) {
|
|
1465
1130
|
try {
|
|
1466
1131
|
const violated = search.findViolatedInvariant(successor.state, state);
|
|
1467
|
-
const violation = violated && { name: violated.name, ...getTrace(index, successor) };
|
|
1132
|
+
const violation = violated && { name: violated.name, ...traces.getTrace(index, successor) };
|
|
1468
1133
|
if (violation && !options.isContinued) {
|
|
1469
1134
|
return withOutDegrees(reportViolation("invariant-violation", violation));
|
|
1470
1135
|
}
|
|
1471
1136
|
if (violation) reportContinuedViolation("invariant-violation", violation);
|
|
1472
1137
|
} catch (error) {
|
|
1473
1138
|
if (isStackOverflow(error)) throw error;
|
|
1474
|
-
// TLC replays the expansion and skips the invariants of a seen state, the failed one
|
|
1475
|
-
// included unless the constraints exclude it. A failed replay leaves out the outdegree.
|
|
1476
1139
|
const replay = captureOutput(() => replayNext(index));
|
|
1477
1140
|
return createFailureResult(
|
|
1478
1141
|
error,
|
|
1479
|
-
appendTraceOutput(getFailedTrace(index, successor), replay.lines),
|
|
1142
|
+
appendTraceOutput(traces.getFailedTrace(index, successor), replay.lines),
|
|
1480
1143
|
replay.result ?? { outDegrees: getFailureOutDegrees() },
|
|
1481
1144
|
);
|
|
1482
1145
|
}
|
|
@@ -1484,7 +1147,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1484
1147
|
const violatedProperty = search.findViolatedActionProperty(state, successor.state);
|
|
1485
1148
|
const propertyViolation = violatedProperty && {
|
|
1486
1149
|
name: violatedProperty.name,
|
|
1487
|
-
...getTrace(index, successor),
|
|
1150
|
+
...traces.getTrace(index, successor),
|
|
1488
1151
|
};
|
|
1489
1152
|
if (propertyViolation && !options.isContinued) {
|
|
1490
1153
|
return withOutDegrees(reportViolation("liveness-violation", propertyViolation));
|
|
@@ -1493,47 +1156,101 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1493
1156
|
if (!isNew) return undefined;
|
|
1494
1157
|
if (coverage) countCoverageVariables(coverage, successor.state);
|
|
1495
1158
|
if (!isCanonicalizedFirst) canonicalizeState(successor.state);
|
|
1496
|
-
|
|
1497
|
-
|
|
1159
|
+
markSeenState(seenStates, found.hash, states.length);
|
|
1160
|
+
if (pendingStates) {
|
|
1161
|
+
const pending = findStateIndex(pendingStates, found.hash, found.fingerprintState);
|
|
1162
|
+
if (pending !== -1) liveness?.storeState(-2 - pending, states.length);
|
|
1163
|
+
}
|
|
1164
|
+
addState(successor.state, found.fingerprintState, index, successor.action);
|
|
1498
1165
|
runtime.queueSize++;
|
|
1499
1166
|
return undefined;
|
|
1500
1167
|
};
|
|
1501
1168
|
|
|
1502
|
-
|
|
1503
|
-
|
|
1169
|
+
let outcome: CheckResult | undefined;
|
|
1170
|
+
let coveredNode = -1;
|
|
1504
1171
|
if (liveness) {
|
|
1505
1172
|
options.onProgress?.({ kind: "liveness-prepared", branches: liveness.branches });
|
|
1506
1173
|
}
|
|
1507
|
-
// TLC checks the assumptions once it has built the liveness checker.
|
|
1508
1174
|
const assumptionViolation = findViolatedAssumption();
|
|
1509
1175
|
if (assumptionViolation) return createResult("assumption-violation", assumptionViolation);
|
|
1510
1176
|
options.onProgress?.({ kind: "initial-states-started" });
|
|
1177
|
+
const typedChecks =
|
|
1178
|
+
!options.isContinued &&
|
|
1179
|
+
options.dump === undefined &&
|
|
1180
|
+
// A set of small integers on the tier is a 31-bit mask, which a lower bound could overflow.
|
|
1181
|
+
options.maxSetSize === undefined &&
|
|
1182
|
+
!hasPostconditions
|
|
1183
|
+
? search.getTypedChecks(liveness?.solutions)
|
|
1184
|
+
: undefined;
|
|
1185
|
+
const typed =
|
|
1186
|
+
typedChecks &&
|
|
1187
|
+
runTypedSearch(environment, {
|
|
1188
|
+
...typedChecks,
|
|
1189
|
+
isDeadlockChecked: config.checkDeadlock,
|
|
1190
|
+
isFingerprinted: !options.isFingerprintDistanceSkipped,
|
|
1191
|
+
livenessCheck: options.livenessCheck ?? "default",
|
|
1192
|
+
});
|
|
1193
|
+
if (typed && !typed.deadlock && !typed.violation && !typed.lasso) {
|
|
1194
|
+
for (let count = 2; count < typed.initialStates.generated; count *= 2) {
|
|
1195
|
+
reportInitialStatesProgress(count, options.onProgress);
|
|
1196
|
+
}
|
|
1197
|
+
options.onProgress?.({ kind: "initial-states-computed", initialStates: typed.initialStates });
|
|
1198
|
+
const statistics = {
|
|
1199
|
+
...createResult("success"),
|
|
1200
|
+
generatedStates: typed.generatedStates,
|
|
1201
|
+
distinctStates: typed.distinctStates,
|
|
1202
|
+
queuedStates: 0,
|
|
1203
|
+
depth: typed.generatedStates === 0 ? 0 : Math.max(typed.depth, 1),
|
|
1204
|
+
initialStates: typed.initialStates,
|
|
1205
|
+
};
|
|
1206
|
+
if (liveness && options.livenessCheck !== "off") {
|
|
1207
|
+
options.onProgress?.({
|
|
1208
|
+
kind: "liveness-started",
|
|
1209
|
+
branches: liveness.branches,
|
|
1210
|
+
isComplete: true,
|
|
1211
|
+
// The tier stores and expands every successor, so the graph of each branch has every state.
|
|
1212
|
+
states: liveness.branches * typed.distinctStates,
|
|
1213
|
+
statistics,
|
|
1214
|
+
});
|
|
1215
|
+
options.onProgress?.({ kind: "liveness-finished" });
|
|
1216
|
+
}
|
|
1217
|
+
return {
|
|
1218
|
+
...statistics,
|
|
1219
|
+
outDegrees: typed.outDegrees,
|
|
1220
|
+
fingerprintDistance: options.isFingerprintDistanceSkipped
|
|
1221
|
+
? undefined
|
|
1222
|
+
: getFingerprintDistance(
|
|
1223
|
+
typed.distinctStates,
|
|
1224
|
+
typed.generatedStates,
|
|
1225
|
+
typed.forEachFingerprintRun,
|
|
1226
|
+
),
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1511
1229
|
if (spec.init !== undefined) {
|
|
1512
|
-
|
|
1513
|
-
const overflow: { state: Value[] | undefined } = { state: undefined };
|
|
1230
|
+
let overflowState: Value[] | undefined;
|
|
1514
1231
|
const reportInitialFailure = (error: unknown, state: Value[]) => {
|
|
1515
1232
|
const replay = captureOutput(replayInit);
|
|
1516
1233
|
return createFailureResult(
|
|
1517
1234
|
error,
|
|
1518
1235
|
{ trace: [], traceOutput: replay.lines },
|
|
1519
|
-
{ initialState: state, ...replay.result,
|
|
1236
|
+
{ initialState: state, ...replay.result, phase: "initial" },
|
|
1520
1237
|
);
|
|
1521
1238
|
};
|
|
1522
1239
|
try {
|
|
1523
1240
|
const onInitialState = (state: Value[]) => {
|
|
1524
1241
|
reportInitialStatesProgress(runtime.initialStates, options.onProgress);
|
|
1525
|
-
if (
|
|
1242
|
+
if (overflowState) {
|
|
1526
1243
|
runtime.generatedStates++;
|
|
1527
1244
|
runtime.initialStates++;
|
|
1528
1245
|
return false;
|
|
1529
1246
|
}
|
|
1530
1247
|
try {
|
|
1531
|
-
outcome
|
|
1248
|
+
outcome = visitInitialState(state);
|
|
1532
1249
|
} catch (error) {
|
|
1533
|
-
if (isStackOverflow(error))
|
|
1534
|
-
else outcome
|
|
1250
|
+
if (isStackOverflow(error)) overflowState = state;
|
|
1251
|
+
else outcome = reportInitialFailure(error, state);
|
|
1535
1252
|
}
|
|
1536
|
-
return outcome
|
|
1253
|
+
return outcome !== undefined;
|
|
1537
1254
|
};
|
|
1538
1255
|
if (coverage) {
|
|
1539
1256
|
try {
|
|
@@ -1543,9 +1260,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1543
1260
|
(state) => {
|
|
1544
1261
|
if (onInitialState(state)) throw STOP_WALK;
|
|
1545
1262
|
},
|
|
1546
|
-
|
|
1547
|
-
throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
|
|
1548
|
-
},
|
|
1263
|
+
rejectIncompleteInitialState,
|
|
1549
1264
|
);
|
|
1550
1265
|
} catch (error) {
|
|
1551
1266
|
if (error !== STOP_WALK) throw error;
|
|
@@ -1553,11 +1268,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1553
1268
|
} else {
|
|
1554
1269
|
forEachInitialState(spec.init, environment, onInitialState, spec.scope);
|
|
1555
1270
|
}
|
|
1556
|
-
if (
|
|
1557
|
-
outcome
|
|
1271
|
+
if (overflowState) {
|
|
1272
|
+
outcome = reportInitialFailure(createStackOverflowError(), overflowState);
|
|
1558
1273
|
}
|
|
1559
1274
|
} catch (error) {
|
|
1560
|
-
// TLC prints null for each undefined variable and stops before the statistics.
|
|
1561
1275
|
if (error instanceof TlaIllegalStateError) {
|
|
1562
1276
|
const illegal = createFailureResult(
|
|
1563
1277
|
error,
|
|
@@ -1569,23 +1283,22 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1569
1283
|
failure: illegal.failure && { ...illegal.failure, isWithoutStatistics: true },
|
|
1570
1284
|
};
|
|
1571
1285
|
}
|
|
1572
|
-
// TLC prints the error before it replays the initial predicate with its call stack.
|
|
1573
1286
|
const replay = captureOutput(replayInit);
|
|
1574
1287
|
return createFailureResult(
|
|
1575
1288
|
error,
|
|
1576
1289
|
{ trace: [], traceOutput: replay.lines },
|
|
1577
|
-
{ ...replay.result,
|
|
1290
|
+
{ ...replay.result, phase: "initial" },
|
|
1578
1291
|
);
|
|
1579
1292
|
}
|
|
1580
1293
|
}
|
|
1581
|
-
if (outcome
|
|
1582
|
-
|
|
1294
|
+
if (outcome) return outcome;
|
|
1295
|
+
computedInitialStates = {
|
|
1583
1296
|
generated: runtime.initialStates,
|
|
1584
1297
|
distinct: runtime.distinctStates,
|
|
1585
1298
|
};
|
|
1586
1299
|
options.onProgress?.({
|
|
1587
1300
|
kind: "initial-states-computed",
|
|
1588
|
-
initialStates:
|
|
1301
|
+
initialStates: computedInitialStates,
|
|
1589
1302
|
});
|
|
1590
1303
|
|
|
1591
1304
|
const next = spec.next;
|
|
@@ -1597,8 +1310,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1597
1310
|
}
|
|
1598
1311
|
return createSuccess();
|
|
1599
1312
|
}
|
|
1600
|
-
// TLC labels and colors a -dump edge by its action, so a graph that names its edges generates
|
|
1601
|
-
// successors action by action.
|
|
1602
1313
|
const isNamingEdges = Boolean(
|
|
1603
1314
|
options.dump?.dot && (options.dump.actionLabels || options.dump.colorize),
|
|
1604
1315
|
);
|
|
@@ -1610,19 +1321,19 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1610
1321
|
onSuccessor: (successor: Successor, action: SpecAction | undefined) => boolean,
|
|
1611
1322
|
) => {
|
|
1612
1323
|
if (coverage) {
|
|
1613
|
-
|
|
1324
|
+
let successorCount = 0;
|
|
1614
1325
|
try {
|
|
1615
1326
|
coverageActions.forEach((action) => {
|
|
1616
|
-
|
|
1327
|
+
coveredNode = action.node;
|
|
1617
1328
|
walkCoveredSuccessors(action, state, (successor) => {
|
|
1618
|
-
|
|
1329
|
+
successorCount++;
|
|
1619
1330
|
if (onSuccessor({ state: successor, action: action.name }, action)) throw STOP_WALK;
|
|
1620
1331
|
});
|
|
1621
1332
|
});
|
|
1622
1333
|
} catch (error) {
|
|
1623
1334
|
if (error !== STOP_WALK) throw error;
|
|
1624
1335
|
}
|
|
1625
|
-
return
|
|
1336
|
+
return successorCount;
|
|
1626
1337
|
}
|
|
1627
1338
|
if (!isNamingEdges) {
|
|
1628
1339
|
return forEachSuccessor(
|
|
@@ -1635,9 +1346,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1635
1346
|
onUnsatisfied,
|
|
1636
1347
|
);
|
|
1637
1348
|
}
|
|
1638
|
-
|
|
1639
|
-
return
|
|
1640
|
-
if (
|
|
1349
|
+
let isStopped = false;
|
|
1350
|
+
return nextActions.reduce((count, action) => {
|
|
1351
|
+
if (isStopped) return count;
|
|
1641
1352
|
return (
|
|
1642
1353
|
count +
|
|
1643
1354
|
forEachSuccessor(
|
|
@@ -1645,8 +1356,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1645
1356
|
state,
|
|
1646
1357
|
environment,
|
|
1647
1358
|
(successor) => {
|
|
1648
|
-
|
|
1649
|
-
return
|
|
1359
|
+
isStopped = onSuccessor(successor, action);
|
|
1360
|
+
return isStopped;
|
|
1650
1361
|
},
|
|
1651
1362
|
action.scope,
|
|
1652
1363
|
undefined,
|
|
@@ -1655,17 +1366,13 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1655
1366
|
);
|
|
1656
1367
|
}, 0);
|
|
1657
1368
|
};
|
|
1658
|
-
// TLC's worker adds a state to the behavior graph even after its next states fail, and prints
|
|
1659
|
-
// the call stack of an error in that, unless it is a FingerprintException. TLC 1.7.4 prints none.
|
|
1660
1369
|
const getLiveCallStack = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1661
1370
|
if (!liveness || is174) return undefined;
|
|
1662
|
-
const replay = getReplayFailure((tracing) =>
|
|
1371
|
+
const replay = getReplayFailure(environment, (tracing) =>
|
|
1663
1372
|
liveness.addState(index, states[index], liveSuccessors, tracing),
|
|
1664
1373
|
);
|
|
1665
1374
|
return replay?.callStack.length && !replay.fingerprint ? replay.callStack : undefined;
|
|
1666
1375
|
};
|
|
1667
|
-
// On an error in adding the state after the trace, TLC adds it again to print the call stack
|
|
1668
|
-
// instead of replaying the next-state relation, which TLC 1.7.4 doesn't.
|
|
1669
1376
|
const addFailedLiveState = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1670
1377
|
try {
|
|
1671
1378
|
liveness?.addState(index, states[index], liveSuccessors);
|
|
@@ -1678,16 +1385,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1678
1385
|
const replayFailedNext = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1679
1386
|
const live = captureOutput(() => addFailedLiveState(index, liveSuccessors));
|
|
1680
1387
|
if (live.result) {
|
|
1681
|
-
const result = { callStack: live.result
|
|
1388
|
+
const result: FailureOptions = { phase: "behavior-graph", callStack: live.result };
|
|
1682
1389
|
return { result, lines: live.lines };
|
|
1683
1390
|
}
|
|
1684
1391
|
const replay = captureOutput(() => replayNext(index));
|
|
1685
1392
|
return { result: replay.result, lines: [...live.lines, ...replay.lines] };
|
|
1686
1393
|
};
|
|
1687
|
-
// TLC reports a stack overflow in the next states without a replay, up to the state it expands.
|
|
1688
1394
|
const reportNextStateOverflow = (index: number) =>
|
|
1689
|
-
createFailureResult(createStackOverflowError(), getStateTrace(index), {
|
|
1690
|
-
// After the trace, TLC replays the next-state relation with its call stack, printing again.
|
|
1395
|
+
createFailureResult(createStackOverflowError(), traces.getStateTrace(index), { phase: "next" });
|
|
1691
1396
|
const reportNextStateFailure = (
|
|
1692
1397
|
error: unknown,
|
|
1693
1398
|
index: number,
|
|
@@ -1697,8 +1402,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1697
1402
|
const replay = replayFailedNext(index, liveSuccessors);
|
|
1698
1403
|
return createFailureResult(
|
|
1699
1404
|
withNextStateExitCode(error),
|
|
1700
|
-
appendTraceOutput(getStateTrace(index), replay.lines),
|
|
1701
|
-
{
|
|
1405
|
+
appendTraceOutput(traces.getStateTrace(index), replay.lines),
|
|
1406
|
+
{ phase: "next", ...replay.result },
|
|
1702
1407
|
);
|
|
1703
1408
|
};
|
|
1704
1409
|
const expandState = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
@@ -1716,22 +1421,20 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1716
1421
|
: undefined;
|
|
1717
1422
|
const successorCount = forEachActionSuccessor(state, writeUnsatisfied, (successor, action) => {
|
|
1718
1423
|
try {
|
|
1719
|
-
outcome
|
|
1424
|
+
outcome = visitSuccessor(index, successor, liveSuccessors, source, action);
|
|
1720
1425
|
} catch (error) {
|
|
1721
1426
|
if (isStackOverflow(error)) {
|
|
1722
|
-
outcome
|
|
1427
|
+
outcome = reportNextStateOverflow(index);
|
|
1723
1428
|
return true;
|
|
1724
1429
|
}
|
|
1725
|
-
// TLC 1.7.4 reports the wrapped error without the trace, except for a failed property, and
|
|
1726
|
-
// stops its worker before it adds the state to the behavior graph.
|
|
1727
1430
|
const replay = is174
|
|
1728
1431
|
? captureOutput(() => replayNext(index))
|
|
1729
1432
|
: replayFailedNext(index, liveSuccessors);
|
|
1730
1433
|
if (is174 && error instanceof TlaEvaluationError && !isHeadedError(error)) {
|
|
1731
|
-
outcome
|
|
1434
|
+
outcome = createFailureResult(
|
|
1732
1435
|
new TlaEvaluationError(`${getWrappedException(error)}${error.message}`, error),
|
|
1733
1436
|
appendTraceOutput({ trace: [] }, replay.lines),
|
|
1734
|
-
{
|
|
1437
|
+
{ phase: "next", ...replay.result },
|
|
1735
1438
|
);
|
|
1736
1439
|
return true;
|
|
1737
1440
|
}
|
|
@@ -1745,25 +1448,26 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1745
1448
|
true,
|
|
1746
1449
|
)
|
|
1747
1450
|
: undefined;
|
|
1748
|
-
outcome
|
|
1451
|
+
outcome = createFailureResult(
|
|
1749
1452
|
error,
|
|
1750
1453
|
appendTraceOutput(
|
|
1751
|
-
traceFailure ? getStateTrace(index) : getFailedTrace(index, successor),
|
|
1454
|
+
traceFailure ? traces.getStateTrace(index) : traces.getFailedTrace(index, successor),
|
|
1752
1455
|
replay.lines,
|
|
1753
1456
|
),
|
|
1754
|
-
{
|
|
1457
|
+
{ phase: "next", ...replay.result, traceFailure },
|
|
1755
1458
|
);
|
|
1756
1459
|
}
|
|
1757
|
-
return outcome
|
|
1460
|
+
return outcome !== undefined;
|
|
1758
1461
|
});
|
|
1759
1462
|
current.isExpanding = false;
|
|
1760
|
-
const result = outcome
|
|
1761
|
-
// TLC 1.7.4's worker stops at a violation.
|
|
1463
|
+
const result = outcome;
|
|
1762
1464
|
if (result?.violation && !is174) {
|
|
1763
1465
|
const live = captureOutput(() => addFailedLiveState(index, liveSuccessors));
|
|
1764
1466
|
return {
|
|
1765
1467
|
...result,
|
|
1766
1468
|
violation: appendTraceOutput(result.violation, live.lines),
|
|
1469
|
+
// TLC adds the state to the behavior graph before it reports the coverage.
|
|
1470
|
+
coverage: getCoverage(),
|
|
1767
1471
|
...(live.result && { liveCallStack: live.result }),
|
|
1768
1472
|
};
|
|
1769
1473
|
}
|
|
@@ -1774,7 +1478,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1774
1478
|
}
|
|
1775
1479
|
const accepted = liveness?.addState(index, state, liveSuccessors);
|
|
1776
1480
|
if (!liveness || !accepted) return undefined;
|
|
1777
|
-
const steps = getPathSteps(accepted);
|
|
1481
|
+
const steps = traces.getPathSteps(accepted);
|
|
1778
1482
|
const properties = getViolatedProperties(
|
|
1779
1483
|
liveness,
|
|
1780
1484
|
steps.map((step) => step.state),
|
|
@@ -1783,13 +1487,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1783
1487
|
return reportViolation("property-violation", {
|
|
1784
1488
|
name: properties[0],
|
|
1785
1489
|
properties,
|
|
1786
|
-
...toTrace(steps, accepted, { known: 0 }),
|
|
1490
|
+
...traces.toTrace(steps, accepted, { known: 0 }),
|
|
1787
1491
|
});
|
|
1788
1492
|
};
|
|
1789
1493
|
if (successorCount === 0 && config.checkDeadlock) {
|
|
1790
|
-
const deadlock = reportViolation("deadlock", {
|
|
1791
|
-
|
|
1792
|
-
|
|
1494
|
+
const deadlock = reportViolation("deadlock", {
|
|
1495
|
+
name: "deadlock",
|
|
1496
|
+
...traces.getStateTrace(index),
|
|
1497
|
+
});
|
|
1793
1498
|
const live = captureOutput(() => {
|
|
1794
1499
|
try {
|
|
1795
1500
|
return { additional: addLiveState()?.violation };
|
|
@@ -1801,7 +1506,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1801
1506
|
const reported = deadlock.violation
|
|
1802
1507
|
? { ...deadlock, violation: appendTraceOutput(deadlock.violation, live.lines) }
|
|
1803
1508
|
: deadlock;
|
|
1804
|
-
// An error in adding the state stops TLC 1.7.4's worker before it counts the state.
|
|
1805
1509
|
const counted = withOutDegrees(
|
|
1806
1510
|
reported,
|
|
1807
1511
|
live.result.isFailed ? getFailureOutDegrees() : getPartialOutDegrees(),
|
|
@@ -1813,7 +1517,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1813
1517
|
try {
|
|
1814
1518
|
return addLiveState();
|
|
1815
1519
|
} catch (error) {
|
|
1816
|
-
// TLC 1.7.4 reports this as an unexpected exception, without the trace or a call stack.
|
|
1817
1520
|
if (is174 && error instanceof TlaEvaluationError) {
|
|
1818
1521
|
const unexpected = new TlaEvaluationError(
|
|
1819
1522
|
`${isEvalException(error) ? UNEXPECTED_EVAL_EXCEPTION : UNEXPECTED_EXCEPTION}${error.message}`,
|
|
@@ -1824,15 +1527,13 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1824
1527
|
{ outDegrees: getFailureOutDegrees() },
|
|
1825
1528
|
);
|
|
1826
1529
|
}
|
|
1827
|
-
|
|
1828
|
-
const replay = getReplayFailure((tracing) =>
|
|
1530
|
+
const replay = getReplayFailure(environment, (tracing) =>
|
|
1829
1531
|
liveness?.addState(index, state, liveSuccessors, tracing),
|
|
1830
1532
|
);
|
|
1831
|
-
return createFailureResult(error, getStateTrace(index), {
|
|
1533
|
+
return createFailureResult(error, traces.getStateTrace(index), {
|
|
1832
1534
|
outDegrees: getFailureOutDegrees(),
|
|
1833
1535
|
callStack: replay?.callStack.length ? replay.callStack : undefined,
|
|
1834
|
-
|
|
1835
|
-
isCallStackFirst: true,
|
|
1536
|
+
phase: "liveness",
|
|
1836
1537
|
});
|
|
1837
1538
|
}
|
|
1838
1539
|
};
|
|
@@ -1853,12 +1554,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1853
1554
|
text: `The stuttering counterexample above may be caused by the absence of a fairness constraint in the behavior specification ${name} defined at ${formatRange(range)}. To rule out such counterexamples, conjoin a suitable fairness constraint to ${name} ${book}`,
|
|
1854
1555
|
};
|
|
1855
1556
|
};
|
|
1856
|
-
// TLC names the properties and the step back into the cycle from the states it prints.
|
|
1857
1557
|
const reportLasso = (checker: LivenessChecker, lasso: Lasso) => {
|
|
1858
1558
|
const path = [...lasso.prefix, ...lasso.cycle];
|
|
1859
1559
|
const loopStart = lasso.prefix.length;
|
|
1860
|
-
const steps = getPathSteps(path, loopStart);
|
|
1861
|
-
const trace = toTrace(steps, path, { loopStart, known: 0 }).trace;
|
|
1560
|
+
const steps = traces.getPathSteps(path, loopStart);
|
|
1561
|
+
const trace = traces.toTrace(steps, path, { loopStart, known: 0 }).trace;
|
|
1862
1562
|
const properties = getViolatedProperties(
|
|
1863
1563
|
checker,
|
|
1864
1564
|
steps.map((step) => step.state),
|
|
@@ -1870,7 +1570,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1870
1570
|
const loop =
|
|
1871
1571
|
cycleStart === cycleEnd
|
|
1872
1572
|
? { result: undefined, lines: [] }
|
|
1873
|
-
: captureOutput(() =>
|
|
1573
|
+
: captureOutput(() =>
|
|
1574
|
+
traces.findStepAction(cycleEnd, lastState, states[cycleStart], false),
|
|
1575
|
+
);
|
|
1874
1576
|
const isStutteringWarned = cycleStart === cycleEnd && lasso.isCycleConstrained;
|
|
1875
1577
|
return reportViolation(
|
|
1876
1578
|
"liveness-violation",
|
|
@@ -1888,58 +1590,167 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1888
1590
|
? getStepAction(trace[trace.length - 1])
|
|
1889
1591
|
: loop.result
|
|
1890
1592
|
? toActionValue(loop.result)
|
|
1891
|
-
: createActionRecord(
|
|
1593
|
+
: createActionRecord(
|
|
1594
|
+
traces.findSuccessorWithFingerprint(lastState, cycleStart)?.action,
|
|
1595
|
+
),
|
|
1892
1596
|
);
|
|
1893
1597
|
};
|
|
1894
1598
|
const isPeriodic = liveness !== undefined && (options.livenessCheck ?? "default") === "default";
|
|
1895
1599
|
const startedAt = performance.now();
|
|
1896
1600
|
const periodic = {
|
|
1897
1601
|
at: startedAt + PERIODIC_START,
|
|
1898
|
-
size
|
|
1602
|
+
// The size of each branch's graph when TLC last checked it, which starts at 1.
|
|
1603
|
+
sizes: liveness?.getStateCounts().map(() => 1) ?? [],
|
|
1899
1604
|
time: 0,
|
|
1900
1605
|
coverageCount: Math.trunc(options.coverage ?? 0),
|
|
1901
1606
|
};
|
|
1902
|
-
|
|
1607
|
+
// TLC counts the states of the graphs of all branches, which can differ.
|
|
1608
|
+
const getGraphStates = (checker: LivenessChecker) =>
|
|
1609
|
+
checker.getStateCounts().reduce((sum, count) => sum + count, 0);
|
|
1610
|
+
const findPeriodicViolation = (checker: LivenessChecker) => {
|
|
1903
1611
|
const now = performance.now();
|
|
1904
|
-
const
|
|
1612
|
+
const counts = checker.getStateCounts();
|
|
1613
|
+
const isGrown = counts.some(
|
|
1614
|
+
(count, branch) =>
|
|
1615
|
+
(count - periodic.sizes[branch]) / periodic.sizes[branch] > LIVENESS_GROWTH,
|
|
1616
|
+
);
|
|
1905
1617
|
if (!isGrown || periodic.time > (now - startedAt) * LIVENESS_RATIO) return undefined;
|
|
1906
|
-
periodic.
|
|
1907
|
-
if (!liveness) return undefined;
|
|
1618
|
+
periodic.sizes = counts;
|
|
1908
1619
|
options.onProgress?.({
|
|
1909
1620
|
kind: "liveness-started",
|
|
1910
|
-
branches:
|
|
1621
|
+
branches: checker.branches,
|
|
1911
1622
|
isComplete: false,
|
|
1912
|
-
states:
|
|
1623
|
+
states: getGraphStates(checker),
|
|
1913
1624
|
statistics: createResult("success"),
|
|
1914
1625
|
});
|
|
1915
|
-
const lasso =
|
|
1626
|
+
const lasso = checker.findViolation();
|
|
1916
1627
|
if (!lasso) options.onProgress?.({ kind: "liveness-finished" });
|
|
1917
1628
|
periodic.time += performance.now() - now;
|
|
1918
1629
|
return lasso;
|
|
1919
1630
|
};
|
|
1920
|
-
|
|
1631
|
+
const adoptTypedSearch = (searched: TypedResult) => {
|
|
1632
|
+
runtime.generatedStates = searched.generatedStates;
|
|
1633
|
+
runtime.distinctStates = searched.distinctStates;
|
|
1634
|
+
runtime.queueSize = searched.queuedStates;
|
|
1635
|
+
runtime.diameter = searched.depth;
|
|
1636
|
+
searchDepth = searched.depth;
|
|
1637
|
+
outDegrees.splice(0, outDegrees.length, ...searched.outDegrees);
|
|
1638
|
+
newStateCount = 0;
|
|
1639
|
+
};
|
|
1640
|
+
// The tier found a state without successors, or a successor that violates an invariant or an
|
|
1641
|
+
// action property. The interpreter rebuilds the tier's path to it and reports it, as it would after
|
|
1642
|
+
// its own search.
|
|
1643
|
+
const path = typed?.deadlock ?? typed?.violation;
|
|
1644
|
+
const initialIndex = path ? states.findIndex((state) => path.isPathState(0, state)) : -1;
|
|
1645
|
+
if (typed && path && initialIndex !== -1) {
|
|
1646
|
+
const steps: { successor: Successor; action: SpecAction | undefined }[] = [];
|
|
1647
|
+
const getLastState = () => steps.at(-1)?.successor.state ?? states[initialIndex];
|
|
1648
|
+
for (let position = 1; position === steps.length + 1 && position < path.length; position++) {
|
|
1649
|
+
// The interpreter expands only the states it stores, which it has canonicalized.
|
|
1650
|
+
canonicalizeState(getLastState());
|
|
1651
|
+
forEachActionSuccessor(getLastState(), undefined, (successor, action) => {
|
|
1652
|
+
if (!path.isPathState(position, successor.state)) return false;
|
|
1653
|
+
steps.push({ successor, action });
|
|
1654
|
+
return true;
|
|
1655
|
+
});
|
|
1656
|
+
}
|
|
1657
|
+
const isRebuilt = steps.length === path.length - 1;
|
|
1658
|
+
const violating = typed.violation && isRebuilt ? steps.pop() : undefined;
|
|
1659
|
+
if (violating && isCanonicalizedFirst) canonicalizeState(violating.successor.state);
|
|
1660
|
+
const violatedInvariant =
|
|
1661
|
+
violating && search.findViolatedInvariant(violating.successor.state, getLastState());
|
|
1662
|
+
const violatedProperty =
|
|
1663
|
+
violating &&
|
|
1664
|
+
!violatedInvariant &&
|
|
1665
|
+
search.findViolatedActionProperty(getLastState(), violating.successor.state);
|
|
1666
|
+
const violated = violatedInvariant ?? violatedProperty;
|
|
1667
|
+
const isDeadlocked =
|
|
1668
|
+
typed.deadlock !== undefined &&
|
|
1669
|
+
isRebuilt &&
|
|
1670
|
+
forEachActionSuccessor(getLastState(), undefined, () => true) === 0;
|
|
1671
|
+
if (isDeadlocked || violated) {
|
|
1672
|
+
const parent = { index: initialIndex };
|
|
1673
|
+
for (const step of steps) {
|
|
1674
|
+
visitSuccessor(parent.index, step.successor, [], undefined, step.action);
|
|
1675
|
+
parent.index = states.length - 1;
|
|
1676
|
+
}
|
|
1677
|
+
adoptTypedSearch(typed);
|
|
1678
|
+
Object.assign(current, { index: parent.index, candidate: undefined, isExpanding: true });
|
|
1679
|
+
if (violating && violated) {
|
|
1680
|
+
lookUpSuccessor(states[parent.index], violating.successor);
|
|
1681
|
+
current.candidate = violating.successor.state;
|
|
1682
|
+
current.candidateLevel = depths[parent.index] + 1;
|
|
1683
|
+
return withOutDegrees(
|
|
1684
|
+
reportViolation(violatedInvariant ? "invariant-violation" : "liveness-violation", {
|
|
1685
|
+
name: violated.name,
|
|
1686
|
+
...traces.getTrace(parent.index, violating.successor),
|
|
1687
|
+
}),
|
|
1688
|
+
);
|
|
1689
|
+
}
|
|
1690
|
+
const result = expandState(parent.index, []);
|
|
1691
|
+
if (result) return result;
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
// The tier found a behavior that violates a temporal property after its whole search. The
|
|
1695
|
+
// interpreter stores the paths to the lasso's states and reports it, as it would after its own.
|
|
1696
|
+
const lassoSteps = new Map<number, { successor: Successor; action: SpecAction | undefined }>();
|
|
1697
|
+
for (const entry of typed?.lasso?.states ?? []) {
|
|
1698
|
+
const initial = entry.parent === -1 ? states.find(entry.isState) : undefined;
|
|
1699
|
+
if (initial) {
|
|
1700
|
+
lassoSteps.set(entry.index, {
|
|
1701
|
+
successor: { state: initial, action: undefined },
|
|
1702
|
+
action: undefined,
|
|
1703
|
+
});
|
|
1704
|
+
}
|
|
1705
|
+
const parent = lassoSteps.get(entry.parent)?.successor.state;
|
|
1706
|
+
if (!parent) continue;
|
|
1707
|
+
// The interpreter expands only the states it stores, which it has canonicalized.
|
|
1708
|
+
canonicalizeState(parent);
|
|
1709
|
+
forEachActionSuccessor(parent, undefined, (successor, action) => {
|
|
1710
|
+
if (!entry.isState(successor.state)) return false;
|
|
1711
|
+
lassoSteps.set(entry.index, { successor, action });
|
|
1712
|
+
return true;
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
const lassoIndexes = new Map<number, number>();
|
|
1716
|
+
const typedLasso =
|
|
1717
|
+
typed?.lasso && lassoSteps.size === typed.lasso.states.length ? typed.lasso : undefined;
|
|
1718
|
+
typedLasso?.states.forEach((entry) => {
|
|
1719
|
+
const step = lassoSteps.get(entry.index);
|
|
1720
|
+
const parent = lassoIndexes.get(entry.parent);
|
|
1721
|
+
if (step && parent !== undefined)
|
|
1722
|
+
visitSuccessor(parent, step.successor, [], undefined, step.action);
|
|
1723
|
+
lassoIndexes.set(
|
|
1724
|
+
entry.index,
|
|
1725
|
+
parent === undefined ? states.findIndex(entry.isState) : states.length - 1,
|
|
1726
|
+
);
|
|
1727
|
+
});
|
|
1728
|
+
if (typed && typedLasso) adoptTypedSearch(typed);
|
|
1729
|
+
for (
|
|
1730
|
+
let index = typedLasso ? states.length : 0;
|
|
1731
|
+
index < states.length && !runtime.isStopped;
|
|
1732
|
+
index++
|
|
1733
|
+
) {
|
|
1921
1734
|
current.index = index;
|
|
1922
1735
|
current.candidate = undefined;
|
|
1923
1736
|
runtime.queueSize = states.length - index - 1;
|
|
1924
1737
|
current.isExpanding = true;
|
|
1925
1738
|
const liveSuccessors: LiveSuccessor[] = [];
|
|
1926
1739
|
try {
|
|
1927
|
-
outcome
|
|
1740
|
+
outcome = expandState(index, liveSuccessors);
|
|
1928
1741
|
} catch (error) {
|
|
1929
|
-
outcome
|
|
1742
|
+
outcome =
|
|
1930
1743
|
error instanceof TlaIncompleteSuccessorError
|
|
1931
1744
|
? reportIncompleteSuccessor(index, error)
|
|
1932
1745
|
: reportNextStateFailure(error, index, liveSuccessors);
|
|
1933
1746
|
}
|
|
1934
|
-
if (outcome
|
|
1747
|
+
if (outcome) return outcome;
|
|
1935
1748
|
outDegrees[getOutDegreeBucket()]++;
|
|
1936
|
-
|
|
1937
|
-
// TLC checks liveness on the graph so far, then reports how far the search got.
|
|
1749
|
+
newStateCount = 0;
|
|
1938
1750
|
if ((isPeriodic || options.onProgress) && performance.now() >= periodic.at) {
|
|
1939
1751
|
periodic.at = performance.now() + PROGRESS_INTERVAL;
|
|
1940
|
-
const lasso = isPeriodic ? findPeriodicViolation(
|
|
1752
|
+
const lasso = isPeriodic && liveness ? findPeriodicViolation(liveness) : undefined;
|
|
1941
1753
|
if (liveness && lasso) return reportLasso(liveness, lasso);
|
|
1942
|
-
// TLC reports the coverage with every report after the first `coverage` reports since the last.
|
|
1943
1754
|
const isCoverageDue = options.coverage !== undefined && periodic.coverageCount === 0;
|
|
1944
1755
|
periodic.coverageCount = isCoverageDue
|
|
1945
1756
|
? Math.trunc(options.coverage ?? 0)
|
|
@@ -1960,14 +1771,24 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1960
1771
|
kind: "liveness-started",
|
|
1961
1772
|
branches: finalLiveness.branches,
|
|
1962
1773
|
isComplete: true,
|
|
1963
|
-
|
|
1774
|
+
// The tier that found the lasso stored and expanded every successor, so each graph has every state.
|
|
1775
|
+
states: typedLasso
|
|
1776
|
+
? finalLiveness.branches * runtime.distinctStates
|
|
1777
|
+
: getGraphStates(finalLiveness),
|
|
1964
1778
|
statistics: createResult("success"),
|
|
1965
1779
|
});
|
|
1966
1780
|
}
|
|
1967
|
-
const
|
|
1781
|
+
const getLassoIndexes = (indexes: number[]) =>
|
|
1782
|
+
indexes.map((index) => lassoIndexes.get(index) ?? -1);
|
|
1783
|
+
const lasso = typedLasso
|
|
1784
|
+
? {
|
|
1785
|
+
prefix: getLassoIndexes(typedLasso.prefix),
|
|
1786
|
+
cycle: getLassoIndexes(typedLasso.cycle),
|
|
1787
|
+
isCycleConstrained: typedLasso.isCycleConstrained,
|
|
1788
|
+
}
|
|
1789
|
+
: finalLiveness?.findViolation();
|
|
1968
1790
|
if (finalLiveness && lasso) return reportLasso(finalLiveness, lasso);
|
|
1969
1791
|
|
|
1970
|
-
// TLC finishes the check of the temporal properties before it checks the postconditions.
|
|
1971
1792
|
if (finalLiveness) options.onProgress?.({ kind: "liveness-finished" });
|
|
1972
1793
|
const missingPostcondition = specification.moduleOperators.find(
|
|
1973
1794
|
(operator) => operator.kind === "postcondition" && operator.key === undefined,
|
|
@@ -1985,5 +1806,5 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1985
1806
|
postcondition,
|
|
1986
1807
|
});
|
|
1987
1808
|
}
|
|
1988
|
-
return
|
|
1809
|
+
return continuedStatus ? createResult(continuedStatus) : createSuccess();
|
|
1989
1810
|
};
|