tla-ts 0.0.3 → 0.0.4-dev.2a873ee
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 +996 -0
- package/dist/prove.js +996 -0
- package/dist/run-cli.cjs +37 -20
- package/dist/run-cli.js +37 -20
- package/dist/tlapm.cjs +10 -0
- package/dist/tlapm.js +10 -0
- package/dist/transfer.cjs +1387 -18
- package/dist/transfer.js +1387 -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 +4 -7
- package/src/builtins.ts +29 -11
- package/src/bundled-modules.ts +3 -3
- package/src/canonical.ts +4 -3
- package/src/check.ts +1540 -235
- package/src/cli-options.ts +12 -6
- package/src/cli.ts +8 -1
- package/src/codegen.ts +98 -39
- package/src/config.ts +254 -181
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +540 -140
- package/src/errors.ts +284 -4
- package/src/evaluate.ts +1043 -293
- package/src/exit-codes.ts +22 -43
- package/src/fingerprints.ts +46 -11
- package/src/index.ts +11 -0
- package/src/instances.ts +19 -16
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +191 -45
- package/src/lexer.ts +127 -30
- package/src/live-check.ts +867 -0
- package/src/liveness.ts +218 -572
- package/src/{obligation-action.ts → obligations/action.ts} +247 -69
- package/src/{obligation-anon.ts → obligations/anon.ts} +49 -47
- package/src/obligations/ctx.ts +64 -0
- package/src/{obligation-deref.ts → obligations/deref.ts} +51 -92
- package/src/{obligation-expression.ts → obligations/expression.ts} +117 -57
- package/src/{obligation-format.ts → obligations/format.ts} +7 -8
- package/src/{obligation-generate.ts → obligations/generate.ts} +170 -192
- package/src/{obligations.ts → obligations/index.ts} +32 -16
- package/src/{obligation-levels.ts → obligations/levels.ts} +26 -28
- package/src/{obligation-module.ts → obligations/module.ts} +113 -121
- package/src/obligations/pickle.ts +98 -0
- package/src/obligations/pragma.ts +189 -0
- package/src/{obligation-printer.ts → obligations/printer.ts} +22 -80
- package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
- package/src/{obligation-source.ts → obligations/source.ts} +156 -99
- package/src/obligations/temporal.ts +321 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
- package/src/ocaml-marshal.ts +166 -0
- package/src/parallel-worker.ts +169 -224
- package/src/parallel.ts +140 -81
- package/src/parser.ts +456 -147
- package/src/pcal-ast.ts +770 -0
- package/src/pcal-parse.ts +1523 -0
- package/src/pcal-tokenize.ts +516 -0
- package/src/pcal-translate.ts +1230 -0
- package/src/pcal-validate.ts +454 -0
- package/src/prove/decide-pool.ts +95 -0
- package/src/prove/deciders.ts +33 -0
- package/src/prove/first-order.ts +78 -0
- package/src/prove/isabelle/LICENSE +36 -0
- package/src/prove/isabelle/LICENSE-tlapm +26 -0
- package/src/prove/isabelle/decide.ts +47 -0
- package/src/prove/isabelle/encode.ts +446 -0
- package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
- package/src/prove/isabelle/isar/method.ts +367 -0
- package/src/prove/isabelle/isar/proof.ts +28 -0
- package/src/prove/isabelle/isar/statement.ts +57 -0
- package/src/prove/isabelle/isar/theory.ts +192 -0
- package/src/prove/isabelle/isar/type-check.ts +278 -0
- package/src/prove/isabelle/provers/blast/blast.ts +258 -0
- package/src/prove/isabelle/provers/blast/branch.ts +322 -0
- package/src/prove/isabelle/provers/blast/prove.ts +347 -0
- package/src/prove/isabelle/provers/blast/rules.ts +330 -0
- package/src/prove/isabelle/provers/blast/state.ts +180 -0
- package/src/prove/isabelle/provers/blast/term.ts +546 -0
- package/src/prove/isabelle/provers/clasimp.ts +150 -0
- package/src/prove/isabelle/provers/classical.ts +389 -0
- package/src/prove/isabelle/provers/hypsubst.ts +433 -0
- package/src/prove/isabelle/pure/bicompose.ts +174 -0
- package/src/prove/isabelle/pure/consts.ts +32 -0
- package/src/prove/isabelle/pure/conv.ts +79 -0
- package/src/prove/isabelle/pure/drule.ts +264 -0
- package/src/prove/isabelle/pure/envir.ts +331 -0
- package/src/prove/isabelle/pure/goal.ts +53 -0
- package/src/prove/isabelle/pure/interrupt.ts +16 -0
- package/src/prove/isabelle/pure/list.ts +12 -0
- package/src/prove/isabelle/pure/logic.ts +330 -0
- package/src/prove/isabelle/pure/name.ts +98 -0
- package/src/prove/isabelle/pure/net.ts +215 -0
- package/src/prove/isabelle/pure/object-logic.ts +41 -0
- package/src/prove/isabelle/pure/pattern.ts +631 -0
- package/src/prove/isabelle/pure/raw-simplifier.ts +338 -0
- package/src/prove/isabelle/pure/rewriter.ts +602 -0
- package/src/prove/isabelle/pure/search.ts +68 -0
- package/src/prove/isabelle/pure/seq.ts +133 -0
- package/src/prove/isabelle/pure/simplifier.ts +106 -0
- package/src/prove/isabelle/pure/table.ts +201 -0
- package/src/prove/isabelle/pure/tactic.ts +168 -0
- package/src/prove/isabelle/pure/tactical.ts +264 -0
- package/src/prove/isabelle/pure/term-ord.ts +105 -0
- package/src/prove/isabelle/pure/term.ts +688 -0
- package/src/prove/isabelle/pure/thm.ts +783 -0
- package/src/prove/isabelle/pure/type.ts +121 -0
- package/src/prove/isabelle/pure/unify.ts +753 -0
- package/src/prove/isabelle/pure/variable.ts +25 -0
- package/src/prove/isabelle/tla/classical-setup.ts +101 -0
- package/src/prove/isabelle/tla/context.ts +74 -0
- package/src/prove/isabelle/tla/logic-data.ts +5 -0
- package/src/prove/isabelle/tla/logic.ts +215 -0
- package/src/prove/isabelle/tla/simpdata.ts +241 -0
- package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
- package/src/prove/ocaml.ts +22 -0
- package/src/prove/prep/action.ts +508 -0
- package/src/prove/prep/defs.ts +33 -0
- package/src/prove/prep/elab.ts +156 -0
- package/src/prove/prep/enabled-axioms.ts +189 -0
- package/src/prove/prep/enabled.ts +43 -0
- package/src/prove/prep/fingerprint.ts +388 -0
- package/src/prove/prep/flatten.ts +70 -0
- package/src/prove/prep/level-comparison.ts +529 -0
- package/src/prove/prep/md5.ts +67 -0
- package/src/prove/prep/pragma.ts +221 -0
- package/src/prove/prep/trivial.ts +22 -0
- package/src/prove/prove-worker.ts +22 -0
- package/src/prove/prove.ts +498 -0
- package/src/prove/ptl/decide.ts +68 -0
- package/src/prove/ptl/encode.ts +255 -0
- package/src/prove/ptl/sat.ts +151 -0
- package/src/prove/ptl/tableau.ts +276 -0
- package/src/prove/smt/axiomatize.ts +69 -0
- package/src/prove/smt/axioms.ts +209 -0
- package/src/prove/smt/context.ts +108 -0
- package/src/prove/smt/data.ts +636 -0
- package/src/prove/smt/encode.ts +164 -0
- package/src/prove/smt/extensionality.ts +65 -0
- package/src/prove/smt/flatten.ts +112 -0
- package/src/prove/smt/format.ts +154 -0
- package/src/prove/smt/instances.ts +181 -0
- package/src/prove/smt/rewrite.ts +772 -0
- package/src/prove/smt/simplify.ts +57 -0
- package/src/prove/smt/solver/act-cache.ts +265 -0
- package/src/prove/smt/solver/arith-rewriter.ts +962 -0
- package/src/prove/smt/solver/array.ts +22 -0
- package/src/prove/smt/solver/asserted-formulas.ts +469 -0
- package/src/prove/smt/solver/ast-lt.ts +157 -0
- package/src/prove/smt/solver/ast-util.ts +91 -0
- package/src/prove/smt/solver/ast.ts +1315 -0
- package/src/prove/smt/solver/auf-solver.ts +572 -0
- package/src/prove/smt/solver/case-split-queue.ts +178 -0
- package/src/prove/smt/solver/cg-table.ts +175 -0
- package/src/prove/smt/solver/clause.ts +276 -0
- package/src/prove/smt/solver/conflict-resolution.ts +343 -0
- package/src/prove/smt/solver/context.ts +1292 -0
- package/src/prove/smt/solver/ctx-simplify.ts +334 -0
- package/src/prove/smt/solver/der.ts +224 -0
- package/src/prove/smt/solver/dyn-ack.ts +141 -0
- package/src/prove/smt/solver/e-matching.ts +659 -0
- package/src/prove/smt/solver/enode.ts +259 -0
- package/src/prove/smt/solver/expr-ref.ts +21 -0
- package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
- package/src/prove/smt/solver/fingerprints.ts +92 -0
- package/src/prove/smt/solver/flat-literals.ts +51 -0
- package/src/prove/smt/solver/goal.ts +138 -0
- package/src/prove/smt/solver/hash.ts +173 -0
- package/src/prove/smt/solver/hashtable.ts +166 -0
- package/src/prove/smt/solver/internalizer.ts +1381 -0
- package/src/prove/smt/solver/lbool.ts +5 -0
- package/src/prove/smt/solver/literal.ts +24 -0
- package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
- package/src/prove/smt/solver/lp/constraints.ts +78 -0
- package/src/prove/smt/solver/lp/containers.ts +296 -0
- package/src/prove/smt/solver/lp/core-solver.ts +504 -0
- package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
- package/src/prove/smt/solver/lp/dep-intervals.ts +642 -0
- package/src/prove/smt/solver/lp/dependency.ts +51 -0
- package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
- package/src/prove/smt/solver/lp/explanation.ts +46 -0
- package/src/prove/smt/solver/lp/gomory.ts +255 -0
- package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
- package/src/prove/smt/solver/lp/hnf.ts +281 -0
- package/src/prove/smt/solver/lp/int-cube.ts +295 -0
- package/src/prove/smt/solver/lp/int-solver.ts +514 -0
- package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
- package/src/prove/smt/solver/lp/lar-term.ts +62 -0
- package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
- package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
- package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
- package/src/prove/smt/solver/lp/nex.ts +120 -0
- package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
- package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
- package/src/prove/smt/solver/lp/nla-core.ts +968 -0
- package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
- package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
- package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
- package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
- package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
- package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
- package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
- package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
- package/src/prove/smt/solver/lp/nla-order.ts +307 -0
- package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
- package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
- package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
- package/src/prove/smt/solver/lp/nla-types.ts +124 -0
- package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
- package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
- package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
- package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
- package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
- package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
- package/src/prove/smt/solver/lp/pdd.ts +971 -0
- package/src/prove/smt/solver/lp/random-updater.ts +138 -0
- package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
- package/src/prove/smt/solver/lp/union-find.ts +96 -0
- package/src/prove/smt/solver/mam-compiler.ts +847 -0
- package/src/prove/smt/solver/mam-interpreter.ts +400 -0
- package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
- package/src/prove/smt/solver/model-checker.ts +347 -0
- package/src/prove/smt/solver/model-evaluator.ts +262 -0
- package/src/prove/smt/solver/model-finder.ts +155 -0
- package/src/prove/smt/solver/model-generator.ts +97 -0
- package/src/prove/smt/solver/model-macro-solver.ts +728 -0
- package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
- package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
- package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
- package/src/prove/smt/solver/nlsat/explain.ts +607 -0
- package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
- package/src/prove/smt/solver/nlsat/levelwise.ts +737 -0
- package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
- package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
- package/src/prove/smt/solver/nlsat/solver.ts +911 -0
- package/src/prove/smt/solver/nlsat/types.ts +43 -0
- package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
- package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
- package/src/prove/smt/solver/nnf.ts +469 -0
- package/src/prove/smt/solver/pattern-inference.ts +351 -0
- package/src/prove/smt/solver/poly-rewriter.ts +477 -0
- package/src/prove/smt/solver/propagate-values.ts +83 -0
- package/src/prove/smt/solver/proto-model.ts +551 -0
- package/src/prove/smt/solver/pull-quant.ts +139 -0
- package/src/prove/smt/solver/qe-lite-der.ts +526 -0
- package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
- package/src/prove/smt/solver/qe-lite.ts +381 -0
- package/src/prove/smt/solver/qi-queue.ts +362 -0
- package/src/prove/smt/solver/quant-tactics.ts +117 -0
- package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
- package/src/prove/smt/solver/quantifier-manager.ts +186 -0
- package/src/prove/smt/solver/random-gen.ts +10 -0
- package/src/prove/smt/solver/rational.ts +165 -0
- package/src/prove/smt/solver/ref-vector.ts +62 -0
- package/src/prove/smt/solver/relevancy.ts +247 -0
- package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
- package/src/prove/smt/solver/rewriter.ts +843 -0
- package/src/prove/smt/solver/rlimit.ts +79 -0
- package/src/prove/smt/solver/smtlib-parser.ts +526 -0
- package/src/prove/smt/solver/solver.ts +71 -0
- package/src/prove/smt/solver/sort.ts +35 -0
- package/src/prove/smt/solver/sticky-generations.ts +69 -0
- package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
- package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
- package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
- package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
- package/src/prove/smt/solver/theory-lra-model.ts +243 -0
- package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
- package/src/prove/smt/solver/theory-lra-state.ts +43 -0
- package/src/prove/smt/solver/theory-lra.ts +56 -0
- package/src/prove/smt/solver/var-subst.ts +258 -0
- package/src/prove/smt/solver/z3-license.txt +10 -0
- package/src/prove/smt/table.ts +170 -0
- package/src/prove/tlapm/tlapm.ts +96 -0
- package/src/prove/tlaps-module.ts +510 -0
- package/src/prove/verdict.ts +18 -0
- package/src/prove/zenon/LICENSE +32 -0
- package/src/prove/zenon/check/check.ts +105 -0
- package/src/prove/zenon/check/definitions.ts +144 -0
- package/src/prove/zenon/check/equality.ts +182 -0
- package/src/prove/zenon/check/functions.ts +62 -0
- package/src/prove/zenon/check/keys.ts +125 -0
- package/src/prove/zenon/check/propositional.ts +104 -0
- package/src/prove/zenon/check/records.ts +188 -0
- package/src/prove/zenon/check/relations.ts +121 -0
- package/src/prove/zenon/check/rewrites.ts +224 -0
- package/src/prove/zenon/check/sets.ts +302 -0
- package/src/prove/zenon/check/terms.ts +127 -0
- package/src/prove/zenon/check/tla.ts +126 -0
- package/src/prove/zenon/decide.ts +113 -0
- package/src/prove/zenon/encode.ts +379 -0
- package/src/prove/zenon/eqrel.ts +300 -0
- package/src/prove/zenon/equality-rules.ts +435 -0
- package/src/prove/zenon/expr.ts +551 -0
- package/src/prove/zenon/index-table.ts +350 -0
- package/src/prove/zenon/isar-case.ts +513 -0
- package/src/prove/zenon/isar.ts +1249 -0
- package/src/prove/zenon/limits.ts +15 -0
- package/src/prove/zenon/llproof.ts +173 -0
- package/src/prove/zenon/mltoll.ts +1566 -0
- package/src/prove/zenon/node.ts +297 -0
- package/src/prove/zenon/ocaml.ts +169 -0
- package/src/prove/zenon/parse.ts +247 -0
- package/src/prove/zenon/phrase.ts +191 -0
- package/src/prove/zenon/proof.ts +198 -0
- package/src/prove/zenon/propositional-rules.ts +387 -0
- package/src/prove/zenon/rules.ts +94 -0
- package/src/prove/zenon/search.ts +288 -0
- package/src/prove/zenon/tla/functions.ts +151 -0
- package/src/prove/zenon/tla/llproof.ts +480 -0
- package/src/prove/zenon/tla/records.ts +225 -0
- package/src/prove/zenon/tla/rewrites.ts +447 -0
- package/src/prove/zenon/tla/sets.ts +304 -0
- package/src/prove/zenon/tla/terms.ts +162 -0
- package/src/prove/zenon/tla/tla.ts +506 -0
- package/src/randomization.ts +24 -7
- package/src/resolve.ts +1481 -426
- package/src/run-cli.ts +1483 -212
- package/src/runtime.ts +19 -1
- package/src/sany-builtins.ts +147 -0
- package/src/sany-generator.ts +3128 -0
- package/src/sany-levels.ts +1208 -0
- package/src/sany-lexer.ts +545 -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 +356 -0
- package/src/sany-selectors.ts +738 -0
- package/src/sany-source.ts +248 -0
- package/src/sany-xml.ts +1017 -0
- package/src/spec-description.ts +42 -11
- package/src/standard-modules.ts +203 -148
- package/src/standard-ranges.ts +116 -0
- package/src/state-graph.ts +180 -0
- package/src/subexpressions.ts +231 -171
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +241 -110
- package/src/symmetry.ts +194 -54
- package/src/tableau.ts +54 -25
- package/src/tlapm-cache.ts +236 -0
- package/src/tlc-ext.ts +42 -29
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +52 -43
- package/src/tlc-modules.ts +4 -0
- package/src/tlc-order.ts +78 -10
- package/src/tlc-random.ts +84 -33
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-summary.ts +20 -5
- package/src/tlc-version.ts +19 -0
- package/src/transfer.ts +15 -3
- package/src/values.ts +787 -190
- package/src/worker.ts +65 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
package/src/run-cli.ts
CHANGED
|
@@ -5,12 +5,27 @@ import {
|
|
|
5
5
|
readFileSync,
|
|
6
6
|
readSync,
|
|
7
7
|
realpathSync,
|
|
8
|
+
rmSync,
|
|
8
9
|
writeFileSync,
|
|
9
10
|
} from "node:fs";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
11
|
+
import { basename, delimiter, dirname, isAbsolute, join, resolve } from "node:path";
|
|
12
|
+
import { arch, availableParallelism, release, tmpdir, type } from "node:os";
|
|
13
|
+
import { pathToFileURL } from "node:url";
|
|
14
|
+
import { getHeapStatistics } from "node:v8";
|
|
15
|
+
import { version } from "../package.json";
|
|
16
|
+
import type { Expression } from "./ast";
|
|
17
|
+
import { describeRange } from "./evaluate";
|
|
18
|
+
import type {
|
|
19
|
+
CheckProgress,
|
|
20
|
+
InitialStateViolation,
|
|
21
|
+
OutputLine,
|
|
22
|
+
CheckResult,
|
|
23
|
+
CheckStatus,
|
|
24
|
+
InitialStates,
|
|
25
|
+
SearchStatistics,
|
|
26
|
+
TraceStep,
|
|
27
|
+
Violation,
|
|
28
|
+
} from "./check";
|
|
14
29
|
import { defineCommand, type ParsedArgs } from "./cli-options";
|
|
15
30
|
import { parseConfig } from "./config";
|
|
16
31
|
import {
|
|
@@ -19,20 +34,66 @@ import {
|
|
|
19
34
|
TlaError,
|
|
20
35
|
TlaEvaluationError,
|
|
21
36
|
TlaProofError,
|
|
37
|
+
TlaSyntaxError,
|
|
38
|
+
getUnexpectedException,
|
|
39
|
+
TlaJavaException,
|
|
40
|
+
UNEXPECTED_EXCEPTION,
|
|
41
|
+
TlaSanyFatalError,
|
|
42
|
+
TlaUnsupportedError,
|
|
22
43
|
} from "./errors";
|
|
23
|
-
import { EXIT_STATUS } from "./exit-codes";
|
|
24
|
-
import type { LineRange } from "./
|
|
25
|
-
import { getAtPrefix, getLocusText } from "./
|
|
26
|
-
import {
|
|
44
|
+
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
45
|
+
import type { LineRange } from "./obligations/generate";
|
|
46
|
+
import { getAtPrefix, getLocusText } from "./obligations/expression";
|
|
47
|
+
import {
|
|
48
|
+
formatSummary,
|
|
49
|
+
getObligations,
|
|
50
|
+
WHOLE_MODULE,
|
|
51
|
+
type ModuleObligations,
|
|
52
|
+
type PrintedObligation,
|
|
53
|
+
} from "./obligations";
|
|
54
|
+
import { format, renderDoc } from "./obligations/format";
|
|
55
|
+
import { printSequent } from "./obligations/printer";
|
|
27
56
|
import { check } from "./parallel";
|
|
28
|
-
import {
|
|
57
|
+
import { parseModule } from "./parser";
|
|
58
|
+
import {
|
|
59
|
+
encodeProofTheory,
|
|
60
|
+
formatNormalized,
|
|
61
|
+
proveObligations,
|
|
62
|
+
type ProofAttempt,
|
|
63
|
+
} from "./prove/prove";
|
|
64
|
+
import { TLAPS_MODULE } from "./prove/tlaps-module";
|
|
65
|
+
import type { StateDump } from "./state-graph";
|
|
29
66
|
import {
|
|
30
67
|
formatProbability,
|
|
31
68
|
getActualProbability,
|
|
32
69
|
getOptimisticProbability,
|
|
33
70
|
getOutDegreeSummary,
|
|
34
71
|
} from "./tlc-summary";
|
|
35
|
-
import {
|
|
72
|
+
import { getTlapmPaths } from "./prove/tlapm/tlapm";
|
|
73
|
+
import {
|
|
74
|
+
getKnownResults,
|
|
75
|
+
loadFingerprints,
|
|
76
|
+
saveHistory,
|
|
77
|
+
type FingerprintTable,
|
|
78
|
+
} from "./tlapm-cache";
|
|
79
|
+
import type { SanySpecification } from "./sany-generator";
|
|
80
|
+
import { SANY_174_STANDARD_MODULES, SANY_STANDARD_MODULES } from "./sany-modules";
|
|
81
|
+
import { getSanyModuleName, getSanyReport, type SanyModuleOrigin } from "./sany-report";
|
|
82
|
+
import { exportSanyXml, XML_EXPORT_EXIT_CODE, type XmlExportOptions } from "./sany-xml";
|
|
83
|
+
import { getTlcFingerprint } from "./tlc-random";
|
|
84
|
+
import { getTlcVersion, type TlcVersion } from "./tlc-version";
|
|
85
|
+
import {
|
|
86
|
+
createMessagePrinter,
|
|
87
|
+
formatTlcDate,
|
|
88
|
+
formatInnerMessage,
|
|
89
|
+
formatNestedMessage,
|
|
90
|
+
formatTlcDuration,
|
|
91
|
+
getCodedMessage,
|
|
92
|
+
MESSAGE_CODE,
|
|
93
|
+
MESSAGE_LEVEL,
|
|
94
|
+
type MessagePrinter,
|
|
95
|
+
} from "./tlc-messages";
|
|
96
|
+
import { formatState } from "./values";
|
|
36
97
|
|
|
37
98
|
const EXIT_CODES: Record<CheckStatus, number> = {
|
|
38
99
|
success: EXIT_STATUS.success,
|
|
@@ -48,25 +109,100 @@ const EXIT_CODES: Record<CheckStatus, number> = {
|
|
|
48
109
|
const CHECK_COMMAND = defineCommand("tla-ts <Spec.tla|Spec.cfg|glob>... {options}", [
|
|
49
110
|
{ flag: "-config <Spec.cfg>" },
|
|
50
111
|
{ flag: "-deadlock" },
|
|
112
|
+
// Like TLC, -dump takes a format only when the next argument starts with dot and a file follows.
|
|
113
|
+
{
|
|
114
|
+
flag: "-dump [<format>] <file>",
|
|
115
|
+
getArity: (rest) => (rest.length > 1 && rest[0].startsWith("dot") ? 2 : 1),
|
|
116
|
+
},
|
|
117
|
+
{ flag: "-fp <num>" },
|
|
51
118
|
{ flag: "-lncheck <final|default>" },
|
|
119
|
+
{ flag: "-metadir <directory>" },
|
|
120
|
+
{ flag: "-nowarning" },
|
|
52
121
|
{ flag: "-seed <num>" },
|
|
122
|
+
{ flag: "-tool" },
|
|
53
123
|
{ flag: "-workers <count|auto>" },
|
|
54
124
|
]);
|
|
55
125
|
|
|
56
|
-
const
|
|
57
|
-
{ flag: "-N"
|
|
126
|
+
const TLAPM_COMMAND = defineCommand("tla-ts tlapm {options} <Module.tla|glob>...", [
|
|
127
|
+
{ flag: "-N" },
|
|
128
|
+
{ flag: "--summary" },
|
|
129
|
+
{ flag: "--strict" },
|
|
58
130
|
{ flag: "--toolbox <start> <end>" },
|
|
59
131
|
{ flag: "--line <num>" },
|
|
60
132
|
{ flag: "--printallobs" },
|
|
61
|
-
{ flag: "--
|
|
62
|
-
{ flag: "--
|
|
133
|
+
{ flag: "--threads <num>" },
|
|
134
|
+
{ flag: "--version" },
|
|
63
135
|
{ flag: "-I <directory>", isRepeatable: true },
|
|
136
|
+
{ flag: "-k" },
|
|
137
|
+
{ flag: "--noproving" },
|
|
138
|
+
{ flag: "--nofp" },
|
|
139
|
+
{ flag: "--nofpl <start> <end>" },
|
|
140
|
+
{ flag: "--safefp" },
|
|
141
|
+
{ flag: "--cleanfp" },
|
|
142
|
+
{ flag: "--usefp <file>" },
|
|
143
|
+
{ flag: "--cache-dir <directory>" },
|
|
64
144
|
]);
|
|
65
145
|
|
|
146
|
+
const TLAPM_INTEGER_OPTIONS = new Set(["--toolbox", "--line", "--threads", "--nofpl"]);
|
|
147
|
+
|
|
148
|
+
const XML_EXPORT_FLAGS = new Set(["-o", "-t", "-r", "-u"]);
|
|
149
|
+
|
|
150
|
+
const XML_EXPORT_174_FLAGS = new Set(["-o"]);
|
|
151
|
+
|
|
152
|
+
// The usage that XMLExporter.printUsage prints with UsageGenerator.
|
|
153
|
+
const XML_EXPORT_USAGE = (() => {
|
|
154
|
+
const bold = (text: string) => `\x1b[1m${text}\x1b[0m`;
|
|
155
|
+
const options = [
|
|
156
|
+
["-I", "Include; use given directory path to resolve module dependencies."],
|
|
157
|
+
["-help", "Print this usage information."],
|
|
158
|
+
["-o", "Offline mode; skip XML schema validation step."],
|
|
159
|
+
[
|
|
160
|
+
"-r",
|
|
161
|
+
"Restrict mode; include only declarations and definitions of the specified module, excluding extended or instantiated modules.",
|
|
162
|
+
],
|
|
163
|
+
["-t", "Terse; format XML output without tabs or newlines."],
|
|
164
|
+
[
|
|
165
|
+
"-u",
|
|
166
|
+
"Uncomment; process boxed comments and single-line comments (\\*) in pre-comments to extract their content.",
|
|
167
|
+
],
|
|
168
|
+
];
|
|
169
|
+
const tips = [
|
|
170
|
+
"Only one root TLA+ file can be parsed per run.",
|
|
171
|
+
"Multiple directory search paths can be given by providing multiple -I arguments.",
|
|
172
|
+
"XML schema validation does not require network access.",
|
|
173
|
+
];
|
|
174
|
+
return [
|
|
175
|
+
"",
|
|
176
|
+
bold("NAME"),
|
|
177
|
+
"",
|
|
178
|
+
"\ttla2sany.xml.XMLExporter - Emit SANY's parse tree as XML - Version 2.2 created 08 July 2020",
|
|
179
|
+
"",
|
|
180
|
+
"",
|
|
181
|
+
bold("SYNOPSIS"),
|
|
182
|
+
"",
|
|
183
|
+
`\t${bold("tla2sany.xml.XMLExporter")} [${bold("-Iortu")}] [${bold("-help")}] FILE`,
|
|
184
|
+
"",
|
|
185
|
+
bold("DESCRIPTION"),
|
|
186
|
+
"",
|
|
187
|
+
"\tGiven a TLA+ file, parse that file with SANY then translate the module's semantic parse tree to XML, including all the modules depended on. The XML is printed to stdout and its output format is given by an XML Schema file (.xsd) found at https://proofs.tlapl.us/doc/web/sany.xsd.",
|
|
188
|
+
"",
|
|
189
|
+
bold("OPTIONS"),
|
|
190
|
+
"",
|
|
191
|
+
...options.map(([flag, description]) => `\t${bold(flag)}\n\t\t${description}`),
|
|
192
|
+
"",
|
|
193
|
+
bold("TIPS"),
|
|
194
|
+
"",
|
|
195
|
+
...tips.flatMap((tip) => [`\t${tip}`, ""]),
|
|
196
|
+
"",
|
|
197
|
+
].join("\n");
|
|
198
|
+
})();
|
|
199
|
+
|
|
66
200
|
const USAGE = [
|
|
67
201
|
`Usage: ${CHECK_COMMAND.usage}`,
|
|
68
|
-
` ${
|
|
69
|
-
" tla-ts
|
|
202
|
+
` ${TLAPM_COMMAND.usage}`,
|
|
203
|
+
" tla-ts [<JVM option>]... tlc2.TLC <TLC option>... <Spec>",
|
|
204
|
+
" (-cp tla2tools.jar or -Dtla-ts.tlc=1.7.4 picks the TLC to reproduce)",
|
|
205
|
+
" tla-ts [<JVM option>]... tla2sany.xml.XMLExporter [-I <directory>]... [-o] [-t] [-r] [-u] <Module.tla>",
|
|
70
206
|
].join("\n");
|
|
71
207
|
|
|
72
208
|
const GLOB_CHARACTERS = /[*?[{]/;
|
|
@@ -95,232 +231,885 @@ const getWorkerCount = (values: string[] | undefined) => {
|
|
|
95
231
|
: Math.max(1, Number.parseInt(values[0], 10) || 1);
|
|
96
232
|
};
|
|
97
233
|
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
234
|
+
const UNSUPPORTED_DUMP_FORMATS = ["constrained", "stuttering", "strict"];
|
|
235
|
+
|
|
236
|
+
// TLC names the file of a -dump by its format unless the name already ends that way.
|
|
237
|
+
const getDumpPath = (path: string, extension: string) =>
|
|
238
|
+
path.endsWith(extension) ? path : `${path}${extension}`;
|
|
239
|
+
|
|
240
|
+
const getDump = (values: string[]): StateDump => {
|
|
241
|
+
if (values.length === 1) return { path: getDumpPath(values[0], ".dump") };
|
|
242
|
+
const format = values[0].toLowerCase();
|
|
243
|
+
return {
|
|
244
|
+
path: getDumpPath(values[1], ".dot"),
|
|
245
|
+
dot: true,
|
|
246
|
+
colorize: format.includes("colorize"),
|
|
247
|
+
actionLabels: format.includes("actionlabels"),
|
|
248
|
+
snapshot: format.includes("snapshot"),
|
|
249
|
+
};
|
|
106
250
|
};
|
|
107
251
|
|
|
108
|
-
|
|
109
|
-
|
|
252
|
+
// What the spec prints as TLC rebuilds a trace, before it prints the states or after.
|
|
253
|
+
const printInitialStatesProgress = (printer: MessagePrinter, count: number) =>
|
|
254
|
+
printer.print(
|
|
255
|
+
MESSAGE_CODE.computingInitProgress,
|
|
256
|
+
MESSAGE_LEVEL.none,
|
|
257
|
+
`Computed ${count} initial states...`,
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const getInitialViolationHeadline = (
|
|
261
|
+
status: InitialStateViolation["status"],
|
|
262
|
+
name: string | undefined,
|
|
263
|
+
) =>
|
|
264
|
+
status === "invariant-violation"
|
|
265
|
+
? {
|
|
266
|
+
code: MESSAGE_CODE.invariantViolatedInitial,
|
|
267
|
+
text: `Invariant ${name} is violated by the initial state:`,
|
|
268
|
+
}
|
|
269
|
+
: {
|
|
270
|
+
code: MESSAGE_CODE.propertyViolatedInitial,
|
|
271
|
+
text: `Property ${name} is violated by the initial state:`,
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const printTraceOutput = (printer: MessagePrinter, lines: OutputLine[] | undefined) =>
|
|
275
|
+
lines?.forEach((line) => {
|
|
276
|
+
if (typeof line === "string") return console.log(line);
|
|
277
|
+
if (line.kind === "initial-states-progress") {
|
|
278
|
+
return printInitialStatesProgress(printer, line.count);
|
|
279
|
+
}
|
|
280
|
+
const headline = getInitialViolationHeadline(line.status, line.name);
|
|
281
|
+
printer.print(
|
|
282
|
+
headline.code,
|
|
283
|
+
MESSAGE_LEVEL.error,
|
|
284
|
+
`${headline.text}\n${formatState(line.state)}`,
|
|
285
|
+
);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
const printTrace = (
|
|
289
|
+
printer: MessagePrinter,
|
|
290
|
+
trace: TraceStep[],
|
|
291
|
+
heading: { code: number; text: string } = {
|
|
292
|
+
code: MESSAGE_CODE.behaviorUpToThisPoint,
|
|
293
|
+
text: "The behavior up to this point is:",
|
|
294
|
+
},
|
|
295
|
+
isRebuiltAfterHeading = false,
|
|
296
|
+
) => {
|
|
297
|
+
if (trace.length > 0) printer.print(heading.code, MESSAGE_LEVEL.error, heading.text);
|
|
110
298
|
trace.forEach((step, index) => {
|
|
111
|
-
|
|
112
|
-
|
|
299
|
+
if (index > 0 || isRebuiltAfterHeading) printTraceOutput(printer, step.output);
|
|
300
|
+
printer.print(
|
|
301
|
+
MESSAGE_CODE.statePrint2,
|
|
302
|
+
MESSAGE_LEVEL.state,
|
|
303
|
+
`${index + 1}: <${step.label ?? step.action ?? "Initial predicate"}>\n${formatState(step.state)}`,
|
|
304
|
+
);
|
|
113
305
|
});
|
|
114
306
|
};
|
|
115
307
|
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
308
|
+
const COUNTER_EXAMPLE = {
|
|
309
|
+
code: MESSAGE_CODE.counterExample,
|
|
310
|
+
text: "The following behavior constitutes a counter-example:\n",
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// TLC 1.7.4 doesn't name the properties, and later versions name none when they can't tell which.
|
|
314
|
+
const getTemporalHeadline = (names: string[], version: TlcVersion) =>
|
|
315
|
+
version === "1.7.4" || names.length === 0
|
|
316
|
+
? "Temporal properties were violated.\n"
|
|
317
|
+
: names.length === 1
|
|
318
|
+
? `Temporal property ${names[0]} was violated.\n`
|
|
319
|
+
: `Temporal properties ${names.slice(0, -1).join(", ")}${names.length > 2 ? "," : ""} and ${names[names.length - 1]} were violated.\n`;
|
|
320
|
+
|
|
321
|
+
// TLC's FingerprintException#getTrace: the range of each source, innermost first, skipping a
|
|
322
|
+
// source the same as the one inside it.
|
|
323
|
+
const formatFingerprintTrace = (sources: Expression[]) =>
|
|
324
|
+
sources
|
|
325
|
+
.filter((source, index) => source !== sources[index - 1])
|
|
326
|
+
.map((source, index) => `${index}) ${describeRange(source)}\n`)
|
|
327
|
+
.toReversed()
|
|
328
|
+
.join("");
|
|
329
|
+
|
|
330
|
+
// TLC's CallStack.toString: the range of each expression, skipping an expression that it evaluates
|
|
331
|
+
// again right inside itself.
|
|
332
|
+
const formatCallStack = (expressions: Expression[]) => {
|
|
333
|
+
if (expressions.length === 0) return " The error call stack is empty.\n";
|
|
334
|
+
const lines: string[] = [];
|
|
335
|
+
expressions.forEach((expression, index) => {
|
|
336
|
+
const range = expression.location.range;
|
|
337
|
+
if (expression === expressions[index - 1] || !range) return;
|
|
338
|
+
lines.push(
|
|
339
|
+
`${lines.length}. Line ${range.start.line}, column ${range.start.column} to line ${range.end.line}, column ${range.end.column} in ${range.module}\n`,
|
|
340
|
+
);
|
|
341
|
+
});
|
|
342
|
+
return `${lines.join("")}\n`;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const printInitialStates = (printer: MessagePrinter, initialStates: InitialStates) => {
|
|
346
|
+
const generated = initialStates.generated;
|
|
347
|
+
const distinct = initialStates.distinct;
|
|
348
|
+
const date = formatTlcDate(new Date());
|
|
349
|
+
if (generated === distinct) {
|
|
350
|
+
printer.print(
|
|
351
|
+
MESSAGE_CODE.initGenerated1,
|
|
352
|
+
MESSAGE_LEVEL.none,
|
|
353
|
+
`Finished computing initial states: ${distinct} distinct state${distinct === 1 ? "" : "s"} generated at ${date}.`,
|
|
354
|
+
);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
printer.print(
|
|
358
|
+
MESSAGE_CODE.initGenerated2,
|
|
359
|
+
MESSAGE_LEVEL.none,
|
|
360
|
+
`Finished computing initial states: ${generated} state${generated === 1 ? "" : "s"} generated, with ${distinct} of them distinct at ${date}.`,
|
|
361
|
+
);
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
interface Timing {
|
|
365
|
+
start: number;
|
|
366
|
+
// Whether TLC has printed that SANY finished.
|
|
367
|
+
isParsed: boolean;
|
|
368
|
+
// When TLC started to check the temporal properties on the complete state graph.
|
|
369
|
+
liveness: number | undefined;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// TLC reports how far the search got when it prints messages for a program to read, at level 1 or
|
|
373
|
+
// deeper even before it finds a state. As the search goes and when it ends, it adds how many
|
|
374
|
+
// states it generated and found a minute.
|
|
375
|
+
const printProgress = (
|
|
376
|
+
printer: MessagePrinter,
|
|
377
|
+
statistics: SearchStatistics,
|
|
378
|
+
startTime?: number,
|
|
379
|
+
) => {
|
|
380
|
+
const minutes = Math.max(Date.now() - (startTime ?? 0), 1) / 60_000;
|
|
381
|
+
const format = (count: number) => count.toLocaleString("en-US");
|
|
382
|
+
const getRate = (count: number, unit: string) =>
|
|
383
|
+
startTime === undefined ? "" : ` (${format(Math.floor(count / minutes))} ${unit}/min)`;
|
|
384
|
+
printer.print(
|
|
385
|
+
MESSAGE_CODE.progress,
|
|
386
|
+
MESSAGE_LEVEL.none,
|
|
387
|
+
`Progress(${Math.max(statistics.depth, 1)}) at ${formatTlcDate(new Date())}: ${format(statistics.generatedStates)} states generated${getRate(statistics.generatedStates, "s")}, ${format(statistics.distinctStates)} distinct states found${getRate(statistics.distinctStates, "ds")}, ${format(statistics.queuedStates)} states left on queue.`,
|
|
388
|
+
);
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
const getClassPath = (directory: string, module: string) => join(directory, `${module}.class`);
|
|
392
|
+
|
|
393
|
+
// The messages TLC prints as the search goes.
|
|
394
|
+
const printCheckProgress = (
|
|
395
|
+
printer: MessagePrinter,
|
|
396
|
+
progress: CheckProgress,
|
|
397
|
+
timing: Timing,
|
|
398
|
+
directory: string,
|
|
399
|
+
) => {
|
|
400
|
+
const print = printer.print;
|
|
401
|
+
switch (progress.kind) {
|
|
402
|
+
case "parsed":
|
|
403
|
+
timing.isParsed = true;
|
|
404
|
+
if (printer.isTool) print(MESSAGE_CODE.sanyFinished, MESSAGE_LEVEL.none, "SANY finished.");
|
|
405
|
+
print(
|
|
406
|
+
MESSAGE_CODE.starting,
|
|
407
|
+
MESSAGE_LEVEL.none,
|
|
408
|
+
`Starting... (${formatTlcDate(new Date())})`,
|
|
409
|
+
);
|
|
410
|
+
return;
|
|
411
|
+
// TLC 1.7.4 warns about neither a constant-level invariant nor a state-level property.
|
|
412
|
+
case "constant-level-invariant":
|
|
413
|
+
if (printer.version === "1.7.4") return;
|
|
414
|
+
print(
|
|
415
|
+
MESSAGE_CODE.constantLevelInvariant,
|
|
416
|
+
MESSAGE_LEVEL.warning,
|
|
417
|
+
`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.`,
|
|
418
|
+
);
|
|
419
|
+
return;
|
|
420
|
+
case "state-level-property":
|
|
421
|
+
if (printer.version === "1.7.4") return;
|
|
422
|
+
print(
|
|
423
|
+
MESSAGE_CODE.stateLevelProperty,
|
|
424
|
+
MESSAGE_LEVEL.warning,
|
|
425
|
+
`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.`,
|
|
426
|
+
);
|
|
427
|
+
return;
|
|
428
|
+
case "liveness-initializing":
|
|
429
|
+
if (progress.isSymmetric) {
|
|
430
|
+
print(
|
|
431
|
+
MESSAGE_CODE.livenessSymmetry,
|
|
432
|
+
MESSAGE_LEVEL.warning,
|
|
433
|
+
"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.",
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
// Only TLC 1.7.4 warns about constraints.
|
|
437
|
+
if (progress.isConstrained && printer.version === "1.7.4") {
|
|
438
|
+
print(
|
|
439
|
+
MESSAGE_CODE.livenessConstraints,
|
|
440
|
+
MESSAGE_LEVEL.warning,
|
|
441
|
+
"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.",
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
return;
|
|
445
|
+
case "liveness-prepared":
|
|
446
|
+
print(
|
|
447
|
+
MESSAGE_CODE.temporalBranches,
|
|
448
|
+
MESSAGE_LEVEL.none,
|
|
449
|
+
`Implied-temporal checking--satisfiability problem has ${progress.branches} branches.`,
|
|
450
|
+
);
|
|
451
|
+
return;
|
|
452
|
+
case "java-override": {
|
|
453
|
+
// Class#getResource, which names the class file TLC loads the override from.
|
|
454
|
+
const location = pathToFileURL(resolve(getClassPath(directory, progress.module))).href;
|
|
455
|
+
print(
|
|
456
|
+
progress.isMatched ? MESSAGE_CODE.javaOverrideLoaded : MESSAGE_CODE.javaOverrideMismatch,
|
|
457
|
+
progress.isMatched ? MESSAGE_LEVEL.none : MESSAGE_LEVEL.warning,
|
|
458
|
+
`${progress.isMatched ? "Loading" : "Failed to match"} ${progress.operator} operator override from ${location.replace("file:///", "file:/")} with signature: <Java Method: ${progress.signature}>.`,
|
|
459
|
+
);
|
|
460
|
+
return;
|
|
122
461
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
? `Error: Temporal property ${name} was violated.\n`
|
|
147
|
-
: isInitial
|
|
148
|
-
? `Error: Property ${name} is violated by the initial state:`
|
|
149
|
-
: `Error: Action property ${name} is violated.`,
|
|
150
|
-
"postcondition-violation": `Error: ${violation.message ?? `Postcondition ${name} is false.`}`,
|
|
151
|
-
}[result.status];
|
|
152
|
-
if (violation.counts) console.log(violation.counts);
|
|
153
|
-
console.log(headline);
|
|
154
|
-
if (isInitial) printState(violation.trace[0].state);
|
|
155
|
-
else if (loopStart === undefined) printTrace(violation.trace);
|
|
156
|
-
else {
|
|
157
|
-
printTrace(violation.trace, "Error: The following behavior constitutes a counter-example:\n");
|
|
158
|
-
const isStuttering = loopStart === violation.trace.length - 1;
|
|
159
|
-
console.log(
|
|
160
|
-
isStuttering
|
|
161
|
-
? `State ${loopStart + 2}: Stuttering`
|
|
162
|
-
: `Back to state ${loopStart + 1}${violation.loopLabel ? `: <${violation.loopLabel}>\n` : ""}`,
|
|
462
|
+
case "initial-states-started":
|
|
463
|
+
print(MESSAGE_CODE.computingInit, MESSAGE_LEVEL.none, "Computing initial states...");
|
|
464
|
+
return;
|
|
465
|
+
case "initial-states-progress":
|
|
466
|
+
printInitialStatesProgress(printer, progress.count);
|
|
467
|
+
return;
|
|
468
|
+
case "initial-states-computed":
|
|
469
|
+
printInitialStates(printer, progress.initialStates);
|
|
470
|
+
return;
|
|
471
|
+
case "progress":
|
|
472
|
+
printProgress(printer, progress.statistics, timing.start);
|
|
473
|
+
return;
|
|
474
|
+
case "liveness-started": {
|
|
475
|
+
timing.liveness = Date.now();
|
|
476
|
+
// TLC reports how far the search got before it checks the complete state graph.
|
|
477
|
+
if (progress.isComplete) printProgress(printer, progress.statistics);
|
|
478
|
+
const branches = progress.branches > 1 ? `${progress.branches} branches of ` : "";
|
|
479
|
+
// TLC counts the states of the behavior graph of each branch, without its tableau nodes.
|
|
480
|
+
const states = progress.branches * progress.states;
|
|
481
|
+
print(
|
|
482
|
+
MESSAGE_CODE.checkingTemporal,
|
|
483
|
+
MESSAGE_LEVEL.none,
|
|
484
|
+
`Checking ${branches}temporal properties for the ${progress.isComplete ? "complete" : "current"} state space with ${states} total distinct states at (${formatTlcDate(new Date())})`,
|
|
163
485
|
);
|
|
486
|
+
return;
|
|
164
487
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
488
|
+
case "liveness-finished":
|
|
489
|
+
printLivenessEnd(printer, timing);
|
|
490
|
+
return;
|
|
491
|
+
case "warning":
|
|
492
|
+
print(progress.code, MESSAGE_LEVEL.warning, progress.text);
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
const printLivenessEnd = (printer: MessagePrinter, timing: Timing) => {
|
|
497
|
+
if (timing.liveness === undefined) return;
|
|
498
|
+
printer.print(
|
|
499
|
+
MESSAGE_CODE.checkingTemporalEnd,
|
|
500
|
+
MESSAGE_LEVEL.none,
|
|
501
|
+
`Finished checking temporal properties in ${formatTlcDuration(Date.now() - timing.liveness)} at ${formatTlcDate(new Date())}`,
|
|
502
|
+
);
|
|
503
|
+
timing.liveness = undefined;
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
// Prints a violation, and returns whether TLC goes on to print the statistics of the search.
|
|
507
|
+
const printViolation = (status: CheckStatus, violation: Violation, printer: MessagePrinter) => {
|
|
508
|
+
const print = printer.print;
|
|
509
|
+
const name = violation.name;
|
|
510
|
+
const loopStart = violation.loopStart;
|
|
511
|
+
// TLC prints a violation by an initial state without the behavior or the statistics.
|
|
512
|
+
const isInitial =
|
|
513
|
+
loopStart === undefined &&
|
|
514
|
+
violation.trace.length === 1 &&
|
|
515
|
+
(status === "invariant-violation" || status === "liveness-violation");
|
|
516
|
+
const temporal = {
|
|
517
|
+
code: MESSAGE_CODE.temporalPropertyViolated,
|
|
518
|
+
text: getTemporalHeadline(violation.properties ?? [name], printer.version),
|
|
519
|
+
};
|
|
520
|
+
const headline = {
|
|
521
|
+
success: undefined,
|
|
522
|
+
error: undefined,
|
|
523
|
+
"assumption-violation": violation.message
|
|
524
|
+
? {
|
|
525
|
+
code: MESSAGE_CODE.assumptionEvaluationError,
|
|
526
|
+
text: formatInnerMessage(
|
|
527
|
+
MESSAGE_CODE.assumptionEvaluationError,
|
|
528
|
+
`Evaluating assumption ${name} failed.\n${violation.message}`,
|
|
529
|
+
printer.isTool,
|
|
530
|
+
),
|
|
531
|
+
}
|
|
532
|
+
: { code: MESSAGE_CODE.assumptionFalse, text: `Assumption ${name} is false.` },
|
|
533
|
+
deadlock: { code: MESSAGE_CODE.deadlockReached, text: "Deadlock reached." },
|
|
534
|
+
"invariant-violation": isInitial
|
|
535
|
+
? getInitialViolationHeadline("invariant-violation", name)
|
|
536
|
+
: { code: MESSAGE_CODE.invariantViolatedBehavior, text: `Invariant ${name} is violated.` },
|
|
537
|
+
"property-violation": temporal,
|
|
538
|
+
"liveness-violation":
|
|
539
|
+
loopStart !== undefined
|
|
540
|
+
? temporal
|
|
541
|
+
: isInitial
|
|
542
|
+
? getInitialViolationHeadline("liveness-violation", name)
|
|
543
|
+
: {
|
|
544
|
+
code: MESSAGE_CODE.actionPropertyViolatedBehavior,
|
|
545
|
+
text: `Action property ${name} is violated.`,
|
|
546
|
+
},
|
|
547
|
+
"postcondition-violation": {
|
|
548
|
+
code: violation.postcondition?.code ?? MESSAGE_CODE.general,
|
|
549
|
+
text: violation.message ?? `Postcondition ${name} is false.`,
|
|
550
|
+
},
|
|
551
|
+
}[status];
|
|
552
|
+
// A safety property's counterexample ends where it breaks, and a liveness one loops back.
|
|
553
|
+
const isProperty = status === "property-violation";
|
|
554
|
+
const isLasso = loopStart !== undefined && !isProperty;
|
|
555
|
+
const isCounterExample = isProperty || isLasso;
|
|
556
|
+
// TLC rebuilds a liveness counterexample before it reports the violation, and 1.7.4's
|
|
557
|
+
// LiveWorker#printTrace after it prints the heading of the counterexample.
|
|
558
|
+
const isRebuiltFirst = isCounterExample && printer.version !== "1.7.4";
|
|
559
|
+
if (isRebuiltFirst) printTraceOutput(printer, violation.trace[0]?.output);
|
|
560
|
+
if (violation.counts) console.log(violation.counts);
|
|
561
|
+
if (headline) {
|
|
562
|
+
// TLC prints the initial state that violates a property in the same message.
|
|
563
|
+
const text = isInitial
|
|
564
|
+
? `${headline.text}\n${formatState(violation.trace[0].state)}`
|
|
565
|
+
: headline.text;
|
|
566
|
+
print(headline.code, MESSAGE_LEVEL.error, text);
|
|
567
|
+
}
|
|
568
|
+
if (!isInitial) {
|
|
569
|
+
if (!isCounterExample) printTraceOutput(printer, violation.trace[0]?.output);
|
|
570
|
+
printTrace(
|
|
571
|
+
printer,
|
|
572
|
+
violation.trace,
|
|
573
|
+
isCounterExample ? COUNTER_EXAMPLE : undefined,
|
|
574
|
+
isCounterExample && !isRebuiltFirst,
|
|
575
|
+
);
|
|
576
|
+
printTraceOutput(printer, violation.traceOutput);
|
|
577
|
+
}
|
|
578
|
+
if (isLasso) {
|
|
579
|
+
const label = violation.loopLabel;
|
|
580
|
+
if (loopStart === violation.trace.length - 1)
|
|
581
|
+
print(MESSAGE_CODE.statePrint3, MESSAGE_LEVEL.state, `${loopStart + 2}: Stuttering`);
|
|
582
|
+
else if (printer.isTool)
|
|
583
|
+
print(
|
|
584
|
+
MESSAGE_CODE.backToState,
|
|
585
|
+
MESSAGE_LEVEL.state,
|
|
586
|
+
`${loopStart + 1}: Back to state${label ? `: <${label}>\n` : ""}`,
|
|
587
|
+
);
|
|
588
|
+
else console.log(`Back to state ${loopStart + 1}${label ? `: <${label}>\n` : ""}`);
|
|
589
|
+
}
|
|
590
|
+
// TLC 1.7.4 doesn't explain a stuttering counterexample.
|
|
591
|
+
if (violation.warning && printer.version !== "1.7.4")
|
|
592
|
+
print(violation.warning.code, MESSAGE_LEVEL.warning, violation.warning.text);
|
|
593
|
+
// TLC checks the postconditions after it prints a counterexample.
|
|
594
|
+
const postcondition =
|
|
595
|
+
violation.unwitnessed ??
|
|
596
|
+
(status === "postcondition-violation" ? undefined : violation.postcondition);
|
|
597
|
+
if (postcondition?.counts) console.log(postcondition.counts);
|
|
598
|
+
if (postcondition) print(postcondition.code, MESSAGE_LEVEL.error, postcondition.message);
|
|
599
|
+
// TLC checks assumptions before it starts the search, so it has no statistics to print.
|
|
600
|
+
return !isInitial && status !== "assumption-violation";
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
const printNestedExpressions = (printer: MessagePrinter, callStack: Expression[]) =>
|
|
604
|
+
printer.print(
|
|
605
|
+
MESSAGE_CODE.nestedExpression,
|
|
606
|
+
MESSAGE_LEVEL.error,
|
|
607
|
+
`The error occurred when TLC was evaluating the nested\nexpressions at the following positions:\n${formatCallStack(callStack)}`,
|
|
608
|
+
);
|
|
609
|
+
|
|
610
|
+
const printResult = (result: CheckResult, printer: MessagePrinter, timing: Timing) => {
|
|
611
|
+
const print = printer.print;
|
|
612
|
+
if (result.failure) {
|
|
613
|
+
const failure = result.failure;
|
|
614
|
+
const message = printer.isTool ? failure.toolMessage : failure.message;
|
|
615
|
+
const printCallStack = () => {
|
|
616
|
+
const fingerprint = failure.fingerprint;
|
|
617
|
+
if (fingerprint) {
|
|
618
|
+
// TLC prints the call stack when the replay has one, and otherwise the sources of the
|
|
619
|
+
// values it failed to fingerprint, innermost first. TLC 1.7.4 always prints the sources.
|
|
620
|
+
const trace =
|
|
621
|
+
failure.callStack?.length && printer.version !== "1.7.4"
|
|
622
|
+
? formatCallStack(failure.callStack)
|
|
623
|
+
: formatFingerprintTrace(fingerprint.sources);
|
|
624
|
+
print(
|
|
625
|
+
MESSAGE_CODE.fingerprintFailed,
|
|
626
|
+
MESSAGE_LEVEL.error,
|
|
627
|
+
`TLC was unable to fingerprint.\n\nFingerprint Stack Trace:\n${trace}\nReason:\n${formatNestedMessage(fingerprint.reason, printer.isTool)}`,
|
|
628
|
+
);
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
if (failure.callStack) printNestedExpressions(printer, failure.callStack);
|
|
632
|
+
};
|
|
633
|
+
if (failure.isCallStackFirst) printCallStack();
|
|
634
|
+
// TLC prints the state as it reports the error, so a state it can't print fails outside the
|
|
635
|
+
// checker, which TLC reports as an exception it did not expect.
|
|
636
|
+
const initialState =
|
|
637
|
+
failure.initialState &&
|
|
638
|
+
(() => {
|
|
639
|
+
try {
|
|
640
|
+
return `While working on the initial state:\n${formatState(failure.initialState)}`;
|
|
641
|
+
} catch (error) {
|
|
642
|
+
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
643
|
+
throw setExitCode(
|
|
644
|
+
new TlaEvaluationError(`${UNEXPECTED_EXCEPTION}${error.message}`),
|
|
645
|
+
EXIT_STATUS.error,
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
})();
|
|
649
|
+
// TLC prints an error on an initial state and the state as one message.
|
|
650
|
+
print(
|
|
651
|
+
initialState ? MESSAGE_CODE.initialState : failure.code,
|
|
652
|
+
MESSAGE_LEVEL.error,
|
|
653
|
+
initialState ? `${message}\n${initialState}` : message,
|
|
654
|
+
);
|
|
655
|
+
printTraceOutput(printer, failure.trace[0]?.output);
|
|
656
|
+
printTrace(printer, failure.trace);
|
|
657
|
+
const traceFailure = failure.traceFailure;
|
|
658
|
+
if (traceFailure) {
|
|
659
|
+
print(
|
|
660
|
+
traceFailure.code,
|
|
661
|
+
MESSAGE_LEVEL.error,
|
|
662
|
+
printer.isTool ? traceFailure.toolMessage : traceFailure.message,
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
printTraceOutput(printer, failure.traceOutput);
|
|
666
|
+
const postcondition = failure.postcondition;
|
|
667
|
+
if (postcondition?.counts) console.log(postcondition.counts);
|
|
668
|
+
if (postcondition) print(postcondition.code, MESSAGE_LEVEL.error, postcondition.message);
|
|
669
|
+
if (!failure.isCallStackFirst) printCallStack();
|
|
670
|
+
} else if (result.violation) {
|
|
671
|
+
if (!printViolation(result.status, result.violation, printer)) return;
|
|
672
|
+
// TLC adds a deadlocked state to the behavior graph after it reports the deadlock, which can
|
|
673
|
+
// violate a temporal property too.
|
|
674
|
+
const additional = result.additionalViolation;
|
|
675
|
+
if (additional) printViolation("property-violation", additional, printer);
|
|
676
|
+
if (result.liveCallStack) printNestedExpressions(printer, result.liveCallStack);
|
|
170
677
|
} else {
|
|
678
|
+
printLivenessEnd(printer, timing);
|
|
171
679
|
const optimistic = getOptimisticProbability(result.distinctStates, result.generatedStates);
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
680
|
+
const actual =
|
|
681
|
+
result.fingerprintDistance === undefined
|
|
682
|
+
? []
|
|
683
|
+
: [
|
|
684
|
+
` based on the actual fingerprints: val = ${formatProbability(getActualProbability(result.fingerprintDistance))}`,
|
|
685
|
+
];
|
|
686
|
+
print(
|
|
687
|
+
MESSAGE_CODE.success,
|
|
688
|
+
MESSAGE_LEVEL.none,
|
|
689
|
+
[
|
|
690
|
+
"Model checking completed. No error has been found.",
|
|
691
|
+
" Estimates of the probability that TLC did not check all reachable states",
|
|
692
|
+
" because two distinct states had the same fingerprint:",
|
|
693
|
+
` calculated (optimistic): val = ${formatProbability(optimistic)}`,
|
|
694
|
+
...actual,
|
|
695
|
+
].join("\n"),
|
|
696
|
+
);
|
|
180
697
|
}
|
|
181
|
-
|
|
698
|
+
if (result.failure?.isWithoutStatistics) return;
|
|
699
|
+
if (result.status !== "success") printLivenessEnd(printer, timing);
|
|
700
|
+
if (printer.isTool) printProgress(printer, result, timing.start);
|
|
701
|
+
print(
|
|
702
|
+
MESSAGE_CODE.stats,
|
|
703
|
+
MESSAGE_LEVEL.none,
|
|
182
704
|
`${result.generatedStates} states generated, ${result.distinctStates} distinct states found, ${result.queuedStates} states left on queue.`,
|
|
183
705
|
);
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
706
|
+
// ModelChecker#printSummary prints the depth, which TLC 1.7.4 prints only after a search it
|
|
707
|
+
// reports as successful, and as at least 1, and then the outdegree of a successful search.
|
|
708
|
+
const is174 = printer.version === "1.7.4";
|
|
709
|
+
const outDegrees = is174 ? (result.outDegrees ?? result.violationOutDegrees) : result.outDegrees;
|
|
710
|
+
if (!is174 || outDegrees) {
|
|
711
|
+
print(
|
|
712
|
+
MESSAGE_CODE.searchDepth,
|
|
713
|
+
MESSAGE_LEVEL.none,
|
|
714
|
+
`The depth of the complete state graph search is ${is174 ? Math.max(result.depth, 1) : result.depth}.`,
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
const outDegree = outDegrees && getOutDegreeSummary(outDegrees);
|
|
718
|
+
if (outDegree) print(MESSAGE_CODE.stateGraphOutdegree, MESSAGE_LEVEL.none, outDegree);
|
|
187
719
|
};
|
|
188
720
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
721
|
+
// Like TLC, tla-ts finds a module in the directory of the spec, then in each library directory.
|
|
722
|
+
const findModuleFile = (directories: string[], name: string) =>
|
|
723
|
+
directories.map((directory) => join(directory, `${name}.tla`)).find(existsSync);
|
|
724
|
+
|
|
725
|
+
const createModuleLoader = (directories: string[]) => (name: string) => {
|
|
726
|
+
const path = findModuleFile(directories, name);
|
|
727
|
+
return path === undefined ? undefined : readFileSync(path, "utf8");
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
// SimpleFilenameToStream: SANY names the file of a module it can't find, and where it looked.
|
|
731
|
+
const printMissingFile = (userDirectory: string, fileName: string, directories: string[]) =>
|
|
732
|
+
console.error(
|
|
733
|
+
`File does not exist: ${userDirectory}/${fileName} while looking in these directories: ${userDirectory}, ${directories.join(", ")}, classpath:/tla2sany/StandardModules, classpath:/`,
|
|
734
|
+
);
|
|
735
|
+
|
|
736
|
+
// The URL of the directory of SANY's standard modules in a tla2tools.jar.
|
|
737
|
+
const getStandardModulesUrl = (jar: string) =>
|
|
738
|
+
`jar:file:${pathToFileURL(resolve(jar)).pathname}!/tla2sany/StandardModules/`;
|
|
739
|
+
|
|
740
|
+
// Java's Files.createTempDirectory names a directory by a random unsigned long. tla-ts derives it
|
|
741
|
+
// from TLC's fingerprint of what the directory holds, so that each run of a spec prints the same
|
|
742
|
+
// files.
|
|
743
|
+
const getTemporaryName = (contents: string) => getTlcFingerprint([contents]).toString();
|
|
744
|
+
|
|
745
|
+
// The file TLC's SANY says it parses each module from: the real path of a module's own file, or a
|
|
746
|
+
// copy in a temporary directory of a module from the root module's file or from the jar on the
|
|
747
|
+
// class path, followed by where TLC copied it from.
|
|
748
|
+
const createFileDescriber = (
|
|
749
|
+
specPath: string,
|
|
750
|
+
directories: string[],
|
|
751
|
+
java: JavaProperties,
|
|
752
|
+
metadir: string | undefined,
|
|
753
|
+
version: TlcVersion,
|
|
754
|
+
) => {
|
|
755
|
+
const temporary = java.temporaryDirectory ?? tmpdir();
|
|
756
|
+
const temporaryDirectory = existsSync(temporary) ? realpathSync(temporary) : resolve(temporary);
|
|
757
|
+
const libraryDirectory = join(temporaryDirectory, `tlc-${getTemporaryName(resolve(specPath))}`);
|
|
758
|
+
const jar = getJar(java);
|
|
759
|
+
return (name: string, origin: SanyModuleOrigin) => {
|
|
760
|
+
const fileName = `${name}.tla`;
|
|
761
|
+
if (origin === "file") return realpathSync(findModuleFile(directories, name) ?? specPath);
|
|
762
|
+
// TLC 1.7.4 copies a standard module into the temporary directory itself.
|
|
763
|
+
if (version === "1.7.4") return join(temporaryDirectory, fileName);
|
|
764
|
+
// FileUtil.createTempFile copies a module from the root module's file into the -metadir.
|
|
765
|
+
if (origin === "root file") {
|
|
766
|
+
const directory = metadir === undefined ? temporaryDirectory : resolve(metadir);
|
|
767
|
+
const root = realpathSync(specPath);
|
|
768
|
+
return `${join(directory, getTemporaryName(`${root} ${name}`), fileName)} (${root})`;
|
|
769
|
+
}
|
|
770
|
+
const copy = join(libraryDirectory, fileName);
|
|
771
|
+
return jar === undefined ? copy : `${copy} (${getStandardModulesUrl(jar)}${fileName})`;
|
|
772
|
+
};
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
const printWelcome = (printer: MessagePrinter) =>
|
|
776
|
+
printer.print(MESSAGE_CODE.version, MESSAGE_LEVEL.none, `TLC2 Version ${version} (rev: tla-ts)`);
|
|
777
|
+
|
|
778
|
+
// TLC.printErrorMsg: TLC says which version it is, then why it can't read its options.
|
|
779
|
+
const printCommandLineError = (printer: MessagePrinter, message: string) => {
|
|
780
|
+
printWelcome(printer);
|
|
781
|
+
printer.print(
|
|
782
|
+
MESSAGE_CODE.commandLineError,
|
|
783
|
+
MESSAGE_LEVEL.error,
|
|
784
|
+
`${message}\nUsage: java tlc2.TLC [-help] [-option] inputfile`,
|
|
785
|
+
);
|
|
786
|
+
return 1;
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
// TLC.printStartupBanner, with what runs tla-ts in place of the JVM. tla-ts keeps its fingerprints
|
|
790
|
+
// and its queue of states in memory.
|
|
791
|
+
const printStartupBanner = (printer: MessagePrinter, seed: string, workers: number) =>
|
|
792
|
+
printer.print(
|
|
793
|
+
MESSAGE_CODE.modelChecking,
|
|
794
|
+
MESSAGE_LEVEL.none,
|
|
795
|
+
`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).`,
|
|
796
|
+
);
|
|
797
|
+
|
|
798
|
+
// TLC loads Integers for the binary trace that its trace exploration spec records. -generateSpecTE
|
|
799
|
+
// turns the spec on, and -tool, -continue, -noGenerateSpecTE and -noTE turn it off, as
|
|
800
|
+
// -noGenerateSpecTEBin and -noTEBin turn off the binary trace. TLC 1.7.4 records no such trace.
|
|
801
|
+
const isTraceRecorded = (args: ParsedArgs, version: TlcVersion) => {
|
|
802
|
+
const flags = [...args.unknown, ...args.options.map((option) => option.name)];
|
|
803
|
+
const has = (name: string, alias = name) =>
|
|
804
|
+
flags.some((flag) => flag === name || flag.toLowerCase() === alias.toLowerCase());
|
|
805
|
+
const isSpecGenerated =
|
|
806
|
+
has("-generateSpecTE") ||
|
|
807
|
+
(!has("-noGenerateSpecTE", "-noTE") && !has("-tool") && !has("-continue"));
|
|
808
|
+
return version !== "1.7.4" && isSpecGenerated && !has("-noGenerateSpecTEBin", "-noTEBin");
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
const checkSpec = async (
|
|
812
|
+
specPath: string,
|
|
813
|
+
args: ParsedArgs,
|
|
814
|
+
java: JavaProperties,
|
|
815
|
+
printer: MessagePrinter,
|
|
816
|
+
) => {
|
|
817
|
+
// TLC.handleParameters: TLC reads its options before it says which version it is.
|
|
818
|
+
const seed = args.has("-seed") ? args.get("-seed")?.[0] : "0";
|
|
819
|
+
if (seed === undefined) return printCommandLineError(printer, "Error: seed required.");
|
|
820
|
+
if (!isJavaLong(seed)) {
|
|
821
|
+
return printCommandLineError(
|
|
822
|
+
printer,
|
|
823
|
+
`Error: An integer for seed required. But encountered ${seed}`,
|
|
824
|
+
);
|
|
825
|
+
}
|
|
826
|
+
const livenessCheck = args.has("-lncheck") ? args.get("-lncheck")?.[0]?.toLowerCase() : "default";
|
|
827
|
+
if (livenessCheck === undefined) {
|
|
828
|
+
return printCommandLineError(
|
|
829
|
+
printer,
|
|
830
|
+
"Error: expect a strategy such as final for -lncheck option.",
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
const dumpValues = args.get("-dump");
|
|
834
|
+
if (dumpValues?.length === 0) {
|
|
835
|
+
return printCommandLineError(printer, "Error: A file name for dumping states required.");
|
|
836
|
+
}
|
|
837
|
+
const unsupportedFormat =
|
|
838
|
+
dumpValues?.length === 2 &&
|
|
839
|
+
UNSUPPORTED_DUMP_FORMATS.find((format) => dumpValues[0].toLowerCase().includes(format));
|
|
840
|
+
if (unsupportedFormat) {
|
|
841
|
+
console.error(`Error: tla-ts does not support the -dump format ${unsupportedFormat}.`);
|
|
842
|
+
return 1;
|
|
843
|
+
}
|
|
844
|
+
// tla-ts fingerprints states as TLC does with -fp 0.
|
|
845
|
+
const fingerprint = args.get("-fp")?.[0];
|
|
846
|
+
if (fingerprint !== undefined && Number(fingerprint) !== 0) {
|
|
847
|
+
console.error(
|
|
848
|
+
`Error: tla-ts fingerprints states as TLC does with -fp 0, not -fp ${fingerprint}.`,
|
|
849
|
+
);
|
|
850
|
+
return 1;
|
|
193
851
|
}
|
|
852
|
+
const workers = getWorkerCount(args.get("-workers"));
|
|
853
|
+
const version = printer.version;
|
|
854
|
+
printWelcome(printer);
|
|
855
|
+
printStartupBanner(printer, seed, workers);
|
|
194
856
|
const configPath =
|
|
195
857
|
args.get("-config")?.[0] ??
|
|
196
858
|
(args.has("-config") ? undefined : specPath.replace(/\.tla$/, ".cfg"));
|
|
197
859
|
if (!configPath || !existsSync(configPath)) {
|
|
198
|
-
|
|
860
|
+
printer.print(
|
|
861
|
+
MESSAGE_CODE.configFileError,
|
|
862
|
+
MESSAGE_LEVEL.error,
|
|
863
|
+
`TLC encountered the following error when trying to read the configuration file ${configPath ?? ""}:\nFile not found.`,
|
|
864
|
+
);
|
|
199
865
|
return EXIT_STATUS.configParseError;
|
|
200
866
|
}
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
867
|
+
const fileName = basename(specPath, ".tla");
|
|
868
|
+
const timing: Timing = { start: Date.now(), liveness: undefined, isParsed: false };
|
|
869
|
+
// Without -tool, TLC prints how long it ran for a person to read.
|
|
870
|
+
const printFinished = () => {
|
|
871
|
+
const runtime = Date.now() - timing.start;
|
|
872
|
+
printer.print(
|
|
873
|
+
MESSAGE_CODE.finished,
|
|
874
|
+
MESSAGE_LEVEL.none,
|
|
875
|
+
`Finished in ${printer.isTool ? `${runtime}ms` : formatTlcDuration(runtime)} at (${formatTlcDate(new Date())})`,
|
|
876
|
+
);
|
|
877
|
+
};
|
|
878
|
+
const printParsingFailed = () =>
|
|
879
|
+
printer.print(
|
|
880
|
+
MESSAGE_CODE.parsingFailed,
|
|
881
|
+
MESSAGE_LEVEL.error,
|
|
882
|
+
"Parsing or semantic analysis failed.",
|
|
883
|
+
);
|
|
884
|
+
// TLC prints how long it ran even when it stops at an error.
|
|
885
|
+
const printFailure = (error: TlaError) => {
|
|
886
|
+
if (error instanceof TlaSyntaxError) {
|
|
887
|
+
printParsingFailed();
|
|
888
|
+
} else {
|
|
889
|
+
printError(error, printer);
|
|
890
|
+
}
|
|
891
|
+
printFinished();
|
|
892
|
+
return getErrorExitCode(error);
|
|
893
|
+
};
|
|
894
|
+
// TLC reads the configuration file before it parses the spec, and prints how long it ran even
|
|
895
|
+
// when it can't read it.
|
|
896
|
+
const config = (() => {
|
|
897
|
+
try {
|
|
898
|
+
return parseConfig(readFileSync(configPath, "utf8"), version);
|
|
899
|
+
} catch (error) {
|
|
900
|
+
if (!(error instanceof TlaConfigError)) throw error;
|
|
901
|
+
return error;
|
|
902
|
+
}
|
|
903
|
+
})();
|
|
904
|
+
// TLC 1.7.4 reports a configuration file it can't parse as an exception it didn't expect.
|
|
905
|
+
if (config instanceof TlaConfigError && version === "1.7.4") {
|
|
906
|
+
printer.print(
|
|
907
|
+
MESSAGE_CODE.general,
|
|
908
|
+
MESSAGE_LEVEL.error,
|
|
909
|
+
`${getUnexpectedException("tlc2.tool.ConfigFileException")}${formatNestedMessage(config.message, printer.isTool)}`,
|
|
910
|
+
);
|
|
911
|
+
printFinished();
|
|
912
|
+
return EXIT_STATUS.error;
|
|
207
913
|
}
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
|
|
914
|
+
if (config instanceof TlaConfigError) return printFailure(config);
|
|
915
|
+
if (args.has("-deadlock")) config.checkDeadlock = false;
|
|
916
|
+
const directory = dirname(specPath);
|
|
917
|
+
const directories = [directory, ...java.libraries];
|
|
918
|
+
const loadModule = createModuleLoader(directories);
|
|
919
|
+
const isRecorded = isTraceRecorded(args, version);
|
|
920
|
+
const run = async () => {
|
|
921
|
+
const source = readFileSync(specPath, "utf8");
|
|
922
|
+
const moduleName = parseModule(source).name;
|
|
923
|
+
if (moduleName !== fileName) {
|
|
924
|
+
throw new TlaSanyFatalError(
|
|
925
|
+
`File name '${fileName}' does not match the name '${moduleName}' of the top level module it contains.`,
|
|
926
|
+
undefined,
|
|
927
|
+
);
|
|
928
|
+
}
|
|
929
|
+
const result = await check({
|
|
930
|
+
workers,
|
|
931
|
+
livenessCheck: ["final", "seqfinal", "off"].includes(livenessCheck) ? "final" : "default",
|
|
932
|
+
seed: BigInt(seed),
|
|
933
|
+
dump: dumpValues && getDump(dumpValues),
|
|
934
|
+
isTool: printer.isTool,
|
|
935
|
+
isTraceRecorded: isRecorded,
|
|
936
|
+
isSanyReported: true,
|
|
937
|
+
isWarningEnabled: !args.has("-nowarning"),
|
|
938
|
+
version,
|
|
939
|
+
onProgress: (progress) => printCheckProgress(printer, progress, timing, directory),
|
|
940
|
+
source,
|
|
941
|
+
config,
|
|
942
|
+
onPause: () => readSync(0, Buffer.alloc(1)),
|
|
943
|
+
loadModule,
|
|
944
|
+
loadClass: (name) => {
|
|
945
|
+
const classPath = getClassPath(directory, name);
|
|
946
|
+
return existsSync(classPath) ? readFileSync(classPath) : undefined;
|
|
947
|
+
},
|
|
948
|
+
readFile: (path) => (existsSync(path) ? readFileSync(path, "utf8") : undefined),
|
|
949
|
+
writeFile: (path, content) => {
|
|
950
|
+
mkdirSync(dirname(resolve(path)), { recursive: true });
|
|
951
|
+
writeFileSync(path, content);
|
|
952
|
+
},
|
|
953
|
+
});
|
|
954
|
+
printResult(result, printer, timing);
|
|
955
|
+
printFinished();
|
|
956
|
+
return result.failure?.exitCode ?? EXIT_CODES[result.status];
|
|
957
|
+
};
|
|
958
|
+
if (printer.isTool) {
|
|
959
|
+
printer.print(MESSAGE_CODE.startingSany, MESSAGE_LEVEL.none, "Starting SANY...");
|
|
211
960
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
961
|
+
// TLC.handleParameters: SANY names the spec as TLC's arguments do, except that TLC runs from the
|
|
962
|
+
// directory of a spec given by an absolute path, and names it by its file name. SANY looks for
|
|
963
|
+
// the spec's modules in the spec's directory and the TLA-Library directories.
|
|
964
|
+
const isAbsoluteSpec = isAbsolute(specPath);
|
|
965
|
+
const specName = isAbsoluteSpec ? fileName : specPath.replace(/\.tla$/, "");
|
|
966
|
+
const jar = getJar(java);
|
|
967
|
+
const reportMissingFile =
|
|
968
|
+
version === "1.7.4" ? createMissingFilePrinter174(specPath, java, jar) : undefined;
|
|
969
|
+
if (reportMissingFile) {
|
|
970
|
+
if (!existsSync(specPath) && !SANY_174_STANDARD_MODULES.has(fileName)) {
|
|
971
|
+
reportMissingFile(`${fileName}.tla`);
|
|
972
|
+
}
|
|
973
|
+
} else if (!existsSync(specPath) && !SANY_STANDARD_MODULES.has(fileName)) {
|
|
974
|
+
printMissingFile(
|
|
975
|
+
isAbsoluteSpec ? directory : process.cwd(),
|
|
976
|
+
isAbsoluteSpec ? `${fileName}.tla` : `./${specName}.tla`,
|
|
977
|
+
[...(isAbsoluteSpec || directory === "." ? [] : [directory]), ...java.libraries],
|
|
978
|
+
);
|
|
216
979
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
980
|
+
// TLC prints what SANY prints as it parses the spec, and the errors it rejects the spec for.
|
|
981
|
+
const sany = getSanyReport(
|
|
982
|
+
specPath,
|
|
983
|
+
reportMissingFile ? reportMissingModules174(loadModule, reportMissingFile) : loadModule,
|
|
984
|
+
{
|
|
985
|
+
fileName: specName,
|
|
986
|
+
describeFile: createFileDescriber(
|
|
987
|
+
specPath,
|
|
988
|
+
directories,
|
|
989
|
+
java,
|
|
990
|
+
args.get("-metadir")?.[0],
|
|
991
|
+
version,
|
|
992
|
+
),
|
|
993
|
+
version,
|
|
994
|
+
// TLC's trace exploration spec records the trace with the post condition of _TLCTrace.
|
|
995
|
+
rootExtendees: isRecorded ? ["_TLCTrace"] : undefined,
|
|
996
|
+
onPrint: (text) => process.stdout.write(text),
|
|
997
|
+
onPrintError: (text) => process.stderr.write(text),
|
|
229
998
|
},
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
|
|
999
|
+
);
|
|
1000
|
+
if (sany.isFailed) {
|
|
1001
|
+
printCheckProgress(printer, { kind: "parsed" }, timing, directory);
|
|
1002
|
+
printParsingFailed();
|
|
1003
|
+
printFinished();
|
|
1004
|
+
return EXIT_STATUS.specParseError;
|
|
1005
|
+
}
|
|
1006
|
+
try {
|
|
1007
|
+
return await run();
|
|
1008
|
+
} catch (error) {
|
|
1009
|
+
if (!(error instanceof TlaError)) throw error;
|
|
1010
|
+
if (error instanceof TlaSyntaxError) console.log(formatSanyErrors(error, fileName));
|
|
1011
|
+
if (!timing.isParsed) printCheckProgress(printer, { kind: "parsed" }, timing, directory);
|
|
1012
|
+
return printFailure(error);
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
1015
|
+
|
|
1016
|
+
// What SANY prints about a spec it rejects: a module it can't find or parse is a fatal error, and
|
|
1017
|
+
// it reports the other errors as semantic errors.
|
|
1018
|
+
const formatSanyErrors = (error: TlaSyntaxError, specName: string) => {
|
|
1019
|
+
const isFatal = error instanceof TlaSanyFatalError;
|
|
1020
|
+
if (!isFatal && !error.failure)
|
|
1021
|
+
return `Semantic errors:\n\n*** Errors: 1\n\n${error.message}\n\n`;
|
|
1022
|
+
const report = !isFatal
|
|
1023
|
+
? `In module ${specName}\n\nCould not parse module ${specName} from file ${specName}.tla`
|
|
1024
|
+
: error.location === undefined
|
|
1025
|
+
? `Unknown location\n\n${error.message}`
|
|
1026
|
+
: `In module ${error.location}\n\n${error.message}`;
|
|
1027
|
+
const parseError = error.failure ? `***Parse Error***\n${error.message}\n\n` : "";
|
|
1028
|
+
return `${parseError}\nFatal errors while parsing TLA+ spec in file ${specName}\n\n${report}\n*** Errors: 1\n\n${report}\n\n\n`;
|
|
242
1029
|
};
|
|
243
1030
|
|
|
244
1031
|
// TLC prints the errors it raises itself. tla-ts names the others, such as a module SANY rejects.
|
|
245
|
-
const printError = (error: TlaError) => {
|
|
1032
|
+
const printError = (error: TlaError, printer: MessagePrinter) => {
|
|
246
1033
|
if (error instanceof TlaConfigError || error instanceof TlaEvaluationError) {
|
|
247
|
-
|
|
1034
|
+
// TLC prints an error it raises with a message code, such as a configuration error, with
|
|
1035
|
+
// that code.
|
|
1036
|
+
const coded = getCodedMessage(error.message);
|
|
1037
|
+
const code = coded && !coded.isEvalException ? coded.code : MESSAGE_CODE.general;
|
|
1038
|
+
return printer.print(
|
|
1039
|
+
code,
|
|
1040
|
+
MESSAGE_LEVEL.error,
|
|
1041
|
+
formatInnerMessage(code, error.message, printer.isTool),
|
|
1042
|
+
);
|
|
248
1043
|
}
|
|
249
1044
|
console.error(`${error.name}: ${error.message}`);
|
|
250
1045
|
};
|
|
251
1046
|
|
|
252
1047
|
// Prints a TlaError and returns its exit code.
|
|
253
|
-
const reportErrors = async (
|
|
1048
|
+
const reportErrors = async (
|
|
1049
|
+
run: () => number | Promise<number>,
|
|
1050
|
+
printer = createMessagePrinter(false),
|
|
1051
|
+
) => {
|
|
254
1052
|
try {
|
|
255
1053
|
return await run();
|
|
256
1054
|
} catch (error) {
|
|
257
1055
|
if (!(error instanceof TlaError)) throw error;
|
|
258
|
-
printError(error);
|
|
1056
|
+
printError(error, printer);
|
|
259
1057
|
return getErrorExitCode(error);
|
|
260
1058
|
}
|
|
261
1059
|
};
|
|
262
1060
|
|
|
263
|
-
// Runs each path in turn,
|
|
264
|
-
// first that is not success.
|
|
265
|
-
const runEach = async (
|
|
1061
|
+
// Runs each path in turn, as TLC runs in a process of its own, so an error in one leaves the others
|
|
1062
|
+
// to report. The exit code is the first that is not success.
|
|
1063
|
+
const runEach = async (
|
|
1064
|
+
paths: string[],
|
|
1065
|
+
runPath: (path: string, printer: MessagePrinter) => number | Promise<number>,
|
|
1066
|
+
createPrinter: () => MessagePrinter,
|
|
1067
|
+
) => {
|
|
266
1068
|
const exitCodes: number[] = [];
|
|
267
1069
|
for (const [index, path] of paths.entries()) {
|
|
268
1070
|
if (index > 0) console.log("");
|
|
269
|
-
|
|
1071
|
+
const printer = createPrinter();
|
|
1072
|
+
exitCodes.push(await reportErrors(() => runPath(path, printer), printer));
|
|
270
1073
|
}
|
|
271
1074
|
return exitCodes.find((exitCode) => exitCode !== EXIT_STATUS.success) ?? EXIT_STATUS.success;
|
|
272
1075
|
};
|
|
273
1076
|
|
|
274
|
-
// tlapm
|
|
275
|
-
// bin/tlapm.
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
.map((directory) => join(directory, "tlapm"))
|
|
280
|
-
.filter((path) => existsSync(path));
|
|
281
|
-
|
|
282
|
-
const getTlapmLibrary = () =>
|
|
283
|
-
getTlapmPaths()
|
|
1077
|
+
// tlapm searches the current directory, then its standard library at lib/tlapm/stdlib beside
|
|
1078
|
+
// bin/tlapm, then each -I directory, the last given first.
|
|
1079
|
+
const getLibraryDirectories = (parsed: ParsedArgs) => [
|
|
1080
|
+
".",
|
|
1081
|
+
...getTlapmPaths()
|
|
284
1082
|
.map((path) => join(dirname(dirname(realpathSync(path))), "lib/tlapm/stdlib"))
|
|
285
|
-
.
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const proveWithTlapm = (args: string[]) => {
|
|
291
|
-
const tlapm = getTlapmPaths()[0];
|
|
292
|
-
if (tlapm === undefined) {
|
|
293
|
-
console.error(
|
|
294
|
-
"Error: tla-ts prove runs tlapm to prove obligations, but tlapm isn't on your PATH. Install tlapm, or pass -N to only generate the obligations.",
|
|
295
|
-
);
|
|
296
|
-
return 1;
|
|
297
|
-
}
|
|
298
|
-
return spawnSync(tlapm, expandGlobs(args), { stdio: "inherit" }).status ?? 1;
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
const readModule = (path: string) =>
|
|
302
|
-
existsSync(path) ? { file: path, source: readFileSync(path, "utf8") } : undefined;
|
|
1083
|
+
.filter((path) => existsSync(path))
|
|
1084
|
+
.slice(0, 1),
|
|
1085
|
+
...parsed.options.flatMap((option) => (option.name === "-I" ? option.values : [])).toReversed(),
|
|
1086
|
+
];
|
|
303
1087
|
|
|
304
1088
|
// A message of tlapm's toolbox protocol, which it writes to stderr.
|
|
305
1089
|
const printToolboxMessage = (fields: string[]) =>
|
|
306
1090
|
console.error(`@!!BEGIN\n${fields.map((field) => `@!!${field}\n`).join("")}@!!END\n`);
|
|
307
1091
|
|
|
308
|
-
const
|
|
1092
|
+
const printObligationMessage = (obligation: PrintedObligation, status: string, fields: string[]) =>
|
|
1093
|
+
printToolboxMessage([
|
|
1094
|
+
"type:obligation",
|
|
1095
|
+
`id:${obligation.id}`,
|
|
1096
|
+
`loc:${obligation.location}`,
|
|
1097
|
+
`status:${status}`,
|
|
1098
|
+
...fields,
|
|
1099
|
+
]);
|
|
1100
|
+
|
|
1101
|
+
const TLAPM_VERSION = "9ed0376";
|
|
309
1102
|
|
|
310
1103
|
const quoteArgument = (arg: string) =>
|
|
311
1104
|
/^[+,\-./0-9:=@A-Z_a-z]+$/.test(arg) ? arg : `'${arg.replaceAll("'", "'\\''")}'`;
|
|
312
1105
|
|
|
313
|
-
const printToolboxHeader = (args: string[]) =>
|
|
314
|
-
const now = new Date();
|
|
315
|
-
const pad = (value: number) => String(value).padStart(2, "0");
|
|
316
|
-
const date = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
|
|
317
|
-
const time = `${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`;
|
|
1106
|
+
const printToolboxHeader = (args: string[]) =>
|
|
318
1107
|
console.log(
|
|
319
|
-
`\n\\* TLAPM version ${TLAPM_VERSION}\n\\* launched at ${
|
|
1108
|
+
`\n\\* TLAPM version ${TLAPM_VERSION}\n\\* launched at ${formatTlcDate(new Date())} with command line:\n\\* ${["tla-ts", "tlapm", ...args].map(quoteArgument).join(" ")}\n`,
|
|
320
1109
|
);
|
|
321
|
-
};
|
|
322
1110
|
|
|
323
|
-
|
|
1111
|
+
// The most severe first.
|
|
1112
|
+
const STRICT_EXIT_STATUS = { failed: 10, incomplete: 11, emptyTarget: 12 };
|
|
324
1113
|
|
|
325
1114
|
const checkStrictly = (result: ModuleObligations, isTargeted: boolean, isSummary: boolean) => {
|
|
326
1115
|
const summary = result.summary;
|
|
@@ -348,6 +1137,17 @@ const checkStrictly = (result: ModuleObligations, isTargeted: boolean, isSummary
|
|
|
348
1137
|
|
|
349
1138
|
const TLAPM_FAILURE_STATUS = 3;
|
|
350
1139
|
|
|
1140
|
+
const UNPROVED_ENDING = [
|
|
1141
|
+
' tlapm ending abnormally with Failure("backend errors: there are unproved obligations")',
|
|
1142
|
+
'Raised at Stdlib.failwith in file "stdlib.ml", line 29, characters 17-33',
|
|
1143
|
+
'Called from Tlapm_lib.process_module in file "src/tlapm_lib.ml", lines 492-493, characters 12-37',
|
|
1144
|
+
'Called from Tlapm_lib.main.f in file "src/tlapm_lib.ml", line 640, characters 23-43',
|
|
1145
|
+
'Called from Stdlib__List.fold_left in file "list.ml", line 125, characters 24-34',
|
|
1146
|
+
'Called from Tlapm_lib.main in file "src/tlapm_lib.ml", line 643, characters 13-40',
|
|
1147
|
+
'Called from Tlapm_lib.init in file "src/tlapm_lib.ml", line 659, characters 8-59',
|
|
1148
|
+
"",
|
|
1149
|
+
].join("\n");
|
|
1150
|
+
|
|
351
1151
|
const generateObligations = (generate: () => ModuleObligations[]) => {
|
|
352
1152
|
try {
|
|
353
1153
|
return generate();
|
|
@@ -358,12 +1158,114 @@ const generateObligations = (generate: () => ModuleObligations[]) => {
|
|
|
358
1158
|
}
|
|
359
1159
|
};
|
|
360
1160
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
const
|
|
364
|
-
const
|
|
1161
|
+
// Toolbox.print_res_aux.
|
|
1162
|
+
const printAttempt = (obligation: PrintedObligation, attempt: ProofAttempt) => {
|
|
1163
|
+
const limit = attempt.method.timeLimitMs;
|
|
1164
|
+
const used =
|
|
1165
|
+
attempt.timeUsedMs === undefined
|
|
1166
|
+
? ""
|
|
1167
|
+
: `; time-used: ${(attempt.timeUsedMs / 1000).toFixed(1)} (${Math.round((100 * attempt.timeUsedMs) / limit)}%)`;
|
|
1168
|
+
const times =
|
|
1169
|
+
limit === 0
|
|
1170
|
+
? ""
|
|
1171
|
+
: `time-limit: ${limit === Infinity ? "inf" : Number((limit / 1000).toPrecision(6))}${used}`;
|
|
1172
|
+
const method = [attempt.method.tactic, times].filter(Boolean).join("; ");
|
|
1173
|
+
const isSmt = attempt.method.prover === "smt" || attempt.method.prover === "z3";
|
|
1174
|
+
const note =
|
|
1175
|
+
isSmt && attempt.reason === "false" && attempt.verdict
|
|
1176
|
+
? `(* SMT failed with status = ${attempt.verdict}\n *)\n`
|
|
1177
|
+
: "";
|
|
1178
|
+
printObligationMessage(obligation, attempt.isProved ? "proved" : "failed", [
|
|
1179
|
+
`prover:${attempt.method.prover}`,
|
|
1180
|
+
...(method === "" ? [] : [`meth:${method}`]),
|
|
1181
|
+
...(attempt.reason === undefined ? [] : [`reason:${attempt.reason}`]),
|
|
1182
|
+
`already:${attempt.isReused}`,
|
|
1183
|
+
...(attempt.isProved
|
|
1184
|
+
? []
|
|
1185
|
+
: [
|
|
1186
|
+
`obl:${attempt.isReused ? "" : `\n${note}`}${formatNormalized(obligation, attempt.isReused)}`,
|
|
1187
|
+
]),
|
|
1188
|
+
]);
|
|
1189
|
+
};
|
|
1190
|
+
|
|
1191
|
+
// Method.Fail, for an error obligation or one no method was tried on.
|
|
1192
|
+
const printFailure = (obligation: PrintedObligation, reason: string) =>
|
|
1193
|
+
printObligationMessage(obligation, "failed", [
|
|
1194
|
+
"prover:fail",
|
|
1195
|
+
"meth:time-limit: inf",
|
|
1196
|
+
`reason:${reason}`,
|
|
1197
|
+
"already:false",
|
|
1198
|
+
`obl:${obligation.text}`,
|
|
1199
|
+
]);
|
|
1200
|
+
|
|
1201
|
+
interface ProvingSettings {
|
|
1202
|
+
isToolbox: boolean;
|
|
1203
|
+
isProving: boolean;
|
|
1204
|
+
workers: number;
|
|
1205
|
+
isFingerprinted: (obligation: PrintedObligation) => boolean;
|
|
1206
|
+
fingerprints: FingerprintTable;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
// Tlapm_lib.process_obs. Returns whether some obligation failed.
|
|
1210
|
+
const proveModule = async (
|
|
1211
|
+
result: ModuleObligations,
|
|
1212
|
+
theoryPath: string,
|
|
1213
|
+
fingerprintsPath: string,
|
|
1214
|
+
settings: ProvingSettings,
|
|
1215
|
+
) => {
|
|
1216
|
+
const known = getKnownResults(settings.fingerprints);
|
|
1217
|
+
const reports = await proveObligations(result.obligations, {
|
|
1218
|
+
workers: settings.workers,
|
|
1219
|
+
results: known.results,
|
|
1220
|
+
isFingerprinted: settings.isFingerprinted,
|
|
1221
|
+
isProving: settings.isProving,
|
|
1222
|
+
onReport: (report, obligation) => {
|
|
1223
|
+
if (!settings.isToolbox) return;
|
|
1224
|
+
if (report.obligation.status === "trivial")
|
|
1225
|
+
return printObligationMessage(obligation, "trivial", ["prover:tlapm", "already:false"]);
|
|
1226
|
+
if (obligation.kind.kind === "Error") return printFailure(obligation, "user error");
|
|
1227
|
+
report.attempts.forEach((attempt) => printAttempt(obligation, attempt));
|
|
1228
|
+
},
|
|
1229
|
+
});
|
|
1230
|
+
writeFileSync(theoryPath, encodeProofTheory(result.name, reports, result.obligations));
|
|
1231
|
+
console.log(`(* created new ${JSON.stringify(theoryPath)} *)`);
|
|
1232
|
+
known.save(fingerprintsPath);
|
|
1233
|
+
console.log(`(* fingerprints written in ${JSON.stringify(fingerprintsPath)} *)`);
|
|
1234
|
+
if (!settings.isProving) return false;
|
|
1235
|
+
const unproved = reports.flatMap((report, index) =>
|
|
1236
|
+
"reason" in report.obligation ? [{ report, obligation: result.obligations[index] }] : [],
|
|
1237
|
+
);
|
|
1238
|
+
if (settings.isToolbox) {
|
|
1239
|
+
unproved
|
|
1240
|
+
.filter(
|
|
1241
|
+
(entry) => entry.report.attempts.length === 0 && entry.obligation.kind.kind !== "Error",
|
|
1242
|
+
)
|
|
1243
|
+
.forEach((entry) => printFailure(entry.obligation, "unexpected error"));
|
|
1244
|
+
}
|
|
1245
|
+
unproved
|
|
1246
|
+
.toReversed()
|
|
1247
|
+
.forEach((entry) =>
|
|
1248
|
+
console.error(
|
|
1249
|
+
`${getAtPrefix(entry.obligation.locus)}${renderDoc(format("[ERROR]: @[<v2>Could not prove or check:@,%a@]", printSequent(entry.obligation.sequent)), 35)}`,
|
|
1250
|
+
),
|
|
1251
|
+
);
|
|
1252
|
+
const total = `${result.obligations.length} obligation${result.obligations.length > 1 ? "s" : ""}`;
|
|
1253
|
+
console.error(
|
|
1254
|
+
unproved.length === 0
|
|
1255
|
+
? `${getAtPrefix(result.location)}[INFO]: All ${total} proved.`
|
|
1256
|
+
: `${getAtPrefix(result.location)}[ERROR]: ${unproved.length}/${total} failed.\nThere were backend errors processing module \`${JSON.stringify(result.name)}\`.`,
|
|
1257
|
+
);
|
|
1258
|
+
return unproved.length > 0;
|
|
1259
|
+
};
|
|
1260
|
+
|
|
1261
|
+
const runTlapm = async (args: string[]) => {
|
|
1262
|
+
const parsed = TLAPM_COMMAND.parse(args);
|
|
1263
|
+
const isProcessing = !parsed.has("-N") && !parsed.has("--summary");
|
|
1264
|
+
const unsupported =
|
|
1265
|
+
parsed.unknown[0] ??
|
|
1266
|
+
(isProcessing && parsed.has("--printallobs") ? "--printallobs" : undefined);
|
|
365
1267
|
if (unsupported !== undefined) {
|
|
366
|
-
console.error(`Error: tla-ts
|
|
1268
|
+
console.error(`Error: tla-ts tlapm does not support the tlapm option ${unsupported}.`);
|
|
367
1269
|
return 1;
|
|
368
1270
|
}
|
|
369
1271
|
if (parsed.incomplete) {
|
|
@@ -371,13 +1273,19 @@ const prove = (args: string[]) => {
|
|
|
371
1273
|
return 1;
|
|
372
1274
|
}
|
|
373
1275
|
const nonInteger = parsed.options.find(
|
|
374
|
-
(option) =>
|
|
1276
|
+
(option) =>
|
|
1277
|
+
TLAPM_INTEGER_OPTIONS.has(option.name) &&
|
|
1278
|
+
option.values.some((value) => !/^-?\d+$/.test(value)),
|
|
375
1279
|
);
|
|
376
1280
|
if (nonInteger) {
|
|
377
1281
|
console.error(`Error: option '${nonInteger.name}' expects an integer.`);
|
|
378
1282
|
return 1;
|
|
379
1283
|
}
|
|
380
|
-
|
|
1284
|
+
if (parsed.has("--version")) {
|
|
1285
|
+
console.log(TLAPM_VERSION);
|
|
1286
|
+
return EXIT_STATUS.success;
|
|
1287
|
+
}
|
|
1288
|
+
const files = getInputPaths(parsed.positionals).map((input) => input.path);
|
|
381
1289
|
const modulePaths = files.map((path) => (path.endsWith(".tla") ? path : `${path}.tla`));
|
|
382
1290
|
if (modulePaths.length === 0) {
|
|
383
1291
|
console.error(USAGE);
|
|
@@ -392,15 +1300,12 @@ const prove = (args: string[]) => {
|
|
|
392
1300
|
if (option.name === "--line") return start === 0 ? WHOLE_MODULE : { start, end: start };
|
|
393
1301
|
return range;
|
|
394
1302
|
}, WHOLE_MODULE);
|
|
395
|
-
// tlapm searches
|
|
396
|
-
// directory, the last given first.
|
|
397
|
-
const tlapmLibrary = getTlapmLibrary();
|
|
398
|
-
const includes = parsed.options.flatMap((option) => (option.name === "-I" ? option.values : []));
|
|
1303
|
+
// tlapm also searches each module's directory. Without tlapm, TLAPS is tla-ts's copy.
|
|
399
1304
|
const directories = modulePaths.reduce(
|
|
400
1305
|
(found, path) => (found.includes(dirname(path)) ? found : [dirname(path), ...found]),
|
|
401
|
-
|
|
1306
|
+
getLibraryDirectories(parsed),
|
|
402
1307
|
);
|
|
403
|
-
|
|
1308
|
+
const moduleNames = new Set<string>();
|
|
404
1309
|
const results = generateObligations(() => {
|
|
405
1310
|
const missingIndex = modulePaths.findIndex((path) => !existsSync(path));
|
|
406
1311
|
if (missingIndex !== -1) {
|
|
@@ -410,8 +1315,16 @@ const prove = (args: string[]) => {
|
|
|
410
1315
|
}
|
|
411
1316
|
return getObligations(
|
|
412
1317
|
modulePaths.map((path) => ({ file: `./${path}`, source: readFileSync(path, "utf8") })),
|
|
413
|
-
(name) =>
|
|
414
|
-
|
|
1318
|
+
(name) => {
|
|
1319
|
+
moduleNames.add(name);
|
|
1320
|
+
// tlapm names each file it reads by joining a search directory and the name, as in
|
|
1321
|
+
// ./Module.tla.
|
|
1322
|
+
const file = directories
|
|
1323
|
+
.map((directory) => `${directory}/${name}.tla`)
|
|
1324
|
+
.find((path) => existsSync(path));
|
|
1325
|
+
if (file !== undefined) return { file, source: readFileSync(file, "utf8") };
|
|
1326
|
+
return name === "TLAPS" ? { file: "TLAPS.tla", source: TLAPS_MODULE } : undefined;
|
|
1327
|
+
},
|
|
415
1328
|
{
|
|
416
1329
|
lines,
|
|
417
1330
|
onWarning: (warning) => {
|
|
@@ -426,36 +1339,96 @@ const prove = (args: string[]) => {
|
|
|
426
1339
|
);
|
|
427
1340
|
});
|
|
428
1341
|
if (!results) return TLAPM_FAILURE_STATUS;
|
|
429
|
-
const
|
|
1342
|
+
const cacheDirectory =
|
|
1343
|
+
parsed.get("--cache-dir")?.[0] ?? process.env.TLAPM_CACHE_DIR ?? ".tlacache";
|
|
1344
|
+
const forgottenLines = parsed.get("--nofpl")?.map(Number) ?? [0, 0];
|
|
1345
|
+
const settings: ProvingSettings = {
|
|
1346
|
+
isToolbox,
|
|
1347
|
+
isProving: !parsed.has("--noproving"),
|
|
1348
|
+
workers: Math.max(1, Number(parsed.get("--threads")?.[0] ?? availableParallelism())),
|
|
1349
|
+
isFingerprinted: (obligation) =>
|
|
1350
|
+
!parsed.has("--nofp") &&
|
|
1351
|
+
!(
|
|
1352
|
+
obligation.locus &&
|
|
1353
|
+
obligation.locus.startLine >= forgottenLines[0] &&
|
|
1354
|
+
obligation.locus.endLine <= forgottenLines[1]
|
|
1355
|
+
),
|
|
1356
|
+
fingerprints: new Map(),
|
|
1357
|
+
};
|
|
1358
|
+
const statuses: number[] = [];
|
|
1359
|
+
for (const [index, result] of results.entries()) {
|
|
1360
|
+
// Tlapm_lib.mkdir_tlaps.
|
|
1361
|
+
const directory = `${cacheDirectory}/${result.name}.tlaps`;
|
|
1362
|
+
const fingerprintsPath = `${directory}/fingerprints`;
|
|
1363
|
+
const loadedPath = parsed.get("--usefp")?.[0] ?? fingerprintsPath;
|
|
1364
|
+
mkdirSync(directory, { recursive: true });
|
|
1365
|
+
if (parsed.has("--cleanfp") && existsSync(fingerprintsPath)) {
|
|
1366
|
+
rmSync(fingerprintsPath);
|
|
1367
|
+
console.log(`(* fingerprints file ${JSON.stringify(fingerprintsPath)} removed *)`);
|
|
1368
|
+
}
|
|
1369
|
+
if (!parsed.has("--cleanfp") && existsSync(loadedPath) && result.summary.total !== 0) {
|
|
1370
|
+
console.log(
|
|
1371
|
+
parsed.has("--nofp")
|
|
1372
|
+
? `(* will not use fingerprints (because of option \`--nofp\`), but will now load fingerprints from the file \`${loadedPath}\`, in order to overwrite with the new fingerprints, and then save the results at the end. *)`
|
|
1373
|
+
: `(* loading fingerprints in ${JSON.stringify(loadedPath)} *)`,
|
|
1374
|
+
);
|
|
1375
|
+
loadFingerprints(settings.fingerprints, loadedPath, parsed.has("--safefp"));
|
|
1376
|
+
}
|
|
430
1377
|
if (parsed.has("--summary")) console.log(formatSummary(result));
|
|
431
1378
|
if (isToolbox) {
|
|
432
1379
|
result.obligations.forEach((obligation) =>
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
`
|
|
437
|
-
|
|
438
|
-
...(parsed.has("--printallobs") ? [`obl:${obligation.text}`] : []),
|
|
439
|
-
]),
|
|
1380
|
+
printObligationMessage(
|
|
1381
|
+
obligation,
|
|
1382
|
+
"to be proved",
|
|
1383
|
+
parsed.has("--printallobs") ? [`obl:${obligation.text}`] : [],
|
|
1384
|
+
),
|
|
440
1385
|
);
|
|
441
1386
|
printToolboxMessage(["type:obligationsnumber", `count:${result.obligations.length}`]);
|
|
442
1387
|
}
|
|
443
|
-
if (
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
1388
|
+
if (parsed.has("--strict"))
|
|
1389
|
+
statuses.push(
|
|
1390
|
+
...checkStrictly(result, lines.start > 0 || lines.end < Infinity, parsed.has("--summary")),
|
|
1391
|
+
);
|
|
1392
|
+
if (!isProcessing) continue;
|
|
1393
|
+
// tlapm's history holds the source of each module read so far.
|
|
1394
|
+
saveHistory(
|
|
1395
|
+
fingerprintsPath,
|
|
1396
|
+
[...moduleNames, ...results.slice(0, index + 1).map((innerResult) => innerResult.name)].map(
|
|
1397
|
+
(name) => `${name}.tla`,
|
|
1398
|
+
),
|
|
1399
|
+
);
|
|
1400
|
+
const isFailed = await proveModule(
|
|
1401
|
+
result,
|
|
1402
|
+
`${directory}/${result.name}.thy`,
|
|
1403
|
+
fingerprintsPath,
|
|
1404
|
+
settings,
|
|
1405
|
+
);
|
|
1406
|
+
if (isFailed && parsed.has("--strict")) statuses.push(STRICT_EXIT_STATUS.failed);
|
|
1407
|
+
if (isFailed && !parsed.has("--strict") && !isToolbox) {
|
|
1408
|
+
console.error(UNPROVED_ENDING);
|
|
1409
|
+
return TLAPM_FAILURE_STATUS;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
return (
|
|
1413
|
+
Object.values(STRICT_EXIT_STATUS).find((status) => statuses.includes(status)) ??
|
|
1414
|
+
EXIT_STATUS.success
|
|
1415
|
+
);
|
|
449
1416
|
};
|
|
450
1417
|
|
|
451
|
-
const
|
|
452
|
-
if (args[0] === "prove") return reportErrors(() => prove(args.slice(1)));
|
|
1418
|
+
const checkSpecs = async (args: string[], java: JavaProperties) => {
|
|
453
1419
|
const parsed = CHECK_COMMAND.parse(args);
|
|
454
1420
|
const inputs = getInputPaths(parsed.positionals);
|
|
455
1421
|
const isConfigured = parsed.has("-config");
|
|
456
|
-
//
|
|
1422
|
+
// Like TLC, a spec named without an extension is the .tla file of that name. A glob also matches
|
|
1423
|
+
// modules that only other specs import, which have no configuration.
|
|
457
1424
|
const specPaths = inputs
|
|
458
|
-
.map((input) => ({
|
|
1425
|
+
.map((input) => ({
|
|
1426
|
+
...input,
|
|
1427
|
+
path:
|
|
1428
|
+
input.isGlobbed || /\.(tla|cfg)$/.test(input.path)
|
|
1429
|
+
? input.path.replace(/\.cfg$/, ".tla")
|
|
1430
|
+
: `${input.path}.tla`,
|
|
1431
|
+
}))
|
|
459
1432
|
.filter(
|
|
460
1433
|
(input) =>
|
|
461
1434
|
input.path.endsWith(".tla") &&
|
|
@@ -470,7 +1443,305 @@ const run = async (args: string[]) => {
|
|
|
470
1443
|
console.error("Error: -config applies to one specification, but several were given.");
|
|
471
1444
|
return 1;
|
|
472
1445
|
}
|
|
473
|
-
|
|
1446
|
+
// TLC also looks for the spec itself in the library directories.
|
|
1447
|
+
const findSpec = (path: string) =>
|
|
1448
|
+
existsSync(path) || isAbsolute(path)
|
|
1449
|
+
? path
|
|
1450
|
+
: (java.libraries.map((directory) => join(directory, path)).find(existsSync) ?? path);
|
|
1451
|
+
const paths = [...new Set(specPaths.map(findSpec))];
|
|
1452
|
+
const tlcVersion = java.tlcVersion ?? "master";
|
|
1453
|
+
return runEach(
|
|
1454
|
+
paths,
|
|
1455
|
+
(path, printer) => {
|
|
1456
|
+
// TLC checks one spec, so tla-ts names each of several it checks.
|
|
1457
|
+
if (paths.length > 1)
|
|
1458
|
+
console.log(`Checking ${basename(path)} with ${basename(path, ".tla")}.cfg`);
|
|
1459
|
+
return checkSpec(path, parsed, java, printer);
|
|
1460
|
+
},
|
|
1461
|
+
() => createMessagePrinter(parsed.has("-tool"), !parsed.has("-nowarning"), tlcVersion),
|
|
1462
|
+
);
|
|
1463
|
+
};
|
|
1464
|
+
|
|
1465
|
+
// XMLExporter.run prints why it cannot parse its arguments, and its usage.
|
|
1466
|
+
const printXmlExportUsageError = (message: string) => {
|
|
1467
|
+
process.stderr.write(`ERROR: ${message}\n${XML_EXPORT_USAGE}`);
|
|
1468
|
+
return XML_EXPORT_EXIT_CODE.argsParsingFailure;
|
|
1469
|
+
};
|
|
1470
|
+
|
|
1471
|
+
// XMLExporter.run writes the XML of a specification, and why it can't when it can't.
|
|
1472
|
+
const writeXml = (specification: SanySpecification, options: XmlExportOptions) => {
|
|
1473
|
+
try {
|
|
1474
|
+
process.stdout.write(exportSanyXml(specification, options));
|
|
1475
|
+
return EXIT_STATUS.success;
|
|
1476
|
+
} catch (error) {
|
|
1477
|
+
if (!(error instanceof TlaUnsupportedError)) throw error;
|
|
1478
|
+
const exitCode = getErrorExitCode(error);
|
|
1479
|
+
const unwound = error instanceof TlaJavaException ? error.unwound : "";
|
|
1480
|
+
console.error(
|
|
1481
|
+
exitCode === XML_EXPORT_EXIT_CODE.uncaughtException
|
|
1482
|
+
? `${unwound}Exception in thread "main" ${error.message}`
|
|
1483
|
+
: `ERROR: ${error.message}`,
|
|
1484
|
+
);
|
|
1485
|
+
return exitCode;
|
|
1486
|
+
}
|
|
1487
|
+
};
|
|
1488
|
+
|
|
1489
|
+
interface XmlExportArgs {
|
|
1490
|
+
flags: Set<string>;
|
|
1491
|
+
includes: string[];
|
|
1492
|
+
error: "missing-include" | "several-files" | undefined;
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
// XMLExporter reads the flags before the last argument, which names the module, and skips an
|
|
1496
|
+
// argument it does not know, which then counts as another module.
|
|
1497
|
+
const parseXmlExportArgs = (args: string[], flagNames: Set<string>): XmlExportArgs => {
|
|
1498
|
+
const parsed: XmlExportArgs = { flags: new Set(), includes: [], error: undefined };
|
|
1499
|
+
const last = { flag: -1 };
|
|
1500
|
+
for (let index = 0; index < args.length - 1; index++) {
|
|
1501
|
+
if (flagNames.has(args[index])) {
|
|
1502
|
+
parsed.flags.add(args[index]);
|
|
1503
|
+
last.flag = index;
|
|
1504
|
+
continue;
|
|
1505
|
+
}
|
|
1506
|
+
if (args[index] !== "-I") continue;
|
|
1507
|
+
index++;
|
|
1508
|
+
if (index > args.length - 2) return { ...parsed, error: "missing-include" };
|
|
1509
|
+
parsed.includes.push(args[index]);
|
|
1510
|
+
last.flag = index;
|
|
1511
|
+
}
|
|
1512
|
+
return last.flag === args.length - 2 ? parsed : { ...parsed, error: "several-files" };
|
|
1513
|
+
};
|
|
1514
|
+
|
|
1515
|
+
const exportXml = (args: string[]) => {
|
|
1516
|
+
if (args.length === 0) return printXmlExportUsageError("at least one .tla file must be given");
|
|
1517
|
+
const parsed = parseXmlExportArgs(args, XML_EXPORT_FLAGS);
|
|
1518
|
+
if (parsed.error === "missing-include") {
|
|
1519
|
+
return printXmlExportUsageError(
|
|
1520
|
+
"the -I flag must be followed by a directory and at least one .tla file",
|
|
1521
|
+
);
|
|
1522
|
+
}
|
|
1523
|
+
if (parsed.error === "several-files") {
|
|
1524
|
+
return printXmlExportUsageError("Only one TLA file to check allowed!");
|
|
1525
|
+
}
|
|
1526
|
+
const name = args[args.length - 1];
|
|
1527
|
+
if (name === "-help") {
|
|
1528
|
+
process.stdout.write(XML_EXPORT_USAGE);
|
|
1529
|
+
return EXIT_STATUS.success;
|
|
1530
|
+
}
|
|
1531
|
+
const fileName = name.endsWith(".tla") ? name : `${name}.tla`;
|
|
1532
|
+
// SANY looks for each module in the working directory, then in the -I directories, which
|
|
1533
|
+
// XMLExporter passes in place of TLA-Library, then among its standard modules.
|
|
1534
|
+
const directories = [".", ...parsed.includes];
|
|
1535
|
+
const path = directories.map((directory) => resolve(directory, fileName)).find(existsSync);
|
|
1536
|
+
if (path === undefined && !SANY_STANDARD_MODULES.has(fileName.slice(0, -".tla".length))) {
|
|
1537
|
+
printMissingFile(process.cwd(), `./${fileName}`, parsed.includes);
|
|
1538
|
+
}
|
|
1539
|
+
// XMLExporter.parseSpec prints SANY's errors, and XMLExporter.run why it fails.
|
|
1540
|
+
const sany = getSanyReport(path ?? fileName, createModuleLoader(directories), {
|
|
1541
|
+
fileName: name,
|
|
1542
|
+
isXmlExport: true,
|
|
1543
|
+
});
|
|
1544
|
+
process.stderr.write(sany.text);
|
|
1545
|
+
if (sany.isFailed || sany.specification === undefined) {
|
|
1546
|
+
console.error("ERROR: Failed to parse module.");
|
|
1547
|
+
return XML_EXPORT_EXIT_CODE.specParsingFailure;
|
|
1548
|
+
}
|
|
1549
|
+
return writeXml(sany.specification, {
|
|
1550
|
+
version: "master",
|
|
1551
|
+
isRestricted: parsed.flags.has("-r"),
|
|
1552
|
+
isUncommented: parsed.flags.has("-u"),
|
|
1553
|
+
isTerse: parsed.flags.has("-t"),
|
|
1554
|
+
});
|
|
1555
|
+
};
|
|
1556
|
+
|
|
1557
|
+
// TLC 1.7.4's FileUtil.createNamedInputStream names the last file that SimpleFilenameToStream
|
|
1558
|
+
// looked for a module in, and the directories it looks in, the standard modules in the jar last,
|
|
1559
|
+
// which tla-ts leaves out without a jar.
|
|
1560
|
+
const printMissingFile174 = (path: string, libraries: string[], jar: string | undefined) =>
|
|
1561
|
+
console.error(
|
|
1562
|
+
`File does not exist: ${isAbsolute(path) ? path : `${process.cwd()}/${path}`} while looking in these directories: ${[...libraries, ...(jar === undefined ? [] : [getStandardModulesUrl(jar)])].join(", ")}`,
|
|
1563
|
+
);
|
|
1564
|
+
|
|
1565
|
+
// SimpleFilenameToStream ends a library directory with a separator.
|
|
1566
|
+
const toLibraryPath = (directory: string) =>
|
|
1567
|
+
directory.endsWith("/") ? directory : `${directory}/`;
|
|
1568
|
+
|
|
1569
|
+
// TLC 1.7.4's SimpleFilenameToStream looks for a module in the directory of a spec that TLC is
|
|
1570
|
+
// given by an absolute path, then in the directory that a relative path names, or else in the
|
|
1571
|
+
// TLA-Library directories.
|
|
1572
|
+
const createMissingFilePrinter174 = (
|
|
1573
|
+
specPath: string,
|
|
1574
|
+
java: JavaProperties,
|
|
1575
|
+
jar: string | undefined,
|
|
1576
|
+
) => {
|
|
1577
|
+
const specDirectory = specPath.slice(0, specPath.lastIndexOf("/") + 1);
|
|
1578
|
+
const isRelativeToDirectory = !isAbsolute(specPath) && specDirectory !== "";
|
|
1579
|
+
const libraries = (isRelativeToDirectory ? [specDirectory] : java.libraries).map(toLibraryPath);
|
|
1580
|
+
const lastDirectory =
|
|
1581
|
+
libraries.length > 0
|
|
1582
|
+
? libraries[libraries.length - 1]
|
|
1583
|
+
: isAbsolute(specPath)
|
|
1584
|
+
? specDirectory
|
|
1585
|
+
: "";
|
|
1586
|
+
return (fileName: string) => printMissingFile174(`${lastDirectory}${fileName}`, libraries, jar);
|
|
1587
|
+
};
|
|
1588
|
+
|
|
1589
|
+
// TLC 1.7.4's SANY reports each module it can't find as it looks for it.
|
|
1590
|
+
const reportMissingModules174 =
|
|
1591
|
+
(loadModule: (name: string) => string | undefined, onMissing: (fileName: string) => void) =>
|
|
1592
|
+
(name: string) => {
|
|
1593
|
+
const text = loadModule(name);
|
|
1594
|
+
if (text === undefined && !SANY_174_STANDARD_MODULES.has(name)) onMissing(`${name}.tla`);
|
|
1595
|
+
return text;
|
|
1596
|
+
};
|
|
1597
|
+
|
|
1598
|
+
// TLC 1.7.4's XMLExporter.main throws an exception for an argument it can't take or a
|
|
1599
|
+
// specification without a root module.
|
|
1600
|
+
const printXmlExporterException = (exception: string, line: number) => {
|
|
1601
|
+
console.error(
|
|
1602
|
+
`Exception in thread "main" ${exception}\n\tat tla2sany.xml.XMLExporter.main(XMLExporter.java:${line})`,
|
|
1603
|
+
);
|
|
1604
|
+
return XML_EXPORT_EXIT_CODE.uncaughtException;
|
|
1605
|
+
};
|
|
1606
|
+
|
|
1607
|
+
// TLC 1.7.4's XMLExporter.main, which takes only -o, as it can't validate the XML without
|
|
1608
|
+
// fetching its schema, and -I, and exports a specification that SANY finds errors in.
|
|
1609
|
+
const exportXml174 = (args: string[], jar: string | undefined) => {
|
|
1610
|
+
if (args.length === 0) {
|
|
1611
|
+
return printXmlExporterException(
|
|
1612
|
+
"java.lang.IllegalArgumentException: at least one .tla file must be given",
|
|
1613
|
+
59,
|
|
1614
|
+
);
|
|
1615
|
+
}
|
|
1616
|
+
const parsed = parseXmlExportArgs(args, XML_EXPORT_174_FLAGS);
|
|
1617
|
+
if (parsed.error === "missing-include") {
|
|
1618
|
+
return printXmlExporterException(
|
|
1619
|
+
"java.lang.IllegalArgumentException: the -I flag must be followed by a directory and at least one .tla file",
|
|
1620
|
+
71,
|
|
1621
|
+
);
|
|
1622
|
+
}
|
|
1623
|
+
if (parsed.error === "several-files") {
|
|
1624
|
+
return printXmlExporterException(
|
|
1625
|
+
"java.lang.IllegalArgumentException: Only one TLA file to check allowed!",
|
|
1626
|
+
83,
|
|
1627
|
+
);
|
|
1628
|
+
}
|
|
1629
|
+
const name = args[args.length - 1];
|
|
1630
|
+
const fileName = `${name.replace(/\.tla$/i, "")}.tla`;
|
|
1631
|
+
// SimpleFilenameToStream looks for a module in the working directory, then in the -I
|
|
1632
|
+
// directories, or the root directory when there are none, then among the standard modules.
|
|
1633
|
+
const libraries = (parsed.includes.length === 0 ? ["/"] : parsed.includes).map(toLibraryPath);
|
|
1634
|
+
const directories = [".", ...libraries];
|
|
1635
|
+
const printMissingFile = (moduleFileName: string) =>
|
|
1636
|
+
printMissingFile174(`${libraries[libraries.length - 1]}${moduleFileName}`, libraries, jar);
|
|
1637
|
+
const path = directories.map((directory) => resolve(directory, fileName)).find(existsSync);
|
|
1638
|
+
if (path === undefined && !SANY_174_STANDARD_MODULES.has(basename(fileName, ".tla"))) {
|
|
1639
|
+
printMissingFile(fileName);
|
|
1640
|
+
return EXIT_STATUS.success;
|
|
1641
|
+
}
|
|
1642
|
+
const sany = getSanyReport(
|
|
1643
|
+
path ?? fileName,
|
|
1644
|
+
reportMissingModules174(createModuleLoader(directories), printMissingFile),
|
|
1645
|
+
{
|
|
1646
|
+
fileName: name,
|
|
1647
|
+
isXmlExport: true,
|
|
1648
|
+
version: "1.7.4",
|
|
1649
|
+
},
|
|
1650
|
+
);
|
|
1651
|
+
process.stderr.write(sany.text);
|
|
1652
|
+
if (sany.specification === undefined) {
|
|
1653
|
+
return printXmlExporterException(
|
|
1654
|
+
`tla2sany.xml.XMLExportingException: spec ${(path && getSanyModuleName(readFileSync(path, "utf8"), "1.7.4")) ?? "null"} is malformed - does not have a root module`,
|
|
1655
|
+
110,
|
|
1656
|
+
);
|
|
1657
|
+
}
|
|
1658
|
+
return writeXml(sany.specification, {
|
|
1659
|
+
version: "1.7.4",
|
|
1660
|
+
isRestricted: false,
|
|
1661
|
+
isUncommented: false,
|
|
1662
|
+
isTerse: true,
|
|
1663
|
+
});
|
|
1664
|
+
};
|
|
1665
|
+
|
|
1666
|
+
// Tools that run TLC with Java, such as the statechart skill of pstack, can run tla-ts in place of
|
|
1667
|
+
// java, as in `tla-ts -DTLA-Library=lib -cp tla2tools.jar tlc2.TLC Spec`. tla-ts searches the
|
|
1668
|
+
// TLA-Library directories for modules as TLC does, though not as XMLExporter, which ignores them,
|
|
1669
|
+
// names the files in java.io.tmpdir and the jar on the class path that TLC would copy and read
|
|
1670
|
+
// modules from, and ignores the other options. It reproduces the TLC of that jar, or the one that
|
|
1671
|
+
// -Dtla-ts.tlc names without a jar, as in `tla-ts -Dtla-ts.tlc=1.7.4 tlc2.TLC Spec`.
|
|
1672
|
+
const JAVA_MAIN_CLASSES = ["tlc2.TLC", "tla2sany.xml.XMLExporter"];
|
|
1673
|
+
|
|
1674
|
+
const TLA_LIBRARY_PROPERTY = "-DTLA-Library=";
|
|
1675
|
+
|
|
1676
|
+
const TEMPORARY_DIRECTORY_PROPERTY = "-Djava.io.tmpdir=";
|
|
1677
|
+
|
|
1678
|
+
const TLC_VERSION_PROPERTY = "-Dtla-ts.tlc=";
|
|
1679
|
+
|
|
1680
|
+
// What the java command sets for TLC: the TLA-Library directories it searches for modules, the
|
|
1681
|
+
// class path it finds its standard modules on, and java.io.tmpdir, where it copies them.
|
|
1682
|
+
interface JavaProperties {
|
|
1683
|
+
libraries: string[];
|
|
1684
|
+
classPath?: string;
|
|
1685
|
+
temporaryDirectory?: string;
|
|
1686
|
+
tlcVersion?: TlcVersion;
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
// The tla2tools.jar on the class path.
|
|
1690
|
+
const getJar = (java: JavaProperties) =>
|
|
1691
|
+
java.classPath?.split(delimiter).find((entry) => entry.endsWith(".jar"));
|
|
1692
|
+
|
|
1693
|
+
interface JavaLaunch {
|
|
1694
|
+
mainClass: string;
|
|
1695
|
+
args: string[];
|
|
1696
|
+
java: JavaProperties;
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
const getJavaLaunch = (args: string[]): JavaLaunch | undefined => {
|
|
1700
|
+
const java: JavaProperties = { libraries: [] };
|
|
1701
|
+
for (let index = 0; index < args.length; index++) {
|
|
1702
|
+
const arg = args[index];
|
|
1703
|
+
if (arg === "-cp" || arg === "-classpath" || arg === "--class-path") {
|
|
1704
|
+
index++;
|
|
1705
|
+
java.classPath = args[index];
|
|
1706
|
+
} else if (arg === "-jar") {
|
|
1707
|
+
java.classPath = args[index + 1];
|
|
1708
|
+
return { mainClass: "tlc2.TLC", args: args.slice(index + 2), java };
|
|
1709
|
+
} else if (arg.startsWith(TLA_LIBRARY_PROPERTY)) {
|
|
1710
|
+
java.libraries.push(...arg.slice(TLA_LIBRARY_PROPERTY.length).split(delimiter));
|
|
1711
|
+
} else if (arg.startsWith(TEMPORARY_DIRECTORY_PROPERTY)) {
|
|
1712
|
+
java.temporaryDirectory = arg.slice(TEMPORARY_DIRECTORY_PROPERTY.length);
|
|
1713
|
+
} else if (arg.startsWith(TLC_VERSION_PROPERTY)) {
|
|
1714
|
+
java.tlcVersion = arg.slice(TLC_VERSION_PROPERTY.length) === "1.7.4" ? "1.7.4" : "master";
|
|
1715
|
+
} else if (!arg.startsWith("-D") && !arg.startsWith("-X")) {
|
|
1716
|
+
const isLaunch = index > 0 || JAVA_MAIN_CLASSES.includes(arg);
|
|
1717
|
+
return isLaunch ? { mainClass: arg, args: args.slice(index + 1), java } : undefined;
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
return undefined;
|
|
1721
|
+
};
|
|
1722
|
+
|
|
1723
|
+
const runJavaClass = (launch: JavaLaunch) => {
|
|
1724
|
+
if (launch.mainClass === "tlc2.TLC") return checkSpecs(launch.args, launch.java);
|
|
1725
|
+
if (launch.mainClass === "tla2sany.xml.XMLExporter") {
|
|
1726
|
+
return reportErrors(() =>
|
|
1727
|
+
launch.java.tlcVersion === "1.7.4"
|
|
1728
|
+
? exportXml174(launch.args, getJar(launch.java))
|
|
1729
|
+
: exportXml(launch.args),
|
|
1730
|
+
);
|
|
1731
|
+
}
|
|
1732
|
+
console.error(
|
|
1733
|
+
`Error: tla-ts runs the Java classes ${JAVA_MAIN_CLASSES.join(" and ")}, not ${launch.mainClass}.`,
|
|
1734
|
+
);
|
|
1735
|
+
return 1;
|
|
1736
|
+
};
|
|
1737
|
+
|
|
1738
|
+
const run = async (args: string[]) => {
|
|
1739
|
+
if (args[0] === "tlapm") return reportErrors(() => runTlapm(args.slice(1)));
|
|
1740
|
+
const launch = getJavaLaunch(args);
|
|
1741
|
+
if (launch === undefined) return checkSpecs(args, { libraries: [] });
|
|
1742
|
+
// The TLC that -Dtla-ts.tlc names, or else the one of the jar on the class path.
|
|
1743
|
+
launch.java.tlcVersion ??= await getTlcVersion(getJar(launch.java));
|
|
1744
|
+
return runJavaClass(launch);
|
|
474
1745
|
};
|
|
475
1746
|
|
|
476
1747
|
export const runCli = async () => {
|