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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/deciders.cjs +31 -31
  2. package/dist/deciders.js +2 -2
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.cts +12 -2
  5. package/dist/index.d.ts +12 -2
  6. package/dist/index.js +1 -1
  7. package/dist/parallel-worker.cjs +1 -1
  8. package/dist/parallel-worker.js +1 -1
  9. package/dist/prove.cjs +64 -64
  10. package/dist/prove.js +76 -76
  11. package/dist/run.cjs +42 -42
  12. package/dist/run.js +44 -44
  13. package/dist/transfer.cjs +37 -35
  14. package/dist/transfer.js +43 -41
  15. package/dist/worker.cjs +7 -7
  16. package/dist/worker.js +7 -7
  17. package/package.json +1 -1
  18. package/src/ast.ts +10 -1
  19. package/src/check-failure.ts +12 -10
  20. package/src/check-trace.ts +36 -23
  21. package/src/check.ts +182 -135
  22. package/src/cli/tlc-output.ts +17 -2
  23. package/src/cli/tlc.ts +2 -2
  24. package/src/codegen.ts +15 -19
  25. package/src/coverage.ts +190 -1
  26. package/src/dependencies.ts +19 -6
  27. package/src/dfid.ts +80 -27
  28. package/src/environment.ts +30 -1
  29. package/src/evaluate.ts +254 -59
  30. package/src/exit-codes.ts +25 -13
  31. package/src/instances.ts +11 -1
  32. package/src/levels.ts +48 -7
  33. package/src/liveness-checker.ts +98 -27
  34. package/src/liveness.ts +4 -1
  35. package/src/obligations/source.ts +2 -0
  36. package/src/parser.ts +3 -0
  37. package/src/prover/smt/solver/card2bv.ts +7 -4
  38. package/src/prover/smt/solver/context.ts +20 -4
  39. package/src/prover/smt/solver/dependent-expr-state.ts +18 -12
  40. package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
  41. package/src/prover/smt/solver/fd-solver.ts +146 -39
  42. package/src/prover/smt/solver/maxcore.ts +2 -1
  43. package/src/prover/smt/solver/maxsmt-base.ts +1 -0
  44. package/src/prover/smt/solver/model-checker.ts +1 -1
  45. package/src/prover/smt/solver/muz/dl-context.ts +12 -40
  46. package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
  47. package/src/prover/smt/solver/muz/dl-rule.ts +6 -7
  48. package/src/prover/smt/solver/muz/hnf.ts +2 -2
  49. package/src/prover/smt/solver/muz/horn-tactic.ts +14 -1
  50. package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
  51. package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
  52. package/src/prover/smt/solver/opt-context.ts +1 -0
  53. package/src/prover/smt/solver/opt-solver.ts +1 -1
  54. package/src/prover/smt/solver/parallel-tactic.ts +1 -1
  55. package/src/prover/smt/solver/qsat.ts +7 -2
  56. package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
  57. package/src/prover/smt/solver/sat/inc-sat-solver.ts +45 -26
  58. package/src/prover/smt/solver/sat/sat-tactic.ts +4 -2
  59. package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
  60. package/src/prover/smt/solver/smt-consequences.ts +1 -1
  61. package/src/prover/smt/solver/smt-kernel.ts +9 -2
  62. package/src/prover/smt/solver/smtlib-parser.ts +6 -2
  63. package/src/prover/smt/solver/smtlib-script.ts +197 -73
  64. package/src/prover/smt/solver/tactic.ts +64 -37
  65. package/src/resolve.ts +143 -39
  66. package/src/sany/generator-expressions.ts +2 -0
  67. package/src/sany/generator-proofs.ts +1 -0
  68. package/src/search.ts +156 -37
  69. package/src/simulate.ts +143 -150
  70. package/src/spec-description.ts +3 -0
  71. package/src/standard-modules.ts +41 -16
  72. package/src/subexpressions.ts +168 -63
  73. package/src/successors.ts +33 -11
  74. package/src/symmetry.ts +1 -0
  75. package/src/tlc/replay.ts +64 -41
  76. package/src/trace-liveness.ts +529 -0
  77. package/src/typed-tier.ts +20 -6
  78. package/src/values.ts +15 -1
@@ -17,8 +17,11 @@ import {
17
17
  } from "./ast";
18
18
  import { formatRange, TlaSyntaxError, type SanyError } from "./errors";
19
19
  import { getSourceName, mapChildren, mapDefinition } from "./instances";
20
+ import { parenthesizedRanges } from "./parser";
21
+ import { STANDARD_LEVELS } from "./standard-definitions";
20
22
  import { resolveSynonym } from "./tlc/jar-data";
21
23
  import {
24
+ compareLocations,
22
25
  getArity,
23
26
  getBinder,
24
27
  getNameSelectors,
@@ -32,7 +35,6 @@ import {
32
35
  selectionErrors,
33
36
  selectionArguments,
34
37
  selections,
35
- selectionSources,
36
38
  SELECTION_NAME,
37
39
  factReferences,
38
40
  type NullSelection,
@@ -60,6 +62,17 @@ interface SelectingName {
60
62
  }
61
63
 
62
64
  const declaredArities = new WeakMap<Definition, number>();
65
+ const generatedArgumentCounts = new WeakMap<Expression, number>();
66
+
67
+ const resolveDefinition = (
68
+ definition: Definition,
69
+ resolve: (expression: Expression) => Expression,
70
+ ) => {
71
+ const resolved = mapDefinition(definition, resolve);
72
+ const arity = declaredArities.get(definition);
73
+ if (arity !== undefined) declaredArities.set(resolved, arity);
74
+ return resolved;
75
+ };
63
76
 
64
77
  const setDeclaredArities = (declarations: Declaration[], definitions: Definition[]) =>
65
78
  declarations.forEach((declaration) => {
@@ -105,29 +118,33 @@ const findLabel = (
105
118
  }
106
119
  if (expression.kind === "Let")
107
120
  return findLabel(expression.body, name, [...lets, expression.definitions]);
108
- if (expression.kind === "Lambda") return undefined;
109
- for (const child of getChildren(expression)) {
121
+ if (expression.kind === "Lambda" || expression.kind === "Selection") return undefined;
122
+ for (const child of getChildren(expression).slice(0, generatedArgumentCounts.get(expression))) {
110
123
  const found = findLabel(child, name, lets);
111
124
  if (found) return found;
112
125
  }
113
126
  return undefined;
114
127
  };
115
128
 
129
+ const getHiddenLocation = (location: SourceLocation) => ({
130
+ line: location.line,
131
+ column: location.column,
132
+ });
133
+
116
134
  const wrapLets = (body: Expression, lets: Definition[][], location: SourceLocation) =>
117
135
  lets.reduceRight<Expression>(
118
- (inner, definitions) => ({ kind: "Let", definitions, body: inner, location }),
136
+ (inner, definitions) => ({
137
+ kind: "Let",
138
+ definitions,
139
+ body: inner,
140
+ location: getHiddenLocation(location),
141
+ }),
119
142
  body,
120
143
  );
121
144
 
122
145
  const createApplication = (selection: Selection, body: Expression): Expression => {
123
146
  const location = selection.location;
124
- const wrapped = wrapLets(body, selection.lets, location);
125
- if (selection.params.length === 0 && wrapped !== body) return wrapped;
126
- if (selection.params.length === 0) {
127
- const copy = { ...body };
128
- selectionSources.set(copy, selectionSources.get(body) ?? body);
129
- return copy;
130
- }
147
+ if (selection.params.length === 0) return body;
131
148
  if (selection.args.length === 0) {
132
149
  if (selection.params.some((param) => param.arity > 0)) {
133
150
  throw createError("Selected an operator with operator parameters as an argument", location);
@@ -135,7 +152,7 @@ const createApplication = (selection: Selection, body: Expression): Expression =
135
152
  return {
136
153
  kind: "Lambda",
137
154
  params: selection.params.map((param) => param.name),
138
- body: wrapped,
155
+ body,
139
156
  location,
140
157
  };
141
158
  }
@@ -152,7 +169,7 @@ const createApplication = (selection: Selection, body: Expression): Expression =
152
169
  kind: "Operator",
153
170
  name: SELECTION_NAME,
154
171
  params: selection.params,
155
- body: wrapped,
172
+ body,
156
173
  isLocal: true,
157
174
  isRecursive: false,
158
175
  location,
@@ -165,7 +182,7 @@ const createApplication = (selection: Selection, body: Expression): Expression =
165
182
  location,
166
183
  resolution: LOCAL_RESOLUTION,
167
184
  },
168
- location,
185
+ location: getHiddenLocation(location),
169
186
  };
170
187
  };
171
188
 
@@ -194,21 +211,26 @@ const applyDefinition = (definition: Definition, selection: Selection) => {
194
211
  location,
195
212
  resolution: LOCAL_RESOLUTION,
196
213
  };
197
- return createApplication({ ...selection, params: [...selection.params, ...params] }, reference);
214
+ return createApplication(
215
+ { ...selection, params: [...selection.params, ...params] },
216
+ wrapLets(reference, selection.lets, location),
217
+ );
198
218
  };
199
219
 
200
220
  const selectSubexpression = (
201
221
  selectors: Selector[],
202
222
  lookup: Lookup,
203
- isGoal: (name: string) => boolean,
204
223
  reference: Expression & SelectingName,
205
224
  isOperator: boolean,
206
225
  ): Expression => {
207
226
  const location = reference.location;
208
227
  const selection: Selection = { params: [], args: [], lets: [], location };
209
228
  let selectorIndex = 0;
229
+ let operatorIndex = -1;
210
230
  let current: Expression | undefined;
231
+ let unwrappedSelection: Expression | undefined;
211
232
  let isFailed = false;
233
+ let generatedArguments = 0;
212
234
  const nulls: NullSelection[] = [];
213
235
  const applications: SelectionArguments[] = [];
214
236
  let expressionError: SanyError | undefined;
@@ -229,6 +251,7 @@ const selectSubexpression = (
229
251
  nulls,
230
252
  error: { location: formatRange(range), message },
231
253
  });
254
+ generatedArgumentCounts.set(reference, generatedArguments);
232
255
  isFailed = true;
233
256
  return undefined;
234
257
  };
@@ -265,9 +288,13 @@ const selectSubexpression = (
265
288
  if (found.args.length !== arity) {
266
289
  const range = reference.argumentRanges?.[selectorIndex] ?? location.range;
267
290
  const message = `The operator ${resolveSynonym(found.name)} requires ${arity - found.earlier} arguments.`;
268
- if (!isOperator || found.args.length !== 0) return report(range, message);
291
+ if (!isOperator || found.args.length !== 0) {
292
+ generatedArguments += found.earlier;
293
+ return report(range, message);
294
+ }
269
295
  deferToExpression(range, message);
270
296
  }
297
+ generatedArguments += found.args.length;
271
298
  found.args.forEach((arg, index) =>
272
299
  selectionArguments.set(arg, {
273
300
  operator: found.name,
@@ -304,6 +331,7 @@ const selectSubexpression = (
304
331
  selection.params.push(...definition.params);
305
332
  selection.args.push(...found.args);
306
333
  current = definition.body;
334
+ operatorIndex = selectorIndex;
307
335
  selectorIndex++;
308
336
  return undefined;
309
337
  };
@@ -321,6 +349,7 @@ const selectSubexpression = (
321
349
  if (!isOperator) return report(range, message);
322
350
  deferToExpression(range, message);
323
351
  }
352
+ generatedArguments += selector.args.length;
324
353
  selection.lets.push(...found.lets);
325
354
  selection.params.push(...params.map((name) => ({ name, arity: 0 })));
326
355
  selection.args.push(...selector.args);
@@ -334,31 +363,23 @@ const selectSubexpression = (
334
363
  if (!current) throw createError("Subexpression selection failed", location);
335
364
  if (selector.kind === "Colon") return;
336
365
  const range = reference.selectorRanges?.[selectorIndex];
337
- const currentRange = current.location.range;
338
- if (
339
- (current.kind === "Subexpression" ||
340
- (current.kind === "Identifier" && current.name.includes("!")) ||
341
- (current.kind === "Apply" && current.operator.includes("!"))) &&
342
- (currentRange?.module !== location.range?.module || isBefore(current.location, location))
343
- ) {
344
- const selected = selectionErrors.has(current)
345
- ? current
346
- : resolveSubexpressions(current, lookup, isGoal);
347
- const noOperands = `Choosing operand \`${getSelectorName(selector)}' of subexpression with no operands.`;
348
- if (selectionErrors.has(selected)) {
349
- report(range, noOperands);
350
- return;
351
- }
352
- if (selections.has(selected) && selected.kind !== "Lambda") {
353
- checkNull(selected, noOperands, true);
354
- current =
355
- selected.kind === "Let" &&
356
- selected.body.kind === "Apply" &&
357
- selected.body.operator === SELECTION_NAME
358
- ? selected.body
366
+ const noOperands = `Choosing operand \`${getSelectorName(selector)}' of subexpression with no operands.`;
367
+ if (selectionErrors.has(current)) {
368
+ report(range, noOperands);
369
+ return;
370
+ }
371
+ if (selections.has(current) && current.kind !== "Lambda" && current !== unwrappedSelection) {
372
+ checkNull(current, noOperands, true);
373
+ unwrappedSelection = current;
374
+ current =
375
+ current.kind === "Let" &&
376
+ current.body.kind === "Apply" &&
377
+ current.body.operator === SELECTION_NAME
378
+ ? current.body
379
+ : current.kind === "Selection"
380
+ ? current
359
381
  : // SANY wraps a selection without parameters in $Nop, whose only operand is the selection.
360
- { kind: "Tuple", elements: [selected], location: selected.location };
361
- }
382
+ { kind: "Tuple", elements: [current], location: current.location };
362
383
  }
363
384
  if (current.kind === "Label") {
364
385
  current = current.body;
@@ -386,10 +407,14 @@ const selectSubexpression = (
386
407
  }
387
408
  selection.params.push(...binder.names.map((name) => ({ name, arity: 0 })));
388
409
  if (selector.kind === "Bound") {
410
+ generatedArguments += selector.args.length;
389
411
  selection.args.push(...selector.args);
390
412
  applications.push(getExpressionArguments("", range, selector.args));
391
413
  }
392
- current = binder.body;
414
+ current =
415
+ selections.has(current) && binder.body.kind === "Selection"
416
+ ? binder.body.expression
417
+ : binder.body;
393
418
  return;
394
419
  }
395
420
  if (current.kind === "Case") {
@@ -480,6 +505,24 @@ const selectSubexpression = (
480
505
  followLabels();
481
506
  continue;
482
507
  }
508
+ if (selector.kind === "Colon" && selectors[selectorIndex - 1].kind !== "Name") {
509
+ report(
510
+ reference.selectorRanges?.[selectorIndex - 1],
511
+ "!: should not follow an operand selector.",
512
+ );
513
+ return reference;
514
+ }
515
+ if (
516
+ selector.kind === "Colon" &&
517
+ selectors[selectorIndex + 1]?.kind !== "Name" &&
518
+ (operatorIndex !== selectorIndex - 1 || selectorIndex !== selectors.length - 1)
519
+ ) {
520
+ report(
521
+ reference.selectorRanges?.[selectorIndex],
522
+ "`!:' can be used only after a name and either at the end after an\noperator name or before an operator name.",
523
+ );
524
+ return reference;
525
+ }
483
526
  if (selector.kind !== "Colon") {
484
527
  checkNull(
485
528
  current,
@@ -510,7 +553,23 @@ const selectSubexpression = (
510
553
  }
511
554
  deferToExpression(location.range, message);
512
555
  }
513
- const selected = createApplication(selection, current);
556
+ const body = wrapLets(current, selection.lets, location);
557
+ const share = (expression: Expression): Expression => ({
558
+ kind: "Selection",
559
+ expression,
560
+ // SANY's $Nop, which TLC's call stack shows at the reference, wraps only a selection without parameters.
561
+ location:
562
+ selection.params.length === 0 && body.kind !== "Lambda"
563
+ ? location
564
+ : getHiddenLocation(location),
565
+ });
566
+ // SANY selects a LAMBDA itself rather than wrapping it in $Nop, so the selection keeps its arity.
567
+ const selected = createApplication(
568
+ selection,
569
+ body.kind !== "Lambda"
570
+ ? share(body)
571
+ : { ...body, body: selections.has(body) ? body.body : share(body.body), location },
572
+ );
514
573
  nullSelections.set(selected, nulls);
515
574
  if (expressionError) operatorSelectionErrors.set(selected, expressionError);
516
575
  return selected;
@@ -543,14 +602,24 @@ const resolveSubexpressions = (
543
602
  if (!containsReference(expression)) return expression;
544
603
  if (expression.kind === "Let") {
545
604
  if (expression.recursive) setDeclaredArities(expression.recursive, expression.definitions);
605
+ const resolved: Definition[] = [];
546
606
  const local: Lookup = (name) =>
547
- expression.definitions.find((definition) => definition.name === name) ?? lookup(name);
607
+ resolved.find((definition) => definition.name === name) ??
608
+ expression.definitions.find((definition) => definition.name === name) ??
609
+ lookup(name);
548
610
  const isLocalGoal = (name: string) =>
549
611
  !expression.definitions.some((definition) => definition.name === name) && isGoal(name);
550
- const mapped = mapChildren(expression, (child) =>
551
- resolveSubexpressions(child, local, isLocalGoal),
612
+ expression.definitions.forEach((definition) =>
613
+ resolved.push(
614
+ resolveDefinition(definition, (child) => resolveSubexpressions(child, local, isLocalGoal)),
615
+ ),
552
616
  );
553
- return mapped.kind === "Let" && mapped.instances
617
+ const mapped = {
618
+ ...expression,
619
+ definitions: resolved,
620
+ body: resolveSubexpressions(expression.body, local, isLocalGoal),
621
+ };
622
+ return mapped.instances
554
623
  ? {
555
624
  ...mapped,
556
625
  instances: mapped.instances.map((instance) =>
@@ -560,6 +629,14 @@ const resolveSubexpressions = (
560
629
  : mapped;
561
630
  }
562
631
  const callee = expression.kind === "Apply" ? lookup(expression.operator) : undefined;
632
+ // SANY expects an operator argument only of a user-defined operator, which a standard module's built-in operators stand for.
633
+ const calleeParams =
634
+ callee?.kind === "Operator"
635
+ ? callee.params
636
+ : expression.kind === "Apply"
637
+ ? STANDARD_LEVELS.get(expression.operator.slice(expression.operator.lastIndexOf("!") + 1))
638
+ ?.formals
639
+ : undefined;
563
640
  const rebuilt =
564
641
  expression.kind === "Apply"
565
642
  ? {
@@ -569,7 +646,7 @@ const resolveSubexpressions = (
569
646
  arg,
570
647
  lookup,
571
648
  isGoal,
572
- callee?.kind !== "Operator" || callee.params[index]?.arity !== 0,
649
+ calleeParams !== undefined && calleeParams[index]?.arity !== 0,
573
650
  ),
574
651
  ),
575
652
  }
@@ -587,7 +664,16 @@ const resolveSubexpressions = (
587
664
  ? getQualifiedSelectors(mapped.operator, mapped.args, mapped.argumentCounts, lookup)
588
665
  : undefined;
589
666
  const first = selectors?.[0];
590
- if (!selectors) return mapped;
667
+ const setGeneratedArguments = (count: number) => {
668
+ generatedArgumentCounts.set(expression, count);
669
+ generatedArgumentCounts.set(mapped, count);
670
+ };
671
+ if (!selectors) {
672
+ if (mapped.kind === "Apply" && mapped.operator.includes("!") && !lookup(mapped.operator)) {
673
+ setGeneratedArguments(0);
674
+ }
675
+ return mapped;
676
+ }
591
677
  const nameCount = selectors.findIndex((selector) => selector.kind !== "Name");
592
678
  const names = selectors.slice(0, nameCount === -1 ? selectors.length : nameCount);
593
679
  const isQualified = names.some(
@@ -601,9 +687,16 @@ const resolveSubexpressions = (
601
687
  ),
602
688
  );
603
689
  if (first?.kind === "Name" && isGoal(first.name) && !isQualified) return mapped;
604
- if (first?.kind === "Name" && selectors[1].kind !== "Name" && !lookup(first.name)) return mapped;
605
- const selected = selectSubexpression(selectors, lookup, isGoal, mapped, isOperator);
606
- if (selected !== mapped) selections.add(selected);
690
+ if (first?.kind === "Name" && selectors[1].kind !== "Name" && !lookup(first.name)) {
691
+ setGeneratedArguments(0);
692
+ return mapped;
693
+ }
694
+ const selected = selectSubexpression(selectors, lookup, mapped, isOperator);
695
+ const generated = generatedArgumentCounts.get(mapped);
696
+ if (generated !== undefined) setGeneratedArguments(generated);
697
+ const parenthesized = parenthesizedRanges.get(expression);
698
+ if (parenthesized && selected !== mapped) parenthesizedRanges.set(selected, parenthesized);
699
+ if (selected !== mapped) selections.set(selected, mapped);
607
700
  return selected;
608
701
  };
609
702
 
@@ -675,13 +768,15 @@ export const resolveModuleSubexpressions = (module: Module, available: Definitio
675
768
  (definition.isRecursive && declared !== undefined && isBefore(declared, location))
676
769
  );
677
770
  };
771
+ const resolvedDefinitions = new Map<Definition, Definition>();
678
772
  const getVisibleLookup =
679
773
  (lookup: Lookup, location: SourceLocation): Lookup =>
680
774
  (name) => {
681
775
  const definition = lookup(name);
682
- return definition && (!own.has(definition) || isDeclaredBefore(definition, location))
683
- ? definition
684
- : undefined;
776
+ if (!definition || (own.has(definition) && !isDeclaredBefore(definition, location))) {
777
+ return undefined;
778
+ }
779
+ return resolvedDefinitions.get(definition) ?? definition;
685
780
  };
686
781
  const proofLookup = createLookup([...available, ...module.definitions]);
687
782
  const isGoal = (name: string) => goals.has(name);
@@ -730,7 +825,7 @@ export const resolveModuleSubexpressions = (module: Module, available: Definitio
730
825
  definitions: body.definitions.map((definition) =>
731
826
  definition.kind === "Instance"
732
827
  ? resolveInstance(definition, lookup, isProofGoal)
733
- : mapDefinition(definition, resolveInProof),
828
+ : resolveDefinition(definition, resolveInProof),
734
829
  ),
735
830
  };
736
831
  case "Have":
@@ -760,8 +855,8 @@ export const resolveModuleSubexpressions = (module: Module, available: Definitio
760
855
  body: resolver.resolveStep(step.body),
761
856
  proof: resolver.resolveProof(step.proof),
762
857
  };
763
- if (step.body.kind === "Define") {
764
- const definitions = step.body.definitions.flatMap((definition) =>
858
+ if (resolved.body.kind === "Define") {
859
+ const definitions = resolved.body.definitions.flatMap((definition) =>
765
860
  definition.kind === "Instance" ? [] : [definition],
766
861
  );
767
862
  const outer = resolver.lookup;
@@ -775,6 +870,19 @@ export const resolveModuleSubexpressions = (module: Module, available: Definitio
775
870
  };
776
871
  return { lookup, resolveFacts, resolveStatement, resolveStep, resolveProof };
777
872
  };
873
+ const hasReferences =
874
+ module.definitions.some((definition) => containsReference(definition.body)) ||
875
+ module.assumptions.some((assumption) => containsReference(assumption.expression));
876
+ if (hasReferences) {
877
+ [...module.definitions, ...clauses]
878
+ .toSorted((left, right) => compareLocations(left.location, right.location))
879
+ .forEach((definition) =>
880
+ resolvedDefinitions.set(
881
+ definition,
882
+ resolveDefinition(definition, (expression) => resolve(expression, definition.location)),
883
+ ),
884
+ );
885
+ }
778
886
  const resolved = {
779
887
  ...module,
780
888
  theorems: module.theorems.map((theorem) => {
@@ -799,14 +907,11 @@ export const resolveModuleSubexpressions = (module: Module, available: Definitio
799
907
  ),
800
908
  })),
801
909
  };
802
- const hasReferences =
803
- module.definitions.some((definition) => containsReference(definition.body)) ||
804
- module.assumptions.some((assumption) => containsReference(assumption.expression));
805
910
  if (!hasReferences) return resolved;
806
911
  return {
807
912
  ...resolved,
808
- definitions: module.definitions.map((definition) =>
809
- mapDefinition(definition, (expression) => resolve(expression, definition.location)),
913
+ definitions: module.definitions.map(
914
+ (definition) => resolvedDefinitions.get(definition) ?? definition,
810
915
  ),
811
916
  assumptions: module.assumptions.map((assumption) => ({
812
917
  ...assumption,
package/src/successors.ts CHANGED
@@ -274,6 +274,7 @@ const getUnchangedVariables = (
274
274
 
275
275
  const ACTION_KINDS = new Set([
276
276
  "Label",
277
+ "Selection",
277
278
  "And",
278
279
  "Or",
279
280
  "Exists",
@@ -1092,10 +1093,16 @@ const compileAction = (
1092
1093
  case "Let": {
1093
1094
  const body = getChildRunner(expression.body);
1094
1095
  const reevaluated = getReevaluatedDefinitions(expression.definitions, environment);
1096
+ // TLC's Tool#enabled binds a LET's definitions to lazy values it caches, where Tool#getNextStates evaluates them at every use.
1097
+ const cached = { impure: new Set<Definition>(), streamed: reevaluated.streamed };
1095
1098
  return (run, scope, partial, action, isFixed, onComplete) =>
1096
1099
  body(
1097
1100
  run,
1098
- bindDefinitions(expression.definitions, getContext(run, scope, partial), reevaluated),
1101
+ bindDefinitions(
1102
+ expression.definitions,
1103
+ getContext(run, scope, partial),
1104
+ run.isEnabled ? cached : reevaluated,
1105
+ ),
1099
1106
  partial,
1100
1107
  action,
1101
1108
  isFixed,
@@ -1140,6 +1147,8 @@ const compileAction = (
1140
1147
  );
1141
1148
  case "Label":
1142
1149
  return getChildRunner(expression.body);
1150
+ case "Selection":
1151
+ return getChildRunner(expression.expression);
1143
1152
  case "Identifier":
1144
1153
  return compileIdentifier(expression, environment, isInit);
1145
1154
  case "FunctionApplication":
@@ -1204,7 +1213,9 @@ export const isEnabled = (expression: Expression, context: Context): boolean =>
1204
1213
  );
1205
1214
  }
1206
1215
  const environment = context.environment;
1207
- if (environment.callStack) return replayEnabled(expression, context.scope, state, environment);
1216
+ if (environment.callStack || (environment.coverage && environment.coverage.current !== -1)) {
1217
+ return replayEnabled(expression, context.scope, state, environment);
1218
+ }
1208
1219
  const run: Run = {
1209
1220
  environment,
1210
1221
  isInit: false,
@@ -1281,6 +1292,20 @@ export const getInitialStates = (
1281
1292
  return states;
1282
1293
  };
1283
1294
 
1295
+ export const createIncompleteSuccessorError = (
1296
+ partial: State,
1297
+ action: string | undefined,
1298
+ environment: Environment,
1299
+ ) => {
1300
+ const missing = environment.variables.filter((_name, index) => partial[index] === undefined);
1301
+ return new TlaIncompleteSuccessorError(
1302
+ `Successor state is not completely specified by action ${action ?? "Next"}. The following variables are not assigned: ${missing.join(", ")}`,
1303
+ partial,
1304
+ action,
1305
+ missing,
1306
+ );
1307
+ };
1308
+
1284
1309
  export const forEachSuccessor = (
1285
1310
  expression: Expression,
1286
1311
  state: Value[],
@@ -1289,6 +1314,7 @@ export const forEachSuccessor = (
1289
1314
  scope?: Scope,
1290
1315
  generator?: JavaRandom,
1291
1316
  onUnsatisfied?: Run["onUnsatisfied"],
1317
+ onIncomplete?: (state: State, action: string | undefined) => void,
1292
1318
  ) => {
1293
1319
  const run: Run = {
1294
1320
  environment,
@@ -1309,15 +1335,11 @@ export const forEachSuccessor = (
1309
1335
  (partial, action) => {
1310
1336
  if (run.isStopped) return;
1311
1337
  if (!isComplete(partial)) {
1312
- const missing = environment.variables.filter(
1313
- (_name, index) => partial[index] === undefined,
1314
- );
1315
- throw new TlaIncompleteSuccessorError(
1316
- `Successor state is not completely specified by action ${action ?? "Next"}. The following variables are not assigned: ${missing.join(", ")}`,
1317
- partial,
1318
- action,
1319
- missing,
1320
- );
1338
+ if (onIncomplete) {
1339
+ onIncomplete(partial, action);
1340
+ return;
1341
+ }
1342
+ throw createIncompleteSuccessorError(partial, action, environment);
1321
1343
  }
1322
1344
  run.successors++;
1323
1345
  run.isStopped = onSuccessor({ state: partial, action });
package/src/symmetry.ts CHANGED
@@ -139,6 +139,7 @@ export const getSymmetryGroup = (
139
139
  `The set${isPlural ? "s" : ""} ${names.join(", and ")} ${isPlural ? "have" : "has"} been defined to be a symmetry set but contain${isPlural ? "" : "s"} less than two elements.`,
140
140
  );
141
141
  };
142
+ // Deviation from TLC: MVPerms#permutationSubgroup sizes a util.Set one below the number of permutations, which throws for fewer than two.
142
143
  if (permutedSets.length >= elements.length) {
143
144
  warnSmallSets(permutedSets);
144
145
  return undefined;