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