tla-ts 0.0.3 → 0.0.4-dev.1a3acf6
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 +46 -115
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/deciders.cjs +366 -0
- package/dist/deciders.js +366 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +194 -8
- package/dist/index.d.ts +194 -8
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -4
- package/dist/parallel-worker.js +1 -4
- package/dist/prove-worker.cjs +9 -0
- package/dist/prove-worker.d.cts +9 -0
- package/dist/prove-worker.d.ts +9 -0
- package/dist/prove-worker.js +9 -0
- package/dist/prove.cjs +1006 -0
- package/dist/prove.js +1006 -0
- package/dist/run.cjs +45 -0
- package/dist/run.js +45 -0
- package/dist/tlapm.cjs +10 -0
- package/dist/tlapm.js +10 -0
- package/dist/transfer.cjs +1377 -18
- package/dist/transfer.js +1377 -18
- package/dist/worker.cjs +21 -0
- package/dist/worker.js +21 -0
- package/package.json +24 -11
- package/src/ast.ts +149 -8
- package/src/bags.ts +26 -30
- package/src/builtins.ts +45 -19
- package/src/bundled-modules.ts +3 -3
- package/src/check.ts +1182 -900
- package/src/cli/options.ts +109 -0
- package/src/cli/run.ts +63 -0
- package/src/cli/shared.ts +106 -0
- package/src/cli/tlapm.ts +374 -0
- package/src/cli/tlc.ts +941 -0
- package/src/cli/xml-exporter.ts +221 -0
- package/src/cli.ts +9 -2
- package/src/codegen.ts +112 -51
- package/src/config.ts +254 -181
- package/src/dependencies.ts +5 -7
- package/src/environment.ts +579 -184
- package/src/errors.ts +287 -4
- package/src/evaluate.ts +1095 -365
- package/src/exit-codes.ts +22 -43
- package/src/fingerprints.ts +49 -14
- package/src/index.ts +11 -0
- package/src/instances.ts +73 -60
- package/src/java-overrides.ts +183 -66
- package/src/json.ts +31 -36
- package/src/levels.ts +197 -54
- package/src/lexer.ts +127 -30
- package/src/liveness-checker.ts +894 -0
- package/src/liveness.ts +246 -596
- package/src/{obligation-action.ts → obligations/action.ts} +248 -74
- package/src/{obligation-anon.ts → obligations/anonymize.ts} +55 -57
- package/src/obligations/equality.ts +260 -0
- package/src/obligations/expression.ts +618 -0
- package/src/{obligation-format.ts → obligations/format.ts} +7 -8
- package/src/obligations/generate.ts +457 -0
- package/src/{obligations.ts → obligations/index.ts} +46 -32
- package/src/{obligation-levels.ts → obligations/levels.ts} +44 -40
- package/src/obligations/module.ts +445 -0
- package/src/obligations/normalize.ts +554 -0
- package/src/obligations/operators.ts +176 -0
- package/src/obligations/pragma.ts +195 -0
- package/src/{obligation-printer.ts → obligations/printer.ts} +65 -230
- package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
- package/src/obligations/regroup.ts +100 -0
- package/src/{obligation-generate.ts → obligations/simplify.ts} +130 -536
- package/src/{obligation-source.ts → obligations/source.ts} +174 -216
- package/src/{obligation-deref.ts → obligations/subexpression.ts} +84 -115
- package/src/obligations/substitution.ts +261 -0
- package/src/obligations/temporal.ts +321 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
- package/src/parallel-worker.ts +184 -235
- package/src/parallel.ts +156 -91
- package/src/parser.ts +490 -188
- package/src/pcal/ast.ts +755 -0
- package/src/pcal/parse.ts +1487 -0
- package/src/pcal/tokenize.ts +487 -0
- package/src/pcal/translate.ts +1151 -0
- package/src/pcal/validate.ts +444 -0
- package/src/prover/decide-pool.ts +95 -0
- package/src/prover/deciders.ts +33 -0
- package/src/prover/first-order.ts +175 -0
- package/src/prover/isabelle/LICENSE +36 -0
- package/src/prover/isabelle/LICENSE-tlapm +26 -0
- package/src/prover/isabelle/decide.ts +44 -0
- package/src/prover/isabelle/encode.ts +445 -0
- package/src/prover/isabelle/isar/inner-syntax.ts +579 -0
- package/src/prover/isabelle/isar/method.ts +367 -0
- package/src/prover/isabelle/isar/proof.ts +28 -0
- package/src/prover/isabelle/isar/statement.ts +57 -0
- package/src/prover/isabelle/isar/theory.ts +192 -0
- package/src/prover/isabelle/isar/type-check.ts +278 -0
- package/src/prover/isabelle/provers/blast/blast.ts +258 -0
- package/src/prover/isabelle/provers/blast/branch.ts +322 -0
- package/src/prover/isabelle/provers/blast/prove.ts +347 -0
- package/src/prover/isabelle/provers/blast/rules.ts +330 -0
- package/src/prover/isabelle/provers/blast/state.ts +180 -0
- package/src/prover/isabelle/provers/blast/term.ts +546 -0
- package/src/prover/isabelle/provers/clasimp.ts +150 -0
- package/src/prover/isabelle/provers/classical.ts +389 -0
- package/src/prover/isabelle/provers/hypsubst.ts +433 -0
- package/src/prover/isabelle/pure/bicompose.ts +174 -0
- package/src/prover/isabelle/pure/consts.ts +32 -0
- package/src/prover/isabelle/pure/conv.ts +79 -0
- package/src/prover/isabelle/pure/drule.ts +264 -0
- package/src/prover/isabelle/pure/envir.ts +331 -0
- package/src/prover/isabelle/pure/goal.ts +53 -0
- package/src/prover/isabelle/pure/interrupt.ts +16 -0
- package/src/prover/isabelle/pure/list.ts +12 -0
- package/src/prover/isabelle/pure/logic.ts +330 -0
- package/src/prover/isabelle/pure/name.ts +98 -0
- package/src/prover/isabelle/pure/net.ts +215 -0
- package/src/prover/isabelle/pure/object-logic.ts +41 -0
- package/src/prover/isabelle/pure/pattern.ts +631 -0
- package/src/prover/isabelle/pure/raw-simplifier.ts +338 -0
- package/src/prover/isabelle/pure/rewriter.ts +602 -0
- package/src/prover/isabelle/pure/search.ts +68 -0
- package/src/prover/isabelle/pure/seq.ts +133 -0
- package/src/prover/isabelle/pure/simplifier.ts +106 -0
- package/src/prover/isabelle/pure/table.ts +201 -0
- package/src/prover/isabelle/pure/tactic.ts +168 -0
- package/src/prover/isabelle/pure/tactical.ts +264 -0
- package/src/prover/isabelle/pure/term-ord.ts +105 -0
- package/src/prover/isabelle/pure/term.ts +688 -0
- package/src/prover/isabelle/pure/thm.ts +783 -0
- package/src/prover/isabelle/pure/type.ts +121 -0
- package/src/prover/isabelle/pure/unify.ts +753 -0
- package/src/prover/isabelle/pure/variable.ts +25 -0
- package/src/prover/isabelle/tla/classical-setup.ts +101 -0
- package/src/prover/isabelle/tla/context.ts +74 -0
- package/src/prover/isabelle/tla/logic-data.ts +5 -0
- package/src/prover/isabelle/tla/logic.ts +215 -0
- package/src/prover/isabelle/tla/simpdata.ts +241 -0
- package/src/prover/isabelle/tools/intuitionistic.ts +132 -0
- package/src/prover/ocaml.ts +22 -0
- package/src/prover/prep/action.ts +508 -0
- package/src/prover/prep/enabled-axioms.ts +189 -0
- package/src/prover/prep/fingerprint.ts +388 -0
- package/src/prover/prep/level-comparison.ts +529 -0
- package/src/prover/prep/md5.ts +60 -0
- package/src/prover/prep/methods.ts +221 -0
- package/src/prover/prep/normalize.ts +309 -0
- package/src/prover/prove-worker.ts +22 -0
- package/src/prover/prove.ts +492 -0
- package/src/prover/ptl/decide.ts +68 -0
- package/src/prover/ptl/encode.ts +244 -0
- package/src/prover/ptl/sat.ts +151 -0
- package/src/prover/ptl/tableau.ts +276 -0
- package/src/prover/smt/axioms.ts +209 -0
- package/src/prover/smt/context.ts +108 -0
- package/src/prover/smt/data.ts +636 -0
- package/src/prover/smt/encode.ts +275 -0
- package/src/prover/smt/extensionality.ts +65 -0
- package/src/prover/smt/flatten.ts +112 -0
- package/src/prover/smt/format.ts +154 -0
- package/src/prover/smt/instances.ts +181 -0
- package/src/prover/smt/rewrite.ts +766 -0
- package/src/prover/smt/solver/act-cache.ts +265 -0
- package/src/prover/smt/solver/arith-rewriter.ts +962 -0
- package/src/prover/smt/solver/array.ts +22 -0
- package/src/prover/smt/solver/asserted-formulas.ts +469 -0
- package/src/prover/smt/solver/ast-lt.ts +157 -0
- package/src/prover/smt/solver/ast-util.ts +91 -0
- package/src/prover/smt/solver/ast.ts +1315 -0
- package/src/prover/smt/solver/auf-solver.ts +572 -0
- package/src/prover/smt/solver/case-split-queue.ts +178 -0
- package/src/prover/smt/solver/cg-table.ts +175 -0
- package/src/prover/smt/solver/clause.ts +276 -0
- package/src/prover/smt/solver/conflict-resolution.ts +343 -0
- package/src/prover/smt/solver/context.ts +1292 -0
- package/src/prover/smt/solver/ctx-simplify.ts +334 -0
- package/src/prover/smt/solver/der.ts +224 -0
- package/src/prover/smt/solver/dyn-ack.ts +141 -0
- package/src/prover/smt/solver/e-matching.ts +659 -0
- package/src/prover/smt/solver/enode.ts +259 -0
- package/src/prover/smt/solver/expr-ref.ts +21 -0
- package/src/prover/smt/solver/expr-safe-replace.ts +172 -0
- package/src/prover/smt/solver/fingerprints.ts +92 -0
- package/src/prover/smt/solver/flat-literals.ts +51 -0
- package/src/prover/smt/solver/goal.ts +138 -0
- package/src/prover/smt/solver/hash.ts +173 -0
- package/src/prover/smt/solver/hashtable.ts +166 -0
- package/src/prover/smt/solver/internalizer.ts +1381 -0
- package/src/prover/smt/solver/lbool.ts +5 -0
- package/src/prover/smt/solver/literal.ts +24 -0
- package/src/prover/smt/solver/lp/bound-propagator.ts +391 -0
- package/src/prover/smt/solver/lp/constraints.ts +78 -0
- package/src/prover/smt/solver/lp/containers.ts +296 -0
- package/src/prover/smt/solver/lp/core-solver.ts +504 -0
- package/src/prover/smt/solver/lp/cross-nested.ts +224 -0
- package/src/prover/smt/solver/lp/dep-intervals.ts +642 -0
- package/src/prover/smt/solver/lp/dependency.ts +51 -0
- package/src/prover/smt/solver/lp/dioph-eq.ts +1181 -0
- package/src/prover/smt/solver/lp/explanation.ts +46 -0
- package/src/prover/smt/solver/lp/gomory.ts +255 -0
- package/src/prover/smt/solver/lp/hnf-cutter.ts +125 -0
- package/src/prover/smt/solver/lp/hnf.ts +281 -0
- package/src/prover/smt/solver/lp/int-cube.ts +295 -0
- package/src/prover/smt/solver/lp/int-solver.ts +514 -0
- package/src/prover/smt/solver/lp/lar-solver.ts +816 -0
- package/src/prover/smt/solver/lp/lar-term.ts +62 -0
- package/src/prover/smt/solver/lp/lp-settings.ts +91 -0
- package/src/prover/smt/solver/lp/maximize-term.ts +347 -0
- package/src/prover/smt/solver/lp/nex-creator.ts +381 -0
- package/src/prover/smt/solver/lp/nex.ts +120 -0
- package/src/prover/smt/solver/lp/nla-backoff.ts +43 -0
- package/src/prover/smt/solver/lp/nla-basics.ts +398 -0
- package/src/prover/smt/solver/lp/nla-core.ts +968 -0
- package/src/prover/smt/solver/lp/nla-divisions.ts +332 -0
- package/src/prover/smt/solver/lp/nla-emonics.ts +373 -0
- package/src/prover/smt/solver/lp/nla-factorization.ts +30 -0
- package/src/prover/smt/solver/lp/nla-grobner.ts +904 -0
- package/src/prover/smt/solver/lp/nla-horner.ts +126 -0
- package/src/prover/smt/solver/lp/nla-intervals.ts +265 -0
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +715 -0
- package/src/prover/smt/solver/lp/nla-monotone.ts +59 -0
- package/src/prover/smt/solver/lp/nla-order.ts +307 -0
- package/src/prover/smt/solver/lp/nla-patcher.ts +112 -0
- package/src/prover/smt/solver/lp/nla-tangents.ts +251 -0
- package/src/prover/smt/solver/lp/nla-throttle.ts +85 -0
- package/src/prover/smt/solver/lp/nla-types.ts +124 -0
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +141 -0
- package/src/prover/smt/solver/lp/nra-solver.ts +440 -0
- package/src/prover/smt/solver/lp/numeric-pair.ts +65 -0
- package/src/prover/smt/solver/lp/pdd-interval.ts +31 -0
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +184 -0
- package/src/prover/smt/solver/lp/pdd-solver.ts +408 -0
- package/src/prover/smt/solver/lp/pdd.ts +971 -0
- package/src/prover/smt/solver/lp/random-updater.ts +138 -0
- package/src/prover/smt/solver/lp/static-matrix.ts +246 -0
- package/src/prover/smt/solver/lp/union-find.ts +96 -0
- package/src/prover/smt/solver/mam-compiler.ts +847 -0
- package/src/prover/smt/solver/mam-interpreter.ts +400 -0
- package/src/prover/smt/solver/maximize-ac-sharing.ts +118 -0
- package/src/prover/smt/solver/model-checker.ts +347 -0
- package/src/prover/smt/solver/model-evaluator.ts +262 -0
- package/src/prover/smt/solver/model-finder.ts +155 -0
- package/src/prover/smt/solver/model-generator.ts +97 -0
- package/src/prover/smt/solver/model-macro-solver.ts +728 -0
- package/src/prover/smt/solver/nlsat/algebraic.ts +1161 -0
- package/src/prover/smt/solver/nlsat/atoms.ts +238 -0
- package/src/prover/smt/solver/nlsat/evaluator.ts +303 -0
- package/src/prover/smt/solver/nlsat/explain.ts +607 -0
- package/src/prover/smt/solver/nlsat/interval-set.ts +351 -0
- package/src/prover/smt/solver/nlsat/levelwise.ts +737 -0
- package/src/prover/smt/solver/nlsat/mpbq.ts +161 -0
- package/src/prover/smt/solver/nlsat/polynomial.ts +1722 -0
- package/src/prover/smt/solver/nlsat/solver.ts +911 -0
- package/src/prover/smt/solver/nlsat/types.ts +43 -0
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
- package/src/prover/smt/solver/nlsat/upolynomial.ts +996 -0
- package/src/prover/smt/solver/nnf.ts +469 -0
- package/src/prover/smt/solver/pattern-inference.ts +351 -0
- package/src/prover/smt/solver/poly-rewriter.ts +477 -0
- package/src/prover/smt/solver/propagate-values.ts +83 -0
- package/src/prover/smt/solver/proto-model.ts +551 -0
- package/src/prover/smt/solver/pull-quant.ts +139 -0
- package/src/prover/smt/solver/qe-lite-der.ts +526 -0
- package/src/prover/smt/solver/qe-lite-fm.ts +576 -0
- package/src/prover/smt/solver/qe-lite.ts +381 -0
- package/src/prover/smt/solver/qi-queue.ts +362 -0
- package/src/prover/smt/solver/quant-tactics.ts +117 -0
- package/src/prover/smt/solver/quantifier-analyzer.ts +562 -0
- package/src/prover/smt/solver/quantifier-manager.ts +186 -0
- package/src/prover/smt/solver/random-gen.ts +10 -0
- package/src/prover/smt/solver/rational.ts +165 -0
- package/src/prover/smt/solver/ref-vector.ts +62 -0
- package/src/prover/smt/solver/relevancy.ts +247 -0
- package/src/prover/smt/solver/rewriter-tpl.ts +1159 -0
- package/src/prover/smt/solver/rewriter.ts +843 -0
- package/src/prover/smt/solver/rlimit.ts +79 -0
- package/src/prover/smt/solver/smtlib-parser.ts +526 -0
- package/src/prover/smt/solver/solver.ts +71 -0
- package/src/prover/smt/solver/sort.ts +35 -0
- package/src/prover/smt/solver/sticky-generations.ts +69 -0
- package/src/prover/smt/solver/theory-lra-axioms.ts +340 -0
- package/src/prover/smt/solver/theory-lra-bounds.ts +226 -0
- package/src/prover/smt/solver/theory-lra-final-check.ts +252 -0
- package/src/prover/smt/solver/theory-lra-internalize.ts +476 -0
- package/src/prover/smt/solver/theory-lra-model.ts +243 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +405 -0
- package/src/prover/smt/solver/theory-lra-state.ts +43 -0
- package/src/prover/smt/solver/theory-lra.ts +56 -0
- package/src/prover/smt/solver/var-subst.ts +258 -0
- package/src/prover/smt/solver/z3-license.txt +10 -0
- package/src/prover/smt/table.ts +170 -0
- package/src/prover/tlapm/cache.ts +236 -0
- package/src/prover/tlapm/ocaml-marshal.ts +166 -0
- package/src/prover/tlapm/tlapm.ts +96 -0
- package/src/prover/tlaps-module.ts +510 -0
- package/src/prover/verdict.ts +13 -0
- package/src/prover/zenon/LICENSE +32 -0
- package/src/prover/zenon/check/check.ts +105 -0
- package/src/prover/zenon/check/definitions.ts +144 -0
- package/src/prover/zenon/check/equality.ts +182 -0
- package/src/prover/zenon/check/functions.ts +62 -0
- package/src/prover/zenon/check/keys.ts +125 -0
- package/src/prover/zenon/check/propositional.ts +104 -0
- package/src/prover/zenon/check/records.ts +188 -0
- package/src/prover/zenon/check/relations.ts +121 -0
- package/src/prover/zenon/check/rewrites.ts +224 -0
- package/src/prover/zenon/check/sets.ts +302 -0
- package/src/prover/zenon/check/terms.ts +127 -0
- package/src/prover/zenon/check/tla.ts +126 -0
- package/src/prover/zenon/decide.ts +107 -0
- package/src/prover/zenon/encode.ts +378 -0
- package/src/prover/zenon/eqrel.ts +300 -0
- package/src/prover/zenon/equality-rules.ts +435 -0
- package/src/prover/zenon/expr.ts +551 -0
- package/src/prover/zenon/index-table.ts +350 -0
- package/src/prover/zenon/isar-case.ts +513 -0
- package/src/prover/zenon/isar.ts +1249 -0
- package/src/prover/zenon/limits.ts +15 -0
- package/src/prover/zenon/llproof.ts +173 -0
- package/src/prover/zenon/mltoll.ts +1566 -0
- package/src/prover/zenon/node.ts +297 -0
- package/src/prover/zenon/ocaml.ts +169 -0
- package/src/prover/zenon/parse.ts +247 -0
- package/src/prover/zenon/phrase.ts +191 -0
- package/src/prover/zenon/proof.ts +198 -0
- package/src/prover/zenon/propositional-rules.ts +387 -0
- package/src/prover/zenon/rules.ts +94 -0
- package/src/prover/zenon/search.ts +288 -0
- package/src/prover/zenon/tla/functions.ts +151 -0
- package/src/prover/zenon/tla/llproof.ts +480 -0
- package/src/prover/zenon/tla/records.ts +225 -0
- package/src/prover/zenon/tla/rewrites.ts +447 -0
- package/src/prover/zenon/tla/sets.ts +304 -0
- package/src/prover/zenon/tla/terms.ts +162 -0
- package/src/prover/zenon/tla/tla.ts +506 -0
- package/src/randomization.ts +39 -27
- package/src/resolve.ts +1474 -426
- package/src/runtime.ts +25 -7
- package/src/sany/builtins.ts +147 -0
- package/src/sany/generator.ts +3111 -0
- package/src/sany/levels.ts +1205 -0
- package/src/sany/lexer.ts +544 -0
- package/src/sany/linter.ts +122 -0
- package/src/sany/modules.ts +1398 -0
- package/src/sany/nodes.ts +463 -0
- package/src/sany/parse-error.ts +2161 -0
- package/src/sany/report.ts +355 -0
- package/src/sany/selectors.ts +736 -0
- package/src/sany/source.ts +247 -0
- package/src/sany/xml.ts +1016 -0
- package/src/search.ts +969 -0
- package/src/spec-description.ts +66 -29
- package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
- package/src/standard-modules.ts +215 -164
- package/src/state-graph.ts +181 -0
- package/src/subexpressions.ts +231 -171
- package/src/substitution-levels.ts +40 -19
- package/src/successors.ts +253 -125
- package/src/symmetry.ts +194 -54
- package/src/tableau.ts +60 -32
- package/src/tlc/fingerprint.ts +214 -0
- package/src/{tlc-modules.ts → tlc/jar-data.ts} +4 -0
- package/src/tlc/messages.ts +441 -0
- package/src/{tlc-order.ts → tlc/order.ts} +84 -16
- package/src/{tlc-random.ts → tlc/random.ts} +30 -189
- package/src/tlc/replay.ts +659 -0
- package/src/{tlc-summary.ts → tlc/summary.ts} +20 -5
- package/src/{tlc-module.ts → tlc/tlc-operators.ts} +59 -50
- package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +63 -45
- package/src/tlc/version.ts +19 -0
- package/src/transfer.ts +44 -32
- package/src/values.ts +843 -241
- package/src/worker.ts +62 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
- package/dist/run-cli.cjs +0 -28
- package/dist/run-cli.js +0 -28
- package/src/canonical.ts +0 -39
- package/src/cli-options.ts +0 -58
- package/src/obligation-expression.ts +0 -1060
- package/src/obligation-module.ts +0 -1042
- package/src/run-cli.ts +0 -478
package/src/cli/tlc.ts
ADDED
|
@@ -0,0 +1,941 @@
|
|
|
1
|
+
import {
|
|
2
|
+
existsSync,
|
|
3
|
+
mkdirSync,
|
|
4
|
+
readFileSync,
|
|
5
|
+
readSync,
|
|
6
|
+
realpathSync,
|
|
7
|
+
writeFileSync,
|
|
8
|
+
} from "node:fs";
|
|
9
|
+
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
10
|
+
import { arch, availableParallelism, release, tmpdir, type } from "node:os";
|
|
11
|
+
import { pathToFileURL } from "node:url";
|
|
12
|
+
import { getHeapStatistics } from "node:v8";
|
|
13
|
+
import { version } from "../../package.json";
|
|
14
|
+
import type { Expression } from "../ast";
|
|
15
|
+
import { describeRange } from "../evaluate";
|
|
16
|
+
import type {
|
|
17
|
+
CheckProgress,
|
|
18
|
+
InitialStateViolation,
|
|
19
|
+
OutputLine,
|
|
20
|
+
CheckResult,
|
|
21
|
+
CheckStatus,
|
|
22
|
+
InitialStates,
|
|
23
|
+
SearchStatistics,
|
|
24
|
+
TraceStep,
|
|
25
|
+
Violation,
|
|
26
|
+
} from "../check";
|
|
27
|
+
import { parseConfig } from "../config";
|
|
28
|
+
import {
|
|
29
|
+
getErrorExitCode,
|
|
30
|
+
TlaConfigError,
|
|
31
|
+
TlaError,
|
|
32
|
+
TlaEvaluationError,
|
|
33
|
+
TlaSyntaxError,
|
|
34
|
+
getUnexpectedException,
|
|
35
|
+
UNEXPECTED_EXCEPTION,
|
|
36
|
+
TlaSanyFatalError,
|
|
37
|
+
} from "../errors";
|
|
38
|
+
import { EXIT_STATUS, setExitCode } from "../exit-codes";
|
|
39
|
+
import { check } from "../parallel";
|
|
40
|
+
import { parseModule } from "../parser";
|
|
41
|
+
import type { StateDump } from "../state-graph";
|
|
42
|
+
import {
|
|
43
|
+
formatProbability,
|
|
44
|
+
getActualProbability,
|
|
45
|
+
getOptimisticProbability,
|
|
46
|
+
getOutDegreeSummary,
|
|
47
|
+
} from "../tlc/summary";
|
|
48
|
+
import { SANY_174_STANDARD_MODULES, SANY_STANDARD_MODULES } from "../sany/modules";
|
|
49
|
+
import { getSanyReport, type SanyModuleOrigin } from "../sany/report";
|
|
50
|
+
import { getTlcFingerprint } from "../tlc/fingerprint";
|
|
51
|
+
import type { TlcVersion } from "../tlc/version";
|
|
52
|
+
import {
|
|
53
|
+
createMessagePrinter,
|
|
54
|
+
formatTlcDate,
|
|
55
|
+
formatInnerMessage,
|
|
56
|
+
formatNestedMessage,
|
|
57
|
+
formatTlcDuration,
|
|
58
|
+
MESSAGE_CODE,
|
|
59
|
+
MESSAGE_LEVEL,
|
|
60
|
+
type MessagePrinter,
|
|
61
|
+
} from "../tlc/messages";
|
|
62
|
+
import { formatState } from "../values";
|
|
63
|
+
import { CHECK_COMMAND, USAGE, type ParsedArgs } from "./options";
|
|
64
|
+
import {
|
|
65
|
+
createModuleLoader,
|
|
66
|
+
findModuleFile,
|
|
67
|
+
getInputPaths,
|
|
68
|
+
getToolsJar,
|
|
69
|
+
getStandardModulesUrl,
|
|
70
|
+
printError,
|
|
71
|
+
printMissingFile,
|
|
72
|
+
printMissingFile174,
|
|
73
|
+
reportErrors,
|
|
74
|
+
reportMissingModules174,
|
|
75
|
+
toLibraryPath,
|
|
76
|
+
type JavaProperties,
|
|
77
|
+
} from "./shared";
|
|
78
|
+
|
|
79
|
+
const EXIT_CODES: Record<CheckStatus, number> = {
|
|
80
|
+
success: EXIT_STATUS.success,
|
|
81
|
+
"assumption-violation": EXIT_STATUS.assumptionViolation,
|
|
82
|
+
deadlock: EXIT_STATUS.deadlock,
|
|
83
|
+
"invariant-violation": EXIT_STATUS.safetyViolation,
|
|
84
|
+
"property-violation": EXIT_STATUS.safetyViolation,
|
|
85
|
+
"liveness-violation": EXIT_STATUS.livenessViolation,
|
|
86
|
+
"postcondition-violation": EXIT_STATUS.assumptionViolation,
|
|
87
|
+
error: EXIT_STATUS.error,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const isJavaLong = (text: string) =>
|
|
91
|
+
/^[+-]?\d+$/.test(text) && BigInt.asIntN(64, BigInt(text)) === BigInt(text);
|
|
92
|
+
|
|
93
|
+
const getWorkerCount = (values: string[] | undefined) => {
|
|
94
|
+
if (!values) return 1;
|
|
95
|
+
return values[0] === "auto"
|
|
96
|
+
? availableParallelism()
|
|
97
|
+
: Math.max(1, Number.parseInt(values[0], 10) || 1);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const UNSUPPORTED_DUMP_FORMATS = ["constrained", "stuttering", "strict"];
|
|
101
|
+
|
|
102
|
+
// TLC names the file of a -dump by its format unless the name already ends that way.
|
|
103
|
+
const getDumpPath = (path: string, extension: string) =>
|
|
104
|
+
path.endsWith(extension) ? path : `${path}${extension}`;
|
|
105
|
+
|
|
106
|
+
const getStateDump = (values: string[]): StateDump => {
|
|
107
|
+
if (values.length === 1) return { path: getDumpPath(values[0], ".dump") };
|
|
108
|
+
const format = values[0].toLowerCase();
|
|
109
|
+
return {
|
|
110
|
+
path: getDumpPath(values[1], ".dot"),
|
|
111
|
+
dot: true,
|
|
112
|
+
colorize: format.includes("colorize"),
|
|
113
|
+
actionLabels: format.includes("actionlabels"),
|
|
114
|
+
snapshot: format.includes("snapshot"),
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const printInitialStatesProgress = (printer: MessagePrinter, count: number) =>
|
|
119
|
+
printer.print(
|
|
120
|
+
MESSAGE_CODE.computingInitProgress,
|
|
121
|
+
MESSAGE_LEVEL.none,
|
|
122
|
+
`Computed ${count} initial states...`,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const getInitialViolationHeadline = (
|
|
126
|
+
status: InitialStateViolation["status"],
|
|
127
|
+
name: string | undefined,
|
|
128
|
+
) =>
|
|
129
|
+
status === "invariant-violation"
|
|
130
|
+
? {
|
|
131
|
+
code: MESSAGE_CODE.invariantViolatedInitial,
|
|
132
|
+
text: `Invariant ${name} is violated by the initial state:`,
|
|
133
|
+
}
|
|
134
|
+
: {
|
|
135
|
+
code: MESSAGE_CODE.propertyViolatedInitial,
|
|
136
|
+
text: `Property ${name} is violated by the initial state:`,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// What the spec prints as TLC rebuilds a trace, before it prints the states or after.
|
|
140
|
+
const printTraceOutput = (printer: MessagePrinter, lines: OutputLine[] | undefined) =>
|
|
141
|
+
lines?.forEach((line) => {
|
|
142
|
+
if (typeof line === "string") return console.log(line);
|
|
143
|
+
if (line.kind === "initial-states-progress") {
|
|
144
|
+
return printInitialStatesProgress(printer, line.count);
|
|
145
|
+
}
|
|
146
|
+
const headline = getInitialViolationHeadline(line.status, line.name);
|
|
147
|
+
printer.print(
|
|
148
|
+
headline.code,
|
|
149
|
+
MESSAGE_LEVEL.error,
|
|
150
|
+
`${headline.text}\n${formatState(line.state)}`,
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const printTrace = (
|
|
155
|
+
printer: MessagePrinter,
|
|
156
|
+
trace: TraceStep[],
|
|
157
|
+
heading: { code: number; text: string } = {
|
|
158
|
+
code: MESSAGE_CODE.behaviorUpToThisPoint,
|
|
159
|
+
text: "The behavior up to this point is:",
|
|
160
|
+
},
|
|
161
|
+
isRebuiltAfterHeading = false,
|
|
162
|
+
) => {
|
|
163
|
+
if (trace.length > 0) printer.print(heading.code, MESSAGE_LEVEL.error, heading.text);
|
|
164
|
+
trace.forEach((step, index) => {
|
|
165
|
+
if (index > 0 || isRebuiltAfterHeading) printTraceOutput(printer, step.output);
|
|
166
|
+
printer.print(
|
|
167
|
+
MESSAGE_CODE.statePrint2,
|
|
168
|
+
MESSAGE_LEVEL.state,
|
|
169
|
+
`${index + 1}: <${step.label ?? step.action ?? "Initial predicate"}>\n${formatState(step.state)}`,
|
|
170
|
+
);
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const COUNTER_EXAMPLE = {
|
|
175
|
+
code: MESSAGE_CODE.counterExample,
|
|
176
|
+
text: "The following behavior constitutes a counter-example:\n",
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// TLC 1.7.4 doesn't name the properties, and later versions name none when they can't tell which.
|
|
180
|
+
const getTemporalHeadline = (names: string[], version: TlcVersion) =>
|
|
181
|
+
version === "1.7.4" || names.length === 0
|
|
182
|
+
? "Temporal properties were violated.\n"
|
|
183
|
+
: names.length === 1
|
|
184
|
+
? `Temporal property ${names[0]} was violated.\n`
|
|
185
|
+
: `Temporal properties ${names.slice(0, -1).join(", ")}${names.length > 2 ? "," : ""} and ${names[names.length - 1]} were violated.\n`;
|
|
186
|
+
|
|
187
|
+
// TLC's FingerprintException#getTrace: the range of each source, innermost first, skipping a
|
|
188
|
+
// source the same as the one inside it.
|
|
189
|
+
const formatFingerprintTrace = (sources: Expression[]) =>
|
|
190
|
+
sources
|
|
191
|
+
.filter((source, index) => source !== sources[index - 1])
|
|
192
|
+
.map((source, index) => `${index}) ${describeRange(source)}\n`)
|
|
193
|
+
.toReversed()
|
|
194
|
+
.join("");
|
|
195
|
+
|
|
196
|
+
// TLC's CallStack.toString: the range of each expression, skipping an expression that it evaluates
|
|
197
|
+
// again right inside itself.
|
|
198
|
+
const formatCallStack = (expressions: Expression[]) => {
|
|
199
|
+
if (expressions.length === 0) return " The error call stack is empty.\n";
|
|
200
|
+
const lines: string[] = [];
|
|
201
|
+
expressions.forEach((expression, index) => {
|
|
202
|
+
const range = expression.location.range;
|
|
203
|
+
if (expression === expressions[index - 1] || !range) return;
|
|
204
|
+
lines.push(
|
|
205
|
+
`${lines.length}. Line ${range.start.line}, column ${range.start.column} to line ${range.end.line}, column ${range.end.column} in ${range.module}\n`,
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
return `${lines.join("")}\n`;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const printInitialStates = (printer: MessagePrinter, initialStates: InitialStates) => {
|
|
212
|
+
const generated = initialStates.generated;
|
|
213
|
+
const distinct = initialStates.distinct;
|
|
214
|
+
const date = formatTlcDate(new Date());
|
|
215
|
+
if (generated === distinct) {
|
|
216
|
+
printer.print(
|
|
217
|
+
MESSAGE_CODE.initGenerated1,
|
|
218
|
+
MESSAGE_LEVEL.none,
|
|
219
|
+
`Finished computing initial states: ${distinct} distinct state${distinct === 1 ? "" : "s"} generated at ${date}.`,
|
|
220
|
+
);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
printer.print(
|
|
224
|
+
MESSAGE_CODE.initGenerated2,
|
|
225
|
+
MESSAGE_LEVEL.none,
|
|
226
|
+
`Finished computing initial states: ${generated} state${generated === 1 ? "" : "s"} generated, with ${distinct} of them distinct at ${date}.`,
|
|
227
|
+
);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
interface Timing {
|
|
231
|
+
startTime: number;
|
|
232
|
+
// Whether TLC has printed that SANY finished.
|
|
233
|
+
isParsed: boolean;
|
|
234
|
+
livenessStartTime: number | undefined;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// TLC reports a depth of at least 1, even before it finds a state, and rates a minute only once the
|
|
238
|
+
// search has started.
|
|
239
|
+
const printProgress = (
|
|
240
|
+
printer: MessagePrinter,
|
|
241
|
+
statistics: SearchStatistics,
|
|
242
|
+
startTime?: number,
|
|
243
|
+
) => {
|
|
244
|
+
const minutes = Math.max(Date.now() - (startTime ?? 0), 1) / 60_000;
|
|
245
|
+
const formatCount = (count: number) => count.toLocaleString("en-US");
|
|
246
|
+
const getRate = (count: number, unit: string) =>
|
|
247
|
+
startTime === undefined ? "" : ` (${formatCount(Math.floor(count / minutes))} ${unit}/min)`;
|
|
248
|
+
printer.print(
|
|
249
|
+
MESSAGE_CODE.progress,
|
|
250
|
+
MESSAGE_LEVEL.none,
|
|
251
|
+
`Progress(${Math.max(statistics.depth, 1)}) at ${formatTlcDate(new Date())}: ${formatCount(statistics.generatedStates)} states generated${getRate(statistics.generatedStates, "s")}, ${formatCount(statistics.distinctStates)} distinct states found${getRate(statistics.distinctStates, "ds")}, ${formatCount(statistics.queuedStates)} states left on queue.`,
|
|
252
|
+
);
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const getClassPath = (directory: string, module: string) => join(directory, `${module}.class`);
|
|
256
|
+
|
|
257
|
+
const printCheckProgress = (
|
|
258
|
+
printer: MessagePrinter,
|
|
259
|
+
progress: CheckProgress,
|
|
260
|
+
timing: Timing,
|
|
261
|
+
directory: string,
|
|
262
|
+
) => {
|
|
263
|
+
const print = printer.print;
|
|
264
|
+
switch (progress.kind) {
|
|
265
|
+
case "parsed":
|
|
266
|
+
timing.isParsed = true;
|
|
267
|
+
if (printer.isTool) print(MESSAGE_CODE.sanyFinished, MESSAGE_LEVEL.none, "SANY finished.");
|
|
268
|
+
print(
|
|
269
|
+
MESSAGE_CODE.starting,
|
|
270
|
+
MESSAGE_LEVEL.none,
|
|
271
|
+
`Starting... (${formatTlcDate(new Date())})`,
|
|
272
|
+
);
|
|
273
|
+
return;
|
|
274
|
+
// TLC 1.7.4 warns about neither a constant-level invariant nor a state-level property.
|
|
275
|
+
case "constant-level-invariant":
|
|
276
|
+
if (printer.version === "1.7.4") return;
|
|
277
|
+
print(
|
|
278
|
+
MESSAGE_CODE.constantLevelInvariant,
|
|
279
|
+
MESSAGE_LEVEL.warning,
|
|
280
|
+
`The invariant ${progress.name} is a constant-level formula (i.e., it contains no variables, primes, or temporal operators) and evaluates to TRUE. To assert constant-level formulas in your spec, use ASSUME ConstInv. If you optionally want to give the assumption a name, write ASSUME YourAssumption == ConstInv instead. See https://explain.tlapl.us/assumptions-and-invariants for additional details.`,
|
|
281
|
+
);
|
|
282
|
+
return;
|
|
283
|
+
case "state-level-property":
|
|
284
|
+
if (printer.version === "1.7.4") return;
|
|
285
|
+
print(
|
|
286
|
+
MESSAGE_CODE.stateLevelProperty,
|
|
287
|
+
MESSAGE_LEVEL.warning,
|
|
288
|
+
`The formula ${progress.name} is a state-level formula, but it was used as a PROPERTY (or PROPERTIES), where a temporal formula is typically expected. State-level formulas used as PROPERTY or PROPERTIES are only checked in the initial state. To verify that the formula ${progress.name} holds in all states of every behavior, use INVARIANT ${progress.name} instead. Alternatively, applying the "always" temporal operator ([]) to the state-level formula ${progress.name} changes it into a temporal formula, asserting that ${progress.name} holds in all states of every behavior. See https://explain.tlapl.us/invariants-and-properties for additional details.`,
|
|
289
|
+
);
|
|
290
|
+
return;
|
|
291
|
+
case "liveness-initializing":
|
|
292
|
+
if (progress.isSymmetric) {
|
|
293
|
+
print(
|
|
294
|
+
MESSAGE_CODE.livenessSymmetry,
|
|
295
|
+
MESSAGE_LEVEL.warning,
|
|
296
|
+
"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.",
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
// Only TLC 1.7.4 warns about constraints.
|
|
300
|
+
if (progress.isConstrained && printer.version === "1.7.4") {
|
|
301
|
+
print(
|
|
302
|
+
MESSAGE_CODE.livenessConstraints,
|
|
303
|
+
MESSAGE_LEVEL.warning,
|
|
304
|
+
"Declaring state or action constraints during liveness checking is dangerous: Please read section 14.3.5 on page 247 of Specifying Systems (https://lamport.azurewebsites.net/tla/book.html) and optionally the discussion at https://discuss.tlapl.us/msg00994.html for more details.",
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
return;
|
|
308
|
+
case "liveness-prepared":
|
|
309
|
+
print(
|
|
310
|
+
MESSAGE_CODE.temporalBranches,
|
|
311
|
+
MESSAGE_LEVEL.none,
|
|
312
|
+
`Implied-temporal checking--satisfiability problem has ${progress.branches} branches.`,
|
|
313
|
+
);
|
|
314
|
+
return;
|
|
315
|
+
case "java-override": {
|
|
316
|
+
// Class#getResource, which names the class file TLC loads the override from.
|
|
317
|
+
const location = pathToFileURL(resolve(getClassPath(directory, progress.module))).href;
|
|
318
|
+
print(
|
|
319
|
+
progress.isMatched ? MESSAGE_CODE.javaOverrideLoaded : MESSAGE_CODE.javaOverrideMismatch,
|
|
320
|
+
progress.isMatched ? MESSAGE_LEVEL.none : MESSAGE_LEVEL.warning,
|
|
321
|
+
`${progress.isMatched ? "Loading" : "Failed to match"} ${progress.operator} operator override from ${location.replace("file:///", "file:/")} with signature: <Java Method: ${progress.signature}>.`,
|
|
322
|
+
);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
case "initial-states-started":
|
|
326
|
+
print(MESSAGE_CODE.computingInit, MESSAGE_LEVEL.none, "Computing initial states...");
|
|
327
|
+
return;
|
|
328
|
+
case "initial-states-progress":
|
|
329
|
+
printInitialStatesProgress(printer, progress.count);
|
|
330
|
+
return;
|
|
331
|
+
case "initial-states-computed":
|
|
332
|
+
printInitialStates(printer, progress.initialStates);
|
|
333
|
+
return;
|
|
334
|
+
case "progress":
|
|
335
|
+
printProgress(printer, progress.statistics, timing.startTime);
|
|
336
|
+
return;
|
|
337
|
+
case "liveness-started": {
|
|
338
|
+
timing.livenessStartTime = Date.now();
|
|
339
|
+
// TLC reports how far the search got before it checks the complete state graph.
|
|
340
|
+
if (progress.isComplete) printProgress(printer, progress.statistics);
|
|
341
|
+
const branches = progress.branches > 1 ? `${progress.branches} branches of ` : "";
|
|
342
|
+
// TLC counts the states of the behavior graph of each branch, without its tableau nodes.
|
|
343
|
+
const states = progress.branches * progress.states;
|
|
344
|
+
print(
|
|
345
|
+
MESSAGE_CODE.checkingTemporal,
|
|
346
|
+
MESSAGE_LEVEL.none,
|
|
347
|
+
`Checking ${branches}temporal properties for the ${progress.isComplete ? "complete" : "current"} state space with ${states} total distinct states at (${formatTlcDate(new Date())})`,
|
|
348
|
+
);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
case "liveness-finished":
|
|
352
|
+
printLivenessEnd(printer, timing);
|
|
353
|
+
return;
|
|
354
|
+
case "warning":
|
|
355
|
+
print(progress.code, MESSAGE_LEVEL.warning, progress.text);
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const printLivenessEnd = (printer: MessagePrinter, timing: Timing) => {
|
|
360
|
+
if (timing.livenessStartTime === undefined) return;
|
|
361
|
+
printer.print(
|
|
362
|
+
MESSAGE_CODE.checkingTemporalEnd,
|
|
363
|
+
MESSAGE_LEVEL.none,
|
|
364
|
+
`Finished checking temporal properties in ${formatTlcDuration(Date.now() - timing.livenessStartTime)} at ${formatTlcDate(new Date())}`,
|
|
365
|
+
);
|
|
366
|
+
timing.livenessStartTime = undefined;
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
// Prints a violation, and returns whether TLC goes on to print the statistics of the search.
|
|
370
|
+
const printViolation = (status: CheckStatus, violation: Violation, printer: MessagePrinter) => {
|
|
371
|
+
const print = printer.print;
|
|
372
|
+
const name = violation.name;
|
|
373
|
+
const loopStart = violation.loopStart;
|
|
374
|
+
// TLC prints a violation by an initial state without the behavior or the statistics.
|
|
375
|
+
const isInitial =
|
|
376
|
+
loopStart === undefined &&
|
|
377
|
+
violation.trace.length === 1 &&
|
|
378
|
+
(status === "invariant-violation" || status === "liveness-violation");
|
|
379
|
+
const temporal = {
|
|
380
|
+
code: MESSAGE_CODE.temporalPropertyViolated,
|
|
381
|
+
text: getTemporalHeadline(violation.properties ?? [name], printer.version),
|
|
382
|
+
};
|
|
383
|
+
const headline = {
|
|
384
|
+
success: undefined,
|
|
385
|
+
error: undefined,
|
|
386
|
+
"assumption-violation": violation.message
|
|
387
|
+
? {
|
|
388
|
+
code: MESSAGE_CODE.assumptionEvaluationError,
|
|
389
|
+
text: formatInnerMessage(
|
|
390
|
+
MESSAGE_CODE.assumptionEvaluationError,
|
|
391
|
+
`Evaluating assumption ${name} failed.\n${violation.message}`,
|
|
392
|
+
printer.isTool,
|
|
393
|
+
),
|
|
394
|
+
}
|
|
395
|
+
: { code: MESSAGE_CODE.assumptionFalse, text: `Assumption ${name} is false.` },
|
|
396
|
+
deadlock: { code: MESSAGE_CODE.deadlockReached, text: "Deadlock reached." },
|
|
397
|
+
"invariant-violation": isInitial
|
|
398
|
+
? getInitialViolationHeadline("invariant-violation", name)
|
|
399
|
+
: { code: MESSAGE_CODE.invariantViolatedBehavior, text: `Invariant ${name} is violated.` },
|
|
400
|
+
"property-violation": temporal,
|
|
401
|
+
"liveness-violation":
|
|
402
|
+
loopStart !== undefined
|
|
403
|
+
? temporal
|
|
404
|
+
: isInitial
|
|
405
|
+
? getInitialViolationHeadline("liveness-violation", name)
|
|
406
|
+
: {
|
|
407
|
+
code: MESSAGE_CODE.actionPropertyViolatedBehavior,
|
|
408
|
+
text: `Action property ${name} is violated.`,
|
|
409
|
+
},
|
|
410
|
+
"postcondition-violation": {
|
|
411
|
+
code: violation.postcondition?.code ?? MESSAGE_CODE.general,
|
|
412
|
+
text: violation.message ?? `Postcondition ${name} is false.`,
|
|
413
|
+
},
|
|
414
|
+
}[status];
|
|
415
|
+
// A safety property's counterexample ends where it breaks, and a liveness one loops back.
|
|
416
|
+
const isProperty = status === "property-violation";
|
|
417
|
+
const isLasso = loopStart !== undefined && !isProperty;
|
|
418
|
+
const isCounterExample = isProperty || isLasso;
|
|
419
|
+
// TLC rebuilds a liveness counterexample before it reports the violation, and 1.7.4's
|
|
420
|
+
// LiveWorker#printTrace after it prints the heading of the counterexample.
|
|
421
|
+
const isRebuiltFirst = isCounterExample && printer.version !== "1.7.4";
|
|
422
|
+
if (isRebuiltFirst) printTraceOutput(printer, violation.trace[0]?.output);
|
|
423
|
+
if (violation.counts) console.log(violation.counts);
|
|
424
|
+
if (headline) {
|
|
425
|
+
// TLC prints the initial state that violates a property in the same message.
|
|
426
|
+
const text = isInitial
|
|
427
|
+
? `${headline.text}\n${formatState(violation.trace[0].state)}`
|
|
428
|
+
: headline.text;
|
|
429
|
+
print(headline.code, MESSAGE_LEVEL.error, text);
|
|
430
|
+
}
|
|
431
|
+
if (!isInitial) {
|
|
432
|
+
if (!isCounterExample) printTraceOutput(printer, violation.trace[0]?.output);
|
|
433
|
+
printTrace(
|
|
434
|
+
printer,
|
|
435
|
+
violation.trace,
|
|
436
|
+
isCounterExample ? COUNTER_EXAMPLE : undefined,
|
|
437
|
+
isCounterExample && !isRebuiltFirst,
|
|
438
|
+
);
|
|
439
|
+
printTraceOutput(printer, violation.traceOutput);
|
|
440
|
+
}
|
|
441
|
+
if (isLasso) {
|
|
442
|
+
const label = violation.loopLabel;
|
|
443
|
+
if (loopStart === violation.trace.length - 1)
|
|
444
|
+
print(MESSAGE_CODE.statePrint3, MESSAGE_LEVEL.state, `${loopStart + 2}: Stuttering`);
|
|
445
|
+
else if (printer.isTool)
|
|
446
|
+
print(
|
|
447
|
+
MESSAGE_CODE.backToState,
|
|
448
|
+
MESSAGE_LEVEL.state,
|
|
449
|
+
`${loopStart + 1}: Back to state${label ? `: <${label}>\n` : ""}`,
|
|
450
|
+
);
|
|
451
|
+
else console.log(`Back to state ${loopStart + 1}${label ? `: <${label}>\n` : ""}`);
|
|
452
|
+
}
|
|
453
|
+
// TLC 1.7.4 doesn't explain a stuttering counterexample.
|
|
454
|
+
if (violation.warning && printer.version !== "1.7.4")
|
|
455
|
+
print(violation.warning.code, MESSAGE_LEVEL.warning, violation.warning.text);
|
|
456
|
+
// TLC checks the postconditions after it prints a counterexample.
|
|
457
|
+
const postcondition =
|
|
458
|
+
violation.unwitnessed ??
|
|
459
|
+
(status === "postcondition-violation" ? undefined : violation.postcondition);
|
|
460
|
+
if (postcondition?.counts) console.log(postcondition.counts);
|
|
461
|
+
if (postcondition) print(postcondition.code, MESSAGE_LEVEL.error, postcondition.message);
|
|
462
|
+
// TLC checks assumptions before it starts the search, so it has no statistics to print.
|
|
463
|
+
return !isInitial && status !== "assumption-violation";
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
const printNestedExpressions = (printer: MessagePrinter, callStack: Expression[]) =>
|
|
467
|
+
printer.print(
|
|
468
|
+
MESSAGE_CODE.nestedExpression,
|
|
469
|
+
MESSAGE_LEVEL.error,
|
|
470
|
+
`The error occurred when TLC was evaluating the nested\nexpressions at the following positions:\n${formatCallStack(callStack)}`,
|
|
471
|
+
);
|
|
472
|
+
|
|
473
|
+
const printResult = (result: CheckResult, printer: MessagePrinter, timing: Timing) => {
|
|
474
|
+
const print = printer.print;
|
|
475
|
+
if (result.failure) {
|
|
476
|
+
const failure = result.failure;
|
|
477
|
+
const message = printer.isTool ? failure.toolMessage : failure.message;
|
|
478
|
+
const printCallStack = () => {
|
|
479
|
+
const fingerprint = failure.fingerprint;
|
|
480
|
+
if (fingerprint) {
|
|
481
|
+
// TLC prints the call stack when the replay has one, and otherwise the sources of the
|
|
482
|
+
// values it failed to fingerprint, innermost first. TLC 1.7.4 always prints the sources.
|
|
483
|
+
const trace =
|
|
484
|
+
failure.callStack?.length && printer.version !== "1.7.4"
|
|
485
|
+
? formatCallStack(failure.callStack)
|
|
486
|
+
: formatFingerprintTrace(fingerprint.sources);
|
|
487
|
+
print(
|
|
488
|
+
MESSAGE_CODE.fingerprintFailed,
|
|
489
|
+
MESSAGE_LEVEL.error,
|
|
490
|
+
`TLC was unable to fingerprint.\n\nFingerprint Stack Trace:\n${trace}\nReason:\n${formatNestedMessage(fingerprint.reason, printer.isTool)}`,
|
|
491
|
+
);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
if (failure.callStack) printNestedExpressions(printer, failure.callStack);
|
|
495
|
+
};
|
|
496
|
+
if (failure.isCallStackFirst) printCallStack();
|
|
497
|
+
// TLC prints the state as it reports the error, so a state it can't print fails outside the
|
|
498
|
+
// checker, which TLC reports as an exception it did not expect.
|
|
499
|
+
const initialState =
|
|
500
|
+
failure.initialState &&
|
|
501
|
+
(() => {
|
|
502
|
+
try {
|
|
503
|
+
return `While working on the initial state:\n${formatState(failure.initialState)}`;
|
|
504
|
+
} catch (error) {
|
|
505
|
+
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
506
|
+
throw setExitCode(
|
|
507
|
+
new TlaEvaluationError(`${UNEXPECTED_EXCEPTION}${error.message}`),
|
|
508
|
+
EXIT_STATUS.error,
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
})();
|
|
512
|
+
// TLC prints an error on an initial state and the state as one message.
|
|
513
|
+
print(
|
|
514
|
+
initialState ? MESSAGE_CODE.initialState : failure.code,
|
|
515
|
+
MESSAGE_LEVEL.error,
|
|
516
|
+
initialState ? `${message}\n${initialState}` : message,
|
|
517
|
+
);
|
|
518
|
+
printTraceOutput(printer, failure.trace[0]?.output);
|
|
519
|
+
printTrace(printer, failure.trace);
|
|
520
|
+
const traceFailure = failure.traceFailure;
|
|
521
|
+
if (traceFailure) {
|
|
522
|
+
print(
|
|
523
|
+
traceFailure.code,
|
|
524
|
+
MESSAGE_LEVEL.error,
|
|
525
|
+
printer.isTool ? traceFailure.toolMessage : traceFailure.message,
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
printTraceOutput(printer, failure.traceOutput);
|
|
529
|
+
const postcondition = failure.postcondition;
|
|
530
|
+
if (postcondition?.counts) console.log(postcondition.counts);
|
|
531
|
+
if (postcondition) print(postcondition.code, MESSAGE_LEVEL.error, postcondition.message);
|
|
532
|
+
if (!failure.isCallStackFirst) printCallStack();
|
|
533
|
+
} else if (result.violation) {
|
|
534
|
+
if (!printViolation(result.status, result.violation, printer)) return;
|
|
535
|
+
// TLC adds a deadlocked state to the behavior graph after it reports the deadlock, which can
|
|
536
|
+
// violate a temporal property too.
|
|
537
|
+
const additionalViolation = result.additionalViolation;
|
|
538
|
+
if (additionalViolation) printViolation("property-violation", additionalViolation, printer);
|
|
539
|
+
if (result.liveCallStack) printNestedExpressions(printer, result.liveCallStack);
|
|
540
|
+
} else {
|
|
541
|
+
printLivenessEnd(printer, timing);
|
|
542
|
+
const optimistic = getOptimisticProbability(result.distinctStates, result.generatedStates);
|
|
543
|
+
const actual =
|
|
544
|
+
result.fingerprintDistance === undefined
|
|
545
|
+
? []
|
|
546
|
+
: [
|
|
547
|
+
` based on the actual fingerprints: val = ${formatProbability(getActualProbability(result.fingerprintDistance))}`,
|
|
548
|
+
];
|
|
549
|
+
print(
|
|
550
|
+
MESSAGE_CODE.success,
|
|
551
|
+
MESSAGE_LEVEL.none,
|
|
552
|
+
[
|
|
553
|
+
"Model checking completed. No error has been found.",
|
|
554
|
+
" Estimates of the probability that TLC did not check all reachable states",
|
|
555
|
+
" because two distinct states had the same fingerprint:",
|
|
556
|
+
` calculated (optimistic): val = ${formatProbability(optimistic)}`,
|
|
557
|
+
...actual,
|
|
558
|
+
].join("\n"),
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
if (result.failure?.isWithoutStatistics) return;
|
|
562
|
+
if (result.status !== "success") printLivenessEnd(printer, timing);
|
|
563
|
+
if (printer.isTool) printProgress(printer, result, timing.startTime);
|
|
564
|
+
print(
|
|
565
|
+
MESSAGE_CODE.stats,
|
|
566
|
+
MESSAGE_LEVEL.none,
|
|
567
|
+
`${result.generatedStates} states generated, ${result.distinctStates} distinct states found, ${result.queuedStates} states left on queue.`,
|
|
568
|
+
);
|
|
569
|
+
// ModelChecker#printSummary prints the depth, which TLC 1.7.4 prints only after a search it
|
|
570
|
+
// reports as successful, and as at least 1, and then the outdegree of a successful search.
|
|
571
|
+
const is174 = printer.version === "1.7.4";
|
|
572
|
+
const outDegrees = is174 ? (result.outDegrees ?? result.violationOutDegrees) : result.outDegrees;
|
|
573
|
+
if (!is174 || outDegrees) {
|
|
574
|
+
print(
|
|
575
|
+
MESSAGE_CODE.searchDepth,
|
|
576
|
+
MESSAGE_LEVEL.none,
|
|
577
|
+
`The depth of the complete state graph search is ${is174 ? Math.max(result.depth, 1) : result.depth}.`,
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
const outDegree = outDegrees && getOutDegreeSummary(outDegrees);
|
|
581
|
+
if (outDegree) print(MESSAGE_CODE.stateGraphOutdegree, MESSAGE_LEVEL.none, outDegree);
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
// Java's Files.createTempDirectory names a directory by a random unsigned long. tla-ts derives it
|
|
585
|
+
// from TLC's fingerprint of what the directory holds, so that each run of a spec prints the same
|
|
586
|
+
// files.
|
|
587
|
+
const getTemporaryName = (contents: string) => getTlcFingerprint([contents]).toString();
|
|
588
|
+
|
|
589
|
+
// The file TLC's SANY says it parses each module from: the real path of a module's own file, or a
|
|
590
|
+
// copy in a temporary directory of a module from the root module's file or from the jar on the
|
|
591
|
+
// class path, followed by where TLC copied it from.
|
|
592
|
+
const createFileDescriber = (
|
|
593
|
+
specPath: string,
|
|
594
|
+
directories: string[],
|
|
595
|
+
java: JavaProperties,
|
|
596
|
+
metadir: string | undefined,
|
|
597
|
+
version: TlcVersion,
|
|
598
|
+
) => {
|
|
599
|
+
const temporary = java.temporaryDirectory ?? tmpdir();
|
|
600
|
+
const temporaryDirectory = existsSync(temporary) ? realpathSync(temporary) : resolve(temporary);
|
|
601
|
+
const libraryDirectory = join(temporaryDirectory, `tlc-${getTemporaryName(resolve(specPath))}`);
|
|
602
|
+
const jar = getToolsJar(java);
|
|
603
|
+
return (name: string, origin: SanyModuleOrigin) => {
|
|
604
|
+
const fileName = `${name}.tla`;
|
|
605
|
+
if (origin === "file") return realpathSync(findModuleFile(directories, name) ?? specPath);
|
|
606
|
+
// TLC 1.7.4 copies a standard module into the temporary directory itself.
|
|
607
|
+
if (version === "1.7.4") return join(temporaryDirectory, fileName);
|
|
608
|
+
// FileUtil.createTempFile copies a module from the root module's file into the -metadir.
|
|
609
|
+
if (origin === "root file") {
|
|
610
|
+
const directory = metadir === undefined ? temporaryDirectory : resolve(metadir);
|
|
611
|
+
const root = realpathSync(specPath);
|
|
612
|
+
return `${join(directory, getTemporaryName(`${root} ${name}`), fileName)} (${root})`;
|
|
613
|
+
}
|
|
614
|
+
const copy = join(libraryDirectory, fileName);
|
|
615
|
+
return jar === undefined ? copy : `${copy} (${getStandardModulesUrl(jar)}${fileName})`;
|
|
616
|
+
};
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
const printWelcome = (printer: MessagePrinter) =>
|
|
620
|
+
printer.print(MESSAGE_CODE.version, MESSAGE_LEVEL.none, `TLC2 Version ${version} (rev: tla-ts)`);
|
|
621
|
+
|
|
622
|
+
// TLC.printErrorMsg: TLC says which version it is, then why it can't read its options.
|
|
623
|
+
const printCommandLineError = (printer: MessagePrinter, message: string) => {
|
|
624
|
+
printWelcome(printer);
|
|
625
|
+
printer.print(
|
|
626
|
+
MESSAGE_CODE.commandLineError,
|
|
627
|
+
MESSAGE_LEVEL.error,
|
|
628
|
+
`${message}\nUsage: java tlc2.TLC [-help] [-option] inputfile`,
|
|
629
|
+
);
|
|
630
|
+
return 1;
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
// TLC.printStartupBanner, with what runs tla-ts in place of the JVM. tla-ts keeps its fingerprints
|
|
634
|
+
// and its queue of states in memory.
|
|
635
|
+
const printStartupBanner = (printer: MessagePrinter, seed: string, workers: number) =>
|
|
636
|
+
printer.print(
|
|
637
|
+
MESSAGE_CODE.modelChecking,
|
|
638
|
+
MESSAGE_LEVEL.none,
|
|
639
|
+
`Running breadth-first search Model-Checking with fp 0 and seed ${BigInt(seed)} with ${workers} worker${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, MemFPSet, MemStateQueue).`,
|
|
640
|
+
);
|
|
641
|
+
|
|
642
|
+
// TLC loads Integers for the binary trace that its trace exploration spec records. -generateSpecTE
|
|
643
|
+
// turns the spec on, and -tool, -continue, -noGenerateSpecTE and -noTE turn it off, as
|
|
644
|
+
// -noGenerateSpecTEBin and -noTEBin turn off the binary trace. TLC 1.7.4 records no such trace.
|
|
645
|
+
const isTraceRecorded = (args: ParsedArgs, version: TlcVersion) => {
|
|
646
|
+
const flags = [...args.unknown, ...args.options.map((option) => option.name)];
|
|
647
|
+
const hasFlag = (name: string, alias = name) =>
|
|
648
|
+
flags.some((flag) => flag === name || flag.toLowerCase() === alias.toLowerCase());
|
|
649
|
+
const isSpecGenerated =
|
|
650
|
+
hasFlag("-generateSpecTE") ||
|
|
651
|
+
(!hasFlag("-noGenerateSpecTE", "-noTE") && !hasFlag("-tool") && !hasFlag("-continue"));
|
|
652
|
+
return version !== "1.7.4" && isSpecGenerated && !hasFlag("-noGenerateSpecTEBin", "-noTEBin");
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
const checkSpec = async (
|
|
656
|
+
specPath: string,
|
|
657
|
+
args: ParsedArgs,
|
|
658
|
+
java: JavaProperties,
|
|
659
|
+
printer: MessagePrinter,
|
|
660
|
+
) => {
|
|
661
|
+
// TLC.handleParameters: TLC reads its options before it says which version it is.
|
|
662
|
+
const seed = args.has("-seed") ? args.get("-seed")?.[0] : "0";
|
|
663
|
+
if (seed === undefined) return printCommandLineError(printer, "Error: seed required.");
|
|
664
|
+
if (!isJavaLong(seed)) {
|
|
665
|
+
return printCommandLineError(
|
|
666
|
+
printer,
|
|
667
|
+
`Error: An integer for seed required. But encountered ${seed}`,
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
const livenessCheck = args.has("-lncheck") ? args.get("-lncheck")?.[0]?.toLowerCase() : "default";
|
|
671
|
+
if (livenessCheck === undefined) {
|
|
672
|
+
return printCommandLineError(
|
|
673
|
+
printer,
|
|
674
|
+
"Error: expect a strategy such as final for -lncheck option.",
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
const dumpValues = args.get("-dump");
|
|
678
|
+
if (dumpValues?.length === 0) {
|
|
679
|
+
return printCommandLineError(printer, "Error: A file name for dumping states required.");
|
|
680
|
+
}
|
|
681
|
+
const unsupportedFormat =
|
|
682
|
+
dumpValues?.length === 2 &&
|
|
683
|
+
UNSUPPORTED_DUMP_FORMATS.find((format) => dumpValues[0].toLowerCase().includes(format));
|
|
684
|
+
if (unsupportedFormat) {
|
|
685
|
+
console.error(`Error: tla-ts does not support the -dump format ${unsupportedFormat}.`);
|
|
686
|
+
return 1;
|
|
687
|
+
}
|
|
688
|
+
const fingerprintIndex = args.get("-fp")?.[0];
|
|
689
|
+
if (fingerprintIndex !== undefined && Number(fingerprintIndex) !== 0) {
|
|
690
|
+
console.error(
|
|
691
|
+
`Error: tla-ts fingerprints states as TLC does with -fp 0, not -fp ${fingerprintIndex}.`,
|
|
692
|
+
);
|
|
693
|
+
return 1;
|
|
694
|
+
}
|
|
695
|
+
const workers = getWorkerCount(args.get("-workers"));
|
|
696
|
+
const version = printer.version;
|
|
697
|
+
printWelcome(printer);
|
|
698
|
+
printStartupBanner(printer, seed, workers);
|
|
699
|
+
const configPath =
|
|
700
|
+
args.get("-config")?.[0] ??
|
|
701
|
+
(args.has("-config") ? undefined : specPath.replace(/\.tla$/, ".cfg"));
|
|
702
|
+
if (!configPath || !existsSync(configPath)) {
|
|
703
|
+
printer.print(
|
|
704
|
+
MESSAGE_CODE.configFileError,
|
|
705
|
+
MESSAGE_LEVEL.error,
|
|
706
|
+
`TLC encountered the following error when trying to read the configuration file ${configPath ?? ""}:\nFile not found.`,
|
|
707
|
+
);
|
|
708
|
+
return EXIT_STATUS.configParseError;
|
|
709
|
+
}
|
|
710
|
+
const fileName = basename(specPath, ".tla");
|
|
711
|
+
const timing: Timing = { startTime: Date.now(), livenessStartTime: undefined, isParsed: false };
|
|
712
|
+
// Without -tool, TLC prints how long it ran for a person to read.
|
|
713
|
+
const printFinished = () => {
|
|
714
|
+
const runtime = Date.now() - timing.startTime;
|
|
715
|
+
printer.print(
|
|
716
|
+
MESSAGE_CODE.finished,
|
|
717
|
+
MESSAGE_LEVEL.none,
|
|
718
|
+
`Finished in ${printer.isTool ? `${runtime}ms` : formatTlcDuration(runtime)} at (${formatTlcDate(new Date())})`,
|
|
719
|
+
);
|
|
720
|
+
};
|
|
721
|
+
const printParsingFailed = () =>
|
|
722
|
+
printer.print(
|
|
723
|
+
MESSAGE_CODE.parsingFailed,
|
|
724
|
+
MESSAGE_LEVEL.error,
|
|
725
|
+
"Parsing or semantic analysis failed.",
|
|
726
|
+
);
|
|
727
|
+
// TLC prints how long it ran even when it stops at an error.
|
|
728
|
+
const printFailure = (error: TlaError) => {
|
|
729
|
+
if (error instanceof TlaSyntaxError) {
|
|
730
|
+
printParsingFailed();
|
|
731
|
+
} else {
|
|
732
|
+
printError(error, printer);
|
|
733
|
+
}
|
|
734
|
+
printFinished();
|
|
735
|
+
return getErrorExitCode(error);
|
|
736
|
+
};
|
|
737
|
+
// TLC reads the configuration file before it parses the spec, and prints how long it ran even
|
|
738
|
+
// when it can't read it.
|
|
739
|
+
const config = (() => {
|
|
740
|
+
try {
|
|
741
|
+
return parseConfig(readFileSync(configPath, "utf8"), version);
|
|
742
|
+
} catch (error) {
|
|
743
|
+
if (!(error instanceof TlaConfigError)) throw error;
|
|
744
|
+
return error;
|
|
745
|
+
}
|
|
746
|
+
})();
|
|
747
|
+
// TLC 1.7.4 reports a configuration file it can't parse as an exception it didn't expect.
|
|
748
|
+
if (config instanceof TlaConfigError && version === "1.7.4") {
|
|
749
|
+
printer.print(
|
|
750
|
+
MESSAGE_CODE.general,
|
|
751
|
+
MESSAGE_LEVEL.error,
|
|
752
|
+
`${getUnexpectedException("tlc2.tool.ConfigFileException")}${formatNestedMessage(config.message, printer.isTool)}`,
|
|
753
|
+
);
|
|
754
|
+
printFinished();
|
|
755
|
+
return EXIT_STATUS.error;
|
|
756
|
+
}
|
|
757
|
+
if (config instanceof TlaConfigError) return printFailure(config);
|
|
758
|
+
if (args.has("-deadlock")) config.checkDeadlock = false;
|
|
759
|
+
const directory = dirname(specPath);
|
|
760
|
+
const directories = [directory, ...java.libraries];
|
|
761
|
+
const loadModule = createModuleLoader(directories);
|
|
762
|
+
const isRecorded = isTraceRecorded(args, version);
|
|
763
|
+
if (printer.isTool) {
|
|
764
|
+
printer.print(MESSAGE_CODE.startingSany, MESSAGE_LEVEL.none, "Starting SANY...");
|
|
765
|
+
}
|
|
766
|
+
// TLC.handleParameters: SANY names the spec as TLC's arguments do, except that TLC runs from the
|
|
767
|
+
// directory of a spec given by an absolute path, and names it by its file name. SANY looks for
|
|
768
|
+
// the spec's modules in the spec's directory and the TLA-Library directories.
|
|
769
|
+
const isAbsoluteSpec = isAbsolute(specPath);
|
|
770
|
+
const specName = isAbsoluteSpec ? fileName : specPath.replace(/\.tla$/, "");
|
|
771
|
+
const jar = getToolsJar(java);
|
|
772
|
+
const reportMissingFile =
|
|
773
|
+
version === "1.7.4" ? createMissingFilePrinter174(specPath, java, jar) : undefined;
|
|
774
|
+
if (reportMissingFile) {
|
|
775
|
+
if (!existsSync(specPath) && !SANY_174_STANDARD_MODULES.has(fileName)) {
|
|
776
|
+
reportMissingFile(`${fileName}.tla`);
|
|
777
|
+
}
|
|
778
|
+
} else if (!existsSync(specPath) && !SANY_STANDARD_MODULES.has(fileName)) {
|
|
779
|
+
printMissingFile(
|
|
780
|
+
isAbsoluteSpec ? directory : process.cwd(),
|
|
781
|
+
isAbsoluteSpec ? `${fileName}.tla` : `./${specName}.tla`,
|
|
782
|
+
[...(isAbsoluteSpec || directory === "." ? [] : [directory]), ...java.libraries],
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
// TLC prints what SANY prints as it parses the spec, and the errors it rejects the spec for.
|
|
786
|
+
const sany = getSanyReport(
|
|
787
|
+
specPath,
|
|
788
|
+
reportMissingFile ? reportMissingModules174(loadModule, reportMissingFile) : loadModule,
|
|
789
|
+
{
|
|
790
|
+
fileName: specName,
|
|
791
|
+
describeFile: createFileDescriber(
|
|
792
|
+
specPath,
|
|
793
|
+
directories,
|
|
794
|
+
java,
|
|
795
|
+
args.get("-metadir")?.[0],
|
|
796
|
+
version,
|
|
797
|
+
),
|
|
798
|
+
version,
|
|
799
|
+
// TLC's trace exploration spec records the trace with the post condition of _TLCTrace.
|
|
800
|
+
rootExtendees: isRecorded ? ["_TLCTrace"] : undefined,
|
|
801
|
+
onPrint: (text) => process.stdout.write(text),
|
|
802
|
+
onPrintError: (text) => process.stderr.write(text),
|
|
803
|
+
},
|
|
804
|
+
);
|
|
805
|
+
if (sany.isFailed) {
|
|
806
|
+
printCheckProgress(printer, { kind: "parsed" }, timing, directory);
|
|
807
|
+
printParsingFailed();
|
|
808
|
+
printFinished();
|
|
809
|
+
return EXIT_STATUS.specParseError;
|
|
810
|
+
}
|
|
811
|
+
try {
|
|
812
|
+
const source = readFileSync(specPath, "utf8");
|
|
813
|
+
const moduleName = parseModule(source).name;
|
|
814
|
+
if (moduleName !== fileName) {
|
|
815
|
+
throw new TlaSanyFatalError(
|
|
816
|
+
`File name '${fileName}' does not match the name '${moduleName}' of the top level module it contains.`,
|
|
817
|
+
undefined,
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
const result = await check({
|
|
821
|
+
workers,
|
|
822
|
+
livenessCheck: ["final", "seqfinal", "off"].includes(livenessCheck) ? "final" : "default",
|
|
823
|
+
seed: BigInt(seed),
|
|
824
|
+
dump: dumpValues && getStateDump(dumpValues),
|
|
825
|
+
isTool: printer.isTool,
|
|
826
|
+
isTraceRecorded: isRecorded,
|
|
827
|
+
isSanyReported: true,
|
|
828
|
+
isWarningEnabled: !args.has("-nowarning"),
|
|
829
|
+
version,
|
|
830
|
+
onProgress: (progress) => printCheckProgress(printer, progress, timing, directory),
|
|
831
|
+
source,
|
|
832
|
+
config,
|
|
833
|
+
onPause: () => readSync(0, Buffer.alloc(1)),
|
|
834
|
+
loadModule,
|
|
835
|
+
loadClass: (name) => {
|
|
836
|
+
const classPath = getClassPath(directory, name);
|
|
837
|
+
return existsSync(classPath) ? readFileSync(classPath) : undefined;
|
|
838
|
+
},
|
|
839
|
+
readFile: (path) => (existsSync(path) ? readFileSync(path, "utf8") : undefined),
|
|
840
|
+
writeFile: (path, content) => {
|
|
841
|
+
mkdirSync(dirname(resolve(path)), { recursive: true });
|
|
842
|
+
writeFileSync(path, content);
|
|
843
|
+
},
|
|
844
|
+
});
|
|
845
|
+
printResult(result, printer, timing);
|
|
846
|
+
printFinished();
|
|
847
|
+
return result.failure?.exitCode ?? EXIT_CODES[result.status];
|
|
848
|
+
} catch (error) {
|
|
849
|
+
if (!(error instanceof TlaError)) throw error;
|
|
850
|
+
if (error instanceof TlaSyntaxError) console.log(formatSanyErrors(error, fileName));
|
|
851
|
+
if (!timing.isParsed) printCheckProgress(printer, { kind: "parsed" }, timing, directory);
|
|
852
|
+
return printFailure(error);
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
// What SANY prints about a spec it rejects: a module it can't find or parse is a fatal error, and
|
|
857
|
+
// it reports the other errors as semantic errors.
|
|
858
|
+
const formatSanyErrors = (error: TlaSyntaxError, specName: string) => {
|
|
859
|
+
const isFatal = error instanceof TlaSanyFatalError;
|
|
860
|
+
if (!isFatal && !error.failure)
|
|
861
|
+
return `Semantic errors:\n\n*** Errors: 1\n\n${error.message}\n\n`;
|
|
862
|
+
const report = !isFatal
|
|
863
|
+
? `In module ${specName}\n\nCould not parse module ${specName} from file ${specName}.tla`
|
|
864
|
+
: error.location === undefined
|
|
865
|
+
? `Unknown location\n\n${error.message}`
|
|
866
|
+
: `In module ${error.location}\n\n${error.message}`;
|
|
867
|
+
const parseError = error.failure ? `***Parse Error***\n${error.message}\n\n` : "";
|
|
868
|
+
return `${parseError}\nFatal errors while parsing TLA+ spec in file ${specName}\n\n${report}\n*** Errors: 1\n\n${report}\n\n\n`;
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
export const checkSpecs = async (args: string[], java: JavaProperties) => {
|
|
872
|
+
const parsed = CHECK_COMMAND.parse(args);
|
|
873
|
+
const inputs = getInputPaths(parsed.positionals);
|
|
874
|
+
const isConfigured = parsed.has("-config");
|
|
875
|
+
// Like TLC, a spec named without an extension is the .tla file of that name. A glob also matches
|
|
876
|
+
// modules that only other specs import, which have no configuration.
|
|
877
|
+
const specPaths = inputs
|
|
878
|
+
.map((input) => ({
|
|
879
|
+
...input,
|
|
880
|
+
path:
|
|
881
|
+
input.isGlobbed || /\.(tla|cfg)$/.test(input.path)
|
|
882
|
+
? input.path.replace(/\.cfg$/, ".tla")
|
|
883
|
+
: `${input.path}.tla`,
|
|
884
|
+
}))
|
|
885
|
+
.filter(
|
|
886
|
+
(input) =>
|
|
887
|
+
input.path.endsWith(".tla") &&
|
|
888
|
+
(!input.isGlobbed || isConfigured || existsSync(input.path.replace(/\.tla$/, ".cfg"))),
|
|
889
|
+
)
|
|
890
|
+
.map((input) => input.path);
|
|
891
|
+
if (specPaths.length === 0) {
|
|
892
|
+
console.error(USAGE);
|
|
893
|
+
return 1;
|
|
894
|
+
}
|
|
895
|
+
if (isConfigured && specPaths.length > 1) {
|
|
896
|
+
console.error("Error: -config applies to one specification, but several were given.");
|
|
897
|
+
return 1;
|
|
898
|
+
}
|
|
899
|
+
// TLC also looks for the spec itself in the library directories.
|
|
900
|
+
const findSpec = (path: string) =>
|
|
901
|
+
existsSync(path) || isAbsolute(path)
|
|
902
|
+
? path
|
|
903
|
+
: (java.libraries.map((directory) => join(directory, path)).find(existsSync) ?? path);
|
|
904
|
+
const paths = [...new Set(specPaths.map(findSpec))];
|
|
905
|
+
// Each spec is checked as TLC would in a process of its own, so an error in one leaves the others
|
|
906
|
+
// to report. The exit code is the first that is not success.
|
|
907
|
+
const exitCodes: number[] = [];
|
|
908
|
+
for (const [index, path] of paths.entries()) {
|
|
909
|
+
if (index > 0) console.log("");
|
|
910
|
+
// TLC checks one spec, so tla-ts names each of several it checks.
|
|
911
|
+
if (paths.length > 1)
|
|
912
|
+
console.log(`Checking ${basename(path)} with ${basename(path, ".tla")}.cfg`);
|
|
913
|
+
const printer = createMessagePrinter(
|
|
914
|
+
parsed.has("-tool"),
|
|
915
|
+
!parsed.has("-nowarning"),
|
|
916
|
+
java.tlcVersion ?? "master",
|
|
917
|
+
);
|
|
918
|
+
exitCodes.push(await reportErrors(() => checkSpec(path, parsed, java, printer), printer));
|
|
919
|
+
}
|
|
920
|
+
return exitCodes.find((exitCode) => exitCode !== EXIT_STATUS.success) ?? EXIT_STATUS.success;
|
|
921
|
+
};
|
|
922
|
+
|
|
923
|
+
// TLC 1.7.4's SimpleFilenameToStream looks for a module in the directory of a spec that TLC is
|
|
924
|
+
// given by an absolute path, then in the directory that a relative path names, or else in the
|
|
925
|
+
// TLA-Library directories.
|
|
926
|
+
const createMissingFilePrinter174 = (
|
|
927
|
+
specPath: string,
|
|
928
|
+
java: JavaProperties,
|
|
929
|
+
jar: string | undefined,
|
|
930
|
+
) => {
|
|
931
|
+
const specDirectory = specPath.slice(0, specPath.lastIndexOf("/") + 1);
|
|
932
|
+
const isRelativeToDirectory = !isAbsolute(specPath) && specDirectory !== "";
|
|
933
|
+
const libraries = (isRelativeToDirectory ? [specDirectory] : java.libraries).map(toLibraryPath);
|
|
934
|
+
const lastDirectory =
|
|
935
|
+
libraries.length > 0
|
|
936
|
+
? libraries[libraries.length - 1]
|
|
937
|
+
: isAbsolute(specPath)
|
|
938
|
+
? specDirectory
|
|
939
|
+
: "";
|
|
940
|
+
return (fileName: string) => printMissingFile174(`${lastDirectory}${fileName}`, libraries, jar);
|
|
941
|
+
};
|