tla-ts 0.0.3-dev.bfd303f → 0.0.3-dev.c2b256f

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 (81) hide show
  1. package/dist/cli.cjs +1 -1
  2. package/dist/cli.js +1 -1
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.cts +169 -27
  5. package/dist/index.d.ts +169 -27
  6. package/dist/index.js +1 -1
  7. package/dist/parallel-worker.cjs +1 -1
  8. package/dist/parallel-worker.js +2 -2
  9. package/dist/parallel.cjs +1 -1
  10. package/dist/parallel.js +2 -2
  11. package/dist/run-cli.cjs +1351 -20
  12. package/dist/run-cli.js +1351 -20
  13. package/dist/transfer.cjs +83 -28
  14. package/dist/transfer.js +83 -28
  15. package/package.json +5 -1
  16. package/src/ast.ts +57 -6
  17. package/src/bags.ts +4 -7
  18. package/src/builtins.ts +29 -11
  19. package/src/bundled-modules.ts +3 -3
  20. package/src/canonical.ts +4 -3
  21. package/src/check.ts +1332 -262
  22. package/src/cli.ts +8 -1
  23. package/src/codegen.ts +68 -21
  24. package/src/config.ts +252 -179
  25. package/src/environment.ts +437 -123
  26. package/src/errors.ts +195 -7
  27. package/src/evaluate.ts +718 -146
  28. package/src/exit-codes.ts +6 -24
  29. package/src/index.ts +1 -0
  30. package/src/instances.ts +4 -2
  31. package/src/java-overrides.ts +104 -25
  32. package/src/levels.ts +183 -37
  33. package/src/lexer.ts +112 -29
  34. package/src/live-check.ts +204 -146
  35. package/src/liveness.ts +190 -117
  36. package/src/obligation-expression.ts +2 -2
  37. package/src/obligation-source.ts +2 -0
  38. package/src/parallel-worker.ts +6 -1
  39. package/src/parallel.ts +57 -6
  40. package/src/parser.ts +445 -147
  41. package/src/pcal-ast.ts +770 -0
  42. package/src/pcal-parse.ts +1523 -0
  43. package/src/pcal-tokenize.ts +516 -0
  44. package/src/pcal-translate.ts +1230 -0
  45. package/src/pcal-validate.ts +454 -0
  46. package/src/randomization.ts +24 -7
  47. package/src/resolve.ts +1439 -411
  48. package/src/run-cli.ts +1167 -155
  49. package/src/runtime.ts +16 -0
  50. package/src/sany-builtins.ts +147 -0
  51. package/src/sany-generator.ts +3112 -0
  52. package/src/sany-levels.ts +1208 -0
  53. package/src/sany-lexer.ts +545 -0
  54. package/src/sany-linter.ts +122 -0
  55. package/src/sany-modules.ts +1398 -0
  56. package/src/sany-nodes.ts +463 -0
  57. package/src/sany-parse-error.ts +2161 -0
  58. package/src/sany-report.ts +354 -0
  59. package/src/sany-selectors.ts +738 -0
  60. package/src/sany-source.ts +248 -0
  61. package/src/sany-xml.ts +1017 -0
  62. package/src/spec-description.ts +26 -7
  63. package/src/standard-modules.ts +203 -146
  64. package/src/standard-ranges.ts +116 -0
  65. package/src/state-graph.ts +29 -6
  66. package/src/subexpressions.ts +221 -161
  67. package/src/substitution-levels.ts +38 -17
  68. package/src/successors.ts +158 -120
  69. package/src/symmetry.ts +168 -50
  70. package/src/tableau.ts +3 -1
  71. package/src/tlc-ext.ts +13 -17
  72. package/src/tlc-messages.ts +329 -0
  73. package/src/tlc-module.ts +49 -21
  74. package/src/tlc-modules.ts +0 -4
  75. package/src/tlc-order.ts +55 -9
  76. package/src/tlc-random.ts +28 -3
  77. package/src/tlc-replay.ts +655 -0
  78. package/src/tlc-version.ts +18 -0
  79. package/src/transfer.ts +15 -3
  80. package/src/value-sources.ts +29 -0
  81. package/src/values.ts +683 -256
package/src/successors.ts CHANGED
@@ -1,46 +1,47 @@
1
1
  import {
2
2
  getChildren,
3
3
  isLocallyResolved,
4
- type Bound,
5
4
  type Definition,
6
5
  type Expression,
7
6
  type QuantifierExpression,
8
7
  } from "./ast";
8
+ import { getKindString } from "./builtins";
9
9
  import { getReadVariables } from "./dependencies";
10
- import { TlaEvaluationError, TlaIncompleteStateError } from "./errors";
10
+ import { TlaEvaluationError, TlaIllegalStateError, TlaIncompleteSuccessorError } from "./errors";
11
11
  import { EXIT_STATUS, setExitCode } from "./exit-codes";
12
12
  import {
13
13
  describeLocation,
14
+ describeNode,
14
15
  describeRange,
15
- bindArgument,
16
+ bindLazyArguments,
16
17
  bindDefinitions,
17
18
  bindOperatorArguments,
18
19
  bindValue,
19
20
  compileArgumentScope,
20
21
  evaluate,
21
- getEntryEvaluator,
22
22
  expectBoolean,
23
23
  forEachBinding,
24
- getBoundsDomain,
24
+ getLazyFunction,
25
+ toKeepLazyContext,
25
26
  getDefinition,
26
- getEnumeratedElements,
27
+ getContextElements,
27
28
  getReevaluatedDefinitions,
28
29
  lookupScope,
29
30
  resolveApplyOperator,
30
31
  resolveGlobalOperator,
32
+ toUnspecifiedSubscriptError,
31
33
  type Context,
32
34
  type Environment,
33
- type Evaluator,
34
35
  type Scope,
35
36
  type State,
36
37
  } from "./evaluate";
37
38
  import { mapChildren } from "./instances";
39
+ import { isAssignedShortcut, LITERAL_KINDS, replayEnabled } from "./tlc-replay";
38
40
  import {
39
- createTuple,
40
41
  formatValue,
41
42
  getStreamedElements,
42
- isElementOf,
43
- isEnumerable,
43
+ isFunctionValue,
44
+ isTlcEnumerable,
44
45
  valuesEqual,
45
46
  type Value,
46
47
  } from "./values";
@@ -53,6 +54,8 @@ export interface Successor {
53
54
  interface Run {
54
55
  environment: Environment;
55
56
  isInit: boolean;
57
+ // Whether the run computes ENABLED rather than the successors of the state.
58
+ isEnabled: boolean;
56
59
  current: Value[] | undefined;
57
60
  isStopped: boolean;
58
61
  }
@@ -89,25 +92,47 @@ const assign = (partial: State, index: number, value: Value) => {
89
92
  return copy;
90
93
  };
91
94
 
92
- // TLC's Tool.getInitStates and Tool.getNextStates report a value where they expect a formula.
93
- const expectFormula = (expression: Expression, value: Value, isInit: boolean) => {
94
- if (typeof value === "boolean") return value;
95
- throw new TlaEvaluationError(
96
- `In computing ${isInit ? "initial" : "next"} states, TLC expected a boolean expression,\nbut instead found ${formatValue(value)}.\n${describeRange(expression)}`,
97
- );
95
+ // What TLC says it was computing when it fails.
96
+ const getComputation = (run: Run) =>
97
+ run.isInit ? "initial states" : run.isEnabled ? "ENABLED" : "next states";
98
+
99
+ // TLC fails with an unexpected exception when it fails to compute the next states or ENABLED.
100
+ const createRunError = (run: Run, message: string) => {
101
+ const error = new TlaEvaluationError(message);
102
+ return run.isInit ? error : setExitCode(error, EXIT_STATUS.error);
98
103
  };
99
104
 
100
- const holds = (expression: Expression, context: Context, value = evaluate(expression, context)) => {
101
- // TLC rejects a number in the next-state relation when it splits the relation into actions.
102
- if (context.next !== undefined && expression.kind === "Number") {
103
- throw setExitCode(
104
- new TlaEvaluationError(
105
- `The next state relation is not a boolean expression.\n${expression.text ?? expression.value}`,
106
- ),
107
- EXIT_STATUS.error,
108
- );
105
+ // TLC's message for a conjunct that isn't a boolean, which differs for a literal it walks to rather
106
+ // than evaluates.
107
+ const getNonBooleanMessage = (
108
+ run: Run,
109
+ value: Value,
110
+ expression: Expression,
111
+ isWalked: boolean,
112
+ ) => {
113
+ const node = describeNode(expression);
114
+ if (isWalked && LITERAL_KINDS.has(expression.kind)) {
115
+ return run.isEnabled
116
+ ? `Attempted to compute ENABLED on a non-boolean expression.\n${node}`
117
+ : `The ${run.isInit ? "init" : "next"} state relation is not a boolean expression.\n${node}`;
118
+ }
119
+ return `In computing ${getComputation(run)}, TLC expected a boolean expression,\nbut instead found ${formatValue(value)}.\n${node}`;
120
+ };
121
+
122
+ // TLC words an IF whose condition isn't a boolean differently for each computation.
123
+ const getIfConditionMessage = (run: Run, value: Value, expression: Expression) => {
124
+ const kind = getKindString(value);
125
+ const range = describeRange(expression);
126
+ if (run.isEnabled) {
127
+ return `In computing ENABLED, a non-boolean expression(${kind}) was used as the guard condition of an IF.\n${range}`;
109
128
  }
110
- return expectFormula(expression, value, context.next === undefined);
129
+ return `In computing ${getComputation(run)}, a non-boolean expression (${kind}) was used as the condition of an IF.${run.isInit ? "\n" : ""}${range}`;
130
+ };
131
+
132
+ const holds = (run: Run, expression: Expression, context: Context, isWalked = true) => {
133
+ const value = evaluate(expression, context);
134
+ if (typeof value === "boolean") return value;
135
+ throw createRunError(run, getNonBooleanMessage(run, value, expression, isWalked));
111
136
  };
112
137
 
113
138
  const isAssignmentOperator = (operator: string) =>
@@ -332,7 +357,6 @@ const compileConjunction = (
332
357
  isInit: boolean,
333
358
  ): Runner => {
334
359
  const conjuncts = operands.map((operand) => toConjunct(operand, environment, isInit));
335
- const evaluators: (Evaluator | undefined)[] = conjuncts.map(() => undefined);
336
360
  const runFrom = (
337
361
  start: number,
338
362
  run: Run,
@@ -343,11 +367,12 @@ const compileConjunction = (
343
367
  ): void => {
344
368
  let current = partial;
345
369
  let context: Context | undefined;
370
+ const isShortcut = isAssignedShortcut(run);
346
371
  for (let index = start; index < conjuncts.length; index++) {
347
- if (index > 0 && run.isInit && isComplete(current)) {
372
+ if (index > 0 && isShortcut && isComplete(current)) {
348
373
  context ??= getContext(run, scope, current);
349
374
  for (let rest = index; rest < conjuncts.length; rest++) {
350
- if (!holdsInInit(conjuncts[rest].expression, context)) return;
375
+ if (!holds(run, conjuncts[rest].expression, context, false)) return;
351
376
  }
352
377
  onComplete(current, action);
353
378
  return;
@@ -355,17 +380,12 @@ const compileConjunction = (
355
380
  const conjunct = conjuncts[index];
356
381
  if (conjunct.kind === "Guard") {
357
382
  context ??= getContext(run, scope, current);
358
- const evaluator = (evaluators[index] ??= getEntryEvaluator(
359
- conjunct.expression,
360
- environment,
361
- ));
362
- if (!holds(conjunct.expression, context, evaluator(context))) return;
383
+ if (!holds(run, conjunct.expression, context)) return;
363
384
  continue;
364
385
  }
365
386
  if (conjunct.kind === "Assign") {
366
387
  context ??= getContext(run, scope, current);
367
- const evaluator = (evaluators[index] ??= getEntryEvaluator(conjunct.value, environment));
368
- const value = evaluator(context);
388
+ const value = evaluate(conjunct.value, context);
369
389
  const assigned = current[conjunct.index];
370
390
  if (assigned === undefined) {
371
391
  current = assign(current, conjunct.index, value);
@@ -401,13 +421,10 @@ const compileConjunction = (
401
421
  runFrom(0, run, scope, partial, action, onComplete);
402
422
  };
403
423
 
404
- const holdsInInit = (expression: Expression, context: Context) =>
405
- expectFormula(expression, evaluate(expression, context), true);
406
-
407
424
  const compileGuard =
408
425
  (expression: Expression): Runner =>
409
426
  (run, scope, partial, action, _isFixed, onComplete) => {
410
- if (holds(expression, getContext(run, scope, partial))) onComplete(partial, action);
427
+ if (holds(run, expression, getContext(run, scope, partial))) onComplete(partial, action);
411
428
  };
412
429
 
413
430
  const compileMembership = (
@@ -419,16 +436,17 @@ const compileMembership = (
419
436
  const index = getIndex(run, scope, partial);
420
437
  const context = getContext(run, scope, partial);
421
438
  if (partial[index] !== undefined) {
422
- if (holds(expression, context)) onComplete(partial, action);
439
+ if (holds(run, expression, context)) onComplete(partial, action);
423
440
  return;
424
441
  }
425
442
  const evaluated = evaluate(set, context);
426
443
  const value: Value =
427
444
  expression.operator === "\\subseteq" ? { kind: "Subset", base: evaluated } : evaluated;
428
- if (!isEnumerable(value)) {
429
- throw new TlaEvaluationError(
430
- `In computing ${run.isInit ? "initial" : "next"} states, the right side of \\IN is not enumerable.\n${describeRange(expression)}`,
431
- );
445
+ if (!isTlcEnumerable(value)) {
446
+ const message = run.isEnabled
447
+ ? "The right side of \\IN is not enumerable."
448
+ : `In computing ${getComputation(run)}, the right side of \\IN is not enumerable.`;
449
+ throw createRunError(run, `${message}\n${describeRange(expression)}`);
432
450
  }
433
451
  const elements = getStreamedElements(value);
434
452
  for (let position = 0; position < elements.length && !run.isStopped; position++) {
@@ -478,65 +496,43 @@ const compileDynamicAssignment = (
478
496
  };
479
497
  };
480
498
 
481
- interface FunctionAction {
482
- bounds: Bound[];
483
- body: Expression;
484
- scope: Scope | undefined;
485
- }
486
-
487
- const getFunctionAction = (
488
- expression: Expression,
489
- scope: Scope | undefined,
490
- partial: State,
491
- run: Run,
492
- ): FunctionAction | undefined => {
493
- if (expression.kind === "FunctionConstruction") {
494
- return { bounds: expression.bounds, body: expression.body, scope };
495
- }
496
- if (expression.kind !== "Identifier") return undefined;
497
- const binding = lookupScope(scope, expression.name);
498
- if (binding?.kind === "Thunk") {
499
- return getFunctionAction(binding.expression, binding.scope, partial, run);
500
- }
501
- const definition = binding ? undefined : getDefinition(expression.name, run.environment);
502
- if (definition?.kind !== "Function") return undefined;
503
- const self = evaluate(expression, getContext(run, undefined, partial));
504
- return {
505
- bounds: definition.bounds,
506
- body: definition.body,
507
- scope: bindValue(undefined, definition.name, self),
508
- };
509
- };
510
-
499
+ // Tool.getInitStates and Tool.getNextStates walk the body of a function they apply that is still
500
+ // lazy, which they evaluate as TLC computes the initial states eagerly, and otherwise apply it.
511
501
  const compileFunctionAction = (
512
502
  expression: Expression & { kind: "FunctionApplication" },
513
503
  environment: Environment,
514
504
  isInit: boolean,
515
505
  ): Runner => {
516
- const guard = compileGuard(expression);
506
+ const node = describeRange(expression);
517
507
  return (run, scope, partial, action, isFixed, onComplete) => {
518
- const lambda = getFunctionAction(expression.function, scope, partial, run);
519
- if (!lambda) {
520
- guard(run, scope, partial, action, isFixed, onComplete);
508
+ const context = getContext(run, scope, partial);
509
+ const value = evaluate(expression.function, isInit ? context : toKeepLazyContext(context));
510
+ const lambda = getLazyFunction(value);
511
+ if (lambda !== undefined) {
512
+ getRunner(lambda.body, environment, isInit)(
513
+ run,
514
+ bindLazyArguments(lambda, expression, context),
515
+ partial,
516
+ action,
517
+ isFixed,
518
+ onComplete,
519
+ );
521
520
  return;
522
521
  }
523
- const context = getContext(run, scope, partial);
524
- const args = expression.args.map((arg) => evaluate(arg, context));
525
- const argument = args.length === 1 ? args[0] : createTuple(args);
526
- const domain = getBoundsDomain(lambda.bounds, getContext(run, lambda.scope, partial));
527
- if (!isElementOf(argument, domain)) {
528
- throw new TlaEvaluationError(
529
- `Attempted to apply a function to ${formatValue(argument)}, which is not in its domain at ${describeLocation(expression)}`,
522
+ if (!isFunctionValue(value)) {
523
+ throw createRunError(
524
+ run,
525
+ `In computing ${getComputation(run)}, a non-function (${getKindString(value)}) was applied as a function.\n${node}`,
530
526
  );
531
527
  }
532
- getRunner(lambda.body, environment, isInit)(
533
- run,
534
- bindArgument(lambda.bounds, lambda.scope, argument),
535
- partial,
536
- action,
537
- isFixed,
538
- onComplete,
539
- );
528
+ const result = evaluate(expression, context);
529
+ if (typeof result !== "boolean") {
530
+ throw createRunError(
531
+ run,
532
+ `In computing ${getComputation(run)}, TLC expected a boolean expression,\nbut didn't find one.\n${node}`,
533
+ );
534
+ }
535
+ if (result) onComplete(partial, action);
540
536
  };
541
537
  };
542
538
 
@@ -560,7 +556,7 @@ const compileUnchanged = (expression: Expression, environment: Environment): Run
560
556
  );
561
557
  return;
562
558
  }
563
- if (holds(unchanged, getContext(run, scope, partial))) onComplete(partial, action);
559
+ if (holds(run, unchanged, getContext(run, scope, partial))) onComplete(partial, action);
564
560
  };
565
561
  };
566
562
 
@@ -755,9 +751,10 @@ const compileAction = (
755
751
  if (expression.bounds.length === 1 && bound.pattern.kind === "Name") {
756
752
  const name = bound.pattern.name;
757
753
  return (run, scope, partial, action, isFixed, onComplete) => {
758
- const elements = getEnumeratedElements(
754
+ const elements = getContextElements(
759
755
  evaluate(bound.set, getContext(run, scope, partial)),
760
756
  bound.set,
757
+ environment.runtime.version,
761
758
  );
762
759
  for (let index = 0; index < elements.length && !run.isStopped; index++) {
763
760
  body(
@@ -777,7 +774,11 @@ const compileAction = (
777
774
  return (run, scope, partial, action, isFixed, onComplete) => {
778
775
  const context = getContext(run, scope, partial);
779
776
  const sets = expression.bounds.map((innerBound) =>
780
- getEnumeratedElements(evaluate(innerBound.set, context), innerBound.set),
777
+ getContextElements(
778
+ evaluate(innerBound.set, context),
779
+ innerBound.set,
780
+ environment.runtime.version,
781
+ ),
781
782
  );
782
783
  if (sets.some((elements) => elements.length === 0)) return;
783
784
  const visit = (index: number, boundScope: Scope | undefined): void => {
@@ -790,7 +791,7 @@ const compileAction = (
790
791
  const elementScope = bindValue(boundScope, hoisted.names[index], element);
791
792
  if (index === sets.length - 1) {
792
793
  const guardContext = getContext(run, elementScope, partial);
793
- if (!hoisted.guards.every((guard) => holds(guard, guardContext))) continue;
794
+ if (!hoisted.guards.every((guard) => holds(run, guard, guardContext))) continue;
794
795
  }
795
796
  visit(index - 1, elementScope);
796
797
  }
@@ -825,7 +826,7 @@ const compileAction = (
825
826
  );
826
827
  if (isBoundToValues) {
827
828
  const isSatisfied = scopes.every((boundScope) =>
828
- holds(expression.body, getContext(run, boundScope, partial)),
829
+ holds(run, expression.body, getContext(run, boundScope, partial)),
829
830
  );
830
831
  if (isSatisfied) onComplete(partial, action);
831
832
  return;
@@ -839,7 +840,7 @@ const compileAction = (
839
840
  const isSatisfied = scopes
840
841
  .slice(index)
841
842
  .every((boundScope) =>
842
- holdsInInit(expression.body, getContext(run, boundScope, nextPartial)),
843
+ holds(run, expression.body, getContext(run, boundScope, nextPartial)),
843
844
  );
844
845
  if (isSatisfied) onComplete(nextPartial, nextAction);
845
846
  return;
@@ -856,26 +857,38 @@ const compileAction = (
856
857
  const alternative = child(expression.alternative);
857
858
  return (run, scope, partial, action, isFixed, onComplete) => {
858
859
  const condition = evaluate(expression.condition, getContext(run, scope, partial));
859
- const branch = expectBoolean(condition, "an IF condition") ? consequent : alternative;
860
+ if (typeof condition !== "boolean") {
861
+ throw createRunError(run, getIfConditionMessage(run, condition, expression));
862
+ }
863
+ const branch = condition ? consequent : alternative;
860
864
  branch(run, scope, partial, action, isFixed, onComplete);
861
865
  };
862
866
  }
863
867
  case "Case": {
864
868
  const arms = expression.arms.map((arm) => ({
865
869
  condition: arm.condition,
870
+ source: arm.body,
866
871
  body: child(arm.body),
867
872
  }));
868
873
  const other = expression.other ? child(expression.other) : undefined;
869
874
  return (run, scope, partial, action, isFixed, onComplete) => {
870
875
  const context = getContext(run, scope, partial);
871
- const arm = arms.find((candidate) =>
872
- expectBoolean(evaluate(candidate.condition, context), "a CASE guard"),
873
- );
876
+ const arm = arms.find((candidate) => {
877
+ const value = evaluate(candidate.condition, context);
878
+ if (typeof value === "boolean") return value;
879
+ // TLC leaves out the space before the kind under ENABLED.
880
+ throw createRunError(
881
+ run,
882
+ `In computing ${getComputation(run)}, a non-boolean expression${run.isEnabled ? "" : " "}(${getKindString(value)}) was used as a guard condition of a CASE.\n${describeNode(candidate.source)}`,
883
+ );
884
+ });
874
885
  const body = arm?.body ?? other;
875
- if (!body)
876
- throw new TlaEvaluationError(
877
- `In computing ${run.isInit ? "initial" : "next"} states, TLC encountered a CASE with no conditions true.\n${describeRange(expression)}`,
886
+ if (!body) {
887
+ throw createRunError(
888
+ run,
889
+ `In computing ${getComputation(run)}, TLC encountered a CASE with no conditions true.\n${describeRange(expression)}`,
878
890
  );
891
+ }
879
892
  body(run, scope, partial, action, isFixed, onComplete);
880
893
  };
881
894
  }
@@ -904,10 +917,18 @@ const compileAction = (
904
917
  case "AngleAction": {
905
918
  const body = child(expression.action);
906
919
  const unchanged = getUnchangedWrapper(expression.subscript);
920
+ const isUnchanged = (run: Run, scope: Scope | undefined, nextPartial: State) => {
921
+ try {
922
+ return holds(run, unchanged, getContext(run, scope, nextPartial));
923
+ } catch (error) {
924
+ throw run.isEnabled
925
+ ? toUnspecifiedSubscriptError(error, environment.runtime.version)
926
+ : error;
927
+ }
928
+ };
907
929
  return (run, scope, partial, action, isFixed, onComplete) =>
908
930
  body(run, scope, partial, action, isFixed, (nextPartial, nextAction) => {
909
- if (!holds(unchanged, getContext(run, scope, nextPartial)))
910
- onComplete(nextPartial, nextAction);
931
+ if (!isUnchanged(run, scope, nextPartial)) onComplete(nextPartial, nextAction);
911
932
  });
912
933
  }
913
934
  case "BoxAction":
@@ -984,7 +1005,15 @@ export const isEnabled = (expression: Expression, context: Context): boolean =>
984
1005
  );
985
1006
  }
986
1007
  const environment = context.environment;
987
- const run: Run = { environment, isInit: false, current: state, isStopped: false };
1008
+ // TLC computes ENABLED again with its call stack recorded as it computes successors.
1009
+ if (environment.callStack) return replayEnabled(expression, context.scope, state, environment);
1010
+ const run: Run = {
1011
+ environment,
1012
+ isInit: false,
1013
+ isEnabled: true,
1014
+ current: state,
1015
+ isStopped: false,
1016
+ };
988
1017
  // TLC stops computing ENABLED at the first successor, so it skips the rest of the action.
989
1018
  getRunner(expression, environment, false)(
990
1019
  run,
@@ -1005,7 +1034,13 @@ export const forEachInitialState = (
1005
1034
  onState: (state: Value[]) => boolean,
1006
1035
  scope?: Scope,
1007
1036
  ) => {
1008
- const run: Run = { environment, isInit: true, current: undefined, isStopped: false };
1037
+ const run: Run = {
1038
+ environment,
1039
+ isInit: true,
1040
+ isEnabled: false,
1041
+ current: undefined,
1042
+ isStopped: false,
1043
+ };
1009
1044
  getRunner(expression, environment, true)(
1010
1045
  run,
1011
1046
  scope,
@@ -1017,12 +1052,7 @@ export const forEachInitialState = (
1017
1052
  if (!isComplete(partial)) {
1018
1053
  // TLC reports an initial state that isn't completely specified as an illegal state, not as
1019
1054
  // an evaluation failure.
1020
- throw setExitCode(
1021
- new TlaEvaluationError(
1022
- `The initial predicate does not assign ${getMissingVariables(partial, environment).join(", ")}`,
1023
- ),
1024
- EXIT_STATUS.error,
1025
- );
1055
+ throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
1026
1056
  }
1027
1057
  run.isStopped = onState(partial);
1028
1058
  },
@@ -1054,7 +1084,13 @@ export const forEachSuccessor = (
1054
1084
  onSuccessor: (successor: Successor) => boolean,
1055
1085
  scope?: Scope,
1056
1086
  ) => {
1057
- const run: Run = { environment, isInit: false, current: state, isStopped: false };
1087
+ const run: Run = {
1088
+ environment,
1089
+ isInit: false,
1090
+ isEnabled: false,
1091
+ current: state,
1092
+ isStopped: false,
1093
+ };
1058
1094
  const counter = { successors: 0 };
1059
1095
  getRunner(expression, environment, false)(
1060
1096
  run,
@@ -1065,10 +1101,12 @@ export const forEachSuccessor = (
1065
1101
  (partial, action) => {
1066
1102
  if (run.isStopped) return;
1067
1103
  if (!isComplete(partial)) {
1068
- throw new TlaIncompleteStateError(
1104
+ const missing = getMissingVariables(partial, environment);
1105
+ throw new TlaIncompleteSuccessorError(
1106
+ `Successor state is not completely specified by action ${action ?? "Next"}. The following variables are not assigned: ${missing.join(", ")}`,
1069
1107
  partial,
1070
1108
  action,
1071
- getMissingVariables(partial, environment).sort(),
1109
+ missing,
1072
1110
  );
1073
1111
  }
1074
1112
  counter.successors++;