tla-ts 0.0.10-dev.99796fe03 → 0.0.10-dev.a17d6d9fa

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 (226) hide show
  1. package/dist/compile.cjs +3 -3
  2. package/dist/compile.js +1 -1
  3. package/dist/deciders.cjs +36 -36
  4. package/dist/deciders.js +54 -54
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.d.cts +3 -2
  7. package/dist/index.d.ts +3 -2
  8. package/dist/index.js +1 -1
  9. package/dist/parallel-worker.cjs +1 -1
  10. package/dist/parallel-worker.js +1 -1
  11. package/dist/prove-worker.cjs +1 -1
  12. package/dist/prove-worker.js +1 -1
  13. package/dist/prove.cjs +60 -60
  14. package/dist/prove.js +78 -78
  15. package/dist/run.cjs +42 -44
  16. package/dist/run.js +44 -46
  17. package/dist/tlapm.cjs +1 -1
  18. package/dist/tlapm.js +2 -2
  19. package/dist/transfer.cjs +43 -43
  20. package/dist/transfer.js +39 -39
  21. package/dist/worker.cjs +6 -6
  22. package/dist/worker.js +6 -6
  23. package/package.json +1 -1
  24. package/src/ast.ts +1 -0
  25. package/src/bags.ts +50 -29
  26. package/src/builtins.ts +4 -3
  27. package/src/check-failure.ts +1 -1
  28. package/src/check-trace.ts +90 -51
  29. package/src/check.ts +367 -178
  30. package/src/cli/runtime-invariants.ts +20 -56
  31. package/src/cli/tlc-arguments.ts +2 -2
  32. package/src/cli/tlc-output.ts +1 -2
  33. package/src/cli/tlc.ts +16 -10
  34. package/src/cli/xml-exporter.ts +1 -1
  35. package/src/codegen.ts +26 -9
  36. package/src/dependencies.ts +49 -9
  37. package/src/dfid.ts +22 -10
  38. package/src/environment.ts +58 -33
  39. package/src/errors.ts +7 -0
  40. package/src/evaluate.ts +117 -41
  41. package/src/exit-codes.ts +4 -2
  42. package/src/instances.ts +5 -5
  43. package/src/java-hash.ts +14 -0
  44. package/src/java-overrides.ts +2 -2
  45. package/src/levels.ts +138 -90
  46. package/src/liveness-checker.ts +81 -33
  47. package/src/liveness.ts +49 -11
  48. package/src/obligations/index.ts +1 -1
  49. package/src/obligations/normalize.ts +1 -4
  50. package/src/obligations/printer.ts +5 -5
  51. package/src/parallel-worker.ts +8 -2
  52. package/src/parallel.ts +5 -0
  53. package/src/parser.ts +112 -145
  54. package/src/prover/isabelle/isar/attrib.ts +4 -4
  55. package/src/prover/isabelle/isar/rule-cases.ts +8 -6
  56. package/src/prover/isabelle/provers/clasimp.ts +1 -1
  57. package/src/prover/isabelle/provers/hypsubst.ts +2 -2
  58. package/src/prover/isabelle/pure/rewriter.ts +3 -3
  59. package/src/prover/isabelle/pure/term.ts +3 -3
  60. package/src/prover/prep/md5.ts +26 -29
  61. package/src/prover/smt/rewrite.ts +2 -7
  62. package/src/prover/smt/simplify.ts +1 -1
  63. package/src/prover/smt/solver/arith-rewriter.ts +11 -3
  64. package/src/prover/smt/solver/array-rewriter.ts +12 -2
  65. package/src/prover/smt/solver/asserted-formulas.ts +169 -58
  66. package/src/prover/smt/solver/ast-lt.ts +1 -1
  67. package/src/prover/smt/solver/ast.ts +63 -14
  68. package/src/prover/smt/solver/auf-solver.ts +23 -12
  69. package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
  70. package/src/prover/smt/solver/blast-term-ite.ts +47 -0
  71. package/src/prover/smt/solver/bound-simplifier.ts +11 -13
  72. package/src/prover/smt/solver/bv-decl-plugin.ts +13 -10
  73. package/src/prover/smt/solver/bv-rewriter.ts +1 -1
  74. package/src/prover/smt/solver/card2bv.ts +32 -18
  75. package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -24
  76. package/src/prover/smt/solver/context.ts +47 -9
  77. package/src/prover/smt/solver/ctx-simplify.ts +1 -2
  78. package/src/prover/smt/solver/datatype-decl-plugin.ts +15 -7
  79. package/src/prover/smt/solver/dependent-expr-state.ts +9 -4
  80. package/src/prover/smt/solver/diff-neq.ts +1 -2
  81. package/src/prover/smt/solver/elim-bounds.ts +89 -0
  82. package/src/prover/smt/solver/elim-term-ite-tactic.ts +48 -0
  83. package/src/prover/smt/solver/elim-uncnstr.ts +5 -8
  84. package/src/prover/smt/solver/euf/arith-internalize.ts +1 -1
  85. package/src/prover/smt/solver/euf/array-internalize.ts +1 -1
  86. package/src/prover/smt/solver/euf/bv-internalize.ts +1 -1
  87. package/src/prover/smt/solver/euf/egraph.ts +4 -11
  88. package/src/prover/smt/solver/euf/euf-solver.ts +1 -2
  89. package/src/prover/smt/solver/euf/mam.ts +1 -5
  90. package/src/prover/smt/solver/euf/q-ematch.ts +1 -2
  91. package/src/prover/smt/solver/euf/th-solver.ts +0 -7
  92. package/src/prover/smt/solver/expr2polynomial.ts +204 -79
  93. package/src/prover/smt/solver/factor.ts +36 -14
  94. package/src/prover/smt/solver/fd-solver.ts +2 -0
  95. package/src/prover/smt/solver/fix-dl-var.ts +1 -2
  96. package/src/prover/smt/solver/fpa-rewriter.ts +1 -2
  97. package/src/prover/smt/solver/fpa2bv-converter.ts +3 -1
  98. package/src/prover/smt/solver/fpa2bv-rewriter.ts +1 -0
  99. package/src/prover/smt/solver/goal.ts +6 -3
  100. package/src/prover/smt/solver/goal2nlsat.ts +57 -30
  101. package/src/prover/smt/solver/hashtable.ts +4 -0
  102. package/src/prover/smt/solver/internalizer.ts +1 -1
  103. package/src/prover/smt/solver/logic-tactics.ts +9 -2
  104. package/src/prover/smt/solver/lp/lp-settings.ts +5 -1
  105. package/src/prover/smt/solver/lp/nla-core.ts +1 -1
  106. package/src/prover/smt/solver/lp/nla-grobner.ts +2 -2
  107. package/src/prover/smt/solver/lp/nra-solver.ts +45 -39
  108. package/src/prover/smt/solver/lp/pdd.ts +2 -3
  109. package/src/prover/smt/solver/lp/union-find.ts +1 -1
  110. package/src/prover/smt/solver/mam-compiler.ts +1 -1
  111. package/src/prover/smt/solver/model-based-opt.ts +1 -1
  112. package/src/prover/smt/solver/model-evaluator.ts +2 -0
  113. package/src/prover/smt/solver/model-generator.ts +85 -43
  114. package/src/prover/smt/solver/mpf.ts +2 -4
  115. package/src/prover/smt/solver/mus.ts +2 -3
  116. package/src/prover/smt/solver/muz/dl-context.ts +10 -4
  117. package/src/prover/smt/solver/muz/dl-mk-slice.ts +3 -3
  118. package/src/prover/smt/solver/muz/dl-rule.ts +2 -2
  119. package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +1 -1
  120. package/src/prover/smt/solver/muz/horn-tactic.ts +1 -1
  121. package/src/prover/smt/solver/muz/spacer-context.ts +2 -4
  122. package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
  123. package/src/prover/smt/solver/nlqsat.ts +1 -1
  124. package/src/prover/smt/solver/nlsat/algebraic.ts +196 -92
  125. package/src/prover/smt/solver/nlsat/atoms.ts +52 -33
  126. package/src/prover/smt/solver/nlsat/explain.ts +375 -217
  127. package/src/prover/smt/solver/nlsat/levelwise.ts +460 -240
  128. package/src/prover/smt/solver/nlsat/polynomial.ts +2366 -681
  129. package/src/prover/smt/solver/nlsat/solver.ts +74 -64
  130. package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -17
  131. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -4
  132. package/src/prover/smt/solver/nlsat/upolynomial.ts +41 -18
  133. package/src/prover/smt/solver/nlsat-tactic.ts +1 -1
  134. package/src/prover/smt/solver/nnf.ts +6 -2
  135. package/src/prover/smt/solver/opt-context.ts +20 -7
  136. package/src/prover/smt/solver/opt-nlsat.ts +29 -18
  137. package/src/prover/smt/solver/opt-pareto.ts +19 -0
  138. package/src/prover/smt/solver/opt-preprocess.ts +1 -1
  139. package/src/prover/smt/solver/opt-solver.ts +9 -5
  140. package/src/prover/smt/solver/optsmt.ts +1 -1
  141. package/src/prover/smt/solver/pb-rewriter.ts +1 -4
  142. package/src/prover/smt/solver/poly-rewriter.ts +75 -18
  143. package/src/prover/smt/solver/probes.ts +88 -23
  144. package/src/prover/smt/solver/proto-model.ts +8 -8
  145. package/src/prover/smt/solver/push-app-ite.ts +37 -0
  146. package/src/prover/smt/solver/qe-arith-plugin.ts +2 -4
  147. package/src/prover/smt/solver/qe-lite.ts +2 -2
  148. package/src/prover/smt/solver/qe.ts +3 -2
  149. package/src/prover/smt/solver/qsat.ts +16 -6
  150. package/src/prover/smt/solver/quantifier-manager.ts +14 -9
  151. package/src/prover/smt/solver/recfun-decl-plugin.ts +2 -1
  152. package/src/prover/smt/solver/rewriter.ts +31 -25
  153. package/src/prover/smt/solver/rlimit.ts +4 -0
  154. package/src/prover/smt/solver/sat/config.ts +1 -1
  155. package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
  156. package/src/prover/smt/solver/sat/inc-sat-solver.ts +39 -5
  157. package/src/prover/smt/solver/sat/model-converter.ts +1 -1
  158. package/src/prover/smt/solver/sat/pb-solver.ts +1 -1
  159. package/src/prover/smt/solver/sat/sat-tactic.ts +13 -5
  160. package/src/prover/smt/solver/sat/simplifier.ts +1 -1
  161. package/src/prover/smt/solver/sat/solver.ts +25 -47
  162. package/src/prover/smt/solver/seq-axioms.ts +20 -35
  163. package/src/prover/smt/solver/seq-decl-plugin.ts +1 -1
  164. package/src/prover/smt/solver/seq-derive.ts +2 -2
  165. package/src/prover/smt/solver/seq-eq-solver.ts +2 -2
  166. package/src/prover/smt/solver/seq-monadic.ts +7 -5
  167. package/src/prover/smt/solver/seq-re-rewriter.ts +2 -1
  168. package/src/prover/smt/solver/seq-re-util.ts +1 -1
  169. package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
  170. package/src/prover/smt/solver/seq-regex-live.ts +2 -2
  171. package/src/prover/smt/solver/seq-rewriter.ts +31 -29
  172. package/src/prover/smt/solver/seq-skolem.ts +0 -23
  173. package/src/prover/smt/solver/seq-view-witness.ts +4 -4
  174. package/src/prover/smt/solver/smt-kernel.ts +39 -5
  175. package/src/prover/smt/solver/smt-setup.ts +96 -10
  176. package/src/prover/smt/solver/smtlib-parser.ts +584 -223
  177. package/src/prover/smt/solver/smtlib-script.ts +509 -154
  178. package/src/prover/smt/solver/solve-eqs.ts +36 -37
  179. package/src/prover/smt/solver/solver.ts +18 -3
  180. package/src/prover/smt/solver/tactic.ts +284 -168
  181. package/src/prover/smt/solver/theory-bv.ts +13 -3
  182. package/src/prover/smt/solver/theory-fpa.ts +1 -1
  183. package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
  184. package/src/prover/smt/solver/theory-lra-internalize.ts +2 -0
  185. package/src/prover/smt/solver/theory-lra-propagate.ts +11 -3
  186. package/src/prover/smt/solver/theory-lra.ts +1 -1
  187. package/src/prover/smt/solver/theory-pb.ts +24 -7
  188. package/src/prover/smt/solver/theory-seq-solve.ts +1 -1
  189. package/src/prover/smt/solver/theory-seq-state.ts +2 -21
  190. package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
  191. package/src/prover/tlapm/cache.ts +8 -8
  192. package/src/prover/zenon/index-table.ts +5 -2
  193. package/src/prover/zenon/isar-case.ts +1 -1
  194. package/src/prover/zenon/isar.ts +2 -2
  195. package/src/prover/zenon/phrase.ts +1 -1
  196. package/src/resolve.ts +959 -243
  197. package/src/runtime.ts +7 -1
  198. package/src/sany/builtins.ts +10 -10
  199. package/src/sany/generation.ts +2 -13
  200. package/src/sany/generator-definitions.ts +3 -1
  201. package/src/sany/generator-expressions.ts +36 -30
  202. package/src/sany/generator-proofs.ts +5 -3
  203. package/src/sany/generator.ts +2 -1
  204. package/src/sany/lexer.ts +3 -3
  205. package/src/sany/modules.ts +4 -2
  206. package/src/sany/nodes.ts +1 -1
  207. package/src/sany/selectors.ts +11 -6
  208. package/src/sany/xml.ts +2 -3
  209. package/src/search.ts +166 -101
  210. package/src/simulate.ts +110 -50
  211. package/src/spec-description.ts +5 -6
  212. package/src/standard-modules.ts +15 -6
  213. package/src/subexpressions.ts +398 -108
  214. package/src/successors.ts +4 -2
  215. package/src/symmetry.ts +1 -1
  216. package/src/tlc/jar-data.ts +10 -0
  217. package/src/tlc/messages.ts +3 -3
  218. package/src/tlc/order.ts +14 -3
  219. package/src/tlc/random.ts +2 -1
  220. package/src/tlc/replay.ts +3 -2
  221. package/src/tlc/tlc-operators.ts +10 -8
  222. package/src/tlc/tlcext-operators.ts +44 -15
  223. package/src/tlc/trace-spec.ts +9 -22
  224. package/src/typed-tier.ts +32 -25
  225. package/src/typescript/types.ts +2 -2
  226. package/src/values.ts +135 -78
@@ -81,7 +81,7 @@ export const findDomain = (type: ts.Type, context: Context): string | Infinite =
81
81
  if (type.isUnion()) {
82
82
  const literals = type.types.map((member) => getLiteral(member, context));
83
83
  const others = findDomains(
84
- type.types.filter((_, index) => literals[index] === undefined),
84
+ type.types.filter((_value, index) => literals[index] === undefined),
85
85
  context,
86
86
  );
87
87
  if (!Array.isArray(others)) return others;
@@ -91,7 +91,7 @@ export const findDomain = (type: ts.Type, context: Context): string | Infinite =
91
91
  isNumericKey(left) && isNumericKey(right) ? Number(left) - Number(right) : 0,
92
92
  );
93
93
  return [...(enumerated.length > 0 ? [`{${enumerated.join(", ")}}`] : []), ...others]
94
- .map((domain, _, domains) => (domains.length > 1 ? wrap(domain) : domain))
94
+ .map((domain, _index, domains) => (domains.length > 1 ? wrap(domain) : domain))
95
95
  .join(" \\cup ");
96
96
  }
97
97
  const literal = getLiteral(type, context);
package/src/values.ts CHANGED
@@ -231,7 +231,7 @@ export const isModelValue = (value: Value): value is ModelValue =>
231
231
  export const isEnumeratedSet = (value: Value): value is SetValue | MixedSetValue =>
232
232
  typeof value === "object" && (value.kind === "Set" || value.kind === "MixedSet");
233
233
 
234
- export const describeKind = (value: Value) => {
234
+ const describeKind = (value: Value) => {
235
235
  if (typeof value === "boolean") return "boolean";
236
236
  if (typeof value === "number") return "integer";
237
237
  if (typeof value === "string") return "string";
@@ -266,8 +266,19 @@ export const getPrintedPairs = (functionValue: FunctionValue): [Value, Value][]
266
266
  ? functionValue.domain.map((key, index) => [key, functionValue.range[index]])
267
267
  : getWrittenPairs(functionValue);
268
268
 
269
- export const createWrittenRecord = (names: Value[], range: Value[], writtenNames: Value[]) =>
270
- setWrittenOrder(createSortedRecord(names, range), writtenNames);
269
+ export const createWrittenRecord = (
270
+ names: Value[],
271
+ writtenIndexes: number[],
272
+ writtenRange: Value[],
273
+ writtenNames: Value[],
274
+ ) =>
275
+ setWrittenOrder(
276
+ createSortedRecord(
277
+ names,
278
+ writtenIndexes.map((index) => writtenRange[index]),
279
+ ),
280
+ writtenNames,
281
+ );
271
282
 
272
283
  const forgetWrittenOrder = (value: Value): void => {
273
284
  if (typeof value !== "object" || (value.kind !== "Function" && value.kind !== "Set")) return;
@@ -339,16 +350,16 @@ const checkModelValueTypes = (left: Value, right: Value, isEquality: boolean) =>
339
350
  if (isModelValue(left) && isModelValue(right)) {
340
351
  if (leftType === undefined || rightType === undefined || leftType === rightType) return;
341
352
  throw new TlaEvaluationError(
342
- `Attempted to ${action} the differently-typed model values ${formatValue(left)} and ${formatValue(right)}`,
353
+ `Attempted to ${action} the differently-typed model values ${prettyPrint(formatValue(left))} and ${prettyPrint(formatValue(right))}`,
343
354
  );
344
355
  }
345
356
  if (leftType !== undefined) {
346
357
  throw new TlaEvaluationError(
347
- `Attempted to ${action}${isEquality ? "" : " the"} typed model value ${formatValue(left)} and non-model value\n${formatValue(right)}`,
358
+ `Attempted to ${action}${isEquality ? "" : " the"} typed model value ${prettyPrint(formatValue(left))} and non-model value\n${prettyPrint(formatValue(right))}`,
348
359
  );
349
360
  }
350
361
  throw new TlaEvaluationError(
351
- `Attempted to ${action} the typed model value ${formatValue(right)} and the non-model value\n${formatValue(left)}`,
362
+ `Attempted to ${action} the typed model value ${prettyPrint(formatValue(right))} and the non-model value\n${prettyPrint(formatValue(left))}`,
352
363
  );
353
364
  };
354
365
 
@@ -453,7 +464,7 @@ const isOverriddenComparison = (left: Value, right: Value) =>
453
464
  const createComparisonError = (left: Value, right: Value) =>
454
465
  new TlaEvaluationError(
455
466
  isOverriddenSet(left)
456
- ? `Attempted to compare overridden value ${formatValue(left, true)} with non-overridden value:\n${formatValue(right)}`
467
+ ? `Attempted to compare overridden value ${prettyPrint(formatValue(left, true))} with non-overridden value:\n${prettyPrint(formatValue(right))}`
457
468
  : `Attempted to compare ${describeKind(left)} ${formatValue(left)} with ${describeKind(right)} ${formatValue(right)}`,
458
469
  );
459
470
 
@@ -464,7 +475,7 @@ const compareOverriddenSets = (
464
475
  ) => {
465
476
  if (!isOverriddenSet(left)) {
466
477
  throw new TlaEvaluationError(
467
- `Attempted to ${verb} the set ${formatValue(isEnumerable(left) ? toFiniteSet(left) : left, true)} with the value:\n${formatValue(right, true)}`,
478
+ `Attempted to ${verb} the set ${prettyPrint(formatValue(isEnumerable(left) ? toFiniteSet(left) : left, true))} with the value:\n${prettyPrint(formatValue(right, true))}`,
468
479
  );
469
480
  }
470
481
  if (!isOverriddenSet(right)) throw createComparisonError(left, right);
@@ -475,14 +486,16 @@ const compareOverriddenSets = (
475
486
  return leftName === "Nat" ? -1 : 1;
476
487
  }
477
488
  throw new TlaModuleError(
478
- `Attempted to compare ${formatValue(left, true)} with the value\n${formatValue(right, true)}`,
489
+ `Attempted to compare ${prettyPrint(formatValue(left, true))} with the value\n${prettyPrint(formatValue(right, true))}`,
479
490
  );
480
491
  };
481
492
 
482
493
  export const ANY_SET: InfiniteSetValue = { kind: "InfiniteSet", name: "Any" };
483
494
 
484
495
  const compareAny = (other: Value): never => {
485
- throw new TlaModuleError(`Attempted to compare ANY with the value\n${formatValue(other)}`);
496
+ throw new TlaModuleError(
497
+ `Attempted to compare ANY with the value\n${prettyPrint(formatValue(other))}`,
498
+ );
486
499
  };
487
500
 
488
501
  const compareWithItself = (value: Value) => {
@@ -863,7 +876,7 @@ const describeScalarMismatch = (
863
876
  SCALAR_KINDS[
864
877
  typeof left === "number" ? "number" : typeof left === "string" ? "string" : "boolean"
865
878
  ];
866
- return `Attempted to ${isEquality ? kind.equality : "compare"} ${kind.name} ${formatValue(left)} with ${kind.other}:\n${formatValue(right)}`;
879
+ return `Attempted to ${isEquality ? kind.equality : "compare"} ${kind.name} ${prettyPrint(formatValue(left))} with ${kind.other}:\n${prettyPrint(formatValue(right))}`;
867
880
  };
868
881
 
869
882
  const getComparisonVerb = (isEquality: boolean) => (isEquality ? "check equality of" : "compare");
@@ -878,7 +891,7 @@ const compareTlcFunctions = (
878
891
  if (!other) {
879
892
  if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
880
893
  throw new TlaEvaluationError(
881
- `Attempted to ${getComparisonVerb(isEquality)} the function ${formatValue(left)} with the value:\n${formatValue(right)}`,
894
+ `Attempted to ${getComparisonVerb(isEquality)} the function ${prettyPrint(formatValue(left))} with the value:\n${prettyPrint(formatValue(right))}`,
882
895
  );
883
896
  }
884
897
  if (functionValue.range.length !== other.range.length)
@@ -899,7 +912,7 @@ const compareTlcFunctions = (
899
912
  const key = keys[index];
900
913
  if (typeof key !== "number") {
901
914
  throw new TlaEvaluationError(
902
- `Attempted to compare ${isEquality ? "an " : ""}integer with non-integer${isEquality || functionValue.low !== undefined ? ":" : ""}\n${formatValue(key)}.`,
915
+ `Attempted to compare ${isEquality ? "an " : ""}integer with non-integer${isEquality || functionValue.low !== undefined ? ":" : ""}\n${prettyPrint(formatValue(key))}.`,
903
916
  );
904
917
  }
905
918
  const difference =
@@ -936,7 +949,7 @@ const compareFunctionLikeTlc = (
936
949
  if (!record) {
937
950
  if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
938
951
  throw new TlaEvaluationError(
939
- `Attempted to ${getComparisonVerb(isEquality)} record:\n${formatValue(left)}\nwith non-record\n${formatValue(right)}`,
952
+ `Attempted to ${getComparisonVerb(isEquality)} record:\n${prettyPrint(formatValue(left))}\nwith non-record\n${prettyPrint(formatValue(right))}`,
940
953
  );
941
954
  }
942
955
  return (
@@ -978,7 +991,7 @@ const compareSetLikeTlc = (left: ObjectValue, right: Value, isEquality: boolean)
978
991
  if (!isSetValue(right)) {
979
992
  if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
980
993
  throw new TlaEvaluationError(
981
- `Attempted to ${getComparisonVerb(isEquality)} the set ${formatValue(left)} with the value:\n${formatValue(right)}`,
994
+ `Attempted to ${getComparisonVerb(isEquality)} the set ${prettyPrint(formatValue(left))} with the value:\n${prettyPrint(formatValue(right))}`,
982
995
  );
983
996
  }
984
997
  const sets = getSetElementsLikeTlc(left, right);
@@ -1057,6 +1070,7 @@ export const markNormalized = (value: Value): void => {
1057
1070
  value.elements.forEach(markNormalized);
1058
1071
  }
1059
1072
  if (value.kind === "Function") {
1073
+ value.writtenKeys = undefined;
1060
1074
  value.domain.forEach(markNormalized);
1061
1075
  value.range.forEach(markNormalized);
1062
1076
  }
@@ -1330,7 +1344,7 @@ const getUnionSet = (set: Value, index: number, union: UnionValue) => {
1330
1344
  throw new TlaEvaluationError(
1331
1345
  index === 0
1332
1346
  ? "Attempted to enumerate UNION(s), but some element of s is nonenumerable."
1333
- : `Attempted to enumerate the nonenumerable set:\n${formatValue(set)}\nwhen enumerating:\n${formatUnion(union)}`,
1347
+ : `Attempted to enumerate the nonenumerable set:\n${prettyPrint(formatValue(set))}\nwhen enumerating:\n${prettyPrint(formatUnion(union))}`,
1334
1348
  );
1335
1349
  };
1336
1350
 
@@ -1530,13 +1544,13 @@ const enumerateSet = (
1530
1544
  if (!isVersion174 && isEmptySet(value)) return [];
1531
1545
  if (isOverriddenSet(value.domain)) {
1532
1546
  throw new TlaEvaluationError(
1533
- `Attempted to enumerate a set of the form [D -> R],but the domain D:\n${formatValue(value.domain)}\ncannot be enumerated.`,
1547
+ `Attempted to enumerate a set of the form [D -> R],but the domain D:\n${prettyPrint(formatValue(value.domain))}\ncannot be enumerated.`,
1534
1548
  );
1535
1549
  }
1536
1550
  const domain = getFunctionDomain(value.domain);
1537
1551
  if ((domain.length > 0 || isVersion174) && isOverriddenSet(value.range)) {
1538
1552
  throw new TlaEvaluationError(
1539
- `Attempted to enumerate a set of the form [D -> R],but the range R:\n${formatValue(value.range)}\ncannot be enumerated.`,
1553
+ `Attempted to enumerate a set of the form [D -> R],but the range R:\n${prettyPrint(formatValue(value.range))}\ncannot be enumerated.`,
1540
1554
  );
1541
1555
  }
1542
1556
  const range = domain.length === 0 ? [] : getElements(value.range);
@@ -1550,7 +1564,7 @@ const enumerateSet = (
1550
1564
  value.sets,
1551
1565
  getElements,
1552
1566
  (set, index) =>
1553
- `Attempted to enumerate a set of the form [l1 : v1, ..., ln : vn],\nbut can't enumerate the value of the \`${value.names[index]}' field:\n${formatValue(set)}`,
1567
+ `Attempted to enumerate a set of the form [l1 : v1, ..., ln : vn],\nbut can't enumerate the value of the \`${value.names[index]}' field:\n${prettyPrint(formatValue(set))}`,
1554
1568
  );
1555
1569
  return getCartesianProduct(fields).map((combination) =>
1556
1570
  createRecord(value.names.map((name, index): [string, Value] => [name, combination[index]])),
@@ -1562,14 +1576,14 @@ const enumerateSet = (
1562
1576
  value.factors,
1563
1577
  getElements,
1564
1578
  (factor, index) =>
1565
- `Attempted to enumerate a set of the form s1 \\X s2 ... \\X sn,\nbut can't enumerate s${index}:\n${formatValue(factor)}`,
1579
+ `Attempted to enumerate a set of the form s1 \\X s2 ... \\X sn,\nbut can't enumerate s${index}:\n${prettyPrint(formatValue(factor))}`,
1566
1580
  );
1567
1581
  return getCartesianProduct(factors).map(createTuple);
1568
1582
  }
1569
1583
  case "FilteredSet":
1570
1584
  if (!isSetValue(value.base) || isOverriddenSet(value.base)) {
1571
1585
  throw new TlaEvaluationError(
1572
- `Attempted to enumerate { x \\in S : p(x) } when S:\n${formatValue(value.base)}\nis not enumerable`,
1586
+ `Attempted to enumerate { x \\in S : p(x) } when S:\n${prettyPrint(formatValue(value.base))}\nis not enumerable`,
1573
1587
  );
1574
1588
  }
1575
1589
  return toFiniteSet(
@@ -1593,12 +1607,12 @@ const enumerateSet = (
1593
1607
  !isTlcEnumerable(value.right)
1594
1608
  ) {
1595
1609
  throw new TlaEvaluationError(
1596
- `Attempted to enumerate S \\cap T when neither S:\n${formatValue(value.left)}\nnor T:\n${formatValue(value.right)}\nis enumerable`,
1610
+ `Attempted to enumerate S \\cap T when neither S:\n${prettyPrint(formatValue(value.left))}\nnor T:\n${prettyPrint(formatValue(value.right))}\nis enumerable`,
1597
1611
  );
1598
1612
  }
1599
1613
  if (value.operator === "\\" && !isTlcEnumerable(value.left)) {
1600
1614
  throw new TlaEvaluationError(
1601
- `Attempted to enumerate S \\ T when S:\n${formatValue(value.left)}\nis not enumerable.`,
1615
+ `Attempted to enumerate S \\ T when S:\n${prettyPrint(formatValue(value.left))}\nis not enumerable.`,
1602
1616
  );
1603
1617
  }
1604
1618
  if (value.operator === "\\cup") {
@@ -1689,7 +1703,7 @@ const openStream = (value: Value): void => {
1689
1703
  const listUnionLikeTlc = (union: SetOperationValue) => {
1690
1704
  if (!isTlcEnumerable(union.left) || !isTlcEnumerable(union.right)) {
1691
1705
  throw new TlaEvaluationError(
1692
- `Attempted to enumerate S \\cup T when S:\n${formatValue(union.left)}\nand T:\n${formatValue(union.right)}\nare not both enumerable`,
1706
+ `Attempted to enumerate S \\cup T when S:\n${prettyPrint(formatValue(union.left))}\nand T:\n${prettyPrint(formatValue(union.right))}\nare not both enumerable`,
1693
1707
  );
1694
1708
  }
1695
1709
  openStream(union.left);
@@ -1827,6 +1841,7 @@ const someElementOfStream = (value: ObjectValue, visit: (element: Value) => bool
1827
1841
 
1828
1842
  export const isEmptySet = (value: Value): boolean => {
1829
1843
  if (typeof value !== "object" || !isSetValue(value)) {
1844
+ setTrace.sets?.push(value);
1830
1845
  throw new TlaEvaluationError(`Shouldn't call isEmpty() on value ${formatValue(value)}`);
1831
1846
  }
1832
1847
  switch (value.kind) {
@@ -1868,18 +1883,18 @@ const getProductCardinality = (
1868
1883
  }, 1);
1869
1884
 
1870
1885
  const describeOverflow = (value: Value) =>
1871
- `Overflow when computing the number of elements in:\n${formatValue(value)}`;
1886
+ `Overflow when computing the number of elements in:\n${prettyPrint(formatValue(value))}`;
1872
1887
 
1873
1888
  export const getCardinality = (value: Value, version?: TlcVersion): number => {
1874
1889
  if (typeof value !== "object") {
1875
1890
  throw new TlaEvaluationError(
1876
- `Attempted to compute the number of elements in the ${describeKind(value)} ${formatValue(value)}.`,
1891
+ `Attempted to compute the number of elements in the ${describeKind(value)} ${prettyPrint(formatValue(value))}.`,
1877
1892
  );
1878
1893
  }
1879
1894
  switch (value.kind) {
1880
1895
  case "ModelValue":
1881
1896
  throw new TlaEvaluationError(
1882
- `Attempted to compute the number of elements in the model value ${formatValue(value)}.`,
1897
+ `Attempted to compute the number of elements in the model value ${prettyPrint(formatValue(value))}.`,
1883
1898
  );
1884
1899
  case "Function":
1885
1900
  return value.domain.length;
@@ -1897,7 +1912,7 @@ export const getCardinality = (value: Value, version?: TlcVersion): number => {
1897
1912
  case "InfiniteSet":
1898
1913
  case "SequenceSet":
1899
1914
  throw new TlaEvaluationError(
1900
- `Attempted to compute the number of elements in the overridden value ${formatValue(value)}.`,
1915
+ `Attempted to compute the number of elements in the overridden value ${prettyPrint(formatValue(value))}.`,
1901
1916
  );
1902
1917
  case "Subset": {
1903
1918
  const size = getCardinality(value.base, version);
@@ -1928,7 +1943,8 @@ export const getCardinality = (value: Value, version?: TlcVersion): number => {
1928
1943
  return getProductCardinality(
1929
1944
  value.factors,
1930
1945
  version,
1931
- () => `Overflow when computing the number of elements in ${formatValue(value)}`,
1946
+ () =>
1947
+ `Overflow when computing the number of elements in ${prettyPrint(formatValue(value))}`,
1932
1948
  );
1933
1949
  default:
1934
1950
  cacheSet(value);
@@ -1937,12 +1953,12 @@ export const getCardinality = (value: Value, version?: TlcVersion): number => {
1937
1953
  };
1938
1954
 
1939
1955
  const describeInfiniteCheck = (value: Value) =>
1940
- `Attempted to check if the set ${formatValue(value)}is finite.`;
1956
+ `Attempted to check if the set ${prettyPrint(formatValue(value))}is finite.`;
1941
1957
 
1942
1958
  export const isFiniteSet = (value: Value): boolean => {
1943
1959
  if (typeof value !== "object" || value.kind === "ModelValue") {
1944
1960
  throw new TlaEvaluationError(
1945
- `Attempted to check if the ${describeKind(value)} ${formatValue(value)} is a finite set.`,
1961
+ `Attempted to check if the ${describeKind(value)} ${prettyPrint(formatValue(value))} is a finite set.`,
1946
1962
  );
1947
1963
  }
1948
1964
  switch (value.kind) {
@@ -1953,7 +1969,7 @@ export const isFiniteSet = (value: Value): boolean => {
1953
1969
  return true;
1954
1970
  case "LazyFunction":
1955
1971
  throw new TlaEvaluationError(
1956
- `Attempted to check if the function:\n${formatValue(value)}\nis a finite set.`,
1972
+ `Attempted to check if the function:\n${prettyPrint(formatValue(value))}\nis a finite set.`,
1957
1973
  );
1958
1974
  case "InfiniteSet":
1959
1975
  return false;
@@ -1999,7 +2015,7 @@ export const isFiniteSet = (value: Value): boolean => {
1999
2015
  case "FilteredSet":
2000
2016
  if (!isFiniteSet(value.base)) {
2001
2017
  throw new TlaEvaluationError(
2002
- `Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${formatValue(value.base)}\nis finite.`,
2018
+ `Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${prettyPrint(formatValue(value.base))}\nis finite.`,
2003
2019
  );
2004
2020
  }
2005
2021
  return true;
@@ -2053,14 +2069,15 @@ export const getSequenceElements = (value: Value): Value[] | undefined => {
2053
2069
  };
2054
2070
 
2055
2071
  const describeNonSetMembership = (element: Value, value: Value) => {
2056
- const prefix = `Attempted to check if the value:\n${formatValue(element)}\nis an element of the`;
2057
- if (!isFunctionValue(value)) return `${prefix} ${describeKind(value)} ${formatValue(value)}`;
2072
+ const prefix = `Attempted to check if the value:\n${prettyPrint(formatValue(element))}\nis an element of the`;
2073
+ if (!isFunctionValue(value))
2074
+ return `${prefix} ${describeKind(value)} ${prettyPrint(formatValue(value))}`;
2058
2075
  const functionClass = getFunctionClass(value);
2059
2076
  if (functionClass === "record") {
2060
- return `Attempted to check if element:\n${formatValue(element)}\nis in the record:\n${formatValue(value)}`;
2077
+ return `Attempted to check if element:\n${prettyPrint(formatValue(element))}\nis in the record:\n${prettyPrint(formatValue(value))}`;
2061
2078
  }
2062
2079
  if (functionClass === "tuple") return "Attempted to check set membership in a tuple value.";
2063
- return `${prefix} function ${formatValue(value)}`;
2080
+ return `${prefix} function ${prettyPrint(formatValue(value))}`;
2064
2081
  };
2065
2082
 
2066
2083
  interface TracedCallStack {
@@ -2166,7 +2183,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
2166
2183
  if (typeof element === "number") return element >= set.low && element <= set.high;
2167
2184
  if (set.low <= set.high && (!isModelValue(element) || element.type !== undefined)) {
2168
2185
  throw new TlaEvaluationError(
2169
- `Attempted to check if the value:\n${formatValue(element)}\nis in the integer interval ${formatValue(set)}`,
2186
+ `Attempted to check if the value:\n${prettyPrint(formatValue(element))}\nis in the integer interval ${prettyPrint(formatValue(set))}`,
2170
2187
  );
2171
2188
  }
2172
2189
  return false;
@@ -2177,7 +2194,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
2177
2194
  set.name === "STRING" ? typeof element === "string" : typeof element === "number";
2178
2195
  if (!isMemberType) {
2179
2196
  throw new TlaModuleError(
2180
- `Attempted to check if the value:\n${formatValue(element)}\nis an element of ${set.name}.`,
2197
+ `Attempted to check if the value:\n${prettyPrint(formatValue(element))}\nis an element of ${set.name}.`,
2181
2198
  );
2182
2199
  }
2183
2200
  return set.name !== "Nat" || (typeof element === "number" && element >= 0);
@@ -2212,7 +2229,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
2212
2229
  if (!functionValue || !isRecordDomain(functionValue.domain)) {
2213
2230
  if (isModelValue(element)) return isModelValueMember(element, set);
2214
2231
  throw new TlaEvaluationError(
2215
- `Attempted to check if non-record\n${formatValue(element)}\nis in the set of records:\n${formatValue(set)}`,
2232
+ `Attempted to check if non-record\n${formatValue(element)}\nis in the set of records:\n${prettyPrint(formatValue(set))}`,
2216
2233
  );
2217
2234
  }
2218
2235
  return (
@@ -2232,7 +2249,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
2232
2249
  if (isModelValue(element)) return isModelValueMember(element, set);
2233
2250
  if (isFunction) return false;
2234
2251
  throw new TlaEvaluationError(
2235
- `Attempted to check if non-tuple\n${formatValue(element)}\nis in the set of tuples:\n${formatValue(set)}`,
2252
+ `Attempted to check if non-tuple\n${prettyPrint(formatValue(element))}\nis in the set of tuples:\n${prettyPrint(formatValue(set))}`,
2236
2253
  );
2237
2254
  }
2238
2255
  return (
@@ -2252,7 +2269,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
2252
2269
  case "Union": {
2253
2270
  if (!isTlcEnumerable(set.base)) {
2254
2271
  throw new TlaEvaluationError(
2255
- `Attempted to check if:\n ${formatValue(element)}\nis an element of the non-enumerable set:\n ${formatUnion(set)}`,
2272
+ `Attempted to check if:\n ${prettyPrint(formatValue(element))}\nis an element of the non-enumerable set:\n ${prettyPrint(formatUnion(set))}`,
2256
2273
  );
2257
2274
  }
2258
2275
  const sets = toFiniteSet(set.base).elements;
@@ -2311,12 +2328,9 @@ export const toFiniteFunction = (value: Value): FunctionValue => {
2311
2328
  throw new TlaEvaluationError("The domains of formal parameters must be enumerable.");
2312
2329
  }
2313
2330
  const domain = getFunctionDomain(value.domain);
2314
- value.enumerated = setFunctionClass(
2315
- createSortedFunction(
2316
- domain,
2317
- domain.map((key) => value.apply(key)),
2318
- ),
2319
- getFunctionClass(value),
2331
+ value.enumerated = createSortedFunction(
2332
+ domain,
2333
+ domain.map((key) => value.apply(key)),
2320
2334
  );
2321
2335
  return value.enumerated;
2322
2336
  }
@@ -2425,6 +2439,24 @@ const findKeyIndexLikeTlc = (
2425
2439
  return computeLikeTlcOnFailure(findDomainIndex, failKeyLikeTlc, functionValue, argument);
2426
2440
  };
2427
2441
 
2442
+ const describeBoundArgument = (
2443
+ functionValue: LazyFunctionValue,
2444
+ position: string,
2445
+ shown: Value,
2446
+ problem: string,
2447
+ ) =>
2448
+ `In applying the function\n${prettyPrint(formatValue(functionValue))},\nthe ${position} is:\n${prettyPrint(formatValue(shown))}\nwhich ${problem}.\n`;
2449
+
2450
+ const createArgumentListError = (functionValue: LazyFunctionValue, argument: Value) =>
2451
+ new TlaEvaluationError(
2452
+ describeBoundArgument(
2453
+ functionValue,
2454
+ "argument list",
2455
+ argument,
2456
+ "does not match its formal parameter",
2457
+ ),
2458
+ );
2459
+
2428
2460
  // Deviation from TLC: FcnLambdaValue#apply indexes past an argument tuple shorter than the bounds and ignores a longer one, where this rejects the list.
2429
2461
  const checkBoundArguments = (
2430
2462
  functionValue: LazyFunctionValue,
@@ -2433,25 +2465,20 @@ const checkBoundArguments = (
2433
2465
  ) => {
2434
2466
  const domain = functionValue.domain;
2435
2467
  const elements = getSequenceElements(argument);
2436
- const describe = (position: string, shown: Value, problem: string) =>
2437
- `In applying the function\n${prettyPrint(formatValue(functionValue))},\nthe ${position} is:\n${prettyPrint(formatValue(shown))}\nwhich ${problem}.\n`;
2438
- const createListError = () =>
2439
- new TlaEvaluationError(
2440
- describe("argument list", argument, "does not match its formal parameter"),
2441
- );
2442
- if (elements === undefined) throw createListError();
2468
+ if (elements === undefined) throw createArgumentListError(functionValue, argument);
2443
2469
  if (typeof domain !== "object" || domain.kind !== "ProductSet") {
2444
2470
  throw new TlaEvaluationError(
2445
2471
  `Attempted to apply a function to ${formatValue(argument)}, which is not in its domain`,
2446
2472
  );
2447
2473
  }
2448
2474
  tupleLengths.forEach((tupleLength, index) => {
2449
- if (index >= elements.length) throw createListError();
2475
+ if (index >= elements.length) throw createArgumentListError(functionValue, argument);
2450
2476
  const element = elements[index];
2451
2477
  const position = `argument number ${index + 1}`;
2452
2478
  if (!isElementOf(element, domain.factors[index])) {
2453
2479
  throw new TlaEvaluationError(
2454
- describe(
2480
+ describeBoundArgument(
2481
+ functionValue,
2455
2482
  position,
2456
2483
  element,
2457
2484
  tupleLength === undefined
@@ -2462,11 +2489,18 @@ const checkBoundArguments = (
2462
2489
  }
2463
2490
  if (tupleLength !== undefined && getSequenceElements(element)?.length !== tupleLength) {
2464
2491
  throw new TlaEvaluationError(
2465
- describe(position, element, "does not match its formal parameter"),
2492
+ describeBoundArgument(
2493
+ functionValue,
2494
+ position,
2495
+ element,
2496
+ "does not match its formal parameter",
2497
+ ),
2466
2498
  );
2467
2499
  }
2468
2500
  });
2469
- if (elements.length > tupleLengths.length) throw createListError();
2501
+ if (elements.length > tupleLengths.length) {
2502
+ throw createArgumentListError(functionValue, argument);
2503
+ }
2470
2504
  };
2471
2505
 
2472
2506
  const isOutsideLambdaDomain = (functionValue: FunctionValue, argument: Value) =>
@@ -2544,6 +2578,12 @@ export const updateFunction = (
2544
2578
  functionValue.kind === "LazyFunction" &&
2545
2579
  (isKeptLazy || functionValue.enumerated === undefined);
2546
2580
  if (isLazy) {
2581
+ if (
2582
+ functionValue.boundTupleLengths !== undefined &&
2583
+ getSequenceElements(argument) === undefined
2584
+ ) {
2585
+ throw createArgumentListError(functionValue, argument);
2586
+ }
2547
2587
  if (!isElementOf(argument, functionValue.domain)) return functionValue;
2548
2588
  const updated = update(functionValue.apply(argument));
2549
2589
  return setFunctionClass<LazyFunctionValue>(
@@ -2657,7 +2697,7 @@ const fingerprintValue = (value: Value): void => {
2657
2697
  if (typeof value !== "object" || value.kind === "ModelValue") return;
2658
2698
  if (value.kind === "InfiniteSet" || value.kind === "SequenceSet") {
2659
2699
  throw new TlaEvaluationError(
2660
- `TLC has found a state in which the value of a variable contains ${formatValue(value)}`,
2700
+ `TLC has found a state in which the value of a variable contains ${prettyPrint(formatValue(value))}`,
2661
2701
  );
2662
2702
  }
2663
2703
  if (isSetValue(value)) {
@@ -2897,56 +2937,73 @@ const toPrintedFunction = (value: LazyFunctionValue) => {
2897
2937
 
2898
2938
  export const formatNormalizedCopies = (values: Value[]) => {
2899
2939
  const markedSets: SetValue[] = [];
2900
- const normalize = (value: Value): void => {
2940
+ const writtenFunctions: [FunctionValue, Value[]][] = [];
2941
+ const copiedFunctions: LazyFunctionValue[] = [];
2942
+ // TLC prints a deep copy, which copies functions but shares sets, so it caches only the functions inside a set.
2943
+ const normalize = (value: Value, isWrittenOrderKept: boolean, isCopied: boolean): void => {
2901
2944
  if (typeof value !== "object") return;
2945
+ const normalizeInner = (inner: Value) => normalize(inner, isWrittenOrderKept, false);
2902
2946
  switch (value.kind) {
2903
2947
  case "Set":
2904
- value.elements.forEach(normalize);
2948
+ value.elements.forEach(normalizeInner);
2905
2949
  if (value.isNormalized) return;
2906
2950
  value.isNormalized = true;
2907
2951
  markedSets.push(value);
2908
2952
  return;
2909
2953
  case "MixedSet":
2910
- value.elements.forEach(normalize);
2954
+ value.elements.forEach(normalizeInner);
2911
2955
  toFiniteSet(value);
2912
2956
  return;
2913
- case "Function":
2914
- value.range.forEach(normalize);
2957
+ case "Function": {
2958
+ const isRangeWrittenOrderKept = isWrittenOrderKept || getFunctionClass(value) === "lambda";
2959
+ value.range.forEach((inner) => normalize(inner, isRangeWrittenOrderKept, isCopied));
2960
+ if (isWrittenOrderKept || value.writtenKeys === undefined) return;
2961
+ writtenFunctions.push([value, value.writtenKeys]);
2962
+ value.writtenKeys = undefined;
2915
2963
  return;
2964
+ }
2916
2965
  case "LazyFunction":
2917
- normalize(value.enumerated ?? value.domain);
2966
+ if (value.enumerated) return normalize(value.enumerated, true, isCopied);
2967
+ if (isCopied) copiedFunctions.push(value);
2968
+ normalizeInner(value.domain);
2918
2969
  return;
2919
2970
  case "SetOperation":
2920
- normalize(value.left);
2921
- normalize(value.right);
2971
+ normalizeInner(value.left);
2972
+ normalizeInner(value.right);
2922
2973
  return;
2923
2974
  case "FunctionSet":
2924
- normalize(value.domain);
2925
- normalize(value.range);
2975
+ normalizeInner(value.domain);
2976
+ normalizeInner(value.range);
2926
2977
  return;
2927
2978
  case "RecordSet":
2928
- value.sets.forEach(normalize);
2979
+ value.sets.forEach(normalizeInner);
2929
2980
  return;
2930
2981
  case "ProductSet":
2931
- value.factors.forEach(normalize);
2982
+ value.factors.forEach(normalizeInner);
2932
2983
  return;
2933
2984
  case "Subset":
2934
2985
  case "Union":
2935
2986
  case "FilteredSet":
2936
2987
  case "SequenceSet":
2937
- normalize(value.base);
2988
+ normalizeInner(value.base);
2938
2989
  return;
2939
2990
  default:
2940
2991
  return;
2941
2992
  }
2942
2993
  };
2943
2994
  try {
2944
- values.forEach(normalize);
2995
+ values.forEach((value) => normalize(value, false, true));
2945
2996
  return values.map((value) => formatValue(value, true, true));
2946
2997
  } finally {
2947
2998
  markedSets.forEach((set) => {
2948
2999
  set.isNormalized = false;
2949
3000
  });
3001
+ copiedFunctions.forEach((copied) => {
3002
+ copied.enumerated = undefined;
3003
+ });
3004
+ writtenFunctions.forEach((entry) => {
3005
+ entry[0].writtenKeys = entry[1];
3006
+ });
2950
3007
  }
2951
3008
  };
2952
3009
 
@@ -3092,10 +3149,10 @@ export const formatState = (state: Record<string, Value>, previous?: Record<stri
3092
3149
  );
3093
3150
  }
3094
3151
  return entries
3095
- .filter(([name]) => !(isFormatted && name === "_format"))
3096
- .filter(([name, value]) => !previous || !isUnchanged(previous[name], value))
3097
- .map(([name, value]) => {
3098
- const text = formatJava(format, [name, prettyPrint(formatValue(value))]);
3152
+ .filter((entry) => !(isFormatted && entry[0] === "_format"))
3153
+ .filter((entry) => !previous || !isUnchanged(previous[entry[0]], entry[1]))
3154
+ .map((entry) => {
3155
+ const text = formatJava(format, [entry[0], prettyPrint(formatValue(entry[1]))]);
3099
3156
  if (text === undefined) {
3100
3157
  throw new TlaAliasFormatError(
3101
3158
  `The _format field of the ALIAS ${alias} is ${formatValue(format)}, but it must format two strings, the name and the value of a field.`,