tla-ts 0.0.10-dev.a17d6d9fa → 0.0.10-dev.a5705bfbf

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.
Files changed (78) hide show
  1. package/dist/deciders.cjs +31 -31
  2. package/dist/deciders.js +2 -2
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.cts +12 -2
  5. package/dist/index.d.ts +12 -2
  6. package/dist/index.js +1 -1
  7. package/dist/parallel-worker.cjs +1 -1
  8. package/dist/parallel-worker.js +1 -1
  9. package/dist/prove.cjs +64 -64
  10. package/dist/prove.js +76 -76
  11. package/dist/run.cjs +42 -42
  12. package/dist/run.js +44 -44
  13. package/dist/transfer.cjs +37 -35
  14. package/dist/transfer.js +43 -41
  15. package/dist/worker.cjs +7 -7
  16. package/dist/worker.js +7 -7
  17. package/package.json +1 -1
  18. package/src/ast.ts +10 -1
  19. package/src/check-failure.ts +12 -10
  20. package/src/check-trace.ts +36 -23
  21. package/src/check.ts +182 -135
  22. package/src/cli/tlc-output.ts +17 -2
  23. package/src/cli/tlc.ts +2 -2
  24. package/src/codegen.ts +15 -19
  25. package/src/coverage.ts +190 -1
  26. package/src/dependencies.ts +19 -6
  27. package/src/dfid.ts +80 -27
  28. package/src/environment.ts +30 -1
  29. package/src/evaluate.ts +254 -59
  30. package/src/exit-codes.ts +25 -13
  31. package/src/instances.ts +11 -1
  32. package/src/levels.ts +48 -7
  33. package/src/liveness-checker.ts +98 -27
  34. package/src/liveness.ts +4 -1
  35. package/src/obligations/source.ts +2 -0
  36. package/src/parser.ts +3 -0
  37. package/src/prover/smt/solver/card2bv.ts +7 -4
  38. package/src/prover/smt/solver/context.ts +20 -4
  39. package/src/prover/smt/solver/dependent-expr-state.ts +18 -12
  40. package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
  41. package/src/prover/smt/solver/fd-solver.ts +146 -39
  42. package/src/prover/smt/solver/maxcore.ts +2 -1
  43. package/src/prover/smt/solver/maxsmt-base.ts +1 -0
  44. package/src/prover/smt/solver/model-checker.ts +1 -1
  45. package/src/prover/smt/solver/muz/dl-context.ts +12 -40
  46. package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
  47. package/src/prover/smt/solver/muz/dl-rule.ts +6 -7
  48. package/src/prover/smt/solver/muz/hnf.ts +2 -2
  49. package/src/prover/smt/solver/muz/horn-tactic.ts +14 -1
  50. package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
  51. package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
  52. package/src/prover/smt/solver/opt-context.ts +1 -0
  53. package/src/prover/smt/solver/opt-solver.ts +1 -1
  54. package/src/prover/smt/solver/parallel-tactic.ts +1 -1
  55. package/src/prover/smt/solver/qsat.ts +7 -2
  56. package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
  57. package/src/prover/smt/solver/sat/inc-sat-solver.ts +45 -26
  58. package/src/prover/smt/solver/sat/sat-tactic.ts +4 -2
  59. package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
  60. package/src/prover/smt/solver/smt-consequences.ts +1 -1
  61. package/src/prover/smt/solver/smt-kernel.ts +9 -2
  62. package/src/prover/smt/solver/smtlib-parser.ts +6 -2
  63. package/src/prover/smt/solver/smtlib-script.ts +197 -73
  64. package/src/prover/smt/solver/tactic.ts +64 -37
  65. package/src/resolve.ts +143 -39
  66. package/src/sany/generator-expressions.ts +2 -0
  67. package/src/sany/generator-proofs.ts +1 -0
  68. package/src/search.ts +156 -37
  69. package/src/simulate.ts +143 -150
  70. package/src/spec-description.ts +3 -0
  71. package/src/standard-modules.ts +41 -16
  72. package/src/subexpressions.ts +168 -63
  73. package/src/successors.ts +33 -11
  74. package/src/symmetry.ts +1 -0
  75. package/src/tlc/replay.ts +64 -41
  76. package/src/trace-liveness.ts +529 -0
  77. package/src/typed-tier.ts +20 -6
  78. package/src/values.ts +15 -1
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
- getCoverageLabel,
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 {
@@ -58,6 +56,7 @@ import {
58
56
  type LiveSuccessor,
59
57
  } from "./liveness-checker";
60
58
  import {
59
+ addActionCoverage,
61
60
  createCheckEnvironment,
62
61
  createMissingOperatorError,
63
62
  createSearch,
@@ -65,7 +64,10 @@ import {
65
64
  findAssumptionViolation,
66
65
  reportInitialStatesProgress,
67
66
  reportStartup,
67
+ STOP_WALK,
68
+ walkCoveredSuccessors,
68
69
  withNextStateExitCode,
70
+ type CoveredAction,
69
71
  } from "./search";
70
72
  import {
71
73
  getActionLabel,
@@ -83,6 +85,7 @@ import {
83
85
  type StateWriter,
84
86
  } from "./state-graph";
85
87
  import {
88
+ createIncompleteSuccessorError,
86
89
  forEachInitialState,
87
90
  forEachSuccessor,
88
91
  getInitialStates,
@@ -102,12 +105,7 @@ import {
102
105
  import { createTautologyError } from "./liveness";
103
106
  import { KEY_SEPARATOR } from "./resolve";
104
107
  import { writeTraceSpec } from "./tlc/trace-spec";
105
- import {
106
- getPrimedRanges,
107
- replayInitialStates,
108
- replaySuccessors,
109
- walkSuccessors,
110
- } from "./tlc/replay";
108
+ import { replayInitialStates, replaySuccessors, walkSuccessors } from "./tlc/replay";
111
109
  import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc/summary";
112
110
  import {
113
111
  createActionRecord,
@@ -272,6 +270,11 @@ export interface Postcondition {
272
270
  counts?: string;
273
271
  }
274
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
+
275
278
  /** An evaluation that failed during the search, with the behavior up to the state TLC was working on. */
276
279
  export interface EvaluationFailure {
277
280
  code: number;
@@ -288,7 +291,7 @@ export interface EvaluationFailure {
288
291
  /** The FingerprintException the replay raises, which TLC reports in place of the call stack. */
289
292
  fingerprint?: FingerprintFailure;
290
293
  /** How TLC reports failing again as it prints the trace, since it can't fingerprint the state. */
291
- traceFailure?: FailureMessage;
294
+ traceFailure?: TraceFailure;
292
295
  /** A POSTCONDITION that is false or fails after the trace, which TLC checks as it prints one. */
293
296
  postcondition?: Postcondition;
294
297
  /** Whether TLC stops before it prints the statistics, as it does for an illegal initial state. */
@@ -324,10 +327,6 @@ export interface CheckResult {
324
327
  coverage?: CoverageReport;
325
328
  }
326
329
 
327
- interface CoveredAction extends SpecAction {
328
- node: number;
329
- }
330
-
331
330
  interface ReportedViolation extends Omit<Violation, "loopStart"> {
332
331
  loopStart?: number;
333
332
  }
@@ -346,16 +345,17 @@ const toUnexpectedError = (error: TlaEvaluationError) =>
346
345
  `${isEvalException(error) ? UNEXPECTED_EVAL_EXCEPTION : UNEXPECTED_EXCEPTION}${error.message}`,
347
346
  );
348
347
 
349
- const getTraceFailure = (error: TlaEvaluationError) =>
350
- getFailureMessage(
348
+ const getTraceFailure = (error: TlaEvaluationError, output: OutputLine[]): TraceFailure => ({
349
+ ...getFailureMessage(
351
350
  isEvalException(error)
352
351
  ? new TlaEvaluationError(`${UNEXPECTED_EVAL_EXCEPTION}${error.message}`)
353
352
  : error,
354
353
  true,
355
- );
354
+ ),
355
+ output,
356
+ });
356
357
 
357
358
  const STOP_REPLAY = new Error("The replay stopped");
358
- const STOP_WALK = new Error("The walk stopped");
359
359
 
360
360
  export const checkSequentially = (options: CheckOptions): CheckResult => {
361
361
  const stateWriter =
@@ -402,14 +402,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
402
402
  options.coverage === undefined
403
403
  ? undefined
404
404
  : createCoverage(specification.environment.variables.length);
405
- const environment: Environment = coverage
406
- ? {
407
- ...specification.environment,
408
- evaluators: new WeakMap(),
409
- entryEvaluators: new WeakMap(),
410
- definitionEvaluators: new WeakMap(),
411
- coverage,
412
- }
405
+ const environment = coverage
406
+ ? createCoverageEnvironment(specification.environment, coverage)
413
407
  : specification.environment;
414
408
  const runtime = environment.runtime;
415
409
  const is174 = runtime.version === "1.7.4";
@@ -592,59 +586,36 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
592
586
  const getFingerprintState = search.getFingerprintState;
593
587
  // Tool's constructor splits the next-state relation into actions before TLC checks anything.
594
588
  const nextActions = getDescription().actions;
595
- const addCoverageRelations = (kind: "init" | "next", actions: SpecAction[]) =>
596
- actions.map((action): CoveredAction => ({
597
- ...action,
598
- node: coverage
599
- ? addCoverageRelation(
600
- coverage,
601
- kind,
602
- getCoverageLabel(action.name, action.expression, environment),
603
- action.expression,
604
- action.scope,
605
- )
606
- : -1,
607
- }));
608
- const coverageInits = addCoverageRelations("init", coverage ? getDescription().inits : []);
609
- const coverageActions = addCoverageRelations("next", coverage ? nextActions : []);
610
- if (coverage) buildCoverage(coverage, environment, getPrimedRanges(coverageActions, environment));
611
- const walkCoveredSuccessors = (
612
- action: CoveredAction,
613
- state: Value[],
614
- onState: (successor: Value[]) => void,
615
- ) =>
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;
616
595
  walkSuccessors(
617
596
  action,
618
597
  action.node,
619
598
  state,
620
599
  environment,
621
- (successor) => {
622
- if (coverage) coverage.primary[action.node]++;
623
- onState(successor);
624
- },
625
- (partial) => {
626
- const missing = environment.variables.filter(
627
- (_variable, index) => partial[index] === undefined,
628
- );
629
- throw new TlaIncompleteSuccessorError(
630
- `Successor state is not completely specified by action ${action.name}. The following variables are not assigned: ${missing.join(", ")}`,
631
- partial,
632
- action.name,
633
- missing,
634
- );
600
+ () => complete++,
601
+ () => {
602
+ incomplete++;
603
+ return true;
635
604
  },
636
605
  );
637
- const getCoveredSuccessors = (action: CoveredAction, state: Value[]) => {
638
- const successors: Successor[] = [];
639
- walkCoveredSuccessors(action, state, (successor) =>
640
- successors.push({ state: successor, action: action.name }),
641
- );
642
- return successors;
606
+ if (coverage) coverage.primary[action.node] += complete + incomplete;
607
+ return incomplete > 0;
643
608
  };
644
609
  // TLC generates the successors of each action again, which its coverage counts.
645
610
  const findSuccessorAction = (state: Value[], isMatch: (successor: Successor) => boolean) =>
646
611
  coverage
647
- ? coverageActions.find((item) => getCoveredSuccessors(item, state).some(isMatch))
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
+ })
648
619
  : nextActions.find((item) =>
649
620
  getSuccessors(item.expression, state, environment, item.scope).some(isMatch),
650
621
  );
@@ -686,7 +657,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
686
657
  const deferred: unknown[] = [];
687
658
  const addReplayed = createReplayedStates();
688
659
  return getReplayFailure(environment, (tracing) => {
689
- replayInitialStates(getDescription().inits, tracing, (state) => {
660
+ replayInitialStates(coverage ? coverageInits : getDescription().inits, tracing, (state) => {
690
661
  reportInitialStatesProgress(replayedCount, (progress) => capturedLines?.push(progress));
691
662
  replayedCount++;
692
663
  runtime.generatedStates = replayedCount;
@@ -723,7 +694,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
723
694
  const state = states[index];
724
695
  const source = stateWriter && getGraphState(state, depths[index]);
725
696
  const addReplayed = createReplayedStates();
726
- replaySuccessors(nextActions, state, tracing, (next, action) => {
697
+ replaySuccessors(coverage ? coverageActions : nextActions, state, tracing, (next, action) => {
727
698
  const addFingerprint = () => {
728
699
  const isUnseen = addReplayed(next, tracing.callStack);
729
700
  if (source) {
@@ -749,6 +720,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
749
720
  isConstrained: search.isConstrained,
750
721
  });
751
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
+ };
752
732
  const liveness = withLivenessExitCode(() =>
753
733
  withUnexpectedException(() =>
754
734
  createLivenessChecker(search.properties.liveness, spec.temporals, environment, {
@@ -756,7 +736,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
756
736
  (tlcFingerprints[successor.index] ??= Number(
757
737
  BigInt.asIntN(32, runtime.getFingerprint(successor.state)),
758
738
  )),
759
- forEachActionSuccessors: (source, state, onSuccessors) => {
739
+ forEachActionSuccessors: (source, state, onSuccessors, replay) => {
740
+ liveState = state;
760
741
  let successors: LiveSuccessor[] = [];
761
742
  const addSuccessor = (successor: Value[]) => {
762
743
  canonicalizeState(successor);
@@ -782,9 +763,22 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
782
763
  const livenessSource = current.livenessSource;
783
764
  current.livenessSource = source;
784
765
  try {
785
- // TLC's coverage counts the successors of each action the graph generates again.
786
766
  if (coverage) {
787
- walkCoveredSuccessors(coverageActions[position], state, addSuccessor);
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
+ });
788
782
  } else {
789
783
  const action = nextActions[position];
790
784
  forEachSuccessor(
@@ -793,6 +787,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
793
787
  environment,
794
788
  visitSuccessor,
795
789
  action.scope,
790
+ undefined,
791
+ undefined,
792
+ addIncomplete,
796
793
  );
797
794
  }
798
795
  } finally {
@@ -834,10 +831,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
834
831
  const canonicalizeState = createCanonicalizer();
835
832
 
836
833
  const toRecord = search.toRecord;
837
- const getSpecInitialStates = () => {
838
- if (coverage) return getCoveredInitialStates();
839
- return spec.init === undefined ? [] : getInitialStates(spec.init, environment, spec.scope);
840
- };
834
+ const getUncoveredInitialStates = () =>
835
+ spec.init === undefined ? [] : getInitialStates(spec.init, environment, spec.scope);
836
+ const getSpecInitialStates = () =>
837
+ coverage ? getCoveredInitialStates() : getUncoveredInitialStates();
841
838
  const isUnfingerprintable = (state: Value[]) => {
842
839
  try {
843
840
  return getFingerprintState(state).some((value) => getFingerprintError(value) !== undefined);
@@ -846,19 +843,27 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
846
843
  return true;
847
844
  }
848
845
  };
846
+ const checkFailedTrace = (behavior: Behavior, counterExample?: CounterExampleOptions) => {
847
+ if (!counterExample) return { behavior, postcondition: undefined };
848
+ const checked = checkTracePostconditions(
849
+ behavior.trace,
850
+ undefined,
851
+ getStepAlias,
852
+ counterExample.isConsole,
853
+ );
854
+ return {
855
+ behavior: appendTraceOutput(behavior, checked.lines),
856
+ postcondition: checked.unwitnessed ?? checked.postcondition,
857
+ };
858
+ };
849
859
  const createFailureResult = (
850
860
  failed: unknown,
851
861
  behavior: Behavior,
852
862
  failureOptions: FailureOptions = {},
853
- counterExample?: CounterExampleOptions,
863
+ postcondition?: Postcondition,
854
864
  ) => {
855
865
  const error = isStackOverflow(failed) ? new TlaStackOverflowError() : failed;
856
866
  if (!(error instanceof TlaEvaluationError)) throw error;
857
- const checked =
858
- counterExample &&
859
- checkTracePostconditions(behavior.trace, undefined, getStepAlias, counterExample.isConsole);
860
- const postcondition = checked?.unwitnessed ?? checked?.postcondition;
861
- const traceOutput = [...(behavior.traceOutput ?? []), ...(checked?.lines ?? [])];
862
867
  return {
863
868
  ...createResult("error", undefined, {
864
869
  ...getFailureMessage(
@@ -866,7 +871,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
866
871
  failureOptions.phase !== undefined && failureOptions.phase !== "initial",
867
872
  ),
868
873
  ...behavior,
869
- ...(traceOutput.length > 0 && { traceOutput }),
870
874
  ...(postcondition && { postcondition }),
871
875
  initialState:
872
876
  failureOptions.initialState && !(error instanceof TlaModuleError)
@@ -891,18 +895,20 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
891
895
  const found = captureOutput(() => {
892
896
  try {
893
897
  return {
894
- action: nextActions.find((item) =>
895
- hasIncompleteSuccessor(item.expression, states[index], environment, item.scope),
896
- ),
897
- traceFailure: undefined,
898
+ action: coverage
899
+ ? coverageActions.find((item) => hasCoveredIncompleteSuccessor(item, states[index]))
900
+ : nextActions.find((item) =>
901
+ hasIncompleteSuccessor(item.expression, states[index], environment, item.scope),
902
+ ),
903
+ failed: undefined,
898
904
  };
899
905
  } catch (failed) {
900
906
  if (!(failed instanceof TlaEvaluationError)) throw failed;
901
- return { action: undefined, traceFailure: getTraceFailure(failed) };
907
+ return { action: undefined, failed };
902
908
  }
903
909
  });
904
910
  const action = found.result.action;
905
- const traceFailure = found.result.traceFailure;
911
+ const traceFailure = found.result.failed && getTraceFailure(found.result.failed, found.lines);
906
912
  const message = getIncompleteSuccessorMessage(
907
913
  error.variables,
908
914
  error.action,
@@ -910,9 +916,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
910
916
  options.version,
911
917
  );
912
918
  const live = captureOutput(() => addFailedLiveState(index, liveSuccessors));
913
- const trace = traces.getStateTrace(index, error.state).trace;
914
- const failure = createFailureResult(
915
- error,
919
+ const trace = traces.getStateTrace(index, {
920
+ incomplete: error.state,
921
+ isPrintedOnly: true,
922
+ }).trace;
923
+ const checked = checkFailedTrace(
916
924
  appendTraceOutput(
917
925
  {
918
926
  trace: traceFailure
@@ -933,9 +941,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
933
941
  },
934
942
  live.lines,
935
943
  ),
936
- { callStack: live.result, traceFailure },
937
944
  { isConsole: true },
938
945
  );
946
+ const failure = createFailureResult(
947
+ error,
948
+ checked.behavior,
949
+ { callStack: live.result, traceFailure },
950
+ checked.postcondition,
951
+ );
939
952
  return withOutDegrees({
940
953
  ...failure,
941
954
  failure: failure.failure && {
@@ -996,6 +1009,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
996
1009
  tracedSteps,
997
1010
  captureOutput,
998
1011
  getInitialStates: getSpecInitialStates,
1012
+ getUncoveredInitialStates,
999
1013
  findSuccessorAction,
1000
1014
  });
1001
1015
  const getPath = (index: number): Value[][] =>
@@ -1059,14 +1073,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1059
1073
  });
1060
1074
 
1061
1075
  const visitInitialState = (state: Value[]) => {
1062
- canonicalizeState(state);
1063
1076
  runtime.generatedStates++;
1064
1077
  runtime.initialStates++;
1065
1078
  current.candidate = state;
1066
1079
  current.candidateLevel = 1;
1067
- const fingerprintState = getFingerprintState(state);
1068
- const hash = getStateHash(fingerprintState);
1069
1080
  const isInModel = search.satisfiesConstraints(state);
1081
+ // TLC fingerprints only a state in the model, which sorts its records in place.
1082
+ if (isInModel) canonicalizeState(state);
1083
+ const fingerprintState = isInModel ? getFingerprintState(state) : state;
1084
+ const hash = isInModel ? getStateHash(fingerprintState) : 0;
1070
1085
  if (isInModel) {
1071
1086
  search.trackStatePossible(state);
1072
1087
  fingerprintModelState(fingerprintState);
@@ -1113,18 +1128,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1113
1128
  // Looks a successor up, where the constraints keep it in the model, as the search does before it
1114
1129
  // checks the successor.
1115
1130
  const lookUpSuccessor = (state: Value[], successor: Successor) => {
1116
- const fingerprintState = getFingerprintState(successor.state);
1117
- const hash = getStateHash(fingerprintState);
1118
- const foundIndex = findStateIndex(seenStates, hash, fingerprintState);
1119
1131
  const isStateInModel = search.satisfiesConstraints(successor.state, state);
1120
1132
  if (isStateInModel) search.trackStatePossible(successor.state);
1121
1133
  const isInModel = isStateInModel && search.satisfiesActionConstraints(state, successor.state);
1134
+ const fingerprintState = isInModel ? getFingerprintState(successor.state) : successor.state;
1135
+ const hash = isInModel ? getStateHash(fingerprintState) : 0;
1122
1136
  if (isInModel) {
1123
1137
  search.trackActionPossible(state, successor.state);
1124
1138
  fingerprintModelState(fingerprintState);
1125
1139
  successor.state.forEach(markFingerprinted);
1126
1140
  }
1127
- const existing = isInModel ? foundIndex : -1;
1141
+ const existing = isInModel ? findStateIndex(seenStates, hash, fingerprintState) : -1;
1128
1142
  return {
1129
1143
  fingerprintState,
1130
1144
  hash,
@@ -1189,17 +1203,23 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1189
1203
  if (!found.isSeen) {
1190
1204
  try {
1191
1205
  const violated = search.findViolatedInvariant(successor.state, state);
1192
- const violation = violated && { name: violated.name, ...traces.getTrace(index, successor) };
1206
+ const violation = violated && {
1207
+ name: violated.name,
1208
+ ...traces.getTrace(index, successor, { isPrintedOnly: options.isContinued }),
1209
+ };
1193
1210
  if (violation && !options.isContinued) {
1194
1211
  return withOutDegrees(reportViolation("invariant-violation", violation));
1195
1212
  }
1196
1213
  if (violation) reportContinuedViolation("invariant-violation", violation);
1197
1214
  } catch (error) {
1198
1215
  if (isStackOverflow(error)) throw error;
1199
- const replay = captureOutput(() => replayNext(index));
1216
+ const behavior = traces.getTrace(index, successor, { isPrintedOnly: true });
1217
+ const replay = is174
1218
+ ? captureOutput(() => replayNext(index))
1219
+ : replayFailedNext(index, liveSuccessors);
1200
1220
  return createFailureResult(
1201
1221
  error,
1202
- appendTraceOutput(traces.getFailedTrace(index, successor), replay.lines),
1222
+ appendTraceOutput(behavior, replay.lines),
1203
1223
  replay.result ?? { outDegrees: getFailureOutDegrees() },
1204
1224
  );
1205
1225
  }
@@ -1207,7 +1227,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1207
1227
  const violatedProperty = search.findViolatedActionProperty(state, successor.state);
1208
1228
  const propertyViolation = violatedProperty && {
1209
1229
  name: violatedProperty.name,
1210
- ...traces.getTrace(index, successor),
1230
+ ...traces.getTrace(index, successor, { isPrintedOnly: options.isContinued }),
1211
1231
  };
1212
1232
  if (propertyViolation && !options.isContinued) {
1213
1233
  return withOutDegrees(reportViolation("liveness-violation", propertyViolation));
@@ -1399,7 +1419,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1399
1419
  try {
1400
1420
  coverageActions.forEach((action) => {
1401
1421
  coveredNode = action.node;
1402
- walkCoveredSuccessors(action, state, (successor) => {
1422
+ walkCoveredSuccessors(coverage, action, state, environment, (successor) => {
1403
1423
  successorCount++;
1404
1424
  if (onSuccessor({ state: successor, action: action.name }, action)) throw STOP_WALK;
1405
1425
  });
@@ -1454,6 +1474,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1454
1474
  return undefined;
1455
1475
  } catch (error) {
1456
1476
  if (!(error instanceof TlaEvaluationError)) throw error;
1477
+ // TLC fails to fingerprint an incomplete successor with an exception Worker#doNextCheckLiveness doesn't rerun for a call stack.
1478
+ if (error instanceof TlaIncompleteSuccessorError) return undefined;
1457
1479
  return getLiveCallStack(index, liveSuccessors);
1458
1480
  }
1459
1481
  };
@@ -1464,20 +1486,26 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1464
1486
  return { result, lines: live.lines };
1465
1487
  }
1466
1488
  const replay = captureOutput(() => replayNext(index));
1467
- return { result: replay.result, lines: [...live.lines, ...replay.lines] };
1468
- };
1469
- const getNextFailureTrace = (index: number, counterExample?: CounterExampleOptions) => {
1470
- const behavior = traces.getStateTrace(index);
1471
- return counterExample ? behavior : { trace: behavior.trace };
1489
+ const result: FailureOptions =
1490
+ replay.result ?? (is174 ? {} : { outDegrees: getFailureOutDegrees() });
1491
+ return { result, lines: [...live.lines, ...replay.lines] };
1472
1492
  };
1473
- const reportNextStateOverflow = (index: number, counterExample?: CounterExampleOptions) =>
1474
- createFailureResult(
1493
+ const getNextFailureTrace = (index: number, counterExample?: CounterExampleOptions) =>
1494
+ checkFailedTrace(
1495
+ traces.getStateTrace(index, { isPrintedOnly: !counterExample }),
1496
+ counterExample,
1497
+ );
1498
+ const reportNextStateOverflow = (index: number, counterExample?: CounterExampleOptions) => {
1499
+ const checked = getNextFailureTrace(index, counterExample);
1500
+ return createFailureResult(
1475
1501
  createStackOverflowError(),
1476
- getNextFailureTrace(index, counterExample),
1502
+ checked.behavior,
1477
1503
  { phase: "next" },
1478
- counterExample,
1504
+ checked.postcondition,
1479
1505
  );
1506
+ };
1480
1507
  // Deviation from TLC: under -continue, TLC's Worker reports a state whose next-state relation failed as deadlocked, or else reports the failure twice as its replay fails again.
1508
+ // Deviation from TLC: under -continue, ModelChecker#doNextEvalFailed rethrows a failed invariant to Worker#doNextFailed, which reports it again with the code of its error.
1481
1509
  const reportNextStateFailure = (
1482
1510
  error: unknown,
1483
1511
  index: number,
@@ -1490,12 +1518,13 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1490
1518
  ? { isConsole: false }
1491
1519
  : undefined;
1492
1520
  if (isStackOverflow(error)) return reportNextStateOverflow(index, counterExample);
1521
+ const checked = getNextFailureTrace(index, counterExample);
1493
1522
  const replay = replayFailedNext(index, liveSuccessors);
1494
1523
  return createFailureResult(
1495
1524
  withNextStateExitCode(error),
1496
- appendTraceOutput(getNextFailureTrace(index, counterExample), replay.lines),
1525
+ appendTraceOutput(checked.behavior, replay.lines),
1497
1526
  { phase: "next", ...replay.result },
1498
- counterExample,
1527
+ checked.postcondition,
1499
1528
  );
1500
1529
  };
1501
1530
  const addLiveState = (
@@ -1563,10 +1592,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1563
1592
  outcome = reportNextStateOverflow(index);
1564
1593
  return true;
1565
1594
  }
1566
- const replay = is174
1567
- ? captureOutput(() => replayNext(index))
1568
- : replayFailedNext(index, liveSuccessors);
1569
1595
  if (is174 && error instanceof TlaEvaluationError && !isHeadedError(error)) {
1596
+ const replay = captureOutput(() => replayNext(index));
1570
1597
  outcome = createFailureResult(
1571
1598
  new TlaEvaluationError(`${getWrappedException(error)}${error.message}`, error),
1572
1599
  appendTraceOutput({ trace: [] }, replay.lines),
@@ -1574,17 +1601,33 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1574
1601
  );
1575
1602
  return true;
1576
1603
  }
1577
- const isTraceFailed = isUnfingerprintable(successor.state);
1604
+ const traceError =
1605
+ error instanceof TlaEvaluationError && isUnfingerprintable(successor.state)
1606
+ ? error
1607
+ : undefined;
1608
+ const behavior = traceError
1609
+ ? traces.getStateTrace(index, { isPrintedOnly: true })
1610
+ : traces.getTrace(index, successor, { isPrintedOnly: true });
1578
1611
  const traceFailure =
1579
- isTraceFailed && error instanceof TlaEvaluationError ? getTraceFailure(error) : undefined;
1580
- outcome = createFailureResult(
1581
- error,
1582
- appendTraceOutput(
1583
- traceFailure ? traces.getStateTrace(index) : traces.getFailedTrace(index, successor),
1584
- replay.lines,
1585
- ),
1586
- { phase: "next", ...replay.result, traceFailure },
1587
- );
1612
+ traceError &&
1613
+ getTraceFailure(
1614
+ traceError,
1615
+ captureOutput(() => {
1616
+ try {
1617
+ traces.findStepAction(index, state, successor.state, true);
1618
+ } catch (failed) {
1619
+ if (!(failed instanceof TlaEvaluationError)) throw failed;
1620
+ }
1621
+ }).lines,
1622
+ );
1623
+ const replay = is174
1624
+ ? captureOutput(() => replayNext(index))
1625
+ : replayFailedNext(index, liveSuccessors);
1626
+ outcome = createFailureResult(error, appendTraceOutput(behavior, replay.lines), {
1627
+ phase: "next",
1628
+ ...replay.result,
1629
+ traceFailure,
1630
+ });
1588
1631
  }
1589
1632
  return outcome !== undefined;
1590
1633
  });
@@ -1608,9 +1651,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1608
1651
  ...traces.getStateTrace(index),
1609
1652
  });
1610
1653
  const live = addReportedLiveState(index, liveSuccessors, source);
1611
- const reported = deadlock.violation
1612
- ? { ...deadlock, violation: appendTraceOutput(deadlock.violation, live.lines) }
1613
- : deadlock;
1654
+ const reported = {
1655
+ ...deadlock,
1656
+ violation: deadlock.violation && appendTraceOutput(deadlock.violation, live.lines),
1657
+ coverage: getCoverage(),
1658
+ };
1614
1659
  const counted = withOutDegrees(
1615
1660
  reported,
1616
1661
  live.result.isFailed ? getFailureOutDegrees() : getPartialOutDegrees(),
@@ -1632,7 +1677,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
1632
1677
  const replay = getReplayFailure(environment, (tracing) =>
1633
1678
  liveness?.addState(index, state, liveSuccessors, tracing),
1634
1679
  );
1635
- return createFailureResult(error, traces.getStateTrace(index), {
1680
+ const behavior = traces.getStateTrace(index, { isPrintedOnly: true });
1681
+ const replayed = captureOutput(() => replayNext(index));
1682
+ return createFailureResult(error, appendTraceOutput(behavior, replayed.lines), {
1636
1683
  outDegrees: getFailureOutDegrees(),
1637
1684
  callStack: replay?.callStack.length ? replay.callStack : undefined,
1638
1685
  phase: "liveness",