tla-ts 0.0.10-dev.1ebc153bd → 0.0.10-dev.22f7435d3
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/deciders.cjs +31 -31
- package/dist/deciders.js +30 -30
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +68 -68
- package/dist/prove.js +61 -61
- package/dist/run.cjs +42 -42
- package/dist/run.js +44 -44
- package/dist/transfer.cjs +38 -38
- package/dist/transfer.js +29 -29
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/bags.ts +5 -2
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +9 -6
- package/src/check-trace.ts +116 -64
- package/src/check.ts +343 -166
- package/src/cli/tlc-output.ts +1 -0
- package/src/cli/tlc.ts +3 -2
- package/src/codegen.ts +23 -8
- package/src/dependencies.ts +5 -4
- package/src/dfid.ts +13 -8
- package/src/environment.ts +1 -0
- package/src/evaluate.ts +58 -23
- package/src/exit-codes.ts +27 -13
- package/src/java-hash.ts +14 -0
- package/src/liveness-checker.ts +131 -81
- package/src/liveness.ts +48 -10
- package/src/parser.ts +6 -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 +109 -63
- package/src/prover/smt/solver/ast.ts +5 -3
- package/src/prover/smt/solver/auf-solver.ts +23 -12
- package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
- package/src/prover/smt/solver/bound-simplifier.ts +10 -11
- package/src/prover/smt/solver/card2bv.ts +34 -15
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -23
- package/src/prover/smt/solver/context.ts +44 -11
- package/src/prover/smt/solver/dependent-expr-state.ts +19 -13
- package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
- package/src/prover/smt/solver/elim-bounds.ts +89 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +1 -1
- package/src/prover/smt/solver/fd-solver.ts +146 -39
- package/src/prover/smt/solver/internalizer.ts +1 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +4 -0
- 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-checker.ts +1 -1
- package/src/prover/smt/solver/model-evaluator.ts +2 -0
- package/src/prover/smt/solver/model-generator.ts +82 -42
- package/src/prover/smt/solver/muz/dl-context.ts +12 -40
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
- package/src/prover/smt/solver/muz/dl-rule.ts +6 -7
- package/src/prover/smt/solver/muz/hnf.ts +2 -2
- package/src/prover/smt/solver/muz/horn-tactic.ts +14 -1
- package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
- package/src/prover/smt/solver/opt-context.ts +12 -4
- package/src/prover/smt/solver/opt-pareto.ts +19 -0
- package/src/prover/smt/solver/opt-solver.ts +4 -3
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- package/src/prover/smt/solver/poly-rewriter.ts +1 -0
- package/src/prover/smt/solver/proto-model.ts +4 -2
- package/src/prover/smt/solver/push-app-ite.ts +37 -0
- package/src/prover/smt/solver/qsat.ts +23 -8
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
- package/src/prover/smt/solver/rewriter.ts +31 -25
- package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +56 -28
- package/src/prover/smt/solver/sat/sat-tactic.ts +13 -4
- package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
- package/src/prover/smt/solver/smt-consequences.ts +1 -1
- package/src/prover/smt/solver/smt-kernel.ts +39 -4
- package/src/prover/smt/solver/smt-setup.ts +28 -4
- package/src/prover/smt/solver/smtlib-parser.ts +31 -4
- package/src/prover/smt/solver/smtlib-script.ts +219 -82
- package/src/prover/smt/solver/solve-eqs.ts +24 -17
- package/src/prover/smt/solver/solver.ts +18 -3
- package/src/prover/smt/solver/tactic.ts +132 -78
- package/src/prover/smt/solver/theory-bv.ts +11 -1
- 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 +1 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +7 -1
- package/src/prover/smt/solver/theory-lra.ts +1 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
- package/src/resolve.ts +446 -167
- package/src/runtime.ts +4 -0
- package/src/search.ts +161 -92
- package/src/simulate.ts +165 -102
- package/src/spec-description.ts +3 -4
- package/src/standard-modules.ts +56 -22
- package/src/subexpressions.ts +168 -49
- package/src/successors.ts +6 -3
- package/src/symmetry.ts +1 -0
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +22 -14
- package/src/tlc/tlc-operators.ts +7 -7
- package/src/tlc/tlcext-operators.ts +26 -10
- package/src/tlc/trace-spec.ts +6 -20
- package/src/typed-tier.ts +9 -4
- package/src/values.ts +95 -57
package/src/check.ts
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
} from "./check-failure";
|
|
38
38
|
import {
|
|
39
39
|
createTraceBuilder,
|
|
40
|
+
NEXT_RECOVERY_FAILURE,
|
|
40
41
|
type Behavior,
|
|
41
42
|
type SearchPosition,
|
|
42
43
|
type TracedStep,
|
|
@@ -108,7 +109,11 @@ import {
|
|
|
108
109
|
walkSuccessors,
|
|
109
110
|
} from "./tlc/replay";
|
|
110
111
|
import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc/summary";
|
|
111
|
-
import {
|
|
112
|
+
import {
|
|
113
|
+
createActionRecord,
|
|
114
|
+
createCounterExample,
|
|
115
|
+
type CounterExampleLoop,
|
|
116
|
+
} from "./tlc/tlcext-operators";
|
|
112
117
|
import type { TlcVersion } from "./tlc/version";
|
|
113
118
|
import { runTypedSearch, type TypedResult } from "./typed-tier";
|
|
114
119
|
import {
|
|
@@ -267,6 +272,11 @@ export interface Postcondition {
|
|
|
267
272
|
counts?: string;
|
|
268
273
|
}
|
|
269
274
|
|
|
275
|
+
export interface TraceFailure extends FailureMessage {
|
|
276
|
+
/** What the spec prints as TLC rebuilds the step it then fails to print. */
|
|
277
|
+
output: OutputLine[];
|
|
278
|
+
}
|
|
279
|
+
|
|
270
280
|
/** An evaluation that failed during the search, with the behavior up to the state TLC was working on. */
|
|
271
281
|
export interface EvaluationFailure {
|
|
272
282
|
code: number;
|
|
@@ -283,7 +293,7 @@ export interface EvaluationFailure {
|
|
|
283
293
|
/** The FingerprintException the replay raises, which TLC reports in place of the call stack. */
|
|
284
294
|
fingerprint?: FingerprintFailure;
|
|
285
295
|
/** How TLC reports failing again as it prints the trace, since it can't fingerprint the state. */
|
|
286
|
-
traceFailure?:
|
|
296
|
+
traceFailure?: TraceFailure;
|
|
287
297
|
/** A POSTCONDITION that is false or fails after the trace, which TLC checks as it prints one. */
|
|
288
298
|
postcondition?: Postcondition;
|
|
289
299
|
/** Whether TLC stops before it prints the statistics, as it does for an illegal initial state. */
|
|
@@ -309,7 +319,7 @@ export interface CheckResult {
|
|
|
309
319
|
outDegrees: number[] | undefined;
|
|
310
320
|
/** The smallest distance between two fingerprints, when TLC estimates a collision from them. */
|
|
311
321
|
fingerprintDistance: bigint | undefined;
|
|
312
|
-
/** A temporal property TLC finds violated as it adds
|
|
322
|
+
/** A temporal property TLC finds violated as it adds the state it stopped at to the behavior graph, reported after. */
|
|
313
323
|
additionalViolation?: Violation;
|
|
314
324
|
/** Where TLC's worker fails to add the state to the behavior graph after it reports a violation. */
|
|
315
325
|
liveCallStack?: Expression[];
|
|
@@ -327,11 +337,30 @@ interface ReportedViolation extends Omit<Violation, "loopStart"> {
|
|
|
327
337
|
loopStart?: number;
|
|
328
338
|
}
|
|
329
339
|
|
|
340
|
+
interface CounterExampleOptions {
|
|
341
|
+
isConsole: boolean;
|
|
342
|
+
}
|
|
343
|
+
|
|
330
344
|
const appendTraceOutput = <Traced extends Behavior>(behavior: Traced, lines: OutputLine[]) => ({
|
|
331
345
|
...behavior,
|
|
332
346
|
traceOutput: [...(behavior.traceOutput ?? []), ...lines],
|
|
333
347
|
});
|
|
334
348
|
|
|
349
|
+
const toUnexpectedError = (error: TlaEvaluationError) =>
|
|
350
|
+
new TlaEvaluationError(
|
|
351
|
+
`${isEvalException(error) ? UNEXPECTED_EVAL_EXCEPTION : UNEXPECTED_EXCEPTION}${error.message}`,
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
const getTraceFailure = (error: TlaEvaluationError, output: OutputLine[]): TraceFailure => ({
|
|
355
|
+
...getFailureMessage(
|
|
356
|
+
isEvalException(error)
|
|
357
|
+
? new TlaEvaluationError(`${UNEXPECTED_EVAL_EXCEPTION}${error.message}`)
|
|
358
|
+
: error,
|
|
359
|
+
true,
|
|
360
|
+
),
|
|
361
|
+
output,
|
|
362
|
+
});
|
|
363
|
+
|
|
335
364
|
const STOP_REPLAY = new Error("The replay stopped");
|
|
336
365
|
const STOP_WALK = new Error("The walk stopped");
|
|
337
366
|
|
|
@@ -508,19 +537,24 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
508
537
|
specification.moduleOperators.some((operator) => operator.kind === "postcondition");
|
|
509
538
|
const tracedSteps = new WeakMap<TraceStep, TracedStep>();
|
|
510
539
|
const getStepState = (step: TraceStep) => tracedSteps.get(step)?.state ?? step.state;
|
|
540
|
+
// TLC's Worker#doPostCondition and LiveCheck bind CounterExample to the alias of each state, while its initial states and lassos keep the states.
|
|
541
|
+
const getStepAlias = (step: TraceStep) => tracedSteps.get(step)?.alias ?? step.state;
|
|
511
542
|
const getStepAction = (step: TraceStep) => {
|
|
512
543
|
const action = tracedSteps.get(step)?.action;
|
|
513
544
|
return action ? toActionValue(action) : createActionRecord(step.action);
|
|
514
545
|
};
|
|
515
546
|
const checkTracePostconditions = (
|
|
516
547
|
trace: TraceStep[],
|
|
517
|
-
loop:
|
|
548
|
+
loop: CounterExampleLoop | undefined,
|
|
549
|
+
getState: (step: TraceStep) => Record<string, Value>,
|
|
550
|
+
isConsole = true,
|
|
518
551
|
) => {
|
|
519
552
|
if (hasPostconditions) {
|
|
520
553
|
runtime.counterExample = createCounterExample(
|
|
521
|
-
trace.map(
|
|
554
|
+
trace.map(getState),
|
|
522
555
|
trace.slice(1).map(getStepAction),
|
|
523
556
|
loop,
|
|
557
|
+
isConsole,
|
|
524
558
|
);
|
|
525
559
|
}
|
|
526
560
|
const unwitnessed = search.findUnwitnessedPossible();
|
|
@@ -532,12 +566,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
532
566
|
const reportViolation = (
|
|
533
567
|
status: CheckStatus,
|
|
534
568
|
violation: ReportedViolation,
|
|
569
|
+
getState = getStepAlias,
|
|
535
570
|
getLoopAction?: () => Value,
|
|
536
571
|
) => {
|
|
537
572
|
const start = violation.loopStart;
|
|
538
573
|
const checked = checkTracePostconditions(
|
|
539
574
|
violation.trace,
|
|
540
575
|
start === undefined || !getLoopAction ? undefined : { start, action: getLoopAction() },
|
|
576
|
+
getState,
|
|
541
577
|
);
|
|
542
578
|
return createResult(status, {
|
|
543
579
|
...violation,
|
|
@@ -594,6 +630,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
594
630
|
onState(successor);
|
|
595
631
|
},
|
|
596
632
|
(partial) => {
|
|
633
|
+
if (coverage) coverage.primary[action.node]++;
|
|
597
634
|
const missing = environment.variables.filter(
|
|
598
635
|
(_variable, index) => partial[index] === undefined,
|
|
599
636
|
);
|
|
@@ -605,6 +642,23 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
605
642
|
);
|
|
606
643
|
},
|
|
607
644
|
);
|
|
645
|
+
const hasCoveredIncompleteSuccessor = (action: CoveredAction, state: Value[]) => {
|
|
646
|
+
let complete = 0;
|
|
647
|
+
let incomplete = 0;
|
|
648
|
+
walkSuccessors(
|
|
649
|
+
action,
|
|
650
|
+
action.node,
|
|
651
|
+
state,
|
|
652
|
+
environment,
|
|
653
|
+
() => complete++,
|
|
654
|
+
() => {
|
|
655
|
+
incomplete++;
|
|
656
|
+
return true;
|
|
657
|
+
},
|
|
658
|
+
);
|
|
659
|
+
if (coverage) coverage.primary[action.node] += complete + incomplete;
|
|
660
|
+
return incomplete > 0;
|
|
661
|
+
};
|
|
608
662
|
const getCoveredSuccessors = (action: CoveredAction, state: Value[]) => {
|
|
609
663
|
const successors: Successor[] = [];
|
|
610
664
|
walkCoveredSuccessors(action, state, (successor) =>
|
|
@@ -657,7 +711,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
657
711
|
const deferred: unknown[] = [];
|
|
658
712
|
const addReplayed = createReplayedStates();
|
|
659
713
|
return getReplayFailure(environment, (tracing) => {
|
|
660
|
-
replayInitialStates(getDescription().inits, tracing, (state) => {
|
|
714
|
+
replayInitialStates(coverage ? coverageInits : getDescription().inits, tracing, (state) => {
|
|
661
715
|
reportInitialStatesProgress(replayedCount, (progress) => capturedLines?.push(progress));
|
|
662
716
|
replayedCount++;
|
|
663
717
|
runtime.generatedStates = replayedCount;
|
|
@@ -668,16 +722,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
668
722
|
runtime.queueSize++;
|
|
669
723
|
liveness?.addInitialState(states.length, state, tracing);
|
|
670
724
|
};
|
|
671
|
-
|
|
672
|
-
if (violation) {
|
|
725
|
+
search.checkReplayedInitialState(state, tracing, addFingerprint, (violation) => {
|
|
673
726
|
const traced = traces.toTrace([{ action: undefined, state }], []).trace[0].state;
|
|
674
727
|
capturedLines?.push({
|
|
675
728
|
kind: "initial-state-violation",
|
|
676
729
|
...violation,
|
|
677
730
|
state: traced,
|
|
678
731
|
});
|
|
679
|
-
|
|
680
|
-
|
|
732
|
+
if (!options.isContinued || violation.status !== "invariant-violation") {
|
|
733
|
+
throw STOP_REPLAY;
|
|
734
|
+
}
|
|
735
|
+
});
|
|
681
736
|
} catch (error) {
|
|
682
737
|
const isFingerprintFailure =
|
|
683
738
|
error instanceof TlaEvaluationError && tracing.callStack?.fingerprint !== undefined;
|
|
@@ -693,7 +748,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
693
748
|
const state = states[index];
|
|
694
749
|
const source = stateWriter && getGraphState(state, depths[index]);
|
|
695
750
|
const addReplayed = createReplayedStates();
|
|
696
|
-
replaySuccessors(nextActions, state, tracing, (next, action) => {
|
|
751
|
+
replaySuccessors(coverage ? coverageActions : nextActions, state, tracing, (next, action) => {
|
|
697
752
|
const addFingerprint = () => {
|
|
698
753
|
const isUnseen = addReplayed(next, tracing.callStack);
|
|
699
754
|
if (source) {
|
|
@@ -726,11 +781,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
726
781
|
(tlcFingerprints[successor.index] ??= Number(
|
|
727
782
|
BigInt.asIntN(32, runtime.getFingerprint(successor.state)),
|
|
728
783
|
)),
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
if (spec.next === undefined) return successors;
|
|
732
|
-
const livenessSource = current.livenessSource;
|
|
733
|
-
current.livenessSource = source;
|
|
784
|
+
forEachActionSuccessors: (source, state, onSuccessors) => {
|
|
785
|
+
let successors: LiveSuccessor[] = [];
|
|
734
786
|
const addSuccessor = (successor: Value[]) => {
|
|
735
787
|
canonicalizeState(successor);
|
|
736
788
|
const isInModel =
|
|
@@ -745,28 +797,34 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
745
797
|
state: successor,
|
|
746
798
|
});
|
|
747
799
|
};
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
800
|
+
const visitSuccessor = (successor: Successor) => {
|
|
801
|
+
addSuccessor(successor.state);
|
|
802
|
+
return false;
|
|
803
|
+
};
|
|
804
|
+
const actionCount = coverage ? coverageActions.length : nextActions.length;
|
|
805
|
+
for (let position = 0; position < actionCount; position++) {
|
|
806
|
+
successors = [];
|
|
807
|
+
const livenessSource = current.livenessSource;
|
|
808
|
+
current.livenessSource = source;
|
|
809
|
+
try {
|
|
810
|
+
// TLC's coverage counts the successors of each action the graph generates again.
|
|
811
|
+
if (coverage) {
|
|
812
|
+
walkCoveredSuccessors(coverageActions[position], state, addSuccessor);
|
|
813
|
+
} else {
|
|
814
|
+
const action = nextActions[position];
|
|
815
|
+
forEachSuccessor(
|
|
816
|
+
action.expression,
|
|
817
|
+
state,
|
|
818
|
+
environment,
|
|
819
|
+
visitSuccessor,
|
|
820
|
+
action.scope,
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
} finally {
|
|
824
|
+
current.livenessSource = livenessSource;
|
|
765
825
|
}
|
|
766
|
-
|
|
767
|
-
current.livenessSource = livenessSource;
|
|
826
|
+
onSuccessors(successors);
|
|
768
827
|
}
|
|
769
|
-
return successors;
|
|
770
828
|
},
|
|
771
829
|
}),
|
|
772
830
|
),
|
|
@@ -801,10 +859,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
801
859
|
const canonicalizeState = createCanonicalizer();
|
|
802
860
|
|
|
803
861
|
const toRecord = search.toRecord;
|
|
804
|
-
const
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
862
|
+
const getUncoveredInitialStates = () =>
|
|
863
|
+
spec.init === undefined ? [] : getInitialStates(spec.init, environment, spec.scope);
|
|
864
|
+
const getSpecInitialStates = () =>
|
|
865
|
+
coverage ? getCoveredInitialStates() : getUncoveredInitialStates();
|
|
808
866
|
const isUnfingerprintable = (state: Value[]) => {
|
|
809
867
|
try {
|
|
810
868
|
return getFingerprintState(state).some((value) => getFingerprintError(value) !== undefined);
|
|
@@ -813,19 +871,27 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
813
871
|
return true;
|
|
814
872
|
}
|
|
815
873
|
};
|
|
874
|
+
const checkFailedTrace = (behavior: Behavior, counterExample?: CounterExampleOptions) => {
|
|
875
|
+
if (!counterExample) return { behavior, postcondition: undefined };
|
|
876
|
+
const checked = checkTracePostconditions(
|
|
877
|
+
behavior.trace,
|
|
878
|
+
undefined,
|
|
879
|
+
getStepAlias,
|
|
880
|
+
counterExample.isConsole,
|
|
881
|
+
);
|
|
882
|
+
return {
|
|
883
|
+
behavior: appendTraceOutput(behavior, checked.lines),
|
|
884
|
+
postcondition: checked.unwitnessed ?? checked.postcondition,
|
|
885
|
+
};
|
|
886
|
+
};
|
|
816
887
|
const createFailureResult = (
|
|
817
888
|
failed: unknown,
|
|
818
889
|
behavior: Behavior,
|
|
819
890
|
failureOptions: FailureOptions = {},
|
|
891
|
+
postcondition?: Postcondition,
|
|
820
892
|
) => {
|
|
821
893
|
const error = isStackOverflow(failed) ? new TlaStackOverflowError() : failed;
|
|
822
894
|
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
895
|
return {
|
|
830
896
|
...createResult("error", undefined, {
|
|
831
897
|
...getFailureMessage(
|
|
@@ -833,7 +899,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
833
899
|
failureOptions.phase !== undefined && failureOptions.phase !== "initial",
|
|
834
900
|
),
|
|
835
901
|
...behavior,
|
|
836
|
-
...(traceOutput.length > 0 && { traceOutput }),
|
|
837
902
|
...(postcondition && { postcondition }),
|
|
838
903
|
initialState:
|
|
839
904
|
failureOptions.initialState && !(error instanceof TlaModuleError)
|
|
@@ -848,38 +913,66 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
848
913
|
outDegrees: failureOptions.outDegrees,
|
|
849
914
|
};
|
|
850
915
|
};
|
|
851
|
-
// Deviation from TLC:
|
|
916
|
+
// Deviation from TLC: Worker#doPostCondition throws an ArrayIndexOutOfBoundsException at an incomplete successor, where tla-ts checks the postconditions with the successor in CounterExample.
|
|
852
917
|
const reportIncompleteSuccessor = (
|
|
853
918
|
index: number,
|
|
854
919
|
error: TlaIncompleteSuccessorError,
|
|
855
920
|
liveSuccessors: LiveSuccessor[],
|
|
856
921
|
) => {
|
|
857
922
|
runtime.generatedStates++;
|
|
858
|
-
const
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
923
|
+
const found = captureOutput(() => {
|
|
924
|
+
try {
|
|
925
|
+
return {
|
|
926
|
+
action: coverage
|
|
927
|
+
? coverageActions.find((item) => hasCoveredIncompleteSuccessor(item, states[index]))
|
|
928
|
+
: nextActions.find((item) =>
|
|
929
|
+
hasIncompleteSuccessor(item.expression, states[index], environment, item.scope),
|
|
930
|
+
),
|
|
931
|
+
failed: undefined,
|
|
932
|
+
};
|
|
933
|
+
} catch (failed) {
|
|
934
|
+
if (!(failed instanceof TlaEvaluationError)) throw failed;
|
|
935
|
+
return { action: undefined, failed };
|
|
936
|
+
}
|
|
937
|
+
});
|
|
938
|
+
const action = found.result.action;
|
|
939
|
+
const traceFailure = found.result.failed && getTraceFailure(found.result.failed, found.lines);
|
|
870
940
|
const message = getIncompleteSuccessorMessage(
|
|
871
941
|
error.variables,
|
|
872
942
|
error.action,
|
|
873
943
|
nextActions.length,
|
|
874
944
|
options.version,
|
|
875
945
|
);
|
|
876
|
-
const undefinedValue = createModelValue("null");
|
|
877
|
-
const partial = error.state.map((value) => value ?? undefinedValue);
|
|
878
946
|
const live = captureOutput(() => addFailedLiveState(index, liveSuccessors));
|
|
947
|
+
const trace = traces.getStateTrace(index, { incomplete: error.state, isFailed: true }).trace;
|
|
948
|
+
const checked = checkFailedTrace(
|
|
949
|
+
appendTraceOutput(
|
|
950
|
+
{
|
|
951
|
+
trace: traceFailure
|
|
952
|
+
? trace
|
|
953
|
+
: [
|
|
954
|
+
...trace,
|
|
955
|
+
traces.getIncompleteStep(
|
|
956
|
+
error.state,
|
|
957
|
+
trace.length + 1,
|
|
958
|
+
{
|
|
959
|
+
action: error.action,
|
|
960
|
+
label: action && getActionLabel(action, options.version),
|
|
961
|
+
output: found.lines,
|
|
962
|
+
},
|
|
963
|
+
action,
|
|
964
|
+
),
|
|
965
|
+
],
|
|
966
|
+
},
|
|
967
|
+
live.lines,
|
|
968
|
+
),
|
|
969
|
+
{ isConsole: true },
|
|
970
|
+
);
|
|
879
971
|
const failure = createFailureResult(
|
|
880
972
|
error,
|
|
881
|
-
|
|
882
|
-
{ callStack: live.result },
|
|
973
|
+
checked.behavior,
|
|
974
|
+
{ callStack: live.result, traceFailure },
|
|
975
|
+
checked.postcondition,
|
|
883
976
|
);
|
|
884
977
|
return withOutDegrees({
|
|
885
978
|
...failure,
|
|
@@ -889,14 +982,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
889
982
|
message,
|
|
890
983
|
toolMessage: message,
|
|
891
984
|
exitCode: EXIT_STATUS.specEvaluationFailure,
|
|
892
|
-
trace: [
|
|
893
|
-
...failure.failure.trace,
|
|
894
|
-
{
|
|
895
|
-
action: error.action,
|
|
896
|
-
label: action && getActionLabel(action, options.version),
|
|
897
|
-
state: toRecord(partial),
|
|
898
|
-
},
|
|
899
|
-
],
|
|
900
985
|
},
|
|
901
986
|
});
|
|
902
987
|
};
|
|
@@ -949,6 +1034,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
949
1034
|
tracedSteps,
|
|
950
1035
|
captureOutput,
|
|
951
1036
|
getInitialStates: getSpecInitialStates,
|
|
1037
|
+
getUncoveredInitialStates,
|
|
952
1038
|
findSuccessorAction,
|
|
953
1039
|
});
|
|
954
1040
|
const getPath = (index: number): Value[][] =>
|
|
@@ -975,7 +1061,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
975
1061
|
const index = state === current.candidate ? -1 : states.indexOf(state);
|
|
976
1062
|
return index === -1 ? [...getPath(current.index), state] : getPath(index);
|
|
977
1063
|
};
|
|
978
|
-
runtime.getCurrentState = () =>
|
|
1064
|
+
runtime.getCurrentState = () =>
|
|
1065
|
+
current.rebuilt?.state ?? (current.index === -1 ? undefined : states[current.index]);
|
|
979
1066
|
runtime.setLivenessSource = (index) => {
|
|
980
1067
|
current.livenessSource = index ?? -1;
|
|
981
1068
|
};
|
|
@@ -1011,14 +1098,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1011
1098
|
});
|
|
1012
1099
|
|
|
1013
1100
|
const visitInitialState = (state: Value[]) => {
|
|
1014
|
-
canonicalizeState(state);
|
|
1015
1101
|
runtime.generatedStates++;
|
|
1016
1102
|
runtime.initialStates++;
|
|
1017
1103
|
current.candidate = state;
|
|
1018
1104
|
current.candidateLevel = 1;
|
|
1019
|
-
const fingerprintState = getFingerprintState(state);
|
|
1020
|
-
const hash = getStateHash(fingerprintState);
|
|
1021
1105
|
const isInModel = search.satisfiesConstraints(state);
|
|
1106
|
+
// TLC fingerprints only a state in the model, which sorts its records in place.
|
|
1107
|
+
if (isInModel) canonicalizeState(state);
|
|
1108
|
+
const fingerprintState = isInModel ? getFingerprintState(state) : state;
|
|
1109
|
+
const hash = isInModel ? getStateHash(fingerprintState) : 0;
|
|
1022
1110
|
if (isInModel) {
|
|
1023
1111
|
search.trackStatePossible(state);
|
|
1024
1112
|
fingerprintModelState(fingerprintState);
|
|
@@ -1034,7 +1122,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1034
1122
|
stateWriter?.writeInitialState(getGraphState(state, 1));
|
|
1035
1123
|
}
|
|
1036
1124
|
if (options.isContinued) {
|
|
1037
|
-
search.
|
|
1125
|
+
search.forEachViolatedInvariant(state, (invariant) =>
|
|
1038
1126
|
reportContinuedViolation("invariant-violation", {
|
|
1039
1127
|
name: invariant.name,
|
|
1040
1128
|
...traces.toTrace([{ action: undefined, state }], []),
|
|
@@ -1043,17 +1131,19 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1043
1131
|
}
|
|
1044
1132
|
const violated = options.isContinued ? undefined : search.findViolatedInvariant(state);
|
|
1045
1133
|
if (violated) {
|
|
1046
|
-
return reportViolation(
|
|
1047
|
-
|
|
1048
|
-
...traces.toTrace([{ action: undefined, state }], []),
|
|
1049
|
-
|
|
1134
|
+
return reportViolation(
|
|
1135
|
+
"invariant-violation",
|
|
1136
|
+
{ name: violated.name, ...traces.toTrace([{ action: undefined, state }], []) },
|
|
1137
|
+
getStepState,
|
|
1138
|
+
);
|
|
1050
1139
|
}
|
|
1051
1140
|
const failedPredicate = search.findFailedInitialPredicate(state);
|
|
1052
1141
|
if (failedPredicate) {
|
|
1053
|
-
return reportViolation(
|
|
1054
|
-
|
|
1055
|
-
...traces.toTrace([{ action: undefined, state }], []),
|
|
1056
|
-
|
|
1142
|
+
return reportViolation(
|
|
1143
|
+
"liveness-violation",
|
|
1144
|
+
{ name: failedPredicate.name, ...traces.toTrace([{ action: undefined, state }], []) },
|
|
1145
|
+
getStepState,
|
|
1146
|
+
);
|
|
1057
1147
|
}
|
|
1058
1148
|
if (!isInModel) return undefined;
|
|
1059
1149
|
markSeenState(seenStates, hash, states.length);
|
|
@@ -1063,18 +1153,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1063
1153
|
// Looks a successor up, where the constraints keep it in the model, as the search does before it
|
|
1064
1154
|
// checks the successor.
|
|
1065
1155
|
const lookUpSuccessor = (state: Value[], successor: Successor) => {
|
|
1066
|
-
const fingerprintState = getFingerprintState(successor.state);
|
|
1067
|
-
const hash = getStateHash(fingerprintState);
|
|
1068
|
-
const foundIndex = findStateIndex(seenStates, hash, fingerprintState);
|
|
1069
1156
|
const isStateInModel = search.satisfiesConstraints(successor.state, state);
|
|
1070
1157
|
if (isStateInModel) search.trackStatePossible(successor.state);
|
|
1071
1158
|
const isInModel = isStateInModel && search.satisfiesActionConstraints(state, successor.state);
|
|
1159
|
+
const fingerprintState = isInModel ? getFingerprintState(successor.state) : successor.state;
|
|
1160
|
+
const hash = isInModel ? getStateHash(fingerprintState) : 0;
|
|
1072
1161
|
if (isInModel) {
|
|
1073
1162
|
search.trackActionPossible(state, successor.state);
|
|
1074
1163
|
fingerprintModelState(fingerprintState);
|
|
1075
1164
|
successor.state.forEach(markFingerprinted);
|
|
1076
1165
|
}
|
|
1077
|
-
const existing = isInModel ?
|
|
1166
|
+
const existing = isInModel ? findStateIndex(seenStates, hash, fingerprintState) : -1;
|
|
1078
1167
|
return {
|
|
1079
1168
|
fingerprintState,
|
|
1080
1169
|
hash,
|
|
@@ -1146,10 +1235,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1146
1235
|
if (violation) reportContinuedViolation("invariant-violation", violation);
|
|
1147
1236
|
} catch (error) {
|
|
1148
1237
|
if (isStackOverflow(error)) throw error;
|
|
1238
|
+
const behavior = traces.getTrace(index, successor, { isFailed: true });
|
|
1149
1239
|
const replay = captureOutput(() => replayNext(index));
|
|
1150
1240
|
return createFailureResult(
|
|
1151
1241
|
error,
|
|
1152
|
-
appendTraceOutput(
|
|
1242
|
+
appendTraceOutput(behavior, replay.lines),
|
|
1153
1243
|
replay.result ?? { outDegrees: getFailureOutDegrees() },
|
|
1154
1244
|
);
|
|
1155
1245
|
}
|
|
@@ -1282,14 +1372,29 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1282
1372
|
}
|
|
1283
1373
|
} catch (error) {
|
|
1284
1374
|
if (error instanceof TlaIllegalStateError) {
|
|
1375
|
+
reportInitialStatesProgress(runtime.initialStates, options.onProgress);
|
|
1376
|
+
runtime.generatedStates++;
|
|
1377
|
+
runtime.initialStates++;
|
|
1378
|
+
const state = error.state.map((value) => value ?? createModelValue("null"));
|
|
1379
|
+
// Deviation from TLC: CounterExample holds a Java null for an unassigned variable and leaks a NullPointerException, where tla-ts binds the model value null.
|
|
1380
|
+
const checked = checkTracePostconditions(
|
|
1381
|
+
[{ action: undefined, label: undefined, state: toRecord(state) }],
|
|
1382
|
+
undefined,
|
|
1383
|
+
getStepState,
|
|
1384
|
+
);
|
|
1385
|
+
const postcondition = checked.unwitnessed ?? checked.postcondition;
|
|
1285
1386
|
const illegal = createFailureResult(
|
|
1286
1387
|
error,
|
|
1287
|
-
{ trace: [] },
|
|
1288
|
-
{ initialState:
|
|
1388
|
+
{ trace: [], traceOutput: checked.lines },
|
|
1389
|
+
{ initialState: state },
|
|
1289
1390
|
);
|
|
1290
1391
|
return {
|
|
1291
1392
|
...illegal,
|
|
1292
|
-
failure: illegal.failure && {
|
|
1393
|
+
failure: illegal.failure && {
|
|
1394
|
+
...illegal.failure,
|
|
1395
|
+
isWithoutStatistics: true,
|
|
1396
|
+
...(postcondition && { postcondition }),
|
|
1397
|
+
},
|
|
1293
1398
|
};
|
|
1294
1399
|
}
|
|
1295
1400
|
const replay = captureOutput(replayInit);
|
|
@@ -1375,6 +1480,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1375
1480
|
);
|
|
1376
1481
|
}, 0);
|
|
1377
1482
|
};
|
|
1483
|
+
// Deviation from TLC: Worker#doNextCheckLiveness doesn't catch a FingerprintException from its rerun, so TLC prints the behavior without the failure.
|
|
1378
1484
|
const getLiveCallStack = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1379
1485
|
if (!liveness || is174) return undefined;
|
|
1380
1486
|
const replay = getReplayFailure(environment, (tracing) =>
|
|
@@ -1398,23 +1504,87 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1398
1504
|
return { result, lines: live.lines };
|
|
1399
1505
|
}
|
|
1400
1506
|
const replay = captureOutput(() => replayNext(index));
|
|
1401
|
-
|
|
1507
|
+
const result: FailureOptions =
|
|
1508
|
+
replay.result ?? (is174 ? {} : { outDegrees: getFailureOutDegrees() });
|
|
1509
|
+
return { result, lines: [...live.lines, ...replay.lines] };
|
|
1510
|
+
};
|
|
1511
|
+
const getNextFailureTrace = (index: number, counterExample?: CounterExampleOptions) =>
|
|
1512
|
+
checkFailedTrace(traces.getStateTrace(index, { isFailed: !counterExample }), counterExample);
|
|
1513
|
+
const reportNextStateOverflow = (index: number, counterExample?: CounterExampleOptions) => {
|
|
1514
|
+
const checked = getNextFailureTrace(index, counterExample);
|
|
1515
|
+
return createFailureResult(
|
|
1516
|
+
createStackOverflowError(),
|
|
1517
|
+
checked.behavior,
|
|
1518
|
+
{ phase: "next" },
|
|
1519
|
+
checked.postcondition,
|
|
1520
|
+
);
|
|
1402
1521
|
};
|
|
1403
|
-
|
|
1404
|
-
createFailureResult(createStackOverflowError(), traces.getStateTrace(index), { phase: "next" });
|
|
1522
|
+
// 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.
|
|
1405
1523
|
const reportNextStateFailure = (
|
|
1406
1524
|
error: unknown,
|
|
1407
1525
|
index: number,
|
|
1408
1526
|
liveSuccessors: LiveSuccessor[],
|
|
1527
|
+
generated: number,
|
|
1409
1528
|
) => {
|
|
1410
|
-
|
|
1529
|
+
// TLC's Worker goes on to find a state without successors deadlocked after it fails, which checks the postconditions.
|
|
1530
|
+
const counterExample =
|
|
1531
|
+
config.checkDeadlock && runtime.generatedStates === generated
|
|
1532
|
+
? { isConsole: false }
|
|
1533
|
+
: undefined;
|
|
1534
|
+
if (isStackOverflow(error)) return reportNextStateOverflow(index, counterExample);
|
|
1535
|
+
const checked = getNextFailureTrace(index, counterExample);
|
|
1411
1536
|
const replay = replayFailedNext(index, liveSuccessors);
|
|
1412
1537
|
return createFailureResult(
|
|
1413
1538
|
withNextStateExitCode(error),
|
|
1414
|
-
appendTraceOutput(
|
|
1539
|
+
appendTraceOutput(checked.behavior, replay.lines),
|
|
1415
1540
|
{ phase: "next", ...replay.result },
|
|
1541
|
+
checked.postcondition,
|
|
1416
1542
|
);
|
|
1417
1543
|
};
|
|
1544
|
+
const addLiveState = (
|
|
1545
|
+
index: number,
|
|
1546
|
+
liveSuccessors: LiveSuccessor[],
|
|
1547
|
+
source: GraphState | undefined,
|
|
1548
|
+
) => {
|
|
1549
|
+
if (liveness && source && (is174 || options.dump?.stuttering)) {
|
|
1550
|
+
stateWriter?.writeStuttering(source);
|
|
1551
|
+
}
|
|
1552
|
+
const accepted = liveness?.addState(index, states[index], liveSuccessors);
|
|
1553
|
+
if (!liveness || !accepted) return undefined;
|
|
1554
|
+
// Deviation from TLC: under -continue, TLC's LiveCheck throws an InvariantViolatedException after it reports the property, which its Worker reports as unexpected.
|
|
1555
|
+
const steps = traces.getPathSteps(accepted);
|
|
1556
|
+
const properties = getViolatedProperties(
|
|
1557
|
+
liveness,
|
|
1558
|
+
steps.map((step) => step.state),
|
|
1559
|
+
steps.length - 1,
|
|
1560
|
+
);
|
|
1561
|
+
return reportViolation("property-violation", {
|
|
1562
|
+
name: properties[0],
|
|
1563
|
+
properties,
|
|
1564
|
+
...traces.toTrace(steps, accepted, { known: 0 }),
|
|
1565
|
+
});
|
|
1566
|
+
};
|
|
1567
|
+
const addReportedLiveState = (
|
|
1568
|
+
index: number,
|
|
1569
|
+
liveSuccessors: LiveSuccessor[],
|
|
1570
|
+
source: GraphState | undefined,
|
|
1571
|
+
) =>
|
|
1572
|
+
captureOutput(() => {
|
|
1573
|
+
try {
|
|
1574
|
+
return {
|
|
1575
|
+
additional: addLiveState(index, liveSuccessors, source)?.violation,
|
|
1576
|
+
isFailed: false,
|
|
1577
|
+
callStack: undefined,
|
|
1578
|
+
};
|
|
1579
|
+
} catch (error) {
|
|
1580
|
+
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1581
|
+
return {
|
|
1582
|
+
additional: undefined,
|
|
1583
|
+
isFailed: true,
|
|
1584
|
+
callStack: getLiveCallStack(index, liveSuccessors),
|
|
1585
|
+
};
|
|
1586
|
+
}
|
|
1587
|
+
});
|
|
1418
1588
|
const expandState = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1419
1589
|
const state = states[index];
|
|
1420
1590
|
const source = stateWriter && getGraphState(state, depths[index]);
|
|
@@ -1436,10 +1606,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1436
1606
|
outcome = reportNextStateOverflow(index);
|
|
1437
1607
|
return true;
|
|
1438
1608
|
}
|
|
1439
|
-
const replay = is174
|
|
1440
|
-
? captureOutput(() => replayNext(index))
|
|
1441
|
-
: replayFailedNext(index, liveSuccessors);
|
|
1442
1609
|
if (is174 && error instanceof TlaEvaluationError && !isHeadedError(error)) {
|
|
1610
|
+
const replay = captureOutput(() => replayNext(index));
|
|
1443
1611
|
outcome = createFailureResult(
|
|
1444
1612
|
new TlaEvaluationError(`${getWrappedException(error)}${error.message}`, error),
|
|
1445
1613
|
appendTraceOutput({ trace: [] }, replay.lines),
|
|
@@ -1447,71 +1615,56 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1447
1615
|
);
|
|
1448
1616
|
return true;
|
|
1449
1617
|
}
|
|
1450
|
-
const
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
? getFailureMessage(
|
|
1454
|
-
isEvalException(error)
|
|
1455
|
-
? new TlaEvaluationError(`${UNEXPECTED_EVAL_EXCEPTION}${error.message}`)
|
|
1456
|
-
: error,
|
|
1457
|
-
true,
|
|
1458
|
-
)
|
|
1618
|
+
const traceError =
|
|
1619
|
+
error instanceof TlaEvaluationError && isUnfingerprintable(successor.state)
|
|
1620
|
+
? error
|
|
1459
1621
|
: undefined;
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1622
|
+
const behavior = traceError
|
|
1623
|
+
? traces.getStateTrace(index, { isFailed: true })
|
|
1624
|
+
: traces.getTrace(index, successor, { isFailed: true });
|
|
1625
|
+
const traceFailure =
|
|
1626
|
+
traceError &&
|
|
1627
|
+
getTraceFailure(
|
|
1628
|
+
traceError,
|
|
1629
|
+
captureOutput(() => {
|
|
1630
|
+
try {
|
|
1631
|
+
traces.findStepAction(index, state, successor.state, true);
|
|
1632
|
+
} catch (failed) {
|
|
1633
|
+
if (!(failed instanceof TlaEvaluationError)) throw failed;
|
|
1634
|
+
}
|
|
1635
|
+
}).lines,
|
|
1636
|
+
);
|
|
1637
|
+
const replay = is174
|
|
1638
|
+
? captureOutput(() => replayNext(index))
|
|
1639
|
+
: replayFailedNext(index, liveSuccessors);
|
|
1640
|
+
outcome = createFailureResult(error, appendTraceOutput(behavior, replay.lines), {
|
|
1641
|
+
phase: "next",
|
|
1642
|
+
...replay.result,
|
|
1643
|
+
traceFailure,
|
|
1644
|
+
});
|
|
1468
1645
|
}
|
|
1469
1646
|
return outcome !== undefined;
|
|
1470
1647
|
});
|
|
1471
1648
|
current.isExpanding = false;
|
|
1472
1649
|
const result = outcome;
|
|
1473
1650
|
if (result?.violation && !is174) {
|
|
1474
|
-
const live =
|
|
1651
|
+
const live = addReportedLiveState(index, liveSuccessors, source);
|
|
1475
1652
|
return {
|
|
1476
1653
|
...result,
|
|
1477
1654
|
violation: appendTraceOutput(result.violation, live.lines),
|
|
1478
1655
|
// TLC adds the state to the behavior graph before it reports the coverage.
|
|
1479
1656
|
coverage: getCoverage(),
|
|
1480
|
-
...(live.result && {
|
|
1657
|
+
...(live.result.additional && { additionalViolation: live.result.additional }),
|
|
1658
|
+
...(live.result.callStack && { liveCallStack: live.result.callStack }),
|
|
1481
1659
|
};
|
|
1482
1660
|
}
|
|
1483
1661
|
if (result) return result;
|
|
1484
|
-
const addLiveState = () => {
|
|
1485
|
-
if (liveness && source && (is174 || options.dump?.stuttering)) {
|
|
1486
|
-
stateWriter?.writeStuttering(source);
|
|
1487
|
-
}
|
|
1488
|
-
const accepted = liveness?.addState(index, state, liveSuccessors);
|
|
1489
|
-
if (!liveness || !accepted) return undefined;
|
|
1490
|
-
const steps = traces.getPathSteps(accepted);
|
|
1491
|
-
const properties = getViolatedProperties(
|
|
1492
|
-
liveness,
|
|
1493
|
-
steps.map((step) => step.state),
|
|
1494
|
-
steps.length - 1,
|
|
1495
|
-
);
|
|
1496
|
-
return reportViolation("property-violation", {
|
|
1497
|
-
name: properties[0],
|
|
1498
|
-
properties,
|
|
1499
|
-
...traces.toTrace(steps, accepted, { known: 0 }),
|
|
1500
|
-
});
|
|
1501
|
-
};
|
|
1502
1662
|
if (successorCount === 0 && config.checkDeadlock) {
|
|
1503
1663
|
const deadlock = reportViolation("deadlock", {
|
|
1504
1664
|
name: "deadlock",
|
|
1505
1665
|
...traces.getStateTrace(index),
|
|
1506
1666
|
});
|
|
1507
|
-
const live =
|
|
1508
|
-
try {
|
|
1509
|
-
return { additional: addLiveState()?.violation };
|
|
1510
|
-
} catch (error) {
|
|
1511
|
-
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1512
|
-
return { isFailed: true, callStack: getLiveCallStack(index, liveSuccessors) };
|
|
1513
|
-
}
|
|
1514
|
-
});
|
|
1667
|
+
const live = addReportedLiveState(index, liveSuccessors, source);
|
|
1515
1668
|
const reported = deadlock.violation
|
|
1516
1669
|
? { ...deadlock, violation: appendTraceOutput(deadlock.violation, live.lines) }
|
|
1517
1670
|
: deadlock;
|
|
@@ -1524,14 +1677,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1524
1677
|
return live.result.callStack ? { ...counted, liveCallStack: live.result.callStack } : counted;
|
|
1525
1678
|
}
|
|
1526
1679
|
try {
|
|
1527
|
-
return addLiveState();
|
|
1680
|
+
return addLiveState(index, liveSuccessors, source);
|
|
1528
1681
|
} catch (error) {
|
|
1529
1682
|
if (is174 && error instanceof TlaEvaluationError) {
|
|
1530
|
-
const unexpected = new TlaEvaluationError(
|
|
1531
|
-
`${isEvalException(error) ? UNEXPECTED_EVAL_EXCEPTION : UNEXPECTED_EXCEPTION}${error.message}`,
|
|
1532
|
-
);
|
|
1533
1683
|
return createFailureResult(
|
|
1534
|
-
setExitCode(
|
|
1684
|
+
setExitCode(toUnexpectedError(error), EXIT_STATUS.error),
|
|
1535
1685
|
{ trace: [] },
|
|
1536
1686
|
{ outDegrees: getFailureOutDegrees() },
|
|
1537
1687
|
);
|
|
@@ -1539,7 +1689,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1539
1689
|
const replay = getReplayFailure(environment, (tracing) =>
|
|
1540
1690
|
liveness?.addState(index, state, liveSuccessors, tracing),
|
|
1541
1691
|
);
|
|
1542
|
-
|
|
1692
|
+
const behavior = traces.getStateTrace(index, { isFailed: true });
|
|
1693
|
+
const replayed = captureOutput(() => replayNext(index));
|
|
1694
|
+
return createFailureResult(error, appendTraceOutput(behavior, replayed.lines), {
|
|
1543
1695
|
outDegrees: getFailureOutDegrees(),
|
|
1544
1696
|
callStack: replay?.callStack.length ? replay.callStack : undefined,
|
|
1545
1697
|
phase: "liveness",
|
|
@@ -1563,10 +1715,20 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1563
1715
|
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}`,
|
|
1564
1716
|
};
|
|
1565
1717
|
};
|
|
1718
|
+
const toLivenessFailure = (error: TlaEvaluationError) =>
|
|
1719
|
+
setExitCode(toUnexpectedError(error), EXIT_STATUS.abort);
|
|
1720
|
+
const getLassoSteps = (path: number[]) => {
|
|
1721
|
+
try {
|
|
1722
|
+
return traces.getPathSteps(path);
|
|
1723
|
+
} catch (error) {
|
|
1724
|
+
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1725
|
+
throw toLivenessFailure(error);
|
|
1726
|
+
}
|
|
1727
|
+
};
|
|
1566
1728
|
const reportLasso = (checker: LivenessChecker, lasso: Lasso) => {
|
|
1567
1729
|
const path = [...lasso.prefix, ...lasso.cycle];
|
|
1568
1730
|
const loopStart = lasso.prefix.length;
|
|
1569
|
-
const steps =
|
|
1731
|
+
const steps = getLassoSteps(path);
|
|
1570
1732
|
const trace = traces.toTrace(steps, path, { loopStart, known: 0 }).trace;
|
|
1571
1733
|
const properties = getViolatedProperties(
|
|
1572
1734
|
checker,
|
|
@@ -1576,13 +1738,28 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1576
1738
|
const cycleStart = path[loopStart];
|
|
1577
1739
|
const cycleEnd = path[path.length - 1];
|
|
1578
1740
|
const lastState = steps[steps.length - 1].state;
|
|
1579
|
-
const
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1741
|
+
const isStuttering = cycleStart === cycleEnd;
|
|
1742
|
+
const loop = isStuttering
|
|
1743
|
+
? { result: undefined, lines: [] }
|
|
1744
|
+
: captureOutput(() => traces.findStepAction(cycleEnd, lastState, states[cycleStart], false));
|
|
1745
|
+
const back =
|
|
1746
|
+
isStuttering || loop.result
|
|
1747
|
+
? undefined
|
|
1748
|
+
: traces.findSuccessorWithFingerprint(lastState, cycleEnd, cycleStart);
|
|
1749
|
+
if (!isStuttering && !loop.result && !back) {
|
|
1750
|
+
options.onProgress?.({
|
|
1751
|
+
kind: "violation",
|
|
1752
|
+
status: "property-violation",
|
|
1753
|
+
violation: {
|
|
1754
|
+
name: properties[0],
|
|
1755
|
+
properties,
|
|
1756
|
+
trace,
|
|
1757
|
+
traceOutput: loop.lines,
|
|
1758
|
+
loopStart: undefined,
|
|
1759
|
+
},
|
|
1760
|
+
});
|
|
1761
|
+
throw toLivenessFailure(new TlaEvaluationError(NEXT_RECOVERY_FAILURE));
|
|
1762
|
+
}
|
|
1586
1763
|
return reportViolation(
|
|
1587
1764
|
"liveness-violation",
|
|
1588
1765
|
{
|
|
@@ -1592,16 +1769,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1592
1769
|
traceOutput: loop.lines,
|
|
1593
1770
|
loopStart,
|
|
1594
1771
|
loopLabel: loop.result && getActionLabel(loop.result, options.version),
|
|
1595
|
-
warning:
|
|
1772
|
+
warning: isStuttering && lasso.isCycleConstrained ? getStutteringWarning() : undefined,
|
|
1596
1773
|
},
|
|
1774
|
+
getStepState,
|
|
1597
1775
|
() =>
|
|
1598
|
-
|
|
1776
|
+
isStuttering
|
|
1599
1777
|
? getStepAction(trace[trace.length - 1])
|
|
1600
1778
|
: loop.result
|
|
1601
1779
|
? toActionValue(loop.result)
|
|
1602
|
-
: createActionRecord(
|
|
1603
|
-
traces.findSuccessorWithFingerprint(lastState, cycleStart)?.action,
|
|
1604
|
-
),
|
|
1780
|
+
: createActionRecord(back?.action),
|
|
1605
1781
|
);
|
|
1606
1782
|
};
|
|
1607
1783
|
const isPeriodic = liveness !== undefined && (options.livenessCheck ?? "default") === "default";
|
|
@@ -1743,13 +1919,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1743
1919
|
runtime.queueSize = states.length - index - 1;
|
|
1744
1920
|
current.isExpanding = true;
|
|
1745
1921
|
const liveSuccessors: LiveSuccessor[] = [];
|
|
1922
|
+
const generated = runtime.generatedStates;
|
|
1746
1923
|
try {
|
|
1747
1924
|
outcome = expandState(index, liveSuccessors);
|
|
1748
1925
|
} catch (error) {
|
|
1749
1926
|
outcome =
|
|
1750
1927
|
error instanceof TlaIncompleteSuccessorError
|
|
1751
1928
|
? reportIncompleteSuccessor(index, error, liveSuccessors)
|
|
1752
|
-
: reportNextStateFailure(error, index, liveSuccessors);
|
|
1929
|
+
: reportNextStateFailure(error, index, liveSuccessors, generated);
|
|
1753
1930
|
}
|
|
1754
1931
|
if (outcome) return outcome;
|
|
1755
1932
|
outDegrees[getOutDegreeBucket()]++;
|