tla-ts 0.0.3-dev.bffbba3 → 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 +150 -8
  5. package/dist/index.d.ts +150 -8
  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 +86 -28
  14. package/dist/transfer.js +86 -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 +1358 -219
  22. package/src/cli.ts +8 -1
  23. package/src/codegen.ts +68 -18
  24. package/src/config.ts +252 -179
  25. package/src/environment.ts +457 -132
  26. package/src/errors.ts +217 -3
  27. package/src/evaluate.ts +724 -117
  28. package/src/exit-codes.ts +5 -4
  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 +220 -84
  35. package/src/liveness.ts +192 -65
  36. package/src/obligation-expression.ts +2 -2
  37. package/src/obligation-source.ts +2 -0
  38. package/src/parallel-worker.ts +8 -3
  39. package/src/parallel.ts +56 -5
  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 +162 -114
  69. package/src/symmetry.ts +180 -52
  70. package/src/tableau.ts +4 -2
  71. package/src/tlc-ext.ts +13 -17
  72. package/src/tlc-messages.ts +329 -0
  73. package/src/tlc-module.ts +46 -18
  74. package/src/tlc-order.ts +56 -6
  75. package/src/tlc-random.ts +37 -9
  76. package/src/tlc-replay.ts +655 -0
  77. package/src/tlc-summary.ts +20 -5
  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 +684 -204
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, UNEXPECTED_EXCEPTION } 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,14 +92,47 @@ const assign = (partial: State, index: number, value: Value) => {
89
92
  return copy;
90
93
  };
91
94
 
92
- const holds = (expression: Expression, context: Context, value = evaluate(expression, context)) => {
93
- if (typeof value === "boolean") return value;
94
- try {
95
- return expectBoolean(value, `the action at ${describeLocation(expression)}`);
96
- } catch (error) {
97
- // TLC fails with an unexpected exception when the next-state relation isn't a boolean.
98
- throw context.next === undefined ? error : setExitCode(error, EXIT_STATUS.error);
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);
103
+ };
104
+
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}`;
99
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}`;
128
+ }
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));
100
136
  };
101
137
 
102
138
  const isAssignmentOperator = (operator: string) =>
@@ -321,7 +357,6 @@ const compileConjunction = (
321
357
  isInit: boolean,
322
358
  ): Runner => {
323
359
  const conjuncts = operands.map((operand) => toConjunct(operand, environment, isInit));
324
- const evaluators: (Evaluator | undefined)[] = conjuncts.map(() => undefined);
325
360
  const runFrom = (
326
361
  start: number,
327
362
  run: Run,
@@ -332,11 +367,12 @@ const compileConjunction = (
332
367
  ): void => {
333
368
  let current = partial;
334
369
  let context: Context | undefined;
370
+ const isShortcut = isAssignedShortcut(run);
335
371
  for (let index = start; index < conjuncts.length; index++) {
336
- if (index > 0 && run.isInit && isComplete(current)) {
372
+ if (index > 0 && isShortcut && isComplete(current)) {
337
373
  context ??= getContext(run, scope, current);
338
374
  for (let rest = index; rest < conjuncts.length; rest++) {
339
- if (!holdsInInit(conjuncts[rest].expression, context)) return;
375
+ if (!holds(run, conjuncts[rest].expression, context, false)) return;
340
376
  }
341
377
  onComplete(current, action);
342
378
  return;
@@ -344,17 +380,12 @@ const compileConjunction = (
344
380
  const conjunct = conjuncts[index];
345
381
  if (conjunct.kind === "Guard") {
346
382
  context ??= getContext(run, scope, current);
347
- const evaluator = (evaluators[index] ??= getEntryEvaluator(
348
- conjunct.expression,
349
- environment,
350
- ));
351
- if (!holds(conjunct.expression, context, evaluator(context))) return;
383
+ if (!holds(run, conjunct.expression, context)) return;
352
384
  continue;
353
385
  }
354
386
  if (conjunct.kind === "Assign") {
355
387
  context ??= getContext(run, scope, current);
356
- const evaluator = (evaluators[index] ??= getEntryEvaluator(conjunct.value, environment));
357
- const value = evaluator(context);
388
+ const value = evaluate(conjunct.value, context);
358
389
  const assigned = current[conjunct.index];
359
390
  if (assigned === undefined) {
360
391
  current = assign(current, conjunct.index, value);
@@ -390,16 +421,10 @@ const compileConjunction = (
390
421
  runFrom(0, run, scope, partial, action, onComplete);
391
422
  };
392
423
 
393
- const holdsInInit = (expression: Expression, context: Context) =>
394
- expectBoolean(
395
- evaluate(expression, context),
396
- `the initial predicate at ${describeLocation(expression)}`,
397
- );
398
-
399
424
  const compileGuard =
400
425
  (expression: Expression): Runner =>
401
426
  (run, scope, partial, action, _isFixed, onComplete) => {
402
- if (holds(expression, getContext(run, scope, partial))) onComplete(partial, action);
427
+ if (holds(run, expression, getContext(run, scope, partial))) onComplete(partial, action);
403
428
  };
404
429
 
405
430
  const compileMembership = (
@@ -411,16 +436,17 @@ const compileMembership = (
411
436
  const index = getIndex(run, scope, partial);
412
437
  const context = getContext(run, scope, partial);
413
438
  if (partial[index] !== undefined) {
414
- if (holds(expression, context)) onComplete(partial, action);
439
+ if (holds(run, expression, context)) onComplete(partial, action);
415
440
  return;
416
441
  }
417
442
  const evaluated = evaluate(set, context);
418
443
  const value: Value =
419
444
  expression.operator === "\\subseteq" ? { kind: "Subset", base: evaluated } : evaluated;
420
- if (!isEnumerable(value)) {
421
- throw new TlaEvaluationError(
422
- `In computing next states, the right side of \\in is not enumerable: ${formatValue(value)} at ${describeLocation(expression)}`,
423
- );
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)}`);
424
450
  }
425
451
  const elements = getStreamedElements(value);
426
452
  for (let position = 0; position < elements.length && !run.isStopped; position++) {
@@ -470,65 +496,43 @@ const compileDynamicAssignment = (
470
496
  };
471
497
  };
472
498
 
473
- interface FunctionAction {
474
- bounds: Bound[];
475
- body: Expression;
476
- scope: Scope | undefined;
477
- }
478
-
479
- const getFunctionAction = (
480
- expression: Expression,
481
- scope: Scope | undefined,
482
- partial: State,
483
- run: Run,
484
- ): FunctionAction | undefined => {
485
- if (expression.kind === "FunctionConstruction") {
486
- return { bounds: expression.bounds, body: expression.body, scope };
487
- }
488
- if (expression.kind !== "Identifier") return undefined;
489
- const binding = lookupScope(scope, expression.name);
490
- if (binding?.kind === "Thunk") {
491
- return getFunctionAction(binding.expression, binding.scope, partial, run);
492
- }
493
- const definition = binding ? undefined : getDefinition(expression.name, run.environment);
494
- if (definition?.kind !== "Function") return undefined;
495
- const self = evaluate(expression, getContext(run, undefined, partial));
496
- return {
497
- bounds: definition.bounds,
498
- body: definition.body,
499
- scope: bindValue(undefined, definition.name, self),
500
- };
501
- };
502
-
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.
503
501
  const compileFunctionAction = (
504
502
  expression: Expression & { kind: "FunctionApplication" },
505
503
  environment: Environment,
506
504
  isInit: boolean,
507
505
  ): Runner => {
508
- const guard = compileGuard(expression);
506
+ const node = describeRange(expression);
509
507
  return (run, scope, partial, action, isFixed, onComplete) => {
510
- const lambda = getFunctionAction(expression.function, scope, partial, run);
511
- if (!lambda) {
512
- 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
+ );
513
520
  return;
514
521
  }
515
- const context = getContext(run, scope, partial);
516
- const args = expression.args.map((arg) => evaluate(arg, context));
517
- const argument = args.length === 1 ? args[0] : createTuple(args);
518
- const domain = getBoundsDomain(lambda.bounds, getContext(run, lambda.scope, partial));
519
- if (!isElementOf(argument, domain)) {
520
- throw new TlaEvaluationError(
521
- `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}`,
522
526
  );
523
527
  }
524
- getRunner(lambda.body, environment, isInit)(
525
- run,
526
- bindArgument(lambda.bounds, lambda.scope, argument),
527
- partial,
528
- action,
529
- isFixed,
530
- onComplete,
531
- );
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);
532
536
  };
533
537
  };
534
538
 
@@ -552,7 +556,7 @@ const compileUnchanged = (expression: Expression, environment: Environment): Run
552
556
  );
553
557
  return;
554
558
  }
555
- if (holds(unchanged, getContext(run, scope, partial))) onComplete(partial, action);
559
+ if (holds(run, unchanged, getContext(run, scope, partial))) onComplete(partial, action);
556
560
  };
557
561
  };
558
562
 
@@ -747,9 +751,10 @@ const compileAction = (
747
751
  if (expression.bounds.length === 1 && bound.pattern.kind === "Name") {
748
752
  const name = bound.pattern.name;
749
753
  return (run, scope, partial, action, isFixed, onComplete) => {
750
- const elements = getEnumeratedElements(
754
+ const elements = getContextElements(
751
755
  evaluate(bound.set, getContext(run, scope, partial)),
752
756
  bound.set,
757
+ environment.runtime.version,
753
758
  );
754
759
  for (let index = 0; index < elements.length && !run.isStopped; index++) {
755
760
  body(
@@ -769,7 +774,11 @@ const compileAction = (
769
774
  return (run, scope, partial, action, isFixed, onComplete) => {
770
775
  const context = getContext(run, scope, partial);
771
776
  const sets = expression.bounds.map((innerBound) =>
772
- getEnumeratedElements(evaluate(innerBound.set, context), innerBound.set),
777
+ getContextElements(
778
+ evaluate(innerBound.set, context),
779
+ innerBound.set,
780
+ environment.runtime.version,
781
+ ),
773
782
  );
774
783
  if (sets.some((elements) => elements.length === 0)) return;
775
784
  const visit = (index: number, boundScope: Scope | undefined): void => {
@@ -782,7 +791,7 @@ const compileAction = (
782
791
  const elementScope = bindValue(boundScope, hoisted.names[index], element);
783
792
  if (index === sets.length - 1) {
784
793
  const guardContext = getContext(run, elementScope, partial);
785
- if (!hoisted.guards.every((guard) => holds(guard, guardContext))) continue;
794
+ if (!hoisted.guards.every((guard) => holds(run, guard, guardContext))) continue;
786
795
  }
787
796
  visit(index - 1, elementScope);
788
797
  }
@@ -817,7 +826,7 @@ const compileAction = (
817
826
  );
818
827
  if (isBoundToValues) {
819
828
  const isSatisfied = scopes.every((boundScope) =>
820
- holds(expression.body, getContext(run, boundScope, partial)),
829
+ holds(run, expression.body, getContext(run, boundScope, partial)),
821
830
  );
822
831
  if (isSatisfied) onComplete(partial, action);
823
832
  return;
@@ -831,7 +840,7 @@ const compileAction = (
831
840
  const isSatisfied = scopes
832
841
  .slice(index)
833
842
  .every((boundScope) =>
834
- holdsInInit(expression.body, getContext(run, boundScope, nextPartial)),
843
+ holds(run, expression.body, getContext(run, boundScope, nextPartial)),
835
844
  );
836
845
  if (isSatisfied) onComplete(nextPartial, nextAction);
837
846
  return;
@@ -848,26 +857,38 @@ const compileAction = (
848
857
  const alternative = child(expression.alternative);
849
858
  return (run, scope, partial, action, isFixed, onComplete) => {
850
859
  const condition = evaluate(expression.condition, getContext(run, scope, partial));
851
- 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;
852
864
  branch(run, scope, partial, action, isFixed, onComplete);
853
865
  };
854
866
  }
855
867
  case "Case": {
856
868
  const arms = expression.arms.map((arm) => ({
857
869
  condition: arm.condition,
870
+ source: arm.body,
858
871
  body: child(arm.body),
859
872
  }));
860
873
  const other = expression.other ? child(expression.other) : undefined;
861
874
  return (run, scope, partial, action, isFixed, onComplete) => {
862
875
  const context = getContext(run, scope, partial);
863
- const arm = arms.find((candidate) =>
864
- expectBoolean(evaluate(candidate.condition, context), "a CASE guard"),
865
- );
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
+ });
866
885
  const body = arm?.body ?? other;
867
- if (!body)
868
- throw new TlaEvaluationError(
869
- `${UNEXPECTED_EXCEPTION}In computing 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)}`,
870
890
  );
891
+ }
871
892
  body(run, scope, partial, action, isFixed, onComplete);
872
893
  };
873
894
  }
@@ -896,10 +917,18 @@ const compileAction = (
896
917
  case "AngleAction": {
897
918
  const body = child(expression.action);
898
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
+ };
899
929
  return (run, scope, partial, action, isFixed, onComplete) =>
900
930
  body(run, scope, partial, action, isFixed, (nextPartial, nextAction) => {
901
- if (!holds(unchanged, getContext(run, scope, nextPartial)))
902
- onComplete(nextPartial, nextAction);
931
+ if (!isUnchanged(run, scope, nextPartial)) onComplete(nextPartial, nextAction);
903
932
  });
904
933
  }
905
934
  case "BoxAction":
@@ -976,7 +1005,15 @@ export const isEnabled = (expression: Expression, context: Context): boolean =>
976
1005
  );
977
1006
  }
978
1007
  const environment = context.environment;
979
- 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
+ };
980
1017
  // TLC stops computing ENABLED at the first successor, so it skips the rest of the action.
981
1018
  getRunner(expression, environment, false)(
982
1019
  run,
@@ -997,7 +1034,13 @@ export const forEachInitialState = (
997
1034
  onState: (state: Value[]) => boolean,
998
1035
  scope?: Scope,
999
1036
  ) => {
1000
- 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
+ };
1001
1044
  getRunner(expression, environment, true)(
1002
1045
  run,
1003
1046
  scope,
@@ -1009,12 +1052,7 @@ export const forEachInitialState = (
1009
1052
  if (!isComplete(partial)) {
1010
1053
  // TLC reports an initial state that isn't completely specified as an illegal state, not as
1011
1054
  // an evaluation failure.
1012
- throw setExitCode(
1013
- new TlaEvaluationError(
1014
- `The initial predicate does not assign ${getMissingVariables(partial, environment).join(", ")}`,
1015
- ),
1016
- EXIT_STATUS.error,
1017
- );
1055
+ throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
1018
1056
  }
1019
1057
  run.isStopped = onState(partial);
1020
1058
  },
@@ -1046,7 +1084,13 @@ export const forEachSuccessor = (
1046
1084
  onSuccessor: (successor: Successor) => boolean,
1047
1085
  scope?: Scope,
1048
1086
  ) => {
1049
- 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
+ };
1050
1094
  const counter = { successors: 0 };
1051
1095
  getRunner(expression, environment, false)(
1052
1096
  run,
@@ -1057,8 +1101,12 @@ export const forEachSuccessor = (
1057
1101
  (partial, action) => {
1058
1102
  if (run.isStopped) return;
1059
1103
  if (!isComplete(partial)) {
1060
- throw new TlaEvaluationError(
1061
- `Successor state is not completely specified by action ${action ?? "Next"}. The following variables are not assigned: ${getMissingVariables(partial, environment).join(", ")}`,
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(", ")}`,
1107
+ partial,
1108
+ action,
1109
+ missing,
1062
1110
  );
1063
1111
  }
1064
1112
  counter.successors++;