tla-ts 0.0.3-dev.6979965 → 0.0.3-dev.6ac5593

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 (56) hide show
  1. package/README.md +16 -2
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.d.cts +72 -22
  4. package/dist/index.d.ts +72 -22
  5. package/dist/index.js +1 -1
  6. package/dist/parallel-worker.cjs +2 -2
  7. package/dist/parallel-worker.js +2 -2
  8. package/dist/parallel.cjs +1 -1
  9. package/dist/parallel.js +2 -2
  10. package/dist/run-cli.cjs +20 -17
  11. package/dist/run-cli.js +22 -19
  12. package/dist/transfer.cjs +46 -16
  13. package/dist/transfer.js +46 -16
  14. package/package.json +1 -1
  15. package/src/ast.ts +121 -4
  16. package/src/builtins.ts +9 -3
  17. package/src/check.ts +521 -105
  18. package/src/cli-options.ts +11 -5
  19. package/src/codegen.ts +15 -22
  20. package/src/config.ts +224 -170
  21. package/src/dependencies.ts +2 -2
  22. package/src/environment.ts +410 -130
  23. package/src/errors.ts +109 -3
  24. package/src/evaluate.ts +443 -194
  25. package/src/exit-codes.ts +39 -42
  26. package/src/fingerprints.ts +2 -1
  27. package/src/instances.ts +17 -16
  28. package/src/levels.ts +185 -44
  29. package/src/lexer.ts +5 -1
  30. package/src/live-check.ts +772 -0
  31. package/src/liveness.ts +120 -543
  32. package/src/parallel-worker.ts +102 -115
  33. package/src/parallel.ts +34 -23
  34. package/src/parser.ts +184 -54
  35. package/src/resolve.ts +1378 -420
  36. package/src/run-cli.ts +115 -20
  37. package/src/runtime.ts +3 -1
  38. package/src/sany-lexer.ts +615 -0
  39. package/src/sany-parse-error.ts +3143 -0
  40. package/src/spec-description.ts +19 -8
  41. package/src/standard-modules.ts +54 -45
  42. package/src/standard-ranges.ts +116 -0
  43. package/src/state-graph.ts +157 -0
  44. package/src/subexpressions.ts +231 -171
  45. package/src/substitution-levels.ts +38 -17
  46. package/src/successors.ts +184 -40
  47. package/src/symmetry.ts +123 -43
  48. package/src/tableau.ts +51 -24
  49. package/src/tlc-ext.ts +29 -12
  50. package/src/tlc-module.ts +14 -33
  51. package/src/tlc-modules.ts +4 -0
  52. package/src/tlc-order.ts +25 -7
  53. package/src/tlc-random.ts +9 -6
  54. package/src/tlc-summary.ts +20 -5
  55. package/src/value-sources.ts +29 -0
  56. package/src/values.ts +249 -65
package/src/check.ts CHANGED
@@ -1,32 +1,46 @@
1
- import type { Assumption, Definition, Expression, SourceLocation } from "./ast";
1
+ import {
2
+ getChildren,
3
+ isLocallyResolved,
4
+ type Assumption,
5
+ type Definition,
6
+ type Expression,
7
+ type SourceLocation,
8
+ } from "./ast";
2
9
  import { parseConfig, type ConfigValue, type ModelConfig } from "./config";
3
10
  import { getReadVariables } from "./dependencies";
4
11
  import { createEnvironment } from "./environment";
5
- import { getErrorExitCode, TlaConfigError, TlaEvaluationError, TlaModuleError } from "./errors";
6
- import { EXIT_STATUS, setExitCode, setNextStatePhase, withLivenessExitCode } from "./exit-codes";
12
+ import {
13
+ getErrorExitCode,
14
+ isStackOverflow,
15
+ formatRange,
16
+ STACK_OVERFLOW,
17
+ TlaConfigError,
18
+ TlaEvaluationError,
19
+ TlaIllegalStateError,
20
+ TlaIncompleteStateError,
21
+ TlaModuleError,
22
+ UNEXPECTED_EXCEPTION,
23
+ } from "./errors";
24
+ import { EXIT_STATUS, setExitCode, withLivenessExitCode } from "./exit-codes";
7
25
  import {
8
26
  describeRange,
9
27
  evaluate,
10
28
  expectBoolean,
11
- formatRange,
12
- getChildren,
13
29
  getDefinition,
14
30
  isConstantLevel,
15
31
  isImpure,
16
- isLocallyResolved,
17
32
  type Context,
18
33
  type Environment,
19
34
  type Scope,
20
35
  } from "./evaluate";
21
36
  import {
22
37
  createLivenessChecker,
23
- expandTemporal,
24
- getLevel,
25
38
  type Lasso,
39
+ type LiveGraph,
40
+ type LivenessChecker,
26
41
  type LiveSuccessor,
27
- type ScopedExpression,
28
- type TemporalProperty,
29
- } from "./liveness";
42
+ } from "./live-check";
43
+ import { expandTemporal, getLevel, type ScopedExpression, type TemporalProperty } from "./liveness";
30
44
  import { ACTION_LEVEL, createLevelAnalyzer, TEMPORAL_LEVEL } from "./levels";
31
45
  import { prettyPrint } from "./pretty-print";
32
46
  import {
@@ -38,19 +52,30 @@ import {
38
52
  } from "./successors";
39
53
  import {
40
54
  getActionLabel,
55
+ getActionSignature,
41
56
  getNextActions,
42
57
  getSpecificationValue,
43
58
  type SpecAction,
44
59
  } from "./spec-description";
60
+ import {
61
+ createStateWriter,
62
+ type GraphState,
63
+ type StateDump,
64
+ type StateWriter,
65
+ } from "./state-graph";
45
66
  import { getRepresentative, getSymmetryGroup } from "./symmetry";
46
- import { getTlcStringOrder, getTlcVariableOrder } from "./tlc-order";
67
+ import { getTlcStringOrder, getTlcDeclarationOrder } from "./tlc-order";
47
68
  import { createTlcFingerprinter, getTlcFingerprint } from "./tlc-random";
48
69
  import { createCanonicalizer } from "./canonical";
49
70
  import { getPossibleCounts, type CheckerRuntime } from "./runtime";
50
71
  import { createCounterExample } from "./tlc-ext";
72
+ import { getFingerprintTrace, valueSources } from "./value-sources";
51
73
  import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc-summary";
52
74
  import {
75
+ assertFingerprintable,
53
76
  combineHash,
77
+ createModelValue,
78
+ formatState,
54
79
  formatValue,
55
80
  getValueHash,
56
81
  isFunctionValue,
@@ -74,6 +99,8 @@ export interface CheckOptions {
74
99
  workers?: number;
75
100
  // TLC's -lncheck: "final" checks liveness only on the complete state graph.
76
101
  livenessCheck?: "default" | "final";
102
+ // TLC's -dump: writes the reachable states, or with `dot` the state graph, through writeFile.
103
+ dump?: StateDump;
77
104
  }
78
105
 
79
106
  export type CheckStatus =
@@ -95,6 +122,8 @@ export interface TraceStep {
95
122
 
96
123
  export interface Violation {
97
124
  name: string;
125
+ // Every temporal property that a liveness counterexample violates, in the configuration's order.
126
+ properties?: string[];
98
127
  trace: TraceStep[];
99
128
  loopStart: number | undefined;
100
129
  loopLabel?: string;
@@ -115,6 +144,25 @@ export interface EvaluationFailure {
115
144
  trace: TraceStep[];
116
145
  initialState: Record<string, Value> | undefined;
117
146
  exitCode: number;
147
+ replay?: Replay;
148
+ isWithoutStatistics?: boolean;
149
+ }
150
+
151
+ // TLC replays a failed step to print the expressions it was evaluating when the replay failed.
152
+ export interface Replay {
153
+ output: string[];
154
+ callStack: string[] | undefined;
155
+ fingerprint?: Fingerprint;
156
+ // The worker that fails to check liveness replays the step at once, so TLC prints the stack
157
+ // before the error, and only when it holds a frame.
158
+ isBeforeError?: boolean;
159
+ }
160
+
161
+ // TLC reports an error from a method of a value that has a source as one it was unable to
162
+ // fingerprint. With an empty stack, it lists the sources of the values instead.
163
+ export interface Fingerprint {
164
+ sources: string[];
165
+ reason: string;
118
166
  }
119
167
 
120
168
  export interface CheckResult {
@@ -226,7 +274,7 @@ const getConstantValue = (name: string, definition: Definition, environment: Env
226
274
  try {
227
275
  return evaluate(createIdentifier(name), getContext(environment, undefined, undefined));
228
276
  } catch (error) {
229
- if (error instanceof TlaEvaluationError) return undefined;
277
+ if (error instanceof TlaEvaluationError || isStackOverflow(error)) return undefined;
230
278
  throw error;
231
279
  }
232
280
  };
@@ -255,8 +303,11 @@ const getInvariants = (names: string[], environment: Environment) => {
255
303
  levels.params.size === 0
256
304
  ? ""
257
305
  : "\nNote that a bug can cause TLC to incorrectly report this error.\nIf you believe your TLA+ or PlusCal specification to be correct,\nplease check if this bug described in LevelNode.java starting at line 590ff affects you.";
258
- throw new TlaConfigError(
259
- `The invariant ${name} is not a state predicate (one with no primes or temporal operators).${note}`,
306
+ throw setExitCode(
307
+ new TlaConfigError(
308
+ `The invariant ${name} is not a state predicate (one with no primes or temporal operators).${note}`,
309
+ ),
310
+ EXIT_STATUS.safetyEvaluationFailure,
260
311
  );
261
312
  }
262
313
  return [{ name, expression: createIdentifier(name), scope: undefined }];
@@ -354,8 +405,11 @@ const getSpecification = (config: ModelConfig, environment: Environment): Specif
354
405
  conjunct.kind === "Always" &&
355
406
  getLevel(conjunct.expression, item.scope, environment) < ACTION_LEVEL
356
407
  ) {
357
- throw new TlaConfigError(
358
- `TLC cannot handle []P in the specification ${config.specification} when P is a state predicate`,
408
+ throw setExitCode(
409
+ new TlaConfigError(
410
+ `TLC cannot handle the temporal formula ${describeRange(conjunct.expression)}`,
411
+ ),
412
+ EXIT_STATUS.error,
359
413
  );
360
414
  }
361
415
  const level = getLevel(conjunct, item.scope, environment);
@@ -425,12 +479,12 @@ const getProperties = (config: ModelConfig, environment: Environment): Propertie
425
479
  config.properties.forEach((name) => {
426
480
  const definition = getConfigPredicate("property", name, environment);
427
481
  if (!definition) return;
428
- expandTemporal(definition.body, undefined, environment, true).forEach((item) => {
482
+ expandTemporal(definition.body, undefined, environment, true, name).forEach((item) => {
429
483
  const conjunct = item.expression;
430
484
  if (isConstantTrue(item, environment, "property")) return;
431
485
  if (conjunct.kind === "Always" && conjunct.expression.kind === "BoxAction") {
432
486
  properties.actionProperties.push({
433
- name,
487
+ name: item.name,
434
488
  box: conjunct.expression,
435
489
  action: conjunct.expression.action,
436
490
  subscript: conjunct.expression.subscript,
@@ -442,12 +496,22 @@ const getProperties = (config: ModelConfig, environment: Environment): Propertie
442
496
  conjunct.kind === "Always" &&
443
497
  getLevel(conjunct.expression, item.scope, environment) <= 1
444
498
  ) {
445
- properties.invariants.push({ name, expression: conjunct.expression, scope: item.scope });
499
+ // TLC names the invariant []P after P when P is an operator name.
500
+ const expression = conjunct.expression;
501
+ properties.invariants.push({
502
+ name: expression.kind === "Identifier" ? expression.name : item.name,
503
+ expression,
504
+ scope: item.scope,
505
+ });
446
506
  return;
447
507
  }
448
508
  const level = getLevel(conjunct, item.scope, environment);
449
509
  if (level < ACTION_LEVEL) {
450
- properties.initialPredicates.push({ name, expression: conjunct, scope: item.scope });
510
+ properties.initialPredicates.push({
511
+ name: item.name,
512
+ expression: conjunct,
513
+ scope: item.scope,
514
+ });
451
515
  return;
452
516
  }
453
517
  if (level === ACTION_LEVEL) {
@@ -507,7 +571,9 @@ const getMembership = (
507
571
  const getStateChecks = (named: NamedExpression[], environment: Environment): StateCheck[] =>
508
572
  named.flatMap((item) =>
509
573
  getConjuncts(item.expression, environment).map((expression) => {
510
- const variables = getReadVariables(expression, environment);
574
+ // A LET or an argument in the scope can read variables the expression doesn't name.
575
+ const variables =
576
+ item.scope === undefined ? getReadVariables(expression, environment) : undefined;
511
577
  return {
512
578
  name: item.name,
513
579
  expression,
@@ -686,7 +752,7 @@ export const createSearch = (
686
752
  const possible = getPossiblePredicates(config.possible, environment);
687
753
  if (environment.variables.length === 0) return undefined;
688
754
  const symmetryGroup =
689
- config.symmetry === undefined ? [] : getSymmetryGroup(config.symmetry, environment);
755
+ config.symmetry === undefined ? undefined : getSymmetryGroup(config.symmetry, environment);
690
756
  if (config.view !== undefined) getConfigOperator("view function", config.view, environment);
691
757
  const view =
692
758
  config.view === undefined
@@ -718,14 +784,12 @@ export const createSearch = (
718
784
  .sort((left, right) => getTlcPosition(left) - getTlcPosition(right));
719
785
  return tlcOrder.indices;
720
786
  };
721
- // A representative in TLC's variable order is the one whose fingerprint TLC reports.
722
- const order = symmetryGroup.length > 0 ? getTlcOrder() : undefined;
723
787
  const getViewValue = (expression: Expression, state: Value[]) =>
724
788
  evaluate(expression, getContext(environment, state, undefined));
725
789
  const getTlcStateFingerprint = (state: Value[]) => {
726
790
  const indices = getTlcOrder();
727
791
  const representative =
728
- symmetryGroup.length === 0 ? state : getRepresentative(state, symmetryGroup, indices);
792
+ symmetryGroup === undefined ? state : getRepresentative(state, symmetryGroup, indices);
729
793
  return getTlcFingerprint(
730
794
  view === undefined
731
795
  ? indices.map((index) => representative[index])
@@ -748,22 +812,27 @@ export const createSearch = (
748
812
  return {
749
813
  properties,
750
814
  spec,
751
- isSymmetric: symmetryGroup.length > 0,
815
+ isSymmetric: symmetryGroup !== undefined,
752
816
  getTlcOrder,
753
817
  getStoredFingerprints: (states, fingerprintStates) => {
754
818
  if (view !== undefined || isFingerprintedLikeTlc) {
755
819
  return BigInt64Array.from(states, getTlcStateFingerprint);
756
820
  }
757
- const indices = getTlcOrder();
758
- const getFingerprint = createTlcFingerprinter();
759
- return BigInt64Array.from(fingerprintStates, (state) =>
760
- getFingerprint(indices.map((index) => state[index])),
821
+ const fingerprints = new BigInt64Array(fingerprintStates.length);
822
+ const fingerprint = createTlcFingerprinter(
823
+ getTlcOrder(),
824
+ new Int32Array(fingerprints.buffer),
761
825
  );
826
+ fingerprintStates.forEach(fingerprint);
827
+ return fingerprints;
762
828
  },
763
829
  getFingerprintState: (state) => {
764
830
  if (isFingerprintedLikeTlc) return [String(getTlcStateFingerprint(state))];
831
+ // A representative in TLC's variable order is the one whose fingerprint TLC reports.
765
832
  const representative =
766
- symmetryGroup.length === 0 ? state : getRepresentative(state, symmetryGroup, order);
833
+ symmetryGroup === undefined
834
+ ? state
835
+ : getRepresentative(state, symmetryGroup, getTlcOrder());
767
836
  return view === undefined ? representative : [getViewValue(view.expression, representative)];
768
837
  },
769
838
  findViolatedInvariant: (state, parent) =>
@@ -790,11 +859,17 @@ export const createSearch = (
790
859
  }
791
860
  }),
792
861
  satisfiesConstraints: (state, parent) =>
793
- constraints.every(
794
- (constraint) =>
795
- isUnchangedFor(constraint, state, parent) ||
796
- holdsLikeTlc(constraint.expression, getContext(environment, state, undefined)),
797
- ),
862
+ constraints.every((constraint) => {
863
+ try {
864
+ return (
865
+ isUnchangedFor(constraint, state, parent) ||
866
+ holdsLikeTlc(constraint.expression, getContext(environment, state, undefined))
867
+ );
868
+ } catch (error) {
869
+ // TLC reports a failing constraint on a successor like a failure of the next-state relation.
870
+ throw parent ? toNextStateError(error) : error;
871
+ }
872
+ }),
798
873
  findFailedInitialPredicate: (state) =>
799
874
  properties.initialPredicates.find(
800
875
  (predicate) =>
@@ -820,18 +895,20 @@ export const createSearch = (
820
895
  )
821
896
  );
822
897
  } catch (error) {
823
- throw withHeadline(error, `Evaluating action property ${property.name} failed.`);
898
+ throw withHeadline(
899
+ withNextStateExitCode(error),
900
+ `Evaluating action property ${property.name} failed.`,
901
+ );
824
902
  }
825
903
  }),
826
904
  satisfiesActionConstraints: (state, next) =>
827
- actionConstraints.every((constraint) =>
828
- holdsLikeTlc(
829
- constraint.expression,
830
- getContext(environment, state, next),
831
- (expression) =>
832
- `TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a java.lang.RuntimeException\n: ${getExpectedBoolean(expression, environment)}`,
833
- ),
834
- ),
905
+ actionConstraints.every((constraint) => {
906
+ try {
907
+ return holdsLikeTlc(constraint.expression, getContext(environment, state, next));
908
+ } catch (error) {
909
+ throw toNextStateError(error);
910
+ }
911
+ }),
835
912
  trackStatePossible:
836
913
  statePossible.length === 0
837
914
  ? ignorePossible
@@ -857,6 +934,64 @@ export const createSearch = (
857
934
  };
858
935
  };
859
936
 
937
+ // TLC exits with the code of a standard module's failure only when the failure escapes the
938
+ // computation of next states. In every other phase, the phase decides the code.
939
+ const withNextStateExitCode = (error: unknown) =>
940
+ error instanceof TlaModuleError ? setExitCode(error, error.exitCode) : error;
941
+
942
+ // TLC reports a failure of the next-state relation, or of the liveness check of a step, as an
943
+ // unexpected exception, unless a standard module raised it as an EvalException.
944
+ const toNextStateError = (error: unknown) =>
945
+ error instanceof TlaEvaluationError &&
946
+ !(error instanceof TlaModuleError) &&
947
+ !(error instanceof TlaIncompleteStateError)
948
+ ? setExitCode(
949
+ new TlaEvaluationError(`${UNEXPECTED_EXCEPTION}${error.message}`, error),
950
+ getErrorExitCode(error),
951
+ )
952
+ : withNextStateExitCode(error);
953
+
954
+ const isRepeated = (frame: string, index: number, frames: string[]) =>
955
+ index > 0 && frames[index - 1] === frame;
956
+
957
+ // FingerprintException#getTrace numbers the sources from the outermost value and lists the innermost
958
+ // first.
959
+ const getSourceTrace = (sources: Expression[]) =>
960
+ sources
961
+ .flatMap((source) => (source.location.range ? [formatRange(source.location.range)] : []))
962
+ .filter((source, index, all) => !isRepeated(source, index, all))
963
+ .map((source, index) => `${index}) ${source}`)
964
+ .reverse();
965
+
966
+ // TLC keeps the stack only when an evaluation fails, and prints each expression on it once, however
967
+ // many times in a row it pushed it.
968
+ const getReplayedCallStack = (
969
+ replay: () => void,
970
+ trace: Expression[],
971
+ ): Pick<Replay, "callStack" | "fingerprint"> => {
972
+ try {
973
+ replay();
974
+ return { callStack: undefined };
975
+ } catch (error) {
976
+ if (!(error instanceof TlaEvaluationError)) return { callStack: [] };
977
+ const callStack = trace
978
+ .flatMap((expression) => {
979
+ const range = expression.location.range;
980
+ return range
981
+ ? [
982
+ `Line ${range.start.line}, column ${range.start.column} to line ${range.end.line}, column ${range.end.column} in ${range.module}`,
983
+ ]
984
+ : [];
985
+ })
986
+ .filter((frame, index, frames) => !isRepeated(frame, index, frames));
987
+ const sources = getFingerprintTrace(error);
988
+ return {
989
+ callStack,
990
+ fingerprint: sources && { sources: getSourceTrace(sources), reason: error.message },
991
+ };
992
+ }
993
+ };
994
+
860
995
  const withHeadline = (error: unknown, headline: string) =>
861
996
  error instanceof TlaEvaluationError
862
997
  ? setExitCode(
@@ -865,15 +1000,30 @@ const withHeadline = (error: unknown, headline: string) =>
865
1000
  )
866
1001
  : error;
867
1002
 
1003
+ // TLC finishes the -dump file whether or not the search finds a violation.
868
1004
  export const checkSequentially = (options: CheckOptions): CheckResult => {
869
- setNextStatePhase(false);
1005
+ const stateWriter = options.dump && createStateWriter(options.dump, options.writeFile);
1006
+ try {
1007
+ return searchStates(options, stateWriter);
1008
+ } catch (error) {
1009
+ // TLC reports a stack overflow outside the search as a failure of its own, with exit code 255.
1010
+ throw isStackOverflow(error)
1011
+ ? setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error)
1012
+ : error;
1013
+ } finally {
1014
+ stateWriter?.close();
1015
+ }
1016
+ };
1017
+
1018
+ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefined): CheckResult => {
870
1019
  const config = typeof options.config === "string" ? parseConfig(options.config) : options.config;
871
1020
  const onPrint = options.onPrint ?? console.log;
872
1021
  // TLC prints again while it rebuilds a trace, between the states it prints. Printing those lines
873
1022
  // before the trace would misplace them, so rebuilding a trace prints nothing.
874
- const output = { isMuted: false };
1023
+ const output = { isMuted: false, replayed: undefined as string[] | undefined };
875
1024
  const print = (text: string) => {
876
- if (!output.isMuted) onPrint(text);
1025
+ if (output.replayed) output.replayed.push(text);
1026
+ else if (!output.isMuted) onPrint(text);
877
1027
  };
878
1028
  const withoutOutput = <Result>(rebuild: () => Result) => {
879
1029
  output.isMuted = true;
@@ -935,9 +1085,9 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
935
1085
  ),
936
1086
  });
937
1087
 
938
- const search = createSearch(config, environment, () =>
939
- getTlcVariableOrder(options.source, options.loadModule),
940
- );
1088
+ const getVariableOrder = () =>
1089
+ getTlcDeclarationOrder(options.source, options.loadModule, "variable");
1090
+ const search = createSearch(config, environment, getVariableOrder);
941
1091
  const assumptionViolation = findAssumptionViolation(specification.assumptions, environment);
942
1092
  if (assumptionViolation) return createResult("assumption-violation", assumptionViolation);
943
1093
  if (!search) return createSuccess();
@@ -961,9 +1111,114 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
961
1111
  const spec = search.spec;
962
1112
  const getFingerprintState = search.getFingerprintState;
963
1113
  const nextActions = { value: undefined as SpecAction[] | undefined };
1114
+ const replayFailure = (
1115
+ result: CheckResult,
1116
+ replay: (tracedSearch: Search, traced: Environment) => void,
1117
+ isBeforeError = false,
1118
+ ): CheckResult => {
1119
+ if (!result.failure) return result;
1120
+ const trace: Expression[] = [];
1121
+ const traced: Environment = { ...environment, evaluators: new WeakMap(), trace };
1122
+ const tracedSearch = createSearch(config, traced, getVariableOrder);
1123
+ if (!tracedSearch) return result;
1124
+ const replayed: string[] = [];
1125
+ output.replayed = replayed;
1126
+ valueSources.current = new WeakMap();
1127
+ const replayedStack = getReplayedCallStack(() => replay(tracedSearch, traced), trace);
1128
+ valueSources.current = undefined;
1129
+ output.replayed = undefined;
1130
+ return {
1131
+ ...result,
1132
+ failure: { ...result.failure, replay: { output: replayed, ...replayedStack, isBeforeError } },
1133
+ };
1134
+ };
1135
+ // TLC fingerprints a state outside CallStackTool, so a failure of a value with a source leaves
1136
+ // the stack empty. Any other failure keeps the stack of the initial predicate.
1137
+ const fingerprintReplayed = (state: Value[], traced: Environment) => {
1138
+ try {
1139
+ getStateHash(getFingerprintState(state));
1140
+ } catch (error) {
1141
+ if (traced.trace && getFingerprintTrace(error)) traced.trace.length = 0;
1142
+ throw error;
1143
+ }
1144
+ };
1145
+ // TLC checks every initial state again, as when it first generated them.
1146
+ const replayInitialStates = (result: CheckResult) =>
1147
+ replayFailure(result, (tracedSearch, traced) => {
1148
+ if (spec.init === undefined) return;
1149
+ forEachInitialState(
1150
+ spec.init,
1151
+ traced,
1152
+ (state) => {
1153
+ if (tracedSearch.satisfiesConstraints(state)) fingerprintReplayed(state, traced);
1154
+ return (
1155
+ tracedSearch.findViolatedInvariant(state) !== undefined ||
1156
+ tracedSearch.findFailedInitialPredicate(state) !== undefined
1157
+ );
1158
+ },
1159
+ spec.scope,
1160
+ );
1161
+ });
1162
+ // TLC rebuilds the behavior up to the state it expanded before it replays the step.
1163
+ const rebuildBehavior = (index: number): void => {
1164
+ const parent = parents[index];
1165
+ if (parent === -1) {
1166
+ getSpecInitialStates();
1167
+ return;
1168
+ }
1169
+ rebuildBehavior(parent);
1170
+ getLabel(parent, states[parent], states[index]);
1171
+ };
1172
+ // TLC generates the successors of each action before it checks them. It checks the invariants
1173
+ // only of a successor outside the model, since it has seen the others.
1174
+ const replaySuccessors = (result: CheckResult, index: number) =>
1175
+ replayFailure(result, (tracedSearch, traced) => {
1176
+ rebuildBehavior(index);
1177
+ const state = states[index];
1178
+ nextActions.value ??= getNextActions(config, environment, specification.instanceActions);
1179
+ nextActions.value.find((action) =>
1180
+ getSuccessors(action.expression, state, traced, action.scope).some((successor) => {
1181
+ const isInModel =
1182
+ tracedSearch.satisfiesConstraints(successor.state) &&
1183
+ tracedSearch.satisfiesActionConstraints(state, successor.state);
1184
+ if (isInModel) fingerprintReplayed(successor.state, traced);
1185
+ return (
1186
+ (!isInModel && tracedSearch.findViolatedInvariant(successor.state) !== undefined) ||
1187
+ tracedSearch.findViolatedActionProperty(state, successor.state) !== undefined
1188
+ );
1189
+ }),
1190
+ );
1191
+ });
964
1192
  const isReducing = config.view !== undefined || config.symmetry !== undefined;
1193
+ const tlcFingerprints: number[] = [];
1194
+ const liveGraph: LiveGraph = {
1195
+ getFingerprint: (index) =>
1196
+ (tlcFingerprints[index] ??= Number(BigInt.asIntN(32, runtime.getFingerprint(states[index])))),
1197
+ getSuccessors: (state) => {
1198
+ const successors: LiveSuccessor[] = [];
1199
+ if (spec.next === undefined) return successors;
1200
+ forEachSuccessor(
1201
+ spec.next,
1202
+ state,
1203
+ environment,
1204
+ (successor) => {
1205
+ canonicalizeState(successor.state);
1206
+ const isInModel =
1207
+ search.satisfiesConstraints(successor.state, state) &&
1208
+ search.satisfiesActionConstraints(state, successor.state);
1209
+ if (!isInModel) return false;
1210
+ const fingerprintState = getFingerprintState(successor.state);
1211
+ const index = findStateIndex(getStateHash(fingerprintState), fingerprintState);
1212
+ successors.push({ index, state: successor.state });
1213
+ return false;
1214
+ },
1215
+ spec.scope,
1216
+ );
1217
+ return successors;
1218
+ },
1219
+ };
965
1220
  const liveness = withLivenessExitCode(() =>
966
- createLivenessChecker(search.properties.liveness, spec.temporals, environment),
1221
+ createLivenessChecker(search.properties.liveness, spec.temporals, environment, liveGraph),
967
1222
  );
968
1223
  const isCanonicalizedFirst = search.isSymmetric || liveness !== undefined;
969
1224
 
@@ -972,7 +1227,9 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
972
1227
  const parents: number[] = [];
973
1228
  const actions: (string | undefined)[] = [];
974
1229
  const depths: number[] = [];
975
- const buckets = new Map<number, number | number[]>();
1230
+ // A Map holds at most 2^24 entries, so an open-addressing table keeps each seen state's hash
1231
+ // and its index plus one side by side, probed by the hash.
1232
+ const seen = { slots: new Int32Array(1 << 17), size: 0, shift: 16 };
976
1233
  const canonicalizeState = createCanonicalizer();
977
1234
 
978
1235
  const toRecord = (state: Value[]): Record<string, Value> =>
@@ -985,11 +1242,16 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
985
1242
  position: number,
986
1243
  loopStart: number | undefined,
987
1244
  ) => {
988
- const state = steps[position].state;
989
- const next = (steps[position + 1] ?? steps[loopStart ?? position]).state;
990
1245
  // TLC evaluates TLCGet("level") and Trace in an alias at the state's position in the trace.
991
1246
  runtime.getLevel = () => position + 1;
992
1247
  runtime.getBehavior = () => steps.slice(0, position + 1).map((step) => step.state);
1248
+ return evaluateAlias(
1249
+ alias,
1250
+ steps[position].state,
1251
+ (steps[position + 1] ?? steps[loopStart ?? position]).state,
1252
+ );
1253
+ };
1254
+ const evaluateAlias = (alias: string, state: Value[], next: Value[] | undefined) => {
993
1255
  try {
994
1256
  const body = getConfigDefinition("alias", alias, environment).body;
995
1257
  const value = evaluate(createIdentifier(alias), getContext(environment, state, next));
@@ -1091,7 +1353,17 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
1091
1353
  trace: TraceStep[],
1092
1354
  initialState?: Value[],
1093
1355
  failureOutDegrees?: number[],
1094
- ) => {
1356
+ ): CheckResult => {
1357
+ // TLC exits with 255 on a stack overflow while it computes next states, and prints the
1358
+ // behavior up to the state it was expanding.
1359
+ if (isStackOverflow(error)) {
1360
+ return current.isExpanding
1361
+ ? toFailure(
1362
+ setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error),
1363
+ getStateTrace(current.index),
1364
+ )
1365
+ : toFailure(new TlaEvaluationError(STACK_OVERFLOW), trace, initialState);
1366
+ }
1095
1367
  if (!(error instanceof TlaEvaluationError)) throw error;
1096
1368
  return {
1097
1369
  ...createResult("error", undefined, {
@@ -1104,7 +1376,7 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
1104
1376
  outDegrees: failureOutDegrees,
1105
1377
  };
1106
1378
  };
1107
- const getPathTrace = (path: number[], loopStart?: number) => {
1379
+ const getPathSteps = (path: number[], loopStart?: number) => {
1108
1380
  const steps = getPathStates(path, NEXT_RECOVERY_FAILURE);
1109
1381
  const last = steps[steps.length - 1].state;
1110
1382
  const isClosed =
@@ -1113,12 +1385,13 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
1113
1385
  loopStart === path.length - 1 ||
1114
1386
  findSuccessorWithFingerprint(last, path[loopStart]) !== undefined;
1115
1387
  if (!isClosed) throw new TlaEvaluationError(NEXT_RECOVERY_FAILURE);
1116
- return toTrace(steps, path, loopStart);
1388
+ return steps;
1117
1389
  };
1118
1390
  const getStateHash = (state: Value[]) => {
1119
1391
  let hash = 0x811c9dc5;
1120
1392
  for (let index = 0; index < state.length; index++)
1121
1393
  hash = combineHash(hash, getValueHash(state[index]));
1394
+ assertFingerprintable(state);
1122
1395
  return hash & 0x3fffffff;
1123
1396
  };
1124
1397
  const isSameState = (stored: Value[], state: Value[]) => {
@@ -1127,19 +1400,35 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
1127
1400
  }
1128
1401
  return true;
1129
1402
  };
1403
+ const getSlot = (hash: number) => (Math.imul(hash, 0x9e3779b1) >>> seen.shift) << 1;
1130
1404
  const findStateIndex = (hash: number, state: Value[]) => {
1131
- const bucket = buckets.get(hash);
1132
- if (bucket === undefined) return -1;
1133
- if (typeof bucket === "number") {
1134
- return isSameState(fingerprintStates[bucket], state) ? bucket : -1;
1405
+ const mask = seen.slots.length - 1;
1406
+ for (let slot = getSlot(hash); ; slot = (slot + 2) & mask) {
1407
+ const entry = seen.slots[slot + 1];
1408
+ if (entry === 0) return -1;
1409
+ if (seen.slots[slot] === hash && isSameState(fingerprintStates[entry - 1], state)) {
1410
+ return entry - 1;
1411
+ }
1135
1412
  }
1136
- return bucket.find((index) => isSameState(fingerprintStates[index], state)) ?? -1;
1413
+ };
1414
+ const insertSeen = (hash: number, entry: number) => {
1415
+ const mask = seen.slots.length - 1;
1416
+ let slot = getSlot(hash);
1417
+ while (seen.slots[slot + 1] !== 0) slot = (slot + 2) & mask;
1418
+ seen.slots[slot] = hash;
1419
+ seen.slots[slot + 1] = entry;
1137
1420
  };
1138
1421
  const markSeen = (hash: number, index: number) => {
1139
- const bucket = buckets.get(hash);
1140
- if (bucket === undefined) buckets.set(hash, index);
1141
- else if (typeof bucket === "number") buckets.set(hash, [bucket, index]);
1142
- else bucket.push(index);
1422
+ seen.size++;
1423
+ if (seen.size * 4 > seen.slots.length) {
1424
+ const slots = seen.slots;
1425
+ seen.slots = new Int32Array(slots.length * 2);
1426
+ seen.shift--;
1427
+ for (let slot = 0; slot < slots.length; slot += 2) {
1428
+ if (slots[slot + 1] !== 0) insertSeen(slots[slot], slots[slot + 1]);
1429
+ }
1430
+ }
1431
+ insertSeen(hash, index + 1);
1143
1432
  };
1144
1433
  const countDistinctState = (depth: number) => {
1145
1434
  runtime.distinctStates = states.length + 1;
@@ -1165,6 +1454,7 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
1165
1454
  isExpanding: false,
1166
1455
  candidate: undefined as Value[] | undefined,
1167
1456
  candidateLevel: 0,
1457
+ isFingerprinting: false,
1168
1458
  livenessSource: -1,
1169
1459
  };
1170
1460
  const getPath = (index: number): Value[][] =>
@@ -1179,7 +1469,7 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
1179
1469
  };
1180
1470
  runtime.getCurrentState = () => (current.index === -1 ? undefined : states[current.index]);
1181
1471
  runtime.setLivenessSource = (index) => {
1182
- current.livenessSource = index;
1472
+ current.livenessSource = index ?? -1;
1183
1473
  };
1184
1474
  runtime.getLevel = (state) => {
1185
1475
  const source = current.livenessSource;
@@ -1190,6 +1480,18 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
1190
1480
  return current.isExpanding ? depths[current.index] + 1 : 0;
1191
1481
  };
1192
1482
 
1483
+ const getGraphState = (state: Value[], level: number): GraphState => ({
1484
+ fingerprint: BigInt.asIntN(64, runtime.getFingerprint(state)),
1485
+ level,
1486
+ getLabel: () =>
1487
+ formatState(
1488
+ config.alias === undefined
1489
+ ? toRecord(state)
1490
+ : evaluateAlias(config.alias, state, undefined),
1491
+ ),
1492
+ getText: () => formatState(toRecord(state)),
1493
+ });
1494
+
1193
1495
  const visitInitialState = (state: Value[]) => {
1194
1496
  canonicalizeState(state);
1195
1497
  runtime.generatedStates++;
@@ -1206,6 +1508,7 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
1206
1508
  countDistinctState(1);
1207
1509
  runtime.queueSize++;
1208
1510
  liveness?.addInitialState(states.length, state);
1511
+ stateWriter?.writeInitialState(getGraphState(state, 1));
1209
1512
  }
1210
1513
  const violated = search.findViolatedInvariant(state);
1211
1514
  if (violated) {
@@ -1226,20 +1529,36 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
1226
1529
  addState(state, fingerprintState, -1, undefined);
1227
1530
  return undefined;
1228
1531
  };
1229
- const visitSuccessor = (index: number, successor: Successor, liveSuccessors: LiveSuccessor[]) => {
1532
+ const visitSuccessor = (
1533
+ index: number,
1534
+ successor: Successor,
1535
+ liveSuccessors: LiveSuccessor[],
1536
+ source: GraphState | undefined,
1537
+ action: SpecAction | undefined,
1538
+ ) => {
1230
1539
  const state = states[index];
1231
1540
  runtime.generatedStates++;
1232
1541
  current.candidate = successor.state;
1233
1542
  current.candidateLevel = depths[index] + 1;
1234
1543
  if (isCanonicalizedFirst) canonicalizeState(successor.state);
1544
+ current.isFingerprinting = true;
1235
1545
  const fingerprintState = getFingerprintState(successor.state);
1236
1546
  const hash = getStateHash(fingerprintState);
1547
+ current.isFingerprinting = false;
1237
1548
  const found = findStateIndex(hash, fingerprintState);
1238
1549
  const isStateInModel = search.satisfiesConstraints(successor.state, state);
1239
1550
  if (isStateInModel) search.trackStatePossible(successor.state);
1240
1551
  const isInModel = isStateInModel && search.satisfiesActionConstraints(state, successor.state);
1241
1552
  if (isInModel) search.trackActionPossible(state, successor.state);
1242
1553
  const existing = isInModel ? found : -1;
1554
+ if (source && isInModel) {
1555
+ stateWriter?.writeSuccessor(
1556
+ source,
1557
+ getGraphState(successor.state, depths[index] + 1),
1558
+ existing !== -1,
1559
+ action && { name: action.name, signature: getActionSignature(action) },
1560
+ );
1561
+ }
1243
1562
  if (existing !== -1 && liveness) {
1244
1563
  const stored = states[existing];
1245
1564
  const isStored = stored.every((value, position) => value === successor.state[position]);
@@ -1297,10 +1616,22 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
1297
1616
  spec.scope,
1298
1617
  );
1299
1618
  } catch (error) {
1300
- return toFailure(error, []);
1619
+ if (!(error instanceof TlaIllegalStateError))
1620
+ return replayInitialStates(toFailure(error, []));
1621
+ // TLC prints an illegal initial state with null for each variable it leaves undefined, and
1622
+ // stops before it prints the statistics.
1623
+ const illegal = toFailure(
1624
+ error,
1625
+ [],
1626
+ error.state.map((value) => value ?? createModelValue("null")),
1627
+ );
1628
+ return {
1629
+ ...illegal,
1630
+ failure: illegal.failure && { ...illegal.failure, isWithoutStatistics: true },
1631
+ };
1301
1632
  }
1302
1633
  }
1303
- if (outcome.result) return outcome.result;
1634
+ if (outcome.result) return replayInitialStates(outcome.result);
1304
1635
 
1305
1636
  const next = spec.next;
1306
1637
  if (next === undefined) {
@@ -1311,23 +1642,58 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
1311
1642
  }
1312
1643
  return createSuccess();
1313
1644
  }
1645
+ // TLC labels and colors an edge of the -dump state graph by the action that generated it. When
1646
+ // the graph names its edges, the search generates successors action by action, as TLC does.
1647
+ const isNamingEdges = Boolean(
1648
+ options.dump?.dot && (options.dump.actionLabels || options.dump.colorize),
1649
+ );
1650
+ const forEachActionSuccessor = (
1651
+ state: Value[],
1652
+ onSuccessor: (successor: Successor, action: SpecAction | undefined) => boolean,
1653
+ ) => {
1654
+ if (!isNamingEdges) {
1655
+ return forEachSuccessor(
1656
+ next,
1657
+ state,
1658
+ environment,
1659
+ (successor) => onSuccessor(successor, undefined),
1660
+ spec.scope,
1661
+ );
1662
+ }
1663
+ nextActions.value ??= getNextActions(config, environment, specification.instanceActions);
1664
+ const progress = { isStopped: false };
1665
+ return nextActions.value.reduce((count, action) => {
1666
+ if (progress.isStopped) return count;
1667
+ return (
1668
+ count +
1669
+ forEachSuccessor(
1670
+ action.expression,
1671
+ state,
1672
+ environment,
1673
+ (successor) => {
1674
+ progress.isStopped = onSuccessor(successor, action);
1675
+ return progress.isStopped;
1676
+ },
1677
+ action.scope,
1678
+ )
1679
+ );
1680
+ }, 0);
1681
+ };
1314
1682
  const expandState = (index: number) => {
1315
1683
  const state = states[index];
1316
1684
  const liveSuccessors: LiveSuccessor[] = [];
1317
- const successorCount = forEachSuccessor(
1318
- next,
1319
- state,
1320
- environment,
1321
- (successor) => {
1322
- try {
1323
- outcome.result = visitSuccessor(index, successor, liveSuccessors);
1324
- } catch (error) {
1325
- outcome.result = toFailure(error, getTrace(index, successor));
1326
- }
1327
- return outcome.result !== undefined;
1328
- },
1329
- spec.scope,
1330
- );
1685
+ const source = stateWriter && getGraphState(state, depths[index]);
1686
+ const successorCount = forEachActionSuccessor(state, (successor, action) => {
1687
+ try {
1688
+ outcome.result = visitSuccessor(index, successor, liveSuccessors, source, action);
1689
+ } catch (error) {
1690
+ // TLC reports a successor it cannot fingerprint as a failure of the state it expands.
1691
+ if (current.isFingerprinting) throw error;
1692
+ const failure = toFailure(error, getTrace(index, successor));
1693
+ outcome.result = isStackOverflow(error) ? failure : replaySuccessors(failure, index);
1694
+ }
1695
+ return outcome.result !== undefined;
1696
+ });
1331
1697
  current.isExpanding = false;
1332
1698
  if (outcome.result) return outcome.result;
1333
1699
  if (successorCount === 0 && config.checkDeadlock) {
@@ -1335,32 +1701,78 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
1335
1701
  }
1336
1702
  try {
1337
1703
  const accepted = liveness?.addState(index, state, liveSuccessors);
1338
- current.livenessSource = -1;
1339
- if (!accepted) return undefined;
1704
+ if (!liveness || !accepted) return undefined;
1705
+ const steps = getPathSteps(accepted);
1706
+ const properties = liveness.getViolatedProperties(
1707
+ steps.map((step) => step.state),
1708
+ steps.length - 1,
1709
+ );
1340
1710
  return reportViolation("property-violation", {
1341
- name: accepted.name,
1342
- trace: getPathTrace(accepted.path),
1711
+ name: properties[0],
1712
+ properties,
1713
+ trace: toTrace(steps, accepted),
1343
1714
  });
1344
1715
  } catch (error) {
1345
- return toFailure(error, getStateTrace(index), undefined, getPartialOutDegrees());
1716
+ return replayFailure(
1717
+ toFailure(toNextStateError(error), getStateTrace(index), undefined, getPartialOutDegrees()),
1718
+ (_, traced) =>
1719
+ createLivenessChecker(
1720
+ search.properties.liveness,
1721
+ spec.temporals,
1722
+ traced,
1723
+ liveGraph,
1724
+ )?.addState(index, state, liveSuccessors),
1725
+ true,
1726
+ );
1346
1727
  }
1347
1728
  };
1348
- const reportLasso = (lasso: Lasso) => {
1729
+ // TLC names the action when the next-state relation has more than one, and prints the
1730
+ // incomplete successor with null for each variable it leaves undefined.
1731
+ const reportIncompleteSuccessor = (error: TlaIncompleteStateError, index: number) => {
1732
+ nextActions.value ??= getNextActions(config, environment, specification.instanceActions);
1733
+ const actions = nextActions.value;
1734
+ const action =
1735
+ actions.length === 1 ? actions[0] : actions.find((item) => item.name === error.action);
1736
+ const variables = `variable${error.missing.length > 1 ? "s are" : " is"} not defined: ${error.missing.join(", ")}.\n`;
1737
+ runtime.generatedStates++;
1738
+ return toFailure(
1739
+ actions.length === 1
1740
+ ? error
1741
+ : new TlaEvaluationError(
1742
+ `Successor state is not completely specified by action ${error.action} of the next-state relation. The following ${variables}`,
1743
+ ),
1744
+ [
1745
+ ...getStateTrace(index),
1746
+ {
1747
+ action: error.action,
1748
+ label: action && getActionLabel(action),
1749
+ state: toRecord(error.state.map((value) => value ?? createModelValue("null"))),
1750
+ },
1751
+ ],
1752
+ );
1753
+ };
1754
+ // TLC names the properties and the step back into the cycle from the states it prints.
1755
+ const reportLasso = (checker: LivenessChecker, lasso: Lasso) => {
1349
1756
  const path = [...lasso.prefix, ...lasso.cycle];
1350
- const trace = getPathTrace(path, lasso.prefix.length);
1351
- const back = path[lasso.prefix.length];
1757
+ const loopStart = lasso.prefix.length;
1758
+ const steps = getPathSteps(path, loopStart);
1759
+ const trace = toTrace(steps, path, loopStart);
1760
+ const properties = checker.getViolatedProperties(
1761
+ steps.map((step) => step.state),
1762
+ loopStart,
1763
+ );
1764
+ const back = path[loopStart];
1352
1765
  const last = path[path.length - 1];
1766
+ const lastState = steps[steps.length - 1].state;
1353
1767
  const loopLabel =
1354
- back === last ? undefined : withoutOutput(() => getLabel(last, states[last], states[back]));
1768
+ back === last ? undefined : withoutOutput(() => getLabel(last, lastState, states[back]));
1355
1769
  return reportViolation(
1356
1770
  "liveness-violation",
1357
- { name: lasso.name, trace, loopStart: lasso.prefix.length, loopLabel },
1771
+ { name: properties[0], properties, trace, loopStart, loopLabel },
1358
1772
  () =>
1359
1773
  back === last
1360
1774
  ? trace[trace.length - 1].action
1361
- : getTraceSuccessors(states[last]).find((successor) =>
1362
- isSameState(successor.state, states[back]),
1363
- )?.action,
1775
+ : findSuccessorWithFingerprint(lastState, back)?.action,
1364
1776
  );
1365
1777
  };
1366
1778
  const isPeriodic = liveness !== undefined && options.livenessCheck !== "final";
@@ -1373,11 +1785,9 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
1373
1785
  if (!isGrown || periodic.time > (now - startedAt) * LIVENESS_RATIO) return undefined;
1374
1786
  periodic.size = expanded;
1375
1787
  const lasso = liveness?.findViolation();
1376
- current.livenessSource = -1;
1377
1788
  periodic.time += performance.now() - now;
1378
1789
  return lasso;
1379
1790
  };
1380
- setNextStatePhase(true);
1381
1791
  for (let index = 0; index < states.length && !runtime.isStopped; index++) {
1382
1792
  current.index = index;
1383
1793
  current.candidate = undefined;
@@ -1386,22 +1796,28 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
1386
1796
  try {
1387
1797
  outcome.result = expandState(index);
1388
1798
  } catch (error) {
1389
- outcome.result = toFailure(error, getStateTrace(index));
1799
+ const failure =
1800
+ error instanceof TlaIncompleteStateError
1801
+ ? reportIncompleteSuccessor(error, index)
1802
+ : toFailure(toNextStateError(error), getStateTrace(index));
1803
+ outcome.result =
1804
+ error instanceof TlaIncompleteStateError || isStackOverflow(error)
1805
+ ? failure
1806
+ : replaySuccessors(failure, index);
1390
1807
  }
1391
1808
  if (outcome.result) return outcome.result;
1392
1809
  outDegrees[getOutDegreeBucket()]++;
1393
1810
  expansion.newStates = 0;
1394
1811
  if (isPeriodic && performance.now() >= periodic.at) {
1395
1812
  const lasso = findPeriodicViolation(index + 1);
1396
- if (lasso) return reportLasso(lasso);
1813
+ if (liveness && lasso) return reportLasso(liveness, lasso);
1397
1814
  }
1398
1815
  }
1399
1816
 
1400
1817
  current.index = -1;
1401
1818
  current.candidate = undefined;
1402
1819
  const lasso = liveness?.findViolation();
1403
- current.livenessSource = -1;
1404
- if (lasso) return reportLasso(lasso);
1820
+ if (liveness && lasso) return reportLasso(liveness, lasso);
1405
1821
 
1406
1822
  const postconditionViolation = search.findPostconditionViolation();
1407
1823
  if (postconditionViolation) {