tla-ts 0.0.9-dev.8298a52 → 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 +7 -0
- package/dist/compile.cjs +3 -3
- package/dist/compile.js +3 -3
- package/dist/deciders.cjs +28 -28
- package/dist/deciders.js +52 -52
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +105 -10
- package/dist/index.d.ts +105 -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 +1 -1
- 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 +1 -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 +564 -366
- package/src/cli/options.ts +10 -5
- 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 +525 -216
- package/src/cli/typescript.ts +0 -3
- 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 +237 -119
- package/src/errors.ts +56 -56
- package/src/evaluate.ts +543 -341
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +10 -10
- package/src/index.ts +3 -0
- package/src/instances.ts +38 -31
- 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 +77 -117
- package/src/liveness.ts +106 -62
- 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 +24 -33
- package/src/parallel.ts +48 -40
- 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 +1 -16
- 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 +260 -91
- 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 +8 -21
- package/src/typescript/collections.ts +0 -15
- package/src/typescript/compile.ts +0 -5
- package/src/typescript/context.ts +0 -12
- package/src/typescript/emit.ts +0 -1
- package/src/typescript/expressions.ts +0 -12
- package/src/typescript/formula.ts +4 -12
- package/src/typescript/functions.ts +6 -17
- package/src/typescript/model.ts +10 -11
- package/src/typescript/names.ts +0 -2
- package/src/typescript/program.ts +0 -3
- package/src/typescript/properties.ts +6 -8
- package/src/typescript/scope.ts +0 -5
- package/src/typescript/steps.ts +0 -10
- package/src/typescript/types.ts +1 -8
- package/src/values.ts +749 -330
- package/src/worker.ts +7 -8
package/src/cli/tlc.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
+
appendFileSync,
|
|
3
|
+
closeSync,
|
|
2
4
|
existsSync,
|
|
3
5
|
mkdirSync,
|
|
6
|
+
openSync,
|
|
4
7
|
readFileSync,
|
|
5
8
|
readSync,
|
|
6
9
|
realpathSync,
|
|
10
|
+
statSync,
|
|
7
11
|
writeFileSync,
|
|
8
12
|
} from "node:fs";
|
|
9
13
|
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
@@ -12,11 +16,15 @@ import { pathToFileURL } from "node:url";
|
|
|
12
16
|
import { getHeapStatistics } from "node:v8";
|
|
13
17
|
import { version } from "../../package.json";
|
|
14
18
|
import type { Expression } from "../ast";
|
|
19
|
+
import type { CoverageReport } from "../coverage";
|
|
15
20
|
import { describeRange } from "../evaluate";
|
|
16
21
|
import type {
|
|
22
|
+
CheckOptions,
|
|
17
23
|
CheckProgress,
|
|
18
24
|
InitialStateViolation,
|
|
25
|
+
ModuleOperator,
|
|
19
26
|
OutputLine,
|
|
27
|
+
Postcondition,
|
|
20
28
|
CheckResult,
|
|
21
29
|
CheckStatus,
|
|
22
30
|
InitialStates,
|
|
@@ -25,11 +33,14 @@ import type {
|
|
|
25
33
|
Violation,
|
|
26
34
|
} from "../check";
|
|
27
35
|
import { parseConfig } from "../config";
|
|
36
|
+
import { checkDepthFirst, type DepthFirstOutput } from "../dfid";
|
|
28
37
|
import {
|
|
29
|
-
|
|
38
|
+
TlaAliasFormatError,
|
|
30
39
|
TlaConfigError,
|
|
31
40
|
TlaError,
|
|
32
41
|
TlaEvaluationError,
|
|
42
|
+
TlaFeatureUnsupportedError,
|
|
43
|
+
TlaMissingCheckpointError,
|
|
33
44
|
TlaSyntaxError,
|
|
34
45
|
getUnexpectedException,
|
|
35
46
|
UNEXPECTED_EXCEPTION,
|
|
@@ -37,7 +48,8 @@ import {
|
|
|
37
48
|
} from "../errors";
|
|
38
49
|
import { EXIT_STATUS, setExitCode } from "../exit-codes";
|
|
39
50
|
import { check } from "../parallel";
|
|
40
|
-
import { parseModule } from "../parser";
|
|
51
|
+
import { extractModule, parseModule } from "../parser";
|
|
52
|
+
import { simulate, type SimulationOutput, type SimulationStatistics } from "../simulate";
|
|
41
53
|
import type { StateDump } from "../state-graph";
|
|
42
54
|
import {
|
|
43
55
|
formatProbability,
|
|
@@ -45,7 +57,11 @@ import {
|
|
|
45
57
|
getOptimisticProbability,
|
|
46
58
|
getOutDegreeSummary,
|
|
47
59
|
} from "../tlc/summary";
|
|
48
|
-
import {
|
|
60
|
+
import {
|
|
61
|
+
getSanyStandardModules,
|
|
62
|
+
SANY_174_STANDARD_MODULES,
|
|
63
|
+
SANY_STANDARD_MODULES,
|
|
64
|
+
} from "../sany/modules";
|
|
49
65
|
import { getSanyReport, type SanyModuleOrigin } from "../sany/report";
|
|
50
66
|
import { getTlcFingerprint } from "../tlc/fingerprint";
|
|
51
67
|
import type { TlcVersion } from "../tlc/version";
|
|
@@ -60,13 +76,16 @@ import {
|
|
|
60
76
|
type MessagePrinter,
|
|
61
77
|
} from "../tlc/messages";
|
|
62
78
|
import { formatState } from "../values";
|
|
63
|
-
import {
|
|
79
|
+
import { addRuntimeInvariants } from "./runtime-invariants";
|
|
80
|
+
import { parseTlcArguments, type TlcArguments } from "./tlc-arguments";
|
|
81
|
+
import { getTlcUsage } from "./tlc-usage";
|
|
64
82
|
import {
|
|
65
83
|
createModuleLoader,
|
|
66
84
|
findModuleFile,
|
|
67
85
|
getInputPaths,
|
|
68
86
|
getToolsJar,
|
|
69
87
|
getStandardModulesUrl,
|
|
88
|
+
getTopLevelExitCode,
|
|
70
89
|
printError,
|
|
71
90
|
printMissingFile,
|
|
72
91
|
printMissingFile174,
|
|
@@ -88,19 +107,12 @@ const EXIT_CODES: Record<CheckStatus, number> = {
|
|
|
88
107
|
error: EXIT_STATUS.error,
|
|
89
108
|
};
|
|
90
109
|
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (!values) return 1;
|
|
96
|
-
return values[0] === "auto"
|
|
97
|
-
? availableParallelism()
|
|
98
|
-
: Math.max(1, Number.parseInt(values[0], 10) || 1);
|
|
110
|
+
const checkNotDirectory = (path: string) => {
|
|
111
|
+
if (statSync(path, { throwIfNoEntry: false })?.isDirectory()) {
|
|
112
|
+
throw new TlaEvaluationError(`${path} (Is a directory)`);
|
|
113
|
+
}
|
|
99
114
|
};
|
|
100
115
|
|
|
101
|
-
const UNSUPPORTED_DUMP_FORMATS = ["constrained", "stuttering", "strict"];
|
|
102
|
-
|
|
103
|
-
// TLC names the file of a -dump by its format unless the name already ends that way.
|
|
104
116
|
const getDumpPath = (path: string, extension: string) =>
|
|
105
117
|
path.endsWith(extension) ? path : `${path}${extension}`;
|
|
106
118
|
|
|
@@ -113,6 +125,9 @@ const getStateDump = (values: string[]): StateDump => {
|
|
|
113
125
|
colorize: format.includes("colorize"),
|
|
114
126
|
actionLabels: format.includes("actionlabels"),
|
|
115
127
|
snapshot: format.includes("snapshot"),
|
|
128
|
+
constrained: format.includes("constrained"),
|
|
129
|
+
stuttering: format.includes("stuttering"),
|
|
130
|
+
strict: format.includes("strict"),
|
|
116
131
|
};
|
|
117
132
|
};
|
|
118
133
|
|
|
@@ -137,7 +152,6 @@ const getInitialViolationHeadline = (
|
|
|
137
152
|
text: `Property ${name} is violated by the initial state:`,
|
|
138
153
|
};
|
|
139
154
|
|
|
140
|
-
// What the spec prints as TLC rebuilds a trace, before it prints the states or after.
|
|
141
155
|
const printTraceOutput = (printer: MessagePrinter, lines: OutputLine[] | undefined) =>
|
|
142
156
|
lines?.forEach((line) => {
|
|
143
157
|
if (typeof line === "string") return console.log(line);
|
|
@@ -152,24 +166,38 @@ const printTraceOutput = (printer: MessagePrinter, lines: OutputLine[] | undefin
|
|
|
152
166
|
);
|
|
153
167
|
});
|
|
154
168
|
|
|
169
|
+
interface TlcPrinter extends MessagePrinter {
|
|
170
|
+
isDiffTrace: boolean;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const BEHAVIOR = {
|
|
174
|
+
code: MESSAGE_CODE.behaviorUpToThisPoint,
|
|
175
|
+
text: "The behavior up to this point is:",
|
|
176
|
+
};
|
|
177
|
+
|
|
155
178
|
const printTrace = (
|
|
156
|
-
printer:
|
|
179
|
+
printer: TlcPrinter,
|
|
157
180
|
trace: TraceStep[],
|
|
158
|
-
heading: { code: number; text: string } =
|
|
159
|
-
code: MESSAGE_CODE.behaviorUpToThisPoint,
|
|
160
|
-
text: "The behavior up to this point is:",
|
|
161
|
-
},
|
|
181
|
+
heading: { code: number; text: string } = BEHAVIOR,
|
|
162
182
|
isRebuiltAfterHeading = false,
|
|
183
|
+
isLastDiffed = heading !== BEHAVIOR,
|
|
163
184
|
) => {
|
|
164
185
|
if (trace.length > 0) printer.print(heading.code, MESSAGE_LEVEL.error, heading.text);
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
186
|
+
try {
|
|
187
|
+
trace.forEach((step, index) => {
|
|
188
|
+
if (index > 0 || isRebuiltAfterHeading) printTraceOutput(printer, step.output);
|
|
189
|
+
const isDiffed =
|
|
190
|
+
printer.isDiffTrace && index > 0 && (isLastDiffed || index < trace.length - 1);
|
|
191
|
+
printer.print(
|
|
192
|
+
MESSAGE_CODE.statePrint2,
|
|
193
|
+
MESSAGE_LEVEL.state,
|
|
194
|
+
`${index + 1}: <${step.label ?? step.action ?? "Initial predicate"}>\n${formatState(step.state, isDiffed ? trace[index - 1].state : undefined)}`,
|
|
195
|
+
);
|
|
196
|
+
});
|
|
197
|
+
} catch (error) {
|
|
198
|
+
if (!(error instanceof TlaAliasFormatError)) throw error;
|
|
199
|
+
printer.print(MESSAGE_CODE.general, MESSAGE_LEVEL.error, error.message);
|
|
200
|
+
}
|
|
173
201
|
};
|
|
174
202
|
|
|
175
203
|
const COUNTER_EXAMPLE = {
|
|
@@ -177,7 +205,6 @@ const COUNTER_EXAMPLE = {
|
|
|
177
205
|
text: "The following behavior constitutes a counter-example:\n",
|
|
178
206
|
};
|
|
179
207
|
|
|
180
|
-
// TLC 1.7.4 doesn't name the properties, and later versions name none when they can't tell which.
|
|
181
208
|
const getTemporalHeadline = (names: string[], version: TlcVersion) =>
|
|
182
209
|
version === "1.7.4" || names.length === 0
|
|
183
210
|
? "Temporal properties were violated.\n"
|
|
@@ -185,8 +212,6 @@ const getTemporalHeadline = (names: string[], version: TlcVersion) =>
|
|
|
185
212
|
? `Temporal property ${names[0]} was violated.\n`
|
|
186
213
|
: `Temporal properties ${names.slice(0, -1).join(", ")}${names.length > 2 ? "," : ""} and ${names[names.length - 1]} were violated.\n`;
|
|
187
214
|
|
|
188
|
-
// TLC's FingerprintException#getTrace: the range of each source, innermost first, skipping a
|
|
189
|
-
// source the same as the one inside it.
|
|
190
215
|
const formatFingerprintTrace = (sources: Expression[]) =>
|
|
191
216
|
sources
|
|
192
217
|
.filter((source, index) => source !== sources[index - 1])
|
|
@@ -194,8 +219,6 @@ const formatFingerprintTrace = (sources: Expression[]) =>
|
|
|
194
219
|
.toReversed()
|
|
195
220
|
.join("");
|
|
196
221
|
|
|
197
|
-
// TLC's CallStack.toString: the range of each expression, skipping an expression that it evaluates
|
|
198
|
-
// again right inside itself.
|
|
199
222
|
const formatCallStack = (expressions: Expression[]) => {
|
|
200
223
|
if (expressions.length === 0) return " The error call stack is empty.\n";
|
|
201
224
|
const lines: string[] = [];
|
|
@@ -230,13 +253,10 @@ const printInitialStates = (printer: MessagePrinter, initialStates: InitialState
|
|
|
230
253
|
|
|
231
254
|
interface Timing {
|
|
232
255
|
startTime: number;
|
|
233
|
-
// Whether TLC has printed that SANY finished.
|
|
234
256
|
isParsed: boolean;
|
|
235
257
|
livenessStartTime: number | undefined;
|
|
236
258
|
}
|
|
237
259
|
|
|
238
|
-
// TLC reports a depth of at least 1, even before it finds a state, and rates a minute only once the
|
|
239
|
-
// search has started.
|
|
240
260
|
const printProgress = (
|
|
241
261
|
printer: MessagePrinter,
|
|
242
262
|
statistics: SearchStatistics,
|
|
@@ -253,10 +273,55 @@ const printProgress = (
|
|
|
253
273
|
);
|
|
254
274
|
};
|
|
255
275
|
|
|
276
|
+
const COVERAGE_CODES = {
|
|
277
|
+
init: MESSAGE_CODE.coverageInit,
|
|
278
|
+
next: MESSAGE_CODE.coverageNext,
|
|
279
|
+
invariant: MESSAGE_CODE.coverageProperty,
|
|
280
|
+
implied: MESSAGE_CODE.coverageProperty,
|
|
281
|
+
constraint: MESSAGE_CODE.coverageConstraint,
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const COVERAGE_OVERHEAD = 5 * 60_000;
|
|
285
|
+
|
|
286
|
+
const printCoverage = (printer: MessagePrinter, coverage: CoverageReport, startTime: number) => {
|
|
287
|
+
const print = (code: number, text: string) => printer.print(code, MESSAGE_LEVEL.none, text);
|
|
288
|
+
print(
|
|
289
|
+
MESSAGE_CODE.coverageStart,
|
|
290
|
+
`The coverage statistics at ${formatTlcDate(new Date())} (see https://explain.tlapl.us/module-coverage-statistics for how to interpret the following statistics).`,
|
|
291
|
+
);
|
|
292
|
+
coverage.variables.forEach((variable) =>
|
|
293
|
+
print(MESSAGE_CODE.coverageVariable, `<${variable.label}>: ${variable.distinct}`),
|
|
294
|
+
);
|
|
295
|
+
coverage.relations.forEach((relation) => {
|
|
296
|
+
const code = COVERAGE_CODES[relation.kind];
|
|
297
|
+
print(
|
|
298
|
+
code,
|
|
299
|
+
code === MESSAGE_CODE.coverageProperty
|
|
300
|
+
? `<${relation.label}>`
|
|
301
|
+
: `<${relation.label}>: ${relation.distinct}:${relation.generated}`,
|
|
302
|
+
);
|
|
303
|
+
relation.expressions.forEach((expression) => {
|
|
304
|
+
const location = ` ${"|".repeat(expression.depth)}${expression.location}`;
|
|
305
|
+
if (expression.cost > 0) {
|
|
306
|
+
print(
|
|
307
|
+
MESSAGE_CODE.coverageValueCost,
|
|
308
|
+
`${location}: ${expression.count}:${expression.cost}`,
|
|
309
|
+
);
|
|
310
|
+
} else print(MESSAGE_CODE.coverageValue, `${location}: ${expression.count}`);
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
if (Date.now() - startTime > COVERAGE_OVERHEAD) {
|
|
314
|
+
print(
|
|
315
|
+
MESSAGE_CODE.coverageEndOverhead,
|
|
316
|
+
"End of statistics (please note that for performance reasons large models\nare best checked with coverage and cost statistics disabled).",
|
|
317
|
+
);
|
|
318
|
+
} else print(MESSAGE_CODE.coverageEnd, "End of statistics.");
|
|
319
|
+
};
|
|
320
|
+
|
|
256
321
|
const getClassPath = (directory: string, module: string) => join(directory, `${module}.class`);
|
|
257
322
|
|
|
258
323
|
const printCheckProgress = (
|
|
259
|
-
printer:
|
|
324
|
+
printer: TlcPrinter,
|
|
260
325
|
progress: CheckProgress,
|
|
261
326
|
timing: Timing,
|
|
262
327
|
directory: string,
|
|
@@ -272,7 +337,6 @@ const printCheckProgress = (
|
|
|
272
337
|
`Starting... (${formatTlcDate(new Date())})`,
|
|
273
338
|
);
|
|
274
339
|
return;
|
|
275
|
-
// TLC 1.7.4 warns about neither a constant-level invariant nor a state-level property.
|
|
276
340
|
case "constant-level-invariant":
|
|
277
341
|
if (printer.version === "1.7.4") return;
|
|
278
342
|
print(
|
|
@@ -297,7 +361,6 @@ const printCheckProgress = (
|
|
|
297
361
|
"Declaring symmetry during liveness checking is dangerous. It might cause TLC to miss violations of the stated liveness properties. Please check liveness without symmetry defined.",
|
|
298
362
|
);
|
|
299
363
|
}
|
|
300
|
-
// Only TLC 1.7.4 warns about constraints.
|
|
301
364
|
if (progress.isConstrained && printer.version === "1.7.4") {
|
|
302
365
|
print(
|
|
303
366
|
MESSAGE_CODE.livenessConstraints,
|
|
@@ -314,7 +377,6 @@ const printCheckProgress = (
|
|
|
314
377
|
);
|
|
315
378
|
return;
|
|
316
379
|
case "java-override": {
|
|
317
|
-
// Class#getResource, which names the class file TLC loads the override from.
|
|
318
380
|
const location = pathToFileURL(resolve(getClassPath(directory, progress.module))).href;
|
|
319
381
|
print(
|
|
320
382
|
progress.isMatched ? MESSAGE_CODE.javaOverrideLoaded : MESSAGE_CODE.javaOverrideMismatch,
|
|
@@ -334,13 +396,14 @@ const printCheckProgress = (
|
|
|
334
396
|
return;
|
|
335
397
|
case "progress":
|
|
336
398
|
printProgress(printer, progress.statistics, timing.startTime);
|
|
399
|
+
if (progress.statistics.coverage) {
|
|
400
|
+
printCoverage(printer, progress.statistics.coverage, timing.startTime);
|
|
401
|
+
}
|
|
337
402
|
return;
|
|
338
403
|
case "liveness-started": {
|
|
339
404
|
timing.livenessStartTime = Date.now();
|
|
340
|
-
// TLC reports how far the search got before it checks the complete state graph.
|
|
341
405
|
if (progress.isComplete) printProgress(printer, progress.statistics);
|
|
342
406
|
const branches = progress.branches > 1 ? `${progress.branches} branches of ` : "";
|
|
343
|
-
// TLC counts the states of the behavior graph of each branch, without its tableau nodes.
|
|
344
407
|
const states = progress.branches * progress.states;
|
|
345
408
|
print(
|
|
346
409
|
MESSAGE_CODE.checkingTemporal,
|
|
@@ -375,12 +438,20 @@ const printLivenessEnd = (printer: MessagePrinter, timing: Timing) => {
|
|
|
375
438
|
timing.livenessStartTime = undefined;
|
|
376
439
|
};
|
|
377
440
|
|
|
378
|
-
|
|
379
|
-
|
|
441
|
+
const printPostcondition = (printer: MessagePrinter, postcondition: Postcondition | undefined) => {
|
|
442
|
+
if (!postcondition) return;
|
|
443
|
+
if (postcondition.counts) console.log(postcondition.counts);
|
|
444
|
+
printer.print(
|
|
445
|
+
postcondition.code,
|
|
446
|
+
MESSAGE_LEVEL.error,
|
|
447
|
+
formatInnerMessage(postcondition.code, postcondition.message, printer.isTool),
|
|
448
|
+
);
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
const printViolation = (status: CheckStatus, violation: Violation, printer: TlcPrinter) => {
|
|
380
452
|
const print = printer.print;
|
|
381
453
|
const name = violation.name;
|
|
382
454
|
const loopStart = violation.loopStart;
|
|
383
|
-
// TLC prints a violation by an initial state without the behavior or the statistics.
|
|
384
455
|
const isInitial =
|
|
385
456
|
loopStart === undefined &&
|
|
386
457
|
violation.trace.length === 1 &&
|
|
@@ -418,20 +489,20 @@ const printViolation = (status: CheckStatus, violation: Violation, printer: Mess
|
|
|
418
489
|
},
|
|
419
490
|
"postcondition-violation": {
|
|
420
491
|
code: violation.postcondition?.code ?? MESSAGE_CODE.general,
|
|
421
|
-
text:
|
|
492
|
+
text: formatInnerMessage(
|
|
493
|
+
violation.postcondition?.code ?? MESSAGE_CODE.general,
|
|
494
|
+
violation.message ?? `Postcondition ${name} is false.`,
|
|
495
|
+
printer.isTool,
|
|
496
|
+
),
|
|
422
497
|
},
|
|
423
498
|
}[status];
|
|
424
|
-
// A safety property's counterexample ends where it breaks, and a liveness one loops back.
|
|
425
499
|
const isProperty = status === "property-violation";
|
|
426
500
|
const isLasso = loopStart !== undefined && !isProperty;
|
|
427
501
|
const isCounterExample = isProperty || isLasso;
|
|
428
|
-
// TLC rebuilds a liveness counterexample before it reports the violation, and 1.7.4's
|
|
429
|
-
// LiveWorker#printTrace after it prints the heading of the counterexample.
|
|
430
502
|
const isRebuiltFirst = isCounterExample && printer.version !== "1.7.4";
|
|
431
503
|
if (isRebuiltFirst) printTraceOutput(printer, violation.trace[0]?.output);
|
|
432
504
|
if (violation.counts) console.log(violation.counts);
|
|
433
505
|
if (headline) {
|
|
434
|
-
// TLC prints the initial state that violates a property in the same message.
|
|
435
506
|
const text = isInitial
|
|
436
507
|
? `${headline.text}\n${formatState(violation.trace[0].state)}`
|
|
437
508
|
: headline.text;
|
|
@@ -445,8 +516,8 @@ const printViolation = (status: CheckStatus, violation: Violation, printer: Mess
|
|
|
445
516
|
isCounterExample ? COUNTER_EXAMPLE : undefined,
|
|
446
517
|
isCounterExample && !isRebuiltFirst,
|
|
447
518
|
);
|
|
448
|
-
printTraceOutput(printer, violation.traceOutput);
|
|
449
519
|
}
|
|
520
|
+
printTraceOutput(printer, violation.traceOutput);
|
|
450
521
|
if (isLasso) {
|
|
451
522
|
const label = violation.loopLabel;
|
|
452
523
|
if (loopStart === violation.trace.length - 1)
|
|
@@ -459,16 +530,13 @@ const printViolation = (status: CheckStatus, violation: Violation, printer: Mess
|
|
|
459
530
|
);
|
|
460
531
|
else console.log(`Back to state ${loopStart + 1}${label ? `: <${label}>\n` : ""}`);
|
|
461
532
|
}
|
|
462
|
-
// TLC 1.7.4 doesn't explain a stuttering counterexample.
|
|
463
533
|
if (violation.warning && printer.version !== "1.7.4")
|
|
464
534
|
print(violation.warning.code, MESSAGE_LEVEL.warning, violation.warning.text);
|
|
465
|
-
// TLC checks the postconditions after it prints a counterexample.
|
|
466
535
|
const postcondition =
|
|
467
536
|
violation.unwitnessed ??
|
|
468
537
|
(status === "postcondition-violation" ? undefined : violation.postcondition);
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
// TLC checks assumptions before it starts the search, so it has no statistics to print.
|
|
538
|
+
printTraceOutput(printer, violation.postconditionOutput);
|
|
539
|
+
printPostcondition(printer, postcondition);
|
|
472
540
|
return !isInitial && status !== "assumption-violation";
|
|
473
541
|
};
|
|
474
542
|
|
|
@@ -479,7 +547,54 @@ const printNestedExpressions = (printer: MessagePrinter, callStack: Expression[]
|
|
|
479
547
|
`The error occurred when TLC was evaluating the nested\nexpressions at the following positions:\n${formatCallStack(callStack)}`,
|
|
480
548
|
);
|
|
481
549
|
|
|
482
|
-
const
|
|
550
|
+
const printSuccess = (printer: MessagePrinter, optimistic: number, actual: number | undefined) =>
|
|
551
|
+
printer.print(
|
|
552
|
+
MESSAGE_CODE.success,
|
|
553
|
+
MESSAGE_LEVEL.none,
|
|
554
|
+
[
|
|
555
|
+
"Model checking completed. No error has been found.",
|
|
556
|
+
" Estimates of the probability that TLC did not check all reachable states",
|
|
557
|
+
" because two distinct states had the same fingerprint:",
|
|
558
|
+
` calculated (optimistic): val = ${formatProbability(optimistic)}`,
|
|
559
|
+
...(actual === undefined
|
|
560
|
+
? []
|
|
561
|
+
: [` based on the actual fingerprints: val = ${formatProbability(actual)}`]),
|
|
562
|
+
].join("\n"),
|
|
563
|
+
);
|
|
564
|
+
|
|
565
|
+
const printDepthFirst = (printer: TlcPrinter, output: DepthFirstOutput) => {
|
|
566
|
+
switch (output.kind) {
|
|
567
|
+
case "message":
|
|
568
|
+
printer.print(
|
|
569
|
+
output.code,
|
|
570
|
+
output.isError ? MESSAGE_LEVEL.error : MESSAGE_LEVEL.none,
|
|
571
|
+
printer.isTool ? output.toolMessage : output.message,
|
|
572
|
+
);
|
|
573
|
+
return;
|
|
574
|
+
case "behavior":
|
|
575
|
+
output.states.forEach((state, index) =>
|
|
576
|
+
output.isInvariant
|
|
577
|
+
? printer.print(
|
|
578
|
+
MESSAGE_CODE.statePrint2,
|
|
579
|
+
MESSAGE_LEVEL.state,
|
|
580
|
+
`${index + 1}: \n${formatState(state, printer.isDiffTrace ? output.states[index - 1] : undefined)}`,
|
|
581
|
+
)
|
|
582
|
+
: printer.print(
|
|
583
|
+
MESSAGE_CODE.statePrint1,
|
|
584
|
+
MESSAGE_LEVEL.state,
|
|
585
|
+
`${index + 1}:\n${formatState(state)}`,
|
|
586
|
+
),
|
|
587
|
+
);
|
|
588
|
+
return;
|
|
589
|
+
case "nested-expressions":
|
|
590
|
+
printNestedExpressions(printer, output.callStack);
|
|
591
|
+
return;
|
|
592
|
+
case "success":
|
|
593
|
+
printSuccess(printer, output.optimistic, output.actual);
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
const printResult = (result: CheckResult, printer: TlcPrinter, timing: Timing) => {
|
|
483
598
|
const print = printer.print;
|
|
484
599
|
if (result.failure) {
|
|
485
600
|
const failure = result.failure;
|
|
@@ -487,8 +602,6 @@ const printResult = (result: CheckResult, printer: MessagePrinter, timing: Timin
|
|
|
487
602
|
const printCallStack = () => {
|
|
488
603
|
const fingerprint = failure.fingerprint;
|
|
489
604
|
if (fingerprint) {
|
|
490
|
-
// TLC prints the call stack when the replay has one, and otherwise the sources of the
|
|
491
|
-
// values it failed to fingerprint, innermost first. TLC 1.7.4 always prints the sources.
|
|
492
605
|
const trace =
|
|
493
606
|
failure.callStack?.length && printer.version !== "1.7.4"
|
|
494
607
|
? formatCallStack(failure.callStack)
|
|
@@ -503,8 +616,6 @@ const printResult = (result: CheckResult, printer: MessagePrinter, timing: Timin
|
|
|
503
616
|
if (failure.callStack) printNestedExpressions(printer, failure.callStack);
|
|
504
617
|
};
|
|
505
618
|
if (failure.isCallStackFirst) printCallStack();
|
|
506
|
-
// TLC prints the state as it reports the error, so a state it can't print fails outside the
|
|
507
|
-
// checker, which TLC reports as an exception it did not expect.
|
|
508
619
|
const initialState =
|
|
509
620
|
failure.initialState &&
|
|
510
621
|
(() => {
|
|
@@ -518,7 +629,6 @@ const printResult = (result: CheckResult, printer: MessagePrinter, timing: Timin
|
|
|
518
629
|
);
|
|
519
630
|
}
|
|
520
631
|
})();
|
|
521
|
-
// TLC prints an error on an initial state and the state as one message.
|
|
522
632
|
print(
|
|
523
633
|
initialState ? MESSAGE_CODE.initialState : failure.code,
|
|
524
634
|
MESSAGE_LEVEL.error,
|
|
@@ -535,48 +645,32 @@ const printResult = (result: CheckResult, printer: MessagePrinter, timing: Timin
|
|
|
535
645
|
);
|
|
536
646
|
}
|
|
537
647
|
printTraceOutput(printer, failure.traceOutput);
|
|
538
|
-
|
|
539
|
-
if (postcondition?.counts) console.log(postcondition.counts);
|
|
540
|
-
if (postcondition) print(postcondition.code, MESSAGE_LEVEL.error, postcondition.message);
|
|
648
|
+
printPostcondition(printer, failure.postcondition);
|
|
541
649
|
if (!failure.isCallStackFirst) printCallStack();
|
|
542
650
|
} else if (result.violation) {
|
|
543
651
|
if (!printViolation(result.status, result.violation, printer)) return;
|
|
544
|
-
// TLC adds a deadlocked state to the behavior graph after it reports the deadlock, which can
|
|
545
|
-
// violate a temporal property too.
|
|
546
652
|
const additionalViolation = result.additionalViolation;
|
|
547
653
|
if (additionalViolation) printViolation("property-violation", additionalViolation, printer);
|
|
548
654
|
if (result.liveCallStack) printNestedExpressions(printer, result.liveCallStack);
|
|
549
|
-
} else {
|
|
655
|
+
} else if (result.status === "success") {
|
|
550
656
|
printLivenessEnd(printer, timing);
|
|
551
|
-
|
|
552
|
-
|
|
657
|
+
printSuccess(
|
|
658
|
+
printer,
|
|
659
|
+
getOptimisticProbability(result.distinctStates, result.generatedStates),
|
|
553
660
|
result.fingerprintDistance === undefined
|
|
554
|
-
?
|
|
555
|
-
:
|
|
556
|
-
` based on the actual fingerprints: val = ${formatProbability(getActualProbability(result.fingerprintDistance))}`,
|
|
557
|
-
];
|
|
558
|
-
print(
|
|
559
|
-
MESSAGE_CODE.success,
|
|
560
|
-
MESSAGE_LEVEL.none,
|
|
561
|
-
[
|
|
562
|
-
"Model checking completed. No error has been found.",
|
|
563
|
-
" Estimates of the probability that TLC did not check all reachable states",
|
|
564
|
-
" because two distinct states had the same fingerprint:",
|
|
565
|
-
` calculated (optimistic): val = ${formatProbability(optimistic)}`,
|
|
566
|
-
...actual,
|
|
567
|
-
].join("\n"),
|
|
661
|
+
? undefined
|
|
662
|
+
: getActualProbability(result.fingerprintDistance),
|
|
568
663
|
);
|
|
569
664
|
}
|
|
570
665
|
if (result.failure?.isWithoutStatistics) return;
|
|
571
666
|
if (result.status !== "success") printLivenessEnd(printer, timing);
|
|
667
|
+
if (result.coverage) printCoverage(printer, result.coverage, timing.startTime);
|
|
572
668
|
if (printer.isTool) printProgress(printer, result, timing.startTime);
|
|
573
669
|
print(
|
|
574
670
|
MESSAGE_CODE.stats,
|
|
575
671
|
MESSAGE_LEVEL.none,
|
|
576
672
|
`${result.generatedStates} states generated, ${result.distinctStates} distinct states found, ${result.queuedStates} states left on queue.`,
|
|
577
673
|
);
|
|
578
|
-
// ModelChecker#printSummary prints the depth, which TLC 1.7.4 prints only after a search it
|
|
579
|
-
// reports as successful, and as at least 1, and then the outdegree of a successful search.
|
|
580
674
|
const is174 = printer.version === "1.7.4";
|
|
581
675
|
const outDegrees = is174 ? (result.outDegrees ?? result.violationOutDegrees) : result.outDegrees;
|
|
582
676
|
if (!is174 || outDegrees) {
|
|
@@ -590,14 +684,9 @@ const printResult = (result: CheckResult, printer: MessagePrinter, timing: Timin
|
|
|
590
684
|
if (outDegree) print(MESSAGE_CODE.stateGraphOutdegree, MESSAGE_LEVEL.none, outDegree);
|
|
591
685
|
};
|
|
592
686
|
|
|
593
|
-
// Java
|
|
594
|
-
// from TLC's fingerprint of what the directory holds, so that each run of a spec prints the same
|
|
595
|
-
// files.
|
|
687
|
+
// Deviation from TLC: Java names the directory by a random unsigned long, and tla-ts by what the directory holds, so that each run of a spec prints the same files.
|
|
596
688
|
const getTemporaryName = (contents: string) => getTlcFingerprint([contents]).toString();
|
|
597
689
|
|
|
598
|
-
// The file TLC's SANY says it parses each module from: the real path of a module's own file, or a
|
|
599
|
-
// copy in a temporary directory of a module from the root module's file or from the jar on the
|
|
600
|
-
// class path, followed by where TLC copied it from.
|
|
601
690
|
const createFileDescriber = (
|
|
602
691
|
specPath: string,
|
|
603
692
|
directories: string[],
|
|
@@ -612,9 +701,7 @@ const createFileDescriber = (
|
|
|
612
701
|
return (name: string, origin: SanyModuleOrigin) => {
|
|
613
702
|
const fileName = `${name}.tla`;
|
|
614
703
|
if (origin === "file") return realpathSync(findModuleFile(directories, name) ?? specPath);
|
|
615
|
-
// TLC 1.7.4 copies a standard module into the temporary directory itself.
|
|
616
704
|
if (version === "1.7.4") return join(temporaryDirectory, fileName);
|
|
617
|
-
// FileUtil.createTempFile copies a module from the root module's file into the -metadir.
|
|
618
705
|
if (origin === "root file") {
|
|
619
706
|
const directory = metadir === undefined ? temporaryDirectory : resolve(metadir);
|
|
620
707
|
const root = realpathSync(specPath);
|
|
@@ -628,8 +715,21 @@ const createFileDescriber = (
|
|
|
628
715
|
const printWelcome = (printer: MessagePrinter) =>
|
|
629
716
|
printer.print(MESSAGE_CODE.version, MESSAGE_LEVEL.none, `TLC2 Version ${version} (rev: tla-ts)`);
|
|
630
717
|
|
|
631
|
-
|
|
632
|
-
const
|
|
718
|
+
const getEmbeddedConfig = (contents: string, name: string) => {
|
|
719
|
+
const lines = contents.split(/\r?\n/);
|
|
720
|
+
const start = lines.findIndex(
|
|
721
|
+
(line) => line.match(/^-----*\s*CONFIG\s+(\S+?)\s*-----*$/)?.[1] === name,
|
|
722
|
+
);
|
|
723
|
+
if (start === -1) return "\n";
|
|
724
|
+
const end = lines.findIndex((line, index) => index > start && line.startsWith("===="));
|
|
725
|
+
return `${lines
|
|
726
|
+
.slice(start + 1, end === -1 ? undefined : end)
|
|
727
|
+
.join("\n")
|
|
728
|
+
.trim()}\n`;
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
const printCommandLineError = (isTool: boolean, version: TlcVersion, message: string) => {
|
|
732
|
+
const printer = createMessagePrinter(isTool, true, version);
|
|
633
733
|
printWelcome(printer);
|
|
634
734
|
printer.print(
|
|
635
735
|
MESSAGE_CODE.commandLineError,
|
|
@@ -639,86 +739,188 @@ const printCommandLineError = (printer: MessagePrinter, message: string) => {
|
|
|
639
739
|
return 1;
|
|
640
740
|
};
|
|
641
741
|
|
|
642
|
-
//
|
|
643
|
-
|
|
644
|
-
const
|
|
742
|
+
// Deviation from TLC: tla-ts keeps its fingerprints and its queue of states in memory.
|
|
743
|
+
const printStartupBanner = (printer: MessagePrinter, args: TlcArguments) => {
|
|
744
|
+
const workers = `${args.workers} worker${args.workers === 1 ? "" : "s"} on ${availableParallelism()} cores with ${Math.floor(getHeapStatistics().heap_size_limit / 1024 / 1024)}MB heap and 0MB offheap memory [pid: ${process.pid}] (${type()} ${release()} ${arch()}, Node.js ${process.versions.node} ${process.arch.endsWith("64") ? 64 : 32}bit`;
|
|
745
|
+
if (args.mode === "model-check" && args.dfidDepth !== undefined) {
|
|
746
|
+
printer.print(
|
|
747
|
+
MESSAGE_CODE.depthFirstModelChecking,
|
|
748
|
+
MESSAGE_LEVEL.none,
|
|
749
|
+
`Running depth-first search Model-Checking with fp ${args.fingerprintIndex} and seed ${args.seed} with ${workers}).`,
|
|
750
|
+
);
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
if (args.mode === "model-check") {
|
|
754
|
+
printer.print(
|
|
755
|
+
MESSAGE_CODE.modelChecking,
|
|
756
|
+
MESSAGE_LEVEL.none,
|
|
757
|
+
`Running breadth-first search Model-Checking with fp ${args.fingerprintIndex} and seed ${args.seed} with ${workers}, MemFPSet, MemStateQueue).`,
|
|
758
|
+
);
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
645
761
|
printer.print(
|
|
646
|
-
MESSAGE_CODE.
|
|
762
|
+
MESSAGE_CODE.simulating,
|
|
647
763
|
MESSAGE_LEVEL.none,
|
|
648
|
-
`Running
|
|
764
|
+
`Running ${args.scheduler === "rl" ? "RL" : "Random"} Simulation with seed ${args.seed} with ${workers}).`,
|
|
649
765
|
);
|
|
766
|
+
};
|
|
650
767
|
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
768
|
+
const printSimulation = (printer: TlcPrinter, output: SimulationOutput) => {
|
|
769
|
+
const print = printer.print;
|
|
770
|
+
switch (output.kind) {
|
|
771
|
+
case "message":
|
|
772
|
+
print(
|
|
773
|
+
output.code,
|
|
774
|
+
output.isError ? MESSAGE_LEVEL.error : MESSAGE_LEVEL.none,
|
|
775
|
+
printer.isTool ? output.toolMessage : output.message,
|
|
776
|
+
);
|
|
777
|
+
return;
|
|
778
|
+
case "behavior": {
|
|
779
|
+
const last = output.trace[output.trace.length - 1];
|
|
780
|
+
if (!output.isLastStateOnly) {
|
|
781
|
+
printTrace(printer, output.trace, BEHAVIOR, false, true);
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
print(MESSAGE_CODE.errorState, MESSAGE_LEVEL.none, "The error state is:\n");
|
|
785
|
+
print(MESSAGE_CODE.statePrint1, MESSAGE_LEVEL.state, `:\n${formatState(last.state)}`);
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
case "progress": {
|
|
789
|
+
const statistics = output.statistics;
|
|
790
|
+
if (printer.isTool) {
|
|
791
|
+
printSimulationProgress(printer, statistics);
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
const variance = statistics.levelM2 / (statistics.traces + 1);
|
|
795
|
+
print(
|
|
796
|
+
MESSAGE_CODE.simulationProgress,
|
|
797
|
+
MESSAGE_LEVEL.none,
|
|
798
|
+
`Progress: ${statistics.generatedStates} states checked, ${statistics.traces} traces generated (trace length: mean=${statistics.levelMean}, var(x)=${Math.round(variance)}, sd=${Math.round(Math.sqrt(variance))})`,
|
|
799
|
+
);
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
case "summary":
|
|
803
|
+
if (printer.isTool) printSimulationProgress(printer, output.statistics);
|
|
804
|
+
print(
|
|
805
|
+
MESSAGE_CODE.simulationStats,
|
|
806
|
+
MESSAGE_LEVEL.none,
|
|
807
|
+
`The number of states generated: ${output.statistics.generatedStates}\nSimulation using seed ${output.statistics.seed} and aril ${output.statistics.aril}`,
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
|
|
812
|
+
const printSimulationProgress = (printer: MessagePrinter, statistics: SimulationStatistics) =>
|
|
813
|
+
printer.print(
|
|
814
|
+
MESSAGE_CODE.simulationProgress,
|
|
815
|
+
MESSAGE_LEVEL.none,
|
|
816
|
+
`Progress(${statistics.traces}) at ${formatTlcDate(new Date())}: ${statistics.generatedStates} states generated, -1 distinct states found, -1 states left on queue.`,
|
|
817
|
+
);
|
|
818
|
+
|
|
819
|
+
const getJavaPath = (path: string) => path.replace(/\/+/g, "/").replace(/(.)\/$/, "$1");
|
|
820
|
+
|
|
821
|
+
const getJavaParent = (path: string) => {
|
|
822
|
+
const normalized = getJavaPath(path);
|
|
823
|
+
const separator = normalized.lastIndexOf("/");
|
|
824
|
+
return separator === -1 ? "." : normalized.slice(0, Math.max(separator, 1));
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
const resolveJavaPath = (directory: string, name: string) =>
|
|
828
|
+
directory.endsWith("/") ? `${directory}${name}` : `${directory}/${name}`;
|
|
829
|
+
|
|
830
|
+
const getTraceSpecLocation = (
|
|
831
|
+
args: TlcArguments,
|
|
832
|
+
version: TlcVersion,
|
|
833
|
+
mainFile: string,
|
|
834
|
+
startTime: number,
|
|
835
|
+
) => {
|
|
836
|
+
const isGenerated =
|
|
837
|
+
version !== "1.7.4" &&
|
|
838
|
+
(args.isTraceSpecForced ||
|
|
839
|
+
(!args.isTraceSpecDisabled &&
|
|
840
|
+
!args.isTool &&
|
|
841
|
+
!args.isContinued &&
|
|
842
|
+
!basename(mainFile).includes("_TTrace")));
|
|
843
|
+
if (!isGenerated) return undefined;
|
|
844
|
+
const output = args.traceSpecPath;
|
|
845
|
+
const module = `${basename(mainFile)}_TTrace_${Math.floor(startTime / 1000)}`;
|
|
846
|
+
const location =
|
|
847
|
+
output === undefined
|
|
848
|
+
? { directory: getJavaParent(mainFile), module }
|
|
849
|
+
: output.toLowerCase().endsWith(".tla")
|
|
850
|
+
? { directory: getJavaParent(output), module: basename(output).replace(/\.tla$/, "") }
|
|
851
|
+
: { directory: getJavaPath(output), module };
|
|
852
|
+
return {
|
|
853
|
+
...location,
|
|
854
|
+
traceFile: args.isTraceBinaryDisabled
|
|
855
|
+
? undefined
|
|
856
|
+
: resolveJavaPath(location.directory, `${location.module}.bin`),
|
|
857
|
+
};
|
|
858
|
+
};
|
|
859
|
+
|
|
860
|
+
const JAVA_FILE_ERRORS: Record<string, string> = {
|
|
861
|
+
ENOENT: "No such file or directory",
|
|
862
|
+
ENOTDIR: "Not a directory",
|
|
863
|
+
EISDIR: "Is a directory",
|
|
864
|
+
EACCES: "Permission denied",
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
const writeJavaFile = (path: string, content: string | Uint8Array) => {
|
|
868
|
+
try {
|
|
869
|
+
writeFileSync(path, content);
|
|
870
|
+
} catch (error) {
|
|
871
|
+
const reason =
|
|
872
|
+
error instanceof Error && "code" in error ? JAVA_FILE_ERRORS[String(error.code)] : undefined;
|
|
873
|
+
if (reason === undefined) throw error;
|
|
874
|
+
throw new TlaEvaluationError(`${path} (${reason})`);
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
|
|
878
|
+
// Java's File#mkdirs reports a failure only through its result, which TLC ignores.
|
|
879
|
+
const makeJavaDirectory = (path: string) => {
|
|
880
|
+
try {
|
|
881
|
+
mkdirSync(path, { recursive: true });
|
|
882
|
+
} catch {}
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
const createMetadir = (args: TlcArguments) => {
|
|
886
|
+
const now = new Date();
|
|
887
|
+
const pad = (value: number, length = 2) => String(value).padStart(length, "0");
|
|
888
|
+
const name = `${pad(now.getFullYear() % 100)}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${pad(now.getHours())}-${pad(now.getMinutes())}-${pad(now.getSeconds())}.${pad(now.getMilliseconds(), 3)}`;
|
|
889
|
+
const directory = join(args.metadir ?? "states", name);
|
|
890
|
+
mkdirSync(directory, { recursive: true });
|
|
891
|
+
return directory;
|
|
662
892
|
};
|
|
663
893
|
|
|
664
894
|
const checkSpec = async (
|
|
665
895
|
specPath: string,
|
|
666
|
-
args:
|
|
896
|
+
args: TlcArguments,
|
|
897
|
+
dump: StateDump | undefined,
|
|
667
898
|
java: JavaProperties,
|
|
668
|
-
printer:
|
|
899
|
+
printer: TlcPrinter,
|
|
669
900
|
) => {
|
|
670
|
-
|
|
671
|
-
const seed = args.has("-seed") ? args.get("-seed")?.[0] : "0";
|
|
672
|
-
if (seed === undefined) return printCommandLineError(printer, "Error: seed required.");
|
|
673
|
-
if (!isJavaLong(seed)) {
|
|
674
|
-
return printCommandLineError(
|
|
675
|
-
printer,
|
|
676
|
-
`Error: An integer for seed required. But encountered ${seed}`,
|
|
677
|
-
);
|
|
678
|
-
}
|
|
679
|
-
const livenessCheck = args.has("-lncheck") ? args.get("-lncheck")?.[0]?.toLowerCase() : "default";
|
|
680
|
-
if (livenessCheck === undefined) {
|
|
681
|
-
return printCommandLineError(
|
|
682
|
-
printer,
|
|
683
|
-
"Error: expect a strategy such as final for -lncheck option.",
|
|
684
|
-
);
|
|
685
|
-
}
|
|
686
|
-
const dumpValues = args.get("-dump");
|
|
687
|
-
if (dumpValues?.length === 0) {
|
|
688
|
-
return printCommandLineError(printer, "Error: A file name for dumping states required.");
|
|
689
|
-
}
|
|
690
|
-
const unsupportedFormat =
|
|
691
|
-
dumpValues?.length === 2 &&
|
|
692
|
-
UNSUPPORTED_DUMP_FORMATS.find((format) => dumpValues[0].toLowerCase().includes(format));
|
|
693
|
-
if (unsupportedFormat) {
|
|
694
|
-
console.error(`Error: tla-ts does not support the -dump format ${unsupportedFormat}.`);
|
|
695
|
-
return 1;
|
|
696
|
-
}
|
|
697
|
-
const fingerprintIndex = args.get("-fp")?.[0];
|
|
698
|
-
if (fingerprintIndex !== undefined && Number(fingerprintIndex) !== 0) {
|
|
699
|
-
console.error(
|
|
700
|
-
`Error: tla-ts fingerprints states as TLC does with -fp 0, not -fp ${fingerprintIndex}.`,
|
|
701
|
-
);
|
|
702
|
-
return 1;
|
|
703
|
-
}
|
|
704
|
-
const workers = getWorkerCount(args.get("-workers"));
|
|
901
|
+
const livenessCheck = args.livenessCheck;
|
|
705
902
|
const version = printer.version;
|
|
706
903
|
printWelcome(printer);
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
904
|
+
const recoverDirectory = args.recoverDirectory;
|
|
905
|
+
if (recoverDirectory !== undefined) {
|
|
906
|
+
throw existsSync(join(recoverDirectory, "vars.chkpt"))
|
|
907
|
+
? new TlaFeatureUnsupportedError(
|
|
908
|
+
`tla-ts can't recover a model check from the checkpoint in ${recoverDirectory}.`,
|
|
909
|
+
)
|
|
910
|
+
: new TlaMissingCheckpointError(recoverDirectory);
|
|
911
|
+
}
|
|
912
|
+
printStartupBanner(printer, args);
|
|
913
|
+
const configPath = args.configPath ?? specPath.replace(/\.tla$/, ".cfg");
|
|
914
|
+
if (!existsSync(configPath)) {
|
|
712
915
|
printer.print(
|
|
713
916
|
MESSAGE_CODE.configFileError,
|
|
714
917
|
MESSAGE_LEVEL.error,
|
|
715
|
-
`TLC encountered the following error when trying to read the configuration file ${configPath
|
|
918
|
+
`TLC encountered the following error when trying to read the configuration file ${configPath}:\nFile not found.`,
|
|
716
919
|
);
|
|
717
920
|
return EXIT_STATUS.configParseError;
|
|
718
921
|
}
|
|
719
922
|
const fileName = basename(specPath, ".tla");
|
|
720
923
|
const timing: Timing = { startTime: Date.now(), livenessStartTime: undefined, isParsed: false };
|
|
721
|
-
// Without -tool, TLC prints how long it ran for a person to read.
|
|
722
924
|
const printFinished = () => {
|
|
723
925
|
const runtime = Date.now() - timing.startTime;
|
|
724
926
|
printer.print(
|
|
@@ -733,7 +935,6 @@ const checkSpec = async (
|
|
|
733
935
|
MESSAGE_LEVEL.error,
|
|
734
936
|
"Parsing or semantic analysis failed.",
|
|
735
937
|
);
|
|
736
|
-
// TLC prints how long it ran even when it stops at an error.
|
|
737
938
|
const printFailure = (error: TlaError) => {
|
|
738
939
|
if (error instanceof TlaSyntaxError) {
|
|
739
940
|
printParsingFailed();
|
|
@@ -741,19 +942,22 @@ const checkSpec = async (
|
|
|
741
942
|
printError(error, printer);
|
|
742
943
|
}
|
|
743
944
|
printFinished();
|
|
744
|
-
return
|
|
945
|
+
return getTopLevelExitCode(error);
|
|
745
946
|
};
|
|
746
|
-
// TLC reads the configuration file before it parses the spec, and prints how long it ran even
|
|
747
|
-
// when it can't read it.
|
|
748
947
|
const config = (() => {
|
|
749
948
|
try {
|
|
750
|
-
|
|
949
|
+
const contents = readFileSync(configPath, "utf8");
|
|
950
|
+
return parseConfig(
|
|
951
|
+
configPath.endsWith(".tla")
|
|
952
|
+
? getEmbeddedConfig(contents, configPath.replaceAll(".tla", ""))
|
|
953
|
+
: contents,
|
|
954
|
+
version,
|
|
955
|
+
);
|
|
751
956
|
} catch (error) {
|
|
752
957
|
if (!(error instanceof TlaConfigError)) throw error;
|
|
753
958
|
return error;
|
|
754
959
|
}
|
|
755
960
|
})();
|
|
756
|
-
// TLC 1.7.4 reports a configuration file it can't parse as an exception it didn't expect.
|
|
757
961
|
if (config instanceof TlaConfigError && version === "1.7.4") {
|
|
758
962
|
printer.print(
|
|
759
963
|
MESSAGE_CODE.general,
|
|
@@ -764,17 +968,23 @@ const checkSpec = async (
|
|
|
764
968
|
return EXIT_STATUS.error;
|
|
765
969
|
}
|
|
766
970
|
if (config instanceof TlaConfigError) return printFailure(config);
|
|
767
|
-
if (args.
|
|
971
|
+
if (!args.isDeadlockChecked) config.checkDeadlock = false;
|
|
768
972
|
const directory = dirname(specPath);
|
|
769
973
|
const directories = [directory, ...java.libraries];
|
|
770
974
|
const loadModule = createModuleLoader(directories);
|
|
771
|
-
const
|
|
975
|
+
const traceSpec = getTraceSpecLocation(
|
|
976
|
+
args,
|
|
977
|
+
version,
|
|
978
|
+
specPath.replace(/\.tla$/, ""),
|
|
979
|
+
timing.startTime,
|
|
980
|
+
);
|
|
981
|
+
const getOperatorModules = (kind: ModuleOperator["kind"]) =>
|
|
982
|
+
args.moduleOperators
|
|
983
|
+
.filter((operator) => operator.kind === kind)
|
|
984
|
+
.map((operator) => operator.module);
|
|
772
985
|
if (printer.isTool) {
|
|
773
986
|
printer.print(MESSAGE_CODE.startingSany, MESSAGE_LEVEL.none, "Starting SANY...");
|
|
774
987
|
}
|
|
775
|
-
// TLC.handleParameters: SANY names the spec as TLC's arguments do, except that TLC runs from the
|
|
776
|
-
// directory of a spec given by an absolute path, and names it by its file name. SANY looks for
|
|
777
|
-
// the spec's modules in the spec's directory and the TLA-Library directories.
|
|
778
988
|
const isAbsoluteSpec = isAbsolute(specPath);
|
|
779
989
|
const specName = isAbsoluteSpec ? fileName : specPath.replace(/\.tla$/, "");
|
|
780
990
|
const jar = getToolsJar(java);
|
|
@@ -791,27 +1001,28 @@ const checkSpec = async (
|
|
|
791
1001
|
[...(isAbsoluteSpec || directory === "." ? [] : [directory]), ...java.libraries],
|
|
792
1002
|
);
|
|
793
1003
|
}
|
|
794
|
-
// TLC prints what SANY prints as it parses the spec, and the errors it rejects the spec for.
|
|
795
1004
|
const sany = getSanyReport(
|
|
796
1005
|
specPath,
|
|
797
1006
|
reportMissingFile ? reportMissingModules174(loadModule, reportMissingFile) : loadModule,
|
|
798
1007
|
{
|
|
799
1008
|
fileName: specName,
|
|
800
|
-
describeFile: createFileDescriber(
|
|
801
|
-
specPath,
|
|
802
|
-
directories,
|
|
803
|
-
java,
|
|
804
|
-
args.get("-metadir")?.[0],
|
|
805
|
-
version,
|
|
806
|
-
),
|
|
1009
|
+
describeFile: createFileDescriber(specPath, directories, java, args.metadir, version),
|
|
807
1010
|
version,
|
|
808
|
-
|
|
809
|
-
|
|
1011
|
+
rootExtendees: [
|
|
1012
|
+
...getOperatorModules("postcondition"),
|
|
1013
|
+
...(traceSpec?.traceFile === undefined ? [] : ["_TLCTrace"]),
|
|
1014
|
+
...args.invariants.flatMap((invariant) => invariant.modules),
|
|
1015
|
+
...getOperatorModules("constraint"),
|
|
1016
|
+
...getOperatorModules("view").slice(0, 1),
|
|
1017
|
+
],
|
|
1018
|
+
suppressedCodes: args.suppressedCodes,
|
|
1019
|
+
errorCodes: args.errorCodes,
|
|
810
1020
|
onPrint: (text) => process.stdout.write(text),
|
|
811
1021
|
onPrintError: (text) => process.stderr.write(text),
|
|
812
1022
|
},
|
|
813
1023
|
);
|
|
814
|
-
|
|
1024
|
+
const specification = sany.specification;
|
|
1025
|
+
if (sany.isFailed || specification === undefined) {
|
|
815
1026
|
printCheckProgress(printer, { kind: "parsed" }, timing, directory);
|
|
816
1027
|
printParsingFailed();
|
|
817
1028
|
printFinished();
|
|
@@ -826,19 +1037,41 @@ const checkSpec = async (
|
|
|
826
1037
|
undefined,
|
|
827
1038
|
);
|
|
828
1039
|
}
|
|
829
|
-
const
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
1040
|
+
const userFile = args.userFile;
|
|
1041
|
+
const standardModules = getSanyStandardModules(version);
|
|
1042
|
+
const invariants = addRuntimeInvariants(
|
|
1043
|
+
source,
|
|
1044
|
+
specification.root,
|
|
1045
|
+
args.invariants,
|
|
1046
|
+
(name) => loadModule(name) ?? standardModules.get(name) ?? extractModule(source, name),
|
|
1047
|
+
version,
|
|
1048
|
+
);
|
|
1049
|
+
config.invariants.push(...invariants.names);
|
|
1050
|
+
const options: CheckOptions = {
|
|
1051
|
+
workers: args.workers,
|
|
1052
|
+
livenessCheck:
|
|
1053
|
+
livenessCheck === "off"
|
|
1054
|
+
? "off"
|
|
1055
|
+
: ["final", "seqfinal"].includes(livenessCheck)
|
|
1056
|
+
? "final"
|
|
1057
|
+
: "default",
|
|
1058
|
+
seed: args.seed,
|
|
1059
|
+
fingerprintPolynomial: args.fingerprintIndex,
|
|
1060
|
+
maxSetSize: args.maxSetSize,
|
|
1061
|
+
isLazyValueExpanded: args.isLazyValueExpanded,
|
|
1062
|
+
isViewPrinted: args.isViewPrinted,
|
|
1063
|
+
dump,
|
|
834
1064
|
isTool: printer.isTool,
|
|
835
|
-
isContinued: args.
|
|
836
|
-
|
|
1065
|
+
isContinued: args.isContinued,
|
|
1066
|
+
moduleOperators: args.moduleOperators,
|
|
1067
|
+
traceSpec,
|
|
1068
|
+
coverage: args.coverage,
|
|
837
1069
|
isSanyReported: true,
|
|
838
|
-
isWarningEnabled:
|
|
1070
|
+
isWarningEnabled: args.isWarningEnabled,
|
|
839
1071
|
version,
|
|
840
1072
|
onProgress: (progress) => printCheckProgress(printer, progress, timing, directory),
|
|
841
|
-
|
|
1073
|
+
onPrint: userFile === undefined ? undefined : (text) => appendFileSync(userFile, `${text}\n`),
|
|
1074
|
+
source: invariants.source,
|
|
842
1075
|
config,
|
|
843
1076
|
onPause: () => readSync(0, Buffer.alloc(1)),
|
|
844
1077
|
loadModule,
|
|
@@ -846,14 +1079,58 @@ const checkSpec = async (
|
|
|
846
1079
|
const classPath = getClassPath(directory, name);
|
|
847
1080
|
return existsSync(classPath) ? readFileSync(classPath) : undefined;
|
|
848
1081
|
},
|
|
849
|
-
readFile: (path) =>
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
writeFileSync(path, content);
|
|
1082
|
+
readFile: (path) => {
|
|
1083
|
+
checkNotDirectory(path);
|
|
1084
|
+
return existsSync(path) ? readFileSync(path, "utf8") : undefined;
|
|
853
1085
|
},
|
|
854
|
-
|
|
1086
|
+
writeFile: writeJavaFile,
|
|
1087
|
+
makeDirectory: makeJavaDirectory,
|
|
1088
|
+
};
|
|
1089
|
+
if (args.mode !== "model-check") {
|
|
1090
|
+
const status = simulate({
|
|
1091
|
+
...options,
|
|
1092
|
+
traceDepth: args.traceDepth,
|
|
1093
|
+
traceCount: args.traceCount,
|
|
1094
|
+
aril: args.aril,
|
|
1095
|
+
isGenerating: args.mode === "generate",
|
|
1096
|
+
scheduler: args.scheduler,
|
|
1097
|
+
onSimulation: (output) => printSimulation(printer, output),
|
|
1098
|
+
});
|
|
1099
|
+
printFinished();
|
|
1100
|
+
return status;
|
|
1101
|
+
}
|
|
1102
|
+
if (args.dfidDepth !== undefined) {
|
|
1103
|
+
const status = checkDepthFirst({
|
|
1104
|
+
...options,
|
|
1105
|
+
maxDepth: args.dfidDepth,
|
|
1106
|
+
onOutput: (output) => printDepthFirst(printer, output),
|
|
1107
|
+
});
|
|
1108
|
+
printFinished();
|
|
1109
|
+
return status;
|
|
1110
|
+
}
|
|
1111
|
+
const result = await check(options);
|
|
855
1112
|
printResult(result, printer, timing);
|
|
856
1113
|
printFinished();
|
|
1114
|
+
if (traceSpec && result.traceSpec !== undefined) {
|
|
1115
|
+
const path = resolveJavaPath(traceSpec.directory, `${traceSpec.module}.tla`);
|
|
1116
|
+
makeJavaDirectory(traceSpec.directory);
|
|
1117
|
+
const failure = (() => {
|
|
1118
|
+
try {
|
|
1119
|
+
writeJavaFile(path, result.traceSpec);
|
|
1120
|
+
return undefined;
|
|
1121
|
+
} catch (error) {
|
|
1122
|
+
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1123
|
+
return error;
|
|
1124
|
+
}
|
|
1125
|
+
})();
|
|
1126
|
+
printer.print(
|
|
1127
|
+
failure ? MESSAGE_CODE.traceSpecFailed : MESSAGE_CODE.traceSpecWritten,
|
|
1128
|
+
MESSAGE_LEVEL.none,
|
|
1129
|
+
failure
|
|
1130
|
+
? `Failed to generate trace exploration spec; error message: ${failure.message}`
|
|
1131
|
+
: `Trace exploration spec path: ${path}`,
|
|
1132
|
+
);
|
|
1133
|
+
}
|
|
857
1134
|
return result.failure?.exitCode ?? EXIT_CODES[result.status];
|
|
858
1135
|
} catch (error) {
|
|
859
1136
|
if (!(error instanceof TlaError)) throw error;
|
|
@@ -863,8 +1140,6 @@ const checkSpec = async (
|
|
|
863
1140
|
}
|
|
864
1141
|
};
|
|
865
1142
|
|
|
866
|
-
// What SANY prints about a spec it rejects: a module it can't find or parse is a fatal error, and
|
|
867
|
-
// it reports the other errors as semantic errors.
|
|
868
1143
|
const formatSanyErrors = (error: TlaSyntaxError, specName: string) => {
|
|
869
1144
|
const isFatal = error instanceof TlaSanyFatalError;
|
|
870
1145
|
if (!isFatal && !error.failure)
|
|
@@ -879,12 +1154,48 @@ const formatSanyErrors = (error: TlaSyntaxError, specName: string) => {
|
|
|
879
1154
|
};
|
|
880
1155
|
|
|
881
1156
|
export const checkSpecs = async (args: string[], java: JavaProperties) => {
|
|
882
|
-
const
|
|
883
|
-
const
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
1157
|
+
const version = java.tlcVersion ?? "master";
|
|
1158
|
+
const parsed = parseTlcArguments(args);
|
|
1159
|
+
if ("error" in parsed) {
|
|
1160
|
+
if (parsed.isUncaught) {
|
|
1161
|
+
console.error(`Exception in thread "main" ${parsed.error}`);
|
|
1162
|
+
return 1;
|
|
1163
|
+
}
|
|
1164
|
+
return printCommandLineError(parsed.isTool, version, parsed.error);
|
|
1165
|
+
}
|
|
1166
|
+
if (parsed.isUsage) {
|
|
1167
|
+
console.log(getTlcUsage());
|
|
1168
|
+
return 1;
|
|
1169
|
+
}
|
|
1170
|
+
const dump =
|
|
1171
|
+
parsed.dump &&
|
|
1172
|
+
getStateDump(
|
|
1173
|
+
parsed.dump.map((value) =>
|
|
1174
|
+
value.includes("${metadir}") ? value.replace("${metadir}", createMetadir(parsed)) : value,
|
|
1175
|
+
),
|
|
1176
|
+
);
|
|
1177
|
+
const dumpPath = dump?.path;
|
|
1178
|
+
if (dumpPath !== undefined) {
|
|
1179
|
+
try {
|
|
1180
|
+
closeSync(openSync(dumpPath, "w"));
|
|
1181
|
+
} catch {
|
|
1182
|
+
console.log(`Error: Unable to write to file ${dumpPath}`);
|
|
1183
|
+
return printCommandLineError(
|
|
1184
|
+
parsed.isTool,
|
|
1185
|
+
version,
|
|
1186
|
+
`Error: Given file name ${dumpPath} for dumping states invalid.`,
|
|
1187
|
+
);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
const isConfigured = parsed.configPath !== undefined;
|
|
1191
|
+
if (isConfigured && parsed.specs.length > 1) {
|
|
1192
|
+
return printCommandLineError(
|
|
1193
|
+
parsed.isTool,
|
|
1194
|
+
version,
|
|
1195
|
+
`Error: more than one input files: ${parsed.specs[0].replace(/\.tla$/, "")} and ${parsed.specs[1]}`,
|
|
1196
|
+
);
|
|
1197
|
+
}
|
|
1198
|
+
const inputs = getInputPaths(parsed.specs);
|
|
888
1199
|
const specPaths = inputs
|
|
889
1200
|
.map((input) => ({
|
|
890
1201
|
...input,
|
|
@@ -901,46 +1212,44 @@ export const checkSpecs = async (args: string[], java: JavaProperties) => {
|
|
|
901
1212
|
)
|
|
902
1213
|
.map((input) => input.path);
|
|
903
1214
|
if (specPaths.length === 0) {
|
|
904
|
-
|
|
905
|
-
return 1;
|
|
1215
|
+
return printCommandLineError(parsed.isTool, version, "Error: Missing input TLA+ module.");
|
|
906
1216
|
}
|
|
907
1217
|
if (isConfigured && specPaths.length > 1) {
|
|
908
1218
|
console.error("Error: -config applies to one specification, but several were given.");
|
|
909
1219
|
return 1;
|
|
910
1220
|
}
|
|
911
|
-
// TLC also looks for the spec itself in the library directories.
|
|
912
1221
|
const findSpec = (path: string) =>
|
|
913
1222
|
existsSync(path) || isAbsolute(path)
|
|
914
1223
|
? path
|
|
915
1224
|
: (java.libraries.map((directory) => join(directory, path)).find(existsSync) ?? path);
|
|
916
1225
|
const paths = [...new Set(specPaths.map(findSpec))];
|
|
917
|
-
// Each spec is checked as TLC would in a process of its own, so an error in one leaves the others
|
|
918
|
-
// to report. The exit code is the first that is not success.
|
|
919
1226
|
const exitCodes: number[] = [];
|
|
920
1227
|
for (const [index, path] of paths.entries()) {
|
|
921
1228
|
if (index > 0) console.log("");
|
|
922
|
-
const printer =
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1229
|
+
const printer = {
|
|
1230
|
+
...createMessagePrinter(
|
|
1231
|
+
parsed.isTool,
|
|
1232
|
+
parsed.isWarningEnabled,
|
|
1233
|
+
version,
|
|
1234
|
+
parsed.suppressedCodes,
|
|
1235
|
+
parsed.errorCodes,
|
|
1236
|
+
),
|
|
1237
|
+
isDiffTrace: parsed.isDiffTrace,
|
|
1238
|
+
};
|
|
927
1239
|
exitCodes.push(
|
|
928
1240
|
await reportErrors(async () => {
|
|
929
1241
|
const specPath = path.endsWith(".ts") ? await writeTypeScriptSpec(path) : path;
|
|
930
|
-
// TLC checks one spec, so tla-ts names each of several it checks.
|
|
1242
|
+
// Deviation from TLC: TLC checks one spec, so tla-ts names each of several it checks.
|
|
931
1243
|
if (paths.length > 1) {
|
|
932
1244
|
console.log(`Checking ${basename(specPath)} with ${basename(specPath, ".tla")}.cfg`);
|
|
933
1245
|
}
|
|
934
|
-
return checkSpec(specPath, parsed, java, printer);
|
|
1246
|
+
return checkSpec(specPath, parsed, dump, java, printer);
|
|
935
1247
|
}, printer),
|
|
936
1248
|
);
|
|
937
1249
|
}
|
|
938
1250
|
return exitCodes.find((exitCode) => exitCode !== EXIT_STATUS.success) ?? EXIT_STATUS.success;
|
|
939
1251
|
};
|
|
940
1252
|
|
|
941
|
-
// TLC 1.7.4's SimpleFilenameToStream looks for a module in the directory of a spec that TLC is
|
|
942
|
-
// given by an absolute path, then in the directory that a relative path names, or else in the
|
|
943
|
-
// TLA-Library directories.
|
|
944
1253
|
const createMissingFilePrinter174 = (
|
|
945
1254
|
specPath: string,
|
|
946
1255
|
java: JavaProperties,
|