tla-ts 0.0.10-dev.96638cd93 → 0.0.10-dev.a17d6d9fa
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 +30 -30
- package/dist/deciders.js +30 -30
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +60 -60
- package/dist/prove.js +73 -73
- package/dist/run.cjs +42 -42
- package/dist/run.js +42 -42
- package/dist/transfer.cjs +34 -34
- package/dist/transfer.js +29 -29
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/src/bags.ts +5 -2
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +1 -1
- package/src/check-trace.ts +90 -51
- package/src/check.ts +251 -133
- package/src/cli/tlc.ts +3 -2
- package/src/codegen.ts +18 -5
- package/src/dfid.ts +13 -8
- package/src/environment.ts +1 -0
- package/src/evaluate.ts +25 -9
- package/src/exit-codes.ts +1 -0
- package/src/java-hash.ts +14 -0
- package/src/liveness-checker.ts +63 -31
- 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 +31 -15
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -23
- package/src/prover/smt/solver/context.ts +24 -7
- package/src/prover/smt/solver/dependent-expr-state.ts +1 -1
- 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/internalizer.ts +1 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +4 -0
- 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/opt-context.ts +11 -4
- package/src/prover/smt/solver/opt-pareto.ts +19 -0
- package/src/prover/smt/solver/opt-solver.ts +3 -2
- 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 +16 -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 +13 -4
- package/src/prover/smt/solver/sat/sat-tactic.ts +9 -2
- package/src/prover/smt/solver/smt-kernel.ts +30 -2
- package/src/prover/smt/solver/smt-setup.ts +28 -4
- package/src/prover/smt/solver/smtlib-parser.ts +26 -3
- package/src/prover/smt/solver/smtlib-script.ts +34 -21
- 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 +68 -41
- 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 +120 -52
- package/src/runtime.ts +4 -0
- package/src/search.ts +117 -81
- package/src/simulate.ts +110 -50
- package/src/spec-description.ts +3 -4
- package/src/standard-modules.ts +15 -6
- package/src/subexpressions.ts +34 -9
- package/src/successors.ts +3 -2
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +3 -2
- 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 +3 -2
- 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 {
|
|
@@ -309,7 +314,7 @@ export interface CheckResult {
|
|
|
309
314
|
outDegrees: number[] | undefined;
|
|
310
315
|
/** The smallest distance between two fingerprints, when TLC estimates a collision from them. */
|
|
311
316
|
fingerprintDistance: bigint | undefined;
|
|
312
|
-
/** A temporal property TLC finds violated as it adds
|
|
317
|
+
/** A temporal property TLC finds violated as it adds the state it stopped at to the behavior graph, reported after. */
|
|
313
318
|
additionalViolation?: Violation;
|
|
314
319
|
/** Where TLC's worker fails to add the state to the behavior graph after it reports a violation. */
|
|
315
320
|
liveCallStack?: Expression[];
|
|
@@ -327,11 +332,28 @@ interface ReportedViolation extends Omit<Violation, "loopStart"> {
|
|
|
327
332
|
loopStart?: number;
|
|
328
333
|
}
|
|
329
334
|
|
|
335
|
+
interface CounterExampleOptions {
|
|
336
|
+
isConsole: boolean;
|
|
337
|
+
}
|
|
338
|
+
|
|
330
339
|
const appendTraceOutput = <Traced extends Behavior>(behavior: Traced, lines: OutputLine[]) => ({
|
|
331
340
|
...behavior,
|
|
332
341
|
traceOutput: [...(behavior.traceOutput ?? []), ...lines],
|
|
333
342
|
});
|
|
334
343
|
|
|
344
|
+
const toUnexpectedError = (error: TlaEvaluationError) =>
|
|
345
|
+
new TlaEvaluationError(
|
|
346
|
+
`${isEvalException(error) ? UNEXPECTED_EVAL_EXCEPTION : UNEXPECTED_EXCEPTION}${error.message}`,
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
const getTraceFailure = (error: TlaEvaluationError) =>
|
|
350
|
+
getFailureMessage(
|
|
351
|
+
isEvalException(error)
|
|
352
|
+
? new TlaEvaluationError(`${UNEXPECTED_EVAL_EXCEPTION}${error.message}`)
|
|
353
|
+
: error,
|
|
354
|
+
true,
|
|
355
|
+
);
|
|
356
|
+
|
|
335
357
|
const STOP_REPLAY = new Error("The replay stopped");
|
|
336
358
|
const STOP_WALK = new Error("The walk stopped");
|
|
337
359
|
|
|
@@ -508,19 +530,24 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
508
530
|
specification.moduleOperators.some((operator) => operator.kind === "postcondition");
|
|
509
531
|
const tracedSteps = new WeakMap<TraceStep, TracedStep>();
|
|
510
532
|
const getStepState = (step: TraceStep) => tracedSteps.get(step)?.state ?? step.state;
|
|
533
|
+
// TLC's Worker#doPostCondition and LiveCheck bind CounterExample to the alias of each state, while its initial states and lassos keep the states.
|
|
534
|
+
const getStepAlias = (step: TraceStep) => tracedSteps.get(step)?.alias ?? step.state;
|
|
511
535
|
const getStepAction = (step: TraceStep) => {
|
|
512
536
|
const action = tracedSteps.get(step)?.action;
|
|
513
537
|
return action ? toActionValue(action) : createActionRecord(step.action);
|
|
514
538
|
};
|
|
515
539
|
const checkTracePostconditions = (
|
|
516
540
|
trace: TraceStep[],
|
|
517
|
-
loop:
|
|
541
|
+
loop: CounterExampleLoop | undefined,
|
|
542
|
+
getState: (step: TraceStep) => Record<string, Value>,
|
|
543
|
+
isConsole = true,
|
|
518
544
|
) => {
|
|
519
545
|
if (hasPostconditions) {
|
|
520
546
|
runtime.counterExample = createCounterExample(
|
|
521
|
-
trace.map(
|
|
547
|
+
trace.map(getState),
|
|
522
548
|
trace.slice(1).map(getStepAction),
|
|
523
549
|
loop,
|
|
550
|
+
isConsole,
|
|
524
551
|
);
|
|
525
552
|
}
|
|
526
553
|
const unwitnessed = search.findUnwitnessedPossible();
|
|
@@ -532,12 +559,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
532
559
|
const reportViolation = (
|
|
533
560
|
status: CheckStatus,
|
|
534
561
|
violation: ReportedViolation,
|
|
562
|
+
getState = getStepAlias,
|
|
535
563
|
getLoopAction?: () => Value,
|
|
536
564
|
) => {
|
|
537
565
|
const start = violation.loopStart;
|
|
538
566
|
const checked = checkTracePostconditions(
|
|
539
567
|
violation.trace,
|
|
540
568
|
start === undefined || !getLoopAction ? undefined : { start, action: getLoopAction() },
|
|
569
|
+
getState,
|
|
541
570
|
);
|
|
542
571
|
return createResult(status, {
|
|
543
572
|
...violation,
|
|
@@ -668,16 +697,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
668
697
|
runtime.queueSize++;
|
|
669
698
|
liveness?.addInitialState(states.length, state, tracing);
|
|
670
699
|
};
|
|
671
|
-
|
|
672
|
-
if (violation) {
|
|
700
|
+
search.checkReplayedInitialState(state, tracing, addFingerprint, (violation) => {
|
|
673
701
|
const traced = traces.toTrace([{ action: undefined, state }], []).trace[0].state;
|
|
674
702
|
capturedLines?.push({
|
|
675
703
|
kind: "initial-state-violation",
|
|
676
704
|
...violation,
|
|
677
705
|
state: traced,
|
|
678
706
|
});
|
|
679
|
-
|
|
680
|
-
|
|
707
|
+
if (!options.isContinued || violation.status !== "invariant-violation") {
|
|
708
|
+
throw STOP_REPLAY;
|
|
709
|
+
}
|
|
710
|
+
});
|
|
681
711
|
} catch (error) {
|
|
682
712
|
const isFingerprintFailure =
|
|
683
713
|
error instanceof TlaEvaluationError && tracing.callStack?.fingerprint !== undefined;
|
|
@@ -726,11 +756,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
726
756
|
(tlcFingerprints[successor.index] ??= Number(
|
|
727
757
|
BigInt.asIntN(32, runtime.getFingerprint(successor.state)),
|
|
728
758
|
)),
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
if (spec.next === undefined) return successors;
|
|
732
|
-
const livenessSource = current.livenessSource;
|
|
733
|
-
current.livenessSource = source;
|
|
759
|
+
forEachActionSuccessors: (source, state, onSuccessors) => {
|
|
760
|
+
let successors: LiveSuccessor[] = [];
|
|
734
761
|
const addSuccessor = (successor: Value[]) => {
|
|
735
762
|
canonicalizeState(successor);
|
|
736
763
|
const isInModel =
|
|
@@ -745,28 +772,34 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
745
772
|
state: successor,
|
|
746
773
|
});
|
|
747
774
|
};
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
775
|
+
const visitSuccessor = (successor: Successor) => {
|
|
776
|
+
addSuccessor(successor.state);
|
|
777
|
+
return false;
|
|
778
|
+
};
|
|
779
|
+
const actionCount = coverage ? coverageActions.length : nextActions.length;
|
|
780
|
+
for (let position = 0; position < actionCount; position++) {
|
|
781
|
+
successors = [];
|
|
782
|
+
const livenessSource = current.livenessSource;
|
|
783
|
+
current.livenessSource = source;
|
|
784
|
+
try {
|
|
785
|
+
// TLC's coverage counts the successors of each action the graph generates again.
|
|
786
|
+
if (coverage) {
|
|
787
|
+
walkCoveredSuccessors(coverageActions[position], state, addSuccessor);
|
|
788
|
+
} else {
|
|
789
|
+
const action = nextActions[position];
|
|
790
|
+
forEachSuccessor(
|
|
791
|
+
action.expression,
|
|
792
|
+
state,
|
|
793
|
+
environment,
|
|
794
|
+
visitSuccessor,
|
|
795
|
+
action.scope,
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
} finally {
|
|
799
|
+
current.livenessSource = livenessSource;
|
|
765
800
|
}
|
|
766
|
-
|
|
767
|
-
current.livenessSource = livenessSource;
|
|
801
|
+
onSuccessors(successors);
|
|
768
802
|
}
|
|
769
|
-
return successors;
|
|
770
803
|
},
|
|
771
804
|
}),
|
|
772
805
|
),
|
|
@@ -817,13 +850,13 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
817
850
|
failed: unknown,
|
|
818
851
|
behavior: Behavior,
|
|
819
852
|
failureOptions: FailureOptions = {},
|
|
853
|
+
counterExample?: CounterExampleOptions,
|
|
820
854
|
) => {
|
|
821
855
|
const error = isStackOverflow(failed) ? new TlaStackOverflowError() : failed;
|
|
822
856
|
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
823
857
|
const checked =
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
: undefined;
|
|
858
|
+
counterExample &&
|
|
859
|
+
checkTracePostconditions(behavior.trace, undefined, getStepAlias, counterExample.isConsole);
|
|
827
860
|
const postcondition = checked?.unwitnessed ?? checked?.postcondition;
|
|
828
861
|
const traceOutput = [...(behavior.traceOutput ?? []), ...(checked?.lines ?? [])];
|
|
829
862
|
return {
|
|
@@ -848,38 +881,60 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
848
881
|
outDegrees: failureOptions.outDegrees,
|
|
849
882
|
};
|
|
850
883
|
};
|
|
851
|
-
// Deviation from TLC:
|
|
884
|
+
// Deviation from TLC: Worker#doPostCondition throws an ArrayIndexOutOfBoundsException at an incomplete successor, where tla-ts checks the postconditions with the successor in CounterExample.
|
|
852
885
|
const reportIncompleteSuccessor = (
|
|
853
886
|
index: number,
|
|
854
887
|
error: TlaIncompleteSuccessorError,
|
|
855
888
|
liveSuccessors: LiveSuccessor[],
|
|
856
889
|
) => {
|
|
857
890
|
runtime.generatedStates++;
|
|
858
|
-
const
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
891
|
+
const found = captureOutput(() => {
|
|
892
|
+
try {
|
|
893
|
+
return {
|
|
894
|
+
action: nextActions.find((item) =>
|
|
895
|
+
hasIncompleteSuccessor(item.expression, states[index], environment, item.scope),
|
|
896
|
+
),
|
|
897
|
+
traceFailure: undefined,
|
|
898
|
+
};
|
|
899
|
+
} catch (failed) {
|
|
900
|
+
if (!(failed instanceof TlaEvaluationError)) throw failed;
|
|
901
|
+
return { action: undefined, traceFailure: getTraceFailure(failed) };
|
|
902
|
+
}
|
|
903
|
+
});
|
|
904
|
+
const action = found.result.action;
|
|
905
|
+
const traceFailure = found.result.traceFailure;
|
|
870
906
|
const message = getIncompleteSuccessorMessage(
|
|
871
907
|
error.variables,
|
|
872
908
|
error.action,
|
|
873
909
|
nextActions.length,
|
|
874
910
|
options.version,
|
|
875
911
|
);
|
|
876
|
-
const undefinedValue = createModelValue("null");
|
|
877
|
-
const partial = error.state.map((value) => value ?? undefinedValue);
|
|
878
912
|
const live = captureOutput(() => addFailedLiveState(index, liveSuccessors));
|
|
913
|
+
const trace = traces.getStateTrace(index, error.state).trace;
|
|
879
914
|
const failure = createFailureResult(
|
|
880
915
|
error,
|
|
881
|
-
appendTraceOutput(
|
|
882
|
-
|
|
916
|
+
appendTraceOutput(
|
|
917
|
+
{
|
|
918
|
+
trace: traceFailure
|
|
919
|
+
? trace
|
|
920
|
+
: [
|
|
921
|
+
...trace,
|
|
922
|
+
traces.getIncompleteStep(
|
|
923
|
+
error.state,
|
|
924
|
+
trace.length + 1,
|
|
925
|
+
{
|
|
926
|
+
action: error.action,
|
|
927
|
+
label: action && getActionLabel(action, options.version),
|
|
928
|
+
output: found.lines,
|
|
929
|
+
},
|
|
930
|
+
action,
|
|
931
|
+
),
|
|
932
|
+
],
|
|
933
|
+
},
|
|
934
|
+
live.lines,
|
|
935
|
+
),
|
|
936
|
+
{ callStack: live.result, traceFailure },
|
|
937
|
+
{ isConsole: true },
|
|
883
938
|
);
|
|
884
939
|
return withOutDegrees({
|
|
885
940
|
...failure,
|
|
@@ -889,14 +944,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
889
944
|
message,
|
|
890
945
|
toolMessage: message,
|
|
891
946
|
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
947
|
},
|
|
901
948
|
});
|
|
902
949
|
};
|
|
@@ -975,7 +1022,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
975
1022
|
const index = state === current.candidate ? -1 : states.indexOf(state);
|
|
976
1023
|
return index === -1 ? [...getPath(current.index), state] : getPath(index);
|
|
977
1024
|
};
|
|
978
|
-
runtime.getCurrentState = () =>
|
|
1025
|
+
runtime.getCurrentState = () =>
|
|
1026
|
+
current.rebuilt?.state ?? (current.index === -1 ? undefined : states[current.index]);
|
|
979
1027
|
runtime.setLivenessSource = (index) => {
|
|
980
1028
|
current.livenessSource = index ?? -1;
|
|
981
1029
|
};
|
|
@@ -1034,7 +1082,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1034
1082
|
stateWriter?.writeInitialState(getGraphState(state, 1));
|
|
1035
1083
|
}
|
|
1036
1084
|
if (options.isContinued) {
|
|
1037
|
-
search.
|
|
1085
|
+
search.forEachViolatedInvariant(state, (invariant) =>
|
|
1038
1086
|
reportContinuedViolation("invariant-violation", {
|
|
1039
1087
|
name: invariant.name,
|
|
1040
1088
|
...traces.toTrace([{ action: undefined, state }], []),
|
|
@@ -1043,17 +1091,19 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1043
1091
|
}
|
|
1044
1092
|
const violated = options.isContinued ? undefined : search.findViolatedInvariant(state);
|
|
1045
1093
|
if (violated) {
|
|
1046
|
-
return reportViolation(
|
|
1047
|
-
|
|
1048
|
-
...traces.toTrace([{ action: undefined, state }], []),
|
|
1049
|
-
|
|
1094
|
+
return reportViolation(
|
|
1095
|
+
"invariant-violation",
|
|
1096
|
+
{ name: violated.name, ...traces.toTrace([{ action: undefined, state }], []) },
|
|
1097
|
+
getStepState,
|
|
1098
|
+
);
|
|
1050
1099
|
}
|
|
1051
1100
|
const failedPredicate = search.findFailedInitialPredicate(state);
|
|
1052
1101
|
if (failedPredicate) {
|
|
1053
|
-
return reportViolation(
|
|
1054
|
-
|
|
1055
|
-
...traces.toTrace([{ action: undefined, state }], []),
|
|
1056
|
-
|
|
1102
|
+
return reportViolation(
|
|
1103
|
+
"liveness-violation",
|
|
1104
|
+
{ name: failedPredicate.name, ...traces.toTrace([{ action: undefined, state }], []) },
|
|
1105
|
+
getStepState,
|
|
1106
|
+
);
|
|
1057
1107
|
}
|
|
1058
1108
|
if (!isInModel) return undefined;
|
|
1059
1109
|
markSeenState(seenStates, hash, states.length);
|
|
@@ -1282,14 +1332,29 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1282
1332
|
}
|
|
1283
1333
|
} catch (error) {
|
|
1284
1334
|
if (error instanceof TlaIllegalStateError) {
|
|
1335
|
+
reportInitialStatesProgress(runtime.initialStates, options.onProgress);
|
|
1336
|
+
runtime.generatedStates++;
|
|
1337
|
+
runtime.initialStates++;
|
|
1338
|
+
const state = error.state.map((value) => value ?? createModelValue("null"));
|
|
1339
|
+
// Deviation from TLC: CounterExample holds a Java null for an unassigned variable and leaks a NullPointerException, where tla-ts binds the model value null.
|
|
1340
|
+
const checked = checkTracePostconditions(
|
|
1341
|
+
[{ action: undefined, label: undefined, state: toRecord(state) }],
|
|
1342
|
+
undefined,
|
|
1343
|
+
getStepState,
|
|
1344
|
+
);
|
|
1345
|
+
const postcondition = checked.unwitnessed ?? checked.postcondition;
|
|
1285
1346
|
const illegal = createFailureResult(
|
|
1286
1347
|
error,
|
|
1287
|
-
{ trace: [] },
|
|
1288
|
-
{ initialState:
|
|
1348
|
+
{ trace: [], traceOutput: checked.lines },
|
|
1349
|
+
{ initialState: state },
|
|
1289
1350
|
);
|
|
1290
1351
|
return {
|
|
1291
1352
|
...illegal,
|
|
1292
|
-
failure: illegal.failure && {
|
|
1353
|
+
failure: illegal.failure && {
|
|
1354
|
+
...illegal.failure,
|
|
1355
|
+
isWithoutStatistics: true,
|
|
1356
|
+
...(postcondition && { postcondition }),
|
|
1357
|
+
},
|
|
1293
1358
|
};
|
|
1294
1359
|
}
|
|
1295
1360
|
const replay = captureOutput(replayInit);
|
|
@@ -1375,6 +1440,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1375
1440
|
);
|
|
1376
1441
|
}, 0);
|
|
1377
1442
|
};
|
|
1443
|
+
// Deviation from TLC: Worker#doNextCheckLiveness doesn't catch a FingerprintException from its rerun, so TLC prints the behavior without the failure.
|
|
1378
1444
|
const getLiveCallStack = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1379
1445
|
if (!liveness || is174) return undefined;
|
|
1380
1446
|
const replay = getReplayFailure(environment, (tracing) =>
|
|
@@ -1400,21 +1466,82 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1400
1466
|
const replay = captureOutput(() => replayNext(index));
|
|
1401
1467
|
return { result: replay.result, lines: [...live.lines, ...replay.lines] };
|
|
1402
1468
|
};
|
|
1403
|
-
const
|
|
1404
|
-
|
|
1469
|
+
const getNextFailureTrace = (index: number, counterExample?: CounterExampleOptions) => {
|
|
1470
|
+
const behavior = traces.getStateTrace(index);
|
|
1471
|
+
return counterExample ? behavior : { trace: behavior.trace };
|
|
1472
|
+
};
|
|
1473
|
+
const reportNextStateOverflow = (index: number, counterExample?: CounterExampleOptions) =>
|
|
1474
|
+
createFailureResult(
|
|
1475
|
+
createStackOverflowError(),
|
|
1476
|
+
getNextFailureTrace(index, counterExample),
|
|
1477
|
+
{ phase: "next" },
|
|
1478
|
+
counterExample,
|
|
1479
|
+
);
|
|
1480
|
+
// 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
1481
|
const reportNextStateFailure = (
|
|
1406
1482
|
error: unknown,
|
|
1407
1483
|
index: number,
|
|
1408
1484
|
liveSuccessors: LiveSuccessor[],
|
|
1485
|
+
generated: number,
|
|
1409
1486
|
) => {
|
|
1410
|
-
|
|
1487
|
+
// TLC's Worker goes on to find a state without successors deadlocked after it fails, which checks the postconditions.
|
|
1488
|
+
const counterExample =
|
|
1489
|
+
config.checkDeadlock && runtime.generatedStates === generated
|
|
1490
|
+
? { isConsole: false }
|
|
1491
|
+
: undefined;
|
|
1492
|
+
if (isStackOverflow(error)) return reportNextStateOverflow(index, counterExample);
|
|
1411
1493
|
const replay = replayFailedNext(index, liveSuccessors);
|
|
1412
1494
|
return createFailureResult(
|
|
1413
1495
|
withNextStateExitCode(error),
|
|
1414
|
-
appendTraceOutput(
|
|
1496
|
+
appendTraceOutput(getNextFailureTrace(index, counterExample), replay.lines),
|
|
1415
1497
|
{ phase: "next", ...replay.result },
|
|
1498
|
+
counterExample,
|
|
1499
|
+
);
|
|
1500
|
+
};
|
|
1501
|
+
const addLiveState = (
|
|
1502
|
+
index: number,
|
|
1503
|
+
liveSuccessors: LiveSuccessor[],
|
|
1504
|
+
source: GraphState | undefined,
|
|
1505
|
+
) => {
|
|
1506
|
+
if (liveness && source && (is174 || options.dump?.stuttering)) {
|
|
1507
|
+
stateWriter?.writeStuttering(source);
|
|
1508
|
+
}
|
|
1509
|
+
const accepted = liveness?.addState(index, states[index], liveSuccessors);
|
|
1510
|
+
if (!liveness || !accepted) return undefined;
|
|
1511
|
+
// Deviation from TLC: under -continue, TLC's LiveCheck throws an InvariantViolatedException after it reports the property, which its Worker reports as unexpected.
|
|
1512
|
+
const steps = traces.getPathSteps(accepted);
|
|
1513
|
+
const properties = getViolatedProperties(
|
|
1514
|
+
liveness,
|
|
1515
|
+
steps.map((step) => step.state),
|
|
1516
|
+
steps.length - 1,
|
|
1416
1517
|
);
|
|
1518
|
+
return reportViolation("property-violation", {
|
|
1519
|
+
name: properties[0],
|
|
1520
|
+
properties,
|
|
1521
|
+
...traces.toTrace(steps, accepted, { known: 0 }),
|
|
1522
|
+
});
|
|
1417
1523
|
};
|
|
1524
|
+
const addReportedLiveState = (
|
|
1525
|
+
index: number,
|
|
1526
|
+
liveSuccessors: LiveSuccessor[],
|
|
1527
|
+
source: GraphState | undefined,
|
|
1528
|
+
) =>
|
|
1529
|
+
captureOutput(() => {
|
|
1530
|
+
try {
|
|
1531
|
+
return {
|
|
1532
|
+
additional: addLiveState(index, liveSuccessors, source)?.violation,
|
|
1533
|
+
isFailed: false,
|
|
1534
|
+
callStack: undefined,
|
|
1535
|
+
};
|
|
1536
|
+
} catch (error) {
|
|
1537
|
+
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1538
|
+
return {
|
|
1539
|
+
additional: undefined,
|
|
1540
|
+
isFailed: true,
|
|
1541
|
+
callStack: getLiveCallStack(index, liveSuccessors),
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1544
|
+
});
|
|
1418
1545
|
const expandState = (index: number, liveSuccessors: LiveSuccessor[]) => {
|
|
1419
1546
|
const state = states[index];
|
|
1420
1547
|
const source = stateWriter && getGraphState(state, depths[index]);
|
|
@@ -1449,14 +1576,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1449
1576
|
}
|
|
1450
1577
|
const isTraceFailed = isUnfingerprintable(successor.state);
|
|
1451
1578
|
const traceFailure =
|
|
1452
|
-
isTraceFailed && error instanceof TlaEvaluationError
|
|
1453
|
-
? getFailureMessage(
|
|
1454
|
-
isEvalException(error)
|
|
1455
|
-
? new TlaEvaluationError(`${UNEXPECTED_EVAL_EXCEPTION}${error.message}`)
|
|
1456
|
-
: error,
|
|
1457
|
-
true,
|
|
1458
|
-
)
|
|
1459
|
-
: undefined;
|
|
1579
|
+
isTraceFailed && error instanceof TlaEvaluationError ? getTraceFailure(error) : undefined;
|
|
1460
1580
|
outcome = createFailureResult(
|
|
1461
1581
|
error,
|
|
1462
1582
|
appendTraceOutput(
|
|
@@ -1471,47 +1591,23 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1471
1591
|
current.isExpanding = false;
|
|
1472
1592
|
const result = outcome;
|
|
1473
1593
|
if (result?.violation && !is174) {
|
|
1474
|
-
const live =
|
|
1594
|
+
const live = addReportedLiveState(index, liveSuccessors, source);
|
|
1475
1595
|
return {
|
|
1476
1596
|
...result,
|
|
1477
1597
|
violation: appendTraceOutput(result.violation, live.lines),
|
|
1478
1598
|
// TLC adds the state to the behavior graph before it reports the coverage.
|
|
1479
1599
|
coverage: getCoverage(),
|
|
1480
|
-
...(live.result && {
|
|
1600
|
+
...(live.result.additional && { additionalViolation: live.result.additional }),
|
|
1601
|
+
...(live.result.callStack && { liveCallStack: live.result.callStack }),
|
|
1481
1602
|
};
|
|
1482
1603
|
}
|
|
1483
1604
|
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
1605
|
if (successorCount === 0 && config.checkDeadlock) {
|
|
1503
1606
|
const deadlock = reportViolation("deadlock", {
|
|
1504
1607
|
name: "deadlock",
|
|
1505
1608
|
...traces.getStateTrace(index),
|
|
1506
1609
|
});
|
|
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
|
-
});
|
|
1610
|
+
const live = addReportedLiveState(index, liveSuccessors, source);
|
|
1515
1611
|
const reported = deadlock.violation
|
|
1516
1612
|
? { ...deadlock, violation: appendTraceOutput(deadlock.violation, live.lines) }
|
|
1517
1613
|
: deadlock;
|
|
@@ -1524,14 +1620,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1524
1620
|
return live.result.callStack ? { ...counted, liveCallStack: live.result.callStack } : counted;
|
|
1525
1621
|
}
|
|
1526
1622
|
try {
|
|
1527
|
-
return addLiveState();
|
|
1623
|
+
return addLiveState(index, liveSuccessors, source);
|
|
1528
1624
|
} catch (error) {
|
|
1529
1625
|
if (is174 && error instanceof TlaEvaluationError) {
|
|
1530
|
-
const unexpected = new TlaEvaluationError(
|
|
1531
|
-
`${isEvalException(error) ? UNEXPECTED_EVAL_EXCEPTION : UNEXPECTED_EXCEPTION}${error.message}`,
|
|
1532
|
-
);
|
|
1533
1626
|
return createFailureResult(
|
|
1534
|
-
setExitCode(
|
|
1627
|
+
setExitCode(toUnexpectedError(error), EXIT_STATUS.error),
|
|
1535
1628
|
{ trace: [] },
|
|
1536
1629
|
{ outDegrees: getFailureOutDegrees() },
|
|
1537
1630
|
);
|
|
@@ -1563,10 +1656,20 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1563
1656
|
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
1657
|
};
|
|
1565
1658
|
};
|
|
1659
|
+
const toLivenessFailure = (error: TlaEvaluationError) =>
|
|
1660
|
+
setExitCode(toUnexpectedError(error), EXIT_STATUS.abort);
|
|
1661
|
+
const getLassoSteps = (path: number[]) => {
|
|
1662
|
+
try {
|
|
1663
|
+
return traces.getPathSteps(path);
|
|
1664
|
+
} catch (error) {
|
|
1665
|
+
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1666
|
+
throw toLivenessFailure(error);
|
|
1667
|
+
}
|
|
1668
|
+
};
|
|
1566
1669
|
const reportLasso = (checker: LivenessChecker, lasso: Lasso) => {
|
|
1567
1670
|
const path = [...lasso.prefix, ...lasso.cycle];
|
|
1568
1671
|
const loopStart = lasso.prefix.length;
|
|
1569
|
-
const steps =
|
|
1672
|
+
const steps = getLassoSteps(path);
|
|
1570
1673
|
const trace = traces.toTrace(steps, path, { loopStart, known: 0 }).trace;
|
|
1571
1674
|
const properties = getViolatedProperties(
|
|
1572
1675
|
checker,
|
|
@@ -1576,13 +1679,28 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1576
1679
|
const cycleStart = path[loopStart];
|
|
1577
1680
|
const cycleEnd = path[path.length - 1];
|
|
1578
1681
|
const lastState = steps[steps.length - 1].state;
|
|
1579
|
-
const
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1682
|
+
const isStuttering = cycleStart === cycleEnd;
|
|
1683
|
+
const loop = isStuttering
|
|
1684
|
+
? { result: undefined, lines: [] }
|
|
1685
|
+
: captureOutput(() => traces.findStepAction(cycleEnd, lastState, states[cycleStart], false));
|
|
1686
|
+
const back =
|
|
1687
|
+
isStuttering || loop.result
|
|
1688
|
+
? undefined
|
|
1689
|
+
: traces.findSuccessorWithFingerprint(lastState, cycleEnd, cycleStart);
|
|
1690
|
+
if (!isStuttering && !loop.result && !back) {
|
|
1691
|
+
options.onProgress?.({
|
|
1692
|
+
kind: "violation",
|
|
1693
|
+
status: "property-violation",
|
|
1694
|
+
violation: {
|
|
1695
|
+
name: properties[0],
|
|
1696
|
+
properties,
|
|
1697
|
+
trace,
|
|
1698
|
+
traceOutput: loop.lines,
|
|
1699
|
+
loopStart: undefined,
|
|
1700
|
+
},
|
|
1701
|
+
});
|
|
1702
|
+
throw toLivenessFailure(new TlaEvaluationError(NEXT_RECOVERY_FAILURE));
|
|
1703
|
+
}
|
|
1586
1704
|
return reportViolation(
|
|
1587
1705
|
"liveness-violation",
|
|
1588
1706
|
{
|
|
@@ -1592,16 +1710,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1592
1710
|
traceOutput: loop.lines,
|
|
1593
1711
|
loopStart,
|
|
1594
1712
|
loopLabel: loop.result && getActionLabel(loop.result, options.version),
|
|
1595
|
-
warning:
|
|
1713
|
+
warning: isStuttering && lasso.isCycleConstrained ? getStutteringWarning() : undefined,
|
|
1596
1714
|
},
|
|
1715
|
+
getStepState,
|
|
1597
1716
|
() =>
|
|
1598
|
-
|
|
1717
|
+
isStuttering
|
|
1599
1718
|
? getStepAction(trace[trace.length - 1])
|
|
1600
1719
|
: loop.result
|
|
1601
1720
|
? toActionValue(loop.result)
|
|
1602
|
-
: createActionRecord(
|
|
1603
|
-
traces.findSuccessorWithFingerprint(lastState, cycleStart)?.action,
|
|
1604
|
-
),
|
|
1721
|
+
: createActionRecord(back?.action),
|
|
1605
1722
|
);
|
|
1606
1723
|
};
|
|
1607
1724
|
const isPeriodic = liveness !== undefined && (options.livenessCheck ?? "default") === "default";
|
|
@@ -1743,13 +1860,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1743
1860
|
runtime.queueSize = states.length - index - 1;
|
|
1744
1861
|
current.isExpanding = true;
|
|
1745
1862
|
const liveSuccessors: LiveSuccessor[] = [];
|
|
1863
|
+
const generated = runtime.generatedStates;
|
|
1746
1864
|
try {
|
|
1747
1865
|
outcome = expandState(index, liveSuccessors);
|
|
1748
1866
|
} catch (error) {
|
|
1749
1867
|
outcome =
|
|
1750
1868
|
error instanceof TlaIncompleteSuccessorError
|
|
1751
1869
|
? reportIncompleteSuccessor(index, error, liveSuccessors)
|
|
1752
|
-
: reportNextStateFailure(error, index, liveSuccessors);
|
|
1870
|
+
: reportNextStateFailure(error, index, liveSuccessors, generated);
|
|
1753
1871
|
}
|
|
1754
1872
|
if (outcome) return outcome;
|
|
1755
1873
|
outDegrees[getOutDegreeBucket()]++;
|
package/src/cli/tlc.ts
CHANGED
|
@@ -280,8 +280,9 @@ const checkSpec = async (
|
|
|
280
280
|
} else {
|
|
281
281
|
printError(error, printer);
|
|
282
282
|
}
|
|
283
|
-
|
|
284
|
-
|
|
283
|
+
const exitCode = getTopLevelExitCode(error);
|
|
284
|
+
if (exitCode !== EXIT_STATUS.abort) printFinished();
|
|
285
|
+
return exitCode;
|
|
285
286
|
};
|
|
286
287
|
const config = (() => {
|
|
287
288
|
try {
|