tla-ts 0.0.10-dev.d618a2d79 → 0.0.10-dev.e5c8dc315
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/dist/compile.cjs +3 -3
- package/dist/compile.js +1 -1
- package/dist/deciders.cjs +36 -36
- package/dist/deciders.js +53 -53
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +18 -4
- package/dist/index.d.ts +18 -4
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +56 -56
- package/dist/prove.js +78 -78
- package/dist/run.cjs +40 -44
- package/dist/run.js +42 -46
- package/dist/tlapm.cjs +1 -1
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +97 -92
- package/dist/transfer.js +97 -92
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +31 -3
- package/src/bags.ts +50 -29
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +13 -11
- package/src/check-trace.ts +146 -93
- package/src/check.ts +518 -281
- package/src/cli/runtime-invariants.ts +20 -56
- package/src/cli/tlc-arguments.ts +2 -2
- package/src/cli/tlc-output.ts +18 -4
- package/src/cli/tlc.ts +18 -12
- package/src/cli/xml-exporter.ts +1 -1
- package/src/codegen.ts +23 -10
- package/src/coverage.ts +255 -18
- package/src/dependencies.ts +68 -15
- package/src/dfid.ts +101 -36
- package/src/environment.ts +155 -66
- package/src/errors.ts +7 -0
- package/src/evaluate.ts +424 -135
- package/src/exit-codes.ts +28 -14
- package/src/instances.ts +152 -25
- package/src/java-hash.ts +14 -0
- package/src/java-overrides.ts +2 -2
- package/src/levels.ts +675 -236
- package/src/lexer.ts +12 -2
- package/src/liveness-checker.ts +179 -60
- package/src/liveness.ts +55 -10
- package/src/obligations/index.ts +1 -1
- package/src/obligations/normalize.ts +1 -4
- package/src/obligations/printer.ts +5 -5
- package/src/obligations/source.ts +2 -0
- package/src/parallel-worker.ts +8 -2
- package/src/parallel.ts +5 -0
- package/src/parser.ts +180 -149
- package/src/prover/isabelle/isar/attrib.ts +4 -4
- package/src/prover/isabelle/isar/rule-cases.ts +8 -6
- package/src/prover/isabelle/provers/clasimp.ts +1 -1
- package/src/prover/isabelle/provers/hypsubst.ts +2 -2
- package/src/prover/isabelle/pure/rewriter.ts +3 -3
- package/src/prover/isabelle/pure/term.ts +3 -3
- package/src/prover/prep/md5.ts +26 -29
- package/src/prover/smt/rewrite.ts +2 -7
- package/src/prover/smt/simplify.ts +1 -1
- package/src/prover/smt/solver/ackermannize-bv-tactic.ts +3 -2
- package/src/prover/smt/solver/arith-rewriter.ts +11 -3
- package/src/prover/smt/solver/array-rewriter.ts +12 -2
- package/src/prover/smt/solver/asserted-formulas.ts +171 -58
- package/src/prover/smt/solver/ast-lt.ts +1 -1
- package/src/prover/smt/solver/ast.ts +66 -14
- package/src/prover/smt/solver/auf-solver.ts +23 -12
- package/src/prover/smt/solver/bit-blast-tactic.ts +28 -2
- package/src/prover/smt/solver/blast-term-ite.ts +47 -0
- package/src/prover/smt/solver/bound-simplifier.ts +11 -13
- package/src/prover/smt/solver/bv-decl-plugin.ts +13 -10
- package/src/prover/smt/solver/bv-rewriter.ts +1 -1
- package/src/prover/smt/solver/bv1-blast.ts +1 -1
- package/src/prover/smt/solver/card2bv.ts +35 -18
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -24
- package/src/prover/smt/solver/context.ts +84 -15
- package/src/prover/smt/solver/ctx-simplify.ts +9 -4
- package/src/prover/smt/solver/datatype-decl-plugin.ts +15 -7
- package/src/prover/smt/solver/dependent-expr-state.ts +28 -16
- package/src/prover/smt/solver/diff-neq.ts +9 -8
- package/src/prover/smt/solver/dt2bv-tactic.ts +66 -28
- package/src/prover/smt/solver/elim-bounds.ts +89 -0
- package/src/prover/smt/solver/elim-term-ite-tactic.ts +48 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +31 -28
- package/src/prover/smt/solver/eq2bv-tactic.ts +15 -6
- package/src/prover/smt/solver/euf/arith-internalize.ts +1 -1
- package/src/prover/smt/solver/euf/array-internalize.ts +1 -1
- package/src/prover/smt/solver/euf/bv-internalize.ts +1 -1
- package/src/prover/smt/solver/euf/egraph.ts +4 -11
- package/src/prover/smt/solver/euf/euf-solver.ts +1 -2
- package/src/prover/smt/solver/euf/mam.ts +1 -5
- package/src/prover/smt/solver/euf/q-ematch.ts +1 -2
- package/src/prover/smt/solver/euf/th-solver.ts +0 -7
- package/src/prover/smt/solver/expr2polynomial.ts +204 -79
- package/src/prover/smt/solver/factor.ts +36 -14
- package/src/prover/smt/solver/fd-solver.ts +608 -139
- package/src/prover/smt/solver/fix-dl-var.ts +2 -3
- package/src/prover/smt/solver/fm-tactic.ts +9 -7
- package/src/prover/smt/solver/fpa-rewriter.ts +1 -2
- package/src/prover/smt/solver/fpa2bv-converter.ts +3 -1
- package/src/prover/smt/solver/fpa2bv-rewriter.ts +1 -0
- package/src/prover/smt/solver/fpa2bv-tactic.ts +1 -1
- package/src/prover/smt/solver/goal.ts +6 -3
- package/src/prover/smt/solver/goal2nlsat.ts +57 -30
- package/src/prover/smt/solver/hashtable.ts +4 -0
- package/src/prover/smt/solver/internalizer.ts +1 -1
- package/src/prover/smt/solver/lia2pb.ts +1 -1
- package/src/prover/smt/solver/logic-tactics.ts +15 -5
- package/src/prover/smt/solver/lp/core-solver.ts +12 -8
- package/src/prover/smt/solver/lp/lar-solver.ts +1 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +6 -2
- package/src/prover/smt/solver/lp/nla-core.ts +1 -1
- package/src/prover/smt/solver/lp/nla-grobner.ts +158 -80
- package/src/prover/smt/solver/lp/nra-solver.ts +45 -39
- package/src/prover/smt/solver/lp/pdd-interval.ts +6 -2
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +60 -20
- package/src/prover/smt/solver/lp/pdd-solver.ts +72 -39
- package/src/prover/smt/solver/lp/pdd.ts +725 -290
- package/src/prover/smt/solver/lp/union-find.ts +1 -1
- package/src/prover/smt/solver/mam-compiler.ts +1 -1
- package/src/prover/smt/solver/maxcore.ts +2 -1
- package/src/prover/smt/solver/maxsmt-base.ts +1 -0
- package/src/prover/smt/solver/model-based-opt.ts +1 -1
- package/src/prover/smt/solver/model-checker.ts +1 -1
- package/src/prover/smt/solver/model-evaluator.ts +2 -0
- package/src/prover/smt/solver/model-generator.ts +85 -43
- package/src/prover/smt/solver/mpf.ts +2 -4
- package/src/prover/smt/solver/mus.ts +2 -3
- package/src/prover/smt/solver/muz/dl-context.ts +22 -44
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
- package/src/prover/smt/solver/muz/dl-mk-slice.ts +3 -3
- package/src/prover/smt/solver/muz/dl-rule.ts +8 -9
- package/src/prover/smt/solver/muz/hnf.ts +2 -2
- package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +1 -1
- package/src/prover/smt/solver/muz/horn-tactic.ts +15 -2
- package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
- package/src/prover/smt/solver/muz/spacer-context.ts +2 -4
- package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
- package/src/prover/smt/solver/nlqsat.ts +2 -1
- package/src/prover/smt/solver/nlsat/algebraic.ts +196 -92
- package/src/prover/smt/solver/nlsat/atoms.ts +52 -33
- package/src/prover/smt/solver/nlsat/explain.ts +375 -217
- package/src/prover/smt/solver/nlsat/levelwise.ts +460 -240
- package/src/prover/smt/solver/nlsat/polynomial.ts +2366 -681
- package/src/prover/smt/solver/nlsat/solver.ts +74 -64
- package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -17
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -4
- package/src/prover/smt/solver/nlsat/upolynomial.ts +41 -18
- package/src/prover/smt/solver/nlsat-tactic.ts +1 -1
- package/src/prover/smt/solver/nnf.ts +6 -2
- package/src/prover/smt/solver/normalize-bounds.ts +2 -2
- package/src/prover/smt/solver/occf.ts +1 -1
- package/src/prover/smt/solver/opt-context.ts +21 -7
- package/src/prover/smt/solver/opt-nlsat.ts +29 -18
- package/src/prover/smt/solver/opt-pareto.ts +19 -0
- package/src/prover/smt/solver/opt-preprocess.ts +1 -1
- package/src/prover/smt/solver/opt-solver.ts +10 -6
- package/src/prover/smt/solver/optsmt.ts +1 -1
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- package/src/prover/smt/solver/pb-rewriter.ts +1 -4
- package/src/prover/smt/solver/pb2bv-tactic.ts +9 -3
- package/src/prover/smt/solver/poly-rewriter.ts +75 -18
- package/src/prover/smt/solver/probes.ts +88 -23
- package/src/prover/smt/solver/proto-model.ts +8 -8
- package/src/prover/smt/solver/purify-arith.ts +51 -49
- package/src/prover/smt/solver/push-app-ite.ts +37 -0
- package/src/prover/smt/solver/qe-arith-plugin.ts +2 -4
- package/src/prover/smt/solver/qe-lite.ts +2 -2
- package/src/prover/smt/solver/qe.ts +3 -2
- package/src/prover/smt/solver/qsat.ts +23 -8
- package/src/prover/smt/solver/quantifier-manager.ts +14 -9
- package/src/prover/smt/solver/recfun-decl-plugin.ts +2 -1
- package/src/prover/smt/solver/reduce-args.ts +2 -2
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
- package/src/prover/smt/solver/rewriter.ts +31 -25
- package/src/prover/smt/solver/rlimit.ts +7 -3
- package/src/prover/smt/solver/sat/config.ts +1 -1
- package/src/prover/smt/solver/sat/goal2sat.ts +75 -12
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +149 -47
- package/src/prover/smt/solver/sat/model-converter.ts +1 -1
- package/src/prover/smt/solver/sat/pb-constraint.ts +7 -0
- package/src/prover/smt/solver/sat/pb-solver.ts +26 -7
- package/src/prover/smt/solver/sat/sat-tactic.ts +54 -25
- package/src/prover/smt/solver/sat/sat2goal.ts +75 -50
- package/src/prover/smt/solver/sat/simplifier.ts +1 -1
- package/src/prover/smt/solver/sat/solver.ts +27 -47
- package/src/prover/smt/solver/seq-axioms.ts +20 -35
- package/src/prover/smt/solver/seq-decl-plugin.ts +1 -1
- package/src/prover/smt/solver/seq-derive.ts +2 -2
- package/src/prover/smt/solver/seq-eq-solver.ts +2 -2
- package/src/prover/smt/solver/seq-monadic.ts +7 -5
- package/src/prover/smt/solver/seq-re-rewriter.ts +2 -1
- package/src/prover/smt/solver/seq-re-util.ts +1 -1
- package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
- package/src/prover/smt/solver/seq-regex-live.ts +2 -2
- package/src/prover/smt/solver/seq-rewriter.ts +31 -29
- package/src/prover/smt/solver/seq-skolem.ts +0 -23
- package/src/prover/smt/solver/seq-view-witness.ts +4 -4
- package/src/prover/smt/solver/smt-consequences.ts +1 -1
- package/src/prover/smt/solver/smt-kernel.ts +48 -7
- package/src/prover/smt/solver/smt-setup.ts +106 -13
- package/src/prover/smt/solver/smtlib-parser.ts +589 -224
- package/src/prover/smt/solver/smtlib-script.ts +718 -213
- package/src/prover/smt/solver/solve-eqs.ts +36 -37
- package/src/prover/smt/solver/solver.ts +18 -4
- package/src/prover/smt/solver/tactic.ts +389 -199
- package/src/prover/smt/solver/theory-bv.ts +13 -3
- package/src/prover/smt/solver/theory-fpa.ts +1 -1
- package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
- package/src/prover/smt/solver/theory-lra-internalize.ts +2 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +12 -3
- package/src/prover/smt/solver/theory-lra-state.ts +1 -1
- package/src/prover/smt/solver/theory-lra.ts +1 -1
- package/src/prover/smt/solver/theory-pb.ts +24 -7
- package/src/prover/smt/solver/theory-seq-solve.ts +1 -1
- package/src/prover/smt/solver/theory-seq-state.ts +2 -21
- package/src/prover/smt/solver/theory-without-terms.ts +24 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +15 -5
- package/src/prover/tlapm/cache.ts +8 -8
- package/src/prover/zenon/index-table.ts +5 -2
- package/src/prover/zenon/isar-case.ts +1 -1
- package/src/prover/zenon/isar.ts +2 -2
- package/src/prover/zenon/phrase.ts +1 -1
- package/src/resolve.ts +1311 -268
- package/src/runtime.ts +21 -2
- package/src/sany/builtins.ts +10 -10
- package/src/sany/generation.ts +5 -15
- package/src/sany/generator-def-entries.ts +123 -36
- package/src/sany/generator-definitions.ts +5 -3
- package/src/sany/generator-expressions.ts +60 -37
- package/src/sany/generator-proofs.ts +19 -12
- package/src/sany/generator.ts +12 -6
- package/src/sany/lexer.ts +15 -7
- package/src/sany/modules.ts +4 -2
- package/src/sany/nodes.ts +1 -1
- package/src/sany/selectors.ts +12 -6
- package/src/sany/xml.ts +2 -3
- package/src/search.ts +321 -135
- package/src/simulate.ts +247 -185
- package/src/spec-description.ts +15 -7
- package/src/standard-definitions.ts +1 -0
- package/src/standard-modules.ts +56 -22
- package/src/subexpressions.ts +666 -147
- package/src/successors.ts +50 -20
- package/src/symmetry.ts +2 -1
- package/src/tlc/jar-data.ts +10 -0
- package/src/tlc/messages.ts +3 -3
- package/src/tlc/order.ts +14 -3
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +147 -46
- package/src/tlc/tlc-operators.ts +10 -8
- package/src/tlc/tlcext-operators.ts +44 -15
- package/src/tlc/trace-spec.ts +9 -22
- package/src/trace-liveness.ts +529 -0
- package/src/typed-tier.ts +52 -31
- package/src/typescript/types.ts +2 -2
- package/src/values.ts +150 -79
package/src/check.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { Expression } from "./ast";
|
|
2
2
|
import { parseConfig, type ModelConfig } from "./config";
|
|
3
3
|
import {
|
|
4
|
-
addCoverageRelation,
|
|
5
|
-
buildCoverage,
|
|
6
4
|
countCoverageVariables,
|
|
7
5
|
createCoverage,
|
|
8
|
-
|
|
6
|
+
createCoverageEnvironment,
|
|
9
7
|
getCoverageReport,
|
|
10
8
|
type CoverageReport,
|
|
11
9
|
} from "./coverage";
|
|
@@ -25,8 +23,8 @@ import {
|
|
|
25
23
|
describeRange,
|
|
26
24
|
getDefinition,
|
|
27
25
|
type CallStack,
|
|
28
|
-
type Environment,
|
|
29
26
|
type FingerprintFailure,
|
|
27
|
+
type State,
|
|
30
28
|
} from "./evaluate";
|
|
31
29
|
import { EXIT_STATUS, setExitCode, withLivenessExitCode } from "./exit-codes";
|
|
32
30
|
import {
|
|
@@ -37,6 +35,7 @@ import {
|
|
|
37
35
|
} from "./check-failure";
|
|
38
36
|
import {
|
|
39
37
|
createTraceBuilder,
|
|
38
|
+
NEXT_RECOVERY_FAILURE,
|
|
40
39
|
type Behavior,
|
|
41
40
|
type SearchPosition,
|
|
42
41
|
type TracedStep,
|
|
@@ -57,6 +56,7 @@ import {
|
|
|
57
56
|
type LiveSuccessor,
|
|
58
57
|
} from "./liveness-checker";
|
|
59
58
|
import {
|
|
59
|
+
addActionCoverage,
|
|
60
60
|
createCheckEnvironment,
|
|
61
61
|
createMissingOperatorError,
|
|
62
62
|
createSearch,
|
|
@@ -64,7 +64,10 @@ import {
|
|
|
64
64
|
findAssumptionViolation,
|
|
65
65
|
reportInitialStatesProgress,
|
|
66
66
|
reportStartup,
|
|
67
|
+
STOP_WALK,
|
|
68
|
+
walkCoveredSuccessors,
|
|
67
69
|
withNextStateExitCode,
|
|
70
|
+
type CoveredAction,
|
|
68
71
|
} from "./search";
|
|
69
72
|
import {
|
|
70
73
|
getActionLabel,
|
|
@@ -82,6 +85,7 @@ import {
|
|
|
82
85
|
type StateWriter,
|
|
83
86
|
} from "./state-graph";
|
|
84
87
|
import {
|
|
88
|
+
createIncompleteSuccessorError,
|
|
85
89
|
forEachInitialState,
|
|
86
90
|
forEachSuccessor,
|
|
87
91
|
getInitialStates,
|
|
@@ -101,14 +105,13 @@ import {
|
|
|
101
105
|
import { createTautologyError } from "./liveness";
|
|
102
106
|
import { KEY_SEPARATOR } from "./resolve";
|
|
103
107
|
import { writeTraceSpec } from "./tlc/trace-spec";
|
|
104
|
-
import {
|
|
105
|
-
getPrimedRanges,
|
|
106
|
-
replayInitialStates,
|
|
107
|
-
replaySuccessors,
|
|
108
|
-
walkSuccessors,
|
|
109
|
-
} from "./tlc/replay";
|
|
108
|
+
import { replayInitialStates, replaySuccessors, walkSuccessors } from "./tlc/replay";
|
|
110
109
|
import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc/summary";
|
|
111
|
-
import {
|
|
110
|
+
import {
|
|
111
|
+
createActionRecord,
|
|
112
|
+
createCounterExample,
|
|
113
|
+
type CounterExampleLoop,
|
|
114
|
+
} from "./tlc/tlcext-operators";
|
|
112
115
|
import type { TlcVersion } from "./tlc/version";
|
|
113
116
|
import { runTypedSearch, type TypedResult } from "./typed-tier";
|
|
114
117
|
import {
|
|
@@ -206,7 +209,7 @@ export type CheckProgress =
|
|
|
206
209
|
branches: number;
|
|
207
210
|
/** Whether TLC checks the complete state graph. */
|
|
208
211
|
isComplete: boolean;
|
|
209
|
-
/** How many states of
|
|
212
|
+
/** How many states the graphs of all branches have together. */
|
|
210
213
|
states: number;
|
|
211
214
|
statistics: SearchStatistics;
|
|
212
215
|
}
|
|
@@ -267,6 +270,11 @@ export interface Postcondition {
|
|
|
267
270
|
counts?: string;
|
|
268
271
|
}
|
|
269
272
|
|
|
273
|
+
export interface TraceFailure extends FailureMessage {
|
|
274
|
+
/** What the spec prints as TLC rebuilds the step it then fails to print. */
|
|
275
|
+
output: OutputLine[];
|
|
276
|
+
}
|
|
277
|
+
|
|
270
278
|
/** An evaluation that failed during the search, with the behavior up to the state TLC was working on. */
|
|
271
279
|
export interface EvaluationFailure {
|
|
272
280
|
code: number;
|
|
@@ -283,7 +291,7 @@ export interface EvaluationFailure {
|
|
|
283
291
|
/** The FingerprintException the replay raises, which TLC reports in place of the call stack. */
|
|
284
292
|
fingerprint?: FingerprintFailure;
|
|
285
293
|
/** How TLC reports failing again as it prints the trace, since it can't fingerprint the state. */
|
|
286
|
-
traceFailure?:
|
|
294
|
+
traceFailure?: TraceFailure;
|
|
287
295
|
/** A POSTCONDITION that is false or fails after the trace, which TLC checks as it prints one. */
|
|
288
296
|
postcondition?: Postcondition;
|
|
289
297
|
/** Whether TLC stops before it prints the statistics, as it does for an illegal initial state. */
|
|
@@ -309,7 +317,7 @@ export interface CheckResult {
|
|
|
309
317
|
outDegrees: number[] | undefined;
|
|
310
318
|
/** The smallest distance between two fingerprints, when TLC estimates a collision from them. */
|
|
311
319
|
fingerprintDistance: bigint | undefined;
|
|
312
|
-
/** A temporal property TLC finds violated as it adds
|
|
320
|
+
/** A temporal property TLC finds violated as it adds the state it stopped at to the behavior graph, reported after. */
|
|
313
321
|
additionalViolation?: Violation;
|
|
314
322
|
/** Where TLC's worker fails to add the state to the behavior graph after it reports a violation. */
|
|
315
323
|
liveCallStack?: Expression[];
|
|
@@ -319,21 +327,35 @@ export interface CheckResult {
|
|
|
319
327
|
coverage?: CoverageReport;
|
|
320
328
|
}
|
|
321
329
|
|
|
322
|
-
interface CoveredAction extends SpecAction {
|
|
323
|
-
node: number;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
330
|
interface ReportedViolation extends Omit<Violation, "loopStart"> {
|
|
327
331
|
loopStart?: number;
|
|
328
332
|
}
|
|
329
333
|
|
|
334
|
+
interface CounterExampleOptions {
|
|
335
|
+
isConsole: boolean;
|
|
336
|
+
}
|
|
337
|
+
|
|
330
338
|
const appendTraceOutput = <Traced extends Behavior>(behavior: Traced, lines: OutputLine[]) => ({
|
|
331
339
|
...behavior,
|
|
332
340
|
traceOutput: [...(behavior.traceOutput ?? []), ...lines],
|
|
333
341
|
});
|
|
334
342
|
|
|
343
|
+
const toUnexpectedError = (error: TlaEvaluationError) =>
|
|
344
|
+
new TlaEvaluationError(
|
|
345
|
+
`${isEvalException(error) ? UNEXPECTED_EVAL_EXCEPTION : UNEXPECTED_EXCEPTION}${error.message}`,
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
const getTraceFailure = (error: TlaEvaluationError, output: OutputLine[]): TraceFailure => ({
|
|
349
|
+
...getFailureMessage(
|
|
350
|
+
isEvalException(error)
|
|
351
|
+
? new TlaEvaluationError(`${UNEXPECTED_EVAL_EXCEPTION}${error.message}`)
|
|
352
|
+
: error,
|
|
353
|
+
true,
|
|
354
|
+
),
|
|
355
|
+
output,
|
|
356
|
+
});
|
|
357
|
+
|
|
335
358
|
const STOP_REPLAY = new Error("The replay stopped");
|
|
336
|
-
const STOP_WALK = new Error("The walk stopped");
|
|
337
359
|
|
|
338
360
|
export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
339
361
|
const stateWriter =
|
|
@@ -380,14 +402,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
380
402
|
options.coverage === undefined
|
|
381
403
|
? undefined
|
|
382
404
|
: createCoverage(specification.environment.variables.length);
|
|
383
|
-
const environment
|
|
384
|
-
?
|
|
385
|
-
...specification.environment,
|
|
386
|
-
evaluators: new WeakMap(),
|
|
387
|
-
entryEvaluators: new WeakMap(),
|
|
388
|
-
definitionEvaluators: new WeakMap(),
|
|
389
|
-
coverage,
|
|
390
|
-
}
|
|
405
|
+
const environment = coverage
|
|
406
|
+
? createCoverageEnvironment(specification.environment, coverage)
|
|
391
407
|
: specification.environment;
|
|
392
408
|
const runtime = environment.runtime;
|
|
393
409
|
const is174 = runtime.version === "1.7.4";
|
|
@@ -415,6 +431,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
415
431
|
key.startsWith(`${name}${KEY_SEPARATOR}`),
|
|
416
432
|
),
|
|
417
433
|
});
|
|
434
|
+
const getCoverage = () =>
|
|
435
|
+
coverage?.relations.some((relation) => relation.kind === "next")
|
|
436
|
+
? getCoverageReport(
|
|
437
|
+
coverage,
|
|
438
|
+
environment,
|
|
439
|
+
specification.variableLocations,
|
|
440
|
+
search?.getTlcOrder() ?? [],
|
|
441
|
+
)
|
|
442
|
+
: undefined;
|
|
418
443
|
const createResult = (
|
|
419
444
|
status: CheckStatus,
|
|
420
445
|
violation?: ReportedViolation,
|
|
@@ -435,14 +460,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
435
460
|
initialStates: computedInitialStates,
|
|
436
461
|
outDegrees: undefined,
|
|
437
462
|
fingerprintDistance: undefined,
|
|
438
|
-
coverage:
|
|
439
|
-
? getCoverageReport(
|
|
440
|
-
coverage,
|
|
441
|
-
environment,
|
|
442
|
-
specification.variableLocations,
|
|
443
|
-
search?.getTlcOrder() ?? [],
|
|
444
|
-
)
|
|
445
|
-
: undefined,
|
|
463
|
+
coverage: getCoverage(),
|
|
446
464
|
...(traceSpec !== undefined && { traceSpec }),
|
|
447
465
|
};
|
|
448
466
|
};
|
|
@@ -466,7 +484,12 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
466
484
|
: getFingerprintDistance(runtime.distinctStates, runtime.generatedStates, (visit) =>
|
|
467
485
|
visit(
|
|
468
486
|
search
|
|
469
|
-
? search.getStoredFingerprints(
|
|
487
|
+
? search.getStoredFingerprints(
|
|
488
|
+
exploredStates.length === 0 ? states : states.concat(exploredStates),
|
|
489
|
+
exploredStates.length === 0
|
|
490
|
+
? fingerprintStates
|
|
491
|
+
: fingerprintStates.concat(exploredFingerprintStates),
|
|
492
|
+
)
|
|
470
493
|
: BigInt64Array.from(states, runtime.getFingerprint),
|
|
471
494
|
),
|
|
472
495
|
),
|
|
@@ -479,6 +502,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
479
502
|
() => created.order.getDeclarationOrder("variable"),
|
|
480
503
|
options.onProgress,
|
|
481
504
|
specification.moduleOperators,
|
|
505
|
+
specification.runtimeInvariants,
|
|
482
506
|
);
|
|
483
507
|
const findViolatedAssumption = () =>
|
|
484
508
|
findAssumptionViolation(specification.assumptions, environment);
|
|
@@ -500,19 +524,24 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
500
524
|
specification.moduleOperators.some((operator) => operator.kind === "postcondition");
|
|
501
525
|
const tracedSteps = new WeakMap<TraceStep, TracedStep>();
|
|
502
526
|
const getStepState = (step: TraceStep) => tracedSteps.get(step)?.state ?? step.state;
|
|
527
|
+
// TLC's Worker#doPostCondition and LiveCheck bind CounterExample to the alias of each state, while its initial states and lassos keep the states.
|
|
528
|
+
const getStepAlias = (step: TraceStep) => tracedSteps.get(step)?.alias ?? step.state;
|
|
503
529
|
const getStepAction = (step: TraceStep) => {
|
|
504
530
|
const action = tracedSteps.get(step)?.action;
|
|
505
531
|
return action ? toActionValue(action) : createActionRecord(step.action);
|
|
506
532
|
};
|
|
507
533
|
const checkTracePostconditions = (
|
|
508
534
|
trace: TraceStep[],
|
|
509
|
-
loop:
|
|
535
|
+
loop: CounterExampleLoop | undefined,
|
|
536
|
+
getState: (step: TraceStep) => Record<string, Value>,
|
|
537
|
+
isConsole = true,
|
|
510
538
|
) => {
|
|
511
539
|
if (hasPostconditions) {
|
|
512
540
|
runtime.counterExample = createCounterExample(
|
|
513
|
-
trace.map(
|
|
541
|
+
trace.map(getState),
|
|
514
542
|
trace.slice(1).map(getStepAction),
|
|
515
543
|
loop,
|
|
544
|
+
isConsole,
|
|
516
545
|
);
|
|
517
546
|
}
|
|
518
547
|
const unwitnessed = search.findUnwitnessedPossible();
|
|
@@ -524,12 +553,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
524
553
|
const reportViolation = (
|
|
525
554
|
status: CheckStatus,
|
|
526
555
|
violation: ReportedViolation,
|
|
556
|
+
getState = getStepAlias,
|
|
527
557
|
getLoopAction?: () => Value,
|
|
528
558
|
) => {
|
|
529
559
|
const start = violation.loopStart;
|
|
530
560
|
const checked = checkTracePostconditions(
|
|
531
561
|
violation.trace,
|
|
532
562
|
start === undefined || !getLoopAction ? undefined : { start, action: getLoopAction() },
|
|
563
|
+
getState,
|
|
533
564
|
);
|
|
534
565
|
return createResult(status, {
|
|
535
566
|
...violation,
|
|
@@ -555,61 +586,43 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
555
586
|
const getFingerprintState = search.getFingerprintState;
|
|
556
587
|
// Tool's constructor splits the next-state relation into actions before TLC checks anything.
|
|
557
588
|
const nextActions = getDescription().actions;
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
const addCoverageRelations = (kind: "init" | "next", actions: SpecAction[]) =>
|
|
565
|
-
actions.map((action): CoveredAction => ({
|
|
566
|
-
...action,
|
|
567
|
-
node: coverage
|
|
568
|
-
? addCoverageRelation(
|
|
569
|
-
coverage,
|
|
570
|
-
kind,
|
|
571
|
-
getCoverageLabel(action.name, action.expression, environment),
|
|
572
|
-
action.expression,
|
|
573
|
-
action.scope,
|
|
574
|
-
)
|
|
575
|
-
: -1,
|
|
576
|
-
}));
|
|
577
|
-
const coverageInits = addCoverageRelations("init", coverage ? getDescription().inits : []);
|
|
578
|
-
const coverageActions = addCoverageRelations("next", coverage ? nextActions : []);
|
|
579
|
-
if (coverage) buildCoverage(coverage, environment, getPrimedRanges(coverageActions, environment));
|
|
580
|
-
const walkCoveredSuccessors = (
|
|
581
|
-
action: CoveredAction,
|
|
582
|
-
state: Value[],
|
|
583
|
-
onState: (successor: Value[]) => void,
|
|
584
|
-
) =>
|
|
589
|
+
const covered = coverage && addActionCoverage(coverage, environment, getDescription());
|
|
590
|
+
const coverageInits = covered?.inits ?? [];
|
|
591
|
+
const coverageActions = covered?.actions ?? [];
|
|
592
|
+
const hasCoveredIncompleteSuccessor = (action: CoveredAction, state: Value[]) => {
|
|
593
|
+
let complete = 0;
|
|
594
|
+
let incomplete = 0;
|
|
585
595
|
walkSuccessors(
|
|
586
596
|
action,
|
|
587
597
|
action.node,
|
|
588
598
|
state,
|
|
589
599
|
environment,
|
|
590
|
-
(
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
(partial) => {
|
|
595
|
-
const missing = environment.variables.filter(
|
|
596
|
-
(_variable, index) => partial[index] === undefined,
|
|
597
|
-
);
|
|
598
|
-
throw new TlaIncompleteSuccessorError(
|
|
599
|
-
`Successor state is not completely specified by action ${action.name}. The following variables are not assigned: ${missing.join(", ")}`,
|
|
600
|
-
partial,
|
|
601
|
-
action.name,
|
|
602
|
-
missing,
|
|
603
|
-
);
|
|
600
|
+
() => complete++,
|
|
601
|
+
() => {
|
|
602
|
+
incomplete++;
|
|
603
|
+
return true;
|
|
604
604
|
},
|
|
605
605
|
);
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
walkCoveredSuccessors(action, state, (successor) =>
|
|
609
|
-
successors.push({ state: successor, action: action.name }),
|
|
610
|
-
);
|
|
611
|
-
return successors;
|
|
606
|
+
if (coverage) coverage.primary[action.node] += complete + incomplete;
|
|
607
|
+
return incomplete > 0;
|
|
612
608
|
};
|
|
609
|
+
// TLC generates the successors of each action again, which its coverage counts.
|
|
610
|
+
const findSuccessorAction = (state: Value[], isMatch: (successor: Successor) => boolean) =>
|
|
611
|
+
coverage
|
|
612
|
+
? coverageActions.find((item) => {
|
|
613
|
+
const successors: Successor[] = [];
|
|
614
|
+
walkCoveredSuccessors(coverage, item, state, environment, (successor) =>
|
|
615
|
+
successors.push({ state: successor, action: item.name }),
|
|
616
|
+
);
|
|
617
|
+
return successors.some(isMatch);
|
|
618
|
+
})
|
|
619
|
+
: nextActions.find((item) =>
|
|
620
|
+
getSuccessors(item.expression, state, environment, item.scope).some(isMatch),
|
|
621
|
+
);
|
|
622
|
+
runtime.getSuccessorAction = (state, next) =>
|
|
623
|
+
findSuccessorAction(state, (successor) =>
|
|
624
|
+
successor.state.every((value, index) => isSameValue(value, next[index])),
|
|
625
|
+
);
|
|
613
626
|
const rejectIncompleteInitialState = (partial: (Value | undefined)[]) => {
|
|
614
627
|
throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
|
|
615
628
|
};
|
|
@@ -628,8 +641,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
628
641
|
return (state: Value[], callStack: CallStack | undefined) => {
|
|
629
642
|
fingerprintReplayed(state, getFingerprintState(state), callStack);
|
|
630
643
|
const fingerprintState = getFingerprintState(state);
|
|
644
|
+
const hash = getStateHash(fingerprintState);
|
|
631
645
|
const isSeen =
|
|
632
|
-
findStateIndex(seenStates,
|
|
646
|
+
findStateIndex(seenStates, hash, fingerprintState) !== -1 ||
|
|
647
|
+
isExplored(hash, fingerprintState) ||
|
|
633
648
|
replayed.some((seen) => isSameState(seen, fingerprintState));
|
|
634
649
|
if (isSeen) return false;
|
|
635
650
|
replayed.push(fingerprintState);
|
|
@@ -642,7 +657,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
642
657
|
const deferred: unknown[] = [];
|
|
643
658
|
const addReplayed = createReplayedStates();
|
|
644
659
|
return getReplayFailure(environment, (tracing) => {
|
|
645
|
-
replayInitialStates(getDescription().inits, tracing, (state) => {
|
|
660
|
+
replayInitialStates(coverage ? coverageInits : getDescription().inits, tracing, (state) => {
|
|
646
661
|
reportInitialStatesProgress(replayedCount, (progress) => capturedLines?.push(progress));
|
|
647
662
|
replayedCount++;
|
|
648
663
|
runtime.generatedStates = replayedCount;
|
|
@@ -653,16 +668,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
653
668
|
runtime.queueSize++;
|
|
654
669
|
liveness?.addInitialState(states.length, state, tracing);
|
|
655
670
|
};
|
|
656
|
-
|
|
657
|
-
if (violation) {
|
|
671
|
+
search.checkReplayedInitialState(state, tracing, addFingerprint, (violation) => {
|
|
658
672
|
const traced = traces.toTrace([{ action: undefined, state }], []).trace[0].state;
|
|
659
673
|
capturedLines?.push({
|
|
660
674
|
kind: "initial-state-violation",
|
|
661
675
|
...violation,
|
|
662
676
|
state: traced,
|
|
663
677
|
});
|
|
664
|
-
|
|
665
|
-
|
|
678
|
+
if (!options.isContinued || violation.status !== "invariant-violation") {
|
|
679
|
+
throw STOP_REPLAY;
|
|
680
|
+
}
|
|
681
|
+
});
|
|
666
682
|
} catch (error) {
|
|
667
683
|
const isFingerprintFailure =
|
|
668
684
|
error instanceof TlaEvaluationError && tracing.callStack?.fingerprint !== undefined;
|
|
@@ -678,7 +694,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
678
694
|
const state = states[index];
|
|
679
695
|
const source = stateWriter && getGraphState(state, depths[index]);
|
|
680
696
|
const addReplayed = createReplayedStates();
|
|
681
|
-
replaySuccessors(nextActions, state, tracing, (next, action) => {
|
|
697
|
+
replaySuccessors(coverage ? coverageActions : nextActions, state, tracing, (next, action) => {
|
|
682
698
|
const addFingerprint = () => {
|
|
683
699
|
const isUnseen = addReplayed(next, tracing.callStack);
|
|
684
700
|
if (source) {
|
|
@@ -704,6 +720,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
704
720
|
isConstrained: search.isConstrained,
|
|
705
721
|
});
|
|
706
722
|
}
|
|
723
|
+
let liveState: Value[] = [];
|
|
724
|
+
const addIncomplete = (successor: State, action: string | undefined) => {
|
|
725
|
+
if (
|
|
726
|
+
search.satisfiesConstraints(successor, liveState) &&
|
|
727
|
+
search.satisfiesActionConstraints(liveState, successor)
|
|
728
|
+
) {
|
|
729
|
+
throw createIncompleteSuccessorError(successor, action, environment);
|
|
730
|
+
}
|
|
731
|
+
};
|
|
707
732
|
const liveness = withLivenessExitCode(() =>
|
|
708
733
|
withUnexpectedException(() =>
|
|
709
734
|
createLivenessChecker(search.properties.liveness, spec.temporals, environment, {
|
|
@@ -711,37 +736,67 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
711
736
|
(tlcFingerprints[successor.index] ??= Number(
|
|
712
737
|
BigInt.asIntN(32, runtime.getFingerprint(successor.state)),
|
|
713
738
|
)),
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
const
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
739
|
+
forEachActionSuccessors: (source, state, onSuccessors, replay) => {
|
|
740
|
+
liveState = state;
|
|
741
|
+
let successors: LiveSuccessor[] = [];
|
|
742
|
+
const addSuccessor = (successor: Value[]) => {
|
|
743
|
+
canonicalizeState(successor);
|
|
744
|
+
const isInModel =
|
|
745
|
+
search.satisfiesConstraints(successor, state) &&
|
|
746
|
+
search.satisfiesActionConstraints(state, successor);
|
|
747
|
+
if (!isInModel) return;
|
|
748
|
+
const fingerprintState = getFingerprintState(successor);
|
|
749
|
+
const hash = getStateHash(fingerprintState);
|
|
750
|
+
const index = findStateIndex(seenStates, hash, fingerprintState);
|
|
751
|
+
successors.push({
|
|
752
|
+
index: index === -1 ? getPendingIndex(hash, fingerprintState) : index,
|
|
753
|
+
state: successor,
|
|
754
|
+
});
|
|
755
|
+
};
|
|
756
|
+
const visitSuccessor = (successor: Successor) => {
|
|
757
|
+
addSuccessor(successor.state);
|
|
758
|
+
return false;
|
|
759
|
+
};
|
|
760
|
+
const actionCount = coverage ? coverageActions.length : nextActions.length;
|
|
761
|
+
for (let position = 0; position < actionCount; position++) {
|
|
762
|
+
successors = [];
|
|
763
|
+
const livenessSource = current.livenessSource;
|
|
764
|
+
current.livenessSource = source;
|
|
765
|
+
try {
|
|
766
|
+
if (coverage) {
|
|
767
|
+
// TLC's coverage counts the successors of each action the graph generates again.
|
|
768
|
+
walkCoveredSuccessors(
|
|
769
|
+
coverage,
|
|
770
|
+
coverageActions[position],
|
|
771
|
+
state,
|
|
772
|
+
replay ?? environment,
|
|
773
|
+
addSuccessor,
|
|
774
|
+
addIncomplete,
|
|
775
|
+
);
|
|
776
|
+
} else if (replay) {
|
|
777
|
+
const action = nextActions[position];
|
|
778
|
+
walkSuccessors(action, -1, state, replay, addSuccessor, (partial) => {
|
|
779
|
+
addIncomplete(partial, action.name);
|
|
780
|
+
return true;
|
|
736
781
|
});
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
782
|
+
} else {
|
|
783
|
+
const action = nextActions[position];
|
|
784
|
+
forEachSuccessor(
|
|
785
|
+
action.expression,
|
|
786
|
+
state,
|
|
787
|
+
environment,
|
|
788
|
+
visitSuccessor,
|
|
789
|
+
action.scope,
|
|
790
|
+
undefined,
|
|
791
|
+
undefined,
|
|
792
|
+
addIncomplete,
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
} finally {
|
|
796
|
+
current.livenessSource = livenessSource;
|
|
797
|
+
}
|
|
798
|
+
onSuccessors(successors);
|
|
743
799
|
}
|
|
744
|
-
return successors;
|
|
745
800
|
},
|
|
746
801
|
}),
|
|
747
802
|
),
|
|
@@ -756,6 +811,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
756
811
|
const actions: (string | undefined)[] = [];
|
|
757
812
|
const depths: number[] = [];
|
|
758
813
|
const seenStates = createStateTable(fingerprintStates);
|
|
814
|
+
const exploredStates: Value[][] = [];
|
|
815
|
+
const exploredFingerprintStates: Value[][] = [];
|
|
816
|
+
let exploredTable: StateTable | undefined;
|
|
817
|
+
const isExplored = (hash: number, fingerprintState: Value[]) =>
|
|
818
|
+
exploredTable !== undefined && findStateIndex(exploredTable, hash, fingerprintState) !== -1;
|
|
759
819
|
const pendingFingerprintStates: Value[][] = [];
|
|
760
820
|
let pendingStates: StateTable | undefined;
|
|
761
821
|
const getPendingIndex = (hash: number, fingerprintState: Value[]) => {
|
|
@@ -768,13 +828,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
768
828
|
}
|
|
769
829
|
return -2 - position;
|
|
770
830
|
};
|
|
771
|
-
|
|
831
|
+
// TLC's states keep their own values, and coverage charges the cost model each value carries.
|
|
832
|
+
const canonicalizeState = coverage ? (state: Value[]) => state : createCanonicalizer();
|
|
772
833
|
|
|
773
834
|
const toRecord = search.toRecord;
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
835
|
+
const getUncoveredInitialStates = () =>
|
|
836
|
+
spec.init === undefined ? [] : getInitialStates(spec.init, environment, spec.scope);
|
|
837
|
+
const getSpecInitialStates = () =>
|
|
838
|
+
coverage ? getCoveredInitialStates() : getUncoveredInitialStates();
|
|
778
839
|
const isUnfingerprintable = (state: Value[]) => {
|
|
779
840
|
try {
|
|
780
841
|
return getFingerprintState(state).some((value) => getFingerprintError(value) !== undefined);
|
|
@@ -783,19 +844,27 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
783
844
|
return true;
|
|
784
845
|
}
|
|
785
846
|
};
|
|
847
|
+
const checkFailedTrace = (behavior: Behavior, counterExample?: CounterExampleOptions) => {
|
|
848
|
+
if (!counterExample) return { behavior, postcondition: undefined };
|
|
849
|
+
const checked = checkTracePostconditions(
|
|
850
|
+
behavior.trace,
|
|
851
|
+
undefined,
|
|
852
|
+
getStepAlias,
|
|
853
|
+
counterExample.isConsole,
|
|
854
|
+
);
|
|
855
|
+
return {
|
|
856
|
+
behavior: appendTraceOutput(behavior, checked.lines),
|
|
857
|
+
postcondition: checked.unwitnessed ?? checked.postcondition,
|
|
858
|
+
};
|
|
859
|
+
};
|
|
786
860
|
const createFailureResult = (
|
|
787
861
|
failed: unknown,
|
|
788
862
|
behavior: Behavior,
|
|
789
863
|
failureOptions: FailureOptions = {},
|
|
864
|
+
postcondition?: Postcondition,
|
|
790
865
|
) => {
|
|
791
866
|
const error = isStackOverflow(failed) ? new TlaStackOverflowError() : failed;
|
|
792
867
|
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
793
|
-
const checked =
|
|
794
|
-
behavior.trace.length > 0 && !failureOptions.traceFailure
|
|
795
|
-
? checkTracePostconditions(behavior.trace, undefined)
|
|
796
|
-
: undefined;
|
|
797
|
-
const postcondition = checked?.unwitnessed ?? checked?.postcondition;
|
|
798
|
-
const traceOutput = [...(behavior.traceOutput ?? []), ...(checked?.lines ?? [])];
|
|
799
868
|
return {
|
|
800
869
|
...createResult("error", undefined, {
|
|
801
870
|
...getFailureMessage(
|
|
@@ -803,7 +872,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
803
872
|
failureOptions.phase !== undefined && failureOptions.phase !== "initial",
|
|
804
873
|
),
|
|
805
874
|
...behavior,
|
|
806
|
-
...(traceOutput.length > 0 && { traceOutput }),
|
|
807
875
|
...(postcondition && { postcondition }),
|
|
808
876
|
initialState:
|
|
809
877
|
failureOptions.initialState && !(error instanceof TlaModuleError)
|
|
@@ -818,29 +886,70 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
818
886
|
outDegrees: failureOptions.outDegrees,
|
|
819
887
|
};
|
|
820
888
|
};
|
|
821
|
-
|
|
889
|
+
// Deviation from TLC: Worker#doPostCondition throws an ArrayIndexOutOfBoundsException at an incomplete successor, where tla-ts checks the postconditions with the successor in CounterExample.
|
|
890
|
+
const reportIncompleteSuccessor = (
|
|
891
|
+
index: number,
|
|
892
|
+
error: TlaIncompleteSuccessorError,
|
|
893
|
+
liveSuccessors: LiveSuccessor[],
|
|
894
|
+
) => {
|
|
822
895
|
runtime.generatedStates++;
|
|
823
|
-
const
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
896
|
+
const found = captureOutput(() => {
|
|
897
|
+
try {
|
|
898
|
+
return {
|
|
899
|
+
action: coverage
|
|
900
|
+
? coverageActions.find((item) => hasCoveredIncompleteSuccessor(item, states[index]))
|
|
901
|
+
: nextActions.find((item) =>
|
|
902
|
+
hasIncompleteSuccessor(item.expression, states[index], environment, item.scope),
|
|
903
|
+
),
|
|
904
|
+
failed: undefined,
|
|
905
|
+
};
|
|
906
|
+
} catch (failed) {
|
|
907
|
+
if (!(failed instanceof TlaEvaluationError)) throw failed;
|
|
908
|
+
return { action: undefined, failed };
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
const action = found.result.action;
|
|
912
|
+
const traceFailure = found.result.failed && getTraceFailure(found.result.failed, found.lines);
|
|
835
913
|
const message = getIncompleteSuccessorMessage(
|
|
836
914
|
error.variables,
|
|
837
915
|
error.action,
|
|
838
916
|
nextActions.length,
|
|
839
917
|
options.version,
|
|
840
918
|
);
|
|
841
|
-
const
|
|
842
|
-
const
|
|
843
|
-
|
|
919
|
+
const live = captureOutput(() => addFailedLiveState(index, liveSuccessors));
|
|
920
|
+
const trace = traces.getStateTrace(index, {
|
|
921
|
+
incomplete: error.state,
|
|
922
|
+
isPrintedOnly: true,
|
|
923
|
+
}).trace;
|
|
924
|
+
const checked = checkFailedTrace(
|
|
925
|
+
appendTraceOutput(
|
|
926
|
+
{
|
|
927
|
+
trace: traceFailure
|
|
928
|
+
? trace
|
|
929
|
+
: [
|
|
930
|
+
...trace,
|
|
931
|
+
traces.getIncompleteStep(
|
|
932
|
+
error.state,
|
|
933
|
+
trace.length + 1,
|
|
934
|
+
{
|
|
935
|
+
action: error.action,
|
|
936
|
+
label: action && getActionLabel(action, options.version),
|
|
937
|
+
output: found.lines,
|
|
938
|
+
},
|
|
939
|
+
action,
|
|
940
|
+
),
|
|
941
|
+
],
|
|
942
|
+
},
|
|
943
|
+
live.lines,
|
|
944
|
+
),
|
|
945
|
+
{ isConsole: true },
|
|
946
|
+
);
|
|
947
|
+
const failure = createFailureResult(
|
|
948
|
+
error,
|
|
949
|
+
checked.behavior,
|
|
950
|
+
{ callStack: live.result, traceFailure },
|
|
951
|
+
checked.postcondition,
|
|
952
|
+
);
|
|
844
953
|
return withOutDegrees({
|
|
845
954
|
...failure,
|
|
846
955
|
failure: failure.failure && {
|
|
@@ -849,14 +958,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
849
958
|
message,
|
|
850
959
|
toolMessage: message,
|
|
851
960
|
exitCode: EXIT_STATUS.specEvaluationFailure,
|
|
852
|
-
trace: [
|
|
853
|
-
...failure.failure.trace,
|
|
854
|
-
{
|
|
855
|
-
action: error.action,
|
|
856
|
-
label: action && getActionLabel(action, options.version),
|
|
857
|
-
state: toRecord(partial),
|
|
858
|
-
},
|
|
859
|
-
],
|
|
860
961
|
},
|
|
861
962
|
});
|
|
862
963
|
};
|
|
@@ -868,7 +969,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
868
969
|
};
|
|
869
970
|
let unstoredFingerprint: Value[] | undefined;
|
|
870
971
|
const countDistinctState = (depth: number) => {
|
|
871
|
-
runtime.distinctStates = states.length + 1;
|
|
972
|
+
runtime.distinctStates = states.length + exploredStates.length + 1;
|
|
872
973
|
searchDepth = Math.max(searchDepth, depth);
|
|
873
974
|
runtime.diameter = Math.max(runtime.diameter, depth);
|
|
874
975
|
};
|
|
@@ -909,24 +1010,35 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
909
1010
|
tracedSteps,
|
|
910
1011
|
captureOutput,
|
|
911
1012
|
getInitialStates: getSpecInitialStates,
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
? coverageActions.find((item) => getCoveredSuccessors(item, state).some(isMatch))
|
|
915
|
-
: nextActions.find((item) =>
|
|
916
|
-
getSuccessors(item.expression, state, environment, item.scope).some(isMatch),
|
|
917
|
-
),
|
|
1013
|
+
getUncoveredInitialStates,
|
|
1014
|
+
findSuccessorAction,
|
|
918
1015
|
});
|
|
919
1016
|
const getPath = (index: number): Value[][] =>
|
|
920
1017
|
index === -1 ? [] : [...getPath(parents[index]), states[index]];
|
|
1018
|
+
// TLC adds a successor's fingerprint to its set before it checks the invariants of the successor.
|
|
921
1019
|
runtime.isSeen = (state) => {
|
|
922
1020
|
const fingerprintState = getFingerprintState(state);
|
|
923
|
-
|
|
1021
|
+
const hash = getStateHash(fingerprintState);
|
|
1022
|
+
return (
|
|
1023
|
+
findStateIndex(seenStates, hash, fingerprintState) !== -1 ||
|
|
1024
|
+
isExplored(hash, fingerprintState) ||
|
|
1025
|
+
(unstoredFingerprint !== undefined && isSameState(unstoredFingerprint, fingerprintState))
|
|
1026
|
+
);
|
|
1027
|
+
};
|
|
1028
|
+
runtime.markExplored = (state) => {
|
|
1029
|
+
const fingerprintState = getFingerprintState(state);
|
|
1030
|
+
exploredTable ??= createStateTable(exploredFingerprintStates);
|
|
1031
|
+
markSeenState(exploredTable, getStateHash(fingerprintState), exploredStates.length);
|
|
1032
|
+
exploredStates.push(state);
|
|
1033
|
+
exploredFingerprintStates.push(fingerprintState);
|
|
1034
|
+
runtime.distinctStates++;
|
|
924
1035
|
};
|
|
925
1036
|
runtime.getBehavior = (state) => {
|
|
926
1037
|
const index = state === current.candidate ? -1 : states.indexOf(state);
|
|
927
1038
|
return index === -1 ? [...getPath(current.index), state] : getPath(index);
|
|
928
1039
|
};
|
|
929
|
-
runtime.getCurrentState = () =>
|
|
1040
|
+
runtime.getCurrentState = () =>
|
|
1041
|
+
current.rebuilt?.state ?? (current.index === -1 ? undefined : states[current.index]);
|
|
930
1042
|
runtime.setLivenessSource = (index) => {
|
|
931
1043
|
current.livenessSource = index ?? -1;
|
|
932
1044
|
};
|
|
@@ -962,14 +1074,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
962
1074
|
});
|
|
963
1075
|
|
|
964
1076
|
const visitInitialState = (state: Value[]) => {
|
|
965
|
-
canonicalizeState(state);
|
|
966
1077
|
runtime.generatedStates++;
|
|
967
1078
|
runtime.initialStates++;
|
|
968
1079
|
current.candidate = state;
|
|
969
1080
|
current.candidateLevel = 1;
|
|
970
|
-
const fingerprintState = getFingerprintState(state);
|
|
971
|
-
const hash = getStateHash(fingerprintState);
|
|
972
1081
|
const isInModel = search.satisfiesConstraints(state);
|
|
1082
|
+
// TLC fingerprints only a state in the model, which sorts its records in place.
|
|
1083
|
+
if (isInModel) canonicalizeState(state);
|
|
1084
|
+
const fingerprintState = isInModel ? getFingerprintState(state) : state;
|
|
1085
|
+
const hash = isInModel ? getStateHash(fingerprintState) : 0;
|
|
973
1086
|
if (isInModel) {
|
|
974
1087
|
search.trackStatePossible(state);
|
|
975
1088
|
fingerprintModelState(fingerprintState);
|
|
@@ -985,7 +1098,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
985
1098
|
stateWriter?.writeInitialState(getGraphState(state, 1));
|
|
986
1099
|
}
|
|
987
1100
|
if (options.isContinued) {
|
|
988
|
-
search.
|
|
1101
|
+
search.forEachViolatedInvariant(state, (invariant) =>
|
|
989
1102
|
reportContinuedViolation("invariant-violation", {
|
|
990
1103
|
name: invariant.name,
|
|
991
1104
|
...traces.toTrace([{ action: undefined, state }], []),
|
|
@@ -994,17 +1107,19 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
994
1107
|
}
|
|
995
1108
|
const violated = options.isContinued ? undefined : search.findViolatedInvariant(state);
|
|
996
1109
|
if (violated) {
|
|
997
|
-
return reportViolation(
|
|
998
|
-
|
|
999
|
-
...traces.toTrace([{ action: undefined, state }], []),
|
|
1000
|
-
|
|
1110
|
+
return reportViolation(
|
|
1111
|
+
"invariant-violation",
|
|
1112
|
+
{ name: violated.name, ...traces.toTrace([{ action: undefined, state }], []) },
|
|
1113
|
+
getStepState,
|
|
1114
|
+
);
|
|
1001
1115
|
}
|
|
1002
1116
|
const failedPredicate = search.findFailedInitialPredicate(state);
|
|
1003
1117
|
if (failedPredicate) {
|
|
1004
|
-
return reportViolation(
|
|
1005
|
-
|
|
1006
|
-
...traces.toTrace([{ action: undefined, state }], []),
|
|
1007
|
-
|
|
1118
|
+
return reportViolation(
|
|
1119
|
+
"liveness-violation",
|
|
1120
|
+
{ name: failedPredicate.name, ...traces.toTrace([{ action: undefined, state }], []) },
|
|
1121
|
+
getStepState,
|
|
1122
|
+
);
|
|
1008
1123
|
}
|
|
1009
1124
|
if (!isInModel) return undefined;
|
|
1010
1125
|
markSeenState(seenStates, hash, states.length);
|
|
@@ -1014,18 +1129,24 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1014
1129
|
// Looks a successor up, where the constraints keep it in the model, as the search does before it
|
|
1015
1130
|
// checks the successor.
|
|
1016
1131
|
const lookUpSuccessor = (state: Value[], successor: Successor) => {
|
|
1017
|
-
const fingerprintState = getFingerprintState(successor.state);
|
|
1018
|
-
const hash = getStateHash(fingerprintState);
|
|
1019
|
-
const foundIndex = findStateIndex(seenStates, hash, fingerprintState);
|
|
1020
1132
|
const isStateInModel = search.satisfiesConstraints(successor.state, state);
|
|
1021
1133
|
if (isStateInModel) search.trackStatePossible(successor.state);
|
|
1022
1134
|
const isInModel = isStateInModel && search.satisfiesActionConstraints(state, successor.state);
|
|
1135
|
+
const fingerprintState = isInModel ? getFingerprintState(successor.state) : successor.state;
|
|
1136
|
+
const hash = isInModel ? getStateHash(fingerprintState) : 0;
|
|
1023
1137
|
if (isInModel) {
|
|
1024
1138
|
search.trackActionPossible(state, successor.state);
|
|
1025
1139
|
fingerprintModelState(fingerprintState);
|
|
1026
1140
|
successor.state.forEach(markFingerprinted);
|
|
1027
1141
|
}
|
|
1028
|
-
|
|
1142
|
+
const existing = isInModel ? findStateIndex(seenStates, hash, fingerprintState) : -1;
|
|
1143
|
+
return {
|
|
1144
|
+
fingerprintState,
|
|
1145
|
+
hash,
|
|
1146
|
+
isInModel,
|
|
1147
|
+
existing,
|
|
1148
|
+
isSeen: existing !== -1 || (isInModel && isExplored(hash, fingerprintState)),
|
|
1149
|
+
};
|
|
1029
1150
|
};
|
|
1030
1151
|
const visitSuccessor = (
|
|
1031
1152
|
index: number,
|
|
@@ -1044,7 +1165,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1044
1165
|
stateWriter?.writeSuccessor(
|
|
1045
1166
|
source,
|
|
1046
1167
|
getGraphState(successor.state, depths[index] + 1),
|
|
1047
|
-
found.
|
|
1168
|
+
found.isSeen,
|
|
1048
1169
|
action && getGraphAction(action),
|
|
1049
1170
|
);
|
|
1050
1171
|
}
|
|
@@ -1066,7 +1187,13 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1066
1187
|
const isStored = stored.every((value, position) => value === successor.state[position]);
|
|
1067
1188
|
liveSuccessors.push({ index: found.existing, state: isStored ? stored : successor.state });
|
|
1068
1189
|
}
|
|
1069
|
-
|
|
1190
|
+
if (found.isSeen && found.existing === -1 && liveness) {
|
|
1191
|
+
liveSuccessors.push({
|
|
1192
|
+
index: getPendingIndex(found.hash, found.fingerprintState),
|
|
1193
|
+
state: successor.state,
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
const isNew = found.isInModel && !found.isSeen;
|
|
1070
1197
|
if (isNew && liveness) liveSuccessors.push({ index: states.length, state: successor.state });
|
|
1071
1198
|
unstoredFingerprint = isNew ? found.fingerprintState : undefined;
|
|
1072
1199
|
if (isNew) {
|
|
@@ -1074,20 +1201,26 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1074
1201
|
newStateCount++;
|
|
1075
1202
|
if (coverage) coverage.secondary[coveredNode]++;
|
|
1076
1203
|
}
|
|
1077
|
-
if (found.
|
|
1204
|
+
if (!found.isSeen) {
|
|
1078
1205
|
try {
|
|
1079
1206
|
const violated = search.findViolatedInvariant(successor.state, state);
|
|
1080
|
-
const violation = violated && {
|
|
1207
|
+
const violation = violated && {
|
|
1208
|
+
name: violated.name,
|
|
1209
|
+
...traces.getTrace(index, successor, { isPrintedOnly: options.isContinued }),
|
|
1210
|
+
};
|
|
1081
1211
|
if (violation && !options.isContinued) {
|
|
1082
1212
|
return withOutDegrees(reportViolation("invariant-violation", violation));
|
|
1083
1213
|
}
|
|
1084
1214
|
if (violation) reportContinuedViolation("invariant-violation", violation);
|
|
1085
1215
|
} catch (error) {
|
|
1086
1216
|
if (isStackOverflow(error)) throw error;
|
|
1087
|
-
const
|
|
1217
|
+
const behavior = traces.getTrace(index, successor, { isPrintedOnly: true });
|
|
1218
|
+
const replay = is174
|
|
1219
|
+
? captureOutput(() => replayNext(index))
|
|
1220
|
+
: replayFailedNext(index, liveSuccessors);
|
|
1088
1221
|
return createFailureResult(
|
|
1089
1222
|
error,
|
|
1090
|
-
appendTraceOutput(
|
|
1223
|
+
appendTraceOutput(behavior, replay.lines),
|
|
1091
1224
|
replay.result ?? { outDegrees: getFailureOutDegrees() },
|
|
1092
1225
|
);
|
|
1093
1226
|
}
|
|
@@ -1095,7 +1228,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1095
1228
|
const violatedProperty = search.findViolatedActionProperty(state, successor.state);
|
|
1096
1229
|
const propertyViolation = violatedProperty && {
|
|
1097
1230
|
name: violatedProperty.name,
|
|
1098
|
-
...traces.getTrace(index, successor),
|
|
1231
|
+
...traces.getTrace(index, successor, { isPrintedOnly: options.isContinued }),
|
|
1099
1232
|
};
|
|
1100
1233
|
if (propertyViolation && !options.isContinued) {
|
|
1101
1234
|
return withOutDegrees(reportViolation("liveness-violation", propertyViolation));
|
|
@@ -1156,7 +1289,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1156
1289
|
kind: "liveness-started",
|
|
1157
1290
|
branches: liveness.branches,
|
|
1158
1291
|
isComplete: true,
|
|
1159
|
-
states: typed.distinctStates,
|
|
1292
|
+
states: liveness.branches * typed.distinctStates,
|
|
1160
1293
|
statistics,
|
|
1161
1294
|
});
|
|
1162
1295
|
options.onProgress?.({ kind: "liveness-finished" });
|
|
@@ -1220,14 +1353,29 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1220
1353
|
}
|
|
1221
1354
|
} catch (error) {
|
|
1222
1355
|
if (error instanceof TlaIllegalStateError) {
|
|
1356
|
+
reportInitialStatesProgress(runtime.initialStates, options.onProgress);
|
|
1357
|
+
runtime.generatedStates++;
|
|
1358
|
+
runtime.initialStates++;
|
|
1359
|
+
const state = error.state.map((value) => value ?? createModelValue("null"));
|
|
1360
|
+
// Deviation from TLC: CounterExample holds a Java null for an unassigned variable and leaks a NullPointerException, where tla-ts binds the model value null.
|
|
1361
|
+
const checked = checkTracePostconditions(
|
|
1362
|
+
[{ action: undefined, label: undefined, state: toRecord(state) }],
|
|
1363
|
+
undefined,
|
|
1364
|
+
getStepState,
|
|
1365
|
+
);
|
|
1366
|
+
const postcondition = checked.unwitnessed ?? checked.postcondition;
|
|
1223
1367
|
const illegal = createFailureResult(
|
|
1224
1368
|
error,
|
|
1225
|
-
{ trace: [] },
|
|
1226
|
-
{ initialState:
|
|
1369
|
+
{ trace: [], traceOutput: checked.lines },
|
|
1370
|
+
{ initialState: state },
|
|
1227
1371
|
);
|
|
1228
1372
|
return {
|
|
1229
1373
|
...illegal,
|
|
1230
|
-
failure: illegal.failure && {
|
|
1374
|
+
failure: illegal.failure && {
|
|
1375
|
+
...illegal.failure,
|
|
1376
|
+
isWithoutStatistics: true,
|
|
1377
|
+
...(postcondition && { postcondition }),
|
|
1378
|
+
},
|
|
1231
1379
|
};
|
|
1232
1380
|
}
|
|
1233
1381
|
const replay = captureOutput(replayInit);
|
|
@@ -1272,7 +1420,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1272
1420
|
try {
|
|
1273
1421
|
coverageActions.forEach((action) => {
|
|
1274
1422
|
coveredNode = action.node;
|
|
1275
|
-
walkCoveredSuccessors(action, state, (successor) => {
|
|
1423
|
+
walkCoveredSuccessors(coverage, action, state, environment, (successor) => {
|
|
1276
1424
|
successorCount++;
|
|
1277
1425
|
if (onSuccessor({ state: successor, action: action.name }, action)) throw STOP_WALK;
|
|
1278
1426
|
});
|
|
@@ -1313,6 +1461,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1313
1461
|
);
|
|
1314
1462
|
}, 0);
|
|
1315
1463
|
};
|
|
1464
|
+
// Deviation from TLC: Worker#doNextCheckLiveness doesn't catch a FingerprintException from its rerun, so TLC prints the behavior without the failure.
|
|
1316
1465
|
const getLiveCallStack = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1317
1466
|
if (!liveness || is174) return undefined;
|
|
1318
1467
|
const replay = getReplayFailure(environment, (tracing) =>
|
|
@@ -1326,6 +1475,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1326
1475
|
return undefined;
|
|
1327
1476
|
} catch (error) {
|
|
1328
1477
|
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1478
|
+
// TLC fails to fingerprint an incomplete successor with an exception Worker#doNextCheckLiveness doesn't rerun for a call stack.
|
|
1479
|
+
if (error instanceof TlaIncompleteSuccessorError) return undefined;
|
|
1329
1480
|
return getLiveCallStack(index, liveSuccessors);
|
|
1330
1481
|
}
|
|
1331
1482
|
};
|
|
@@ -1336,23 +1487,91 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1336
1487
|
return { result, lines: live.lines };
|
|
1337
1488
|
}
|
|
1338
1489
|
const replay = captureOutput(() => replayNext(index));
|
|
1339
|
-
|
|
1490
|
+
const result: FailureOptions =
|
|
1491
|
+
replay.result ?? (is174 ? {} : { outDegrees: getFailureOutDegrees() });
|
|
1492
|
+
return { result, lines: [...live.lines, ...replay.lines] };
|
|
1340
1493
|
};
|
|
1341
|
-
const
|
|
1342
|
-
|
|
1494
|
+
const getNextFailureTrace = (index: number, counterExample?: CounterExampleOptions) =>
|
|
1495
|
+
checkFailedTrace(
|
|
1496
|
+
traces.getStateTrace(index, { isPrintedOnly: !counterExample }),
|
|
1497
|
+
counterExample,
|
|
1498
|
+
);
|
|
1499
|
+
const reportNextStateOverflow = (index: number, counterExample?: CounterExampleOptions) => {
|
|
1500
|
+
const checked = getNextFailureTrace(index, counterExample);
|
|
1501
|
+
return createFailureResult(
|
|
1502
|
+
createStackOverflowError(),
|
|
1503
|
+
checked.behavior,
|
|
1504
|
+
{ phase: "next" },
|
|
1505
|
+
checked.postcondition,
|
|
1506
|
+
);
|
|
1507
|
+
};
|
|
1508
|
+
// Deviation from TLC: under -continue, TLC's Worker reports a state whose next-state relation failed as deadlocked, or else reports the failure twice as its replay fails again.
|
|
1509
|
+
// Deviation from TLC: under -continue, ModelChecker#doNextEvalFailed rethrows a failed invariant to Worker#doNextFailed, which reports it again with the code of its error.
|
|
1343
1510
|
const reportNextStateFailure = (
|
|
1344
1511
|
error: unknown,
|
|
1345
1512
|
index: number,
|
|
1346
1513
|
liveSuccessors: LiveSuccessor[],
|
|
1514
|
+
generated: number,
|
|
1347
1515
|
) => {
|
|
1348
|
-
|
|
1516
|
+
// TLC's Worker goes on to find a state without successors deadlocked after it fails, which checks the postconditions.
|
|
1517
|
+
const counterExample =
|
|
1518
|
+
config.checkDeadlock && runtime.generatedStates === generated
|
|
1519
|
+
? { isConsole: false }
|
|
1520
|
+
: undefined;
|
|
1521
|
+
if (isStackOverflow(error)) return reportNextStateOverflow(index, counterExample);
|
|
1522
|
+
const checked = getNextFailureTrace(index, counterExample);
|
|
1349
1523
|
const replay = replayFailedNext(index, liveSuccessors);
|
|
1350
1524
|
return createFailureResult(
|
|
1351
1525
|
withNextStateExitCode(error),
|
|
1352
|
-
appendTraceOutput(
|
|
1526
|
+
appendTraceOutput(checked.behavior, replay.lines),
|
|
1353
1527
|
{ phase: "next", ...replay.result },
|
|
1528
|
+
checked.postcondition,
|
|
1529
|
+
);
|
|
1530
|
+
};
|
|
1531
|
+
const addLiveState = (
|
|
1532
|
+
index: number,
|
|
1533
|
+
liveSuccessors: LiveSuccessor[],
|
|
1534
|
+
source: GraphState | undefined,
|
|
1535
|
+
) => {
|
|
1536
|
+
if (liveness && source && (is174 || options.dump?.stuttering)) {
|
|
1537
|
+
stateWriter?.writeStuttering(source);
|
|
1538
|
+
}
|
|
1539
|
+
const accepted = liveness?.addState(index, states[index], liveSuccessors);
|
|
1540
|
+
if (!liveness || !accepted) return undefined;
|
|
1541
|
+
// Deviation from TLC: under -continue, TLC's LiveCheck throws an InvariantViolatedException after it reports the property, which its Worker reports as unexpected.
|
|
1542
|
+
const steps = traces.getPathSteps(accepted);
|
|
1543
|
+
const properties = getViolatedProperties(
|
|
1544
|
+
liveness,
|
|
1545
|
+
steps.map((step) => step.state),
|
|
1546
|
+
steps.length - 1,
|
|
1354
1547
|
);
|
|
1548
|
+
return reportViolation("property-violation", {
|
|
1549
|
+
name: properties[0],
|
|
1550
|
+
properties,
|
|
1551
|
+
...traces.toTrace(steps, accepted, { known: 0 }),
|
|
1552
|
+
});
|
|
1355
1553
|
};
|
|
1554
|
+
const addReportedLiveState = (
|
|
1555
|
+
index: number,
|
|
1556
|
+
liveSuccessors: LiveSuccessor[],
|
|
1557
|
+
source: GraphState | undefined,
|
|
1558
|
+
) =>
|
|
1559
|
+
captureOutput(() => {
|
|
1560
|
+
try {
|
|
1561
|
+
return {
|
|
1562
|
+
additional: addLiveState(index, liveSuccessors, source)?.violation,
|
|
1563
|
+
isFailed: false,
|
|
1564
|
+
callStack: undefined,
|
|
1565
|
+
};
|
|
1566
|
+
} catch (error) {
|
|
1567
|
+
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1568
|
+
return {
|
|
1569
|
+
additional: undefined,
|
|
1570
|
+
isFailed: true,
|
|
1571
|
+
callStack: getLiveCallStack(index, liveSuccessors),
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
});
|
|
1356
1575
|
const expandState = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1357
1576
|
const state = states[index];
|
|
1358
1577
|
const source = stateWriter && getGraphState(state, depths[index]);
|
|
@@ -1374,10 +1593,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1374
1593
|
outcome = reportNextStateOverflow(index);
|
|
1375
1594
|
return true;
|
|
1376
1595
|
}
|
|
1377
|
-
const replay = is174
|
|
1378
|
-
? captureOutput(() => replayNext(index))
|
|
1379
|
-
: replayFailedNext(index, liveSuccessors);
|
|
1380
1596
|
if (is174 && error instanceof TlaEvaluationError && !isHeadedError(error)) {
|
|
1597
|
+
const replay = captureOutput(() => replayNext(index));
|
|
1381
1598
|
outcome = createFailureResult(
|
|
1382
1599
|
new TlaEvaluationError(`${getWrappedException(error)}${error.message}`, error),
|
|
1383
1600
|
appendTraceOutput({ trace: [] }, replay.lines),
|
|
@@ -1385,72 +1602,61 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1385
1602
|
);
|
|
1386
1603
|
return true;
|
|
1387
1604
|
}
|
|
1388
|
-
const
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
? getFailureMessage(
|
|
1392
|
-
isEvalException(error)
|
|
1393
|
-
? new TlaEvaluationError(`${UNEXPECTED_EVAL_EXCEPTION}${error.message}`)
|
|
1394
|
-
: error,
|
|
1395
|
-
true,
|
|
1396
|
-
)
|
|
1605
|
+
const traceError =
|
|
1606
|
+
error instanceof TlaEvaluationError && isUnfingerprintable(successor.state)
|
|
1607
|
+
? error
|
|
1397
1608
|
: undefined;
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1609
|
+
const behavior = traceError
|
|
1610
|
+
? traces.getStateTrace(index, { isPrintedOnly: true })
|
|
1611
|
+
: traces.getTrace(index, successor, { isPrintedOnly: true });
|
|
1612
|
+
const traceFailure =
|
|
1613
|
+
traceError &&
|
|
1614
|
+
getTraceFailure(
|
|
1615
|
+
traceError,
|
|
1616
|
+
captureOutput(() => {
|
|
1617
|
+
try {
|
|
1618
|
+
traces.findStepAction(index, state, successor.state, true);
|
|
1619
|
+
} catch (failed) {
|
|
1620
|
+
if (!(failed instanceof TlaEvaluationError)) throw failed;
|
|
1621
|
+
}
|
|
1622
|
+
}).lines,
|
|
1623
|
+
);
|
|
1624
|
+
const replay = is174
|
|
1625
|
+
? captureOutput(() => replayNext(index))
|
|
1626
|
+
: replayFailedNext(index, liveSuccessors);
|
|
1627
|
+
outcome = createFailureResult(error, appendTraceOutput(behavior, replay.lines), {
|
|
1628
|
+
phase: "next",
|
|
1629
|
+
...replay.result,
|
|
1630
|
+
traceFailure,
|
|
1631
|
+
});
|
|
1406
1632
|
}
|
|
1407
1633
|
return outcome !== undefined;
|
|
1408
1634
|
});
|
|
1409
1635
|
current.isExpanding = false;
|
|
1410
1636
|
const result = outcome;
|
|
1411
1637
|
if (result?.violation && !is174) {
|
|
1412
|
-
const live =
|
|
1638
|
+
const live = addReportedLiveState(index, liveSuccessors, source);
|
|
1413
1639
|
return {
|
|
1414
1640
|
...result,
|
|
1415
1641
|
violation: appendTraceOutput(result.violation, live.lines),
|
|
1416
|
-
|
|
1642
|
+
// TLC adds the state to the behavior graph before it reports the coverage.
|
|
1643
|
+
coverage: getCoverage(),
|
|
1644
|
+
...(live.result.additional && { additionalViolation: live.result.additional }),
|
|
1645
|
+
...(live.result.callStack && { liveCallStack: live.result.callStack }),
|
|
1417
1646
|
};
|
|
1418
1647
|
}
|
|
1419
1648
|
if (result) return result;
|
|
1420
|
-
const addLiveState = () => {
|
|
1421
|
-
if (liveness && source && (is174 || options.dump?.stuttering)) {
|
|
1422
|
-
stateWriter?.writeStuttering(source);
|
|
1423
|
-
}
|
|
1424
|
-
const accepted = liveness?.addState(index, state, liveSuccessors);
|
|
1425
|
-
if (!liveness || !accepted) return undefined;
|
|
1426
|
-
const steps = traces.getPathSteps(accepted);
|
|
1427
|
-
const properties = getViolatedProperties(
|
|
1428
|
-
liveness,
|
|
1429
|
-
steps.map((step) => step.state),
|
|
1430
|
-
steps.length - 1,
|
|
1431
|
-
);
|
|
1432
|
-
return reportViolation("property-violation", {
|
|
1433
|
-
name: properties[0],
|
|
1434
|
-
properties,
|
|
1435
|
-
...traces.toTrace(steps, accepted, { known: 0 }),
|
|
1436
|
-
});
|
|
1437
|
-
};
|
|
1438
1649
|
if (successorCount === 0 && config.checkDeadlock) {
|
|
1439
1650
|
const deadlock = reportViolation("deadlock", {
|
|
1440
1651
|
name: "deadlock",
|
|
1441
1652
|
...traces.getStateTrace(index),
|
|
1442
1653
|
});
|
|
1443
|
-
const live =
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
}
|
|
1450
|
-
});
|
|
1451
|
-
const reported = deadlock.violation
|
|
1452
|
-
? { ...deadlock, violation: appendTraceOutput(deadlock.violation, live.lines) }
|
|
1453
|
-
: deadlock;
|
|
1654
|
+
const live = addReportedLiveState(index, liveSuccessors, source);
|
|
1655
|
+
const reported = {
|
|
1656
|
+
...deadlock,
|
|
1657
|
+
violation: deadlock.violation && appendTraceOutput(deadlock.violation, live.lines),
|
|
1658
|
+
coverage: getCoverage(),
|
|
1659
|
+
};
|
|
1454
1660
|
const counted = withOutDegrees(
|
|
1455
1661
|
reported,
|
|
1456
1662
|
live.result.isFailed ? getFailureOutDegrees() : getPartialOutDegrees(),
|
|
@@ -1460,14 +1666,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1460
1666
|
return live.result.callStack ? { ...counted, liveCallStack: live.result.callStack } : counted;
|
|
1461
1667
|
}
|
|
1462
1668
|
try {
|
|
1463
|
-
return addLiveState();
|
|
1669
|
+
return addLiveState(index, liveSuccessors, source);
|
|
1464
1670
|
} catch (error) {
|
|
1465
1671
|
if (is174 && error instanceof TlaEvaluationError) {
|
|
1466
|
-
const unexpected = new TlaEvaluationError(
|
|
1467
|
-
`${isEvalException(error) ? UNEXPECTED_EVAL_EXCEPTION : UNEXPECTED_EXCEPTION}${error.message}`,
|
|
1468
|
-
);
|
|
1469
1672
|
return createFailureResult(
|
|
1470
|
-
setExitCode(
|
|
1673
|
+
setExitCode(toUnexpectedError(error), EXIT_STATUS.error),
|
|
1471
1674
|
{ trace: [] },
|
|
1472
1675
|
{ outDegrees: getFailureOutDegrees() },
|
|
1473
1676
|
);
|
|
@@ -1475,7 +1678,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1475
1678
|
const replay = getReplayFailure(environment, (tracing) =>
|
|
1476
1679
|
liveness?.addState(index, state, liveSuccessors, tracing),
|
|
1477
1680
|
);
|
|
1478
|
-
|
|
1681
|
+
const behavior = traces.getStateTrace(index, { isPrintedOnly: true });
|
|
1682
|
+
const replayed = captureOutput(() => replayNext(index));
|
|
1683
|
+
return createFailureResult(error, appendTraceOutput(behavior, replayed.lines), {
|
|
1479
1684
|
outDegrees: getFailureOutDegrees(),
|
|
1480
1685
|
callStack: replay?.callStack.length ? replay.callStack : undefined,
|
|
1481
1686
|
phase: "liveness",
|
|
@@ -1499,10 +1704,20 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1499
1704
|
text: `The stuttering counterexample above may be caused by the absence of a fairness constraint in the behavior specification ${name} defined at ${formatRange(range)}. To rule out such counterexamples, conjoin a suitable fairness constraint to ${name} ${book}`,
|
|
1500
1705
|
};
|
|
1501
1706
|
};
|
|
1707
|
+
const toLivenessFailure = (error: TlaEvaluationError) =>
|
|
1708
|
+
setExitCode(toUnexpectedError(error), EXIT_STATUS.abort);
|
|
1709
|
+
const getLassoSteps = (path: number[]) => {
|
|
1710
|
+
try {
|
|
1711
|
+
return traces.getPathSteps(path);
|
|
1712
|
+
} catch (error) {
|
|
1713
|
+
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1714
|
+
throw toLivenessFailure(error);
|
|
1715
|
+
}
|
|
1716
|
+
};
|
|
1502
1717
|
const reportLasso = (checker: LivenessChecker, lasso: Lasso) => {
|
|
1503
1718
|
const path = [...lasso.prefix, ...lasso.cycle];
|
|
1504
1719
|
const loopStart = lasso.prefix.length;
|
|
1505
|
-
const steps =
|
|
1720
|
+
const steps = getLassoSteps(path);
|
|
1506
1721
|
const trace = traces.toTrace(steps, path, { loopStart, known: 0 }).trace;
|
|
1507
1722
|
const properties = getViolatedProperties(
|
|
1508
1723
|
checker,
|
|
@@ -1512,13 +1727,28 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1512
1727
|
const cycleStart = path[loopStart];
|
|
1513
1728
|
const cycleEnd = path[path.length - 1];
|
|
1514
1729
|
const lastState = steps[steps.length - 1].state;
|
|
1515
|
-
const
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1730
|
+
const isStuttering = cycleStart === cycleEnd;
|
|
1731
|
+
const loop = isStuttering
|
|
1732
|
+
? { result: undefined, lines: [] }
|
|
1733
|
+
: captureOutput(() => traces.findStepAction(cycleEnd, lastState, states[cycleStart], false));
|
|
1734
|
+
const back =
|
|
1735
|
+
isStuttering || loop.result
|
|
1736
|
+
? undefined
|
|
1737
|
+
: traces.findSuccessorWithFingerprint(lastState, cycleEnd, cycleStart);
|
|
1738
|
+
if (!isStuttering && !loop.result && !back) {
|
|
1739
|
+
options.onProgress?.({
|
|
1740
|
+
kind: "violation",
|
|
1741
|
+
status: "property-violation",
|
|
1742
|
+
violation: {
|
|
1743
|
+
name: properties[0],
|
|
1744
|
+
properties,
|
|
1745
|
+
trace,
|
|
1746
|
+
traceOutput: loop.lines,
|
|
1747
|
+
loopStart: undefined,
|
|
1748
|
+
},
|
|
1749
|
+
});
|
|
1750
|
+
throw toLivenessFailure(new TlaEvaluationError(NEXT_RECOVERY_FAILURE));
|
|
1751
|
+
}
|
|
1522
1752
|
return reportViolation(
|
|
1523
1753
|
"liveness-violation",
|
|
1524
1754
|
{
|
|
@@ -1528,40 +1758,44 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1528
1758
|
traceOutput: loop.lines,
|
|
1529
1759
|
loopStart,
|
|
1530
1760
|
loopLabel: loop.result && getActionLabel(loop.result, options.version),
|
|
1531
|
-
warning:
|
|
1761
|
+
warning: isStuttering && lasso.isCycleConstrained ? getStutteringWarning() : undefined,
|
|
1532
1762
|
},
|
|
1763
|
+
getStepState,
|
|
1533
1764
|
() =>
|
|
1534
|
-
|
|
1765
|
+
isStuttering
|
|
1535
1766
|
? getStepAction(trace[trace.length - 1])
|
|
1536
1767
|
: loop.result
|
|
1537
1768
|
? toActionValue(loop.result)
|
|
1538
|
-
: createActionRecord(
|
|
1539
|
-
traces.findSuccessorWithFingerprint(lastState, cycleStart)?.action,
|
|
1540
|
-
),
|
|
1769
|
+
: createActionRecord(back?.action),
|
|
1541
1770
|
);
|
|
1542
1771
|
};
|
|
1543
1772
|
const isPeriodic = liveness !== undefined && (options.livenessCheck ?? "default") === "default";
|
|
1544
1773
|
const startedAt = performance.now();
|
|
1545
1774
|
const periodic = {
|
|
1546
1775
|
at: startedAt + PERIODIC_START,
|
|
1547
|
-
|
|
1776
|
+
checkedCounts: liveness?.getStateCounts().map(() => 1) ?? [],
|
|
1548
1777
|
time: 0,
|
|
1549
1778
|
coverageCount: Math.trunc(options.coverage ?? 0),
|
|
1550
1779
|
};
|
|
1551
|
-
const
|
|
1780
|
+
const getGraphStates = (checker: LivenessChecker) =>
|
|
1781
|
+
checker.getStateCounts().reduce((sum, count) => sum + count, 0);
|
|
1782
|
+
const findPeriodicViolation = (checker: LivenessChecker) => {
|
|
1552
1783
|
const now = performance.now();
|
|
1553
|
-
const
|
|
1784
|
+
const counts = checker.getStateCounts();
|
|
1785
|
+
const isGrown = counts.some(
|
|
1786
|
+
(count, branch) =>
|
|
1787
|
+
(count - periodic.checkedCounts[branch]) / periodic.checkedCounts[branch] > LIVENESS_GROWTH,
|
|
1788
|
+
);
|
|
1554
1789
|
if (!isGrown || periodic.time > (now - startedAt) * LIVENESS_RATIO) return undefined;
|
|
1555
|
-
periodic.
|
|
1556
|
-
if (!liveness) return undefined;
|
|
1790
|
+
periodic.checkedCounts = counts;
|
|
1557
1791
|
options.onProgress?.({
|
|
1558
1792
|
kind: "liveness-started",
|
|
1559
|
-
branches:
|
|
1793
|
+
branches: checker.branches,
|
|
1560
1794
|
isComplete: false,
|
|
1561
|
-
states:
|
|
1795
|
+
states: getGraphStates(checker),
|
|
1562
1796
|
statistics: createResult("success"),
|
|
1563
1797
|
});
|
|
1564
|
-
const lasso =
|
|
1798
|
+
const lasso = checker.findViolation();
|
|
1565
1799
|
if (!lasso) options.onProgress?.({ kind: "liveness-finished" });
|
|
1566
1800
|
periodic.time += performance.now() - now;
|
|
1567
1801
|
return lasso;
|
|
@@ -1674,20 +1908,21 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1674
1908
|
runtime.queueSize = states.length - index - 1;
|
|
1675
1909
|
current.isExpanding = true;
|
|
1676
1910
|
const liveSuccessors: LiveSuccessor[] = [];
|
|
1911
|
+
const generated = runtime.generatedStates;
|
|
1677
1912
|
try {
|
|
1678
1913
|
outcome = expandState(index, liveSuccessors);
|
|
1679
1914
|
} catch (error) {
|
|
1680
1915
|
outcome =
|
|
1681
1916
|
error instanceof TlaIncompleteSuccessorError
|
|
1682
|
-
? reportIncompleteSuccessor(index, error)
|
|
1683
|
-
: reportNextStateFailure(error, index, liveSuccessors);
|
|
1917
|
+
? reportIncompleteSuccessor(index, error, liveSuccessors)
|
|
1918
|
+
: reportNextStateFailure(error, index, liveSuccessors, generated);
|
|
1684
1919
|
}
|
|
1685
1920
|
if (outcome) return outcome;
|
|
1686
1921
|
outDegrees[getOutDegreeBucket()]++;
|
|
1687
1922
|
newStateCount = 0;
|
|
1688
1923
|
if ((isPeriodic || options.onProgress) && performance.now() >= periodic.at) {
|
|
1689
1924
|
periodic.at = performance.now() + PROGRESS_INTERVAL;
|
|
1690
|
-
const lasso = isPeriodic ? findPeriodicViolation(
|
|
1925
|
+
const lasso = isPeriodic && liveness ? findPeriodicViolation(liveness) : undefined;
|
|
1691
1926
|
if (liveness && lasso) return reportLasso(liveness, lasso);
|
|
1692
1927
|
const isCoverageDue = options.coverage !== undefined && periodic.coverageCount === 0;
|
|
1693
1928
|
periodic.coverageCount = isCoverageDue
|
|
@@ -1709,7 +1944,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1709
1944
|
kind: "liveness-started",
|
|
1710
1945
|
branches: finalLiveness.branches,
|
|
1711
1946
|
isComplete: true,
|
|
1712
|
-
states:
|
|
1947
|
+
states: typedLasso
|
|
1948
|
+
? finalLiveness.branches * runtime.distinctStates
|
|
1949
|
+
: getGraphStates(finalLiveness),
|
|
1713
1950
|
statistics: createResult("success"),
|
|
1714
1951
|
});
|
|
1715
1952
|
}
|