tla-ts 0.0.10-dev.37a75eb5b → 0.0.10-dev.45c0eaef5
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 +33 -33
- package/dist/deciders.js +53 -53
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +17 -3
- package/dist/index.d.ts +17 -3
- 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 +55 -55
- package/dist/prove.js +78 -78
- package/dist/run.cjs +40 -42
- package/dist/run.js +42 -44
- package/dist/tlapm.cjs +1 -1
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +96 -91
- package/dist/transfer.js +95 -90
- 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 +12 -10
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +13 -11
- package/src/check-trace.ts +146 -93
- package/src/check.ts +418 -246
- package/src/cli/tlc-output.ts +17 -2
- package/src/cli/tlc.ts +5 -4
- 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 +93 -35
- package/src/environment.ts +106 -39
- package/src/errors.ts +7 -0
- package/src/evaluate.ts +415 -132
- package/src/exit-codes.ts +28 -15
- package/src/instances.ts +135 -11
- package/src/java-hash.ts +14 -0
- package/src/java-overrides.ts +2 -2
- package/src/levels.ts +674 -236
- package/src/lexer.ts +12 -2
- package/src/liveness-checker.ts +161 -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/parser.ts +110 -111
- 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 +164 -58
- package/src/prover/smt/solver/ast-lt.ts +1 -1
- package/src/prover/smt/solver/ast.ts +65 -13
- 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 +65 -14
- 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 +3 -9
- 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/fd-solver.ts +608 -141
- package/src/prover/smt/solver/fix-dl-var.ts +1 -2
- package/src/prover/smt/solver/fpa2bv-rewriter.ts +1 -0
- package/src/prover/smt/solver/goal.ts +4 -3
- 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-grobner.ts +2 -2
- package/src/prover/smt/solver/lp/pdd.ts +2 -3
- 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 +14 -42
- 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 +1 -4
- 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 +4 -5
- package/src/prover/smt/solver/nlsat/levelwise.ts +0 -4
- package/src/prover/smt/solver/nlsat/polynomial.ts +1 -36
- package/src/prover/smt/solver/nlsat/upolynomial.ts +1 -1
- 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 +16 -7
- 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 +4 -3
- 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/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 +15 -6
- 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 +1 -1
- 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 +40 -6
- package/src/prover/smt/solver/smt-setup.ts +106 -13
- package/src/prover/smt/solver/smtlib-parser.ts +579 -214
- package/src/prover/smt/solver/smtlib-script.ts +600 -170
- 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 +342 -196
- 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 +1226 -246
- package/src/runtime.ts +19 -2
- package/src/sany/builtins.ts +10 -10
- package/src/sany/generation.ts +4 -2
- package/src/sany/generator-def-entries.ts +123 -36
- package/src/sany/generator-definitions.ts +4 -2
- package/src/sany/generator-expressions.ts +51 -20
- package/src/sany/generator-proofs.ts +17 -11
- package/src/sany/generator.ts +11 -5
- 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 +283 -126
- 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 +563 -139
- package/src/successors.ts +50 -20
- package/src/symmetry.ts +2 -1
- package/src/tlc/jar-data.ts +1 -3
- package/src/tlc/messages.ts +3 -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 +26 -10
- 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 {
|
|
@@ -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";
|
|
@@ -508,19 +524,24 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
508
524
|
specification.moduleOperators.some((operator) => operator.kind === "postcondition");
|
|
509
525
|
const tracedSteps = new WeakMap<TraceStep, TracedStep>();
|
|
510
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;
|
|
511
529
|
const getStepAction = (step: TraceStep) => {
|
|
512
530
|
const action = tracedSteps.get(step)?.action;
|
|
513
531
|
return action ? toActionValue(action) : createActionRecord(step.action);
|
|
514
532
|
};
|
|
515
533
|
const checkTracePostconditions = (
|
|
516
534
|
trace: TraceStep[],
|
|
517
|
-
loop:
|
|
535
|
+
loop: CounterExampleLoop | undefined,
|
|
536
|
+
getState: (step: TraceStep) => Record<string, Value>,
|
|
537
|
+
isConsole = true,
|
|
518
538
|
) => {
|
|
519
539
|
if (hasPostconditions) {
|
|
520
540
|
runtime.counterExample = createCounterExample(
|
|
521
|
-
trace.map(
|
|
541
|
+
trace.map(getState),
|
|
522
542
|
trace.slice(1).map(getStepAction),
|
|
523
543
|
loop,
|
|
544
|
+
isConsole,
|
|
524
545
|
);
|
|
525
546
|
}
|
|
526
547
|
const unwitnessed = search.findUnwitnessedPossible();
|
|
@@ -532,12 +553,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
532
553
|
const reportViolation = (
|
|
533
554
|
status: CheckStatus,
|
|
534
555
|
violation: ReportedViolation,
|
|
556
|
+
getState = getStepAlias,
|
|
535
557
|
getLoopAction?: () => Value,
|
|
536
558
|
) => {
|
|
537
559
|
const start = violation.loopStart;
|
|
538
560
|
const checked = checkTracePostconditions(
|
|
539
561
|
violation.trace,
|
|
540
562
|
start === undefined || !getLoopAction ? undefined : { start, action: getLoopAction() },
|
|
563
|
+
getState,
|
|
541
564
|
);
|
|
542
565
|
return createResult(status, {
|
|
543
566
|
...violation,
|
|
@@ -563,59 +586,36 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
563
586
|
const getFingerprintState = search.getFingerprintState;
|
|
564
587
|
// Tool's constructor splits the next-state relation into actions before TLC checks anything.
|
|
565
588
|
const nextActions = getDescription().actions;
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
kind,
|
|
573
|
-
getCoverageLabel(action.name, action.expression, environment),
|
|
574
|
-
action.expression,
|
|
575
|
-
action.scope,
|
|
576
|
-
)
|
|
577
|
-
: -1,
|
|
578
|
-
}));
|
|
579
|
-
const coverageInits = addCoverageRelations("init", coverage ? getDescription().inits : []);
|
|
580
|
-
const coverageActions = addCoverageRelations("next", coverage ? nextActions : []);
|
|
581
|
-
if (coverage) buildCoverage(coverage, environment, getPrimedRanges(coverageActions, environment));
|
|
582
|
-
const walkCoveredSuccessors = (
|
|
583
|
-
action: CoveredAction,
|
|
584
|
-
state: Value[],
|
|
585
|
-
onState: (successor: Value[]) => void,
|
|
586
|
-
) =>
|
|
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;
|
|
587
595
|
walkSuccessors(
|
|
588
596
|
action,
|
|
589
597
|
action.node,
|
|
590
598
|
state,
|
|
591
599
|
environment,
|
|
592
|
-
(
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
(partial) => {
|
|
597
|
-
const missing = environment.variables.filter(
|
|
598
|
-
(_variable, index) => partial[index] === undefined,
|
|
599
|
-
);
|
|
600
|
-
throw new TlaIncompleteSuccessorError(
|
|
601
|
-
`Successor state is not completely specified by action ${action.name}. The following variables are not assigned: ${missing.join(", ")}`,
|
|
602
|
-
partial,
|
|
603
|
-
action.name,
|
|
604
|
-
missing,
|
|
605
|
-
);
|
|
600
|
+
() => complete++,
|
|
601
|
+
() => {
|
|
602
|
+
incomplete++;
|
|
603
|
+
return true;
|
|
606
604
|
},
|
|
607
605
|
);
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
walkCoveredSuccessors(action, state, (successor) =>
|
|
611
|
-
successors.push({ state: successor, action: action.name }),
|
|
612
|
-
);
|
|
613
|
-
return successors;
|
|
606
|
+
if (coverage) coverage.primary[action.node] += complete + incomplete;
|
|
607
|
+
return incomplete > 0;
|
|
614
608
|
};
|
|
615
609
|
// TLC generates the successors of each action again, which its coverage counts.
|
|
616
610
|
const findSuccessorAction = (state: Value[], isMatch: (successor: Successor) => boolean) =>
|
|
617
611
|
coverage
|
|
618
|
-
? coverageActions.find((item) =>
|
|
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
619
|
: nextActions.find((item) =>
|
|
620
620
|
getSuccessors(item.expression, state, environment, item.scope).some(isMatch),
|
|
621
621
|
);
|
|
@@ -657,7 +657,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
657
657
|
const deferred: unknown[] = [];
|
|
658
658
|
const addReplayed = createReplayedStates();
|
|
659
659
|
return getReplayFailure(environment, (tracing) => {
|
|
660
|
-
replayInitialStates(getDescription().inits, tracing, (state) => {
|
|
660
|
+
replayInitialStates(coverage ? coverageInits : getDescription().inits, tracing, (state) => {
|
|
661
661
|
reportInitialStatesProgress(replayedCount, (progress) => capturedLines?.push(progress));
|
|
662
662
|
replayedCount++;
|
|
663
663
|
runtime.generatedStates = replayedCount;
|
|
@@ -668,16 +668,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
668
668
|
runtime.queueSize++;
|
|
669
669
|
liveness?.addInitialState(states.length, state, tracing);
|
|
670
670
|
};
|
|
671
|
-
|
|
672
|
-
if (violation) {
|
|
671
|
+
search.checkReplayedInitialState(state, tracing, addFingerprint, (violation) => {
|
|
673
672
|
const traced = traces.toTrace([{ action: undefined, state }], []).trace[0].state;
|
|
674
673
|
capturedLines?.push({
|
|
675
674
|
kind: "initial-state-violation",
|
|
676
675
|
...violation,
|
|
677
676
|
state: traced,
|
|
678
677
|
});
|
|
679
|
-
|
|
680
|
-
|
|
678
|
+
if (!options.isContinued || violation.status !== "invariant-violation") {
|
|
679
|
+
throw STOP_REPLAY;
|
|
680
|
+
}
|
|
681
|
+
});
|
|
681
682
|
} catch (error) {
|
|
682
683
|
const isFingerprintFailure =
|
|
683
684
|
error instanceof TlaEvaluationError && tracing.callStack?.fingerprint !== undefined;
|
|
@@ -693,7 +694,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
693
694
|
const state = states[index];
|
|
694
695
|
const source = stateWriter && getGraphState(state, depths[index]);
|
|
695
696
|
const addReplayed = createReplayedStates();
|
|
696
|
-
replaySuccessors(nextActions, state, tracing, (next, action) => {
|
|
697
|
+
replaySuccessors(coverage ? coverageActions : nextActions, state, tracing, (next, action) => {
|
|
697
698
|
const addFingerprint = () => {
|
|
698
699
|
const isUnseen = addReplayed(next, tracing.callStack);
|
|
699
700
|
if (source) {
|
|
@@ -719,6 +720,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
719
720
|
isConstrained: search.isConstrained,
|
|
720
721
|
});
|
|
721
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
|
+
};
|
|
722
732
|
const liveness = withLivenessExitCode(() =>
|
|
723
733
|
withUnexpectedException(() =>
|
|
724
734
|
createLivenessChecker(search.properties.liveness, spec.temporals, environment, {
|
|
@@ -726,11 +736,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
726
736
|
(tlcFingerprints[successor.index] ??= Number(
|
|
727
737
|
BigInt.asIntN(32, runtime.getFingerprint(successor.state)),
|
|
728
738
|
)),
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
const livenessSource = current.livenessSource;
|
|
733
|
-
current.livenessSource = source;
|
|
739
|
+
forEachActionSuccessors: (source, state, onSuccessors, replay) => {
|
|
740
|
+
liveState = state;
|
|
741
|
+
let successors: LiveSuccessor[] = [];
|
|
734
742
|
const addSuccessor = (successor: Value[]) => {
|
|
735
743
|
canonicalizeState(successor);
|
|
736
744
|
const isInModel =
|
|
@@ -745,28 +753,50 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
745
753
|
state: successor,
|
|
746
754
|
});
|
|
747
755
|
};
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
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;
|
|
781
|
+
});
|
|
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;
|
|
765
797
|
}
|
|
766
|
-
|
|
767
|
-
current.livenessSource = livenessSource;
|
|
798
|
+
onSuccessors(successors);
|
|
768
799
|
}
|
|
769
|
-
return successors;
|
|
770
800
|
},
|
|
771
801
|
}),
|
|
772
802
|
),
|
|
@@ -798,13 +828,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
798
828
|
}
|
|
799
829
|
return -2 - position;
|
|
800
830
|
};
|
|
801
|
-
|
|
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();
|
|
802
833
|
|
|
803
834
|
const toRecord = search.toRecord;
|
|
804
|
-
const
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
835
|
+
const getUncoveredInitialStates = () =>
|
|
836
|
+
spec.init === undefined ? [] : getInitialStates(spec.init, environment, spec.scope);
|
|
837
|
+
const getSpecInitialStates = () =>
|
|
838
|
+
coverage ? getCoveredInitialStates() : getUncoveredInitialStates();
|
|
808
839
|
const isUnfingerprintable = (state: Value[]) => {
|
|
809
840
|
try {
|
|
810
841
|
return getFingerprintState(state).some((value) => getFingerprintError(value) !== undefined);
|
|
@@ -813,19 +844,27 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
813
844
|
return true;
|
|
814
845
|
}
|
|
815
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
|
+
};
|
|
816
860
|
const createFailureResult = (
|
|
817
861
|
failed: unknown,
|
|
818
862
|
behavior: Behavior,
|
|
819
863
|
failureOptions: FailureOptions = {},
|
|
864
|
+
postcondition?: Postcondition,
|
|
820
865
|
) => {
|
|
821
866
|
const error = isStackOverflow(failed) ? new TlaStackOverflowError() : failed;
|
|
822
867
|
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
823
|
-
const checked =
|
|
824
|
-
behavior.trace.length > 0 && !failureOptions.traceFailure
|
|
825
|
-
? checkTracePostconditions(behavior.trace, undefined)
|
|
826
|
-
: undefined;
|
|
827
|
-
const postcondition = checked?.unwitnessed ?? checked?.postcondition;
|
|
828
|
-
const traceOutput = [...(behavior.traceOutput ?? []), ...(checked?.lines ?? [])];
|
|
829
868
|
return {
|
|
830
869
|
...createResult("error", undefined, {
|
|
831
870
|
...getFailureMessage(
|
|
@@ -833,7 +872,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
833
872
|
failureOptions.phase !== undefined && failureOptions.phase !== "initial",
|
|
834
873
|
),
|
|
835
874
|
...behavior,
|
|
836
|
-
...(traceOutput.length > 0 && { traceOutput }),
|
|
837
875
|
...(postcondition && { postcondition }),
|
|
838
876
|
initialState:
|
|
839
877
|
failureOptions.initialState && !(error instanceof TlaModuleError)
|
|
@@ -848,29 +886,70 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
848
886
|
outDegrees: failureOptions.outDegrees,
|
|
849
887
|
};
|
|
850
888
|
};
|
|
851
|
-
|
|
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
|
+
) => {
|
|
852
895
|
runtime.generatedStates++;
|
|
853
|
-
const
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
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);
|
|
865
913
|
const message = getIncompleteSuccessorMessage(
|
|
866
914
|
error.variables,
|
|
867
915
|
error.action,
|
|
868
916
|
nextActions.length,
|
|
869
917
|
options.version,
|
|
870
918
|
);
|
|
871
|
-
const
|
|
872
|
-
const
|
|
873
|
-
|
|
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
|
+
);
|
|
874
953
|
return withOutDegrees({
|
|
875
954
|
...failure,
|
|
876
955
|
failure: failure.failure && {
|
|
@@ -879,14 +958,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
879
958
|
message,
|
|
880
959
|
toolMessage: message,
|
|
881
960
|
exitCode: EXIT_STATUS.specEvaluationFailure,
|
|
882
|
-
trace: [
|
|
883
|
-
...failure.failure.trace,
|
|
884
|
-
{
|
|
885
|
-
action: error.action,
|
|
886
|
-
label: action && getActionLabel(action, options.version),
|
|
887
|
-
state: toRecord(partial),
|
|
888
|
-
},
|
|
889
|
-
],
|
|
890
961
|
},
|
|
891
962
|
});
|
|
892
963
|
};
|
|
@@ -939,6 +1010,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
939
1010
|
tracedSteps,
|
|
940
1011
|
captureOutput,
|
|
941
1012
|
getInitialStates: getSpecInitialStates,
|
|
1013
|
+
getUncoveredInitialStates,
|
|
942
1014
|
findSuccessorAction,
|
|
943
1015
|
});
|
|
944
1016
|
const getPath = (index: number): Value[][] =>
|
|
@@ -965,7 +1037,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
965
1037
|
const index = state === current.candidate ? -1 : states.indexOf(state);
|
|
966
1038
|
return index === -1 ? [...getPath(current.index), state] : getPath(index);
|
|
967
1039
|
};
|
|
968
|
-
runtime.getCurrentState = () =>
|
|
1040
|
+
runtime.getCurrentState = () =>
|
|
1041
|
+
current.rebuilt?.state ?? (current.index === -1 ? undefined : states[current.index]);
|
|
969
1042
|
runtime.setLivenessSource = (index) => {
|
|
970
1043
|
current.livenessSource = index ?? -1;
|
|
971
1044
|
};
|
|
@@ -1001,14 +1074,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1001
1074
|
});
|
|
1002
1075
|
|
|
1003
1076
|
const visitInitialState = (state: Value[]) => {
|
|
1004
|
-
canonicalizeState(state);
|
|
1005
1077
|
runtime.generatedStates++;
|
|
1006
1078
|
runtime.initialStates++;
|
|
1007
1079
|
current.candidate = state;
|
|
1008
1080
|
current.candidateLevel = 1;
|
|
1009
|
-
const fingerprintState = getFingerprintState(state);
|
|
1010
|
-
const hash = getStateHash(fingerprintState);
|
|
1011
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;
|
|
1012
1086
|
if (isInModel) {
|
|
1013
1087
|
search.trackStatePossible(state);
|
|
1014
1088
|
fingerprintModelState(fingerprintState);
|
|
@@ -1024,7 +1098,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1024
1098
|
stateWriter?.writeInitialState(getGraphState(state, 1));
|
|
1025
1099
|
}
|
|
1026
1100
|
if (options.isContinued) {
|
|
1027
|
-
search.
|
|
1101
|
+
search.forEachViolatedInvariant(state, (invariant) =>
|
|
1028
1102
|
reportContinuedViolation("invariant-violation", {
|
|
1029
1103
|
name: invariant.name,
|
|
1030
1104
|
...traces.toTrace([{ action: undefined, state }], []),
|
|
@@ -1033,17 +1107,19 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1033
1107
|
}
|
|
1034
1108
|
const violated = options.isContinued ? undefined : search.findViolatedInvariant(state);
|
|
1035
1109
|
if (violated) {
|
|
1036
|
-
return reportViolation(
|
|
1037
|
-
|
|
1038
|
-
...traces.toTrace([{ action: undefined, state }], []),
|
|
1039
|
-
|
|
1110
|
+
return reportViolation(
|
|
1111
|
+
"invariant-violation",
|
|
1112
|
+
{ name: violated.name, ...traces.toTrace([{ action: undefined, state }], []) },
|
|
1113
|
+
getStepState,
|
|
1114
|
+
);
|
|
1040
1115
|
}
|
|
1041
1116
|
const failedPredicate = search.findFailedInitialPredicate(state);
|
|
1042
1117
|
if (failedPredicate) {
|
|
1043
|
-
return reportViolation(
|
|
1044
|
-
|
|
1045
|
-
...traces.toTrace([{ action: undefined, state }], []),
|
|
1046
|
-
|
|
1118
|
+
return reportViolation(
|
|
1119
|
+
"liveness-violation",
|
|
1120
|
+
{ name: failedPredicate.name, ...traces.toTrace([{ action: undefined, state }], []) },
|
|
1121
|
+
getStepState,
|
|
1122
|
+
);
|
|
1047
1123
|
}
|
|
1048
1124
|
if (!isInModel) return undefined;
|
|
1049
1125
|
markSeenState(seenStates, hash, states.length);
|
|
@@ -1053,18 +1129,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1053
1129
|
// Looks a successor up, where the constraints keep it in the model, as the search does before it
|
|
1054
1130
|
// checks the successor.
|
|
1055
1131
|
const lookUpSuccessor = (state: Value[], successor: Successor) => {
|
|
1056
|
-
const fingerprintState = getFingerprintState(successor.state);
|
|
1057
|
-
const hash = getStateHash(fingerprintState);
|
|
1058
|
-
const foundIndex = findStateIndex(seenStates, hash, fingerprintState);
|
|
1059
1132
|
const isStateInModel = search.satisfiesConstraints(successor.state, state);
|
|
1060
1133
|
if (isStateInModel) search.trackStatePossible(successor.state);
|
|
1061
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;
|
|
1062
1137
|
if (isInModel) {
|
|
1063
1138
|
search.trackActionPossible(state, successor.state);
|
|
1064
1139
|
fingerprintModelState(fingerprintState);
|
|
1065
1140
|
successor.state.forEach(markFingerprinted);
|
|
1066
1141
|
}
|
|
1067
|
-
const existing = isInModel ?
|
|
1142
|
+
const existing = isInModel ? findStateIndex(seenStates, hash, fingerprintState) : -1;
|
|
1068
1143
|
return {
|
|
1069
1144
|
fingerprintState,
|
|
1070
1145
|
hash,
|
|
@@ -1129,17 +1204,23 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1129
1204
|
if (!found.isSeen) {
|
|
1130
1205
|
try {
|
|
1131
1206
|
const violated = search.findViolatedInvariant(successor.state, state);
|
|
1132
|
-
const violation = violated && {
|
|
1207
|
+
const violation = violated && {
|
|
1208
|
+
name: violated.name,
|
|
1209
|
+
...traces.getTrace(index, successor, { isPrintedOnly: options.isContinued }),
|
|
1210
|
+
};
|
|
1133
1211
|
if (violation && !options.isContinued) {
|
|
1134
1212
|
return withOutDegrees(reportViolation("invariant-violation", violation));
|
|
1135
1213
|
}
|
|
1136
1214
|
if (violation) reportContinuedViolation("invariant-violation", violation);
|
|
1137
1215
|
} catch (error) {
|
|
1138
1216
|
if (isStackOverflow(error)) throw error;
|
|
1139
|
-
const
|
|
1217
|
+
const behavior = traces.getTrace(index, successor, { isPrintedOnly: true });
|
|
1218
|
+
const replay = is174
|
|
1219
|
+
? captureOutput(() => replayNext(index))
|
|
1220
|
+
: replayFailedNext(index, liveSuccessors);
|
|
1140
1221
|
return createFailureResult(
|
|
1141
1222
|
error,
|
|
1142
|
-
appendTraceOutput(
|
|
1223
|
+
appendTraceOutput(behavior, replay.lines),
|
|
1143
1224
|
replay.result ?? { outDegrees: getFailureOutDegrees() },
|
|
1144
1225
|
);
|
|
1145
1226
|
}
|
|
@@ -1147,7 +1228,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1147
1228
|
const violatedProperty = search.findViolatedActionProperty(state, successor.state);
|
|
1148
1229
|
const propertyViolation = violatedProperty && {
|
|
1149
1230
|
name: violatedProperty.name,
|
|
1150
|
-
...traces.getTrace(index, successor),
|
|
1231
|
+
...traces.getTrace(index, successor, { isPrintedOnly: options.isContinued }),
|
|
1151
1232
|
};
|
|
1152
1233
|
if (propertyViolation && !options.isContinued) {
|
|
1153
1234
|
return withOutDegrees(reportViolation("liveness-violation", propertyViolation));
|
|
@@ -1208,7 +1289,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1208
1289
|
kind: "liveness-started",
|
|
1209
1290
|
branches: liveness.branches,
|
|
1210
1291
|
isComplete: true,
|
|
1211
|
-
// The tier stores and expands every successor, so the graph of each branch has every state.
|
|
1212
1292
|
states: liveness.branches * typed.distinctStates,
|
|
1213
1293
|
statistics,
|
|
1214
1294
|
});
|
|
@@ -1273,14 +1353,29 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1273
1353
|
}
|
|
1274
1354
|
} catch (error) {
|
|
1275
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;
|
|
1276
1367
|
const illegal = createFailureResult(
|
|
1277
1368
|
error,
|
|
1278
|
-
{ trace: [] },
|
|
1279
|
-
{ initialState:
|
|
1369
|
+
{ trace: [], traceOutput: checked.lines },
|
|
1370
|
+
{ initialState: state },
|
|
1280
1371
|
);
|
|
1281
1372
|
return {
|
|
1282
1373
|
...illegal,
|
|
1283
|
-
failure: illegal.failure && {
|
|
1374
|
+
failure: illegal.failure && {
|
|
1375
|
+
...illegal.failure,
|
|
1376
|
+
isWithoutStatistics: true,
|
|
1377
|
+
...(postcondition && { postcondition }),
|
|
1378
|
+
},
|
|
1284
1379
|
};
|
|
1285
1380
|
}
|
|
1286
1381
|
const replay = captureOutput(replayInit);
|
|
@@ -1325,7 +1420,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1325
1420
|
try {
|
|
1326
1421
|
coverageActions.forEach((action) => {
|
|
1327
1422
|
coveredNode = action.node;
|
|
1328
|
-
walkCoveredSuccessors(action, state, (successor) => {
|
|
1423
|
+
walkCoveredSuccessors(coverage, action, state, environment, (successor) => {
|
|
1329
1424
|
successorCount++;
|
|
1330
1425
|
if (onSuccessor({ state: successor, action: action.name }, action)) throw STOP_WALK;
|
|
1331
1426
|
});
|
|
@@ -1366,6 +1461,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1366
1461
|
);
|
|
1367
1462
|
}, 0);
|
|
1368
1463
|
};
|
|
1464
|
+
// Deviation from TLC: Worker#doNextCheckLiveness doesn't catch a FingerprintException from its rerun, so TLC prints the behavior without the failure.
|
|
1369
1465
|
const getLiveCallStack = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1370
1466
|
if (!liveness || is174) return undefined;
|
|
1371
1467
|
const replay = getReplayFailure(environment, (tracing) =>
|
|
@@ -1379,6 +1475,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1379
1475
|
return undefined;
|
|
1380
1476
|
} catch (error) {
|
|
1381
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;
|
|
1382
1480
|
return getLiveCallStack(index, liveSuccessors);
|
|
1383
1481
|
}
|
|
1384
1482
|
};
|
|
@@ -1389,23 +1487,91 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1389
1487
|
return { result, lines: live.lines };
|
|
1390
1488
|
}
|
|
1391
1489
|
const replay = captureOutput(() => replayNext(index));
|
|
1392
|
-
|
|
1490
|
+
const result: FailureOptions =
|
|
1491
|
+
replay.result ?? (is174 ? {} : { outDegrees: getFailureOutDegrees() });
|
|
1492
|
+
return { result, lines: [...live.lines, ...replay.lines] };
|
|
1393
1493
|
};
|
|
1394
|
-
const
|
|
1395
|
-
|
|
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.
|
|
1396
1510
|
const reportNextStateFailure = (
|
|
1397
1511
|
error: unknown,
|
|
1398
1512
|
index: number,
|
|
1399
1513
|
liveSuccessors: LiveSuccessor[],
|
|
1514
|
+
generated: number,
|
|
1400
1515
|
) => {
|
|
1401
|
-
|
|
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);
|
|
1402
1523
|
const replay = replayFailedNext(index, liveSuccessors);
|
|
1403
1524
|
return createFailureResult(
|
|
1404
1525
|
withNextStateExitCode(error),
|
|
1405
|
-
appendTraceOutput(
|
|
1526
|
+
appendTraceOutput(checked.behavior, replay.lines),
|
|
1406
1527
|
{ phase: "next", ...replay.result },
|
|
1528
|
+
checked.postcondition,
|
|
1407
1529
|
);
|
|
1408
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,
|
|
1547
|
+
);
|
|
1548
|
+
return reportViolation("property-violation", {
|
|
1549
|
+
name: properties[0],
|
|
1550
|
+
properties,
|
|
1551
|
+
...traces.toTrace(steps, accepted, { known: 0 }),
|
|
1552
|
+
});
|
|
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
|
+
});
|
|
1409
1575
|
const expandState = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1410
1576
|
const state = states[index];
|
|
1411
1577
|
const source = stateWriter && getGraphState(state, depths[index]);
|
|
@@ -1427,10 +1593,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1427
1593
|
outcome = reportNextStateOverflow(index);
|
|
1428
1594
|
return true;
|
|
1429
1595
|
}
|
|
1430
|
-
const replay = is174
|
|
1431
|
-
? captureOutput(() => replayNext(index))
|
|
1432
|
-
: replayFailedNext(index, liveSuccessors);
|
|
1433
1596
|
if (is174 && error instanceof TlaEvaluationError && !isHeadedError(error)) {
|
|
1597
|
+
const replay = captureOutput(() => replayNext(index));
|
|
1434
1598
|
outcome = createFailureResult(
|
|
1435
1599
|
new TlaEvaluationError(`${getWrappedException(error)}${error.message}`, error),
|
|
1436
1600
|
appendTraceOutput({ trace: [] }, replay.lines),
|
|
@@ -1438,74 +1602,61 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1438
1602
|
);
|
|
1439
1603
|
return true;
|
|
1440
1604
|
}
|
|
1441
|
-
const
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
? getFailureMessage(
|
|
1445
|
-
isEvalException(error)
|
|
1446
|
-
? new TlaEvaluationError(`${UNEXPECTED_EVAL_EXCEPTION}${error.message}`)
|
|
1447
|
-
: error,
|
|
1448
|
-
true,
|
|
1449
|
-
)
|
|
1605
|
+
const traceError =
|
|
1606
|
+
error instanceof TlaEvaluationError && isUnfingerprintable(successor.state)
|
|
1607
|
+
? error
|
|
1450
1608
|
: undefined;
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
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
|
+
});
|
|
1459
1632
|
}
|
|
1460
1633
|
return outcome !== undefined;
|
|
1461
1634
|
});
|
|
1462
1635
|
current.isExpanding = false;
|
|
1463
1636
|
const result = outcome;
|
|
1464
1637
|
if (result?.violation && !is174) {
|
|
1465
|
-
const live =
|
|
1638
|
+
const live = addReportedLiveState(index, liveSuccessors, source);
|
|
1466
1639
|
return {
|
|
1467
1640
|
...result,
|
|
1468
1641
|
violation: appendTraceOutput(result.violation, live.lines),
|
|
1469
1642
|
// TLC adds the state to the behavior graph before it reports the coverage.
|
|
1470
1643
|
coverage: getCoverage(),
|
|
1471
|
-
...(live.result && {
|
|
1644
|
+
...(live.result.additional && { additionalViolation: live.result.additional }),
|
|
1645
|
+
...(live.result.callStack && { liveCallStack: live.result.callStack }),
|
|
1472
1646
|
};
|
|
1473
1647
|
}
|
|
1474
1648
|
if (result) return result;
|
|
1475
|
-
const addLiveState = () => {
|
|
1476
|
-
if (liveness && source && (is174 || options.dump?.stuttering)) {
|
|
1477
|
-
stateWriter?.writeStuttering(source);
|
|
1478
|
-
}
|
|
1479
|
-
const accepted = liveness?.addState(index, state, liveSuccessors);
|
|
1480
|
-
if (!liveness || !accepted) return undefined;
|
|
1481
|
-
const steps = traces.getPathSteps(accepted);
|
|
1482
|
-
const properties = getViolatedProperties(
|
|
1483
|
-
liveness,
|
|
1484
|
-
steps.map((step) => step.state),
|
|
1485
|
-
steps.length - 1,
|
|
1486
|
-
);
|
|
1487
|
-
return reportViolation("property-violation", {
|
|
1488
|
-
name: properties[0],
|
|
1489
|
-
properties,
|
|
1490
|
-
...traces.toTrace(steps, accepted, { known: 0 }),
|
|
1491
|
-
});
|
|
1492
|
-
};
|
|
1493
1649
|
if (successorCount === 0 && config.checkDeadlock) {
|
|
1494
1650
|
const deadlock = reportViolation("deadlock", {
|
|
1495
1651
|
name: "deadlock",
|
|
1496
1652
|
...traces.getStateTrace(index),
|
|
1497
1653
|
});
|
|
1498
|
-
const live =
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
}
|
|
1505
|
-
});
|
|
1506
|
-
const reported = deadlock.violation
|
|
1507
|
-
? { ...deadlock, violation: appendTraceOutput(deadlock.violation, live.lines) }
|
|
1508
|
-
: 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
|
+
};
|
|
1509
1660
|
const counted = withOutDegrees(
|
|
1510
1661
|
reported,
|
|
1511
1662
|
live.result.isFailed ? getFailureOutDegrees() : getPartialOutDegrees(),
|
|
@@ -1515,14 +1666,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1515
1666
|
return live.result.callStack ? { ...counted, liveCallStack: live.result.callStack } : counted;
|
|
1516
1667
|
}
|
|
1517
1668
|
try {
|
|
1518
|
-
return addLiveState();
|
|
1669
|
+
return addLiveState(index, liveSuccessors, source);
|
|
1519
1670
|
} catch (error) {
|
|
1520
1671
|
if (is174 && error instanceof TlaEvaluationError) {
|
|
1521
|
-
const unexpected = new TlaEvaluationError(
|
|
1522
|
-
`${isEvalException(error) ? UNEXPECTED_EVAL_EXCEPTION : UNEXPECTED_EXCEPTION}${error.message}`,
|
|
1523
|
-
);
|
|
1524
1672
|
return createFailureResult(
|
|
1525
|
-
setExitCode(
|
|
1673
|
+
setExitCode(toUnexpectedError(error), EXIT_STATUS.error),
|
|
1526
1674
|
{ trace: [] },
|
|
1527
1675
|
{ outDegrees: getFailureOutDegrees() },
|
|
1528
1676
|
);
|
|
@@ -1530,7 +1678,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1530
1678
|
const replay = getReplayFailure(environment, (tracing) =>
|
|
1531
1679
|
liveness?.addState(index, state, liveSuccessors, tracing),
|
|
1532
1680
|
);
|
|
1533
|
-
|
|
1681
|
+
const behavior = traces.getStateTrace(index, { isPrintedOnly: true });
|
|
1682
|
+
const replayed = captureOutput(() => replayNext(index));
|
|
1683
|
+
return createFailureResult(error, appendTraceOutput(behavior, replayed.lines), {
|
|
1534
1684
|
outDegrees: getFailureOutDegrees(),
|
|
1535
1685
|
callStack: replay?.callStack.length ? replay.callStack : undefined,
|
|
1536
1686
|
phase: "liveness",
|
|
@@ -1554,10 +1704,20 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1554
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}`,
|
|
1555
1705
|
};
|
|
1556
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
|
+
};
|
|
1557
1717
|
const reportLasso = (checker: LivenessChecker, lasso: Lasso) => {
|
|
1558
1718
|
const path = [...lasso.prefix, ...lasso.cycle];
|
|
1559
1719
|
const loopStart = lasso.prefix.length;
|
|
1560
|
-
const steps =
|
|
1720
|
+
const steps = getLassoSteps(path);
|
|
1561
1721
|
const trace = traces.toTrace(steps, path, { loopStart, known: 0 }).trace;
|
|
1562
1722
|
const properties = getViolatedProperties(
|
|
1563
1723
|
checker,
|
|
@@ -1567,13 +1727,28 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1567
1727
|
const cycleStart = path[loopStart];
|
|
1568
1728
|
const cycleEnd = path[path.length - 1];
|
|
1569
1729
|
const lastState = steps[steps.length - 1].state;
|
|
1570
|
-
const
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
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
|
+
}
|
|
1577
1752
|
return reportViolation(
|
|
1578
1753
|
"liveness-violation",
|
|
1579
1754
|
{
|
|
@@ -1583,28 +1758,25 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1583
1758
|
traceOutput: loop.lines,
|
|
1584
1759
|
loopStart,
|
|
1585
1760
|
loopLabel: loop.result && getActionLabel(loop.result, options.version),
|
|
1586
|
-
warning:
|
|
1761
|
+
warning: isStuttering && lasso.isCycleConstrained ? getStutteringWarning() : undefined,
|
|
1587
1762
|
},
|
|
1763
|
+
getStepState,
|
|
1588
1764
|
() =>
|
|
1589
|
-
|
|
1765
|
+
isStuttering
|
|
1590
1766
|
? getStepAction(trace[trace.length - 1])
|
|
1591
1767
|
: loop.result
|
|
1592
1768
|
? toActionValue(loop.result)
|
|
1593
|
-
: createActionRecord(
|
|
1594
|
-
traces.findSuccessorWithFingerprint(lastState, cycleStart)?.action,
|
|
1595
|
-
),
|
|
1769
|
+
: createActionRecord(back?.action),
|
|
1596
1770
|
);
|
|
1597
1771
|
};
|
|
1598
1772
|
const isPeriodic = liveness !== undefined && (options.livenessCheck ?? "default") === "default";
|
|
1599
1773
|
const startedAt = performance.now();
|
|
1600
1774
|
const periodic = {
|
|
1601
1775
|
at: startedAt + PERIODIC_START,
|
|
1602
|
-
|
|
1603
|
-
sizes: liveness?.getStateCounts().map(() => 1) ?? [],
|
|
1776
|
+
checkedCounts: liveness?.getStateCounts().map(() => 1) ?? [],
|
|
1604
1777
|
time: 0,
|
|
1605
1778
|
coverageCount: Math.trunc(options.coverage ?? 0),
|
|
1606
1779
|
};
|
|
1607
|
-
// TLC counts the states of the graphs of all branches, which can differ.
|
|
1608
1780
|
const getGraphStates = (checker: LivenessChecker) =>
|
|
1609
1781
|
checker.getStateCounts().reduce((sum, count) => sum + count, 0);
|
|
1610
1782
|
const findPeriodicViolation = (checker: LivenessChecker) => {
|
|
@@ -1612,10 +1784,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1612
1784
|
const counts = checker.getStateCounts();
|
|
1613
1785
|
const isGrown = counts.some(
|
|
1614
1786
|
(count, branch) =>
|
|
1615
|
-
(count - periodic.
|
|
1787
|
+
(count - periodic.checkedCounts[branch]) / periodic.checkedCounts[branch] > LIVENESS_GROWTH,
|
|
1616
1788
|
);
|
|
1617
1789
|
if (!isGrown || periodic.time > (now - startedAt) * LIVENESS_RATIO) return undefined;
|
|
1618
|
-
periodic.
|
|
1790
|
+
periodic.checkedCounts = counts;
|
|
1619
1791
|
options.onProgress?.({
|
|
1620
1792
|
kind: "liveness-started",
|
|
1621
1793
|
branches: checker.branches,
|
|
@@ -1736,13 +1908,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1736
1908
|
runtime.queueSize = states.length - index - 1;
|
|
1737
1909
|
current.isExpanding = true;
|
|
1738
1910
|
const liveSuccessors: LiveSuccessor[] = [];
|
|
1911
|
+
const generated = runtime.generatedStates;
|
|
1739
1912
|
try {
|
|
1740
1913
|
outcome = expandState(index, liveSuccessors);
|
|
1741
1914
|
} catch (error) {
|
|
1742
1915
|
outcome =
|
|
1743
1916
|
error instanceof TlaIncompleteSuccessorError
|
|
1744
|
-
? reportIncompleteSuccessor(index, error)
|
|
1745
|
-
: reportNextStateFailure(error, index, liveSuccessors);
|
|
1917
|
+
? reportIncompleteSuccessor(index, error, liveSuccessors)
|
|
1918
|
+
: reportNextStateFailure(error, index, liveSuccessors, generated);
|
|
1746
1919
|
}
|
|
1747
1920
|
if (outcome) return outcome;
|
|
1748
1921
|
outDegrees[getOutDegreeBucket()]++;
|
|
@@ -1771,7 +1944,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1771
1944
|
kind: "liveness-started",
|
|
1772
1945
|
branches: finalLiveness.branches,
|
|
1773
1946
|
isComplete: true,
|
|
1774
|
-
// The tier that found the lasso stored and expanded every successor, so each graph has every state.
|
|
1775
1947
|
states: typedLasso
|
|
1776
1948
|
? finalLiveness.branches * runtime.distinctStates
|
|
1777
1949
|
: getGraphStates(finalLiveness),
|