tla-ts 0.0.10-dev.d618a2d79 → 0.0.10-dev.e3e5dd576
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 +49 -44
- package/dist/transfer.js +48 -43
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +14 -2
- package/src/bags.ts +50 -29
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +13 -11
- package/src/check-trace.ts +116 -64
- package/src/check.ts +516 -280
- 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 +190 -1
- package/src/dependencies.ts +68 -15
- package/src/dfid.ts +101 -36
- package/src/environment.ts +123 -38
- package/src/errors.ts +7 -0
- package/src/evaluate.ts +370 -99
- package/src/exit-codes.ts +28 -14
- package/src/instances.ts +135 -11
- 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 +51 -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/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 +27 -1
- 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/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 +1 -2
- 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 +1 -2
- package/src/prover/smt/solver/dt2bv-tactic.ts +57 -21
- 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 +5 -8
- 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 +1 -2
- 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/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/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 +1 -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/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/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/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/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 +65 -12
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +129 -43
- 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 +17 -7
- package/src/prover/smt/solver/sat/sat2goal.ts +72 -48
- 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 +713 -210
- package/src/prover/smt/solver/solve-eqs.ts +36 -37
- package/src/prover/smt/solver/solver.ts +18 -3
- package/src/prover/smt/solver/tactic.ts +350 -195
- 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 +11 -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 +1 -0
- 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 +1274 -257
- package/src/runtime.ts +7 -1
- 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 +18 -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 +11 -6
- package/src/sany/xml.ts +2 -3
- package/src/search.ts +319 -135
- package/src/simulate.ts +235 -182
- package/src/spec-description.ts +8 -6
- package/src/standard-definitions.ts +1 -0
- package/src/standard-modules.ts +56 -22
- package/src/subexpressions.ts +564 -138
- package/src/successors.ts +37 -13
- 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 +67 -43
- 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[]) => {
|
|
@@ -771,10 +831,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
771
831
|
const canonicalizeState = createCanonicalizer();
|
|
772
832
|
|
|
773
833
|
const toRecord = search.toRecord;
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
834
|
+
const getUncoveredInitialStates = () =>
|
|
835
|
+
spec.init === undefined ? [] : getInitialStates(spec.init, environment, spec.scope);
|
|
836
|
+
const getSpecInitialStates = () =>
|
|
837
|
+
coverage ? getCoveredInitialStates() : getUncoveredInitialStates();
|
|
778
838
|
const isUnfingerprintable = (state: Value[]) => {
|
|
779
839
|
try {
|
|
780
840
|
return getFingerprintState(state).some((value) => getFingerprintError(value) !== undefined);
|
|
@@ -783,19 +843,27 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
783
843
|
return true;
|
|
784
844
|
}
|
|
785
845
|
};
|
|
846
|
+
const checkFailedTrace = (behavior: Behavior, counterExample?: CounterExampleOptions) => {
|
|
847
|
+
if (!counterExample) return { behavior, postcondition: undefined };
|
|
848
|
+
const checked = checkTracePostconditions(
|
|
849
|
+
behavior.trace,
|
|
850
|
+
undefined,
|
|
851
|
+
getStepAlias,
|
|
852
|
+
counterExample.isConsole,
|
|
853
|
+
);
|
|
854
|
+
return {
|
|
855
|
+
behavior: appendTraceOutput(behavior, checked.lines),
|
|
856
|
+
postcondition: checked.unwitnessed ?? checked.postcondition,
|
|
857
|
+
};
|
|
858
|
+
};
|
|
786
859
|
const createFailureResult = (
|
|
787
860
|
failed: unknown,
|
|
788
861
|
behavior: Behavior,
|
|
789
862
|
failureOptions: FailureOptions = {},
|
|
863
|
+
postcondition?: Postcondition,
|
|
790
864
|
) => {
|
|
791
865
|
const error = isStackOverflow(failed) ? new TlaStackOverflowError() : failed;
|
|
792
866
|
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
867
|
return {
|
|
800
868
|
...createResult("error", undefined, {
|
|
801
869
|
...getFailureMessage(
|
|
@@ -803,7 +871,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
803
871
|
failureOptions.phase !== undefined && failureOptions.phase !== "initial",
|
|
804
872
|
),
|
|
805
873
|
...behavior,
|
|
806
|
-
...(traceOutput.length > 0 && { traceOutput }),
|
|
807
874
|
...(postcondition && { postcondition }),
|
|
808
875
|
initialState:
|
|
809
876
|
failureOptions.initialState && !(error instanceof TlaModuleError)
|
|
@@ -818,29 +885,70 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
818
885
|
outDegrees: failureOptions.outDegrees,
|
|
819
886
|
};
|
|
820
887
|
};
|
|
821
|
-
|
|
888
|
+
// Deviation from TLC: Worker#doPostCondition throws an ArrayIndexOutOfBoundsException at an incomplete successor, where tla-ts checks the postconditions with the successor in CounterExample.
|
|
889
|
+
const reportIncompleteSuccessor = (
|
|
890
|
+
index: number,
|
|
891
|
+
error: TlaIncompleteSuccessorError,
|
|
892
|
+
liveSuccessors: LiveSuccessor[],
|
|
893
|
+
) => {
|
|
822
894
|
runtime.generatedStates++;
|
|
823
|
-
const
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
895
|
+
const found = captureOutput(() => {
|
|
896
|
+
try {
|
|
897
|
+
return {
|
|
898
|
+
action: coverage
|
|
899
|
+
? coverageActions.find((item) => hasCoveredIncompleteSuccessor(item, states[index]))
|
|
900
|
+
: nextActions.find((item) =>
|
|
901
|
+
hasIncompleteSuccessor(item.expression, states[index], environment, item.scope),
|
|
902
|
+
),
|
|
903
|
+
failed: undefined,
|
|
904
|
+
};
|
|
905
|
+
} catch (failed) {
|
|
906
|
+
if (!(failed instanceof TlaEvaluationError)) throw failed;
|
|
907
|
+
return { action: undefined, failed };
|
|
908
|
+
}
|
|
909
|
+
});
|
|
910
|
+
const action = found.result.action;
|
|
911
|
+
const traceFailure = found.result.failed && getTraceFailure(found.result.failed, found.lines);
|
|
835
912
|
const message = getIncompleteSuccessorMessage(
|
|
836
913
|
error.variables,
|
|
837
914
|
error.action,
|
|
838
915
|
nextActions.length,
|
|
839
916
|
options.version,
|
|
840
917
|
);
|
|
841
|
-
const
|
|
842
|
-
const
|
|
843
|
-
|
|
918
|
+
const live = captureOutput(() => addFailedLiveState(index, liveSuccessors));
|
|
919
|
+
const trace = traces.getStateTrace(index, {
|
|
920
|
+
incomplete: error.state,
|
|
921
|
+
isPrintedOnly: true,
|
|
922
|
+
}).trace;
|
|
923
|
+
const checked = checkFailedTrace(
|
|
924
|
+
appendTraceOutput(
|
|
925
|
+
{
|
|
926
|
+
trace: traceFailure
|
|
927
|
+
? trace
|
|
928
|
+
: [
|
|
929
|
+
...trace,
|
|
930
|
+
traces.getIncompleteStep(
|
|
931
|
+
error.state,
|
|
932
|
+
trace.length + 1,
|
|
933
|
+
{
|
|
934
|
+
action: error.action,
|
|
935
|
+
label: action && getActionLabel(action, options.version),
|
|
936
|
+
output: found.lines,
|
|
937
|
+
},
|
|
938
|
+
action,
|
|
939
|
+
),
|
|
940
|
+
],
|
|
941
|
+
},
|
|
942
|
+
live.lines,
|
|
943
|
+
),
|
|
944
|
+
{ isConsole: true },
|
|
945
|
+
);
|
|
946
|
+
const failure = createFailureResult(
|
|
947
|
+
error,
|
|
948
|
+
checked.behavior,
|
|
949
|
+
{ callStack: live.result, traceFailure },
|
|
950
|
+
checked.postcondition,
|
|
951
|
+
);
|
|
844
952
|
return withOutDegrees({
|
|
845
953
|
...failure,
|
|
846
954
|
failure: failure.failure && {
|
|
@@ -849,14 +957,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
849
957
|
message,
|
|
850
958
|
toolMessage: message,
|
|
851
959
|
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
960
|
},
|
|
861
961
|
});
|
|
862
962
|
};
|
|
@@ -868,7 +968,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
868
968
|
};
|
|
869
969
|
let unstoredFingerprint: Value[] | undefined;
|
|
870
970
|
const countDistinctState = (depth: number) => {
|
|
871
|
-
runtime.distinctStates = states.length + 1;
|
|
971
|
+
runtime.distinctStates = states.length + exploredStates.length + 1;
|
|
872
972
|
searchDepth = Math.max(searchDepth, depth);
|
|
873
973
|
runtime.diameter = Math.max(runtime.diameter, depth);
|
|
874
974
|
};
|
|
@@ -909,24 +1009,35 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
909
1009
|
tracedSteps,
|
|
910
1010
|
captureOutput,
|
|
911
1011
|
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
|
-
),
|
|
1012
|
+
getUncoveredInitialStates,
|
|
1013
|
+
findSuccessorAction,
|
|
918
1014
|
});
|
|
919
1015
|
const getPath = (index: number): Value[][] =>
|
|
920
1016
|
index === -1 ? [] : [...getPath(parents[index]), states[index]];
|
|
1017
|
+
// TLC adds a successor's fingerprint to its set before it checks the invariants of the successor.
|
|
921
1018
|
runtime.isSeen = (state) => {
|
|
922
1019
|
const fingerprintState = getFingerprintState(state);
|
|
923
|
-
|
|
1020
|
+
const hash = getStateHash(fingerprintState);
|
|
1021
|
+
return (
|
|
1022
|
+
findStateIndex(seenStates, hash, fingerprintState) !== -1 ||
|
|
1023
|
+
isExplored(hash, fingerprintState) ||
|
|
1024
|
+
(unstoredFingerprint !== undefined && isSameState(unstoredFingerprint, fingerprintState))
|
|
1025
|
+
);
|
|
1026
|
+
};
|
|
1027
|
+
runtime.markExplored = (state) => {
|
|
1028
|
+
const fingerprintState = getFingerprintState(state);
|
|
1029
|
+
exploredTable ??= createStateTable(exploredFingerprintStates);
|
|
1030
|
+
markSeenState(exploredTable, getStateHash(fingerprintState), exploredStates.length);
|
|
1031
|
+
exploredStates.push(state);
|
|
1032
|
+
exploredFingerprintStates.push(fingerprintState);
|
|
1033
|
+
runtime.distinctStates++;
|
|
924
1034
|
};
|
|
925
1035
|
runtime.getBehavior = (state) => {
|
|
926
1036
|
const index = state === current.candidate ? -1 : states.indexOf(state);
|
|
927
1037
|
return index === -1 ? [...getPath(current.index), state] : getPath(index);
|
|
928
1038
|
};
|
|
929
|
-
runtime.getCurrentState = () =>
|
|
1039
|
+
runtime.getCurrentState = () =>
|
|
1040
|
+
current.rebuilt?.state ?? (current.index === -1 ? undefined : states[current.index]);
|
|
930
1041
|
runtime.setLivenessSource = (index) => {
|
|
931
1042
|
current.livenessSource = index ?? -1;
|
|
932
1043
|
};
|
|
@@ -962,14 +1073,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
962
1073
|
});
|
|
963
1074
|
|
|
964
1075
|
const visitInitialState = (state: Value[]) => {
|
|
965
|
-
canonicalizeState(state);
|
|
966
1076
|
runtime.generatedStates++;
|
|
967
1077
|
runtime.initialStates++;
|
|
968
1078
|
current.candidate = state;
|
|
969
1079
|
current.candidateLevel = 1;
|
|
970
|
-
const fingerprintState = getFingerprintState(state);
|
|
971
|
-
const hash = getStateHash(fingerprintState);
|
|
972
1080
|
const isInModel = search.satisfiesConstraints(state);
|
|
1081
|
+
// TLC fingerprints only a state in the model, which sorts its records in place.
|
|
1082
|
+
if (isInModel) canonicalizeState(state);
|
|
1083
|
+
const fingerprintState = isInModel ? getFingerprintState(state) : state;
|
|
1084
|
+
const hash = isInModel ? getStateHash(fingerprintState) : 0;
|
|
973
1085
|
if (isInModel) {
|
|
974
1086
|
search.trackStatePossible(state);
|
|
975
1087
|
fingerprintModelState(fingerprintState);
|
|
@@ -985,7 +1097,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
985
1097
|
stateWriter?.writeInitialState(getGraphState(state, 1));
|
|
986
1098
|
}
|
|
987
1099
|
if (options.isContinued) {
|
|
988
|
-
search.
|
|
1100
|
+
search.forEachViolatedInvariant(state, (invariant) =>
|
|
989
1101
|
reportContinuedViolation("invariant-violation", {
|
|
990
1102
|
name: invariant.name,
|
|
991
1103
|
...traces.toTrace([{ action: undefined, state }], []),
|
|
@@ -994,17 +1106,19 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
994
1106
|
}
|
|
995
1107
|
const violated = options.isContinued ? undefined : search.findViolatedInvariant(state);
|
|
996
1108
|
if (violated) {
|
|
997
|
-
return reportViolation(
|
|
998
|
-
|
|
999
|
-
...traces.toTrace([{ action: undefined, state }], []),
|
|
1000
|
-
|
|
1109
|
+
return reportViolation(
|
|
1110
|
+
"invariant-violation",
|
|
1111
|
+
{ name: violated.name, ...traces.toTrace([{ action: undefined, state }], []) },
|
|
1112
|
+
getStepState,
|
|
1113
|
+
);
|
|
1001
1114
|
}
|
|
1002
1115
|
const failedPredicate = search.findFailedInitialPredicate(state);
|
|
1003
1116
|
if (failedPredicate) {
|
|
1004
|
-
return reportViolation(
|
|
1005
|
-
|
|
1006
|
-
...traces.toTrace([{ action: undefined, state }], []),
|
|
1007
|
-
|
|
1117
|
+
return reportViolation(
|
|
1118
|
+
"liveness-violation",
|
|
1119
|
+
{ name: failedPredicate.name, ...traces.toTrace([{ action: undefined, state }], []) },
|
|
1120
|
+
getStepState,
|
|
1121
|
+
);
|
|
1008
1122
|
}
|
|
1009
1123
|
if (!isInModel) return undefined;
|
|
1010
1124
|
markSeenState(seenStates, hash, states.length);
|
|
@@ -1014,18 +1128,24 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1014
1128
|
// Looks a successor up, where the constraints keep it in the model, as the search does before it
|
|
1015
1129
|
// checks the successor.
|
|
1016
1130
|
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
1131
|
const isStateInModel = search.satisfiesConstraints(successor.state, state);
|
|
1021
1132
|
if (isStateInModel) search.trackStatePossible(successor.state);
|
|
1022
1133
|
const isInModel = isStateInModel && search.satisfiesActionConstraints(state, successor.state);
|
|
1134
|
+
const fingerprintState = isInModel ? getFingerprintState(successor.state) : successor.state;
|
|
1135
|
+
const hash = isInModel ? getStateHash(fingerprintState) : 0;
|
|
1023
1136
|
if (isInModel) {
|
|
1024
1137
|
search.trackActionPossible(state, successor.state);
|
|
1025
1138
|
fingerprintModelState(fingerprintState);
|
|
1026
1139
|
successor.state.forEach(markFingerprinted);
|
|
1027
1140
|
}
|
|
1028
|
-
|
|
1141
|
+
const existing = isInModel ? findStateIndex(seenStates, hash, fingerprintState) : -1;
|
|
1142
|
+
return {
|
|
1143
|
+
fingerprintState,
|
|
1144
|
+
hash,
|
|
1145
|
+
isInModel,
|
|
1146
|
+
existing,
|
|
1147
|
+
isSeen: existing !== -1 || (isInModel && isExplored(hash, fingerprintState)),
|
|
1148
|
+
};
|
|
1029
1149
|
};
|
|
1030
1150
|
const visitSuccessor = (
|
|
1031
1151
|
index: number,
|
|
@@ -1044,7 +1164,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1044
1164
|
stateWriter?.writeSuccessor(
|
|
1045
1165
|
source,
|
|
1046
1166
|
getGraphState(successor.state, depths[index] + 1),
|
|
1047
|
-
found.
|
|
1167
|
+
found.isSeen,
|
|
1048
1168
|
action && getGraphAction(action),
|
|
1049
1169
|
);
|
|
1050
1170
|
}
|
|
@@ -1066,7 +1186,13 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1066
1186
|
const isStored = stored.every((value, position) => value === successor.state[position]);
|
|
1067
1187
|
liveSuccessors.push({ index: found.existing, state: isStored ? stored : successor.state });
|
|
1068
1188
|
}
|
|
1069
|
-
|
|
1189
|
+
if (found.isSeen && found.existing === -1 && liveness) {
|
|
1190
|
+
liveSuccessors.push({
|
|
1191
|
+
index: getPendingIndex(found.hash, found.fingerprintState),
|
|
1192
|
+
state: successor.state,
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
const isNew = found.isInModel && !found.isSeen;
|
|
1070
1196
|
if (isNew && liveness) liveSuccessors.push({ index: states.length, state: successor.state });
|
|
1071
1197
|
unstoredFingerprint = isNew ? found.fingerprintState : undefined;
|
|
1072
1198
|
if (isNew) {
|
|
@@ -1074,20 +1200,26 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1074
1200
|
newStateCount++;
|
|
1075
1201
|
if (coverage) coverage.secondary[coveredNode]++;
|
|
1076
1202
|
}
|
|
1077
|
-
if (found.
|
|
1203
|
+
if (!found.isSeen) {
|
|
1078
1204
|
try {
|
|
1079
1205
|
const violated = search.findViolatedInvariant(successor.state, state);
|
|
1080
|
-
const violation = violated && {
|
|
1206
|
+
const violation = violated && {
|
|
1207
|
+
name: violated.name,
|
|
1208
|
+
...traces.getTrace(index, successor, { isPrintedOnly: options.isContinued }),
|
|
1209
|
+
};
|
|
1081
1210
|
if (violation && !options.isContinued) {
|
|
1082
1211
|
return withOutDegrees(reportViolation("invariant-violation", violation));
|
|
1083
1212
|
}
|
|
1084
1213
|
if (violation) reportContinuedViolation("invariant-violation", violation);
|
|
1085
1214
|
} catch (error) {
|
|
1086
1215
|
if (isStackOverflow(error)) throw error;
|
|
1087
|
-
const
|
|
1216
|
+
const behavior = traces.getTrace(index, successor, { isPrintedOnly: true });
|
|
1217
|
+
const replay = is174
|
|
1218
|
+
? captureOutput(() => replayNext(index))
|
|
1219
|
+
: replayFailedNext(index, liveSuccessors);
|
|
1088
1220
|
return createFailureResult(
|
|
1089
1221
|
error,
|
|
1090
|
-
appendTraceOutput(
|
|
1222
|
+
appendTraceOutput(behavior, replay.lines),
|
|
1091
1223
|
replay.result ?? { outDegrees: getFailureOutDegrees() },
|
|
1092
1224
|
);
|
|
1093
1225
|
}
|
|
@@ -1095,7 +1227,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1095
1227
|
const violatedProperty = search.findViolatedActionProperty(state, successor.state);
|
|
1096
1228
|
const propertyViolation = violatedProperty && {
|
|
1097
1229
|
name: violatedProperty.name,
|
|
1098
|
-
...traces.getTrace(index, successor),
|
|
1230
|
+
...traces.getTrace(index, successor, { isPrintedOnly: options.isContinued }),
|
|
1099
1231
|
};
|
|
1100
1232
|
if (propertyViolation && !options.isContinued) {
|
|
1101
1233
|
return withOutDegrees(reportViolation("liveness-violation", propertyViolation));
|
|
@@ -1156,7 +1288,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1156
1288
|
kind: "liveness-started",
|
|
1157
1289
|
branches: liveness.branches,
|
|
1158
1290
|
isComplete: true,
|
|
1159
|
-
states: typed.distinctStates,
|
|
1291
|
+
states: liveness.branches * typed.distinctStates,
|
|
1160
1292
|
statistics,
|
|
1161
1293
|
});
|
|
1162
1294
|
options.onProgress?.({ kind: "liveness-finished" });
|
|
@@ -1220,14 +1352,29 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1220
1352
|
}
|
|
1221
1353
|
} catch (error) {
|
|
1222
1354
|
if (error instanceof TlaIllegalStateError) {
|
|
1355
|
+
reportInitialStatesProgress(runtime.initialStates, options.onProgress);
|
|
1356
|
+
runtime.generatedStates++;
|
|
1357
|
+
runtime.initialStates++;
|
|
1358
|
+
const state = error.state.map((value) => value ?? createModelValue("null"));
|
|
1359
|
+
// Deviation from TLC: CounterExample holds a Java null for an unassigned variable and leaks a NullPointerException, where tla-ts binds the model value null.
|
|
1360
|
+
const checked = checkTracePostconditions(
|
|
1361
|
+
[{ action: undefined, label: undefined, state: toRecord(state) }],
|
|
1362
|
+
undefined,
|
|
1363
|
+
getStepState,
|
|
1364
|
+
);
|
|
1365
|
+
const postcondition = checked.unwitnessed ?? checked.postcondition;
|
|
1223
1366
|
const illegal = createFailureResult(
|
|
1224
1367
|
error,
|
|
1225
|
-
{ trace: [] },
|
|
1226
|
-
{ initialState:
|
|
1368
|
+
{ trace: [], traceOutput: checked.lines },
|
|
1369
|
+
{ initialState: state },
|
|
1227
1370
|
);
|
|
1228
1371
|
return {
|
|
1229
1372
|
...illegal,
|
|
1230
|
-
failure: illegal.failure && {
|
|
1373
|
+
failure: illegal.failure && {
|
|
1374
|
+
...illegal.failure,
|
|
1375
|
+
isWithoutStatistics: true,
|
|
1376
|
+
...(postcondition && { postcondition }),
|
|
1377
|
+
},
|
|
1231
1378
|
};
|
|
1232
1379
|
}
|
|
1233
1380
|
const replay = captureOutput(replayInit);
|
|
@@ -1272,7 +1419,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1272
1419
|
try {
|
|
1273
1420
|
coverageActions.forEach((action) => {
|
|
1274
1421
|
coveredNode = action.node;
|
|
1275
|
-
walkCoveredSuccessors(action, state, (successor) => {
|
|
1422
|
+
walkCoveredSuccessors(coverage, action, state, environment, (successor) => {
|
|
1276
1423
|
successorCount++;
|
|
1277
1424
|
if (onSuccessor({ state: successor, action: action.name }, action)) throw STOP_WALK;
|
|
1278
1425
|
});
|
|
@@ -1313,6 +1460,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1313
1460
|
);
|
|
1314
1461
|
}, 0);
|
|
1315
1462
|
};
|
|
1463
|
+
// Deviation from TLC: Worker#doNextCheckLiveness doesn't catch a FingerprintException from its rerun, so TLC prints the behavior without the failure.
|
|
1316
1464
|
const getLiveCallStack = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1317
1465
|
if (!liveness || is174) return undefined;
|
|
1318
1466
|
const replay = getReplayFailure(environment, (tracing) =>
|
|
@@ -1326,6 +1474,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1326
1474
|
return undefined;
|
|
1327
1475
|
} catch (error) {
|
|
1328
1476
|
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1477
|
+
// TLC fails to fingerprint an incomplete successor with an exception Worker#doNextCheckLiveness doesn't rerun for a call stack.
|
|
1478
|
+
if (error instanceof TlaIncompleteSuccessorError) return undefined;
|
|
1329
1479
|
return getLiveCallStack(index, liveSuccessors);
|
|
1330
1480
|
}
|
|
1331
1481
|
};
|
|
@@ -1336,23 +1486,91 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1336
1486
|
return { result, lines: live.lines };
|
|
1337
1487
|
}
|
|
1338
1488
|
const replay = captureOutput(() => replayNext(index));
|
|
1339
|
-
|
|
1489
|
+
const result: FailureOptions =
|
|
1490
|
+
replay.result ?? (is174 ? {} : { outDegrees: getFailureOutDegrees() });
|
|
1491
|
+
return { result, lines: [...live.lines, ...replay.lines] };
|
|
1340
1492
|
};
|
|
1341
|
-
const
|
|
1342
|
-
|
|
1493
|
+
const getNextFailureTrace = (index: number, counterExample?: CounterExampleOptions) =>
|
|
1494
|
+
checkFailedTrace(
|
|
1495
|
+
traces.getStateTrace(index, { isPrintedOnly: !counterExample }),
|
|
1496
|
+
counterExample,
|
|
1497
|
+
);
|
|
1498
|
+
const reportNextStateOverflow = (index: number, counterExample?: CounterExampleOptions) => {
|
|
1499
|
+
const checked = getNextFailureTrace(index, counterExample);
|
|
1500
|
+
return createFailureResult(
|
|
1501
|
+
createStackOverflowError(),
|
|
1502
|
+
checked.behavior,
|
|
1503
|
+
{ phase: "next" },
|
|
1504
|
+
checked.postcondition,
|
|
1505
|
+
);
|
|
1506
|
+
};
|
|
1507
|
+
// 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.
|
|
1508
|
+
// 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
1509
|
const reportNextStateFailure = (
|
|
1344
1510
|
error: unknown,
|
|
1345
1511
|
index: number,
|
|
1346
1512
|
liveSuccessors: LiveSuccessor[],
|
|
1513
|
+
generated: number,
|
|
1347
1514
|
) => {
|
|
1348
|
-
|
|
1515
|
+
// TLC's Worker goes on to find a state without successors deadlocked after it fails, which checks the postconditions.
|
|
1516
|
+
const counterExample =
|
|
1517
|
+
config.checkDeadlock && runtime.generatedStates === generated
|
|
1518
|
+
? { isConsole: false }
|
|
1519
|
+
: undefined;
|
|
1520
|
+
if (isStackOverflow(error)) return reportNextStateOverflow(index, counterExample);
|
|
1521
|
+
const checked = getNextFailureTrace(index, counterExample);
|
|
1349
1522
|
const replay = replayFailedNext(index, liveSuccessors);
|
|
1350
1523
|
return createFailureResult(
|
|
1351
1524
|
withNextStateExitCode(error),
|
|
1352
|
-
appendTraceOutput(
|
|
1525
|
+
appendTraceOutput(checked.behavior, replay.lines),
|
|
1353
1526
|
{ phase: "next", ...replay.result },
|
|
1527
|
+
checked.postcondition,
|
|
1528
|
+
);
|
|
1529
|
+
};
|
|
1530
|
+
const addLiveState = (
|
|
1531
|
+
index: number,
|
|
1532
|
+
liveSuccessors: LiveSuccessor[],
|
|
1533
|
+
source: GraphState | undefined,
|
|
1534
|
+
) => {
|
|
1535
|
+
if (liveness && source && (is174 || options.dump?.stuttering)) {
|
|
1536
|
+
stateWriter?.writeStuttering(source);
|
|
1537
|
+
}
|
|
1538
|
+
const accepted = liveness?.addState(index, states[index], liveSuccessors);
|
|
1539
|
+
if (!liveness || !accepted) return undefined;
|
|
1540
|
+
// Deviation from TLC: under -continue, TLC's LiveCheck throws an InvariantViolatedException after it reports the property, which its Worker reports as unexpected.
|
|
1541
|
+
const steps = traces.getPathSteps(accepted);
|
|
1542
|
+
const properties = getViolatedProperties(
|
|
1543
|
+
liveness,
|
|
1544
|
+
steps.map((step) => step.state),
|
|
1545
|
+
steps.length - 1,
|
|
1354
1546
|
);
|
|
1547
|
+
return reportViolation("property-violation", {
|
|
1548
|
+
name: properties[0],
|
|
1549
|
+
properties,
|
|
1550
|
+
...traces.toTrace(steps, accepted, { known: 0 }),
|
|
1551
|
+
});
|
|
1355
1552
|
};
|
|
1553
|
+
const addReportedLiveState = (
|
|
1554
|
+
index: number,
|
|
1555
|
+
liveSuccessors: LiveSuccessor[],
|
|
1556
|
+
source: GraphState | undefined,
|
|
1557
|
+
) =>
|
|
1558
|
+
captureOutput(() => {
|
|
1559
|
+
try {
|
|
1560
|
+
return {
|
|
1561
|
+
additional: addLiveState(index, liveSuccessors, source)?.violation,
|
|
1562
|
+
isFailed: false,
|
|
1563
|
+
callStack: undefined,
|
|
1564
|
+
};
|
|
1565
|
+
} catch (error) {
|
|
1566
|
+
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1567
|
+
return {
|
|
1568
|
+
additional: undefined,
|
|
1569
|
+
isFailed: true,
|
|
1570
|
+
callStack: getLiveCallStack(index, liveSuccessors),
|
|
1571
|
+
};
|
|
1572
|
+
}
|
|
1573
|
+
});
|
|
1356
1574
|
const expandState = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1357
1575
|
const state = states[index];
|
|
1358
1576
|
const source = stateWriter && getGraphState(state, depths[index]);
|
|
@@ -1374,10 +1592,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1374
1592
|
outcome = reportNextStateOverflow(index);
|
|
1375
1593
|
return true;
|
|
1376
1594
|
}
|
|
1377
|
-
const replay = is174
|
|
1378
|
-
? captureOutput(() => replayNext(index))
|
|
1379
|
-
: replayFailedNext(index, liveSuccessors);
|
|
1380
1595
|
if (is174 && error instanceof TlaEvaluationError && !isHeadedError(error)) {
|
|
1596
|
+
const replay = captureOutput(() => replayNext(index));
|
|
1381
1597
|
outcome = createFailureResult(
|
|
1382
1598
|
new TlaEvaluationError(`${getWrappedException(error)}${error.message}`, error),
|
|
1383
1599
|
appendTraceOutput({ trace: [] }, replay.lines),
|
|
@@ -1385,72 +1601,61 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1385
1601
|
);
|
|
1386
1602
|
return true;
|
|
1387
1603
|
}
|
|
1388
|
-
const
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
? getFailureMessage(
|
|
1392
|
-
isEvalException(error)
|
|
1393
|
-
? new TlaEvaluationError(`${UNEXPECTED_EVAL_EXCEPTION}${error.message}`)
|
|
1394
|
-
: error,
|
|
1395
|
-
true,
|
|
1396
|
-
)
|
|
1604
|
+
const traceError =
|
|
1605
|
+
error instanceof TlaEvaluationError && isUnfingerprintable(successor.state)
|
|
1606
|
+
? error
|
|
1397
1607
|
: undefined;
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1608
|
+
const behavior = traceError
|
|
1609
|
+
? traces.getStateTrace(index, { isPrintedOnly: true })
|
|
1610
|
+
: traces.getTrace(index, successor, { isPrintedOnly: true });
|
|
1611
|
+
const traceFailure =
|
|
1612
|
+
traceError &&
|
|
1613
|
+
getTraceFailure(
|
|
1614
|
+
traceError,
|
|
1615
|
+
captureOutput(() => {
|
|
1616
|
+
try {
|
|
1617
|
+
traces.findStepAction(index, state, successor.state, true);
|
|
1618
|
+
} catch (failed) {
|
|
1619
|
+
if (!(failed instanceof TlaEvaluationError)) throw failed;
|
|
1620
|
+
}
|
|
1621
|
+
}).lines,
|
|
1622
|
+
);
|
|
1623
|
+
const replay = is174
|
|
1624
|
+
? captureOutput(() => replayNext(index))
|
|
1625
|
+
: replayFailedNext(index, liveSuccessors);
|
|
1626
|
+
outcome = createFailureResult(error, appendTraceOutput(behavior, replay.lines), {
|
|
1627
|
+
phase: "next",
|
|
1628
|
+
...replay.result,
|
|
1629
|
+
traceFailure,
|
|
1630
|
+
});
|
|
1406
1631
|
}
|
|
1407
1632
|
return outcome !== undefined;
|
|
1408
1633
|
});
|
|
1409
1634
|
current.isExpanding = false;
|
|
1410
1635
|
const result = outcome;
|
|
1411
1636
|
if (result?.violation && !is174) {
|
|
1412
|
-
const live =
|
|
1637
|
+
const live = addReportedLiveState(index, liveSuccessors, source);
|
|
1413
1638
|
return {
|
|
1414
1639
|
...result,
|
|
1415
1640
|
violation: appendTraceOutput(result.violation, live.lines),
|
|
1416
|
-
|
|
1641
|
+
// TLC adds the state to the behavior graph before it reports the coverage.
|
|
1642
|
+
coverage: getCoverage(),
|
|
1643
|
+
...(live.result.additional && { additionalViolation: live.result.additional }),
|
|
1644
|
+
...(live.result.callStack && { liveCallStack: live.result.callStack }),
|
|
1417
1645
|
};
|
|
1418
1646
|
}
|
|
1419
1647
|
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
1648
|
if (successorCount === 0 && config.checkDeadlock) {
|
|
1439
1649
|
const deadlock = reportViolation("deadlock", {
|
|
1440
1650
|
name: "deadlock",
|
|
1441
1651
|
...traces.getStateTrace(index),
|
|
1442
1652
|
});
|
|
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;
|
|
1653
|
+
const live = addReportedLiveState(index, liveSuccessors, source);
|
|
1654
|
+
const reported = {
|
|
1655
|
+
...deadlock,
|
|
1656
|
+
violation: deadlock.violation && appendTraceOutput(deadlock.violation, live.lines),
|
|
1657
|
+
coverage: getCoverage(),
|
|
1658
|
+
};
|
|
1454
1659
|
const counted = withOutDegrees(
|
|
1455
1660
|
reported,
|
|
1456
1661
|
live.result.isFailed ? getFailureOutDegrees() : getPartialOutDegrees(),
|
|
@@ -1460,14 +1665,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1460
1665
|
return live.result.callStack ? { ...counted, liveCallStack: live.result.callStack } : counted;
|
|
1461
1666
|
}
|
|
1462
1667
|
try {
|
|
1463
|
-
return addLiveState();
|
|
1668
|
+
return addLiveState(index, liveSuccessors, source);
|
|
1464
1669
|
} catch (error) {
|
|
1465
1670
|
if (is174 && error instanceof TlaEvaluationError) {
|
|
1466
|
-
const unexpected = new TlaEvaluationError(
|
|
1467
|
-
`${isEvalException(error) ? UNEXPECTED_EVAL_EXCEPTION : UNEXPECTED_EXCEPTION}${error.message}`,
|
|
1468
|
-
);
|
|
1469
1671
|
return createFailureResult(
|
|
1470
|
-
setExitCode(
|
|
1672
|
+
setExitCode(toUnexpectedError(error), EXIT_STATUS.error),
|
|
1471
1673
|
{ trace: [] },
|
|
1472
1674
|
{ outDegrees: getFailureOutDegrees() },
|
|
1473
1675
|
);
|
|
@@ -1475,7 +1677,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1475
1677
|
const replay = getReplayFailure(environment, (tracing) =>
|
|
1476
1678
|
liveness?.addState(index, state, liveSuccessors, tracing),
|
|
1477
1679
|
);
|
|
1478
|
-
|
|
1680
|
+
const behavior = traces.getStateTrace(index, { isPrintedOnly: true });
|
|
1681
|
+
const replayed = captureOutput(() => replayNext(index));
|
|
1682
|
+
return createFailureResult(error, appendTraceOutput(behavior, replayed.lines), {
|
|
1479
1683
|
outDegrees: getFailureOutDegrees(),
|
|
1480
1684
|
callStack: replay?.callStack.length ? replay.callStack : undefined,
|
|
1481
1685
|
phase: "liveness",
|
|
@@ -1499,10 +1703,20 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1499
1703
|
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
1704
|
};
|
|
1501
1705
|
};
|
|
1706
|
+
const toLivenessFailure = (error: TlaEvaluationError) =>
|
|
1707
|
+
setExitCode(toUnexpectedError(error), EXIT_STATUS.abort);
|
|
1708
|
+
const getLassoSteps = (path: number[]) => {
|
|
1709
|
+
try {
|
|
1710
|
+
return traces.getPathSteps(path);
|
|
1711
|
+
} catch (error) {
|
|
1712
|
+
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1713
|
+
throw toLivenessFailure(error);
|
|
1714
|
+
}
|
|
1715
|
+
};
|
|
1502
1716
|
const reportLasso = (checker: LivenessChecker, lasso: Lasso) => {
|
|
1503
1717
|
const path = [...lasso.prefix, ...lasso.cycle];
|
|
1504
1718
|
const loopStart = lasso.prefix.length;
|
|
1505
|
-
const steps =
|
|
1719
|
+
const steps = getLassoSteps(path);
|
|
1506
1720
|
const trace = traces.toTrace(steps, path, { loopStart, known: 0 }).trace;
|
|
1507
1721
|
const properties = getViolatedProperties(
|
|
1508
1722
|
checker,
|
|
@@ -1512,13 +1726,28 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1512
1726
|
const cycleStart = path[loopStart];
|
|
1513
1727
|
const cycleEnd = path[path.length - 1];
|
|
1514
1728
|
const lastState = steps[steps.length - 1].state;
|
|
1515
|
-
const
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1729
|
+
const isStuttering = cycleStart === cycleEnd;
|
|
1730
|
+
const loop = isStuttering
|
|
1731
|
+
? { result: undefined, lines: [] }
|
|
1732
|
+
: captureOutput(() => traces.findStepAction(cycleEnd, lastState, states[cycleStart], false));
|
|
1733
|
+
const back =
|
|
1734
|
+
isStuttering || loop.result
|
|
1735
|
+
? undefined
|
|
1736
|
+
: traces.findSuccessorWithFingerprint(lastState, cycleEnd, cycleStart);
|
|
1737
|
+
if (!isStuttering && !loop.result && !back) {
|
|
1738
|
+
options.onProgress?.({
|
|
1739
|
+
kind: "violation",
|
|
1740
|
+
status: "property-violation",
|
|
1741
|
+
violation: {
|
|
1742
|
+
name: properties[0],
|
|
1743
|
+
properties,
|
|
1744
|
+
trace,
|
|
1745
|
+
traceOutput: loop.lines,
|
|
1746
|
+
loopStart: undefined,
|
|
1747
|
+
},
|
|
1748
|
+
});
|
|
1749
|
+
throw toLivenessFailure(new TlaEvaluationError(NEXT_RECOVERY_FAILURE));
|
|
1750
|
+
}
|
|
1522
1751
|
return reportViolation(
|
|
1523
1752
|
"liveness-violation",
|
|
1524
1753
|
{
|
|
@@ -1528,40 +1757,44 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1528
1757
|
traceOutput: loop.lines,
|
|
1529
1758
|
loopStart,
|
|
1530
1759
|
loopLabel: loop.result && getActionLabel(loop.result, options.version),
|
|
1531
|
-
warning:
|
|
1760
|
+
warning: isStuttering && lasso.isCycleConstrained ? getStutteringWarning() : undefined,
|
|
1532
1761
|
},
|
|
1762
|
+
getStepState,
|
|
1533
1763
|
() =>
|
|
1534
|
-
|
|
1764
|
+
isStuttering
|
|
1535
1765
|
? getStepAction(trace[trace.length - 1])
|
|
1536
1766
|
: loop.result
|
|
1537
1767
|
? toActionValue(loop.result)
|
|
1538
|
-
: createActionRecord(
|
|
1539
|
-
traces.findSuccessorWithFingerprint(lastState, cycleStart)?.action,
|
|
1540
|
-
),
|
|
1768
|
+
: createActionRecord(back?.action),
|
|
1541
1769
|
);
|
|
1542
1770
|
};
|
|
1543
1771
|
const isPeriodic = liveness !== undefined && (options.livenessCheck ?? "default") === "default";
|
|
1544
1772
|
const startedAt = performance.now();
|
|
1545
1773
|
const periodic = {
|
|
1546
1774
|
at: startedAt + PERIODIC_START,
|
|
1547
|
-
|
|
1775
|
+
checkedCounts: liveness?.getStateCounts().map(() => 1) ?? [],
|
|
1548
1776
|
time: 0,
|
|
1549
1777
|
coverageCount: Math.trunc(options.coverage ?? 0),
|
|
1550
1778
|
};
|
|
1551
|
-
const
|
|
1779
|
+
const getGraphStates = (checker: LivenessChecker) =>
|
|
1780
|
+
checker.getStateCounts().reduce((sum, count) => sum + count, 0);
|
|
1781
|
+
const findPeriodicViolation = (checker: LivenessChecker) => {
|
|
1552
1782
|
const now = performance.now();
|
|
1553
|
-
const
|
|
1783
|
+
const counts = checker.getStateCounts();
|
|
1784
|
+
const isGrown = counts.some(
|
|
1785
|
+
(count, branch) =>
|
|
1786
|
+
(count - periodic.checkedCounts[branch]) / periodic.checkedCounts[branch] > LIVENESS_GROWTH,
|
|
1787
|
+
);
|
|
1554
1788
|
if (!isGrown || periodic.time > (now - startedAt) * LIVENESS_RATIO) return undefined;
|
|
1555
|
-
periodic.
|
|
1556
|
-
if (!liveness) return undefined;
|
|
1789
|
+
periodic.checkedCounts = counts;
|
|
1557
1790
|
options.onProgress?.({
|
|
1558
1791
|
kind: "liveness-started",
|
|
1559
|
-
branches:
|
|
1792
|
+
branches: checker.branches,
|
|
1560
1793
|
isComplete: false,
|
|
1561
|
-
states:
|
|
1794
|
+
states: getGraphStates(checker),
|
|
1562
1795
|
statistics: createResult("success"),
|
|
1563
1796
|
});
|
|
1564
|
-
const lasso =
|
|
1797
|
+
const lasso = checker.findViolation();
|
|
1565
1798
|
if (!lasso) options.onProgress?.({ kind: "liveness-finished" });
|
|
1566
1799
|
periodic.time += performance.now() - now;
|
|
1567
1800
|
return lasso;
|
|
@@ -1674,20 +1907,21 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1674
1907
|
runtime.queueSize = states.length - index - 1;
|
|
1675
1908
|
current.isExpanding = true;
|
|
1676
1909
|
const liveSuccessors: LiveSuccessor[] = [];
|
|
1910
|
+
const generated = runtime.generatedStates;
|
|
1677
1911
|
try {
|
|
1678
1912
|
outcome = expandState(index, liveSuccessors);
|
|
1679
1913
|
} catch (error) {
|
|
1680
1914
|
outcome =
|
|
1681
1915
|
error instanceof TlaIncompleteSuccessorError
|
|
1682
|
-
? reportIncompleteSuccessor(index, error)
|
|
1683
|
-
: reportNextStateFailure(error, index, liveSuccessors);
|
|
1916
|
+
? reportIncompleteSuccessor(index, error, liveSuccessors)
|
|
1917
|
+
: reportNextStateFailure(error, index, liveSuccessors, generated);
|
|
1684
1918
|
}
|
|
1685
1919
|
if (outcome) return outcome;
|
|
1686
1920
|
outDegrees[getOutDegreeBucket()]++;
|
|
1687
1921
|
newStateCount = 0;
|
|
1688
1922
|
if ((isPeriodic || options.onProgress) && performance.now() >= periodic.at) {
|
|
1689
1923
|
periodic.at = performance.now() + PROGRESS_INTERVAL;
|
|
1690
|
-
const lasso = isPeriodic ? findPeriodicViolation(
|
|
1924
|
+
const lasso = isPeriodic && liveness ? findPeriodicViolation(liveness) : undefined;
|
|
1691
1925
|
if (liveness && lasso) return reportLasso(liveness, lasso);
|
|
1692
1926
|
const isCoverageDue = options.coverage !== undefined && periodic.coverageCount === 0;
|
|
1693
1927
|
periodic.coverageCount = isCoverageDue
|
|
@@ -1709,7 +1943,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1709
1943
|
kind: "liveness-started",
|
|
1710
1944
|
branches: finalLiveness.branches,
|
|
1711
1945
|
isComplete: true,
|
|
1712
|
-
states:
|
|
1946
|
+
states: typedLasso
|
|
1947
|
+
? finalLiveness.branches * runtime.distinctStates
|
|
1948
|
+
: getGraphStates(finalLiveness),
|
|
1713
1949
|
statistics: createResult("success"),
|
|
1714
1950
|
});
|
|
1715
1951
|
}
|