tla-ts 0.0.9 → 0.0.10-dev.b4a856304
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -1
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +28 -28
- package/dist/deciders.js +43 -43
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +72 -10
- package/dist/index.d.ts +72 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +116 -36
- package/dist/prove.js +116 -36
- package/dist/run.cjs +143 -31
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +128 -103
- package/dist/transfer.js +128 -103
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +7 -21
- package/src/bags.ts +99 -99
- package/src/builtins.ts +44 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check.ts +576 -300
- package/src/cli/options.ts +11 -6
- package/src/cli/run.ts +2 -2
- package/src/cli/runtime-invariants.ts +135 -0
- package/src/cli/shared.ts +20 -9
- package/src/cli/tlapm.ts +0 -12
- package/src/cli/tlc-arguments.ts +646 -0
- package/src/cli/tlc-usage.ts +362 -0
- package/src/cli/tlc.ts +538 -220
- package/src/cli/typescript.ts +23 -0
- package/src/cli/xml-exporter.ts +4 -16
- package/src/cli.ts +0 -1
- package/src/codegen.ts +191 -64
- package/src/config.ts +140 -109
- package/src/coverage.ts +837 -0
- package/src/dependencies.ts +6 -40
- package/src/dfid.ts +618 -0
- package/src/environment.ts +240 -118
- package/src/errors.ts +70 -55
- package/src/evaluate.ts +630 -297
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +10 -10
- package/src/index.ts +3 -0
- package/src/instances.ts +79 -11
- package/src/java-overrides.ts +2 -12
- package/src/json-reader.ts +456 -0
- package/src/json.ts +262 -139
- package/src/levels.ts +2 -3
- package/src/lexer.ts +17 -26
- package/src/liveness-checker.ts +10 -18
- package/src/liveness.ts +121 -49
- package/src/obligations/action.ts +4 -28
- package/src/obligations/anonymize.ts +84 -80
- package/src/obligations/equality.ts +1 -1
- package/src/obligations/expression.ts +2 -19
- package/src/obligations/format.ts +1 -9
- package/src/obligations/generate.ts +1 -11
- package/src/obligations/index.ts +0 -11
- package/src/obligations/levels.ts +4 -8
- package/src/obligations/module.ts +1 -15
- package/src/obligations/normalize.ts +5 -24
- package/src/obligations/operators.ts +1 -2
- package/src/obligations/pragma.ts +1 -10
- package/src/obligations/printer.ts +47 -46
- package/src/obligations/proof.ts +1 -5
- package/src/obligations/regroup.ts +1 -4
- package/src/obligations/simplify.ts +3 -14
- package/src/obligations/source.ts +1 -21
- package/src/obligations/subexpression.ts +5 -11
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +8 -14
- package/src/obligations/tuples.ts +3 -9
- package/src/parallel-worker.ts +29 -39
- package/src/parallel.ts +29 -13
- package/src/parser.ts +436 -90
- package/src/pcal/ast.ts +7 -28
- package/src/pcal/parse.ts +11 -39
- package/src/pcal/tokenize.ts +4 -20
- package/src/pcal/translate.ts +10 -42
- package/src/pcal/validate.ts +3 -21
- package/src/pretty-print.ts +1 -2
- package/src/prover/decide-pool.ts +5 -10
- package/src/prover/deciders.ts +0 -4
- package/src/prover/first-order.ts +0 -11
- package/src/prover/isabelle/decide.ts +0 -6
- package/src/prover/isabelle/encode.ts +11 -23
- package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
- package/src/prover/isabelle/isar/method.ts +25 -38
- package/src/prover/isabelle/isar/proof.ts +1 -10
- package/src/prover/isabelle/isar/statement.ts +1 -6
- package/src/prover/isabelle/isar/theory.ts +15 -26
- package/src/prover/isabelle/isar/type-check.ts +11 -25
- package/src/prover/isabelle/provers/blast/blast.ts +10 -41
- package/src/prover/isabelle/provers/blast/branch.ts +1 -32
- package/src/prover/isabelle/provers/blast/prove.ts +1 -35
- package/src/prover/isabelle/provers/blast/rules.ts +6 -44
- package/src/prover/isabelle/provers/blast/state.ts +2 -28
- package/src/prover/isabelle/provers/blast/term.ts +9 -36
- package/src/prover/isabelle/provers/clasimp.ts +1 -13
- package/src/prover/isabelle/provers/classical.ts +14 -42
- package/src/prover/isabelle/provers/hypsubst.ts +11 -25
- package/src/prover/isabelle/pure/bicompose.ts +16 -13
- package/src/prover/isabelle/pure/consts.ts +1 -7
- package/src/prover/isabelle/pure/conv.ts +1 -9
- package/src/prover/isabelle/pure/drule.ts +24 -40
- package/src/prover/isabelle/pure/envir.ts +3 -52
- package/src/prover/isabelle/pure/goal.ts +1 -7
- package/src/prover/isabelle/pure/interrupt.ts +0 -5
- package/src/prover/isabelle/pure/list.ts +0 -3
- package/src/prover/isabelle/pure/logic.ts +1 -14
- package/src/prover/isabelle/pure/name.ts +2 -9
- package/src/prover/isabelle/pure/net.ts +3 -59
- package/src/prover/isabelle/pure/object-logic.ts +3 -10
- package/src/prover/isabelle/pure/pattern.ts +2 -19
- package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
- package/src/prover/isabelle/pure/rewriter.ts +26 -58
- package/src/prover/isabelle/pure/search.ts +3 -10
- package/src/prover/isabelle/pure/seq.ts +1 -10
- package/src/prover/isabelle/pure/simplifier.ts +4 -12
- package/src/prover/isabelle/pure/table.ts +1 -31
- package/src/prover/isabelle/pure/tactic.ts +12 -22
- package/src/prover/isabelle/pure/tactical.ts +6 -12
- package/src/prover/isabelle/pure/term-ord.ts +2 -6
- package/src/prover/isabelle/pure/term.ts +2 -43
- package/src/prover/isabelle/pure/thm.ts +13 -36
- package/src/prover/isabelle/pure/type.ts +2 -15
- package/src/prover/isabelle/pure/unify.ts +20 -30
- package/src/prover/isabelle/pure/variable.ts +3 -7
- package/src/prover/isabelle/tla/classical-setup.ts +9 -19
- package/src/prover/isabelle/tla/context.ts +8 -16
- package/src/prover/isabelle/tla/logic.ts +4 -11
- package/src/prover/isabelle/tla/simpdata.ts +46 -34
- package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
- package/src/prover/ocaml.ts +0 -6
- package/src/prover/prep/action.ts +4 -36
- package/src/prover/prep/enabled-axioms.ts +12 -19
- package/src/prover/prep/fingerprint.ts +0 -16
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +9 -36
- package/src/prover/prep/normalize.ts +4 -28
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +0 -36
- package/src/prover/ptl/decide.ts +7 -12
- package/src/prover/ptl/encode.ts +14 -36
- package/src/prover/ptl/sat.ts +24 -32
- package/src/prover/ptl/tableau.ts +12 -26
- package/src/prover/smt/axioms.ts +0 -7
- package/src/prover/smt/context.ts +19 -26
- package/src/prover/smt/data.ts +51 -54
- package/src/prover/smt/encode.ts +14 -35
- package/src/prover/smt/extensionality.ts +0 -10
- package/src/prover/smt/flatten.ts +3 -22
- package/src/prover/smt/format.ts +5 -10
- package/src/prover/smt/instances.ts +0 -10
- package/src/prover/smt/rewrite.ts +66 -101
- package/src/prover/smt/solver/act-cache.ts +0 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -48
- package/src/prover/smt/solver/array.ts +1 -3
- package/src/prover/smt/solver/asserted-formulas.ts +1 -43
- package/src/prover/smt/solver/ast-lt.ts +1 -11
- package/src/prover/smt/solver/ast-util.ts +1 -6
- package/src/prover/smt/solver/ast.ts +1 -143
- package/src/prover/smt/solver/auf-solver.ts +6 -39
- package/src/prover/smt/solver/case-split-queue.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +1 -18
- package/src/prover/smt/solver/clause.ts +1 -27
- package/src/prover/smt/solver/conflict-resolution.ts +0 -9
- package/src/prover/smt/solver/context.ts +4 -61
- package/src/prover/smt/solver/ctx-simplify.ts +14 -41
- package/src/prover/smt/solver/der.ts +2 -21
- package/src/prover/smt/solver/dyn-ack.ts +1 -11
- package/src/prover/smt/solver/e-matching.ts +3 -34
- package/src/prover/smt/solver/enode.ts +1 -21
- package/src/prover/smt/solver/expr-ref.ts +1 -5
- package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
- package/src/prover/smt/solver/fingerprints.ts +1 -12
- package/src/prover/smt/solver/flat-literals.ts +1 -9
- package/src/prover/smt/solver/goal.ts +2 -14
- package/src/prover/smt/solver/hash.ts +0 -8
- package/src/prover/smt/solver/hashtable.ts +1 -12
- package/src/prover/smt/solver/internalizer.ts +6 -98
- package/src/prover/smt/solver/lbool.ts +1 -2
- package/src/prover/smt/solver/literal.ts +0 -3
- package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
- package/src/prover/smt/solver/lp/constraints.ts +2 -8
- package/src/prover/smt/solver/lp/containers.ts +12 -30
- package/src/prover/smt/solver/lp/core-solver.ts +10 -31
- package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
- package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
- package/src/prover/smt/solver/lp/dependency.ts +1 -4
- package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
- package/src/prover/smt/solver/lp/explanation.ts +1 -6
- package/src/prover/smt/solver/lp/gomory.ts +9 -22
- package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
- package/src/prover/smt/solver/lp/hnf.ts +11 -26
- package/src/prover/smt/solver/lp/int-cube.ts +15 -36
- package/src/prover/smt/solver/lp/int-solver.ts +4 -34
- package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
- package/src/prover/smt/solver/lp/lar-term.ts +1 -5
- package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
- package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
- package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
- package/src/prover/smt/solver/lp/nex.ts +1 -6
- package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
- package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
- package/src/prover/smt/solver/lp/nla-core.ts +35 -130
- package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
- package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
- package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
- package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
- package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
- package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
- package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
- package/src/prover/smt/solver/lp/nla-order.ts +2 -13
- package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
- package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
- package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
- package/src/prover/smt/solver/lp/nla-types.ts +1 -11
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
- package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
- package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
- package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
- package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
- package/src/prover/smt/solver/lp/pdd.ts +7 -70
- package/src/prover/smt/solver/lp/random-updater.ts +1 -8
- package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
- package/src/prover/smt/solver/lp/union-find.ts +1 -6
- package/src/prover/smt/solver/mam-compiler.ts +14 -56
- package/src/prover/smt/solver/mam-interpreter.ts +1 -21
- package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
- package/src/prover/smt/solver/model-checker.ts +2 -36
- package/src/prover/smt/solver/model-evaluator.ts +3 -29
- package/src/prover/smt/solver/model-finder.ts +3 -15
- package/src/prover/smt/solver/model-generator.ts +1 -12
- package/src/prover/smt/solver/model-macro-solver.ts +12 -69
- package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
- package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
- package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
- package/src/prover/smt/solver/nlsat/explain.ts +3 -47
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
- package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
- package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
- package/src/prover/smt/solver/nlsat/solver.ts +7 -67
- package/src/prover/smt/solver/nlsat/types.ts +1 -8
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
- package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
- package/src/prover/smt/solver/nnf.ts +3 -38
- package/src/prover/smt/solver/pattern-inference.ts +2 -15
- package/src/prover/smt/solver/poly-rewriter.ts +3 -23
- package/src/prover/smt/solver/propagate-values.ts +1 -10
- package/src/prover/smt/solver/proto-model.ts +3 -48
- package/src/prover/smt/solver/pull-quant.ts +1 -12
- package/src/prover/smt/solver/qe-lite-der.ts +1 -29
- package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
- package/src/prover/smt/solver/qe-lite.ts +3 -33
- package/src/prover/smt/solver/qi-queue.ts +1 -16
- package/src/prover/smt/solver/quant-tactics.ts +5 -22
- package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
- package/src/prover/smt/solver/quantifier-manager.ts +1 -8
- package/src/prover/smt/solver/random-gen.ts +1 -2
- package/src/prover/smt/solver/rational.ts +1 -8
- package/src/prover/smt/solver/ref-vector.ts +1 -6
- package/src/prover/smt/solver/relevancy.ts +2 -15
- package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
- package/src/prover/smt/solver/rewriter.ts +3 -85
- package/src/prover/smt/solver/rlimit.ts +2 -20
- package/src/prover/smt/solver/smtlib-parser.ts +2 -37
- package/src/prover/smt/solver/solver.ts +23 -34
- package/src/prover/smt/solver/sort.ts +1 -5
- package/src/prover/smt/solver/sticky-generations.ts +0 -5
- package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
- package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
- package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
- package/src/prover/smt/solver/theory-lra-model.ts +4 -19
- package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
- package/src/prover/smt/solver/theory-lra-state.ts +3 -8
- package/src/prover/smt/solver/theory-lra.ts +1 -8
- package/src/prover/smt/solver/var-subst.ts +2 -26
- package/src/prover/smt/table.ts +0 -8
- package/src/prover/tlapm/cache.ts +20 -25
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +12 -17
- package/src/prover/verdict.ts +0 -2
- package/src/prover/zenon/check/check.ts +0 -9
- package/src/prover/zenon/check/definitions.ts +5 -15
- package/src/prover/zenon/check/equality.ts +0 -8
- package/src/prover/zenon/check/functions.ts +0 -4
- package/src/prover/zenon/check/keys.ts +0 -7
- package/src/prover/zenon/check/propositional.ts +0 -3
- package/src/prover/zenon/check/records.ts +0 -5
- package/src/prover/zenon/check/relations.ts +0 -13
- package/src/prover/zenon/check/rewrites.ts +0 -6
- package/src/prover/zenon/check/sets.ts +0 -3
- package/src/prover/zenon/check/terms.ts +0 -17
- package/src/prover/zenon/check/tla.ts +0 -6
- package/src/prover/zenon/decide.ts +0 -12
- package/src/prover/zenon/encode.ts +1 -8
- package/src/prover/zenon/eqrel.ts +0 -13
- package/src/prover/zenon/equality-rules.ts +0 -4
- package/src/prover/zenon/expr.ts +1 -26
- package/src/prover/zenon/index-table.ts +17 -38
- package/src/prover/zenon/isar-case.ts +9 -19
- package/src/prover/zenon/isar.ts +1 -29
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +0 -9
- package/src/prover/zenon/mltoll.ts +54 -76
- package/src/prover/zenon/node.ts +1 -11
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +2 -7
- package/src/prover/zenon/phrase.ts +1 -11
- package/src/prover/zenon/proof.ts +0 -9
- package/src/prover/zenon/propositional-rules.ts +0 -5
- package/src/prover/zenon/rules.ts +2 -6
- package/src/prover/zenon/search.ts +1 -17
- package/src/prover/zenon/tla/functions.ts +57 -29
- package/src/prover/zenon/tla/llproof.ts +63 -70
- package/src/prover/zenon/tla/records.ts +56 -27
- package/src/prover/zenon/tla/rewrites.ts +12 -19
- package/src/prover/zenon/tla/sets.ts +68 -39
- package/src/prover/zenon/tla/terms.ts +0 -6
- package/src/prover/zenon/tla/tla.ts +59 -58
- package/src/randomization.ts +84 -35
- package/src/resolve.ts +18 -60
- package/src/runtime.ts +11 -4
- package/src/sany/builtins.ts +3 -4
- package/src/sany/generator.ts +119 -169
- package/src/sany/levels.ts +6 -30
- package/src/sany/lexer.ts +7 -23
- package/src/sany/linter.ts +1 -8
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +0 -31
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +29 -63
- package/src/sany/selectors.ts +15 -39
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +13 -63
- package/src/search.ts +494 -154
- package/src/simulate.ts +694 -0
- package/src/spec-description.ts +166 -48
- package/src/standard-definitions.ts +2 -3
- package/src/standard-modules.ts +264 -68
- package/src/state-graph.ts +51 -18
- package/src/subexpressions.ts +31 -5
- package/src/substitution-levels.ts +2 -3
- package/src/successors.ts +267 -77
- package/src/symmetry.ts +31 -8
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -61
- package/src/tlc/jar-data.ts +113 -6
- package/src/tlc/messages.ts +122 -37
- package/src/tlc/order.ts +33 -38
- package/src/tlc/random.ts +16 -16
- package/src/tlc/replay.ts +563 -211
- package/src/tlc/summary.ts +2 -4
- package/src/tlc/tlc-operators.ts +81 -36
- package/src/tlc/tlcext-operators.ts +138 -117
- package/src/tlc/trace-spec.ts +273 -0
- package/src/tlc/value-stream.ts +143 -0
- package/src/tlc/version.ts +2 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +481 -0
- package/src/typescript/collections.ts +600 -0
- package/src/typescript/compile.ts +65 -0
- package/src/typescript/context.ts +94 -0
- package/src/typescript/emit.ts +121 -0
- package/src/typescript/expressions.ts +496 -0
- package/src/typescript/formula.ts +152 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +163 -0
- package/src/typescript/names.ts +114 -0
- package/src/typescript/program.ts +48 -0
- package/src/typescript/properties.ts +139 -0
- package/src/typescript/scope.ts +112 -0
- package/src/typescript/steps.ts +165 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +826 -276
- package/src/worker.ts +7 -8
package/src/check.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import type { Expression } from "./ast";
|
|
2
2
|
import { parseConfig, type ModelConfig } from "./config";
|
|
3
|
+
import {
|
|
4
|
+
addCoverageRelation,
|
|
5
|
+
buildCoverage,
|
|
6
|
+
countCoverageVariables,
|
|
7
|
+
createCoverage,
|
|
8
|
+
getCoverageLabel,
|
|
9
|
+
getCoverageReport,
|
|
10
|
+
type CoverageReport,
|
|
11
|
+
} from "./coverage";
|
|
3
12
|
import { createEnvironment } from "./environment";
|
|
4
13
|
import {
|
|
5
14
|
createStackOverflowError,
|
|
6
15
|
getErrorExitCode,
|
|
7
16
|
isStackOverflow,
|
|
8
|
-
TlaConfigError,
|
|
9
17
|
TlaEvaluationError,
|
|
10
18
|
TlaIllegalStateError,
|
|
11
19
|
TlaIncompleteSuccessorError,
|
|
@@ -16,7 +24,7 @@ import {
|
|
|
16
24
|
} from "./errors";
|
|
17
25
|
import {
|
|
18
26
|
createTracingEnvironment,
|
|
19
|
-
|
|
27
|
+
describeRange,
|
|
20
28
|
formatRange,
|
|
21
29
|
getDefinition,
|
|
22
30
|
isImpure,
|
|
@@ -24,7 +32,13 @@ import {
|
|
|
24
32
|
type Environment,
|
|
25
33
|
type FingerprintFailure,
|
|
26
34
|
} from "./evaluate";
|
|
27
|
-
import {
|
|
35
|
+
import {
|
|
36
|
+
EXIT_STATUS,
|
|
37
|
+
getExitCode,
|
|
38
|
+
getMessageExitStatus,
|
|
39
|
+
setExitCode,
|
|
40
|
+
withLivenessExitCode,
|
|
41
|
+
} from "./exit-codes";
|
|
28
42
|
import type { JavaOverride } from "./java-overrides";
|
|
29
43
|
import {
|
|
30
44
|
createLivenessChecker,
|
|
@@ -33,11 +47,10 @@ import {
|
|
|
33
47
|
type LiveSuccessor,
|
|
34
48
|
} from "./liveness-checker";
|
|
35
49
|
import {
|
|
36
|
-
|
|
50
|
+
createMissingOperatorError,
|
|
37
51
|
createSearch,
|
|
52
|
+
getIncompleteSuccessorMessage,
|
|
38
53
|
findAssumptionViolation,
|
|
39
|
-
getConfigDefinition,
|
|
40
|
-
getContext,
|
|
41
54
|
reportInitialStatesProgress,
|
|
42
55
|
reportStartup,
|
|
43
56
|
withNextStateExitCode,
|
|
@@ -62,10 +75,10 @@ import {
|
|
|
62
75
|
forEachSuccessor,
|
|
63
76
|
getInitialStates,
|
|
64
77
|
getSuccessors,
|
|
78
|
+
hasIncompleteSuccessor,
|
|
65
79
|
type Successor,
|
|
66
80
|
} from "./successors";
|
|
67
81
|
import {
|
|
68
|
-
formatNestedMessage,
|
|
69
82
|
getCodedMessage,
|
|
70
83
|
getFailureMessage,
|
|
71
84
|
getWrappedException,
|
|
@@ -75,8 +88,17 @@ import {
|
|
|
75
88
|
withUnexpectedException,
|
|
76
89
|
type FailureMessage,
|
|
77
90
|
} from "./tlc/messages";
|
|
91
|
+
import { createTautologyError } from "./liveness";
|
|
92
|
+
import { KEY_SEPARATOR } from "./resolve";
|
|
93
|
+
import { setFingerprintPolynomial } from "./tlc/fingerprint";
|
|
94
|
+
import { writeTraceSpec } from "./tlc/trace-spec";
|
|
78
95
|
import { createTlcOrder } from "./tlc/order";
|
|
79
|
-
import {
|
|
96
|
+
import {
|
|
97
|
+
getPrimedRanges,
|
|
98
|
+
replayInitialStates,
|
|
99
|
+
replaySuccessors,
|
|
100
|
+
walkSuccessors,
|
|
101
|
+
} from "./tlc/replay";
|
|
80
102
|
import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc/summary";
|
|
81
103
|
import { createActionRecord, createCounterExample } from "./tlc/tlcext-operators";
|
|
82
104
|
import type { TlcVersion } from "./tlc/version";
|
|
@@ -87,13 +109,12 @@ import {
|
|
|
87
109
|
formatState,
|
|
88
110
|
getFingerprintError,
|
|
89
111
|
getHeldValues,
|
|
112
|
+
getModelValues,
|
|
90
113
|
getValueHash,
|
|
91
|
-
isFunctionValue,
|
|
92
114
|
isSameValue,
|
|
93
115
|
markFingerprinted,
|
|
94
116
|
setStringOrder,
|
|
95
|
-
|
|
96
|
-
toFiniteFunction,
|
|
117
|
+
setValueOptions,
|
|
97
118
|
type Value,
|
|
98
119
|
} from "./values";
|
|
99
120
|
|
|
@@ -105,37 +126,57 @@ export interface CheckOptions {
|
|
|
105
126
|
onPrint?: (text: string) => void;
|
|
106
127
|
onPause?: () => void;
|
|
107
128
|
readFile?: (path: string) => string | undefined;
|
|
108
|
-
writeFile?: (path: string, content: string) => void;
|
|
129
|
+
writeFile?: (path: string, content: string | Uint8Array) => void;
|
|
130
|
+
makeDirectory?: (path: string) => void;
|
|
109
131
|
seed?: bigint;
|
|
110
132
|
workers?: number;
|
|
111
|
-
// TLC's -lncheck: "final" checks liveness only on the complete
|
|
112
|
-
livenessCheck?: "default" | "final";
|
|
133
|
+
// TLC's -lncheck: "final" checks liveness only on the complete graph, "off" never looks for a cycle.
|
|
134
|
+
livenessCheck?: "default" | "final" | "off";
|
|
135
|
+
// TLC's -fp: the index of the polynomial in TLC's FP64.Polys that fingerprints states.
|
|
136
|
+
fingerprintPolynomial?: number;
|
|
137
|
+
// False for TLC's -terse, which prints a lazy value, such as SUBSET S, without enumerating it.
|
|
138
|
+
isLazyValueExpanded?: boolean;
|
|
139
|
+
// TLC's -view: prints each state as the value of the configuration's VIEW.
|
|
140
|
+
isViewPrinted?: boolean;
|
|
141
|
+
// TLC's -maxSetSize: the most elements TLC enumerates into a set, or states into a list of them.
|
|
142
|
+
maxSetSize?: number;
|
|
113
143
|
// TLC's -dump: writes the reachable states, or with `dot` the state graph, through writeFile.
|
|
114
144
|
dump?: StateDump;
|
|
115
145
|
// TLC's -tool, which changes the messages of TLC's errors.
|
|
116
146
|
isTool?: boolean;
|
|
117
|
-
// TLC's -continue:
|
|
118
|
-
// onProgress and goes on.
|
|
147
|
+
// TLC's -continue: reports each violation through onProgress and goes on.
|
|
119
148
|
isContinued?: boolean;
|
|
120
|
-
|
|
121
|
-
|
|
149
|
+
moduleOperators?: ModuleOperator[];
|
|
150
|
+
// TLC's trace exploration spec, and the binary trace TLC records for it unless -noTEBin.
|
|
151
|
+
traceSpec?: TraceSpecOptions;
|
|
122
152
|
// Whether the caller printed SANY's report, its warnings included, before the check.
|
|
123
153
|
isSanyReported?: boolean;
|
|
124
|
-
// False for TLC's -nowarning, which changes how TLC computes
|
|
154
|
+
// False for TLC's -nowarning, which changes how TLC computes some successors.
|
|
125
155
|
isWarningEnabled?: boolean;
|
|
126
|
-
//
|
|
156
|
+
// TLC's -coverage, in minutes.
|
|
157
|
+
coverage?: number;
|
|
127
158
|
version?: TlcVersion;
|
|
128
|
-
// Reports the points of the search at which TLC prints a message.
|
|
129
159
|
onProgress?: (progress: CheckProgress) => void;
|
|
130
160
|
}
|
|
131
161
|
|
|
162
|
+
export interface TraceSpecOptions {
|
|
163
|
+
module: string;
|
|
164
|
+
traceFile?: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface ModuleOperator {
|
|
168
|
+
kind: "postcondition" | "constraint" | "view";
|
|
169
|
+
module: string;
|
|
170
|
+
operator: string;
|
|
171
|
+
constants?: Record<string, string>;
|
|
172
|
+
}
|
|
173
|
+
|
|
132
174
|
export interface InitialStatesProgress {
|
|
133
175
|
kind: "initial-states-progress";
|
|
134
176
|
count: number;
|
|
135
177
|
}
|
|
136
178
|
|
|
137
|
-
// A check
|
|
138
|
-
// states.
|
|
179
|
+
// A check TLC reports as violated before it stops replaying the initial states.
|
|
139
180
|
export interface InitialStateViolation {
|
|
140
181
|
kind: "initial-state-violation";
|
|
141
182
|
status: "invariant-violation" | "liveness-violation";
|
|
@@ -146,7 +187,6 @@ export interface InitialStateViolation {
|
|
|
146
187
|
// A line the spec prints, or what TLC reports as it replays the initial states.
|
|
147
188
|
export type OutputLine = string | InitialStatesProgress | InitialStateViolation;
|
|
148
189
|
|
|
149
|
-
// The points of the search at which TLC prints a message.
|
|
150
190
|
export type CheckProgress =
|
|
151
191
|
| { kind: "parsed" }
|
|
152
192
|
| { kind: "constant-level-invariant"; name: string }
|
|
@@ -167,7 +207,6 @@ export type CheckProgress =
|
|
|
167
207
|
}
|
|
168
208
|
| { kind: "liveness-finished" }
|
|
169
209
|
| { kind: "sequential-fallback"; string: string }
|
|
170
|
-
// A warning TLC prints as it evaluates the spec, with its message code.
|
|
171
210
|
| { kind: "warning"; code: number; text: string }
|
|
172
211
|
// A violation that the search goes on past with -continue.
|
|
173
212
|
| { kind: "violation"; status: CheckStatus; violation: Violation }
|
|
@@ -176,7 +215,7 @@ export type CheckProgress =
|
|
|
176
215
|
|
|
177
216
|
export interface SearchStatistics extends Pick<
|
|
178
217
|
CheckResult,
|
|
179
|
-
"generatedStates" | "distinctStates" | "queuedStates" | "depth"
|
|
218
|
+
"generatedStates" | "distinctStates" | "queuedStates" | "depth" | "coverage"
|
|
180
219
|
> {}
|
|
181
220
|
|
|
182
221
|
export type CheckStatus =
|
|
@@ -194,8 +233,7 @@ export interface TraceStep {
|
|
|
194
233
|
// TLC's name, parameters and location for the action that took this step.
|
|
195
234
|
label: string | undefined;
|
|
196
235
|
state: Record<string, Value>;
|
|
197
|
-
// What the spec prints
|
|
198
|
-
// trace. The first step has what TLC prints before the trace.
|
|
236
|
+
// What the spec prints before this step as TLC rebuilds the trace, and before it for the first.
|
|
199
237
|
output?: OutputLine[];
|
|
200
238
|
}
|
|
201
239
|
|
|
@@ -204,16 +242,16 @@ export interface Violation {
|
|
|
204
242
|
// Every temporal property that a liveness counterexample violates, in the configuration's order.
|
|
205
243
|
properties?: string[];
|
|
206
244
|
trace: TraceStep[];
|
|
207
|
-
// What the spec prints after
|
|
208
|
-
// the cycle of a lasso or rebuilds the trace once more.
|
|
245
|
+
// What the spec prints after the trace, as TLC finds the lasso's step back or rebuilds the trace.
|
|
209
246
|
traceOutput?: OutputLine[];
|
|
247
|
+
// What the postconditions print, which TLC checks after the lasso's step back.
|
|
248
|
+
postconditionOutput?: OutputLine[];
|
|
210
249
|
loopStart: number | undefined;
|
|
211
250
|
loopLabel?: string;
|
|
212
251
|
message?: string;
|
|
213
252
|
counts?: string;
|
|
214
253
|
unwitnessed?: Postcondition;
|
|
215
|
-
// A POSTCONDITION that is false or fails
|
|
216
|
-
// prints one.
|
|
254
|
+
// A POSTCONDITION that is false or fails, which TLC checks as it prints the counterexample.
|
|
217
255
|
postcondition?: Postcondition;
|
|
218
256
|
// What TLC warns about after a counterexample, with its code.
|
|
219
257
|
warning?: { code: number; text: string };
|
|
@@ -221,7 +259,6 @@ export interface Violation {
|
|
|
221
259
|
|
|
222
260
|
export interface Postcondition {
|
|
223
261
|
name: string;
|
|
224
|
-
// TLC's message code.
|
|
225
262
|
code: number;
|
|
226
263
|
message: string;
|
|
227
264
|
counts?: string;
|
|
@@ -229,7 +266,6 @@ export interface Postcondition {
|
|
|
229
266
|
|
|
230
267
|
// An evaluation that failed during the search, with the behavior up to the state TLC was working on.
|
|
231
268
|
export interface EvaluationFailure {
|
|
232
|
-
// TLC's code for the message, and its text with and without -tool.
|
|
233
269
|
code: number;
|
|
234
270
|
message: string;
|
|
235
271
|
toolMessage: string;
|
|
@@ -237,15 +273,13 @@ export interface EvaluationFailure {
|
|
|
237
273
|
traceOutput?: OutputLine[];
|
|
238
274
|
initialState: Record<string, Value> | undefined;
|
|
239
275
|
exitCode: number;
|
|
240
|
-
// The expressions TLC was evaluating
|
|
241
|
-
// them by replaying the failure.
|
|
276
|
+
// The expressions TLC was evaluating, outermost first, when its replay finds them.
|
|
242
277
|
callStack: Expression[] | undefined;
|
|
243
278
|
// Whether TLC prints the call stack before the error, as it does for a failed liveness check.
|
|
244
279
|
isCallStackFirst?: boolean;
|
|
245
280
|
// The FingerprintException the replay raises, which TLC reports in place of the call stack.
|
|
246
281
|
fingerprint?: FingerprintFailure;
|
|
247
|
-
// How TLC reports failing again as it prints the trace, since it can't fingerprint the state
|
|
248
|
-
// failure occurred in.
|
|
282
|
+
// How TLC reports failing again as it prints the trace, since it can't fingerprint the state.
|
|
249
283
|
traceFailure?: FailureMessage;
|
|
250
284
|
// A POSTCONDITION that is false or fails after the trace, which TLC checks as it prints one.
|
|
251
285
|
postcondition?: Postcondition;
|
|
@@ -253,10 +287,10 @@ export interface EvaluationFailure {
|
|
|
253
287
|
isWithoutStatistics?: boolean;
|
|
254
288
|
}
|
|
255
289
|
|
|
256
|
-
// Where TLC's replay of a failure fails.
|
|
257
290
|
interface ReplayFailure {
|
|
258
291
|
callStack: Expression[];
|
|
259
292
|
fingerprint: FingerprintFailure | undefined;
|
|
293
|
+
replayError?: TlaEvaluationError;
|
|
260
294
|
}
|
|
261
295
|
|
|
262
296
|
export interface InitialStates {
|
|
@@ -272,23 +306,24 @@ export interface CheckResult {
|
|
|
272
306
|
distinctStates: number;
|
|
273
307
|
queuedStates: number;
|
|
274
308
|
depth: number;
|
|
275
|
-
//
|
|
276
|
-
// them all without a violation or an error.
|
|
309
|
+
// Once TLC computed all the initial states without a violation or an error.
|
|
277
310
|
initialStates: InitialStates | undefined;
|
|
278
|
-
// How many states
|
|
279
|
-
// the outdegree of the state graph.
|
|
311
|
+
// How many expanded states found each number of new states, when TLC prints the outdegree.
|
|
280
312
|
outDegrees: number[] | undefined;
|
|
281
|
-
// The smallest distance between
|
|
282
|
-
// collision from the actual fingerprints.
|
|
313
|
+
// The smallest distance between two fingerprints, when TLC estimates a collision from them.
|
|
283
314
|
fingerprintDistance: bigint | undefined;
|
|
284
|
-
// A temporal property TLC finds violated as it adds a deadlocked state
|
|
285
|
-
// which it reports after the deadlock.
|
|
315
|
+
// A temporal property TLC finds violated as it adds a deadlocked state, reported after.
|
|
286
316
|
additionalViolation?: Violation;
|
|
287
317
|
// Where TLC's worker fails to add the state to the behavior graph after it reports a violation.
|
|
288
318
|
liveCallStack?: Expression[];
|
|
289
|
-
//
|
|
290
|
-
// stop on a violation without an error code, which TLC 1.7.4 reports as a successful search.
|
|
319
|
+
// The outdegrees when TLC's workers stop on a violation that TLC 1.7.4 reports as a success.
|
|
291
320
|
violationOutDegrees?: number[];
|
|
321
|
+
traceSpec?: string;
|
|
322
|
+
coverage?: CoverageReport;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
interface CoveredAction extends SpecAction {
|
|
326
|
+
node: number;
|
|
292
327
|
}
|
|
293
328
|
|
|
294
329
|
interface Behavior {
|
|
@@ -307,15 +342,14 @@ interface FailureOptions {
|
|
|
307
342
|
outDegrees?: number[];
|
|
308
343
|
callStack?: Expression[];
|
|
309
344
|
fingerprint?: FingerprintFailure;
|
|
345
|
+
replayError?: TlaEvaluationError;
|
|
310
346
|
isNextState?: boolean;
|
|
311
347
|
isCallStackFirst?: boolean;
|
|
312
348
|
traceFailure?: FailureMessage;
|
|
313
|
-
// Whether the call stack
|
|
314
|
-
// of replaying the error.
|
|
349
|
+
// Whether TLC prints the call stack of adding the state to the behavior graph, not a replay.
|
|
315
350
|
isLiveCallStack?: boolean;
|
|
316
351
|
}
|
|
317
352
|
|
|
318
|
-
// TLC prints what the spec prints as it replays a failure after the trace.
|
|
319
353
|
const appendTraceOutput = <Traced extends Behavior>(behavior: Traced, lines: OutputLine[]) => ({
|
|
320
354
|
...behavior,
|
|
321
355
|
traceOutput: [...(behavior.traceOutput ?? []), ...lines],
|
|
@@ -324,45 +358,22 @@ const appendTraceOutput = <Traced extends Behavior>(behavior: Traced, lines: Out
|
|
|
324
358
|
const INITIAL_RECOVERY_FAILURE = "Failed to recover the initial state from its fingerprint.";
|
|
325
359
|
const NEXT_RECOVERY_FAILURE = "Failed to recover the next state from its fingerprint.";
|
|
326
360
|
|
|
327
|
-
const toAliasRecord = (value: Value, fieldOrder: string[]) => {
|
|
328
|
-
if (!isFunctionValue(value)) return undefined;
|
|
329
|
-
const record = toFiniteFunction(value);
|
|
330
|
-
if (!record.domain.every((key) => typeof key === "string")) return undefined;
|
|
331
|
-
const entries = record.domain.map((key, index): [string, Value] => [
|
|
332
|
-
String(key),
|
|
333
|
-
record.range[index],
|
|
334
|
-
]);
|
|
335
|
-
return Object.fromEntries(
|
|
336
|
-
entries.sort((left, right) => fieldOrder.indexOf(left[0]) - fieldOrder.indexOf(right[0])),
|
|
337
|
-
);
|
|
338
|
-
};
|
|
339
|
-
|
|
340
361
|
// Stops a replay where TLC stops it without a failure, as at a violated invariant.
|
|
341
362
|
const STOP_REPLAY = new Error("The replay stopped");
|
|
363
|
+
const STOP_WALK = new Error("The walk stopped");
|
|
342
364
|
|
|
343
|
-
//
|
|
344
|
-
// configuration error.
|
|
345
|
-
const CONFIG_ERROR_CODES = new Set([
|
|
346
|
-
...Array.from({ length: 24 }, (_, index) => 2222 + index),
|
|
347
|
-
2272,
|
|
348
|
-
2273,
|
|
349
|
-
2274,
|
|
350
|
-
2280,
|
|
351
|
-
2281,
|
|
352
|
-
]);
|
|
353
|
-
|
|
354
|
-
// When TLC's replay of the initial states doesn't fail again, it exits with the code of the
|
|
355
|
-
// TLCRuntimeException it reported.
|
|
365
|
+
// When TLC's replay of the initial states doesn't fail again, it exits with the error's code.
|
|
356
366
|
const getInitialExitCode = (error: TlaEvaluationError) => {
|
|
357
367
|
const coded = getCodedMessage(error.message);
|
|
358
|
-
return coded &&
|
|
368
|
+
return coded &&
|
|
369
|
+
!coded.isEvalException &&
|
|
370
|
+
getMessageExitStatus(coded.code) === EXIT_STATUS.configParseError
|
|
359
371
|
? EXIT_STATUS.configParseError
|
|
360
372
|
: getErrorExitCode(error);
|
|
361
373
|
};
|
|
362
374
|
|
|
363
|
-
// When
|
|
364
|
-
//
|
|
365
|
-
// that heads or wraps another exits as the other.
|
|
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.
|
|
366
377
|
const getReplayExitCode = (error: TlaEvaluationError): number => {
|
|
367
378
|
const inner = error.cause;
|
|
368
379
|
if (inner instanceof TlaEvaluationError) return getReplayExitCode(inner);
|
|
@@ -382,8 +393,8 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
|
382
393
|
}
|
|
383
394
|
};
|
|
384
395
|
|
|
385
|
-
// TLC checks liveness on the graph so far 3 seconds
|
|
386
|
-
//
|
|
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.
|
|
387
398
|
const PERIODIC_START = 3000;
|
|
388
399
|
const PROGRESS_INTERVAL = 60_000;
|
|
389
400
|
const LIVENESS_GROWTH = 0.1;
|
|
@@ -395,8 +406,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
395
406
|
? parseConfig(options.config, options.version)
|
|
396
407
|
: options.config;
|
|
397
408
|
const onPrint = options.onPrint ?? console.log;
|
|
398
|
-
// TLC prints again while it rebuilds a trace,
|
|
399
|
-
// keeps what it prints for the trace.
|
|
409
|
+
// TLC prints again while it rebuilds a trace, so rebuilding keeps what it prints for the trace.
|
|
400
410
|
const capturedOutput = { lines: undefined as OutputLine[] | undefined };
|
|
401
411
|
const print = (text: string) => {
|
|
402
412
|
if (capturedOutput.lines) capturedOutput.lines.push(text);
|
|
@@ -414,23 +424,41 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
414
424
|
};
|
|
415
425
|
const order = createTlcOrder(options.source, options.loadModule);
|
|
416
426
|
setStringOrder(order.getStringOrder(config));
|
|
417
|
-
|
|
427
|
+
setValueOptions(options);
|
|
428
|
+
setFingerprintPolynomial(options.fingerprintPolynomial ?? 0);
|
|
418
429
|
const specification = createEnvironment(config, {
|
|
419
430
|
source: options.source,
|
|
420
431
|
loadModule: options.loadModule,
|
|
421
432
|
order,
|
|
422
433
|
loadClass: options.loadClass,
|
|
423
434
|
print,
|
|
424
|
-
files: {
|
|
435
|
+
files: {
|
|
436
|
+
readFile: options.readFile,
|
|
437
|
+
writeFile: options.writeFile,
|
|
438
|
+
makeDirectory: options.makeDirectory,
|
|
439
|
+
},
|
|
425
440
|
seed: options.seed,
|
|
426
441
|
isTool: options.isTool,
|
|
427
|
-
|
|
442
|
+
traceFile: options.traceSpec?.traceFile,
|
|
428
443
|
isSanyReported: options.isSanyReported,
|
|
429
444
|
isWarningEnabled: options.isWarningEnabled,
|
|
430
445
|
version: options.version,
|
|
446
|
+
moduleOperators: options.moduleOperators,
|
|
431
447
|
});
|
|
432
448
|
reportStartup(specification, config, options.onProgress);
|
|
433
|
-
const
|
|
449
|
+
const coverage =
|
|
450
|
+
options.coverage === undefined
|
|
451
|
+
? undefined
|
|
452
|
+
: createCoverage(specification.environment.variables.length);
|
|
453
|
+
const environment: Environment = coverage
|
|
454
|
+
? {
|
|
455
|
+
...specification.environment,
|
|
456
|
+
evaluators: new WeakMap(),
|
|
457
|
+
entryEvaluators: new WeakMap(),
|
|
458
|
+
definitionEvaluators: new WeakMap(),
|
|
459
|
+
coverage,
|
|
460
|
+
}
|
|
461
|
+
: specification.environment;
|
|
434
462
|
const runtime = environment.runtime;
|
|
435
463
|
const is174 = runtime.version === "1.7.4";
|
|
436
464
|
runtime.pause = options.onPause ?? (() => {});
|
|
@@ -442,27 +470,58 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
442
470
|
specification.instanceActions,
|
|
443
471
|
);
|
|
444
472
|
const statistics = { depth: 0, initialStates: undefined as InitialStates | undefined };
|
|
473
|
+
const getTraceSpec = (trace: TraceStep[], loopStart: number | undefined) =>
|
|
474
|
+
options.traceSpec &&
|
|
475
|
+
writeTraceSpec({
|
|
476
|
+
module: options.traceSpec.module,
|
|
477
|
+
specName: specification.rootName,
|
|
478
|
+
rawConstants: config.rawConstants,
|
|
479
|
+
states: trace.map((step) => getStepState(step)),
|
|
480
|
+
loopStart,
|
|
481
|
+
modelValues: getModelValues().map((value) => value.name),
|
|
482
|
+
isDefined: (name) =>
|
|
483
|
+
environment.definitions.has(name) ||
|
|
484
|
+
environment.constants.has(name) ||
|
|
485
|
+
[...environment.definitions.keys()].some((key) =>
|
|
486
|
+
key.startsWith(`${name}${KEY_SEPARATOR}`),
|
|
487
|
+
),
|
|
488
|
+
});
|
|
445
489
|
const createResult = (
|
|
446
490
|
status: CheckStatus,
|
|
447
491
|
violation?: Omit<Violation, "loopStart"> & { loopStart?: number },
|
|
448
492
|
failure?: EvaluationFailure,
|
|
449
|
-
): CheckResult =>
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
493
|
+
): CheckResult => {
|
|
494
|
+
// TLC writes the trace it printed, and a safety property's counterexample doesn't loop back.
|
|
495
|
+
const traceSpec = getTraceSpec(
|
|
496
|
+
violation?.trace ?? failure?.trace ?? [],
|
|
497
|
+
status === "property-violation" ? undefined : violation?.loopStart,
|
|
498
|
+
);
|
|
499
|
+
return {
|
|
500
|
+
status,
|
|
501
|
+
violation: violation && { ...violation, loopStart: violation.loopStart },
|
|
502
|
+
failure,
|
|
503
|
+
generatedStates: runtime.generatedStates,
|
|
504
|
+
distinctStates: runtime.distinctStates,
|
|
505
|
+
queuedStates: runtime.queueSize,
|
|
506
|
+
depth: runtime.generatedStates === 0 ? 0 : Math.max(statistics.depth, 1),
|
|
507
|
+
initialStates: statistics.initialStates,
|
|
508
|
+
outDegrees: undefined,
|
|
509
|
+
fingerprintDistance: undefined,
|
|
510
|
+
coverage: coverage?.relations.some((relation) => relation.kind === "next")
|
|
511
|
+
? getCoverageReport(
|
|
512
|
+
coverage,
|
|
513
|
+
environment,
|
|
514
|
+
specification.variableLocations,
|
|
515
|
+
search?.getTlcOrder() ?? [],
|
|
516
|
+
)
|
|
517
|
+
: undefined,
|
|
518
|
+
...(traceSpec !== undefined && { traceSpec }),
|
|
519
|
+
};
|
|
520
|
+
};
|
|
461
521
|
const outDegrees = Array.from({ length: OUT_DEGREE_BUCKETS }, () => 0);
|
|
462
522
|
const expansion = { newStates: 0 };
|
|
463
523
|
const getOutDegreeBucket = () => Math.min(expansion.newStates, OUT_DEGREE_BUCKETS - 1);
|
|
464
|
-
// TLC counts the state it was expanding when an evaluation failed, except TLC 1.7.4
|
|
465
|
-
// worker stops before it counts the state.
|
|
524
|
+
// TLC counts the state it was expanding when an evaluation failed, except TLC 1.7.4.
|
|
466
525
|
const getPartialOutDegrees = () =>
|
|
467
526
|
outDegrees.map((count, degree) => (degree === getOutDegreeBucket() ? count + 1 : count));
|
|
468
527
|
const getFailureOutDegrees = () => (is174 ? [...outDegrees] : getPartialOutDegrees());
|
|
@@ -490,8 +549,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
490
549
|
const search = createSearch(
|
|
491
550
|
config,
|
|
492
551
|
environment,
|
|
552
|
+
specification.variableLocations,
|
|
493
553
|
() => order.getDeclarationOrder("variable"),
|
|
494
554
|
options.onProgress,
|
|
555
|
+
specification.moduleOperators,
|
|
495
556
|
);
|
|
496
557
|
const findViolatedAssumption = () =>
|
|
497
558
|
findAssumptionViolation(specification.assumptions, environment);
|
|
@@ -508,9 +569,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
508
569
|
});
|
|
509
570
|
return createSuccess();
|
|
510
571
|
}
|
|
511
|
-
const hasPostconditions =
|
|
512
|
-
|
|
513
|
-
|
|
572
|
+
const hasPostconditions =
|
|
573
|
+
config.postconditions.length > 0 ||
|
|
574
|
+
config.possible.length > 0 ||
|
|
575
|
+
specification.moduleOperators.some((operator) => operator.kind === "postcondition");
|
|
576
|
+
// The state of each step without the alias, and its action, which CounterExample records.
|
|
514
577
|
const traceSteps = new WeakMap<
|
|
515
578
|
TraceStep,
|
|
516
579
|
{ state: Record<string, Value>; action: SpecAction | undefined }
|
|
@@ -520,8 +583,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
520
583
|
const action = traceSteps.get(step)?.action;
|
|
521
584
|
return action ? toActionValue(action) : createActionRecord(step.action);
|
|
522
585
|
};
|
|
523
|
-
//
|
|
524
|
-
// what they print follows the trace.
|
|
586
|
+
// TLC checks the postconditions on each trace it prints, so what they print follows the trace.
|
|
525
587
|
const checkTracePostconditions = (
|
|
526
588
|
trace: TraceStep[],
|
|
527
589
|
loop: { start: number; action: Value } | undefined,
|
|
@@ -549,26 +611,103 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
549
611
|
violation.trace,
|
|
550
612
|
start === undefined || !getLoopAction ? undefined : { start, action: getLoopAction() },
|
|
551
613
|
);
|
|
552
|
-
const traceOutput = [...(violation.traceOutput ?? []), ...checked.lines];
|
|
553
614
|
return createResult(status, {
|
|
554
615
|
...violation,
|
|
555
|
-
...(
|
|
616
|
+
...(checked.lines.length > 0 && { postconditionOutput: checked.lines }),
|
|
556
617
|
...(checked.unwitnessed && { unwitnessed: checked.unwitnessed }),
|
|
557
618
|
...(checked.postcondition && { postcondition: checked.postcondition }),
|
|
558
619
|
});
|
|
559
620
|
};
|
|
560
|
-
// With -continue, TLC prints the trace of a violation without checking the postconditions.
|
|
561
|
-
|
|
621
|
+
// With -continue, TLC prints the trace of a violation without checking the postconditions. It
|
|
622
|
+
// never records the violation, and reports a success at the end, where tla-ts ends with the
|
|
623
|
+
// status of the first violation, as -dfid and -simulate do.
|
|
624
|
+
const continued = { status: undefined as CheckStatus | undefined };
|
|
625
|
+
const reportContinuedViolation = (
|
|
626
|
+
status: CheckStatus,
|
|
627
|
+
violation: Omit<Violation, "loopStart">,
|
|
628
|
+
) => {
|
|
629
|
+
continued.status ??= status;
|
|
562
630
|
options.onProgress?.({
|
|
563
631
|
kind: "violation",
|
|
564
632
|
status,
|
|
565
633
|
violation: { ...violation, loopStart: undefined },
|
|
566
634
|
});
|
|
635
|
+
};
|
|
567
636
|
const spec = search.spec;
|
|
568
637
|
const getFingerprintState = search.getFingerprintState;
|
|
569
638
|
const specNextActions = { value: undefined as SpecAction[] | undefined };
|
|
570
639
|
const getSpecNextActions = () =>
|
|
571
640
|
(specNextActions.value ??= getNextActions(config, environment, specification.instanceActions));
|
|
641
|
+
// Tool's constructor splits the next-state relation into actions before TLC checks anything.
|
|
642
|
+
getSpecNextActions();
|
|
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
|
+
);
|
|
649
|
+
const addCoverageRelations = (kind: "init" | "next", actions: SpecAction[]) =>
|
|
650
|
+
actions.map((action): CoveredAction => ({
|
|
651
|
+
...action,
|
|
652
|
+
node: coverage
|
|
653
|
+
? addCoverageRelation(
|
|
654
|
+
coverage,
|
|
655
|
+
kind,
|
|
656
|
+
getCoverageLabel(action.name, action.expression, environment),
|
|
657
|
+
action.expression,
|
|
658
|
+
action.scope,
|
|
659
|
+
)
|
|
660
|
+
: -1,
|
|
661
|
+
}));
|
|
662
|
+
const coverageInits = addCoverageRelations(
|
|
663
|
+
"init",
|
|
664
|
+
coverage ? getInitActions(config, environment, specification.instanceActions) : [],
|
|
665
|
+
);
|
|
666
|
+
const coverageActions = addCoverageRelations("next", coverage ? getSpecNextActions() : []);
|
|
667
|
+
if (coverage) buildCoverage(coverage, environment, getPrimedRanges(coverageActions, environment));
|
|
668
|
+
const walkCoveredSuccessors = (
|
|
669
|
+
action: CoveredAction,
|
|
670
|
+
state: Value[],
|
|
671
|
+
onState: (successor: Value[]) => void,
|
|
672
|
+
) =>
|
|
673
|
+
walkSuccessors(
|
|
674
|
+
action,
|
|
675
|
+
action.node,
|
|
676
|
+
state,
|
|
677
|
+
environment,
|
|
678
|
+
(successor) => {
|
|
679
|
+
if (coverage) coverage.primary[action.node]++;
|
|
680
|
+
onState(successor);
|
|
681
|
+
},
|
|
682
|
+
(partial) => {
|
|
683
|
+
const missing = environment.variables.filter((_, index) => partial[index] === undefined);
|
|
684
|
+
throw new TlaIncompleteSuccessorError(
|
|
685
|
+
`Successor state is not completely specified by action ${action.name}. The following variables are not assigned: ${missing.join(", ")}`,
|
|
686
|
+
partial,
|
|
687
|
+
action.name,
|
|
688
|
+
missing,
|
|
689
|
+
);
|
|
690
|
+
},
|
|
691
|
+
);
|
|
692
|
+
const getCoveredSuccessors = (action: CoveredAction, state: Value[]) => {
|
|
693
|
+
const successors: Successor[] = [];
|
|
694
|
+
walkCoveredSuccessors(action, state, (successor) =>
|
|
695
|
+
successors.push({ state: successor, action: action.name }),
|
|
696
|
+
);
|
|
697
|
+
return successors;
|
|
698
|
+
};
|
|
699
|
+
const getCoveredInitialStates = () => {
|
|
700
|
+
const initialStates: Value[][] = [];
|
|
701
|
+
replayInitialStates(
|
|
702
|
+
coverageInits,
|
|
703
|
+
environment,
|
|
704
|
+
(state) => initialStates.push(state),
|
|
705
|
+
(partial) => {
|
|
706
|
+
throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
|
|
707
|
+
},
|
|
708
|
+
);
|
|
709
|
+
return initialStates;
|
|
710
|
+
};
|
|
572
711
|
const getReplayFailure = (replay: (tracing: Environment) => void): ReplayFailure | undefined => {
|
|
573
712
|
const tracing = createTracingEnvironment(environment);
|
|
574
713
|
const callStack = tracing.callStack;
|
|
@@ -579,11 +718,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
579
718
|
// A replay that overflows the stack again has an empty call stack.
|
|
580
719
|
if (isStackOverflow(error)) return { callStack: [], fingerprint: undefined };
|
|
581
720
|
if (!(error instanceof TlaEvaluationError) || !callStack) return undefined;
|
|
582
|
-
return {
|
|
721
|
+
return {
|
|
722
|
+
callStack: callStack.expressions,
|
|
723
|
+
fingerprint: callStack.fingerprint,
|
|
724
|
+
replayError: error,
|
|
725
|
+
};
|
|
583
726
|
}
|
|
584
727
|
};
|
|
585
|
-
//
|
|
586
|
-
// fingerprints a value it holds.
|
|
728
|
+
// Outermost first: each value fails as it fingerprints a value it holds.
|
|
587
729
|
const findFailedSources = (value: Value, sources: CallStack["sources"]): Expression[] => {
|
|
588
730
|
if (typeof value !== "object") return [];
|
|
589
731
|
const source = sources.get(value);
|
|
@@ -593,8 +735,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
593
735
|
...(failed === undefined ? [] : findFailedSources(failed, sources)),
|
|
594
736
|
];
|
|
595
737
|
};
|
|
596
|
-
//
|
|
597
|
-
// FingerprintException when it fails to.
|
|
738
|
+
// A value the replay built raises a FingerprintException when TLC fails to fingerprint it.
|
|
598
739
|
const fingerprintReplayed = (state: Value[], callStack: CallStack | undefined) => {
|
|
599
740
|
for (const value of getFingerprintState(state)) {
|
|
600
741
|
const error = getFingerprintError(value);
|
|
@@ -610,8 +751,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
610
751
|
}
|
|
611
752
|
state.forEach(markFingerprinted);
|
|
612
753
|
};
|
|
613
|
-
//
|
|
614
|
-
// that failed after TLC added it.
|
|
754
|
+
// TLC's set of states already holds the state that failed.
|
|
615
755
|
const createReplayedStates = () => {
|
|
616
756
|
const replayed = unstoredState.fingerprint ? [unstoredState.fingerprint] : [];
|
|
617
757
|
return (state: Value[], callStack: CallStack | undefined) => {
|
|
@@ -626,12 +766,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
626
766
|
return true;
|
|
627
767
|
};
|
|
628
768
|
};
|
|
629
|
-
// TLC
|
|
630
|
-
//
|
|
631
|
-
// states left, then throws the exception.
|
|
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.
|
|
632
771
|
const replayInit = () => {
|
|
633
772
|
const replayed = { count: 0 };
|
|
634
|
-
const deferred:
|
|
773
|
+
const deferred: unknown[] = [];
|
|
635
774
|
const addReplayed = createReplayedStates();
|
|
636
775
|
return getReplayFailure((tracing) => {
|
|
637
776
|
replayInitialStates(
|
|
@@ -661,9 +800,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
661
800
|
throw STOP_REPLAY;
|
|
662
801
|
}
|
|
663
802
|
} catch (error) {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
803
|
+
const isFingerprintFailure =
|
|
804
|
+
error instanceof TlaEvaluationError && tracing.callStack?.fingerprint !== undefined;
|
|
805
|
+
if (!isFingerprintFailure && !isStackOverflow(error)) throw error;
|
|
667
806
|
deferred.push(error);
|
|
668
807
|
}
|
|
669
808
|
},
|
|
@@ -671,8 +810,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
671
810
|
if (deferred.length > 0) throw deferred[0];
|
|
672
811
|
});
|
|
673
812
|
};
|
|
674
|
-
// TLC
|
|
675
|
-
// the model to the -dump state graph again.
|
|
813
|
+
// TLC's replay writes each successor in the model to the -dump state graph again.
|
|
676
814
|
const replayNext = (index: number) =>
|
|
677
815
|
getReplayFailure((tracing) => {
|
|
678
816
|
const state = states[index];
|
|
@@ -686,9 +824,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
686
824
|
source,
|
|
687
825
|
getGraphState(next, depths[index] + 1),
|
|
688
826
|
!isUnseen,
|
|
689
|
-
isNamingEdges
|
|
690
|
-
? { name: action.name, signature: getActionSignature(action) }
|
|
691
|
-
: undefined,
|
|
827
|
+
isNamingEdges ? getGraphAction(action) : undefined,
|
|
692
828
|
);
|
|
693
829
|
}
|
|
694
830
|
return isUnseen;
|
|
@@ -716,33 +852,37 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
716
852
|
getSuccessors: (source, state) => {
|
|
717
853
|
const successors: LiveSuccessor[] = [];
|
|
718
854
|
if (spec.next === undefined) return successors;
|
|
719
|
-
// The constraints read the level of the state whose successors they check
|
|
720
|
-
// explored it.
|
|
855
|
+
// The constraints read the level of the state whose successors they check.
|
|
721
856
|
const livenessSource = current.livenessSource;
|
|
722
857
|
current.livenessSource = source;
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
858
|
+
try {
|
|
859
|
+
forEachSuccessor(
|
|
860
|
+
spec.next,
|
|
861
|
+
state,
|
|
862
|
+
environment,
|
|
863
|
+
(successor) => {
|
|
864
|
+
canonicalizeState(successor.state);
|
|
865
|
+
const isInModel =
|
|
866
|
+
search.satisfiesConstraints(successor.state, state) &&
|
|
867
|
+
search.satisfiesActionConstraints(state, successor.state);
|
|
868
|
+
if (!isInModel) return false;
|
|
869
|
+
const fingerprintState = getFingerprintState(successor.state);
|
|
870
|
+
const index = findStateIndex(getStateHash(fingerprintState), fingerprintState);
|
|
871
|
+
successors.push({ index, state: successor.state });
|
|
872
|
+
return false;
|
|
873
|
+
},
|
|
874
|
+
spec.scope,
|
|
875
|
+
);
|
|
876
|
+
} finally {
|
|
877
|
+
current.livenessSource = livenessSource;
|
|
878
|
+
}
|
|
741
879
|
return successors;
|
|
742
880
|
},
|
|
743
881
|
}),
|
|
744
882
|
),
|
|
745
883
|
);
|
|
884
|
+
// ModelChecker rejects a temporal property whose negation has no solution.
|
|
885
|
+
if (liveness?.branches === 0) throw createTautologyError();
|
|
746
886
|
// TLC 1.7.4 creates its model checker, which TLCGet reads, once it has built the liveness checker.
|
|
747
887
|
runtime.isStarted = true;
|
|
748
888
|
const isCanonicalizedFirst = search.isSymmetric || liveness !== undefined;
|
|
@@ -752,64 +892,68 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
752
892
|
const parents: number[] = [];
|
|
753
893
|
const actions: (string | undefined)[] = [];
|
|
754
894
|
const depths: number[] = [];
|
|
755
|
-
// A Map holds at most 2^24 entries, so an open-addressing table keeps each
|
|
756
|
-
// and its index plus one side by side, probed by the hash.
|
|
895
|
+
// A Map holds at most 2^24 entries, so an open-addressing table keeps each hash and index + 1.
|
|
757
896
|
const seenStates = { slots: new Int32Array(1 << 17), size: 0, shift: 16 };
|
|
758
897
|
const canonicalizeState = createCanonicalizer();
|
|
759
898
|
|
|
760
|
-
const toRecord =
|
|
761
|
-
Object.fromEntries(
|
|
762
|
-
search.getTlcOrder().map((index) => [environment.variables[index], state[index]]),
|
|
763
|
-
);
|
|
899
|
+
const toRecord = search.toRecord;
|
|
764
900
|
const getAliasState = (
|
|
765
901
|
alias: string,
|
|
766
902
|
steps: Successor[],
|
|
767
903
|
position: number,
|
|
768
904
|
loopStart: number | undefined,
|
|
769
905
|
) => {
|
|
770
|
-
// TLC evaluates TLCGet("level") and Trace in an alias at the state's position in the trace.
|
|
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;
|
|
771
910
|
runtime.getLevel = () => position + 1;
|
|
772
911
|
runtime.getBehavior = () => steps.slice(0, position + 1).map((step) => step.state);
|
|
773
|
-
return evaluateAlias(
|
|
774
|
-
alias,
|
|
775
|
-
steps[position].state,
|
|
776
|
-
(steps[position + 1] ?? steps[loopStart ?? position]).state,
|
|
777
|
-
);
|
|
778
|
-
};
|
|
779
|
-
const evaluateAlias = (alias: string, state: Value[], next: Value[] | undefined) => {
|
|
780
912
|
try {
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
_ALIASEvalError: formatNestedMessage(error.message, options.isTool ?? false),
|
|
790
|
-
};
|
|
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;
|
|
791
921
|
}
|
|
792
922
|
};
|
|
793
|
-
|
|
794
|
-
|
|
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.
|
|
795
927
|
const findStepAction = (index: number, previous: Value[], state: Value[], isHeld: boolean) => {
|
|
796
928
|
const actions = getSpecNextActions();
|
|
797
929
|
const expanding = { ...current };
|
|
798
|
-
Object.assign(current, {
|
|
930
|
+
Object.assign(current, {
|
|
931
|
+
index,
|
|
932
|
+
isExpanding: true,
|
|
933
|
+
candidate: undefined,
|
|
934
|
+
rebuilt: { state: previous, level: depths[index] },
|
|
935
|
+
});
|
|
799
936
|
const getKey = isHeld ? (values: Value[]) => values : getFingerprintState;
|
|
800
937
|
const key = getKey(state);
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
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
|
+
}
|
|
808
953
|
};
|
|
809
|
-
//
|
|
810
|
-
//
|
|
811
|
-
//
|
|
812
|
-
// or TLC is 1.7.4.
|
|
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.
|
|
813
957
|
const toTrace = (
|
|
814
958
|
steps: Successor[],
|
|
815
959
|
path: number[],
|
|
@@ -834,9 +978,26 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
834
978
|
);
|
|
835
979
|
const outputs = stepActions.map((step) => step.lines);
|
|
836
980
|
const loopStart = traceOptions.loopStart;
|
|
837
|
-
// 1.7.4
|
|
838
|
-
// each state of the cycle as it prints it.
|
|
981
|
+
// TLC 1.7.4 rebuilds a lasso up to its cycle at once, then each cycle state as it prints it.
|
|
839
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
|
+
}
|
|
840
1001
|
const prefixOutput = rebuilt > 0 ? [initialOutput, ...outputs.slice(1, rebuilt)].flat() : [];
|
|
841
1002
|
return {
|
|
842
1003
|
trace: steps.map((step, position) => {
|
|
@@ -858,11 +1019,12 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
858
1019
|
traceOutput: known > 0 && !is174 ? [initialOutput, ...outputs].flat() : [],
|
|
859
1020
|
};
|
|
860
1021
|
};
|
|
861
|
-
const getSpecInitialStates = () =>
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
//
|
|
1022
|
+
const getSpecInitialStates = () => {
|
|
1023
|
+
if (coverage) return getCoveredInitialStates();
|
|
1024
|
+
return spec.init === undefined ? [] : getInitialStates(spec.init, environment, spec.scope);
|
|
1025
|
+
};
|
|
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.
|
|
866
1028
|
const findTraceSuccessor = (state: Value[], isMatch: (successor: Successor) => boolean) =>
|
|
867
1029
|
captureOutput(() => {
|
|
868
1030
|
for (const action of getSpecNextActions()) {
|
|
@@ -891,7 +1053,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
891
1053
|
steps.push({ state: previous, action: "Stuttering" });
|
|
892
1054
|
continue;
|
|
893
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]] };
|
|
894
1059
|
const successor = findSuccessorWithFingerprint(previous, path[position]);
|
|
1060
|
+
current.rebuilt = rebuilt;
|
|
895
1061
|
if (!successor) throw new TlaEvaluationError(nextFailure);
|
|
896
1062
|
steps.push(successor);
|
|
897
1063
|
}
|
|
@@ -914,24 +1080,45 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
914
1080
|
: lastSuccessor.action;
|
|
915
1081
|
return toTrace([...steps, { state: lastSuccessor.state, action }], path, { known: 2 });
|
|
916
1082
|
};
|
|
917
|
-
// TLC
|
|
918
|
-
//
|
|
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.
|
|
919
1085
|
const getStateTrace = (index: number): Behavior =>
|
|
920
1086
|
parents[index] === -1
|
|
921
1087
|
? {
|
|
922
|
-
trace: [
|
|
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
|
+
],
|
|
923
1103
|
traceOutput: is174 ? [] : captureOutput(getSpecInitialStates).lines,
|
|
924
1104
|
}
|
|
925
1105
|
: getTrace(index);
|
|
926
|
-
// TLC rebuilds the trace
|
|
927
|
-
// an
|
|
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
|
+
const isUnfingerprintable = (state: Value[]) => {
|
|
1109
|
+
try {
|
|
1110
|
+
return getFingerprintState(state).some((value) => getFingerprintError(value) !== undefined);
|
|
1111
|
+
} catch (error) {
|
|
1112
|
+
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1113
|
+
return true;
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
928
1116
|
const getFailedTrace = (index: number, successor: Successor): Behavior => ({
|
|
929
1117
|
trace: getTrace(index, successor).trace,
|
|
930
1118
|
});
|
|
931
1119
|
// TLC names the initial state it was checking unless a standard module's Java code failed.
|
|
932
1120
|
const getFailureExitCode = (error: TlaEvaluationError, failureOptions: FailureOptions) => {
|
|
933
|
-
// TLC 1.7.4 exits with the result of
|
|
934
|
-
// when the error isn't in adding a state it has already seen to the behavior graph.
|
|
1121
|
+
// TLC 1.7.4 exits with the result of replaying the initial states, which fails again only here.
|
|
935
1122
|
if (
|
|
936
1123
|
failureOptions.isInitial &&
|
|
937
1124
|
!failureOptions.callStack &&
|
|
@@ -950,11 +1137,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
950
1137
|
getExitCode(error) ?? (error instanceof TlaModuleError ? error.exitCode : EXIT_STATUS.error)
|
|
951
1138
|
);
|
|
952
1139
|
}
|
|
953
|
-
// TLC exits with the code of a failed
|
|
954
|
-
// it does for a replay that fails to fingerprint.
|
|
1140
|
+
// TLC exits with the code of a failed initial replay whatever the error, as for a fingerprint.
|
|
955
1141
|
return failureOptions.isInitial || failureOptions.fingerprint
|
|
956
1142
|
? EXIT_STATUS.specEvaluationFailure
|
|
957
|
-
: getReplayExitCode(error);
|
|
1143
|
+
: getReplayExitCode(failureOptions.replayError ?? error);
|
|
958
1144
|
};
|
|
959
1145
|
const createFailureResult = (
|
|
960
1146
|
failed: unknown,
|
|
@@ -988,21 +1174,27 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
988
1174
|
outDegrees: failureOptions.outDegrees,
|
|
989
1175
|
};
|
|
990
1176
|
};
|
|
991
|
-
// TLC reports a successor
|
|
992
|
-
// with the partial state. It names the action when the next-state relation has several.
|
|
1177
|
+
// TLC reports a partial successor with the trace to it, naming the action if there are several.
|
|
993
1178
|
const reportIncompleteSuccessor = (index: number, error: TlaIncompleteSuccessorError) => {
|
|
994
1179
|
runtime.generatedStates++;
|
|
995
1180
|
const actions = getSpecNextActions();
|
|
1181
|
+
const named =
|
|
1182
|
+
actions.length === 1 ? actions : actions.filter((item) => item.name === error.action);
|
|
1183
|
+
// Inline disjuncts of the next-state relation share its name, so TLC's is the one that failed.
|
|
996
1184
|
const action =
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
const
|
|
1005
|
-
|
|
1185
|
+
named.length === 1
|
|
1186
|
+
? named[0]
|
|
1187
|
+
: captureOutput(() =>
|
|
1188
|
+
named.find((item) =>
|
|
1189
|
+
hasIncompleteSuccessor(item.expression, states[index], environment, item.scope),
|
|
1190
|
+
),
|
|
1191
|
+
).result;
|
|
1192
|
+
const message = getIncompleteSuccessorMessage(
|
|
1193
|
+
error.variables,
|
|
1194
|
+
error.action,
|
|
1195
|
+
actions.length,
|
|
1196
|
+
options.version,
|
|
1197
|
+
);
|
|
1006
1198
|
const undefinedValue = createModelValue("null");
|
|
1007
1199
|
const partial = error.state.map((value) => value ?? undefinedValue);
|
|
1008
1200
|
const failure = createFailureResult(error, getStateTrace(index));
|
|
@@ -1085,8 +1277,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1085
1277
|
}
|
|
1086
1278
|
insertSeen(hash, index + 1);
|
|
1087
1279
|
};
|
|
1088
|
-
//
|
|
1089
|
-
// the check stores after.
|
|
1280
|
+
// TLC adds a new successor to its states before it checks it, which the check stores after.
|
|
1090
1281
|
const unstoredState = { fingerprint: undefined as Value[] | undefined };
|
|
1091
1282
|
const countDistinctState = (depth: number) => {
|
|
1092
1283
|
runtime.distinctStates = states.length + 1;
|
|
@@ -1113,6 +1304,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1113
1304
|
candidate: undefined as Value[] | undefined,
|
|
1114
1305
|
candidateLevel: 0,
|
|
1115
1306
|
livenessSource: -1,
|
|
1307
|
+
rebuilt: undefined as { state: Value[]; level: number } | undefined,
|
|
1116
1308
|
};
|
|
1117
1309
|
const getPath = (index: number): Value[][] =>
|
|
1118
1310
|
index === -1 ? [] : [...getPath(parents[index]), states[index]];
|
|
@@ -1135,6 +1327,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1135
1327
|
const explored = source !== -1 ? source : current.isExpanding ? current.index : -1;
|
|
1136
1328
|
return explored === -1 ? 0 : depths[explored];
|
|
1137
1329
|
}
|
|
1330
|
+
const rebuilt = current.rebuilt;
|
|
1331
|
+
if (rebuilt) return state === rebuilt.state ? rebuilt.level : rebuilt.level + 1;
|
|
1138
1332
|
if (source !== -1) return state === states[source] ? depths[source] : depths[source] + 1;
|
|
1139
1333
|
if (state === current.candidate) return current.candidateLevel;
|
|
1140
1334
|
if (current.index === -1) return 0;
|
|
@@ -1142,6 +1336,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1142
1336
|
return current.isExpanding ? depths[current.index] + 1 : 0;
|
|
1143
1337
|
};
|
|
1144
1338
|
|
|
1339
|
+
const getGraphAction = (action: SpecAction) => ({
|
|
1340
|
+
name: action.name,
|
|
1341
|
+
signature: getActionSignature(action),
|
|
1342
|
+
});
|
|
1145
1343
|
const getGraphState = (state: Value[], level: number): GraphState => ({
|
|
1146
1344
|
fingerprint: BigInt.asIntN(64, runtime.getFingerprint(state)),
|
|
1147
1345
|
level,
|
|
@@ -1233,9 +1431,22 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1233
1431
|
source,
|
|
1234
1432
|
getGraphState(successor.state, depths[index] + 1),
|
|
1235
1433
|
existing !== -1,
|
|
1236
|
-
action &&
|
|
1434
|
+
action && getGraphAction(action),
|
|
1237
1435
|
);
|
|
1238
1436
|
}
|
|
1437
|
+
if (source && !isInModel && options.dump?.constrained) {
|
|
1438
|
+
const excluded = getGraphState(successor.state, depths[index] + 1);
|
|
1439
|
+
search
|
|
1440
|
+
.getExcludingConstraints(state, successor.state)
|
|
1441
|
+
.forEach((constraint) =>
|
|
1442
|
+
stateWriter?.writeConstrained(
|
|
1443
|
+
source,
|
|
1444
|
+
excluded,
|
|
1445
|
+
action && getGraphAction(action),
|
|
1446
|
+
constraint,
|
|
1447
|
+
),
|
|
1448
|
+
);
|
|
1449
|
+
}
|
|
1239
1450
|
if (existing !== -1 && liveness) {
|
|
1240
1451
|
const stored = states[existing];
|
|
1241
1452
|
const isStored = stored.every((value, position) => value === successor.state[position]);
|
|
@@ -1248,6 +1459,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1248
1459
|
if (isNew) {
|
|
1249
1460
|
countDistinctState(depths[index] + 1);
|
|
1250
1461
|
expansion.newStates++;
|
|
1462
|
+
if (coverage) coverage.secondary[coveredAction.node]++;
|
|
1251
1463
|
}
|
|
1252
1464
|
if (existing === -1) {
|
|
1253
1465
|
try {
|
|
@@ -1259,9 +1471,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1259
1471
|
if (violation) reportContinuedViolation("invariant-violation", violation);
|
|
1260
1472
|
} catch (error) {
|
|
1261
1473
|
if (isStackOverflow(error)) throw error;
|
|
1262
|
-
// TLC replays the expansion and skips the invariants of a state
|
|
1263
|
-
// included unless the constraints exclude it.
|
|
1264
|
-
// leaves out the outdegree.
|
|
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.
|
|
1265
1476
|
const replay = captureOutput(() => replayNext(index));
|
|
1266
1477
|
return createFailureResult(
|
|
1267
1478
|
error,
|
|
@@ -1280,6 +1491,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1280
1491
|
}
|
|
1281
1492
|
if (propertyViolation) reportContinuedViolation("liveness-violation", propertyViolation);
|
|
1282
1493
|
if (!isNew) return undefined;
|
|
1494
|
+
if (coverage) countCoverageVariables(coverage, successor.state);
|
|
1283
1495
|
if (!isCanonicalizedFirst) canonicalizeState(successor.state);
|
|
1284
1496
|
markSeen(hash, states.length);
|
|
1285
1497
|
addState(successor.state, fingerprintState, index, successor.action);
|
|
@@ -1288,38 +1500,64 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1288
1500
|
};
|
|
1289
1501
|
|
|
1290
1502
|
const outcome: { result: CheckResult | undefined } = { result: undefined };
|
|
1503
|
+
const coveredAction = { node: -1 };
|
|
1291
1504
|
if (liveness) {
|
|
1292
1505
|
options.onProgress?.({ kind: "liveness-prepared", branches: liveness.branches });
|
|
1293
1506
|
}
|
|
1294
|
-
// TLC checks the assumptions once it has built the liveness checker
|
|
1295
|
-
// constructor.
|
|
1507
|
+
// TLC checks the assumptions once it has built the liveness checker.
|
|
1296
1508
|
const assumptionViolation = findViolatedAssumption();
|
|
1297
1509
|
if (assumptionViolation) return createResult("assumption-violation", assumptionViolation);
|
|
1298
1510
|
options.onProgress?.({ kind: "initial-states-started" });
|
|
1299
1511
|
if (spec.init !== undefined) {
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
} catch (error) {
|
|
1309
|
-
const replay = captureOutput(replayInit);
|
|
1310
|
-
outcome.result = createFailureResult(
|
|
1311
|
-
error,
|
|
1312
|
-
{ trace: [], traceOutput: replay.lines },
|
|
1313
|
-
{ initialState: state, ...replay.result, isInitial: true },
|
|
1314
|
-
);
|
|
1315
|
-
}
|
|
1316
|
-
return outcome.result !== undefined;
|
|
1317
|
-
},
|
|
1318
|
-
spec.scope,
|
|
1512
|
+
// TLC keeps an initial state's StackOverflowError, counts the states after it, then reports it.
|
|
1513
|
+
const overflow: { state: Value[] | undefined } = { state: undefined };
|
|
1514
|
+
const reportInitialFailure = (error: unknown, state: Value[]) => {
|
|
1515
|
+
const replay = captureOutput(replayInit);
|
|
1516
|
+
return createFailureResult(
|
|
1517
|
+
error,
|
|
1518
|
+
{ trace: [], traceOutput: replay.lines },
|
|
1519
|
+
{ initialState: state, ...replay.result, isInitial: true },
|
|
1319
1520
|
);
|
|
1521
|
+
};
|
|
1522
|
+
try {
|
|
1523
|
+
const onInitialState = (state: Value[]) => {
|
|
1524
|
+
reportInitialStatesProgress(runtime.initialStates, options.onProgress);
|
|
1525
|
+
if (overflow.state) {
|
|
1526
|
+
runtime.generatedStates++;
|
|
1527
|
+
runtime.initialStates++;
|
|
1528
|
+
return false;
|
|
1529
|
+
}
|
|
1530
|
+
try {
|
|
1531
|
+
outcome.result = visitInitialState(state);
|
|
1532
|
+
} catch (error) {
|
|
1533
|
+
if (isStackOverflow(error)) overflow.state = state;
|
|
1534
|
+
else outcome.result = reportInitialFailure(error, state);
|
|
1535
|
+
}
|
|
1536
|
+
return outcome.result !== undefined;
|
|
1537
|
+
};
|
|
1538
|
+
if (coverage) {
|
|
1539
|
+
try {
|
|
1540
|
+
replayInitialStates(
|
|
1541
|
+
coverageInits,
|
|
1542
|
+
environment,
|
|
1543
|
+
(state) => {
|
|
1544
|
+
if (onInitialState(state)) throw STOP_WALK;
|
|
1545
|
+
},
|
|
1546
|
+
(partial) => {
|
|
1547
|
+
throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
|
|
1548
|
+
},
|
|
1549
|
+
);
|
|
1550
|
+
} catch (error) {
|
|
1551
|
+
if (error !== STOP_WALK) throw error;
|
|
1552
|
+
}
|
|
1553
|
+
} else {
|
|
1554
|
+
forEachInitialState(spec.init, environment, onInitialState, spec.scope);
|
|
1555
|
+
}
|
|
1556
|
+
if (overflow.state) {
|
|
1557
|
+
outcome.result = reportInitialFailure(createStackOverflowError(), overflow.state);
|
|
1558
|
+
}
|
|
1320
1559
|
} catch (error) {
|
|
1321
|
-
// TLC prints
|
|
1322
|
-
// stops before it prints the statistics.
|
|
1560
|
+
// TLC prints null for each undefined variable and stops before the statistics.
|
|
1323
1561
|
if (error instanceof TlaIllegalStateError) {
|
|
1324
1562
|
const illegal = createFailureResult(
|
|
1325
1563
|
error,
|
|
@@ -1359,15 +1597,33 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1359
1597
|
}
|
|
1360
1598
|
return createSuccess();
|
|
1361
1599
|
}
|
|
1362
|
-
// TLC labels and colors
|
|
1363
|
-
//
|
|
1600
|
+
// TLC labels and colors a -dump edge by its action, so a graph that names its edges generates
|
|
1601
|
+
// successors action by action.
|
|
1364
1602
|
const isNamingEdges = Boolean(
|
|
1365
1603
|
options.dump?.dot && (options.dump.actionLabels || options.dump.colorize),
|
|
1366
1604
|
);
|
|
1367
1605
|
const forEachActionSuccessor = (
|
|
1368
1606
|
state: Value[],
|
|
1607
|
+
onUnsatisfied:
|
|
1608
|
+
| ((successor: Value[], conjunct: Expression, action?: SpecAction) => void)
|
|
1609
|
+
| undefined,
|
|
1369
1610
|
onSuccessor: (successor: Successor, action: SpecAction | undefined) => boolean,
|
|
1370
1611
|
) => {
|
|
1612
|
+
if (coverage) {
|
|
1613
|
+
const progress = { count: 0 };
|
|
1614
|
+
try {
|
|
1615
|
+
coverageActions.forEach((action) => {
|
|
1616
|
+
coveredAction.node = action.node;
|
|
1617
|
+
walkCoveredSuccessors(action, state, (successor) => {
|
|
1618
|
+
progress.count++;
|
|
1619
|
+
if (onSuccessor({ state: successor, action: action.name }, action)) throw STOP_WALK;
|
|
1620
|
+
});
|
|
1621
|
+
});
|
|
1622
|
+
} catch (error) {
|
|
1623
|
+
if (error !== STOP_WALK) throw error;
|
|
1624
|
+
}
|
|
1625
|
+
return progress.count;
|
|
1626
|
+
}
|
|
1371
1627
|
if (!isNamingEdges) {
|
|
1372
1628
|
return forEachSuccessor(
|
|
1373
1629
|
next,
|
|
@@ -1375,6 +1631,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1375
1631
|
environment,
|
|
1376
1632
|
(successor) => onSuccessor(successor, undefined),
|
|
1377
1633
|
spec.scope,
|
|
1634
|
+
undefined,
|
|
1635
|
+
onUnsatisfied,
|
|
1378
1636
|
);
|
|
1379
1637
|
}
|
|
1380
1638
|
const progress = { isStopped: false };
|
|
@@ -1391,13 +1649,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1391
1649
|
return progress.isStopped;
|
|
1392
1650
|
},
|
|
1393
1651
|
action.scope,
|
|
1652
|
+
undefined,
|
|
1653
|
+
onUnsatisfied && ((successor, conjunct) => onUnsatisfied(successor, conjunct, action)),
|
|
1394
1654
|
)
|
|
1395
1655
|
);
|
|
1396
1656
|
}, 0);
|
|
1397
1657
|
};
|
|
1398
|
-
// TLC's worker adds a state to the behavior graph even after its next states fail
|
|
1399
|
-
//
|
|
1400
|
-
// FingerprintException, which the worker doesn't catch. TLC 1.7.4 prints none.
|
|
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.
|
|
1401
1660
|
const getLiveCallStack = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1402
1661
|
if (!liveness || is174) return undefined;
|
|
1403
1662
|
const replay = getReplayFailure((tracing) =>
|
|
@@ -1405,9 +1664,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1405
1664
|
);
|
|
1406
1665
|
return replay?.callStack.length && !replay.fingerprint ? replay.callStack : undefined;
|
|
1407
1666
|
};
|
|
1408
|
-
//
|
|
1409
|
-
//
|
|
1410
|
-
// which TLC 1.7.4 doesn't.
|
|
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.
|
|
1411
1669
|
const addFailedLiveState = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1412
1670
|
try {
|
|
1413
1671
|
liveness?.addState(index, states[index], liveSuccessors);
|
|
@@ -1426,10 +1684,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1426
1684
|
const replay = captureOutput(() => replayNext(index));
|
|
1427
1685
|
return { result: replay.result, lines: [...live.lines, ...replay.lines] };
|
|
1428
1686
|
};
|
|
1429
|
-
// TLC reports a stack overflow
|
|
1430
|
-
// behavior up to the state it expands.
|
|
1687
|
+
// TLC reports a stack overflow in the next states without a replay, up to the state it expands.
|
|
1431
1688
|
const reportNextStateOverflow = (index: number) =>
|
|
1432
|
-
createFailureResult(createStackOverflowError(), getStateTrace(index));
|
|
1689
|
+
createFailureResult(createStackOverflowError(), getStateTrace(index), { isNextState: true });
|
|
1433
1690
|
// After the trace, TLC replays the next-state relation with its call stack, printing again.
|
|
1434
1691
|
const reportNextStateFailure = (
|
|
1435
1692
|
error: unknown,
|
|
@@ -1447,7 +1704,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1447
1704
|
const expandState = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1448
1705
|
const state = states[index];
|
|
1449
1706
|
const source = stateWriter && getGraphState(state, depths[index]);
|
|
1450
|
-
const
|
|
1707
|
+
const writeUnsatisfied =
|
|
1708
|
+
source && options.dump?.constrained
|
|
1709
|
+
? (successor: Value[], conjunct: Expression, action?: SpecAction) =>
|
|
1710
|
+
stateWriter?.writeConstrained(
|
|
1711
|
+
source,
|
|
1712
|
+
getGraphState(successor, depths[index] + 1),
|
|
1713
|
+
action && getGraphAction(action),
|
|
1714
|
+
describeRange(conjunct),
|
|
1715
|
+
)
|
|
1716
|
+
: undefined;
|
|
1717
|
+
const successorCount = forEachActionSuccessor(state, writeUnsatisfied, (successor, action) => {
|
|
1451
1718
|
try {
|
|
1452
1719
|
outcome.result = visitSuccessor(index, successor, liveSuccessors, source, action);
|
|
1453
1720
|
} catch (error) {
|
|
@@ -1455,9 +1722,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1455
1722
|
outcome.result = reportNextStateOverflow(index);
|
|
1456
1723
|
return true;
|
|
1457
1724
|
}
|
|
1458
|
-
// TLC 1.7.4 reports the wrapped error without the trace, except for a failed property,
|
|
1459
|
-
//
|
|
1460
|
-
// adds the state to the behavior graph.
|
|
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.
|
|
1461
1727
|
const replay = is174
|
|
1462
1728
|
? captureOutput(() => replayNext(index))
|
|
1463
1729
|
: replayFailedNext(index, liveSuccessors);
|
|
@@ -1469,11 +1735,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1469
1735
|
);
|
|
1470
1736
|
return true;
|
|
1471
1737
|
}
|
|
1472
|
-
|
|
1473
|
-
// reports as an exception it didn't expect.
|
|
1474
|
-
const isTraceFailed = getFingerprintState(successor.state).some(
|
|
1475
|
-
(value) => getFingerprintError(value) !== undefined,
|
|
1476
|
-
);
|
|
1738
|
+
const isTraceFailed = isUnfingerprintable(successor.state);
|
|
1477
1739
|
const traceFailure =
|
|
1478
1740
|
isTraceFailed && error instanceof TlaEvaluationError
|
|
1479
1741
|
? getFailureMessage(
|
|
@@ -1507,7 +1769,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1507
1769
|
}
|
|
1508
1770
|
if (result) return result;
|
|
1509
1771
|
const addLiveState = () => {
|
|
1510
|
-
if (liveness && source && is174
|
|
1772
|
+
if (liveness && source && (is174 || options.dump?.stuttering)) {
|
|
1773
|
+
stateWriter?.writeStuttering(source);
|
|
1774
|
+
}
|
|
1511
1775
|
const accepted = liveness?.addState(index, state, liveSuccessors);
|
|
1512
1776
|
if (!liveness || !accepted) return undefined;
|
|
1513
1777
|
const steps = getPathSteps(accepted);
|
|
@@ -1524,9 +1788,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1524
1788
|
};
|
|
1525
1789
|
if (successorCount === 0 && config.checkDeadlock) {
|
|
1526
1790
|
const deadlock = reportViolation("deadlock", { name: "deadlock", ...getStateTrace(index) });
|
|
1527
|
-
// TLC's worker still adds the deadlocked state to the behavior graph
|
|
1528
|
-
//
|
|
1529
|
-
// expanded.
|
|
1791
|
+
// TLC's worker still adds the deadlocked state to the behavior graph, reports a temporal
|
|
1792
|
+
// property that violates, and then counts the state as expanded.
|
|
1530
1793
|
const live = captureOutput(() => {
|
|
1531
1794
|
try {
|
|
1532
1795
|
return { additional: addLiveState()?.violation };
|
|
@@ -1550,8 +1813,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1550
1813
|
try {
|
|
1551
1814
|
return addLiveState();
|
|
1552
1815
|
} catch (error) {
|
|
1553
|
-
// TLC 1.7.4
|
|
1554
|
-
// it didn't expect, without the trace or a call stack, and exits as for any general error.
|
|
1816
|
+
// TLC 1.7.4 reports this as an unexpected exception, without the trace or a call stack.
|
|
1555
1817
|
if (is174 && error instanceof TlaEvaluationError) {
|
|
1556
1818
|
const unexpected = new TlaEvaluationError(
|
|
1557
1819
|
`${isEvalException(error) ? UNEXPECTED_EVAL_EXCEPTION : UNEXPECTED_EXCEPTION}${error.message}`,
|
|
@@ -1562,8 +1824,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1562
1824
|
{ outDegrees: getFailureOutDegrees() },
|
|
1563
1825
|
);
|
|
1564
1826
|
}
|
|
1565
|
-
// TLC
|
|
1566
|
-
// before the error, and reports the error as one in computing next states.
|
|
1827
|
+
// TLC adds the state again for the call stack, prints it first, and blames the next states.
|
|
1567
1828
|
const replay = getReplayFailure((tracing) =>
|
|
1568
1829
|
liveness?.addState(index, state, liveSuccessors, tracing),
|
|
1569
1830
|
);
|
|
@@ -1575,7 +1836,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1575
1836
|
});
|
|
1576
1837
|
}
|
|
1577
1838
|
};
|
|
1578
|
-
// TLC's Liveness#printStutteringCounterExampleWarning.
|
|
1579
1839
|
const getStutteringWarning = () => {
|
|
1580
1840
|
const name = config.specification;
|
|
1581
1841
|
const book =
|
|
@@ -1631,9 +1891,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1631
1891
|
: createActionRecord(findSuccessorWithFingerprint(lastState, cycleStart)?.action),
|
|
1632
1892
|
);
|
|
1633
1893
|
};
|
|
1634
|
-
const isPeriodic = liveness !== undefined && options.livenessCheck
|
|
1894
|
+
const isPeriodic = liveness !== undefined && (options.livenessCheck ?? "default") === "default";
|
|
1635
1895
|
const startedAt = performance.now();
|
|
1636
|
-
const periodic = {
|
|
1896
|
+
const periodic = {
|
|
1897
|
+
at: startedAt + PERIODIC_START,
|
|
1898
|
+
size: 1,
|
|
1899
|
+
time: 0,
|
|
1900
|
+
coverageCount: Math.trunc(options.coverage ?? 0),
|
|
1901
|
+
};
|
|
1637
1902
|
const findPeriodicViolation = (expanded: number) => {
|
|
1638
1903
|
const now = performance.now();
|
|
1639
1904
|
const isGrown = (expanded - periodic.size) / periodic.size > LIVENESS_GROWTH;
|
|
@@ -1669,45 +1934,56 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1669
1934
|
if (outcome.result) return outcome.result;
|
|
1670
1935
|
outDegrees[getOutDegreeBucket()]++;
|
|
1671
1936
|
expansion.newStates = 0;
|
|
1672
|
-
// TLC
|
|
1673
|
-
// reports how far the search got.
|
|
1937
|
+
// TLC checks liveness on the graph so far, then reports how far the search got.
|
|
1674
1938
|
if ((isPeriodic || options.onProgress) && performance.now() >= periodic.at) {
|
|
1675
1939
|
periodic.at = performance.now() + PROGRESS_INTERVAL;
|
|
1676
1940
|
const lasso = isPeriodic ? findPeriodicViolation(index + 1) : undefined;
|
|
1677
1941
|
if (liveness && lasso) return reportLasso(liveness, lasso);
|
|
1678
|
-
|
|
1942
|
+
// TLC reports the coverage with every report after the first `coverage` reports since the last.
|
|
1943
|
+
const isCoverageDue = options.coverage !== undefined && periodic.coverageCount === 0;
|
|
1944
|
+
periodic.coverageCount = isCoverageDue
|
|
1945
|
+
? Math.trunc(options.coverage ?? 0)
|
|
1946
|
+
: periodic.coverageCount - 1;
|
|
1947
|
+
const progress = createResult("success");
|
|
1948
|
+
options.onProgress?.({
|
|
1949
|
+
kind: "progress",
|
|
1950
|
+
statistics: { ...progress, coverage: isCoverageDue ? progress.coverage : undefined },
|
|
1951
|
+
});
|
|
1679
1952
|
}
|
|
1680
1953
|
}
|
|
1681
1954
|
|
|
1682
1955
|
current.index = -1;
|
|
1683
1956
|
current.candidate = undefined;
|
|
1684
|
-
|
|
1957
|
+
const finalLiveness = options.livenessCheck === "off" ? undefined : liveness;
|
|
1958
|
+
if (finalLiveness) {
|
|
1685
1959
|
options.onProgress?.({
|
|
1686
1960
|
kind: "liveness-started",
|
|
1687
|
-
branches:
|
|
1961
|
+
branches: finalLiveness.branches,
|
|
1688
1962
|
isComplete: true,
|
|
1689
1963
|
states: runtime.distinctStates,
|
|
1690
1964
|
statistics: createResult("success"),
|
|
1691
1965
|
});
|
|
1692
1966
|
}
|
|
1693
|
-
const lasso =
|
|
1694
|
-
if (
|
|
1967
|
+
const lasso = finalLiveness?.findViolation();
|
|
1968
|
+
if (finalLiveness && lasso) return reportLasso(finalLiveness, lasso);
|
|
1695
1969
|
|
|
1696
1970
|
// TLC finishes the check of the temporal properties before it checks the postconditions.
|
|
1697
|
-
if (
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1971
|
+
if (finalLiveness) options.onProgress?.({ kind: "liveness-finished" });
|
|
1972
|
+
const missingPostcondition = specification.moduleOperators.find(
|
|
1973
|
+
(operator) => operator.kind === "postcondition" && operator.key === undefined,
|
|
1974
|
+
);
|
|
1975
|
+
if (missingPostcondition) {
|
|
1976
|
+
return createFailureResult(createMissingOperatorError(missingPostcondition), { trace: [] });
|
|
1977
|
+
}
|
|
1978
|
+
const postcondition = search.findPostconditionViolation();
|
|
1979
|
+
if (postcondition) {
|
|
1980
|
+
return createResult("postcondition-violation", {
|
|
1981
|
+
name: postcondition.name,
|
|
1982
|
+
message: postcondition.message,
|
|
1983
|
+
counts: postcondition.counts,
|
|
1984
|
+
trace: [],
|
|
1985
|
+
postcondition,
|
|
1986
|
+
});
|
|
1711
1987
|
}
|
|
1712
|
-
return createSuccess();
|
|
1988
|
+
return continued.status ? createResult(continued.status) : createSuccess();
|
|
1713
1989
|
};
|