tla-ts 0.0.9 → 0.0.10-dev.28c823e4b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -1
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +28 -28
- package/dist/deciders.js +43 -43
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +106 -10
- package/dist/index.d.ts +106 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +116 -36
- package/dist/prove.js +116 -36
- package/dist/run.cjs +143 -31
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +129 -104
- package/dist/transfer.js +129 -104
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +4 -23
- package/src/bags.ts +99 -102
- package/src/builtins.ts +40 -78
- package/src/bundled-modules.ts +1 -8
- package/src/check.ts +599 -388
- package/src/cli/options.ts +11 -6
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +136 -0
- package/src/cli/shared.ts +18 -11
- package/src/cli/tlapm.ts +0 -12
- package/src/cli/tlc-arguments.ts +640 -0
- package/src/cli/tlc-usage.ts +361 -0
- package/src/cli/tlc.ts +538 -220
- package/src/cli/typescript.ts +23 -0
- package/src/cli/xml-exporter.ts +4 -16
- package/src/cli.ts +0 -1
- package/src/codegen.ts +191 -64
- package/src/config.ts +140 -109
- package/src/coverage.ts +837 -0
- package/src/dependencies.ts +6 -40
- package/src/dfid.ts +618 -0
- package/src/environment.ts +240 -118
- package/src/errors.ts +70 -55
- package/src/evaluate.ts +596 -339
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +10 -10
- package/src/index.ts +3 -0
- package/src/instances.ts +79 -11
- package/src/java-overrides.ts +4 -19
- package/src/json-reader.ts +455 -0
- package/src/json.ts +255 -139
- package/src/levels.ts +8 -17
- package/src/lexer.ts +80 -100
- package/src/liveness-checker.ts +82 -119
- package/src/liveness.ts +112 -64
- package/src/obligations/action.ts +4 -28
- package/src/obligations/anonymize.ts +84 -80
- package/src/obligations/equality.ts +1 -1
- package/src/obligations/expression.ts +2 -19
- package/src/obligations/format.ts +1 -9
- package/src/obligations/generate.ts +1 -11
- package/src/obligations/index.ts +0 -11
- package/src/obligations/levels.ts +4 -8
- package/src/obligations/module.ts +1 -15
- package/src/obligations/normalize.ts +5 -24
- package/src/obligations/operators.ts +1 -2
- package/src/obligations/pragma.ts +1 -10
- package/src/obligations/printer.ts +47 -46
- package/src/obligations/proof.ts +1 -5
- package/src/obligations/regroup.ts +1 -4
- package/src/obligations/simplify.ts +3 -14
- package/src/obligations/source.ts +1 -21
- package/src/obligations/subexpression.ts +5 -11
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +8 -14
- package/src/obligations/tuples.ts +3 -9
- package/src/parallel-worker.ts +29 -39
- package/src/parallel.ts +53 -44
- package/src/parser.ts +565 -282
- package/src/pcal/ast.ts +53 -86
- package/src/pcal/parse.ts +144 -219
- package/src/pcal/tokenize.ts +91 -131
- package/src/pcal/translate.ts +83 -130
- package/src/pcal/validate.ts +48 -68
- package/src/pretty-print.ts +7 -8
- package/src/prover/decide-pool.ts +5 -10
- package/src/prover/deciders.ts +0 -4
- package/src/prover/first-order.ts +0 -11
- package/src/prover/isabelle/decide.ts +0 -6
- package/src/prover/isabelle/encode.ts +11 -23
- package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
- package/src/prover/isabelle/isar/method.ts +25 -38
- package/src/prover/isabelle/isar/proof.ts +1 -10
- package/src/prover/isabelle/isar/statement.ts +1 -6
- package/src/prover/isabelle/isar/theory.ts +15 -26
- package/src/prover/isabelle/isar/type-check.ts +11 -25
- package/src/prover/isabelle/provers/blast/blast.ts +10 -41
- package/src/prover/isabelle/provers/blast/branch.ts +1 -32
- package/src/prover/isabelle/provers/blast/prove.ts +1 -35
- package/src/prover/isabelle/provers/blast/rules.ts +6 -44
- package/src/prover/isabelle/provers/blast/state.ts +2 -28
- package/src/prover/isabelle/provers/blast/term.ts +9 -36
- package/src/prover/isabelle/provers/clasimp.ts +1 -13
- package/src/prover/isabelle/provers/classical.ts +14 -42
- package/src/prover/isabelle/provers/hypsubst.ts +11 -25
- package/src/prover/isabelle/pure/bicompose.ts +16 -13
- package/src/prover/isabelle/pure/consts.ts +1 -7
- package/src/prover/isabelle/pure/conv.ts +1 -9
- package/src/prover/isabelle/pure/drule.ts +24 -40
- package/src/prover/isabelle/pure/envir.ts +3 -52
- package/src/prover/isabelle/pure/goal.ts +1 -7
- package/src/prover/isabelle/pure/interrupt.ts +0 -5
- package/src/prover/isabelle/pure/list.ts +0 -3
- package/src/prover/isabelle/pure/logic.ts +1 -14
- package/src/prover/isabelle/pure/name.ts +2 -9
- package/src/prover/isabelle/pure/net.ts +3 -59
- package/src/prover/isabelle/pure/object-logic.ts +3 -10
- package/src/prover/isabelle/pure/pattern.ts +2 -19
- package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
- package/src/prover/isabelle/pure/rewriter.ts +26 -58
- package/src/prover/isabelle/pure/search.ts +3 -10
- package/src/prover/isabelle/pure/seq.ts +1 -10
- package/src/prover/isabelle/pure/simplifier.ts +4 -12
- package/src/prover/isabelle/pure/table.ts +1 -31
- package/src/prover/isabelle/pure/tactic.ts +12 -22
- package/src/prover/isabelle/pure/tactical.ts +6 -12
- package/src/prover/isabelle/pure/term-ord.ts +2 -6
- package/src/prover/isabelle/pure/term.ts +2 -43
- package/src/prover/isabelle/pure/thm.ts +13 -36
- package/src/prover/isabelle/pure/type.ts +2 -15
- package/src/prover/isabelle/pure/unify.ts +20 -30
- package/src/prover/isabelle/pure/variable.ts +3 -7
- package/src/prover/isabelle/tla/classical-setup.ts +9 -19
- package/src/prover/isabelle/tla/context.ts +8 -16
- package/src/prover/isabelle/tla/logic.ts +4 -11
- package/src/prover/isabelle/tla/simpdata.ts +46 -34
- package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
- package/src/prover/ocaml.ts +0 -6
- package/src/prover/prep/action.ts +4 -36
- package/src/prover/prep/enabled-axioms.ts +12 -19
- package/src/prover/prep/fingerprint.ts +0 -16
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +9 -36
- package/src/prover/prep/normalize.ts +4 -28
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +0 -36
- package/src/prover/ptl/decide.ts +7 -12
- package/src/prover/ptl/encode.ts +14 -36
- package/src/prover/ptl/sat.ts +24 -32
- package/src/prover/ptl/tableau.ts +12 -26
- package/src/prover/smt/axioms.ts +0 -7
- package/src/prover/smt/context.ts +19 -26
- package/src/prover/smt/data.ts +51 -54
- package/src/prover/smt/encode.ts +14 -35
- package/src/prover/smt/extensionality.ts +0 -10
- package/src/prover/smt/flatten.ts +3 -22
- package/src/prover/smt/format.ts +5 -10
- package/src/prover/smt/instances.ts +0 -10
- package/src/prover/smt/rewrite.ts +66 -101
- package/src/prover/smt/solver/act-cache.ts +0 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -48
- package/src/prover/smt/solver/array.ts +1 -3
- package/src/prover/smt/solver/asserted-formulas.ts +1 -43
- package/src/prover/smt/solver/ast-lt.ts +1 -11
- package/src/prover/smt/solver/ast-util.ts +1 -6
- package/src/prover/smt/solver/ast.ts +1 -143
- package/src/prover/smt/solver/auf-solver.ts +6 -39
- package/src/prover/smt/solver/case-split-queue.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +1 -18
- package/src/prover/smt/solver/clause.ts +1 -27
- package/src/prover/smt/solver/conflict-resolution.ts +0 -9
- package/src/prover/smt/solver/context.ts +4 -61
- package/src/prover/smt/solver/ctx-simplify.ts +14 -41
- package/src/prover/smt/solver/der.ts +2 -21
- package/src/prover/smt/solver/dyn-ack.ts +1 -11
- package/src/prover/smt/solver/e-matching.ts +3 -34
- package/src/prover/smt/solver/enode.ts +1 -21
- package/src/prover/smt/solver/expr-ref.ts +1 -5
- package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
- package/src/prover/smt/solver/fingerprints.ts +1 -12
- package/src/prover/smt/solver/flat-literals.ts +1 -9
- package/src/prover/smt/solver/goal.ts +2 -14
- package/src/prover/smt/solver/hash.ts +0 -8
- package/src/prover/smt/solver/hashtable.ts +1 -12
- package/src/prover/smt/solver/internalizer.ts +6 -98
- package/src/prover/smt/solver/lbool.ts +1 -2
- package/src/prover/smt/solver/literal.ts +0 -3
- package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
- package/src/prover/smt/solver/lp/constraints.ts +2 -8
- package/src/prover/smt/solver/lp/containers.ts +12 -30
- package/src/prover/smt/solver/lp/core-solver.ts +10 -31
- package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
- package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
- package/src/prover/smt/solver/lp/dependency.ts +1 -4
- package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
- package/src/prover/smt/solver/lp/explanation.ts +1 -6
- package/src/prover/smt/solver/lp/gomory.ts +9 -22
- package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
- package/src/prover/smt/solver/lp/hnf.ts +11 -26
- package/src/prover/smt/solver/lp/int-cube.ts +15 -36
- package/src/prover/smt/solver/lp/int-solver.ts +4 -34
- package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
- package/src/prover/smt/solver/lp/lar-term.ts +1 -5
- package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
- package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
- package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
- package/src/prover/smt/solver/lp/nex.ts +1 -6
- package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
- package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
- package/src/prover/smt/solver/lp/nla-core.ts +35 -130
- package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
- package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
- package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
- package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
- package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
- package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
- package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
- package/src/prover/smt/solver/lp/nla-order.ts +2 -13
- package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
- package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
- package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
- package/src/prover/smt/solver/lp/nla-types.ts +1 -11
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
- package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
- package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
- package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
- package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
- package/src/prover/smt/solver/lp/pdd.ts +7 -70
- package/src/prover/smt/solver/lp/random-updater.ts +1 -8
- package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
- package/src/prover/smt/solver/lp/union-find.ts +1 -6
- package/src/prover/smt/solver/mam-compiler.ts +14 -56
- package/src/prover/smt/solver/mam-interpreter.ts +1 -21
- package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
- package/src/prover/smt/solver/model-checker.ts +2 -36
- package/src/prover/smt/solver/model-evaluator.ts +3 -29
- package/src/prover/smt/solver/model-finder.ts +3 -15
- package/src/prover/smt/solver/model-generator.ts +1 -12
- package/src/prover/smt/solver/model-macro-solver.ts +12 -69
- package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
- package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
- package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
- package/src/prover/smt/solver/nlsat/explain.ts +3 -47
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
- package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
- package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
- package/src/prover/smt/solver/nlsat/solver.ts +7 -67
- package/src/prover/smt/solver/nlsat/types.ts +1 -8
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
- package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
- package/src/prover/smt/solver/nnf.ts +3 -38
- package/src/prover/smt/solver/pattern-inference.ts +2 -15
- package/src/prover/smt/solver/poly-rewriter.ts +3 -23
- package/src/prover/smt/solver/propagate-values.ts +1 -10
- package/src/prover/smt/solver/proto-model.ts +3 -48
- package/src/prover/smt/solver/pull-quant.ts +1 -12
- package/src/prover/smt/solver/qe-lite-der.ts +1 -29
- package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
- package/src/prover/smt/solver/qe-lite.ts +3 -33
- package/src/prover/smt/solver/qi-queue.ts +1 -16
- package/src/prover/smt/solver/quant-tactics.ts +5 -22
- package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
- package/src/prover/smt/solver/quantifier-manager.ts +1 -8
- package/src/prover/smt/solver/random-gen.ts +1 -2
- package/src/prover/smt/solver/rational.ts +1 -8
- package/src/prover/smt/solver/ref-vector.ts +1 -6
- package/src/prover/smt/solver/relevancy.ts +2 -15
- package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
- package/src/prover/smt/solver/rewriter.ts +3 -85
- package/src/prover/smt/solver/rlimit.ts +2 -20
- package/src/prover/smt/solver/smtlib-parser.ts +2 -37
- package/src/prover/smt/solver/solver.ts +23 -34
- package/src/prover/smt/solver/sort.ts +1 -5
- package/src/prover/smt/solver/sticky-generations.ts +0 -5
- package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
- package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
- package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
- package/src/prover/smt/solver/theory-lra-model.ts +4 -19
- package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
- package/src/prover/smt/solver/theory-lra-state.ts +3 -8
- package/src/prover/smt/solver/theory-lra.ts +1 -8
- package/src/prover/smt/solver/var-subst.ts +2 -26
- package/src/prover/smt/table.ts +0 -8
- package/src/prover/tlapm/cache.ts +20 -25
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +12 -17
- package/src/prover/verdict.ts +0 -2
- package/src/prover/zenon/check/check.ts +0 -9
- package/src/prover/zenon/check/definitions.ts +5 -15
- package/src/prover/zenon/check/equality.ts +0 -8
- package/src/prover/zenon/check/functions.ts +0 -4
- package/src/prover/zenon/check/keys.ts +0 -7
- package/src/prover/zenon/check/propositional.ts +0 -3
- package/src/prover/zenon/check/records.ts +0 -5
- package/src/prover/zenon/check/relations.ts +0 -13
- package/src/prover/zenon/check/rewrites.ts +0 -6
- package/src/prover/zenon/check/sets.ts +0 -3
- package/src/prover/zenon/check/terms.ts +0 -17
- package/src/prover/zenon/check/tla.ts +0 -6
- package/src/prover/zenon/decide.ts +0 -12
- package/src/prover/zenon/encode.ts +1 -8
- package/src/prover/zenon/eqrel.ts +0 -13
- package/src/prover/zenon/equality-rules.ts +0 -4
- package/src/prover/zenon/expr.ts +1 -26
- package/src/prover/zenon/index-table.ts +17 -38
- package/src/prover/zenon/isar-case.ts +9 -19
- package/src/prover/zenon/isar.ts +1 -29
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +0 -9
- package/src/prover/zenon/mltoll.ts +54 -76
- package/src/prover/zenon/node.ts +1 -11
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +2 -7
- package/src/prover/zenon/phrase.ts +1 -11
- package/src/prover/zenon/proof.ts +0 -9
- package/src/prover/zenon/propositional-rules.ts +0 -5
- package/src/prover/zenon/rules.ts +2 -6
- package/src/prover/zenon/search.ts +1 -17
- package/src/prover/zenon/tla/functions.ts +57 -29
- package/src/prover/zenon/tla/llproof.ts +63 -70
- package/src/prover/zenon/tla/records.ts +56 -27
- package/src/prover/zenon/tla/rewrites.ts +12 -19
- package/src/prover/zenon/tla/sets.ts +68 -39
- package/src/prover/zenon/tla/terms.ts +0 -6
- package/src/prover/zenon/tla/tla.ts +59 -58
- package/src/randomization.ts +81 -35
- package/src/resolve.ts +12 -112
- package/src/runtime.ts +22 -22
- package/src/sany/builtins.ts +2 -5
- package/src/sany/generator.ts +149 -252
- package/src/sany/levels.ts +6 -34
- package/src/sany/lexer.ts +41 -61
- package/src/sany/linter.ts +1 -9
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +0 -31
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +29 -63
- package/src/sany/selectors.ts +15 -39
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +13 -63
- package/src/search.ts +495 -155
- package/src/simulate.ts +685 -0
- package/src/spec-description.ts +176 -69
- package/src/standard-definitions.ts +0 -4
- package/src/standard-modules.ts +254 -69
- package/src/state-graph.ts +50 -24
- package/src/subexpressions.ts +69 -52
- package/src/substitution-levels.ts +2 -3
- package/src/successors.ts +263 -94
- package/src/symmetry.ts +33 -25
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -67
- package/src/tlc/jar-data.ts +112 -6
- package/src/tlc/messages.ts +110 -44
- package/src/tlc/order.ts +37 -60
- package/src/tlc/random.ts +33 -45
- package/src/tlc/replay.ts +549 -217
- package/src/tlc/summary.ts +36 -47
- package/src/tlc/tlc-operators.ts +76 -41
- package/src/tlc/tlcext-operators.ts +139 -122
- package/src/tlc/trace-spec.ts +269 -0
- package/src/tlc/value-stream.ts +139 -0
- package/src/tlc/version.ts +1 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +481 -0
- package/src/typescript/collections.ts +600 -0
- package/src/typescript/compile.ts +65 -0
- package/src/typescript/context.ts +94 -0
- package/src/typescript/emit.ts +121 -0
- package/src/typescript/expressions.ts +496 -0
- package/src/typescript/formula.ts +152 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +163 -0
- package/src/typescript/names.ts +114 -0
- package/src/typescript/program.ts +48 -0
- package/src/typescript/properties.ts +139 -0
- package/src/typescript/scope.ts +112 -0
- package/src/typescript/steps.ts +165 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +780 -337
- package/src/worker.ts +7 -8
package/src/search.ts
CHANGED
|
@@ -10,17 +10,27 @@ import type {
|
|
|
10
10
|
CheckOptions,
|
|
11
11
|
InitialStatesProgress,
|
|
12
12
|
InitialStateViolation,
|
|
13
|
+
ModuleOperator,
|
|
13
14
|
Postcondition,
|
|
14
15
|
Violation,
|
|
15
16
|
} from "./check";
|
|
16
|
-
import type
|
|
17
|
+
import { parseConfig, type ConfigValue, type ModelConfig } from "./config";
|
|
18
|
+
import {
|
|
19
|
+
addCoverageRelation,
|
|
20
|
+
getCoverageLabel,
|
|
21
|
+
runAtCoverageNode,
|
|
22
|
+
type Coverage,
|
|
23
|
+
type CoverageKind,
|
|
24
|
+
} from "./coverage";
|
|
17
25
|
import { getReadVariables, isConstantLevel } from "./dependencies";
|
|
26
|
+
import { createEnvironment, type ResolvedModuleOperator } from "./environment";
|
|
18
27
|
import {
|
|
19
28
|
isStackOverflow,
|
|
20
29
|
TlaConfigError,
|
|
21
30
|
TlaEvaluationError,
|
|
22
31
|
TlaModuleError,
|
|
23
32
|
UNEXPECTED_EXCEPTION,
|
|
33
|
+
formatRange,
|
|
24
34
|
} from "./errors";
|
|
25
35
|
import {
|
|
26
36
|
describeNode,
|
|
@@ -29,7 +39,7 @@ import {
|
|
|
29
39
|
evaluateStartupDefinitions,
|
|
30
40
|
getStartupValue,
|
|
31
41
|
expectBoolean,
|
|
32
|
-
|
|
42
|
+
expectBooleanBody,
|
|
33
43
|
getDefinition,
|
|
34
44
|
type Context,
|
|
35
45
|
type Environment,
|
|
@@ -47,10 +57,30 @@ import {
|
|
|
47
57
|
import { expandTemporal, getLevel, type ScopedExpression, type TemporalProperty } from "./liveness";
|
|
48
58
|
import { prettyPrint } from "./pretty-print";
|
|
49
59
|
import { getPossibleCounts, type CheckerRuntime } from "./runtime";
|
|
60
|
+
import { getSpecificationValue, getSubscriptVariables } from "./spec-description";
|
|
50
61
|
import { getRepresentative, getSymmetryGroup } from "./symmetry";
|
|
51
|
-
import {
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
import {
|
|
63
|
+
formatInnerMessage,
|
|
64
|
+
formatNestedMessage,
|
|
65
|
+
MESSAGE_CODE,
|
|
66
|
+
MISSING_INIT_174,
|
|
67
|
+
withHeadline,
|
|
68
|
+
} from "./tlc/messages";
|
|
69
|
+
import { createTlcOrder } from "./tlc/order";
|
|
70
|
+
import { getTlcFingerprint, getTlcFingerprints, setFingerprintPolynomial } from "./tlc/fingerprint";
|
|
71
|
+
import type { TlcVersion } from "./tlc/version";
|
|
72
|
+
import {
|
|
73
|
+
formatValue,
|
|
74
|
+
getWrittenPairs,
|
|
75
|
+
isFunctionValue,
|
|
76
|
+
isUpdatedElementOf,
|
|
77
|
+
setAliasName,
|
|
78
|
+
setStringOrder,
|
|
79
|
+
setValueOptions,
|
|
80
|
+
setViewText,
|
|
81
|
+
toFiniteFunction,
|
|
82
|
+
type Value,
|
|
83
|
+
} from "./values";
|
|
54
84
|
|
|
55
85
|
interface NamedExpression {
|
|
56
86
|
name: string;
|
|
@@ -58,14 +88,18 @@ interface NamedExpression {
|
|
|
58
88
|
scope: Scope | undefined;
|
|
59
89
|
}
|
|
60
90
|
|
|
91
|
+
interface CoveredCheck {
|
|
92
|
+
expression: Expression;
|
|
93
|
+
scope: Scope | undefined;
|
|
94
|
+
node: number;
|
|
95
|
+
}
|
|
96
|
+
|
|
61
97
|
interface StateCheck extends NamedExpression {
|
|
62
98
|
variables: number[] | undefined;
|
|
63
99
|
membership: Membership | undefined;
|
|
64
|
-
// The whole predicate that TLC evaluates for the check, of which the expression is a conjunct.
|
|
65
100
|
predicate: Expression;
|
|
66
101
|
}
|
|
67
102
|
|
|
68
|
-
// A conjunct `x \in S` whose S reads no variables.
|
|
69
103
|
interface Membership {
|
|
70
104
|
variable: number;
|
|
71
105
|
set: Expression;
|
|
@@ -84,6 +118,7 @@ interface Specification {
|
|
|
84
118
|
next: Expression | undefined;
|
|
85
119
|
scope: Scope | undefined;
|
|
86
120
|
temporals: ScopedExpression[];
|
|
121
|
+
isPropertyFairness: boolean;
|
|
87
122
|
}
|
|
88
123
|
|
|
89
124
|
interface Properties {
|
|
@@ -95,13 +130,12 @@ interface Properties {
|
|
|
95
130
|
|
|
96
131
|
const START: SourceLocation = { line: 0, column: 0 };
|
|
97
132
|
|
|
98
|
-
|
|
133
|
+
const createIdentifier = (name: string): Expression => ({
|
|
99
134
|
kind: "Identifier",
|
|
100
135
|
name,
|
|
101
136
|
location: START,
|
|
102
137
|
});
|
|
103
138
|
|
|
104
|
-
// TLC leaves the kind out when it rejects arguments to the specification or a property.
|
|
105
139
|
const UNNAMED_ARGUMENT_KINDS = new Set(["name", "property"]);
|
|
106
140
|
|
|
107
141
|
const getConfigOperator = (kind: string, name: string, environment: Environment) => {
|
|
@@ -121,22 +155,25 @@ const getConfigOperator = (kind: string, name: string, environment: Environment)
|
|
|
121
155
|
return definition;
|
|
122
156
|
};
|
|
123
157
|
|
|
124
|
-
|
|
125
|
-
|
|
158
|
+
const isLiteralDefinition = (definition: Definition) =>
|
|
159
|
+
definition.body.kind === "Number" || definition.body.kind === "String";
|
|
160
|
+
|
|
126
161
|
const getConstantValue = (name: string, definition: Definition, environment: Environment) => {
|
|
127
|
-
if (
|
|
128
|
-
if (definition
|
|
162
|
+
if (environment.constants.has(name)) return environment.constants.get(name);
|
|
163
|
+
if (!isConstantLevel(definition, environment) || isLiteralDefinition(definition))
|
|
164
|
+
return undefined;
|
|
129
165
|
try {
|
|
130
166
|
return evaluate(createIdentifier(name), getContext(environment, undefined, undefined));
|
|
131
167
|
} catch (error) {
|
|
132
|
-
// TLC swallows whatever the definition throws, a stack overflow included.
|
|
133
168
|
if (error instanceof TlaEvaluationError || isStackOverflow(error)) return undefined;
|
|
134
169
|
throw error;
|
|
135
170
|
}
|
|
136
171
|
};
|
|
137
172
|
|
|
138
|
-
|
|
139
|
-
|
|
173
|
+
const getConfigDefinition = (kind: string, name: string, environment: Environment) => {
|
|
174
|
+
if (environment.constants.has(name)) {
|
|
175
|
+
throw new TlaConfigError(`The ${kind} ${name} cannot be a constant.`);
|
|
176
|
+
}
|
|
140
177
|
const definition = getConfigOperator(kind, name, environment);
|
|
141
178
|
if (getConstantValue(name, definition, environment) !== undefined) {
|
|
142
179
|
throw new TlaConfigError(`The ${kind} ${name} cannot be a constant.`);
|
|
@@ -144,7 +181,6 @@ export const getConfigDefinition = (kind: string, name: string, environment: Env
|
|
|
144
181
|
return definition;
|
|
145
182
|
};
|
|
146
183
|
|
|
147
|
-
// TLC also takes a constant that the configuration assigns a value, which must be TRUE.
|
|
148
184
|
const getConfigPredicate = (kind: string, name: string, environment: Environment) => {
|
|
149
185
|
const definition = environment.constants.has(name)
|
|
150
186
|
? undefined
|
|
@@ -167,26 +203,20 @@ export const reportInitialStatesProgress = (
|
|
|
167
203
|
}
|
|
168
204
|
};
|
|
169
205
|
|
|
170
|
-
|
|
171
|
-
|
|
206
|
+
interface StartupSpecification {
|
|
207
|
+
environment: Environment;
|
|
208
|
+
startupDefinitions: Definition[];
|
|
209
|
+
javaOverrides: JavaOverride[];
|
|
210
|
+
}
|
|
211
|
+
|
|
172
212
|
export const reportStartup = (
|
|
173
|
-
specification:
|
|
174
|
-
environment: Environment;
|
|
175
|
-
startupDefinitions: Definition[];
|
|
176
|
-
javaOverrides: JavaOverride[];
|
|
177
|
-
},
|
|
213
|
+
specification: StartupSpecification,
|
|
178
214
|
config: ModelConfig,
|
|
179
215
|
onProgress: CheckOptions["onProgress"],
|
|
180
216
|
) => {
|
|
181
217
|
const environment = specification.environment;
|
|
182
|
-
|
|
183
|
-
environment.runtime.warn = (code, text) => {
|
|
184
|
-
if (warned.has(text)) return;
|
|
185
|
-
warned.add(text);
|
|
186
|
-
onProgress?.({ kind: "warning", code, text });
|
|
187
|
-
};
|
|
218
|
+
environment.runtime.warn = (code, text) => onProgress?.({ kind: "warning", code, text });
|
|
188
219
|
onProgress?.({ kind: "parsed" });
|
|
189
|
-
// TLC loads the classes of the modules before it computes the constant definitions.
|
|
190
220
|
specification.javaOverrides.forEach((override) =>
|
|
191
221
|
onProgress?.({ kind: "java-override", ...override }),
|
|
192
222
|
);
|
|
@@ -202,7 +232,7 @@ const getInvariants = (names: string[], environment: Environment) => {
|
|
|
202
232
|
const analyzer = createLevelAnalyzer({
|
|
203
233
|
constants: new Set(environment.constants.keys()),
|
|
204
234
|
variables: new Set(environment.variables),
|
|
205
|
-
getDefinition: (name) =>
|
|
235
|
+
getDefinition: (name) => environment.definitions.get(name),
|
|
206
236
|
});
|
|
207
237
|
return names.flatMap((name) => {
|
|
208
238
|
const definition = getConfigPredicate("invariant", name, environment);
|
|
@@ -229,9 +259,11 @@ const getConjuncts = (expression: Expression, environment: Environment): Express
|
|
|
229
259
|
return expression.operands.flatMap((operand) => getConjuncts(operand, environment));
|
|
230
260
|
if (expression.kind === "Identifier" && !environment.constants.has(expression.name)) {
|
|
231
261
|
const definition = getDefinition(expression.name, environment);
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
262
|
+
const isUnfolded =
|
|
263
|
+
definition?.kind === "Operator" &&
|
|
264
|
+
definition.params.length === 0 &&
|
|
265
|
+
getStartupValue(definition, environment) === undefined;
|
|
266
|
+
if (isUnfolded) return getConjuncts(definition.body, environment);
|
|
235
267
|
}
|
|
236
268
|
return [expression];
|
|
237
269
|
};
|
|
@@ -256,7 +288,13 @@ const isConstantTrue = (item: ScopedExpression, environment: Environment, usage:
|
|
|
256
288
|
return true;
|
|
257
289
|
};
|
|
258
290
|
|
|
259
|
-
const getSpecification = (
|
|
291
|
+
const getSpecification = (
|
|
292
|
+
config: ModelConfig,
|
|
293
|
+
environment: Environment,
|
|
294
|
+
variableLocations: SourceLocation[],
|
|
295
|
+
getVariableOrder: () => string[],
|
|
296
|
+
onProgress: CheckOptions["onProgress"],
|
|
297
|
+
): Specification => {
|
|
260
298
|
if (config.specification === undefined) {
|
|
261
299
|
const getOperator = (name: string | undefined, description: string) => {
|
|
262
300
|
if (name === undefined) return undefined;
|
|
@@ -268,6 +306,7 @@ const getSpecification = (config: ModelConfig, environment: Environment): Specif
|
|
|
268
306
|
next: getOperator(config.next, "next state action"),
|
|
269
307
|
scope: undefined,
|
|
270
308
|
temporals: [],
|
|
309
|
+
isPropertyFairness: false,
|
|
271
310
|
};
|
|
272
311
|
}
|
|
273
312
|
if (config.init !== undefined || config.next !== undefined) {
|
|
@@ -278,16 +317,34 @@ const getSpecification = (config: ModelConfig, environment: Environment): Specif
|
|
|
278
317
|
const initConjuncts: ScopedExpression[] = [];
|
|
279
318
|
const nextActions: ScopedExpression[] = [];
|
|
280
319
|
const temporals: ScopedExpression[] = [];
|
|
281
|
-
const
|
|
282
|
-
|
|
320
|
+
const value = environment.constants.has(config.specification)
|
|
321
|
+
? environment.constants.get(config.specification)
|
|
322
|
+
: getConstantValue(
|
|
323
|
+
config.specification,
|
|
324
|
+
getConfigOperator("name", config.specification, environment),
|
|
325
|
+
environment,
|
|
326
|
+
);
|
|
283
327
|
if (value !== undefined) {
|
|
284
328
|
throw new TlaConfigError(
|
|
285
329
|
`The value of ${config.specification} is equal to ${formatValue(value)}`,
|
|
286
330
|
);
|
|
287
331
|
}
|
|
332
|
+
const definition = getConfigOperator("name", config.specification, environment);
|
|
333
|
+
const property = config.properties.length === 1 ? config.properties[0] : undefined;
|
|
334
|
+
let isUntaggedFound = false;
|
|
288
335
|
expandTemporal(definition.body, undefined, environment, false).forEach((item) => {
|
|
289
336
|
const conjunct = item.expression;
|
|
290
337
|
if (isConstantTrue(item, environment, "spec")) return;
|
|
338
|
+
const variableIndex =
|
|
339
|
+
conjunct.kind === "Identifier" && !isLocallyResolved(conjunct)
|
|
340
|
+
? environment.variableIndex.get(conjunct.name)
|
|
341
|
+
: undefined;
|
|
342
|
+
if (conjunct.kind === "Identifier" && variableIndex !== undefined) {
|
|
343
|
+
const range = variableLocations[variableIndex].range;
|
|
344
|
+
throw new TlaConfigError(
|
|
345
|
+
`The operator ${conjunct.name}, which equals ${range ? formatRange(range) : conjunct.name},\ncannot be used as a spec`,
|
|
346
|
+
);
|
|
347
|
+
}
|
|
291
348
|
if (conjunct.kind === "UnboundedQuantifier" && conjunct.isTemporal) {
|
|
292
349
|
throw setExitCode(
|
|
293
350
|
new TlaConfigError(
|
|
@@ -297,14 +354,41 @@ const getSpecification = (config: ModelConfig, environment: Environment): Specif
|
|
|
297
354
|
);
|
|
298
355
|
}
|
|
299
356
|
if (conjunct.kind === "Always" && conjunct.expression.kind === "BoxAction") {
|
|
357
|
+
const variables = getSubscriptVariables(
|
|
358
|
+
conjunct.expression.subscript,
|
|
359
|
+
item.scope,
|
|
360
|
+
environment,
|
|
361
|
+
);
|
|
362
|
+
if (variables === undefined) {
|
|
363
|
+
onProgress?.({
|
|
364
|
+
kind: "warning",
|
|
365
|
+
code: MESSAGE_CODE.subscriptUndetermined,
|
|
366
|
+
text: "TLC could not determine if the subscript of the next-state relation contains\nall state variables. Proceed with fingers crossed.",
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
getVariableOrder()
|
|
370
|
+
.filter((name) => variables !== undefined && !variables.includes(name))
|
|
371
|
+
.forEach((name) =>
|
|
372
|
+
onProgress?.({
|
|
373
|
+
kind: "warning",
|
|
374
|
+
code: MESSAGE_CODE.subscriptMissingVariable,
|
|
375
|
+
text: `The subscript of the next-state relation specified by the specification\ndoes not seem to contain the state variable ${name}`,
|
|
376
|
+
}),
|
|
377
|
+
);
|
|
378
|
+
if (nextActions.length > 0) {
|
|
379
|
+
throw new TlaConfigError(
|
|
380
|
+
"The specification contains more than one conjunct of the form [][Next]_v,\nbut TLC can handle only specifications with one next-state relation.",
|
|
381
|
+
);
|
|
382
|
+
}
|
|
300
383
|
nextActions.push({ expression: conjunct.expression.action, scope: item.scope });
|
|
301
384
|
return;
|
|
302
385
|
}
|
|
303
386
|
if (
|
|
304
387
|
conjunct.kind === "Always" &&
|
|
388
|
+
conjunct.expression.kind !== "Let" &&
|
|
389
|
+
conjunct.expression.kind !== "Label" &&
|
|
305
390
|
getLevel(conjunct.expression, item.scope, environment) < ACTION_LEVEL
|
|
306
391
|
) {
|
|
307
|
-
// TLC accepts the spec and fails when it builds the tableau of the temporal formulas.
|
|
308
392
|
throw setExitCode(
|
|
309
393
|
new TlaEvaluationError(
|
|
310
394
|
`TLC cannot handle the temporal formula ${describeRange(conjunct.expression)}`,
|
|
@@ -314,21 +398,17 @@ const getSpecification = (config: ModelConfig, environment: Environment): Specif
|
|
|
314
398
|
}
|
|
315
399
|
const level = getLevel(conjunct, item.scope, environment);
|
|
316
400
|
if (level === TEMPORAL_LEVEL) {
|
|
401
|
+
if (property === undefined || !item.path.includes(property)) isUntaggedFound = true;
|
|
317
402
|
temporals.push(item);
|
|
318
403
|
return;
|
|
319
404
|
}
|
|
320
405
|
if (level === ACTION_LEVEL) {
|
|
321
406
|
throw new TlaConfigError(
|
|
322
|
-
`TLC cannot handle
|
|
407
|
+
`TLC cannot handle this conjunct of the spec:\n${describeRange(conjunct)}`,
|
|
323
408
|
);
|
|
324
409
|
}
|
|
325
410
|
initConjuncts.push(item);
|
|
326
411
|
});
|
|
327
|
-
if (nextActions.length > 1) {
|
|
328
|
-
throw new TlaConfigError(
|
|
329
|
-
`The specification ${config.specification} must contain at most one [][Next]_vars`,
|
|
330
|
-
);
|
|
331
|
-
}
|
|
332
412
|
const items = [...initConjuncts, ...nextActions];
|
|
333
413
|
const getName = (index: number) => `$specification${index}`;
|
|
334
414
|
const scope = items.reduce<Scope | undefined>(
|
|
@@ -367,6 +447,7 @@ const getSpecification = (config: ModelConfig, environment: Environment): Specif
|
|
|
367
447
|
next: nextActions.length === 0 ? undefined : getReference(nextActions[0], initConjuncts.length),
|
|
368
448
|
scope,
|
|
369
449
|
temporals,
|
|
450
|
+
isPropertyFairness: temporals.length > 0 && !isUntaggedFound,
|
|
370
451
|
};
|
|
371
452
|
};
|
|
372
453
|
|
|
@@ -384,13 +465,9 @@ const getProperties = (
|
|
|
384
465
|
config.properties.forEach((name) => {
|
|
385
466
|
const definition = getConfigPredicate("property", name, environment);
|
|
386
467
|
if (!definition) return;
|
|
387
|
-
// TLC checks a property that is a state formula only on the initial states, so it warns about
|
|
388
|
-
// one as it processes the property, before the constraints.
|
|
389
468
|
if (getLevel(definition.body, undefined, environment) === VARIABLE_LEVEL) {
|
|
390
469
|
onProgress?.({ kind: "state-level-property", name });
|
|
391
470
|
}
|
|
392
|
-
// TLC 1.7.4 expands a property as it does a specification, so it doesn't unroll one that
|
|
393
|
-
// quantifies over a constant set.
|
|
394
471
|
const isProperty = environment.runtime.version !== "1.7.4";
|
|
395
472
|
expandTemporal(definition.body, undefined, environment, isProperty).forEach((item) => {
|
|
396
473
|
const conjunct = item.expression;
|
|
@@ -410,9 +487,6 @@ const getProperties = (
|
|
|
410
487
|
conjunct.kind === "Always" &&
|
|
411
488
|
getLevel(conjunct.expression, item.scope, environment) <= VARIABLE_LEVEL
|
|
412
489
|
) {
|
|
413
|
-
// TLC names the invariant by the operator the property asserts always holds, when it
|
|
414
|
-
// applies the operator to no arguments. The name of an operator another module defines
|
|
415
|
-
// resolves to its key, so the name comes from its definition.
|
|
416
490
|
const body = conjunct.expression;
|
|
417
491
|
const operator =
|
|
418
492
|
body.kind === "Identifier" && !isLocallyResolved(body)
|
|
@@ -435,7 +509,17 @@ const getProperties = (
|
|
|
435
509
|
return;
|
|
436
510
|
}
|
|
437
511
|
if (level === ACTION_LEVEL) {
|
|
438
|
-
|
|
512
|
+
const location = describeRange(conjunct);
|
|
513
|
+
const book = "Specifying Systems at https://lamport.azurewebsites.net/tla/book.html";
|
|
514
|
+
const advice =
|
|
515
|
+
conjunct.kind === "BoxAction"
|
|
516
|
+
? `To check that action ${partName} holds in *every* step of the behavior, define a temporal property by applying the "always" temporal operator ([]) to the formula at ${location} (compare page 90 of ${book}).`
|
|
517
|
+
: conjunct.kind === "AngleAction"
|
|
518
|
+
? `To check that infinitely many ${partName} steps occur, define a temporal property by applying the "always eventually" temporal operator combination ([]<>) to the formula at ${location} (compare page 91 of ${book}).`
|
|
519
|
+
: `To check that action ${partName} holds in *every* step of the behavior, define a temporal property: Let A be the formula at ${location}; rewrite A as [][A]_v, where v is a state function (typically the tuple of variables) (compare page 90 of ${book}).`;
|
|
520
|
+
throw new TlaConfigError(
|
|
521
|
+
`The formula ${partName} at ${location} is an action-level formula (i.e., it contains no temporal operators). Only temporal-level (or state-level) formulas are allowed under PROPERTY or PROPERTIES. ${advice}`,
|
|
522
|
+
);
|
|
439
523
|
}
|
|
440
524
|
properties.liveness.push({ name, expression: conjunct, scope: item.scope });
|
|
441
525
|
});
|
|
@@ -488,7 +572,6 @@ const getMembership = (
|
|
|
488
572
|
: undefined;
|
|
489
573
|
};
|
|
490
574
|
|
|
491
|
-
// TLC evaluates the body of an invariant that the configuration names.
|
|
492
575
|
const getPredicate = (expression: Expression, environment: Environment) => {
|
|
493
576
|
if (expression.kind !== "Identifier" || environment.constants.has(expression.name)) {
|
|
494
577
|
return expression;
|
|
@@ -502,7 +585,6 @@ const getPredicate = (expression: Expression, environment: Environment) => {
|
|
|
502
585
|
const getStateChecks = (named: NamedExpression[], environment: Environment): StateCheck[] =>
|
|
503
586
|
named.flatMap((item) =>
|
|
504
587
|
getConjuncts(item.expression, environment).map((expression) => {
|
|
505
|
-
// A LET or an argument in the scope can read variables the expression doesn't name.
|
|
506
588
|
const variables =
|
|
507
589
|
item.scope === undefined ? getReadVariables(expression, environment) : undefined;
|
|
508
590
|
return {
|
|
@@ -539,8 +621,7 @@ const isWideExpression = (expression: Expression): boolean =>
|
|
|
539
621
|
(expression.kind === "Apply" && DESERIALIZERS.has(expression.operator)) ||
|
|
540
622
|
getChildren(expression).some(isWideExpression);
|
|
541
623
|
|
|
542
|
-
// TLC fingerprints a string by the low byte of each character, so it merges states whose
|
|
543
|
-
// strings differ only above U+00FF. Strings reach a state from literals, the config, or files.
|
|
624
|
+
// TLC fingerprints a string by the low byte of each character, so it merges states whose strings differ only above U+00FF.
|
|
544
625
|
const hasWideString = (config: ModelConfig, environment: Environment) =>
|
|
545
626
|
config.constants.some(
|
|
546
627
|
(constant) =>
|
|
@@ -555,26 +636,26 @@ const hasWideString = (config: ModelConfig, environment: Environment) =>
|
|
|
555
636
|
|
|
556
637
|
interface Search {
|
|
557
638
|
properties: Properties;
|
|
639
|
+
toRecord: (state: Value[]) => Record<string, Value>;
|
|
640
|
+
evaluateAlias: (
|
|
641
|
+
alias: string,
|
|
642
|
+
state: Value[],
|
|
643
|
+
next: Value[] | undefined,
|
|
644
|
+
isTool: boolean,
|
|
645
|
+
) => Record<string, Value>;
|
|
558
646
|
spec: Specification;
|
|
559
647
|
getFingerprintState: (state: Value[]) => Value[];
|
|
560
648
|
getStoredFingerprints: (states: Value[][], fingerprintStates: Value[][]) => BigInt64Array;
|
|
561
649
|
getTlcOrder: () => number[];
|
|
562
650
|
isSymmetric: boolean;
|
|
563
|
-
// TLC drops a constraint that is a true constant formula.
|
|
564
651
|
isConstrained: boolean;
|
|
565
652
|
findViolatedInvariant: (state: Value[], parent?: Value[]) => StateCheck | undefined;
|
|
566
|
-
// Every invariant an initial state violates, which TLC reports with -continue.
|
|
567
653
|
getViolatedInvariants: (state: Value[]) => StateCheck[];
|
|
568
|
-
// The checks of a state that TLC evaluates when it replays the computation of the initial states
|
|
569
|
-
// or of the successors of a state, with an environment that records the call stack. The first
|
|
570
|
-
// returns the check that stops the replay, and the second false where TLC stops it.
|
|
571
|
-
// TLC fingerprints a replayed state that satisfies the constraints before it checks the rest.
|
|
572
654
|
checkReplayedInitialState: (
|
|
573
655
|
state: Value[],
|
|
574
656
|
tracing: Environment,
|
|
575
657
|
addFingerprint: () => void,
|
|
576
658
|
) => Pick<InitialStateViolation, "status" | "name"> | undefined;
|
|
577
|
-
// Adding the fingerprint of a successor tells whether TLC had not seen it yet.
|
|
578
659
|
checkReplayedSuccessor: (
|
|
579
660
|
state: Value[],
|
|
580
661
|
next: Value[],
|
|
@@ -585,14 +666,34 @@ interface Search {
|
|
|
585
666
|
findFailedInitialPredicate: (state: Value[]) => NamedExpression | undefined;
|
|
586
667
|
findViolatedActionProperty: (state: Value[], next: Value[]) => ActionProperty | undefined;
|
|
587
668
|
satisfiesActionConstraints: (state: Value[], next: Value[]) => boolean;
|
|
669
|
+
getExcludingConstraints: (state: Value[], next: Value[]) => string[];
|
|
588
670
|
trackStatePossible: (state: Value[]) => void;
|
|
589
671
|
trackActionPossible: (state: Value[], next: Value[]) => void;
|
|
590
672
|
findUnwitnessedPossible: () => Postcondition | undefined;
|
|
591
|
-
|
|
673
|
+
getReward: (state: Value[] | undefined, next: Value[], fallback: number) => number;
|
|
592
674
|
findPostconditionViolation: (isAfterViolation?: boolean) => Postcondition | undefined;
|
|
593
675
|
}
|
|
594
676
|
|
|
595
|
-
|
|
677
|
+
const toAliasRecord = (value: Value) => {
|
|
678
|
+
if (!isFunctionValue(value)) return undefined;
|
|
679
|
+
const pairs = getWrittenPairs(toFiniteFunction(value));
|
|
680
|
+
if (!pairs.every((pair) => typeof pair[0] === "string")) return undefined;
|
|
681
|
+
return Object.fromEntries(pairs.map((pair) => [String(pair[0]), pair[1]]));
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
export const getIncompleteSuccessorMessage = (
|
|
685
|
+
missing: string[],
|
|
686
|
+
action: string | undefined,
|
|
687
|
+
actionCount: number,
|
|
688
|
+
version: TlcVersion | undefined,
|
|
689
|
+
) => {
|
|
690
|
+
const subject =
|
|
691
|
+
actionCount === 1 ? "the next-state action" : `action ${action} of the next-state relation`;
|
|
692
|
+
const verb = version === "1.7.4" ? "assigned" : "defined";
|
|
693
|
+
return `Successor state is not completely specified by ${subject}. The following variable${missing.length > 1 ? "s are" : " is"} not ${verb}: ${missing.join(", ")}.\n`;
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
const getContext = (
|
|
596
697
|
environment: Environment,
|
|
597
698
|
state: Value[] | undefined,
|
|
598
699
|
next: Value[] | undefined,
|
|
@@ -602,7 +703,6 @@ export const getContext = (
|
|
|
602
703
|
const holds = (expression: Expression, context: Context, description: string) =>
|
|
603
704
|
expectBoolean(evaluate(expression, context), description);
|
|
604
705
|
|
|
605
|
-
// TLC names a check that is not a boolean by the location of the predicate it evaluates.
|
|
606
706
|
const holdsLikeTlc = (
|
|
607
707
|
expression: Expression,
|
|
608
708
|
context: Context,
|
|
@@ -615,17 +715,18 @@ const holdsLikeTlc = (
|
|
|
615
715
|
return value;
|
|
616
716
|
};
|
|
617
717
|
|
|
618
|
-
const
|
|
718
|
+
const getExpectedValue = (kind: string, expression: Expression, environment: Environment) => {
|
|
619
719
|
const definition =
|
|
620
720
|
expression.kind === "Identifier" ? getDefinition(expression.name, environment) : undefined;
|
|
621
721
|
const body = definition?.kind === "Operator" ? definition.body : expression;
|
|
622
722
|
const range = definition?.kind === "Operator" ? definition.bodyRange : undefined;
|
|
623
723
|
const location = range && body.kind !== "Number" ? formatRange(range) : describeNode(body);
|
|
624
|
-
return `TLC expected a
|
|
724
|
+
return `TLC expected a ${kind} value, but did not find one. ${location}`;
|
|
625
725
|
};
|
|
626
726
|
|
|
627
|
-
|
|
628
|
-
|
|
727
|
+
const getExpectedBoolean = (expression: Expression, environment: Environment) =>
|
|
728
|
+
getExpectedValue("boolean", expression, environment);
|
|
729
|
+
|
|
629
730
|
const holdsAsConjunct = (check: StateCheck, context: Context) =>
|
|
630
731
|
holdsLikeTlc(check.expression, context, (expression, environment) => {
|
|
631
732
|
holdsLikeTlc(check.predicate, context);
|
|
@@ -641,13 +742,9 @@ const trackPossible = (items: NamedExpression[], runtime: CheckerRuntime, contex
|
|
|
641
742
|
runtime.possibleCounts.set(item.name, isWitnessed ? count + 1 : count);
|
|
642
743
|
});
|
|
643
744
|
|
|
644
|
-
const getConstantFailure = (
|
|
645
|
-
expression: Expression,
|
|
646
|
-
environment: Environment,
|
|
647
|
-
description: string,
|
|
648
|
-
) => {
|
|
745
|
+
const getConstantFailure = (check: (context: Context) => boolean, environment: Environment) => {
|
|
649
746
|
try {
|
|
650
|
-
return
|
|
747
|
+
return check(getContext(environment, undefined, undefined))
|
|
651
748
|
? undefined
|
|
652
749
|
: { message: undefined };
|
|
653
750
|
} catch (error) {
|
|
@@ -661,25 +758,131 @@ export const findAssumptionViolation = (
|
|
|
661
758
|
environment: Environment,
|
|
662
759
|
): Omit<Violation, "loopStart"> | undefined => {
|
|
663
760
|
for (const assumption of assumptions.filter((candidate) => !candidate.isAxiom)) {
|
|
664
|
-
const failure = getConstantFailure(
|
|
761
|
+
const failure = getConstantFailure(
|
|
762
|
+
(context) =>
|
|
763
|
+
expectBooleanBody(evaluate(assumption.expression, context), assumption.expression),
|
|
764
|
+
environment,
|
|
765
|
+
);
|
|
665
766
|
if (failure) {
|
|
666
|
-
return { name:
|
|
767
|
+
return { name: describeNode(assumption.expression), trace: [], message: failure.message };
|
|
667
768
|
}
|
|
668
769
|
}
|
|
669
770
|
return undefined;
|
|
670
771
|
};
|
|
671
772
|
|
|
773
|
+
export const prepareSearch = (options: CheckOptions) => {
|
|
774
|
+
const config =
|
|
775
|
+
typeof options.config === "string"
|
|
776
|
+
? parseConfig(options.config, options.version)
|
|
777
|
+
: options.config;
|
|
778
|
+
const order = createTlcOrder(options.source, options.loadModule);
|
|
779
|
+
setStringOrder(order.getStringOrder(config));
|
|
780
|
+
setValueOptions(options);
|
|
781
|
+
setFingerprintPolynomial(options.fingerprintPolynomial ?? 0);
|
|
782
|
+
const specification = createEnvironment(config, {
|
|
783
|
+
source: options.source,
|
|
784
|
+
loadModule: options.loadModule,
|
|
785
|
+
order,
|
|
786
|
+
loadClass: options.loadClass,
|
|
787
|
+
print: options.onPrint ?? console.log,
|
|
788
|
+
files: {
|
|
789
|
+
readFile: options.readFile,
|
|
790
|
+
writeFile: options.writeFile,
|
|
791
|
+
makeDirectory: options.makeDirectory,
|
|
792
|
+
},
|
|
793
|
+
seed: options.seed,
|
|
794
|
+
isTool: options.isTool,
|
|
795
|
+
traceFile: options.traceSpec?.traceFile,
|
|
796
|
+
isSanyReported: options.isSanyReported,
|
|
797
|
+
isWarningEnabled: options.isWarningEnabled,
|
|
798
|
+
version: options.version,
|
|
799
|
+
moduleOperators: options.moduleOperators,
|
|
800
|
+
});
|
|
801
|
+
reportStartup(specification, config, options.onProgress);
|
|
802
|
+
const environment = specification.environment;
|
|
803
|
+
environment.runtime.getSpecification = () =>
|
|
804
|
+
getSpecificationValue(
|
|
805
|
+
config,
|
|
806
|
+
environment,
|
|
807
|
+
specification.variableLocations,
|
|
808
|
+
specification.instanceActions,
|
|
809
|
+
);
|
|
810
|
+
const search = createSearch(
|
|
811
|
+
config,
|
|
812
|
+
environment,
|
|
813
|
+
specification.variableLocations,
|
|
814
|
+
() => order.getDeclarationOrder("variable"),
|
|
815
|
+
options.onProgress,
|
|
816
|
+
specification.moduleOperators,
|
|
817
|
+
);
|
|
818
|
+
return { config, specification, environment, search };
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
export const reportAssumptionViolation = (
|
|
822
|
+
assumptions: Assumption[],
|
|
823
|
+
environment: Environment,
|
|
824
|
+
message: (code: number, text: string, toolText: string) => void,
|
|
825
|
+
) => {
|
|
826
|
+
const assumption = findAssumptionViolation(assumptions, environment);
|
|
827
|
+
if (!assumption) return undefined;
|
|
828
|
+
if (assumption.message === undefined) {
|
|
829
|
+
const text = `Assumption ${assumption.name} is false.`;
|
|
830
|
+
message(MESSAGE_CODE.assumptionFalse, text, text);
|
|
831
|
+
return EXIT_STATUS.assumptionViolation;
|
|
832
|
+
}
|
|
833
|
+
const text = `Evaluating assumption ${assumption.name} failed.\n${assumption.message}`;
|
|
834
|
+
message(
|
|
835
|
+
MESSAGE_CODE.assumptionEvaluationError,
|
|
836
|
+
text,
|
|
837
|
+
formatInnerMessage(MESSAGE_CODE.assumptionEvaluationError, text, true),
|
|
838
|
+
);
|
|
839
|
+
return EXIT_STATUS.assumptionViolation;
|
|
840
|
+
};
|
|
841
|
+
|
|
842
|
+
export const createMissingOperatorError = (operator: ModuleOperator) =>
|
|
843
|
+
setExitCode(
|
|
844
|
+
new TlaEvaluationError(
|
|
845
|
+
`${UNEXPECTED_EXCEPTION}Could not find operator: ${operator.operator} in module: ${operator.module}`,
|
|
846
|
+
),
|
|
847
|
+
EXIT_STATUS.error,
|
|
848
|
+
);
|
|
849
|
+
|
|
672
850
|
export const createSearch = (
|
|
673
851
|
config: ModelConfig,
|
|
674
852
|
environment: Environment,
|
|
853
|
+
variableLocations: SourceLocation[],
|
|
675
854
|
getVariableOrder: () => string[],
|
|
676
855
|
onProgress?: CheckOptions["onProgress"],
|
|
856
|
+
moduleOperators: ResolvedModuleOperator[] = [],
|
|
677
857
|
): Search | undefined => {
|
|
858
|
+
const getModuleOperators = (kind: ResolvedModuleOperator["kind"]) =>
|
|
859
|
+
moduleOperators
|
|
860
|
+
.filter((operator) => operator.kind === kind)
|
|
861
|
+
.map((operator) => {
|
|
862
|
+
if (operator.key === undefined) throw createMissingOperatorError(operator);
|
|
863
|
+
return { name: operator.operator, key: operator.key };
|
|
864
|
+
});
|
|
678
865
|
const configInvariants = getInvariants(config.invariants, environment);
|
|
679
|
-
const spec = getSpecification(
|
|
866
|
+
const spec = getSpecification(
|
|
867
|
+
config,
|
|
868
|
+
environment,
|
|
869
|
+
variableLocations,
|
|
870
|
+
getVariableOrder,
|
|
871
|
+
onProgress,
|
|
872
|
+
);
|
|
680
873
|
const properties = getProperties(config, environment, onProgress);
|
|
874
|
+
const live = config.properties[0];
|
|
875
|
+
const liveRange = live && getDefinition(live, environment)?.location.range;
|
|
876
|
+
const specName = config.specification;
|
|
877
|
+
const specRange = specName && getDefinition(specName, environment)?.location.range;
|
|
878
|
+
if (spec.isPropertyFairness && liveRange && specRange) {
|
|
879
|
+
onProgress?.({
|
|
880
|
+
kind: "warning",
|
|
881
|
+
code: MESSAGE_CODE.fairnessTautology,
|
|
882
|
+
text: `Implied-temporal checking is a tautology.\nThe temporal formula ${live} at ${formatRange(liveRange)} equals\nthe fairness constraints of the behavior specification ${specName} at ${formatRange(specRange)}.\nTherefore, checking whether ${specName} => ${live} using TLC will never result in a violation of ${live}.`,
|
|
883
|
+
});
|
|
884
|
+
}
|
|
681
885
|
const invariants = getStateChecks([...configInvariants, ...properties.invariants], environment);
|
|
682
|
-
// The invariants TLC evaluates, each of which may have several conjuncts among the checks.
|
|
683
886
|
const invariantPredicates = [
|
|
684
887
|
...new Map(invariants.map((invariant) => [invariant.predicate, invariant])).values(),
|
|
685
888
|
];
|
|
@@ -702,15 +905,68 @@ export const createSearch = (
|
|
|
702
905
|
if (spec.next === undefined && isCheckingBehaviors) {
|
|
703
906
|
throw new TlaConfigError("The configuration file did not specify the next state predicate.");
|
|
704
907
|
}
|
|
705
|
-
const
|
|
706
|
-
|
|
908
|
+
const namedConstraints = getNamedExpressions(
|
|
909
|
+
"constraint",
|
|
910
|
+
[...config.constraints, ...getModuleOperators("constraint").map((operator) => operator.name)],
|
|
707
911
|
environment,
|
|
708
912
|
);
|
|
913
|
+
const constraints = getStateChecks(namedConstraints, environment);
|
|
709
914
|
const actionConstraints = getNamedExpressions(
|
|
710
915
|
"action constraint",
|
|
711
916
|
config.actionConstraints,
|
|
712
917
|
environment,
|
|
713
918
|
);
|
|
919
|
+
const coverage = environment.coverage;
|
|
920
|
+
const getCoveredChecks = (kind: CoverageKind, items: NamedExpression[], isDefined = true) =>
|
|
921
|
+
items.flatMap((item): CoveredCheck[] => {
|
|
922
|
+
if (!coverage) return [];
|
|
923
|
+
const expression = isDefined ? getPredicate(item.expression, environment) : item.expression;
|
|
924
|
+
const label = getCoverageLabel(isDefined ? item.name : undefined, expression, environment);
|
|
925
|
+
const node = addCoverageRelation(coverage, kind, label, expression, item.scope);
|
|
926
|
+
return [{ expression, scope: item.scope, node }];
|
|
927
|
+
});
|
|
928
|
+
const coveredInvariants = [
|
|
929
|
+
...getCoveredChecks("invariant", configInvariants),
|
|
930
|
+
...getCoveredChecks("invariant", properties.invariants, false),
|
|
931
|
+
];
|
|
932
|
+
const coveredActionConstraints = getCoveredChecks("constraint", actionConstraints);
|
|
933
|
+
const coveredConstraints = getCoveredChecks("constraint", namedConstraints);
|
|
934
|
+
const coveredInitialPredicates = getCoveredChecks("implied", properties.initialPredicates, false);
|
|
935
|
+
const coveredActionProperties = getCoveredChecks(
|
|
936
|
+
"implied",
|
|
937
|
+
properties.actionProperties.map((property) => ({ ...property, expression: property.box })),
|
|
938
|
+
false,
|
|
939
|
+
);
|
|
940
|
+
const evaluateCovered = (
|
|
941
|
+
covered: Coverage,
|
|
942
|
+
check: CoveredCheck,
|
|
943
|
+
state: Value[],
|
|
944
|
+
next: Value[] | undefined,
|
|
945
|
+
) => {
|
|
946
|
+
try {
|
|
947
|
+
return runAtCoverageNode(covered, check.node, () =>
|
|
948
|
+
evaluate(check.expression, getContext(environment, state, next, check.scope)),
|
|
949
|
+
);
|
|
950
|
+
} catch {
|
|
951
|
+
return undefined;
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
const isCoveredHeld = (checks: CoveredCheck[], state: Value[], next?: Value[]) =>
|
|
955
|
+
coverage !== undefined &&
|
|
956
|
+
checks.every((check) => evaluateCovered(coverage, check, state, next) === true);
|
|
957
|
+
const satisfiesCovered = (checks: CoveredCheck[], state: Value[], next?: Value[]) => {
|
|
958
|
+
if (!coverage) return undefined;
|
|
959
|
+
for (const check of checks) {
|
|
960
|
+
const value = evaluateCovered(coverage, check, state, next);
|
|
961
|
+
if (typeof value !== "boolean") return undefined;
|
|
962
|
+
if (!value) {
|
|
963
|
+
coverage.primary[check.node]++;
|
|
964
|
+
return false;
|
|
965
|
+
}
|
|
966
|
+
coverage.secondary[check.node]++;
|
|
967
|
+
}
|
|
968
|
+
return true;
|
|
969
|
+
};
|
|
714
970
|
if (config.rlReward !== undefined) getConfigOperator("rlreward", config.rlReward, environment);
|
|
715
971
|
if (config.periodic !== undefined) getConfigOperator("periodic", config.periodic, environment);
|
|
716
972
|
const possible = getPossiblePredicates(config.possible, environment);
|
|
@@ -719,11 +975,15 @@ export const createSearch = (
|
|
|
719
975
|
config.symmetry === undefined
|
|
720
976
|
? undefined
|
|
721
977
|
: getSymmetryGroup(config.symmetry, environment, config.substitutions);
|
|
722
|
-
|
|
723
|
-
const view =
|
|
978
|
+
const viewDefinition =
|
|
724
979
|
config.view === undefined
|
|
725
980
|
? undefined
|
|
726
|
-
:
|
|
981
|
+
: getConfigDefinition("view function", config.view, environment);
|
|
982
|
+
const viewName = config.view ?? getModuleOperators("view")[0]?.name;
|
|
983
|
+
const view =
|
|
984
|
+
viewName === undefined
|
|
985
|
+
? undefined
|
|
986
|
+
: { name: viewName, expression: createIdentifier(viewName), scope: undefined };
|
|
727
987
|
const actionProperties = properties.actionProperties.map((property) => {
|
|
728
988
|
const unchanged: Expression = {
|
|
729
989
|
kind: "Unchanged",
|
|
@@ -737,18 +997,18 @@ export const createSearch = (
|
|
|
737
997
|
const statePossible = possible.filter((item) => !isActionPossible(item));
|
|
738
998
|
const actionPossible = possible.filter(isActionPossible);
|
|
739
999
|
const runtime = environment.runtime;
|
|
740
|
-
|
|
1000
|
+
let tlcOrder: number[] | undefined;
|
|
741
1001
|
const getTlcOrder = () => {
|
|
742
|
-
if (tlcOrder
|
|
1002
|
+
if (tlcOrder) return tlcOrder;
|
|
743
1003
|
const variableOrder = getVariableOrder();
|
|
744
1004
|
const getTlcPosition = (index: number) => {
|
|
745
1005
|
const position = variableOrder.indexOf(environment.variables[index]);
|
|
746
1006
|
return position === -1 ? environment.variables.length : position;
|
|
747
1007
|
};
|
|
748
|
-
tlcOrder
|
|
749
|
-
.map((
|
|
1008
|
+
tlcOrder = environment.variables
|
|
1009
|
+
.map((_variable, index) => index)
|
|
750
1010
|
.sort((left, right) => getTlcPosition(left) - getTlcPosition(right));
|
|
751
|
-
return tlcOrder
|
|
1011
|
+
return tlcOrder;
|
|
752
1012
|
};
|
|
753
1013
|
const getViewValue = (expression: Expression, state: Value[]) =>
|
|
754
1014
|
evaluate(expression, getContext(environment, state, undefined));
|
|
@@ -762,10 +1022,8 @@ export const createSearch = (
|
|
|
762
1022
|
: [getViewValue(view.expression, representative)],
|
|
763
1023
|
);
|
|
764
1024
|
};
|
|
765
|
-
// With -continue, TLC goes on to the successors of a state that violates an invariant.
|
|
766
1025
|
const violatingStates = new WeakSet<Value[]>();
|
|
767
1026
|
const isViolated = (invariant: StateCheck, state: Value[], parent: Value[] | undefined) => {
|
|
768
|
-
// A parent that satisfies every invariant leaves only what the step changed to fail.
|
|
769
1027
|
const checkedParent = parent && !violatingStates.has(parent) ? parent : undefined;
|
|
770
1028
|
if (isUnchangedFor(invariant, state, checkedParent)) return false;
|
|
771
1029
|
try {
|
|
@@ -779,7 +1037,6 @@ export const createSearch = (
|
|
|
779
1037
|
)
|
|
780
1038
|
: !holdsAsConjunct(invariant, context);
|
|
781
1039
|
} catch (error) {
|
|
782
|
-
// TLC reports a failure only on a state after the initial states as an invariant failure.
|
|
783
1040
|
if (!parent) throw error;
|
|
784
1041
|
throw withHeadline(
|
|
785
1042
|
setExitCode(error, EXIT_STATUS.safetyEvaluationFailure),
|
|
@@ -802,9 +1059,56 @@ export const createSearch = (
|
|
|
802
1059
|
counts: prettyPrint(formatValue(getPossibleCounts(runtime), true)),
|
|
803
1060
|
};
|
|
804
1061
|
};
|
|
1062
|
+
// Deviation from TLC: a tuple VIEW prints as a state only when its elements are distinct variables, since TLC mislabels <<y, x>> and <<x + 1>>.
|
|
1063
|
+
const viewElements = viewDefinition?.body.kind === "Tuple" ? viewDefinition.body.elements : [];
|
|
1064
|
+
const viewNames = viewElements.flatMap((element) =>
|
|
1065
|
+
element.kind === "Identifier" && environment.variables.includes(element.name)
|
|
1066
|
+
? [element.name]
|
|
1067
|
+
: [],
|
|
1068
|
+
);
|
|
1069
|
+
const isStateView =
|
|
1070
|
+
viewDefinition?.body.kind === "Tuple" &&
|
|
1071
|
+
viewNames.length === viewElements.length &&
|
|
1072
|
+
new Set(viewNames).size === viewNames.length;
|
|
1073
|
+
const getViewText = (expression: Expression, state: Value[]) =>
|
|
1074
|
+
isStateView
|
|
1075
|
+
? getTlcOrder()
|
|
1076
|
+
.filter((index) => viewNames.includes(environment.variables[index]))
|
|
1077
|
+
.map(
|
|
1078
|
+
(index) =>
|
|
1079
|
+
`/\\ ${environment.variables[index]} = ${prettyPrint(formatValue(state[index]))}\n`,
|
|
1080
|
+
)
|
|
1081
|
+
.join("")
|
|
1082
|
+
: prettyPrint(formatValue(getViewValue(expression, state)));
|
|
1083
|
+
const holdsActionConstraint = (constraint: NamedExpression, state: Value[], next: Value[]) =>
|
|
1084
|
+
holdsLikeTlc(
|
|
1085
|
+
constraint.expression,
|
|
1086
|
+
getContext(environment, state, next),
|
|
1087
|
+
(expression) => `${UNEXPECTED_EXCEPTION}${getExpectedBoolean(expression, environment)}`,
|
|
1088
|
+
);
|
|
1089
|
+
const toRecord = (state: Value[]): Record<string, Value> => {
|
|
1090
|
+
const record = Object.fromEntries(
|
|
1091
|
+
getTlcOrder().map((index) => [environment.variables[index], state[index]]),
|
|
1092
|
+
);
|
|
1093
|
+
return view === undefined
|
|
1094
|
+
? record
|
|
1095
|
+
: setViewText(record, () => getViewText(view.expression, state));
|
|
1096
|
+
};
|
|
805
1097
|
return {
|
|
806
1098
|
properties,
|
|
807
1099
|
spec,
|
|
1100
|
+
toRecord,
|
|
1101
|
+
evaluateAlias: (alias, state, next, isTool) => {
|
|
1102
|
+
try {
|
|
1103
|
+
getConfigDefinition("alias", alias, environment);
|
|
1104
|
+
const value = evaluate(createIdentifier(alias), getContext(environment, state, next));
|
|
1105
|
+
const record = toAliasRecord(value);
|
|
1106
|
+
return record === undefined ? toRecord(state) : setAliasName(record, alias);
|
|
1107
|
+
} catch (error) {
|
|
1108
|
+
if (!(error instanceof TlaConfigError || error instanceof TlaEvaluationError)) throw error;
|
|
1109
|
+
return { ...toRecord(state), _ALIASEvalError: formatNestedMessage(error.message, isTool) };
|
|
1110
|
+
}
|
|
1111
|
+
},
|
|
808
1112
|
isSymmetric: symmetryGroup !== undefined,
|
|
809
1113
|
isConstrained: constraints.length > 0 || actionConstraints.length > 0,
|
|
810
1114
|
getTlcOrder,
|
|
@@ -816,7 +1120,6 @@ export const createSearch = (
|
|
|
816
1120
|
},
|
|
817
1121
|
getFingerprintState: (state) => {
|
|
818
1122
|
if (isFingerprintedLikeTlc) return [String(getTlcStateFingerprint(state))];
|
|
819
|
-
// A representative in TLC's variable order is the one whose fingerprint TLC reports.
|
|
820
1123
|
const representative =
|
|
821
1124
|
symmetryGroup === undefined
|
|
822
1125
|
? state
|
|
@@ -824,6 +1127,7 @@ export const createSearch = (
|
|
|
824
1127
|
return view === undefined ? representative : [getViewValue(view.expression, representative)];
|
|
825
1128
|
},
|
|
826
1129
|
findViolatedInvariant: (state, parent) => {
|
|
1130
|
+
if (isCoveredHeld(coveredInvariants, state)) return undefined;
|
|
827
1131
|
const violated = invariants.find((invariant) => isViolated(invariant, state, parent));
|
|
828
1132
|
if (violated) violatingStates.add(state);
|
|
829
1133
|
return violated;
|
|
@@ -852,7 +1156,6 @@ export const createSearch = (
|
|
|
852
1156
|
return predicate && { status: "liveness-violation", name: predicate.name };
|
|
853
1157
|
},
|
|
854
1158
|
checkReplayedSuccessor: (state, next, tracing, addFingerprint) => {
|
|
855
|
-
// TLC evaluates the action constraints only on a state that satisfies the constraints.
|
|
856
1159
|
const isInModel =
|
|
857
1160
|
constraints.every((constraint) =>
|
|
858
1161
|
holdsLikeTlc(
|
|
@@ -863,8 +1166,7 @@ export const createSearch = (
|
|
|
863
1166
|
actionConstraints.every((constraint) =>
|
|
864
1167
|
holdsLikeTlc(constraint.expression, getContext(tracing, state, next, constraint.scope)),
|
|
865
1168
|
);
|
|
866
|
-
//
|
|
867
|
-
// one outside the model.
|
|
1169
|
+
// TLC checks the invariants of a successor it has not seen, even outside the model.
|
|
868
1170
|
const isUnseen = isInModel ? addFingerprint() : true;
|
|
869
1171
|
return (
|
|
870
1172
|
(!isUnseen ||
|
|
@@ -880,51 +1182,63 @@ export const createSearch = (
|
|
|
880
1182
|
);
|
|
881
1183
|
},
|
|
882
1184
|
satisfiesConstraints: (state, parent) =>
|
|
1185
|
+
satisfiesCovered(coveredConstraints, state) ??
|
|
883
1186
|
constraints.every(
|
|
884
1187
|
(constraint) =>
|
|
885
1188
|
isUnchangedFor(constraint, state, parent) ||
|
|
886
1189
|
holdsAsConjunct(constraint, getContext(environment, state, undefined)),
|
|
887
1190
|
),
|
|
888
1191
|
findFailedInitialPredicate: (state) =>
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
predicate
|
|
893
|
-
|
|
1192
|
+
isCoveredHeld(coveredInitialPredicates, state)
|
|
1193
|
+
? undefined
|
|
1194
|
+
: properties.initialPredicates.find(
|
|
1195
|
+
(predicate) =>
|
|
1196
|
+
!holdsLikeTlc(
|
|
1197
|
+
predicate.expression,
|
|
1198
|
+
getContext(environment, state, undefined, predicate.scope),
|
|
1199
|
+
),
|
|
894
1200
|
),
|
|
895
|
-
),
|
|
896
1201
|
findViolatedActionProperty: (state, next) =>
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
1202
|
+
isCoveredHeld(coveredActionProperties, state, next)
|
|
1203
|
+
? undefined
|
|
1204
|
+
: actionProperties.find((property) => {
|
|
1205
|
+
try {
|
|
1206
|
+
return (
|
|
1207
|
+
!holdsLikeTlc(
|
|
1208
|
+
property.action,
|
|
1209
|
+
getContext(environment, state, next, property.scope),
|
|
1210
|
+
() =>
|
|
1211
|
+
`Attempted to evaluate an expression of form [A]_e, but A was not a boolean.\n${describeRange(property.box)}`,
|
|
1212
|
+
) &&
|
|
1213
|
+
!holds(
|
|
1214
|
+
property.unchanged,
|
|
1215
|
+
getContext(environment, state, next, property.scope),
|
|
1216
|
+
"a subscript",
|
|
1217
|
+
)
|
|
1218
|
+
);
|
|
1219
|
+
} catch (error) {
|
|
1220
|
+
throw withHeadline(
|
|
1221
|
+
withNextStateExitCode(error),
|
|
1222
|
+
MESSAGE_CODE.actionPropertyEvaluationFailed,
|
|
1223
|
+
`Evaluating action property ${property.name} failed.`,
|
|
1224
|
+
);
|
|
1225
|
+
}
|
|
1226
|
+
}),
|
|
920
1227
|
satisfiesActionConstraints: (state, next) =>
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
1228
|
+
satisfiesCovered(coveredActionConstraints, state, next) ??
|
|
1229
|
+
actionConstraints.every((constraint) => holdsActionConstraint(constraint, state, next)),
|
|
1230
|
+
getExcludingConstraints: (state, next) =>
|
|
1231
|
+
[
|
|
1232
|
+
...constraints.filter(
|
|
1233
|
+
(constraint) => !holdsAsConjunct(constraint, getContext(environment, next, undefined)),
|
|
926
1234
|
),
|
|
927
|
-
|
|
1235
|
+
...actionConstraints.filter(
|
|
1236
|
+
(constraint) => !holdsActionConstraint(constraint, state, next),
|
|
1237
|
+
),
|
|
1238
|
+
].map((constraint) => {
|
|
1239
|
+
const range = getBodyRange(constraint.name, environment);
|
|
1240
|
+
return range ? formatRange(range) : constraint.name;
|
|
1241
|
+
}),
|
|
928
1242
|
trackStatePossible:
|
|
929
1243
|
statePossible.length === 0
|
|
930
1244
|
? ignorePossible
|
|
@@ -936,29 +1250,47 @@ export const createSearch = (
|
|
|
936
1250
|
: (state, next) =>
|
|
937
1251
|
trackPossible(actionPossible, runtime, getContext(environment, state, next)),
|
|
938
1252
|
findUnwitnessedPossible,
|
|
1253
|
+
getReward: (state, next, fallback) => {
|
|
1254
|
+
if (config.rlReward === undefined) return fallback;
|
|
1255
|
+
const expression = createIdentifier(config.rlReward);
|
|
1256
|
+
const value = evaluate(expression, getContext(environment, state, next));
|
|
1257
|
+
if (typeof value !== "number") {
|
|
1258
|
+
throw new TlaEvaluationError(getExpectedValue("integer", expression, environment));
|
|
1259
|
+
}
|
|
1260
|
+
return value;
|
|
1261
|
+
},
|
|
939
1262
|
findPostconditionViolation: (isAfterViolation = false) => {
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
1263
|
+
const modulePostconditions = getModuleOperators("postcondition");
|
|
1264
|
+
const rejection = config.postconditions
|
|
1265
|
+
.map((name) => {
|
|
1266
|
+
const definition = getDefinition(name, environment);
|
|
1267
|
+
if (!definition) {
|
|
1268
|
+
return `The post condition ${name} specified in the configuration file\nis not defined in the specification.`;
|
|
1269
|
+
}
|
|
1270
|
+
if (definition.kind === "Operator" && definition.params.length > 0) {
|
|
1271
|
+
return `TLC requires post condition not to take any argument, but one was given: ${name}`;
|
|
1272
|
+
}
|
|
1273
|
+
const isConstant =
|
|
1274
|
+
!isLiteralDefinition(definition) &&
|
|
1275
|
+
getStartupValue(definition, environment) !== undefined;
|
|
1276
|
+
return isConstant ? `The post condition ${name} cannot be a constant.` : undefined;
|
|
1277
|
+
})
|
|
1278
|
+
.find((message) => message !== undefined);
|
|
1279
|
+
if (rejection !== undefined) {
|
|
947
1280
|
if (isAfterViolation) return undefined;
|
|
948
|
-
throw setExitCode(
|
|
949
|
-
new TlaEvaluationError(
|
|
950
|
-
`${UNEXPECTED_EXCEPTION}The post condition ${constant} cannot be a constant.`,
|
|
951
|
-
),
|
|
952
|
-
EXIT_STATUS.error,
|
|
953
|
-
);
|
|
1281
|
+
throw setExitCode(new TlaEvaluationError(rejection), EXIT_STATUS.configParseError);
|
|
954
1282
|
}
|
|
955
|
-
const
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
const
|
|
1283
|
+
const findViolation = (name: string, key: string) => {
|
|
1284
|
+
const failure = getConstantFailure(
|
|
1285
|
+
(context) => holdsLikeTlc(createIdentifier(key), context),
|
|
1286
|
+
environment,
|
|
1287
|
+
);
|
|
1288
|
+
if (!failure) return undefined;
|
|
1289
|
+
const body = getDefinition(key, environment)?.body;
|
|
1290
|
+
const range = getBodyRange(key, environment);
|
|
1291
|
+
const location = range
|
|
1292
|
+
? ` at ${body?.kind === "Number" ? describeNode(body) : formatRange(range)}`
|
|
1293
|
+
: "";
|
|
962
1294
|
return failure.message === undefined
|
|
963
1295
|
? {
|
|
964
1296
|
name,
|
|
@@ -970,13 +1302,21 @@ export const createSearch = (
|
|
|
970
1302
|
code: MESSAGE_CODE.postconditionFailed,
|
|
971
1303
|
message: `Evaluating postcondition ${name}${location} failed.\n${failure.message}`,
|
|
972
1304
|
};
|
|
1305
|
+
};
|
|
1306
|
+
for (const operator of modulePostconditions) {
|
|
1307
|
+
const violation = findViolation(operator.name, operator.key);
|
|
1308
|
+
if (violation) return violation;
|
|
1309
|
+
}
|
|
1310
|
+
const unwitnessed = findUnwitnessedPossible();
|
|
1311
|
+
if (unwitnessed) return unwitnessed;
|
|
1312
|
+
for (const name of config.postconditions) {
|
|
1313
|
+
const violation = findViolation(name, name);
|
|
1314
|
+
if (violation) return violation;
|
|
973
1315
|
}
|
|
974
1316
|
return undefined;
|
|
975
1317
|
},
|
|
976
1318
|
};
|
|
977
1319
|
};
|
|
978
1320
|
|
|
979
|
-
// TLC exits with the code of a standard module's failure only when the failure escapes the
|
|
980
|
-
// computation of next states. In every other phase, the phase decides the code.
|
|
981
1321
|
export const withNextStateExitCode = (error: unknown) =>
|
|
982
1322
|
error instanceof TlaModuleError ? setExitCode(error, error.exitCode) : error;
|