tla-ts 0.0.4-dev.6dec595 → 0.0.4-dev.7714e32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -126
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/deciders.cjs +366 -0
- package/dist/deciders.js +366 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +44 -12
- package/dist/index.d.ts +44 -12
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -4
- package/dist/parallel-worker.js +1 -4
- package/dist/prove-worker.cjs +9 -0
- package/dist/prove-worker.d.cts +9 -0
- package/dist/prove-worker.d.ts +9 -0
- package/dist/prove-worker.js +9 -0
- package/dist/prove.cjs +1006 -0
- package/dist/prove.js +1006 -0
- package/dist/run.cjs +45 -0
- package/dist/run.js +45 -0
- package/dist/tlapm.cjs +10 -0
- package/dist/tlapm.js +10 -0
- package/dist/transfer.cjs +76 -92
- package/dist/transfer.js +76 -92
- package/dist/worker.cjs +21 -0
- package/dist/worker.js +21 -0
- package/package.json +21 -12
- package/src/ast.ts +2 -2
- package/src/bags.ts +22 -23
- package/src/builtins.ts +16 -8
- package/src/check.ts +131 -1154
- package/src/{cli-options.ts → cli/options.ts} +54 -9
- package/src/cli/run.ts +63 -0
- package/src/cli/shared.ts +106 -0
- package/src/cli/tlapm.ts +374 -0
- package/src/{run-cli.ts → cli/tlc.ts} +112 -718
- package/src/cli/xml-exporter.ts +221 -0
- package/src/cli.ts +1 -1
- package/src/codegen.ts +17 -15
- package/src/config.ts +5 -5
- package/src/dependencies.ts +4 -6
- package/src/environment.ts +55 -60
- package/src/errors.ts +97 -35
- package/src/evaluate.ts +109 -108
- package/src/exit-codes.ts +1 -1
- package/src/fingerprints.ts +3 -3
- package/src/index.ts +10 -0
- package/src/instances.ts +56 -46
- package/src/java-overrides.ts +79 -41
- package/src/json.ts +31 -36
- package/src/levels.ts +10 -13
- package/src/{live-check.ts → liveness-checker.ts} +169 -142
- package/src/liveness.ts +38 -34
- package/src/{obligation-action.ts → obligations/action.ts} +248 -74
- package/src/{obligation-anon.ts → obligations/anonymize.ts} +55 -57
- package/src/obligations/equality.ts +260 -0
- package/src/obligations/expression.ts +618 -0
- package/src/{obligation-format.ts → obligations/format.ts} +7 -8
- package/src/obligations/generate.ts +457 -0
- package/src/{obligations.ts → obligations/index.ts} +46 -32
- package/src/{obligation-levels.ts → obligations/levels.ts} +44 -40
- package/src/obligations/module.ts +445 -0
- package/src/obligations/normalize.ts +554 -0
- package/src/obligations/operators.ts +176 -0
- package/src/obligations/pragma.ts +195 -0
- package/src/{obligation-printer.ts → obligations/printer.ts} +65 -230
- package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
- package/src/obligations/regroup.ts +100 -0
- package/src/{obligation-generate.ts → obligations/simplify.ts} +130 -536
- package/src/{obligation-source.ts → obligations/source.ts} +172 -216
- package/src/{obligation-deref.ts → obligations/subexpression.ts} +84 -115
- package/src/obligations/substitution.ts +261 -0
- package/src/obligations/temporal.ts +321 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
- package/src/parallel-worker.ts +39 -51
- package/src/parallel.ts +39 -66
- package/src/parser.ts +67 -74
- package/src/{pcal-ast.ts → pcal/ast.ts} +2 -17
- package/src/{pcal-parse.ts → pcal/parse.ts} +28 -64
- package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +10 -39
- package/src/{pcal-translate.ts → pcal/translate.ts} +30 -109
- package/src/{pcal-validate.ts → pcal/validate.ts} +10 -20
- package/src/prover/decide-pool.ts +95 -0
- package/src/prover/deciders.ts +33 -0
- package/src/prover/first-order.ts +175 -0
- package/src/prover/isabelle/LICENSE +36 -0
- package/src/prover/isabelle/LICENSE-tlapm +26 -0
- package/src/prover/isabelle/decide.ts +44 -0
- package/src/prover/isabelle/encode.ts +445 -0
- package/src/prover/isabelle/isar/inner-syntax.ts +579 -0
- package/src/prover/isabelle/isar/method.ts +367 -0
- package/src/prover/isabelle/isar/proof.ts +28 -0
- package/src/prover/isabelle/isar/statement.ts +57 -0
- package/src/prover/isabelle/isar/theory.ts +192 -0
- package/src/prover/isabelle/isar/type-check.ts +278 -0
- package/src/prover/isabelle/provers/blast/blast.ts +258 -0
- package/src/prover/isabelle/provers/blast/branch.ts +322 -0
- package/src/prover/isabelle/provers/blast/prove.ts +347 -0
- package/src/prover/isabelle/provers/blast/rules.ts +330 -0
- package/src/prover/isabelle/provers/blast/state.ts +180 -0
- package/src/prover/isabelle/provers/blast/term.ts +546 -0
- package/src/prover/isabelle/provers/clasimp.ts +150 -0
- package/src/prover/isabelle/provers/classical.ts +389 -0
- package/src/prover/isabelle/provers/hypsubst.ts +433 -0
- package/src/prover/isabelle/pure/bicompose.ts +174 -0
- package/src/prover/isabelle/pure/consts.ts +32 -0
- package/src/prover/isabelle/pure/conv.ts +79 -0
- package/src/prover/isabelle/pure/drule.ts +264 -0
- package/src/prover/isabelle/pure/envir.ts +331 -0
- package/src/prover/isabelle/pure/goal.ts +53 -0
- package/src/prover/isabelle/pure/interrupt.ts +16 -0
- package/src/prover/isabelle/pure/list.ts +12 -0
- package/src/prover/isabelle/pure/logic.ts +330 -0
- package/src/prover/isabelle/pure/name.ts +98 -0
- package/src/prover/isabelle/pure/net.ts +215 -0
- package/src/prover/isabelle/pure/object-logic.ts +41 -0
- package/src/prover/isabelle/pure/pattern.ts +631 -0
- package/src/prover/isabelle/pure/raw-simplifier.ts +338 -0
- package/src/prover/isabelle/pure/rewriter.ts +602 -0
- package/src/prover/isabelle/pure/search.ts +68 -0
- package/src/prover/isabelle/pure/seq.ts +133 -0
- package/src/prover/isabelle/pure/simplifier.ts +106 -0
- package/src/prover/isabelle/pure/table.ts +201 -0
- package/src/prover/isabelle/pure/tactic.ts +168 -0
- package/src/prover/isabelle/pure/tactical.ts +264 -0
- package/src/prover/isabelle/pure/term-ord.ts +105 -0
- package/src/prover/isabelle/pure/term.ts +688 -0
- package/src/prover/isabelle/pure/thm.ts +783 -0
- package/src/prover/isabelle/pure/type.ts +121 -0
- package/src/prover/isabelle/pure/unify.ts +753 -0
- package/src/prover/isabelle/pure/variable.ts +25 -0
- package/src/prover/isabelle/tla/classical-setup.ts +101 -0
- package/src/prover/isabelle/tla/context.ts +74 -0
- package/src/prover/isabelle/tla/logic-data.ts +5 -0
- package/src/prover/isabelle/tla/logic.ts +215 -0
- package/src/prover/isabelle/tla/simpdata.ts +241 -0
- package/src/prover/isabelle/tools/intuitionistic.ts +132 -0
- package/src/prover/ocaml.ts +22 -0
- package/src/prover/prep/action.ts +508 -0
- package/src/prover/prep/enabled-axioms.ts +189 -0
- package/src/prover/prep/fingerprint.ts +388 -0
- package/src/prover/prep/level-comparison.ts +529 -0
- package/src/prover/prep/md5.ts +60 -0
- package/src/prover/prep/methods.ts +221 -0
- package/src/prover/prep/normalize.ts +309 -0
- package/src/prover/prove-worker.ts +22 -0
- package/src/prover/prove.ts +492 -0
- package/src/prover/ptl/decide.ts +68 -0
- package/src/prover/ptl/encode.ts +244 -0
- package/src/prover/ptl/sat.ts +151 -0
- package/src/prover/ptl/tableau.ts +276 -0
- package/src/prover/smt/axioms.ts +209 -0
- package/src/prover/smt/context.ts +108 -0
- package/src/prover/smt/data.ts +636 -0
- package/src/prover/smt/encode.ts +275 -0
- package/src/prover/smt/extensionality.ts +65 -0
- package/src/prover/smt/flatten.ts +112 -0
- package/src/prover/smt/format.ts +154 -0
- package/src/prover/smt/instances.ts +181 -0
- package/src/prover/smt/rewrite.ts +766 -0
- package/src/prover/smt/solver/act-cache.ts +265 -0
- package/src/prover/smt/solver/arith-rewriter.ts +962 -0
- package/src/prover/smt/solver/array.ts +22 -0
- package/src/prover/smt/solver/asserted-formulas.ts +469 -0
- package/src/prover/smt/solver/ast-lt.ts +157 -0
- package/src/prover/smt/solver/ast-util.ts +91 -0
- package/src/prover/smt/solver/ast.ts +1315 -0
- package/src/prover/smt/solver/auf-solver.ts +572 -0
- package/src/prover/smt/solver/case-split-queue.ts +178 -0
- package/src/prover/smt/solver/cg-table.ts +175 -0
- package/src/prover/smt/solver/clause.ts +276 -0
- package/src/prover/smt/solver/conflict-resolution.ts +343 -0
- package/src/prover/smt/solver/context.ts +1292 -0
- package/src/prover/smt/solver/ctx-simplify.ts +334 -0
- package/src/prover/smt/solver/der.ts +224 -0
- package/src/prover/smt/solver/dyn-ack.ts +141 -0
- package/src/prover/smt/solver/e-matching.ts +659 -0
- package/src/prover/smt/solver/enode.ts +259 -0
- package/src/prover/smt/solver/expr-ref.ts +21 -0
- package/src/prover/smt/solver/expr-safe-replace.ts +172 -0
- package/src/prover/smt/solver/fingerprints.ts +92 -0
- package/src/prover/smt/solver/flat-literals.ts +51 -0
- package/src/prover/smt/solver/goal.ts +138 -0
- package/src/prover/smt/solver/hash.ts +173 -0
- package/src/prover/smt/solver/hashtable.ts +166 -0
- package/src/prover/smt/solver/internalizer.ts +1381 -0
- package/src/prover/smt/solver/lbool.ts +5 -0
- package/src/prover/smt/solver/literal.ts +24 -0
- package/src/prover/smt/solver/lp/bound-propagator.ts +391 -0
- package/src/prover/smt/solver/lp/constraints.ts +78 -0
- package/src/prover/smt/solver/lp/containers.ts +296 -0
- package/src/prover/smt/solver/lp/core-solver.ts +504 -0
- package/src/prover/smt/solver/lp/cross-nested.ts +224 -0
- package/src/prover/smt/solver/lp/dep-intervals.ts +642 -0
- package/src/prover/smt/solver/lp/dependency.ts +51 -0
- package/src/prover/smt/solver/lp/dioph-eq.ts +1181 -0
- package/src/prover/smt/solver/lp/explanation.ts +46 -0
- package/src/prover/smt/solver/lp/gomory.ts +255 -0
- package/src/prover/smt/solver/lp/hnf-cutter.ts +125 -0
- package/src/prover/smt/solver/lp/hnf.ts +281 -0
- package/src/prover/smt/solver/lp/int-cube.ts +295 -0
- package/src/prover/smt/solver/lp/int-solver.ts +514 -0
- package/src/prover/smt/solver/lp/lar-solver.ts +816 -0
- package/src/prover/smt/solver/lp/lar-term.ts +62 -0
- package/src/prover/smt/solver/lp/lp-settings.ts +91 -0
- package/src/prover/smt/solver/lp/maximize-term.ts +347 -0
- package/src/prover/smt/solver/lp/nex-creator.ts +381 -0
- package/src/prover/smt/solver/lp/nex.ts +120 -0
- package/src/prover/smt/solver/lp/nla-backoff.ts +43 -0
- package/src/prover/smt/solver/lp/nla-basics.ts +398 -0
- package/src/prover/smt/solver/lp/nla-core.ts +968 -0
- package/src/prover/smt/solver/lp/nla-divisions.ts +332 -0
- package/src/prover/smt/solver/lp/nla-emonics.ts +373 -0
- package/src/prover/smt/solver/lp/nla-factorization.ts +30 -0
- package/src/prover/smt/solver/lp/nla-grobner.ts +904 -0
- package/src/prover/smt/solver/lp/nla-horner.ts +126 -0
- package/src/prover/smt/solver/lp/nla-intervals.ts +265 -0
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +715 -0
- package/src/prover/smt/solver/lp/nla-monotone.ts +59 -0
- package/src/prover/smt/solver/lp/nla-order.ts +307 -0
- package/src/prover/smt/solver/lp/nla-patcher.ts +112 -0
- package/src/prover/smt/solver/lp/nla-tangents.ts +251 -0
- package/src/prover/smt/solver/lp/nla-throttle.ts +85 -0
- package/src/prover/smt/solver/lp/nla-types.ts +124 -0
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +141 -0
- package/src/prover/smt/solver/lp/nra-solver.ts +440 -0
- package/src/prover/smt/solver/lp/numeric-pair.ts +65 -0
- package/src/prover/smt/solver/lp/pdd-interval.ts +31 -0
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +184 -0
- package/src/prover/smt/solver/lp/pdd-solver.ts +408 -0
- package/src/prover/smt/solver/lp/pdd.ts +971 -0
- package/src/prover/smt/solver/lp/random-updater.ts +138 -0
- package/src/prover/smt/solver/lp/static-matrix.ts +246 -0
- package/src/prover/smt/solver/lp/union-find.ts +96 -0
- package/src/prover/smt/solver/mam-compiler.ts +847 -0
- package/src/prover/smt/solver/mam-interpreter.ts +400 -0
- package/src/prover/smt/solver/maximize-ac-sharing.ts +118 -0
- package/src/prover/smt/solver/model-checker.ts +347 -0
- package/src/prover/smt/solver/model-evaluator.ts +262 -0
- package/src/prover/smt/solver/model-finder.ts +155 -0
- package/src/prover/smt/solver/model-generator.ts +97 -0
- package/src/prover/smt/solver/model-macro-solver.ts +728 -0
- package/src/prover/smt/solver/nlsat/algebraic.ts +1161 -0
- package/src/prover/smt/solver/nlsat/atoms.ts +238 -0
- package/src/prover/smt/solver/nlsat/evaluator.ts +303 -0
- package/src/prover/smt/solver/nlsat/explain.ts +607 -0
- package/src/prover/smt/solver/nlsat/interval-set.ts +351 -0
- package/src/prover/smt/solver/nlsat/levelwise.ts +737 -0
- package/src/prover/smt/solver/nlsat/mpbq.ts +161 -0
- package/src/prover/smt/solver/nlsat/polynomial.ts +1722 -0
- package/src/prover/smt/solver/nlsat/solver.ts +911 -0
- package/src/prover/smt/solver/nlsat/types.ts +43 -0
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
- package/src/prover/smt/solver/nlsat/upolynomial.ts +996 -0
- package/src/prover/smt/solver/nnf.ts +469 -0
- package/src/prover/smt/solver/pattern-inference.ts +351 -0
- package/src/prover/smt/solver/poly-rewriter.ts +477 -0
- package/src/prover/smt/solver/propagate-values.ts +83 -0
- package/src/prover/smt/solver/proto-model.ts +551 -0
- package/src/prover/smt/solver/pull-quant.ts +139 -0
- package/src/prover/smt/solver/qe-lite-der.ts +526 -0
- package/src/prover/smt/solver/qe-lite-fm.ts +576 -0
- package/src/prover/smt/solver/qe-lite.ts +381 -0
- package/src/prover/smt/solver/qi-queue.ts +362 -0
- package/src/prover/smt/solver/quant-tactics.ts +117 -0
- package/src/prover/smt/solver/quantifier-analyzer.ts +562 -0
- package/src/prover/smt/solver/quantifier-manager.ts +186 -0
- package/src/prover/smt/solver/random-gen.ts +10 -0
- package/src/prover/smt/solver/rational.ts +165 -0
- package/src/prover/smt/solver/ref-vector.ts +62 -0
- package/src/prover/smt/solver/relevancy.ts +247 -0
- package/src/prover/smt/solver/rewriter-tpl.ts +1159 -0
- package/src/prover/smt/solver/rewriter.ts +843 -0
- package/src/prover/smt/solver/rlimit.ts +79 -0
- package/src/prover/smt/solver/smtlib-parser.ts +526 -0
- package/src/prover/smt/solver/solver.ts +71 -0
- package/src/prover/smt/solver/sort.ts +35 -0
- package/src/prover/smt/solver/sticky-generations.ts +69 -0
- package/src/prover/smt/solver/theory-lra-axioms.ts +340 -0
- package/src/prover/smt/solver/theory-lra-bounds.ts +226 -0
- package/src/prover/smt/solver/theory-lra-final-check.ts +252 -0
- package/src/prover/smt/solver/theory-lra-internalize.ts +476 -0
- package/src/prover/smt/solver/theory-lra-model.ts +243 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +405 -0
- package/src/prover/smt/solver/theory-lra-state.ts +43 -0
- package/src/prover/smt/solver/theory-lra.ts +56 -0
- package/src/prover/smt/solver/var-subst.ts +258 -0
- package/src/prover/smt/solver/z3-license.txt +10 -0
- package/src/prover/smt/table.ts +170 -0
- package/src/prover/tlapm/cache.ts +236 -0
- package/src/prover/tlapm/ocaml-marshal.ts +166 -0
- package/src/prover/tlapm/tlapm.ts +96 -0
- package/src/prover/tlaps-module.ts +510 -0
- package/src/prover/verdict.ts +13 -0
- package/src/prover/zenon/LICENSE +32 -0
- package/src/prover/zenon/check/check.ts +105 -0
- package/src/prover/zenon/check/definitions.ts +144 -0
- package/src/prover/zenon/check/equality.ts +182 -0
- package/src/prover/zenon/check/functions.ts +62 -0
- package/src/prover/zenon/check/keys.ts +125 -0
- package/src/prover/zenon/check/propositional.ts +104 -0
- package/src/prover/zenon/check/records.ts +188 -0
- package/src/prover/zenon/check/relations.ts +121 -0
- package/src/prover/zenon/check/rewrites.ts +224 -0
- package/src/prover/zenon/check/sets.ts +302 -0
- package/src/prover/zenon/check/terms.ts +127 -0
- package/src/prover/zenon/check/tla.ts +126 -0
- package/src/prover/zenon/decide.ts +107 -0
- package/src/prover/zenon/encode.ts +378 -0
- package/src/prover/zenon/eqrel.ts +300 -0
- package/src/prover/zenon/equality-rules.ts +435 -0
- package/src/prover/zenon/expr.ts +551 -0
- package/src/prover/zenon/index-table.ts +350 -0
- package/src/prover/zenon/isar-case.ts +513 -0
- package/src/prover/zenon/isar.ts +1249 -0
- package/src/prover/zenon/limits.ts +15 -0
- package/src/prover/zenon/llproof.ts +173 -0
- package/src/prover/zenon/mltoll.ts +1566 -0
- package/src/prover/zenon/node.ts +297 -0
- package/src/prover/zenon/ocaml.ts +169 -0
- package/src/prover/zenon/parse.ts +247 -0
- package/src/prover/zenon/phrase.ts +191 -0
- package/src/prover/zenon/proof.ts +198 -0
- package/src/prover/zenon/propositional-rules.ts +387 -0
- package/src/prover/zenon/rules.ts +94 -0
- package/src/prover/zenon/search.ts +288 -0
- package/src/prover/zenon/tla/functions.ts +151 -0
- package/src/prover/zenon/tla/llproof.ts +480 -0
- package/src/prover/zenon/tla/records.ts +225 -0
- package/src/prover/zenon/tla/rewrites.ts +447 -0
- package/src/prover/zenon/tla/sets.ts +304 -0
- package/src/prover/zenon/tla/terms.ts +162 -0
- package/src/prover/zenon/tla/tla.ts +506 -0
- package/src/randomization.ts +19 -24
- package/src/resolve.ts +15 -22
- package/src/runtime.ts +8 -8
- package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
- package/src/{sany-generator.ts → sany/generator.ts} +38 -55
- package/src/{sany-levels.ts → sany/levels.ts} +45 -48
- package/src/{sany-lexer.ts → sany/lexer.ts} +2 -3
- package/src/{sany-linter.ts → sany/linter.ts} +1 -1
- package/src/{sany-modules.ts → sany/modules.ts} +2 -2
- package/src/{sany-nodes.ts → sany/nodes.ts} +2 -2
- package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
- package/src/{sany-report.ts → sany/report.ts} +16 -17
- package/src/{sany-selectors.ts → sany/selectors.ts} +3 -5
- package/src/{sany-source.ts → sany/source.ts} +6 -7
- package/src/{sany-xml.ts → sany/xml.ts} +5 -6
- package/src/search.ts +969 -0
- package/src/spec-description.ts +26 -20
- package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
- package/src/standard-modules.ts +16 -20
- package/src/state-graph.ts +9 -8
- package/src/substitution-levels.ts +2 -2
- package/src/successors.ts +16 -19
- package/src/symmetry.ts +1 -1
- package/src/tableau.ts +6 -7
- package/src/tlc/fingerprint.ts +214 -0
- package/src/{tlc-messages.ts → tlc/messages.ts} +119 -7
- package/src/{tlc-order.ts → tlc/order.ts} +7 -7
- package/src/{tlc-random.ts → tlc/random.ts} +3 -213
- package/src/{tlc-replay.ts → tlc/replay.ts} +40 -36
- package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
- package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +30 -25
- package/src/transfer.ts +32 -32
- package/src/values.ts +80 -70
- package/src/worker.ts +62 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
- package/dist/run-cli.cjs +0 -55
- package/dist/run-cli.js +0 -55
- package/src/canonical.ts +0 -40
- package/src/obligation-expression.ts +0 -1060
- package/src/obligation-module.ts +0 -1042
- package/src/standard-ranges.ts +0 -116
- package/src/value-sources.ts +0 -29
- /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
- /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
- /package/src/{tlc-version.ts → tlc/version.ts} +0 -0
package/src/check.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
isLocallyResolved,
|
|
4
|
-
type Assumption,
|
|
5
|
-
type Definition,
|
|
6
|
-
type Expression,
|
|
7
|
-
type SourceLocation,
|
|
8
|
-
} from "./ast";
|
|
9
|
-
import { parseConfig, type ConfigValue, type ModelConfig } from "./config";
|
|
10
|
-
import { getReadVariables } from "./dependencies";
|
|
1
|
+
import type { Expression } from "./ast";
|
|
2
|
+
import { parseConfig, type ModelConfig } from "./config";
|
|
11
3
|
import { createEnvironment } from "./environment";
|
|
12
4
|
import {
|
|
5
|
+
createStackOverflowError,
|
|
13
6
|
getErrorExitCode,
|
|
14
7
|
isStackOverflow,
|
|
15
8
|
TlaConfigError,
|
|
@@ -18,44 +11,37 @@ import {
|
|
|
18
11
|
TlaIncompleteSuccessorError,
|
|
19
12
|
TlaModuleError,
|
|
20
13
|
TlaStackOverflowError,
|
|
21
|
-
|
|
14
|
+
UNEXPECTED_EVAL_EXCEPTION,
|
|
22
15
|
UNEXPECTED_EXCEPTION,
|
|
23
16
|
} from "./errors";
|
|
24
|
-
import type { JavaOverride } from "./java-overrides";
|
|
25
|
-
import { EXIT_STATUS, getExitCode, setExitCode, withLivenessExitCode } from "./exit-codes";
|
|
26
17
|
import {
|
|
27
|
-
describeNode,
|
|
28
|
-
describeRange,
|
|
29
18
|
createTracingEnvironment,
|
|
30
19
|
evaluate,
|
|
31
|
-
evaluateStartupDefinitions,
|
|
32
|
-
expectBoolean,
|
|
33
20
|
formatRange,
|
|
34
21
|
getDefinition,
|
|
35
|
-
isConstantLevel,
|
|
36
22
|
isImpure,
|
|
37
23
|
type CallStack,
|
|
38
|
-
type Context,
|
|
39
24
|
type Environment,
|
|
40
25
|
type FingerprintFailure,
|
|
41
|
-
type Scope,
|
|
42
26
|
} from "./evaluate";
|
|
27
|
+
import { EXIT_STATUS, getExitCode, setExitCode, withLivenessExitCode } from "./exit-codes";
|
|
28
|
+
import type { JavaOverride } from "./java-overrides";
|
|
43
29
|
import {
|
|
44
30
|
createLivenessChecker,
|
|
45
31
|
type Lasso,
|
|
46
32
|
type LivenessChecker,
|
|
47
33
|
type LiveSuccessor,
|
|
48
|
-
} from "./
|
|
49
|
-
import { expandTemporal, getLevel, type ScopedExpression, type TemporalProperty } from "./liveness";
|
|
50
|
-
import { ACTION_LEVEL, createLevelAnalyzer, TEMPORAL_LEVEL } from "./levels";
|
|
51
|
-
import { prettyPrint } from "./pretty-print";
|
|
34
|
+
} from "./liveness-checker";
|
|
52
35
|
import {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
36
|
+
createIdentifier,
|
|
37
|
+
createSearch,
|
|
38
|
+
findAssumptionViolation,
|
|
39
|
+
getConfigDefinition,
|
|
40
|
+
getContext,
|
|
41
|
+
reportInitialStatesProgress,
|
|
42
|
+
reportStartup,
|
|
43
|
+
withNextStateExitCode,
|
|
44
|
+
} from "./search";
|
|
59
45
|
import {
|
|
60
46
|
getActionLabel,
|
|
61
47
|
getActionSignature,
|
|
@@ -71,34 +57,40 @@ import {
|
|
|
71
57
|
type StateDump,
|
|
72
58
|
type StateWriter,
|
|
73
59
|
} from "./state-graph";
|
|
74
|
-
import {
|
|
75
|
-
|
|
60
|
+
import {
|
|
61
|
+
forEachInitialState,
|
|
62
|
+
forEachSuccessor,
|
|
63
|
+
getInitialStates,
|
|
64
|
+
getSuccessors,
|
|
65
|
+
type Successor,
|
|
66
|
+
} from "./successors";
|
|
76
67
|
import {
|
|
77
68
|
formatNestedMessage,
|
|
78
69
|
getCodedMessage,
|
|
70
|
+
getFailureMessage,
|
|
71
|
+
getWrappedException,
|
|
79
72
|
isEvalException,
|
|
73
|
+
isHeadedError,
|
|
80
74
|
MESSAGE_CODE,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
import {
|
|
85
|
-
import {
|
|
86
|
-
import {
|
|
87
|
-
import { createActionRecord, createCounterExample } from "./tlc-
|
|
88
|
-
import {
|
|
89
|
-
import type { TlcVersion } from "./tlc-version";
|
|
75
|
+
withUnexpectedException,
|
|
76
|
+
type FailureMessage,
|
|
77
|
+
} from "./tlc/messages";
|
|
78
|
+
import { getTlcStringOrder, getTlcVariableOrder } from "./tlc/order";
|
|
79
|
+
import { replayInitialStates, replaySuccessors } from "./tlc/replay";
|
|
80
|
+
import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc/summary";
|
|
81
|
+
import { createActionRecord, createCounterExample } from "./tlc/tlcext-operators";
|
|
82
|
+
import type { TlcVersion } from "./tlc/version";
|
|
90
83
|
import {
|
|
91
84
|
combineHash,
|
|
85
|
+
createCanonicalizer,
|
|
92
86
|
createModelValue,
|
|
93
87
|
formatState,
|
|
94
|
-
formatValue,
|
|
95
|
-
getHeldValues,
|
|
96
88
|
getFingerprintError,
|
|
97
|
-
|
|
89
|
+
getHeldValues,
|
|
98
90
|
getValueHash,
|
|
99
91
|
isFunctionValue,
|
|
100
92
|
isSameValue,
|
|
101
|
-
|
|
93
|
+
markFingerprinted,
|
|
102
94
|
setStringOrder,
|
|
103
95
|
setValueVersion,
|
|
104
96
|
toFiniteFunction,
|
|
@@ -151,11 +143,7 @@ export interface InitialStateViolation {
|
|
|
151
143
|
// A line the spec prints, or what TLC reports as it replays the initial states.
|
|
152
144
|
export type OutputLine = string | InitialStatesProgress | InitialStateViolation;
|
|
153
145
|
|
|
154
|
-
// The
|
|
155
|
-
// property that is a state formula, finds the branches of the temporal properties, computes the
|
|
156
|
-
// initial states, reporting each time their count reaches a power of two, reports how far the
|
|
157
|
-
// search got 3 seconds after it starts and every minute after, and checks the temporal properties
|
|
158
|
-
// on the state graph so far at those times and on the complete state graph at the end.
|
|
146
|
+
// The points of the search at which TLC prints a message.
|
|
159
147
|
export type CheckProgress =
|
|
160
148
|
| { kind: "parsed" }
|
|
161
149
|
| { kind: "constant-level-invariant"; name: string }
|
|
@@ -225,7 +213,7 @@ export interface Violation {
|
|
|
225
213
|
warning?: { code: number; text: string };
|
|
226
214
|
}
|
|
227
215
|
|
|
228
|
-
interface Postcondition {
|
|
216
|
+
export interface Postcondition {
|
|
229
217
|
name: string;
|
|
230
218
|
// TLC's message code.
|
|
231
219
|
code: number;
|
|
@@ -327,190 +315,9 @@ const appendTraceOutput = <Traced extends Behavior>(behavior: Traced, lines: Out
|
|
|
327
315
|
traceOutput: [...(behavior.traceOutput ?? []), ...lines],
|
|
328
316
|
});
|
|
329
317
|
|
|
330
|
-
interface NamedExpression {
|
|
331
|
-
name: string;
|
|
332
|
-
expression: Expression;
|
|
333
|
-
scope: Scope | undefined;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
interface StateCheck extends NamedExpression {
|
|
337
|
-
variables: number[] | undefined;
|
|
338
|
-
membership: Membership | undefined;
|
|
339
|
-
// The whole predicate that TLC evaluates for the check, of which the expression is a conjunct.
|
|
340
|
-
predicate: Expression;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// A conjunct `x \in S` whose S reads no variables.
|
|
344
|
-
interface Membership {
|
|
345
|
-
variable: number;
|
|
346
|
-
set: Expression;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
interface ActionProperty {
|
|
350
|
-
name: string;
|
|
351
|
-
box: Expression;
|
|
352
|
-
action: Expression;
|
|
353
|
-
subscript: Expression;
|
|
354
|
-
scope: Scope | undefined;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
interface Specification {
|
|
358
|
-
init: Expression | undefined;
|
|
359
|
-
next: Expression | undefined;
|
|
360
|
-
scope: Scope | undefined;
|
|
361
|
-
temporals: ScopedExpression[];
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
interface Properties {
|
|
365
|
-
initialPredicates: NamedExpression[];
|
|
366
|
-
invariants: NamedExpression[];
|
|
367
|
-
actionProperties: ActionProperty[];
|
|
368
|
-
liveness: TemporalProperty[];
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
const START: SourceLocation = { line: 0, column: 0 };
|
|
372
|
-
|
|
373
318
|
const INITIAL_RECOVERY_FAILURE = "Failed to recover the initial state from its fingerprint.";
|
|
374
319
|
const NEXT_RECOVERY_FAILURE = "Failed to recover the next state from its fingerprint.";
|
|
375
320
|
|
|
376
|
-
const createIdentifier = (name: string): Expression => ({
|
|
377
|
-
kind: "Identifier",
|
|
378
|
-
name,
|
|
379
|
-
location: START,
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
// TLC leaves the kind out when it rejects arguments to the specification or a property.
|
|
383
|
-
const UNNAMED_ARGUMENT_KINDS = new Set(["name", "property"]);
|
|
384
|
-
|
|
385
|
-
// TLC checks liveness on the graph so far 3 seconds into the search and then every minute, once
|
|
386
|
-
// the graph has grown by a tenth and liveness checking has taken at most a fifth of the time.
|
|
387
|
-
const PERIODIC_START = 3000;
|
|
388
|
-
const PROGRESS_INTERVAL = 60_000;
|
|
389
|
-
const LIVENESS_GROWTH = 0.1;
|
|
390
|
-
const LIVENESS_RATIO = 0.2;
|
|
391
|
-
|
|
392
|
-
const getConfigOperator = (kind: string, name: string, environment: Environment) => {
|
|
393
|
-
const definition = getDefinition(name, environment);
|
|
394
|
-
if (!definition) {
|
|
395
|
-
throw new TlaConfigError(
|
|
396
|
-
`The ${kind} ${name} specified in the configuration file\nis not defined in the specification.`,
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
if (definition.kind === "Operator" && definition.params.length > 0) {
|
|
400
|
-
throw new TlaConfigError(
|
|
401
|
-
UNNAMED_ARGUMENT_KINDS.has(kind)
|
|
402
|
-
? `TLC requires ${name} not to take any argument.`
|
|
403
|
-
: `TLC requires ${kind} not to take any argument, but one was given: ${name}`,
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
return definition;
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
// TLC evaluates every constant definition before it reads the configuration. It keeps a literal
|
|
410
|
-
// number or string, and a definition that fails to evaluate, as an operator.
|
|
411
|
-
const getConstantValue = (name: string, definition: Definition, environment: Environment) => {
|
|
412
|
-
if (!isConstantLevel(definition, environment)) return undefined;
|
|
413
|
-
if (definition.body.kind === "Number" || definition.body.kind === "String") return undefined;
|
|
414
|
-
try {
|
|
415
|
-
return evaluate(createIdentifier(name), getContext(environment, undefined, undefined));
|
|
416
|
-
} catch (error) {
|
|
417
|
-
// TLC swallows whatever the definition throws, a stack overflow included.
|
|
418
|
-
if (error instanceof TlaEvaluationError || isStackOverflow(error)) return undefined;
|
|
419
|
-
throw error;
|
|
420
|
-
}
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
// TLC takes for an operator only a definition it hasn't replaced with its value.
|
|
424
|
-
const getConfigDefinition = (kind: string, name: string, environment: Environment) => {
|
|
425
|
-
const definition = getConfigOperator(kind, name, environment);
|
|
426
|
-
if (getConstantValue(name, definition, environment) !== undefined) {
|
|
427
|
-
throw new TlaConfigError(`The ${kind} ${name} cannot be a constant.`);
|
|
428
|
-
}
|
|
429
|
-
return definition;
|
|
430
|
-
};
|
|
431
|
-
|
|
432
|
-
// TLC also takes a constant that the configuration assigns a value, which must be TRUE.
|
|
433
|
-
const getConfigPredicate = (kind: string, name: string, environment: Environment) => {
|
|
434
|
-
const definition = environment.constants.has(name)
|
|
435
|
-
? undefined
|
|
436
|
-
: getConfigOperator(kind, name, environment);
|
|
437
|
-
const value = definition
|
|
438
|
-
? getConstantValue(name, definition, environment)
|
|
439
|
-
: environment.constants.get(name);
|
|
440
|
-
if (value !== undefined && value !== true) {
|
|
441
|
-
throw new TlaConfigError(`The ${kind} of ${name} is equal to ${formatValue(value)}`);
|
|
442
|
-
}
|
|
443
|
-
return value === undefined ? definition : undefined;
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
// TLC reports how many initial states it has computed each time the count is a power of two.
|
|
447
|
-
export const reportInitialStatesProgress = (
|
|
448
|
-
count: number,
|
|
449
|
-
onProgress: ((progress: InitialStatesProgress) => void) | undefined,
|
|
450
|
-
) => {
|
|
451
|
-
if (count > 1 && (count & (count - 1)) === 0) {
|
|
452
|
-
onProgress?.({ kind: "initial-states-progress", count });
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
// What TLC does once SANY is done: it computes the constant definitions, then warns about each
|
|
457
|
-
// invariant that is a true constant formula, which it doesn't check. TLC prints each distinct
|
|
458
|
-
// warning once.
|
|
459
|
-
export const reportStartup = (
|
|
460
|
-
specification: {
|
|
461
|
-
environment: Environment;
|
|
462
|
-
startupDefinitions: Definition[];
|
|
463
|
-
javaOverrides: JavaOverride[];
|
|
464
|
-
},
|
|
465
|
-
config: ModelConfig,
|
|
466
|
-
onProgress: CheckOptions["onProgress"],
|
|
467
|
-
) => {
|
|
468
|
-
const environment = specification.environment;
|
|
469
|
-
const warned = new Set<string>();
|
|
470
|
-
environment.runtime.warn = (code, text) => {
|
|
471
|
-
if (warned.has(text)) return;
|
|
472
|
-
warned.add(text);
|
|
473
|
-
onProgress?.({ kind: "warning", code, text });
|
|
474
|
-
};
|
|
475
|
-
onProgress?.({ kind: "parsed" });
|
|
476
|
-
// TLC loads the classes of the modules before it computes the constant definitions.
|
|
477
|
-
specification.javaOverrides.forEach((override) =>
|
|
478
|
-
onProgress?.({ kind: "java-override", ...override }),
|
|
479
|
-
);
|
|
480
|
-
evaluateStartupDefinitions(specification.startupDefinitions, environment);
|
|
481
|
-
config.invariants.forEach((name) => {
|
|
482
|
-
if (!getConfigPredicate("invariant", name, environment)) {
|
|
483
|
-
onProgress?.({ kind: "constant-level-invariant", name });
|
|
484
|
-
}
|
|
485
|
-
});
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
const getInvariants = (names: string[], environment: Environment) => {
|
|
489
|
-
const analyzer = createLevelAnalyzer({
|
|
490
|
-
constants: new Set(environment.constants.keys()),
|
|
491
|
-
variables: new Set(environment.variables),
|
|
492
|
-
getDefinition: (name) => getDefinition(name, environment),
|
|
493
|
-
});
|
|
494
|
-
return names.flatMap((name) => {
|
|
495
|
-
const definition = getConfigPredicate("invariant", name, environment);
|
|
496
|
-
if (!definition) return [];
|
|
497
|
-
const levels = analyzer.analyzeDefinition(definition, new Map());
|
|
498
|
-
if (levels.level >= ACTION_LEVEL) {
|
|
499
|
-
const note =
|
|
500
|
-
levels.params.size === 0
|
|
501
|
-
? ""
|
|
502
|
-
: "\nNote that a bug can cause TLC to incorrectly report this error.\nIf you believe your TLA+ or PlusCal specification to be correct,\nplease check if this bug described in LevelNode.java starting at line 590ff affects you.";
|
|
503
|
-
throw setExitCode(
|
|
504
|
-
new TlaConfigError(
|
|
505
|
-
`The invariant ${name} is not a state predicate (one with no primes or temporal operators).${note}`,
|
|
506
|
-
),
|
|
507
|
-
EXIT_STATUS.safetyEvaluationFailure,
|
|
508
|
-
);
|
|
509
|
-
}
|
|
510
|
-
return [{ name, expression: createIdentifier(name), scope: undefined }];
|
|
511
|
-
});
|
|
512
|
-
};
|
|
513
|
-
|
|
514
321
|
const toAliasRecord = (value: Value, fieldOrder: string[]) => {
|
|
515
322
|
if (!isFunctionValue(value)) return undefined;
|
|
516
323
|
const record = toFiniteFunction(value);
|
|
@@ -524,747 +331,6 @@ const toAliasRecord = (value: Value, fieldOrder: string[]) => {
|
|
|
524
331
|
);
|
|
525
332
|
};
|
|
526
333
|
|
|
527
|
-
const getConjuncts = (expression: Expression, environment: Environment): Expression[] => {
|
|
528
|
-
if (expression.kind === "And")
|
|
529
|
-
return expression.operands.flatMap((operand) => getConjuncts(operand, environment));
|
|
530
|
-
if (expression.kind === "Identifier" && !environment.constants.has(expression.name)) {
|
|
531
|
-
const definition = getDefinition(expression.name, environment);
|
|
532
|
-
if (definition?.kind === "Operator" && definition.params.length === 0) {
|
|
533
|
-
return getConjuncts(definition.body, environment);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
return [expression];
|
|
537
|
-
};
|
|
538
|
-
|
|
539
|
-
const isConstantTrue = (item: ScopedExpression, environment: Environment, usage: string) => {
|
|
540
|
-
const conjunct = item.expression;
|
|
541
|
-
if (conjunct.kind !== "Identifier" || getLevel(conjunct, item.scope, environment) > 0) {
|
|
542
|
-
return false;
|
|
543
|
-
}
|
|
544
|
-
const value = evaluate(conjunct, getContext(environment, undefined, undefined, item.scope));
|
|
545
|
-
if (value === false) {
|
|
546
|
-
throw new TlaConfigError(`The spec is trivially false because ${conjunct.name} is false.`);
|
|
547
|
-
}
|
|
548
|
-
if (value !== true) {
|
|
549
|
-
throw new TlaConfigError(
|
|
550
|
-
`The operator ${conjunct.name}, which equals ${formatValue(value)},\ncannot be used as a ${usage}`,
|
|
551
|
-
);
|
|
552
|
-
}
|
|
553
|
-
return true;
|
|
554
|
-
};
|
|
555
|
-
|
|
556
|
-
const getSpecification = (config: ModelConfig, environment: Environment): Specification => {
|
|
557
|
-
if (config.specification === undefined) {
|
|
558
|
-
const getOperator = (name: string | undefined, description: string) => {
|
|
559
|
-
if (name === undefined) return undefined;
|
|
560
|
-
getConfigDefinition(description, name, environment);
|
|
561
|
-
return createIdentifier(name);
|
|
562
|
-
};
|
|
563
|
-
return {
|
|
564
|
-
init: getOperator(config.init, "initial predicate"),
|
|
565
|
-
next: getOperator(config.next, "next state action"),
|
|
566
|
-
scope: undefined,
|
|
567
|
-
temporals: [],
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
if (config.init !== undefined || config.next !== undefined) {
|
|
571
|
-
throw new TlaConfigError(
|
|
572
|
-
"The configuration file cannot specify both INIT/NEXT and SPECIFICATION fields.",
|
|
573
|
-
);
|
|
574
|
-
}
|
|
575
|
-
const initConjuncts: ScopedExpression[] = [];
|
|
576
|
-
const nextActions: ScopedExpression[] = [];
|
|
577
|
-
const temporals: ScopedExpression[] = [];
|
|
578
|
-
const definition = getConfigOperator("name", config.specification, environment);
|
|
579
|
-
const value = getConstantValue(config.specification, definition, environment);
|
|
580
|
-
if (value !== undefined) {
|
|
581
|
-
throw new TlaConfigError(
|
|
582
|
-
`The value of ${config.specification} is equal to ${formatValue(value)}`,
|
|
583
|
-
);
|
|
584
|
-
}
|
|
585
|
-
expandTemporal(definition.body, undefined, environment, false).forEach((item) => {
|
|
586
|
-
const conjunct = item.expression;
|
|
587
|
-
if (isConstantTrue(item, environment, "spec")) return;
|
|
588
|
-
if (conjunct.kind === "UnboundedQuantifier" && conjunct.isTemporal) {
|
|
589
|
-
throw setExitCode(
|
|
590
|
-
new TlaConfigError(
|
|
591
|
-
"TLC does not support temporal existential, nor universal, quantification over state variables.",
|
|
592
|
-
),
|
|
593
|
-
EXIT_STATUS.error,
|
|
594
|
-
);
|
|
595
|
-
}
|
|
596
|
-
if (conjunct.kind === "Always" && conjunct.expression.kind === "BoxAction") {
|
|
597
|
-
nextActions.push({ expression: conjunct.expression.action, scope: item.scope });
|
|
598
|
-
return;
|
|
599
|
-
}
|
|
600
|
-
if (
|
|
601
|
-
conjunct.kind === "Always" &&
|
|
602
|
-
getLevel(conjunct.expression, item.scope, environment) < ACTION_LEVEL
|
|
603
|
-
) {
|
|
604
|
-
// TLC accepts the spec and fails when it builds the tableau of the temporal formulas.
|
|
605
|
-
throw setExitCode(
|
|
606
|
-
new TlaEvaluationError(
|
|
607
|
-
`TLC cannot handle the temporal formula ${describeRange(conjunct.expression)}`,
|
|
608
|
-
),
|
|
609
|
-
EXIT_STATUS.error,
|
|
610
|
-
);
|
|
611
|
-
}
|
|
612
|
-
const level = getLevel(conjunct, item.scope, environment);
|
|
613
|
-
if (level === TEMPORAL_LEVEL) {
|
|
614
|
-
temporals.push(item);
|
|
615
|
-
return;
|
|
616
|
-
}
|
|
617
|
-
if (level === ACTION_LEVEL) {
|
|
618
|
-
throw new TlaConfigError(
|
|
619
|
-
`TLC cannot handle the action-level conjunct of the specification ${config.specification}`,
|
|
620
|
-
);
|
|
621
|
-
}
|
|
622
|
-
initConjuncts.push(item);
|
|
623
|
-
});
|
|
624
|
-
if (nextActions.length > 1) {
|
|
625
|
-
throw new TlaConfigError(
|
|
626
|
-
`The specification ${config.specification} must contain at most one [][Next]_vars`,
|
|
627
|
-
);
|
|
628
|
-
}
|
|
629
|
-
const items = [...initConjuncts, ...nextActions];
|
|
630
|
-
const getName = (index: number) => `$specification${index}`;
|
|
631
|
-
const scope = items.reduce<Scope | undefined>(
|
|
632
|
-
(parent, item, index) =>
|
|
633
|
-
item.scope === undefined
|
|
634
|
-
? parent
|
|
635
|
-
: {
|
|
636
|
-
name: getName(index),
|
|
637
|
-
binding: {
|
|
638
|
-
kind: "Thunk",
|
|
639
|
-
expression: item.expression,
|
|
640
|
-
scope: item.scope,
|
|
641
|
-
state: undefined,
|
|
642
|
-
next: undefined,
|
|
643
|
-
cache: undefined,
|
|
644
|
-
isStreamed: false,
|
|
645
|
-
},
|
|
646
|
-
parent,
|
|
647
|
-
},
|
|
648
|
-
undefined,
|
|
649
|
-
);
|
|
650
|
-
const getReference = (item: ScopedExpression, index: number): Expression =>
|
|
651
|
-
item.scope === undefined
|
|
652
|
-
? item.expression
|
|
653
|
-
: {
|
|
654
|
-
kind: "Identifier",
|
|
655
|
-
name: getName(index),
|
|
656
|
-
location: item.expression.location,
|
|
657
|
-
resolution: { kind: "Local" },
|
|
658
|
-
};
|
|
659
|
-
return {
|
|
660
|
-
init:
|
|
661
|
-
initConjuncts.length === 0
|
|
662
|
-
? undefined
|
|
663
|
-
: { kind: "And", operands: initConjuncts.map(getReference), location: START },
|
|
664
|
-
next: nextActions.length === 0 ? undefined : getReference(nextActions[0], initConjuncts.length),
|
|
665
|
-
scope,
|
|
666
|
-
temporals,
|
|
667
|
-
};
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
const getProperties = (
|
|
671
|
-
config: ModelConfig,
|
|
672
|
-
environment: Environment,
|
|
673
|
-
onProgress: CheckOptions["onProgress"],
|
|
674
|
-
): Properties => {
|
|
675
|
-
const properties: Properties = {
|
|
676
|
-
initialPredicates: [],
|
|
677
|
-
invariants: [],
|
|
678
|
-
actionProperties: [],
|
|
679
|
-
liveness: [],
|
|
680
|
-
};
|
|
681
|
-
config.properties.forEach((name) => {
|
|
682
|
-
const definition = getConfigPredicate("property", name, environment);
|
|
683
|
-
if (!definition) return;
|
|
684
|
-
// TLC checks a property that is a state formula only on the initial states, so it warns about
|
|
685
|
-
// one as it processes the property, before the constraints.
|
|
686
|
-
if (getLevel(definition.body, undefined, environment) === 1) {
|
|
687
|
-
onProgress?.({ kind: "state-level-property", name });
|
|
688
|
-
}
|
|
689
|
-
// TLC 1.7.4 expands a property as it does a specification, so it doesn't unroll one that
|
|
690
|
-
// quantifies over a constant set.
|
|
691
|
-
const isProperty = environment.runtime.version !== "1.7.4";
|
|
692
|
-
expandTemporal(definition.body, undefined, environment, isProperty).forEach((item) => {
|
|
693
|
-
const conjunct = item.expression;
|
|
694
|
-
if (isConstantTrue(item, environment, "property")) return;
|
|
695
|
-
const partName = item.name ?? name;
|
|
696
|
-
if (conjunct.kind === "Always" && conjunct.expression.kind === "BoxAction") {
|
|
697
|
-
properties.actionProperties.push({
|
|
698
|
-
name: partName,
|
|
699
|
-
box: conjunct.expression,
|
|
700
|
-
action: conjunct.expression.action,
|
|
701
|
-
subscript: conjunct.expression.subscript,
|
|
702
|
-
scope: item.scope,
|
|
703
|
-
});
|
|
704
|
-
return;
|
|
705
|
-
}
|
|
706
|
-
if (
|
|
707
|
-
conjunct.kind === "Always" &&
|
|
708
|
-
getLevel(conjunct.expression, item.scope, environment) <= 1
|
|
709
|
-
) {
|
|
710
|
-
// TLC names the invariant by the operator the property asserts always holds, when it
|
|
711
|
-
// applies the operator to no arguments. The name of an operator another module defines
|
|
712
|
-
// resolves to its key, so the name comes from its definition.
|
|
713
|
-
const body = conjunct.expression;
|
|
714
|
-
const operator =
|
|
715
|
-
body.kind === "Identifier" && !isLocallyResolved(body)
|
|
716
|
-
? getDefinition(body.name, environment)
|
|
717
|
-
: undefined;
|
|
718
|
-
properties.invariants.push({
|
|
719
|
-
name: operator?.name ?? (body.kind === "Identifier" ? body.name : partName),
|
|
720
|
-
expression: body,
|
|
721
|
-
scope: item.scope,
|
|
722
|
-
});
|
|
723
|
-
return;
|
|
724
|
-
}
|
|
725
|
-
const level = getLevel(conjunct, item.scope, environment);
|
|
726
|
-
if (level < ACTION_LEVEL) {
|
|
727
|
-
properties.initialPredicates.push({
|
|
728
|
-
name: partName,
|
|
729
|
-
expression: conjunct,
|
|
730
|
-
scope: item.scope,
|
|
731
|
-
});
|
|
732
|
-
return;
|
|
733
|
-
}
|
|
734
|
-
if (level === ACTION_LEVEL) {
|
|
735
|
-
throw new TlaConfigError(`The property ${name} is an action-level formula`);
|
|
736
|
-
}
|
|
737
|
-
properties.liveness.push({ name, expression: conjunct, scope: item.scope });
|
|
738
|
-
});
|
|
739
|
-
});
|
|
740
|
-
return properties;
|
|
741
|
-
};
|
|
742
|
-
|
|
743
|
-
const getNamedExpressions = (
|
|
744
|
-
kind: string,
|
|
745
|
-
names: string[],
|
|
746
|
-
environment: Environment,
|
|
747
|
-
): NamedExpression[] =>
|
|
748
|
-
names.flatMap((name) =>
|
|
749
|
-
getConfigPredicate(kind, name, environment)
|
|
750
|
-
? [{ name, expression: createIdentifier(name), scope: undefined }]
|
|
751
|
-
: [],
|
|
752
|
-
);
|
|
753
|
-
|
|
754
|
-
const getBodyRange = (name: string, environment: Environment) => {
|
|
755
|
-
const definition = getDefinition(name, environment);
|
|
756
|
-
return definition?.kind === "Operator" ? definition.bodyRange : undefined;
|
|
757
|
-
};
|
|
758
|
-
|
|
759
|
-
const getPossiblePredicates = (names: string[], environment: Environment) =>
|
|
760
|
-
names.map((name, index) => {
|
|
761
|
-
if (names.indexOf(name) !== index) {
|
|
762
|
-
throw new TlaConfigError(`_POSSIBLE lists ${name} more than once`);
|
|
763
|
-
}
|
|
764
|
-
getConfigDefinition("possible", name, environment);
|
|
765
|
-
const expression = createIdentifier(name);
|
|
766
|
-
if (getLevel(expression, undefined, environment) === TEMPORAL_LEVEL) {
|
|
767
|
-
throw new TlaConfigError(
|
|
768
|
-
`The possible of ${name} is equal to a temporal formula; only state- and action-level predicates are supported`,
|
|
769
|
-
);
|
|
770
|
-
}
|
|
771
|
-
return { name, expression, scope: undefined };
|
|
772
|
-
});
|
|
773
|
-
|
|
774
|
-
const getMembership = (
|
|
775
|
-
expression: Expression,
|
|
776
|
-
variables: number[] | undefined,
|
|
777
|
-
environment: Environment,
|
|
778
|
-
): Membership | undefined => {
|
|
779
|
-
if (expression.kind !== "Apply" || expression.operator !== "\\in" || variables?.length !== 1)
|
|
780
|
-
return undefined;
|
|
781
|
-
const element = expression.args[0];
|
|
782
|
-
if (element.kind !== "Identifier" || isLocallyResolved(element)) return undefined;
|
|
783
|
-
return environment.variableIndex.get(element.name) === variables[0]
|
|
784
|
-
? { variable: variables[0], set: expression.args[1] }
|
|
785
|
-
: undefined;
|
|
786
|
-
};
|
|
787
|
-
|
|
788
|
-
// TLC evaluates the body of an invariant that the configuration names.
|
|
789
|
-
const getPredicate = (expression: Expression, environment: Environment) => {
|
|
790
|
-
if (expression.kind !== "Identifier" || environment.constants.has(expression.name)) {
|
|
791
|
-
return expression;
|
|
792
|
-
}
|
|
793
|
-
const definition = getDefinition(expression.name, environment);
|
|
794
|
-
return definition?.kind === "Operator" && definition.params.length === 0
|
|
795
|
-
? definition.body
|
|
796
|
-
: expression;
|
|
797
|
-
};
|
|
798
|
-
|
|
799
|
-
const getStateChecks = (named: NamedExpression[], environment: Environment): StateCheck[] =>
|
|
800
|
-
named.flatMap((item) =>
|
|
801
|
-
getConjuncts(item.expression, environment).map((expression) => {
|
|
802
|
-
// A LET or an argument in the scope can read variables the expression doesn't name.
|
|
803
|
-
const variables =
|
|
804
|
-
item.scope === undefined ? getReadVariables(expression, environment) : undefined;
|
|
805
|
-
return {
|
|
806
|
-
name: item.name,
|
|
807
|
-
expression,
|
|
808
|
-
scope: item.scope,
|
|
809
|
-
variables,
|
|
810
|
-
membership: getMembership(expression, variables, environment),
|
|
811
|
-
predicate: getPredicate(item.expression, environment),
|
|
812
|
-
};
|
|
813
|
-
}),
|
|
814
|
-
);
|
|
815
|
-
|
|
816
|
-
const isUnchangedFor = (stateCheck: StateCheck, state: Value[], parent: Value[] | undefined) => {
|
|
817
|
-
const variables = stateCheck.variables;
|
|
818
|
-
if (!parent || !variables) return false;
|
|
819
|
-
for (let index = 0; index < variables.length; index++) {
|
|
820
|
-
if (state[variables[index]] !== parent[variables[index]]) return false;
|
|
821
|
-
}
|
|
822
|
-
return true;
|
|
823
|
-
};
|
|
824
|
-
|
|
825
|
-
const WIDE_CHARACTER = /[\u0100-\uffff]/;
|
|
826
|
-
|
|
827
|
-
const DESERIALIZERS = new Set(["JsonDeserialize", "ndJsonDeserialize"]);
|
|
828
|
-
|
|
829
|
-
const isWideConfigValue = (value: ConfigValue): boolean =>
|
|
830
|
-
value.kind === "String"
|
|
831
|
-
? WIDE_CHARACTER.test(value.value)
|
|
832
|
-
: value.kind === "Set" && value.elements.some(isWideConfigValue);
|
|
833
|
-
|
|
834
|
-
const isWideExpression = (expression: Expression): boolean =>
|
|
835
|
-
(expression.kind === "String" && WIDE_CHARACTER.test(expression.value)) ||
|
|
836
|
-
(expression.kind === "Apply" && DESERIALIZERS.has(expression.operator)) ||
|
|
837
|
-
getChildren(expression).some(isWideExpression);
|
|
838
|
-
|
|
839
|
-
// TLC fingerprints a string by the low byte of each character, so it merges states whose
|
|
840
|
-
// strings differ only above U+00FF. Strings reach a state from literals, the config, or files.
|
|
841
|
-
const hasWideString = (config: ModelConfig, environment: Environment) =>
|
|
842
|
-
config.constants.some(
|
|
843
|
-
(constant) =>
|
|
844
|
-
isWideConfigValue(constant.value) || (constant.args ?? []).some(isWideConfigValue),
|
|
845
|
-
) ||
|
|
846
|
-
[...environment.definitions.values()].some(
|
|
847
|
-
(definition) =>
|
|
848
|
-
isWideExpression(definition.body) ||
|
|
849
|
-
(definition.kind === "Function" &&
|
|
850
|
-
definition.bounds.some((bound) => isWideExpression(bound.set))),
|
|
851
|
-
);
|
|
852
|
-
|
|
853
|
-
interface Search {
|
|
854
|
-
properties: Properties;
|
|
855
|
-
spec: Specification;
|
|
856
|
-
getFingerprintState: (state: Value[]) => Value[];
|
|
857
|
-
getStoredFingerprints: (states: Value[][], fingerprintStates: Value[][]) => BigInt64Array;
|
|
858
|
-
getTlcOrder: () => number[];
|
|
859
|
-
isSymmetric: boolean;
|
|
860
|
-
// TLC drops a constraint that is a true constant formula.
|
|
861
|
-
isConstrained: boolean;
|
|
862
|
-
findViolatedInvariant: (state: Value[], parent?: Value[]) => StateCheck | undefined;
|
|
863
|
-
// The checks of a state that TLC evaluates when it replays the computation of the initial states
|
|
864
|
-
// or of the successors of a state, with an environment that records the call stack. The first
|
|
865
|
-
// returns the check that stops the replay, and the second false where TLC stops it.
|
|
866
|
-
// TLC fingerprints a replayed state that satisfies the constraints before it checks the rest.
|
|
867
|
-
checkReplayedInitialState: (
|
|
868
|
-
state: Value[],
|
|
869
|
-
tracing: Environment,
|
|
870
|
-
addFingerprint: () => void,
|
|
871
|
-
) => Pick<InitialStateViolation, "status" | "name"> | undefined;
|
|
872
|
-
// Adding the fingerprint of a successor tells whether TLC had not seen it yet.
|
|
873
|
-
checkReplayedSuccessor: (
|
|
874
|
-
state: Value[],
|
|
875
|
-
next: Value[],
|
|
876
|
-
tracing: Environment,
|
|
877
|
-
addFingerprint: () => boolean,
|
|
878
|
-
) => boolean;
|
|
879
|
-
satisfiesConstraints: (state: Value[], parent?: Value[]) => boolean;
|
|
880
|
-
findFailedInitialPredicate: (state: Value[]) => NamedExpression | undefined;
|
|
881
|
-
findViolatedActionProperty: (state: Value[], next: Value[]) => ActionProperty | undefined;
|
|
882
|
-
satisfiesActionConstraints: (state: Value[], next: Value[]) => boolean;
|
|
883
|
-
trackStatePossible: (state: Value[]) => void;
|
|
884
|
-
trackActionPossible: (state: Value[], next: Value[]) => void;
|
|
885
|
-
findUnwitnessedPossible: () => Postcondition | undefined;
|
|
886
|
-
// After a counterexample, TLC skips the postconditions when one of them is constant.
|
|
887
|
-
findPostconditionViolation: (isAfterViolation?: boolean) => Postcondition | undefined;
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
const getContext = (
|
|
891
|
-
environment: Environment,
|
|
892
|
-
state: Value[] | undefined,
|
|
893
|
-
next: Value[] | undefined,
|
|
894
|
-
scope?: Scope,
|
|
895
|
-
) => ({ environment, scope, state, next });
|
|
896
|
-
|
|
897
|
-
const holds = (expression: Expression, context: Context, description: string) =>
|
|
898
|
-
expectBoolean(evaluate(expression, context), description);
|
|
899
|
-
|
|
900
|
-
// TLC names a check that is not a boolean by the location of the predicate it evaluates.
|
|
901
|
-
const holdsLikeTlc = (
|
|
902
|
-
expression: Expression,
|
|
903
|
-
context: Context,
|
|
904
|
-
getMessage = getExpectedBoolean,
|
|
905
|
-
) => {
|
|
906
|
-
const value = evaluate(expression, context);
|
|
907
|
-
if (typeof value !== "boolean") {
|
|
908
|
-
throw new TlaEvaluationError(getMessage(expression, context.environment));
|
|
909
|
-
}
|
|
910
|
-
return value;
|
|
911
|
-
};
|
|
912
|
-
|
|
913
|
-
const getExpectedBoolean = (expression: Expression, environment: Environment) => {
|
|
914
|
-
const definition =
|
|
915
|
-
expression.kind === "Identifier" ? getDefinition(expression.name, environment) : undefined;
|
|
916
|
-
const body = definition?.kind === "Operator" ? definition.body : expression;
|
|
917
|
-
const range = definition?.kind === "Operator" ? definition.bodyRange : undefined;
|
|
918
|
-
const location = range && body.kind !== "Number" ? formatRange(range) : describeNode(body);
|
|
919
|
-
return `TLC expected a boolean value, but did not find one. ${location}`;
|
|
920
|
-
};
|
|
921
|
-
|
|
922
|
-
// TLC evaluates the whole predicate of a check, which fails at a conjunct that isn't a boolean as
|
|
923
|
-
// the conjunction does.
|
|
924
|
-
const holdsAsConjunct = (check: StateCheck, context: Context) =>
|
|
925
|
-
holdsLikeTlc(check.expression, context, (expression, environment) => {
|
|
926
|
-
holdsLikeTlc(check.predicate, context);
|
|
927
|
-
return getExpectedBoolean(expression, environment);
|
|
928
|
-
});
|
|
929
|
-
|
|
930
|
-
const ignorePossible = () => {};
|
|
931
|
-
|
|
932
|
-
const trackPossible = (items: NamedExpression[], runtime: CheckerRuntime, context: Context) =>
|
|
933
|
-
items.forEach((item) => {
|
|
934
|
-
const count = runtime.possibleCounts.get(item.name) ?? 0;
|
|
935
|
-
const isWitnessed = holds(item.expression, context, `_POSSIBLE ${item.name}`);
|
|
936
|
-
runtime.possibleCounts.set(item.name, isWitnessed ? count + 1 : count);
|
|
937
|
-
});
|
|
938
|
-
|
|
939
|
-
const getConstantFailure = (
|
|
940
|
-
expression: Expression,
|
|
941
|
-
environment: Environment,
|
|
942
|
-
description: string,
|
|
943
|
-
) => {
|
|
944
|
-
try {
|
|
945
|
-
return holds(expression, getContext(environment, undefined, undefined), description)
|
|
946
|
-
? undefined
|
|
947
|
-
: { message: undefined };
|
|
948
|
-
} catch (error) {
|
|
949
|
-
if (error instanceof TlaEvaluationError) return { message: error.message };
|
|
950
|
-
throw error;
|
|
951
|
-
}
|
|
952
|
-
};
|
|
953
|
-
|
|
954
|
-
export const findAssumptionViolation = (
|
|
955
|
-
assumptions: Assumption[],
|
|
956
|
-
environment: Environment,
|
|
957
|
-
): Omit<Violation, "loopStart"> | undefined => {
|
|
958
|
-
for (const assumption of assumptions.filter((candidate) => !candidate.isAxiom)) {
|
|
959
|
-
const failure = getConstantFailure(assumption.expression, environment, "an assumption");
|
|
960
|
-
if (failure) {
|
|
961
|
-
return { name: describeRange(assumption.expression), trace: [], message: failure.message };
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
return undefined;
|
|
965
|
-
};
|
|
966
|
-
|
|
967
|
-
export const createSearch = (
|
|
968
|
-
config: ModelConfig,
|
|
969
|
-
environment: Environment,
|
|
970
|
-
getVariableOrder: () => string[],
|
|
971
|
-
onProgress?: CheckOptions["onProgress"],
|
|
972
|
-
): Search | undefined => {
|
|
973
|
-
const configInvariants = getInvariants(config.invariants, environment);
|
|
974
|
-
const spec = getSpecification(config, environment);
|
|
975
|
-
const properties = getProperties(config, environment, onProgress);
|
|
976
|
-
const invariants = getStateChecks([...configInvariants, ...properties.invariants], environment);
|
|
977
|
-
// The invariants TLC evaluates, each of which may have several conjuncts among the checks.
|
|
978
|
-
const invariantPredicates = [
|
|
979
|
-
...new Map(invariants.map((invariant) => [invariant.predicate, invariant])).values(),
|
|
980
|
-
];
|
|
981
|
-
const isCheckingBehaviors =
|
|
982
|
-
invariants.length > 0 ||
|
|
983
|
-
properties.actionProperties.length > 0 ||
|
|
984
|
-
properties.liveness.length > 0;
|
|
985
|
-
if (
|
|
986
|
-
spec.init === undefined &&
|
|
987
|
-
(isCheckingBehaviors ||
|
|
988
|
-
properties.initialPredicates.length > 0 ||
|
|
989
|
-
environment.variables.length > 0)
|
|
990
|
-
) {
|
|
991
|
-
throw new TlaConfigError(
|
|
992
|
-
environment.runtime.version === "1.7.4"
|
|
993
|
-
? MISSING_INIT_174
|
|
994
|
-
: "The configuration file did not specify the initial state predicate.",
|
|
995
|
-
);
|
|
996
|
-
}
|
|
997
|
-
if (spec.next === undefined && isCheckingBehaviors) {
|
|
998
|
-
throw new TlaConfigError("The configuration file did not specify the next state predicate.");
|
|
999
|
-
}
|
|
1000
|
-
const constraints = getStateChecks(
|
|
1001
|
-
getNamedExpressions("constraint", config.constraints, environment),
|
|
1002
|
-
environment,
|
|
1003
|
-
);
|
|
1004
|
-
const actionConstraints = getNamedExpressions(
|
|
1005
|
-
"action constraint",
|
|
1006
|
-
config.actionConstraints,
|
|
1007
|
-
environment,
|
|
1008
|
-
);
|
|
1009
|
-
if (config.rlReward !== undefined) getConfigOperator("rlreward", config.rlReward, environment);
|
|
1010
|
-
if (config.periodic !== undefined) getConfigOperator("periodic", config.periodic, environment);
|
|
1011
|
-
const possible = getPossiblePredicates(config.possible, environment);
|
|
1012
|
-
if (environment.variables.length === 0) return undefined;
|
|
1013
|
-
const symmetryGroup =
|
|
1014
|
-
config.symmetry === undefined
|
|
1015
|
-
? undefined
|
|
1016
|
-
: getSymmetryGroup(config.symmetry, environment, config.substitutions);
|
|
1017
|
-
if (config.view !== undefined) getConfigOperator("view function", config.view, environment);
|
|
1018
|
-
const view =
|
|
1019
|
-
config.view === undefined
|
|
1020
|
-
? undefined
|
|
1021
|
-
: { name: config.view, expression: createIdentifier(config.view), scope: undefined };
|
|
1022
|
-
const actionProperties = properties.actionProperties.map((property) => {
|
|
1023
|
-
const unchanged: Expression = {
|
|
1024
|
-
kind: "Unchanged",
|
|
1025
|
-
expression: property.subscript,
|
|
1026
|
-
location: START,
|
|
1027
|
-
};
|
|
1028
|
-
return { ...property, unchanged };
|
|
1029
|
-
});
|
|
1030
|
-
const isActionPossible = (item: NamedExpression) =>
|
|
1031
|
-
getLevel(item.expression, undefined, environment) >= ACTION_LEVEL;
|
|
1032
|
-
const statePossible = possible.filter((item) => !isActionPossible(item));
|
|
1033
|
-
const actionPossible = possible.filter(isActionPossible);
|
|
1034
|
-
const runtime = environment.runtime;
|
|
1035
|
-
const tlcOrder = { indices: undefined as number[] | undefined };
|
|
1036
|
-
const getTlcOrder = () => {
|
|
1037
|
-
if (tlcOrder.indices) return tlcOrder.indices;
|
|
1038
|
-
const variableOrder = getVariableOrder();
|
|
1039
|
-
const getTlcPosition = (index: number) => {
|
|
1040
|
-
const position = variableOrder.indexOf(environment.variables[index]);
|
|
1041
|
-
return position === -1 ? environment.variables.length : position;
|
|
1042
|
-
};
|
|
1043
|
-
tlcOrder.indices = environment.variables
|
|
1044
|
-
.map((_, index) => index)
|
|
1045
|
-
.sort((left, right) => getTlcPosition(left) - getTlcPosition(right));
|
|
1046
|
-
return tlcOrder.indices;
|
|
1047
|
-
};
|
|
1048
|
-
const getViewValue = (expression: Expression, state: Value[]) =>
|
|
1049
|
-
evaluate(expression, getContext(environment, state, undefined));
|
|
1050
|
-
const getTlcStateFingerprint = (state: Value[]) => {
|
|
1051
|
-
const indices = getTlcOrder();
|
|
1052
|
-
const representative =
|
|
1053
|
-
symmetryGroup === undefined ? state : getRepresentative(state, symmetryGroup, indices);
|
|
1054
|
-
return getTlcFingerprint(
|
|
1055
|
-
view === undefined
|
|
1056
|
-
? indices.map((index) => representative[index])
|
|
1057
|
-
: [getViewValue(view.expression, representative)],
|
|
1058
|
-
);
|
|
1059
|
-
};
|
|
1060
|
-
const isFingerprintedLikeTlc = hasWideString(config, environment);
|
|
1061
|
-
runtime.getFingerprint = getTlcStateFingerprint;
|
|
1062
|
-
const findUnwitnessedPossible = () => {
|
|
1063
|
-
const unwitnessed = possible.find((item) => !runtime.possibleCounts.get(item.name));
|
|
1064
|
-
if (!unwitnessed) return undefined;
|
|
1065
|
-
const range = getBodyRange(unwitnessed.name, environment);
|
|
1066
|
-
const location = range ? ` at ${formatRange(range)}` : "";
|
|
1067
|
-
return {
|
|
1068
|
-
name: unwitnessed.name,
|
|
1069
|
-
code: MESSAGE_CODE.possibleUnwitnessed,
|
|
1070
|
-
message: `The _POSSIBLE predicate ${unwitnessed.name}${location} was never witnessed.\nOthers may be unwitnessed too; only witnessed predicates appear with a\nnon-zero count in the record printed above.\nSee https://explain.tlapl.us/possible-conditions for additional details.`,
|
|
1071
|
-
counts: prettyPrint(formatValue(getPossibleCounts(runtime), true)),
|
|
1072
|
-
};
|
|
1073
|
-
};
|
|
1074
|
-
return {
|
|
1075
|
-
properties,
|
|
1076
|
-
spec,
|
|
1077
|
-
isSymmetric: symmetryGroup !== undefined,
|
|
1078
|
-
isConstrained: constraints.length > 0 || actionConstraints.length > 0,
|
|
1079
|
-
getTlcOrder,
|
|
1080
|
-
getStoredFingerprints: (states, fingerprintStates) => {
|
|
1081
|
-
if (view !== undefined || isFingerprintedLikeTlc) {
|
|
1082
|
-
return BigInt64Array.from(states, getTlcStateFingerprint);
|
|
1083
|
-
}
|
|
1084
|
-
const fingerprints = new BigInt64Array(fingerprintStates.length);
|
|
1085
|
-
const fingerprint = createTlcFingerprinter(
|
|
1086
|
-
getTlcOrder(),
|
|
1087
|
-
new Int32Array(fingerprints.buffer),
|
|
1088
|
-
);
|
|
1089
|
-
fingerprintStates.forEach(fingerprint);
|
|
1090
|
-
return fingerprints;
|
|
1091
|
-
},
|
|
1092
|
-
getFingerprintState: (state) => {
|
|
1093
|
-
if (isFingerprintedLikeTlc) return [String(getTlcStateFingerprint(state))];
|
|
1094
|
-
// A representative in TLC's variable order is the one whose fingerprint TLC reports.
|
|
1095
|
-
const representative =
|
|
1096
|
-
symmetryGroup === undefined
|
|
1097
|
-
? state
|
|
1098
|
-
: getRepresentative(state, symmetryGroup, getTlcOrder());
|
|
1099
|
-
return view === undefined ? representative : [getViewValue(view.expression, representative)];
|
|
1100
|
-
},
|
|
1101
|
-
findViolatedInvariant: (state, parent) =>
|
|
1102
|
-
invariants.find((invariant) => {
|
|
1103
|
-
if (isUnchangedFor(invariant, state, parent)) return false;
|
|
1104
|
-
try {
|
|
1105
|
-
const context = getContext(environment, state, undefined, invariant.scope);
|
|
1106
|
-
const membership = invariant.membership;
|
|
1107
|
-
// The parent satisfies every invariant, so only the entries the step changed can fail.
|
|
1108
|
-
return parent && membership
|
|
1109
|
-
? !isUpdatedElementOf(
|
|
1110
|
-
state[membership.variable],
|
|
1111
|
-
parent[membership.variable],
|
|
1112
|
-
evaluate(membership.set, context),
|
|
1113
|
-
)
|
|
1114
|
-
: !holdsAsConjunct(invariant, context);
|
|
1115
|
-
} catch (error) {
|
|
1116
|
-
// TLC reports a failure only on a state after the initial states as an invariant failure.
|
|
1117
|
-
if (!parent) throw error;
|
|
1118
|
-
throw withHeadline(
|
|
1119
|
-
setExitCode(error, EXIT_STATUS.safetyEvaluationFailure),
|
|
1120
|
-
MESSAGE_CODE.invariantEvaluationFailed,
|
|
1121
|
-
`Evaluating invariant ${invariant.name} failed.`,
|
|
1122
|
-
);
|
|
1123
|
-
}
|
|
1124
|
-
}),
|
|
1125
|
-
checkReplayedInitialState: (state, tracing, addFingerprint) => {
|
|
1126
|
-
const holdsIn = (expression: Expression, scope: Scope | undefined) =>
|
|
1127
|
-
holdsLikeTlc(expression, getContext(tracing, state, undefined, scope));
|
|
1128
|
-
if (constraints.every((constraint) => holdsIn(constraint.predicate, constraint.scope))) {
|
|
1129
|
-
addFingerprint();
|
|
1130
|
-
}
|
|
1131
|
-
const invariant = invariantPredicates.find((check) => !holdsIn(check.predicate, check.scope));
|
|
1132
|
-
if (invariant) return { status: "invariant-violation", name: invariant.name };
|
|
1133
|
-
const predicate = properties.initialPredicates.find(
|
|
1134
|
-
(check) => !holdsIn(check.expression, check.scope),
|
|
1135
|
-
);
|
|
1136
|
-
return predicate && { status: "liveness-violation", name: predicate.name };
|
|
1137
|
-
},
|
|
1138
|
-
checkReplayedSuccessor: (state, next, tracing, addFingerprint) => {
|
|
1139
|
-
// TLC evaluates the action constraints only on a state that satisfies the constraints.
|
|
1140
|
-
const isInModel =
|
|
1141
|
-
constraints.every((constraint) =>
|
|
1142
|
-
holdsLikeTlc(
|
|
1143
|
-
constraint.predicate,
|
|
1144
|
-
getContext(tracing, next, undefined, constraint.scope),
|
|
1145
|
-
),
|
|
1146
|
-
) &&
|
|
1147
|
-
actionConstraints.every((constraint) =>
|
|
1148
|
-
holdsLikeTlc(constraint.expression, getContext(tracing, state, next, constraint.scope)),
|
|
1149
|
-
);
|
|
1150
|
-
// ModelChecker.doNext checks the invariants of a successor it has not seen, which includes
|
|
1151
|
-
// one outside the model.
|
|
1152
|
-
const isUnseen = isInModel ? addFingerprint() : true;
|
|
1153
|
-
return (
|
|
1154
|
-
(!isUnseen ||
|
|
1155
|
-
invariantPredicates.every((invariant) =>
|
|
1156
|
-
holdsLikeTlc(
|
|
1157
|
-
invariant.predicate,
|
|
1158
|
-
getContext(tracing, next, undefined, invariant.scope),
|
|
1159
|
-
),
|
|
1160
|
-
)) &&
|
|
1161
|
-
actionProperties.every((property) =>
|
|
1162
|
-
holdsLikeTlc(property.box, getContext(tracing, state, next, property.scope)),
|
|
1163
|
-
)
|
|
1164
|
-
);
|
|
1165
|
-
},
|
|
1166
|
-
satisfiesConstraints: (state, parent) =>
|
|
1167
|
-
constraints.every(
|
|
1168
|
-
(constraint) =>
|
|
1169
|
-
isUnchangedFor(constraint, state, parent) ||
|
|
1170
|
-
holdsAsConjunct(constraint, getContext(environment, state, undefined)),
|
|
1171
|
-
),
|
|
1172
|
-
findFailedInitialPredicate: (state) =>
|
|
1173
|
-
properties.initialPredicates.find(
|
|
1174
|
-
(predicate) =>
|
|
1175
|
-
!holdsLikeTlc(
|
|
1176
|
-
predicate.expression,
|
|
1177
|
-
getContext(environment, state, undefined, predicate.scope),
|
|
1178
|
-
),
|
|
1179
|
-
),
|
|
1180
|
-
findViolatedActionProperty: (state, next) =>
|
|
1181
|
-
actionProperties.find((property) => {
|
|
1182
|
-
try {
|
|
1183
|
-
return (
|
|
1184
|
-
!holdsLikeTlc(
|
|
1185
|
-
property.action,
|
|
1186
|
-
getContext(environment, state, next, property.scope),
|
|
1187
|
-
() =>
|
|
1188
|
-
`Attempted to evaluate an expression of form [A]_e, but A was not a boolean.\n${describeRange(property.box)}`,
|
|
1189
|
-
) &&
|
|
1190
|
-
!holds(
|
|
1191
|
-
property.unchanged,
|
|
1192
|
-
getContext(environment, state, next, property.scope),
|
|
1193
|
-
"a subscript",
|
|
1194
|
-
)
|
|
1195
|
-
);
|
|
1196
|
-
} catch (error) {
|
|
1197
|
-
throw withHeadline(
|
|
1198
|
-
withNextStateExitCode(error),
|
|
1199
|
-
MESSAGE_CODE.actionPropertyEvaluationFailed,
|
|
1200
|
-
`Evaluating action property ${property.name} failed.`,
|
|
1201
|
-
);
|
|
1202
|
-
}
|
|
1203
|
-
}),
|
|
1204
|
-
satisfiesActionConstraints: (state, next) =>
|
|
1205
|
-
actionConstraints.every((constraint) =>
|
|
1206
|
-
holdsLikeTlc(
|
|
1207
|
-
constraint.expression,
|
|
1208
|
-
getContext(environment, state, next),
|
|
1209
|
-
(expression) => `${UNEXPECTED_EXCEPTION}${getExpectedBoolean(expression, environment)}`,
|
|
1210
|
-
),
|
|
1211
|
-
),
|
|
1212
|
-
trackStatePossible:
|
|
1213
|
-
statePossible.length === 0
|
|
1214
|
-
? ignorePossible
|
|
1215
|
-
: (state) =>
|
|
1216
|
-
trackPossible(statePossible, runtime, getContext(environment, state, undefined)),
|
|
1217
|
-
trackActionPossible:
|
|
1218
|
-
actionPossible.length === 0
|
|
1219
|
-
? ignorePossible
|
|
1220
|
-
: (state, next) =>
|
|
1221
|
-
trackPossible(actionPossible, runtime, getContext(environment, state, next)),
|
|
1222
|
-
findUnwitnessedPossible,
|
|
1223
|
-
findPostconditionViolation: (isAfterViolation = false) => {
|
|
1224
|
-
// TLC replaces a definition it computes when it starts by its value, and then rejects it as
|
|
1225
|
-
// a postcondition before it checks any of them.
|
|
1226
|
-
const constant = config.postconditions.find((name) => {
|
|
1227
|
-
const definition = getDefinition(name, environment);
|
|
1228
|
-
return definition !== undefined && environment.definitionValues.has(definition);
|
|
1229
|
-
});
|
|
1230
|
-
if (constant !== undefined) {
|
|
1231
|
-
if (isAfterViolation) return undefined;
|
|
1232
|
-
throw setExitCode(
|
|
1233
|
-
new TlaEvaluationError(
|
|
1234
|
-
`${UNEXPECTED_EXCEPTION}The post condition ${constant} cannot be a constant.`,
|
|
1235
|
-
),
|
|
1236
|
-
EXIT_STATUS.error,
|
|
1237
|
-
);
|
|
1238
|
-
}
|
|
1239
|
-
const unwitnessed = findUnwitnessedPossible();
|
|
1240
|
-
if (unwitnessed) return unwitnessed;
|
|
1241
|
-
for (const name of config.postconditions) {
|
|
1242
|
-
const failure = getConstantFailure(createIdentifier(name), environment, "a postcondition");
|
|
1243
|
-
if (!failure) continue;
|
|
1244
|
-
const range = getBodyRange(name, environment);
|
|
1245
|
-
const location = range ? ` at ${formatRange(range)}` : "";
|
|
1246
|
-
return failure.message === undefined
|
|
1247
|
-
? {
|
|
1248
|
-
name,
|
|
1249
|
-
code: MESSAGE_CODE.postconditionFalse,
|
|
1250
|
-
message: `Postcondition ${name}${location} is false.`,
|
|
1251
|
-
}
|
|
1252
|
-
: {
|
|
1253
|
-
name,
|
|
1254
|
-
code: MESSAGE_CODE.postconditionFailed,
|
|
1255
|
-
message: `Evaluating postcondition ${name}${location} failed.\n${failure.message}`,
|
|
1256
|
-
};
|
|
1257
|
-
}
|
|
1258
|
-
return undefined;
|
|
1259
|
-
},
|
|
1260
|
-
};
|
|
1261
|
-
};
|
|
1262
|
-
|
|
1263
|
-
// TLC exits with the code of a standard module's failure only when the failure escapes the
|
|
1264
|
-
// computation of next states. In every other phase, the phase decides the code.
|
|
1265
|
-
const withNextStateExitCode = (error: unknown) =>
|
|
1266
|
-
error instanceof TlaModuleError ? setExitCode(error, error.exitCode) : error;
|
|
1267
|
-
|
|
1268
334
|
// Stops a replay where TLC stops it without a failure, as at a violated invariant.
|
|
1269
335
|
const STOP_REPLAY = new Error("The replay stopped");
|
|
1270
336
|
|
|
@@ -1297,106 +363,6 @@ const getReplayExitCode = (error: TlaEvaluationError): number => {
|
|
|
1297
363
|
return error instanceof TlaModuleError ? error.exitCode : EXIT_STATUS.specEvaluationFailure;
|
|
1298
364
|
};
|
|
1299
365
|
|
|
1300
|
-
// An error that TLC reports with a message of its own, by that message's code and first line, and
|
|
1301
|
-
// the error whose message follows.
|
|
1302
|
-
interface HeadedError {
|
|
1303
|
-
code: number;
|
|
1304
|
-
headline: string;
|
|
1305
|
-
inner: TlaEvaluationError;
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
const headedErrors = new WeakMap<Error, HeadedError>();
|
|
1309
|
-
|
|
1310
|
-
const withHeadline = (error: unknown, code: number, headline: string) => {
|
|
1311
|
-
if (!(error instanceof TlaEvaluationError)) return error;
|
|
1312
|
-
const headed = setExitCode(
|
|
1313
|
-
new TlaEvaluationError(`${headline}\n${error.message}`, error),
|
|
1314
|
-
getErrorExitCode(error),
|
|
1315
|
-
);
|
|
1316
|
-
headedErrors.set(headed, { code, headline, inner: error });
|
|
1317
|
-
return headed;
|
|
1318
|
-
};
|
|
1319
|
-
|
|
1320
|
-
const UNEXPECTED_HEADLINE = UNEXPECTED_EXCEPTION.slice(0, UNEXPECTED_EXCEPTION.indexOf("\n"));
|
|
1321
|
-
|
|
1322
|
-
// TLC 1.7.4's Worker wraps an error in adding a successor in a RuntimeException, whose message
|
|
1323
|
-
// names the class of the error.
|
|
1324
|
-
const WRAPPED_EVAL_EXCEPTION = `${UNEXPECTED_EXCEPTION}tlc2.tool.EvalException: `;
|
|
1325
|
-
const WRAPPED_RUNTIME_EXCEPTION = `${UNEXPECTED_EXCEPTION}util.Assert$TLCRuntimeException: `;
|
|
1326
|
-
|
|
1327
|
-
const UNEXPECTED_EVAL_EXCEPTION = getUnexpectedException("tlc2.tool.EvalException");
|
|
1328
|
-
|
|
1329
|
-
const getWrappedException = (error: TlaEvaluationError) =>
|
|
1330
|
-
isEvalException(error) ? WRAPPED_EVAL_EXCEPTION : WRAPPED_RUNTIME_EXCEPTION;
|
|
1331
|
-
|
|
1332
|
-
// TLC reports an EvalException, or a TLCRuntimeException without a message of its own, as an
|
|
1333
|
-
// exception it didn't expect.
|
|
1334
|
-
const withUnexpectedException = <Result>(compute: () => Result) => {
|
|
1335
|
-
try {
|
|
1336
|
-
return compute();
|
|
1337
|
-
} catch (error) {
|
|
1338
|
-
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1339
|
-
if (isEvalException(error)) {
|
|
1340
|
-
throw new TlaEvaluationError(`${UNEXPECTED_EVAL_EXCEPTION}${error.message}`);
|
|
1341
|
-
}
|
|
1342
|
-
if (getCodedMessage(error.message)) throw error;
|
|
1343
|
-
throw new TlaEvaluationError(`${UNEXPECTED_EXCEPTION}${error.message}`);
|
|
1344
|
-
}
|
|
1345
|
-
};
|
|
1346
|
-
|
|
1347
|
-
// The starts of TLC's messages for the exceptions it didn't expect.
|
|
1348
|
-
const UNEXPECTED_EXCEPTIONS = [
|
|
1349
|
-
WRAPPED_EVAL_EXCEPTION,
|
|
1350
|
-
WRAPPED_RUNTIME_EXCEPTION,
|
|
1351
|
-
UNEXPECTED_EXCEPTION,
|
|
1352
|
-
UNEXPECTED_EVAL_EXCEPTION,
|
|
1353
|
-
];
|
|
1354
|
-
|
|
1355
|
-
// The text of an error's message, with the message of a coded error inside it marked in -tool
|
|
1356
|
-
// output as TLC marks it.
|
|
1357
|
-
const formatErrorMessage = (error: TlaEvaluationError, isTool: boolean): string => {
|
|
1358
|
-
const headed = headedErrors.get(error);
|
|
1359
|
-
if (headed) return `${headed.headline}\n${formatErrorMessage(headed.inner, isTool)}`;
|
|
1360
|
-
const message = error.message;
|
|
1361
|
-
const prefix = UNEXPECTED_EXCEPTIONS.find((start) => message.startsWith(start)) ?? "";
|
|
1362
|
-
return `${prefix}${formatNestedMessage(message.slice(prefix.length), isTool)}`;
|
|
1363
|
-
};
|
|
1364
|
-
|
|
1365
|
-
// How TLC reports an error: with the code of its own message for an error that it reports with a
|
|
1366
|
-
// headline; and, when the error escapes the computation of next states, with the code of an
|
|
1367
|
-
// EvalException, or as an unexpected exception for any other error.
|
|
1368
|
-
interface FailureMessage {
|
|
1369
|
-
code: number;
|
|
1370
|
-
message: string;
|
|
1371
|
-
toolMessage: string;
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
const getFailureMessage = (error: TlaEvaluationError, isNextState: boolean): FailureMessage => {
|
|
1375
|
-
const headed = headedErrors.get(error);
|
|
1376
|
-
const message = error.message;
|
|
1377
|
-
if (headed) {
|
|
1378
|
-
return {
|
|
1379
|
-
code: headed.code,
|
|
1380
|
-
message,
|
|
1381
|
-
toolMessage: formatErrorMessage(error, true),
|
|
1382
|
-
};
|
|
1383
|
-
}
|
|
1384
|
-
if (isNextState && isEvalException(error)) {
|
|
1385
|
-
return {
|
|
1386
|
-
code: getCodedMessage(message)?.code ?? MESSAGE_CODE.general,
|
|
1387
|
-
message,
|
|
1388
|
-
toolMessage: message,
|
|
1389
|
-
};
|
|
1390
|
-
}
|
|
1391
|
-
const isUnexpected = isNextState && !message.startsWith(UNEXPECTED_HEADLINE);
|
|
1392
|
-
const prefix = isUnexpected ? UNEXPECTED_EXCEPTION : "";
|
|
1393
|
-
return {
|
|
1394
|
-
code: MESSAGE_CODE.general,
|
|
1395
|
-
message: `${prefix}${message}`,
|
|
1396
|
-
toolMessage: `${prefix}${formatErrorMessage(error, true)}`,
|
|
1397
|
-
};
|
|
1398
|
-
};
|
|
1399
|
-
|
|
1400
366
|
// TLC finishes the -dump file whether or not the search finds a violation.
|
|
1401
367
|
export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
1402
368
|
const stateWriter =
|
|
@@ -1404,14 +370,18 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
|
1404
370
|
try {
|
|
1405
371
|
return searchStates(options, stateWriter);
|
|
1406
372
|
} catch (error) {
|
|
1407
|
-
// TLC reports a stack overflow outside the search on its own, and exits with 255.
|
|
1408
373
|
throw isStackOverflow(error) ? createStackOverflowError() : error;
|
|
1409
374
|
} finally {
|
|
1410
375
|
stateWriter?.close();
|
|
1411
376
|
}
|
|
1412
377
|
};
|
|
1413
378
|
|
|
1414
|
-
|
|
379
|
+
// TLC checks liveness on the graph so far 3 seconds into the search and then every minute, once
|
|
380
|
+
// the graph has grown by a tenth and liveness checking has taken at most a fifth of the time.
|
|
381
|
+
const PERIODIC_START = 3000;
|
|
382
|
+
const PROGRESS_INTERVAL = 60_000;
|
|
383
|
+
const LIVENESS_GROWTH = 0.1;
|
|
384
|
+
const LIVENESS_RATIO = 0.2;
|
|
1415
385
|
|
|
1416
386
|
const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefined): CheckResult => {
|
|
1417
387
|
const config =
|
|
@@ -1421,19 +391,19 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1421
391
|
const onPrint = options.onPrint ?? console.log;
|
|
1422
392
|
// TLC prints again while it rebuilds a trace, between the states it prints, so rebuilding a trace
|
|
1423
393
|
// keeps what it prints for the trace.
|
|
1424
|
-
const
|
|
394
|
+
const capturedOutput = { lines: undefined as OutputLine[] | undefined };
|
|
1425
395
|
const print = (text: string) => {
|
|
1426
|
-
if (
|
|
396
|
+
if (capturedOutput.lines) capturedOutput.lines.push(text);
|
|
1427
397
|
else onPrint(text);
|
|
1428
398
|
};
|
|
1429
|
-
const
|
|
1430
|
-
const outer =
|
|
399
|
+
const captureOutput = <Result>(rebuild: () => Result) => {
|
|
400
|
+
const outer = capturedOutput.lines;
|
|
1431
401
|
const lines: OutputLine[] = [];
|
|
1432
|
-
|
|
402
|
+
capturedOutput.lines = lines;
|
|
1433
403
|
try {
|
|
1434
404
|
return { result: rebuild(), lines };
|
|
1435
405
|
} finally {
|
|
1436
|
-
|
|
406
|
+
capturedOutput.lines = outer;
|
|
1437
407
|
}
|
|
1438
408
|
};
|
|
1439
409
|
setStringOrder(getTlcStringOrder(options.source, config, options.loadModule));
|
|
@@ -1558,7 +528,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1558
528
|
const unwitnessed = search.findUnwitnessedPossible();
|
|
1559
529
|
const checked = unwitnessed
|
|
1560
530
|
? { result: undefined, lines: [] }
|
|
1561
|
-
:
|
|
531
|
+
: captureOutput(() => search.findPostconditionViolation(true));
|
|
1562
532
|
return { unwitnessed, postcondition: checked.result, lines: checked.lines };
|
|
1563
533
|
};
|
|
1564
534
|
const reportViolation = (
|
|
@@ -1581,10 +551,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1581
551
|
};
|
|
1582
552
|
const spec = search.spec;
|
|
1583
553
|
const getFingerprintState = search.getFingerprintState;
|
|
1584
|
-
const
|
|
554
|
+
const specNextActions = { value: undefined as SpecAction[] | undefined };
|
|
1585
555
|
const getSpecNextActions = () =>
|
|
1586
|
-
(
|
|
1587
|
-
// Where TLC's replay of a failed computation fails, or undefined when the replay completes.
|
|
556
|
+
(specNextActions.value ??= getNextActions(config, environment, specification.instanceActions));
|
|
1588
557
|
const getReplayFailure = (replay: (tracing: Environment) => void): ReplayFailure | undefined => {
|
|
1589
558
|
const tracing = createTracingEnvironment(environment);
|
|
1590
559
|
const callStack = tracing.callStack;
|
|
@@ -1654,7 +623,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1654
623
|
getInitActions(config, environment, specification.instanceActions),
|
|
1655
624
|
tracing,
|
|
1656
625
|
(state) => {
|
|
1657
|
-
reportInitialStatesProgress(replayed.count, (progress) =>
|
|
626
|
+
reportInitialStatesProgress(replayed.count, (progress) =>
|
|
627
|
+
capturedOutput.lines?.push(progress),
|
|
628
|
+
);
|
|
1658
629
|
replayed.count++;
|
|
1659
630
|
runtime.generatedStates = replayed.count;
|
|
1660
631
|
if (deferred.length > 0) return;
|
|
@@ -1667,7 +638,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1667
638
|
const violation = search.checkReplayedInitialState(state, tracing, addFingerprint);
|
|
1668
639
|
if (violation) {
|
|
1669
640
|
const traced = toTrace([{ action: undefined, state }], []).trace[0].state;
|
|
1670
|
-
|
|
641
|
+
capturedOutput.lines?.push({
|
|
642
|
+
kind: "initial-state-violation",
|
|
643
|
+
...violation,
|
|
644
|
+
state: traced,
|
|
645
|
+
});
|
|
1671
646
|
throw STOP_REPLAY;
|
|
1672
647
|
}
|
|
1673
648
|
} catch (error) {
|
|
@@ -1764,7 +739,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1764
739
|
const depths: number[] = [];
|
|
1765
740
|
// A Map holds at most 2^24 entries, so an open-addressing table keeps each seen state's hash
|
|
1766
741
|
// and its index plus one side by side, probed by the hash.
|
|
1767
|
-
const
|
|
742
|
+
const seenStates = { slots: new Int32Array(1 << 17), size: 0, shift: 16 };
|
|
1768
743
|
const canonicalizeState = createCanonicalizer();
|
|
1769
744
|
|
|
1770
745
|
const toRecord = (state: Value[]): Record<string, Value> =>
|
|
@@ -1801,9 +776,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1801
776
|
}
|
|
1802
777
|
};
|
|
1803
778
|
// TLC finds the action of a step as the first action that takes it, evaluated as when the search
|
|
1804
|
-
// expanded the previous state.
|
|
1805
|
-
// TLC finds the action of a successor it holds by the successor's values, and of any other state
|
|
1806
|
-
// by its fingerprint.
|
|
779
|
+
// expanded the previous state, by the values of a successor it holds and otherwise by fingerprint.
|
|
1807
780
|
const findStepAction = (index: number, previous: Value[], state: Value[], isHeld: boolean) => {
|
|
1808
781
|
const actions = getSpecNextActions();
|
|
1809
782
|
const expanding = { ...current };
|
|
@@ -1830,12 +803,12 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1830
803
|
const alias = config.alias;
|
|
1831
804
|
const known = traceOptions.known ?? 1;
|
|
1832
805
|
// Rebuilding the trace from the initial predicate can reset what TLCSet stored.
|
|
1833
|
-
const initialOutput = steps.length > 1 ?
|
|
806
|
+
const initialOutput = steps.length > 1 ? captureOutput(getSpecInitialStates).lines : [];
|
|
1834
807
|
// TLC finds the action that takes each step before it evaluates the alias.
|
|
1835
|
-
const
|
|
808
|
+
const stepActions = steps.map((step, position) =>
|
|
1836
809
|
position === 0 || step.action === "Stuttering"
|
|
1837
810
|
? { result: undefined, lines: [] }
|
|
1838
|
-
:
|
|
811
|
+
: captureOutput(() =>
|
|
1839
812
|
findStepAction(
|
|
1840
813
|
path[position - 1],
|
|
1841
814
|
steps[position - 1].state,
|
|
@@ -1844,7 +817,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1844
817
|
),
|
|
1845
818
|
),
|
|
1846
819
|
);
|
|
1847
|
-
const outputs =
|
|
820
|
+
const outputs = stepActions.map((step) => step.lines);
|
|
1848
821
|
const loopStart = traceOptions.loopStart;
|
|
1849
822
|
// 1.7.4's LiveWorker#printTrace rebuilds a lasso up to the start of its cycle at once, and then
|
|
1850
823
|
// each state of the cycle as it prints it.
|
|
@@ -1852,7 +825,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1852
825
|
const prefixOutput = rebuilt > 0 ? [initialOutput, ...outputs.slice(1, rebuilt)].flat() : [];
|
|
1853
826
|
return {
|
|
1854
827
|
trace: steps.map((step, position) => {
|
|
1855
|
-
const action =
|
|
828
|
+
const action = stepActions[position].result;
|
|
1856
829
|
const traceStep: TraceStep = {
|
|
1857
830
|
action: step.action,
|
|
1858
831
|
label: action && getActionLabel(action, options.version),
|
|
@@ -1876,7 +849,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1876
849
|
// generates it. A trace keeps what the spec prints as TLC rebuilds it, so finding its states
|
|
1877
850
|
// prints nothing.
|
|
1878
851
|
const findTraceSuccessor = (state: Value[], isMatch: (successor: Successor) => boolean) =>
|
|
1879
|
-
|
|
852
|
+
captureOutput(() => {
|
|
1880
853
|
for (const action of getSpecNextActions()) {
|
|
1881
854
|
const successor = getSuccessors(action.expression, state, environment, action.scope).find(
|
|
1882
855
|
isMatch,
|
|
@@ -1890,7 +863,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1890
863
|
const findSuccessorWithFingerprint = (state: Value[], index: number) =>
|
|
1891
864
|
findTraceSuccessor(state, (successor) => hasFingerprint(successor.state, index));
|
|
1892
865
|
const getPathStates = (path: number[], nextFailure: string) => {
|
|
1893
|
-
const initial =
|
|
866
|
+
const initial = captureOutput(() =>
|
|
1894
867
|
isReducing || isImpure(environment)
|
|
1895
868
|
? getSpecInitialStates().find((state) => hasFingerprint(state, path[0]))
|
|
1896
869
|
: states[path[0]],
|
|
@@ -1909,7 +882,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1909
882
|
}
|
|
1910
883
|
return steps;
|
|
1911
884
|
};
|
|
1912
|
-
const getTrace = (index: number,
|
|
885
|
+
const getTrace = (index: number, lastSuccessor?: Successor) => {
|
|
1913
886
|
const path: number[] = [];
|
|
1914
887
|
for (let position = index; position !== -1; position = parents[position]) {
|
|
1915
888
|
path.unshift(position);
|
|
@@ -1918,21 +891,21 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1918
891
|
isReducing && path.length > 1
|
|
1919
892
|
? getPathStates(path, INITIAL_RECOVERY_FAILURE)
|
|
1920
893
|
: path.map((position) => ({ state: states[position], action: actions[position] }));
|
|
1921
|
-
if (!
|
|
894
|
+
if (!lastSuccessor) return toTrace(steps, path);
|
|
1922
895
|
const action = isReducing
|
|
1923
|
-
? findTraceSuccessor(states[index], (successor) =>
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
896
|
+
? findTraceSuccessor(states[index], (successor) =>
|
|
897
|
+
isSameState(successor.state, lastSuccessor.state),
|
|
898
|
+
)?.action
|
|
899
|
+
: lastSuccessor.action;
|
|
900
|
+
return toTrace([...steps, { state: lastSuccessor.state, action }], path, { known: 2 });
|
|
1927
901
|
};
|
|
1928
|
-
// TLC prints
|
|
1929
|
-
//
|
|
1930
|
-
// again, though TLC 1.7.4 doesn't.
|
|
902
|
+
// TLC prints a lone initial state without the alias. TLCTrace#getTrace still recovers it from the
|
|
903
|
+
// initial predicate, printing again, though TLC 1.7.4 doesn't.
|
|
1931
904
|
const getStateTrace = (index: number): Behavior =>
|
|
1932
905
|
parents[index] === -1
|
|
1933
906
|
? {
|
|
1934
907
|
trace: [{ action: undefined, label: undefined, state: toRecord(states[index]) }],
|
|
1935
|
-
traceOutput: is174 ? [] :
|
|
908
|
+
traceOutput: is174 ? [] : captureOutput(getSpecInitialStates).lines,
|
|
1936
909
|
}
|
|
1937
910
|
: getTrace(index);
|
|
1938
911
|
// TLC rebuilds the trace again for the postcondition after it prints a violation, but not after
|
|
@@ -1968,7 +941,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1968
941
|
? EXIT_STATUS.specEvaluationFailure
|
|
1969
942
|
: getReplayExitCode(error);
|
|
1970
943
|
};
|
|
1971
|
-
const
|
|
944
|
+
const createFailureResult = (
|
|
945
|
+
failed: unknown,
|
|
946
|
+
behavior: Behavior,
|
|
947
|
+
failureOptions: FailureOptions = {},
|
|
948
|
+
) => {
|
|
1972
949
|
const error = isStackOverflow(failed) ? new TlaStackOverflowError() : failed;
|
|
1973
950
|
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1974
951
|
const checked =
|
|
@@ -2013,7 +990,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2013
990
|
const message = `Successor state is not completely specified by ${subject}. The following variable${missing.length > 1 ? "s are" : " is"} not ${verb}: ${missing.join(", ")}.\n`;
|
|
2014
991
|
const undefinedValue = createModelValue("null");
|
|
2015
992
|
const partial = error.state.map((value) => value ?? undefinedValue);
|
|
2016
|
-
const failure =
|
|
993
|
+
const failure = createFailureResult(error, getStateTrace(index));
|
|
2017
994
|
return withOutDegrees({
|
|
2018
995
|
...failure,
|
|
2019
996
|
failure: failure.failure && {
|
|
@@ -2035,12 +1012,12 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2035
1012
|
};
|
|
2036
1013
|
const getPathSteps = (path: number[], loopStart?: number) => {
|
|
2037
1014
|
const steps = getPathStates(path, NEXT_RECOVERY_FAILURE);
|
|
2038
|
-
const
|
|
1015
|
+
const lastState = steps[steps.length - 1].state;
|
|
2039
1016
|
const isClosed =
|
|
2040
1017
|
!isReducing ||
|
|
2041
1018
|
loopStart === undefined ||
|
|
2042
1019
|
loopStart === path.length - 1 ||
|
|
2043
|
-
findSuccessorWithFingerprint(
|
|
1020
|
+
findSuccessorWithFingerprint(lastState, path[loopStart]) !== undefined;
|
|
2044
1021
|
if (!isClosed) throw new TlaEvaluationError(NEXT_RECOVERY_FAILURE);
|
|
2045
1022
|
return steps;
|
|
2046
1023
|
};
|
|
@@ -2063,30 +1040,30 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2063
1040
|
}
|
|
2064
1041
|
return true;
|
|
2065
1042
|
};
|
|
2066
|
-
const getSlot = (hash: number) => (Math.imul(hash, 0x9e3779b1) >>>
|
|
1043
|
+
const getSlot = (hash: number) => (Math.imul(hash, 0x9e3779b1) >>> seenStates.shift) << 1;
|
|
2067
1044
|
const findStateIndex = (hash: number, state: Value[]) => {
|
|
2068
|
-
const mask =
|
|
1045
|
+
const mask = seenStates.slots.length - 1;
|
|
2069
1046
|
for (let slot = getSlot(hash); ; slot = (slot + 2) & mask) {
|
|
2070
|
-
const entry =
|
|
1047
|
+
const entry = seenStates.slots[slot + 1];
|
|
2071
1048
|
if (entry === 0) return -1;
|
|
2072
|
-
if (
|
|
1049
|
+
if (seenStates.slots[slot] === hash && isSameState(fingerprintStates[entry - 1], state)) {
|
|
2073
1050
|
return entry - 1;
|
|
2074
1051
|
}
|
|
2075
1052
|
}
|
|
2076
1053
|
};
|
|
2077
1054
|
const insertSeen = (hash: number, entry: number) => {
|
|
2078
|
-
const mask =
|
|
1055
|
+
const mask = seenStates.slots.length - 1;
|
|
2079
1056
|
let slot = getSlot(hash);
|
|
2080
|
-
while (
|
|
2081
|
-
|
|
2082
|
-
|
|
1057
|
+
while (seenStates.slots[slot + 1] !== 0) slot = (slot + 2) & mask;
|
|
1058
|
+
seenStates.slots[slot] = hash;
|
|
1059
|
+
seenStates.slots[slot + 1] = entry;
|
|
2083
1060
|
};
|
|
2084
1061
|
const markSeen = (hash: number, index: number) => {
|
|
2085
|
-
|
|
2086
|
-
if (
|
|
2087
|
-
const slots =
|
|
2088
|
-
|
|
2089
|
-
|
|
1062
|
+
seenStates.size++;
|
|
1063
|
+
if (seenStates.size * 4 > seenStates.slots.length) {
|
|
1064
|
+
const slots = seenStates.slots;
|
|
1065
|
+
seenStates.slots = new Int32Array(slots.length * 2);
|
|
1066
|
+
seenStates.shift--;
|
|
2090
1067
|
for (let slot = 0; slot < slots.length; slot += 2) {
|
|
2091
1068
|
if (slots[slot + 1] !== 0) insertSeen(slots[slot], slots[slot + 1]);
|
|
2092
1069
|
}
|
|
@@ -2218,7 +1195,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2218
1195
|
if (isCanonicalizedFirst) canonicalizeState(successor.state);
|
|
2219
1196
|
const fingerprintState = getFingerprintState(successor.state);
|
|
2220
1197
|
const hash = getStateHash(fingerprintState);
|
|
2221
|
-
const
|
|
1198
|
+
const foundIndex = findStateIndex(hash, fingerprintState);
|
|
2222
1199
|
const isStateInModel = search.satisfiesConstraints(successor.state, state);
|
|
2223
1200
|
if (isStateInModel) search.trackStatePossible(successor.state);
|
|
2224
1201
|
const isInModel = isStateInModel && search.satisfiesActionConstraints(state, successor.state);
|
|
@@ -2227,7 +1204,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2227
1204
|
fingerprintModelState(fingerprintState);
|
|
2228
1205
|
successor.state.forEach(markFingerprinted);
|
|
2229
1206
|
}
|
|
2230
|
-
const existing = isInModel ?
|
|
1207
|
+
const existing = isInModel ? foundIndex : -1;
|
|
2231
1208
|
if (source && isInModel) {
|
|
2232
1209
|
stateWriter?.writeSuccessor(
|
|
2233
1210
|
source,
|
|
@@ -2265,8 +1242,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2265
1242
|
// TLC replays the expansion and skips the invariants of a state it has seen, the failed one
|
|
2266
1243
|
// included unless the constraints exclude it. When the replay fails, TLC reports where and
|
|
2267
1244
|
// leaves out the outdegree.
|
|
2268
|
-
const replay =
|
|
2269
|
-
return
|
|
1245
|
+
const replay = captureOutput(() => replayNext(index));
|
|
1246
|
+
return createFailureResult(
|
|
2270
1247
|
error,
|
|
2271
1248
|
appendTraceOutput(getFailedTrace(index, successor), replay.lines),
|
|
2272
1249
|
replay.result ?? { outDegrees: getFailureOutDegrees() },
|
|
@@ -2309,8 +1286,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2309
1286
|
try {
|
|
2310
1287
|
outcome.result = visitInitialState(state);
|
|
2311
1288
|
} catch (error) {
|
|
2312
|
-
const replay =
|
|
2313
|
-
outcome.result =
|
|
1289
|
+
const replay = captureOutput(replayInit);
|
|
1290
|
+
outcome.result = createFailureResult(
|
|
2314
1291
|
error,
|
|
2315
1292
|
{ trace: [], traceOutput: replay.lines },
|
|
2316
1293
|
{ initialState: state, ...replay.result, isInitial: true },
|
|
@@ -2324,7 +1301,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2324
1301
|
// TLC prints an illegal initial state with null for each variable it leaves undefined, and
|
|
2325
1302
|
// stops before it prints the statistics.
|
|
2326
1303
|
if (error instanceof TlaIllegalStateError) {
|
|
2327
|
-
const illegal =
|
|
1304
|
+
const illegal = createFailureResult(
|
|
2328
1305
|
error,
|
|
2329
1306
|
{ trace: [] },
|
|
2330
1307
|
{ initialState: error.state.map((value) => value ?? createModelValue("null")) },
|
|
@@ -2335,8 +1312,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2335
1312
|
};
|
|
2336
1313
|
}
|
|
2337
1314
|
// TLC prints the error before it replays the initial predicate with its call stack.
|
|
2338
|
-
const replay =
|
|
2339
|
-
return
|
|
1315
|
+
const replay = captureOutput(replayInit);
|
|
1316
|
+
return createFailureResult(
|
|
2340
1317
|
error,
|
|
2341
1318
|
{ trace: [], traceOutput: replay.lines },
|
|
2342
1319
|
{ ...replay.result, isInitial: true },
|
|
@@ -2421,18 +1398,18 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2421
1398
|
}
|
|
2422
1399
|
};
|
|
2423
1400
|
const replayFailedNext = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
2424
|
-
const live =
|
|
1401
|
+
const live = captureOutput(() => addFailedLiveState(index, liveSuccessors));
|
|
2425
1402
|
if (live.result) {
|
|
2426
1403
|
const result = { callStack: live.result, fingerprint: undefined, isLiveCallStack: true };
|
|
2427
1404
|
return { result, lines: live.lines };
|
|
2428
1405
|
}
|
|
2429
|
-
const replay =
|
|
1406
|
+
const replay = captureOutput(() => replayNext(index));
|
|
2430
1407
|
return { result: replay.result, lines: [...live.lines, ...replay.lines] };
|
|
2431
1408
|
};
|
|
2432
1409
|
// TLC reports a stack overflow while it computes next states without replaying it, with the
|
|
2433
1410
|
// behavior up to the state it expands.
|
|
2434
1411
|
const reportNextStateOverflow = (index: number) =>
|
|
2435
|
-
|
|
1412
|
+
createFailureResult(createStackOverflowError(), getStateTrace(index));
|
|
2436
1413
|
// After the trace, TLC replays the next-state relation with its call stack, printing again.
|
|
2437
1414
|
const reportNextStateFailure = (
|
|
2438
1415
|
error: unknown,
|
|
@@ -2441,7 +1418,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2441
1418
|
) => {
|
|
2442
1419
|
if (isStackOverflow(error)) return reportNextStateOverflow(index);
|
|
2443
1420
|
const replay = replayFailedNext(index, liveSuccessors);
|
|
2444
|
-
return
|
|
1421
|
+
return createFailureResult(
|
|
2445
1422
|
withNextStateExitCode(error),
|
|
2446
1423
|
appendTraceOutput(getStateTrace(index), replay.lines),
|
|
2447
1424
|
{ isNextState: true, ...replay.result },
|
|
@@ -2462,10 +1439,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2462
1439
|
// which it reports with the trace before it rethrows. The error stops its worker before it
|
|
2463
1440
|
// adds the state to the behavior graph.
|
|
2464
1441
|
const replay = is174
|
|
2465
|
-
?
|
|
1442
|
+
? captureOutput(() => replayNext(index))
|
|
2466
1443
|
: replayFailedNext(index, liveSuccessors);
|
|
2467
|
-
if (is174 && error instanceof TlaEvaluationError && !
|
|
2468
|
-
outcome.result =
|
|
1444
|
+
if (is174 && error instanceof TlaEvaluationError && !isHeadedError(error)) {
|
|
1445
|
+
outcome.result = createFailureResult(
|
|
2469
1446
|
new TlaEvaluationError(`${getWrappedException(error)}${error.message}`, error),
|
|
2470
1447
|
appendTraceOutput({ trace: [] }, replay.lines),
|
|
2471
1448
|
{ isNextState: true, ...replay.result },
|
|
@@ -2486,7 +1463,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2486
1463
|
true,
|
|
2487
1464
|
)
|
|
2488
1465
|
: undefined;
|
|
2489
|
-
outcome.result =
|
|
1466
|
+
outcome.result = createFailureResult(
|
|
2490
1467
|
error,
|
|
2491
1468
|
appendTraceOutput(
|
|
2492
1469
|
traceFailure ? getStateTrace(index) : getFailedTrace(index, successor),
|
|
@@ -2501,7 +1478,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2501
1478
|
const result = outcome.result;
|
|
2502
1479
|
// TLC 1.7.4's worker stops at a violation.
|
|
2503
1480
|
if (result?.violation && !is174) {
|
|
2504
|
-
const live =
|
|
1481
|
+
const live = captureOutput(() => addFailedLiveState(index, liveSuccessors));
|
|
2505
1482
|
return {
|
|
2506
1483
|
...result,
|
|
2507
1484
|
violation: appendTraceOutput(result.violation, live.lines),
|
|
@@ -2530,7 +1507,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2530
1507
|
// TLC's worker still adds the deadlocked state to the behavior graph after it reports the
|
|
2531
1508
|
// deadlock, and reports a temporal property that this violates. Then it counts the state as
|
|
2532
1509
|
// expanded.
|
|
2533
|
-
const live =
|
|
1510
|
+
const live = captureOutput(() => {
|
|
2534
1511
|
try {
|
|
2535
1512
|
return { additional: addLiveState()?.violation };
|
|
2536
1513
|
} catch (error) {
|
|
@@ -2559,7 +1536,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2559
1536
|
const unexpected = new TlaEvaluationError(
|
|
2560
1537
|
`${isEvalException(error) ? UNEXPECTED_EVAL_EXCEPTION : UNEXPECTED_EXCEPTION}${error.message}`,
|
|
2561
1538
|
);
|
|
2562
|
-
return
|
|
1539
|
+
return createFailureResult(
|
|
2563
1540
|
setExitCode(unexpected, EXIT_STATUS.error),
|
|
2564
1541
|
{ trace: [] },
|
|
2565
1542
|
{ outDegrees: getFailureOutDegrees() },
|
|
@@ -2570,7 +1547,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2570
1547
|
const replay = getReplayFailure((tracing) =>
|
|
2571
1548
|
liveness?.addState(index, state, liveSuccessors, tracing),
|
|
2572
1549
|
);
|
|
2573
|
-
return
|
|
1550
|
+
return createFailureResult(error, getStateTrace(index), {
|
|
2574
1551
|
outDegrees: getFailureOutDegrees(),
|
|
2575
1552
|
callStack: replay?.callStack.length ? replay.callStack : undefined,
|
|
2576
1553
|
isNextState: true,
|
|
@@ -2607,14 +1584,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2607
1584
|
steps.map((step) => step.state),
|
|
2608
1585
|
loopStart,
|
|
2609
1586
|
);
|
|
2610
|
-
const
|
|
2611
|
-
const
|
|
1587
|
+
const cycleStart = path[loopStart];
|
|
1588
|
+
const cycleEnd = path[path.length - 1];
|
|
2612
1589
|
const lastState = steps[steps.length - 1].state;
|
|
2613
1590
|
const loop =
|
|
2614
|
-
|
|
1591
|
+
cycleStart === cycleEnd
|
|
2615
1592
|
? { result: undefined, lines: [] }
|
|
2616
|
-
:
|
|
2617
|
-
const isStutteringWarned =
|
|
1593
|
+
: captureOutput(() => findStepAction(cycleEnd, lastState, states[cycleStart], false));
|
|
1594
|
+
const isStutteringWarned = cycleStart === cycleEnd && lasso.isCycleConstrained;
|
|
2618
1595
|
return reportViolation(
|
|
2619
1596
|
"liveness-violation",
|
|
2620
1597
|
{
|
|
@@ -2627,11 +1604,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2627
1604
|
warning: isStutteringWarned ? getStutteringWarning() : undefined,
|
|
2628
1605
|
},
|
|
2629
1606
|
() =>
|
|
2630
|
-
|
|
1607
|
+
cycleStart === cycleEnd
|
|
2631
1608
|
? getStepAction(trace[trace.length - 1])
|
|
2632
1609
|
: loop.result
|
|
2633
1610
|
? toActionValue(loop.result)
|
|
2634
|
-
: createActionRecord(findSuccessorWithFingerprint(lastState,
|
|
1611
|
+
: createActionRecord(findSuccessorWithFingerprint(lastState, cycleStart)?.action),
|
|
2635
1612
|
);
|
|
2636
1613
|
};
|
|
2637
1614
|
const isPeriodic = liveness !== undefined && options.livenessCheck !== "final";
|
|
@@ -2710,7 +1687,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
2710
1687
|
});
|
|
2711
1688
|
}
|
|
2712
1689
|
} catch (error) {
|
|
2713
|
-
return
|
|
1690
|
+
return createFailureResult(error, { trace: [] });
|
|
2714
1691
|
}
|
|
2715
1692
|
return createSuccess();
|
|
2716
1693
|
};
|