tla-ts 0.0.4-dev.b254db0 → 0.0.4-dev.ca40dfe

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 (207) hide show
  1. package/README.md +31 -10
  2. package/dist/cli.cjs +1 -1
  3. package/dist/cli.js +1 -1
  4. package/dist/deciders.cjs +27 -27
  5. package/dist/deciders.js +34 -34
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +12 -14
  8. package/dist/index.d.ts +12 -14
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +37 -27
  15. package/dist/prove.js +39 -29
  16. package/dist/run.cjs +45 -0
  17. package/dist/run.js +45 -0
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +76 -86
  21. package/dist/transfer.js +73 -83
  22. package/dist/worker.cjs +6 -6
  23. package/dist/worker.js +6 -6
  24. package/package.json +1 -1
  25. package/src/ast.ts +2 -2
  26. package/src/bags.ts +22 -23
  27. package/src/builtins.ts +16 -8
  28. package/src/check.ts +131 -1154
  29. package/src/{cli-options.ts → cli/options.ts} +54 -9
  30. package/src/cli/run.ts +63 -0
  31. package/src/cli/shared.ts +106 -0
  32. package/src/cli/tlapm.ts +374 -0
  33. package/src/cli/tlc.ts +941 -0
  34. package/src/cli/xml-exporter.ts +221 -0
  35. package/src/cli.ts +1 -1
  36. package/src/codegen.ts +17 -15
  37. package/src/config.ts +5 -5
  38. package/src/dependencies.ts +4 -6
  39. package/src/environment.ts +55 -60
  40. package/src/errors.ts +12 -36
  41. package/src/evaluate.ts +81 -101
  42. package/src/exit-codes.ts +1 -1
  43. package/src/fingerprints.ts +3 -3
  44. package/src/instances.ts +56 -46
  45. package/src/java-overrides.ts +79 -41
  46. package/src/json.ts +31 -36
  47. package/src/levels.ts +10 -13
  48. package/src/{live-check.ts → liveness-checker.ts} +169 -142
  49. package/src/liveness.ts +38 -34
  50. package/src/obligations/action.ts +9 -45
  51. package/src/obligations/{anon.ts → anonymize.ts} +13 -25
  52. package/src/obligations/equality.ts +260 -0
  53. package/src/obligations/expression.ts +42 -517
  54. package/src/obligations/generate.ts +88 -778
  55. package/src/obligations/index.ts +20 -22
  56. package/src/obligations/levels.ts +36 -41
  57. package/src/obligations/module.ts +88 -708
  58. package/src/obligations/normalize.ts +554 -0
  59. package/src/obligations/operators.ts +176 -0
  60. package/src/obligations/pragma.ts +21 -15
  61. package/src/obligations/printer.ts +81 -188
  62. package/src/obligations/proof.ts +0 -1
  63. package/src/obligations/regroup.ts +100 -0
  64. package/src/obligations/simplify.ts +668 -0
  65. package/src/obligations/source.ts +25 -131
  66. package/src/obligations/{deref.ts → subexpression.ts} +48 -56
  67. package/src/obligations/substitution.ts +261 -0
  68. package/src/obligations/temporal.ts +28 -26
  69. package/src/obligations/tuples.ts +37 -53
  70. package/src/parallel-worker.ts +37 -33
  71. package/src/parallel.ts +30 -24
  72. package/src/parser.ts +67 -74
  73. package/src/{pcal-ast.ts → pcal/ast.ts} +2 -17
  74. package/src/{pcal-parse.ts → pcal/parse.ts} +28 -64
  75. package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +10 -39
  76. package/src/{pcal-translate.ts → pcal/translate.ts} +30 -109
  77. package/src/{pcal-validate.ts → pcal/validate.ts} +10 -20
  78. package/src/prove/decide-pool.ts +7 -12
  79. package/src/{obligations/pickle.ts → prove/first-order.ts} +79 -2
  80. package/src/prove/isabelle/decide.ts +3 -6
  81. package/src/prove/isabelle/encode.ts +35 -93
  82. package/src/prove/isabelle/isar/inner-syntax.ts +1 -1
  83. package/src/prove/isabelle/isar/method.ts +3 -3
  84. package/src/prove/isabelle/isar/type-check.ts +1 -1
  85. package/src/prove/isabelle/provers/blast/blast.ts +1 -1
  86. package/src/prove/isabelle/provers/blast/branch.ts +1 -1
  87. package/src/prove/isabelle/provers/blast/term.ts +3 -4
  88. package/src/prove/isabelle/provers/clasimp.ts +1 -1
  89. package/src/prove/isabelle/provers/classical.ts +3 -3
  90. package/src/prove/isabelle/provers/hypsubst.ts +1 -9
  91. package/src/prove/isabelle/pure/conv.ts +1 -1
  92. package/src/prove/isabelle/pure/drule.ts +2 -2
  93. package/src/prove/isabelle/pure/envir.ts +3 -35
  94. package/src/prove/isabelle/pure/logic.ts +4 -76
  95. package/src/prove/isabelle/pure/name.ts +1 -13
  96. package/src/prove/isabelle/pure/net.ts +2 -49
  97. package/src/prove/isabelle/pure/pattern.ts +3 -22
  98. package/src/prove/isabelle/pure/raw-simplifier.ts +3 -18
  99. package/src/prove/isabelle/pure/seq.ts +0 -23
  100. package/src/prove/isabelle/pure/simplifier.ts +2 -8
  101. package/src/prove/isabelle/pure/table.ts +1 -8
  102. package/src/prove/isabelle/pure/tactic.ts +5 -113
  103. package/src/prove/isabelle/pure/tactical.ts +1 -84
  104. package/src/prove/isabelle/pure/term-ord.ts +1 -55
  105. package/src/prove/isabelle/pure/term.ts +8 -128
  106. package/src/prove/isabelle/pure/thm.ts +4 -27
  107. package/src/prove/isabelle/pure/type.ts +0 -12
  108. package/src/prove/isabelle/pure/unify.ts +1 -1
  109. package/src/prove/isabelle/tla/classical-setup.ts +1 -1
  110. package/src/prove/ocaml.ts +1 -1
  111. package/src/prove/prep/action.ts +23 -36
  112. package/src/prove/prep/enabled-axioms.ts +2 -2
  113. package/src/prove/prep/fingerprint.ts +3 -3
  114. package/src/prove/prep/level-comparison.ts +9 -37
  115. package/src/prove/prep/md5.ts +2 -9
  116. package/src/prove/prep/normalize.ts +309 -0
  117. package/src/prove/prove-worker.ts +2 -5
  118. package/src/prove/prove.ts +98 -111
  119. package/src/prove/ptl/encode.ts +19 -31
  120. package/src/prove/smt/axioms.ts +45 -58
  121. package/src/prove/smt/encode.ts +124 -15
  122. package/src/prove/smt/instances.ts +2 -3
  123. package/src/prove/smt/rewrite.ts +24 -31
  124. package/src/prove/smt/solver/ast-util.ts +0 -56
  125. package/src/prove/smt/solver/case-split-queue.ts +1 -1
  126. package/src/prove/smt/solver/enode.ts +1 -1
  127. package/src/prove/smt/solver/lp/dep-intervals.ts +0 -14
  128. package/src/prove/smt/solver/model-macro-solver.ts +1 -1
  129. package/src/prove/smt/solver/nlsat/algebraic.ts +3 -3
  130. package/src/prove/smt/solver/nlsat/atoms.ts +1 -1
  131. package/src/prove/smt/solver/nlsat/explain.ts +1 -1
  132. package/src/prove/smt/solver/nlsat/interval-set.ts +1 -1
  133. package/src/prove/smt/solver/nlsat/levelwise.ts +4 -7
  134. package/src/prove/smt/solver/nlsat/polynomial.ts +4 -4
  135. package/src/prove/smt/solver/nlsat/upolynomial.ts +2 -2
  136. package/src/prove/smt/solver/pattern-inference.ts +1 -1
  137. package/src/prove/smt/solver/relevancy.ts +2 -2
  138. package/src/prove/smt/solver/rewriter.ts +1 -1
  139. package/src/prove/smt/solver/solver.ts +2 -2
  140. package/src/{tlapm-cache.ts → prove/tlapm/cache.ts} +11 -11
  141. package/src/{ocaml-marshal.ts → prove/tlapm/ocaml-marshal.ts} +1 -1
  142. package/src/prove/verdict.ts +0 -5
  143. package/src/prove/zenon/decide.ts +5 -11
  144. package/src/prove/zenon/encode.ts +21 -80
  145. package/src/prove/zenon/eqrel.ts +1 -1
  146. package/src/prove/zenon/equality-rules.ts +1 -1
  147. package/src/prove/zenon/expr.ts +2 -2
  148. package/src/prove/zenon/index-table.ts +1 -1
  149. package/src/prove/zenon/isar.ts +1 -1
  150. package/src/prove/zenon/llproof.ts +1 -1
  151. package/src/prove/zenon/mltoll.ts +1 -1
  152. package/src/prove/zenon/node.ts +1 -1
  153. package/src/prove/zenon/search.ts +1 -1
  154. package/src/prove/zenon/tla/terms.ts +1 -20
  155. package/src/prove/zenon/tla/tla.ts +1 -1
  156. package/src/randomization.ts +19 -24
  157. package/src/resolve.ts +15 -22
  158. package/src/runtime.ts +8 -8
  159. package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
  160. package/src/{sany-generator.ts → sany/generator.ts} +38 -55
  161. package/src/{sany-levels.ts → sany/levels.ts} +45 -48
  162. package/src/{sany-lexer.ts → sany/lexer.ts} +2 -3
  163. package/src/{sany-linter.ts → sany/linter.ts} +1 -1
  164. package/src/{sany-modules.ts → sany/modules.ts} +2 -2
  165. package/src/{sany-nodes.ts → sany/nodes.ts} +2 -2
  166. package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
  167. package/src/{sany-report.ts → sany/report.ts} +16 -17
  168. package/src/{sany-selectors.ts → sany/selectors.ts} +3 -5
  169. package/src/{sany-source.ts → sany/source.ts} +6 -7
  170. package/src/{sany-xml.ts → sany/xml.ts} +5 -6
  171. package/src/search.ts +969 -0
  172. package/src/spec-description.ts +26 -20
  173. package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
  174. package/src/standard-modules.ts +16 -20
  175. package/src/state-graph.ts +9 -8
  176. package/src/substitution-levels.ts +2 -2
  177. package/src/successors.ts +16 -19
  178. package/src/symmetry.ts +1 -1
  179. package/src/tableau.ts +6 -7
  180. package/src/tlc/fingerprint.ts +214 -0
  181. package/src/{tlc-messages.ts → tlc/messages.ts} +119 -7
  182. package/src/{tlc-order.ts → tlc/order.ts} +7 -7
  183. package/src/{tlc-random.ts → tlc/random.ts} +3 -213
  184. package/src/{tlc-replay.ts → tlc/replay.ts} +40 -36
  185. package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
  186. package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +30 -25
  187. package/src/transfer.ts +32 -32
  188. package/src/values.ts +72 -67
  189. package/src/worker.ts +1 -4
  190. package/dist/run-cli.cjs +0 -45
  191. package/dist/run-cli.js +0 -45
  192. package/src/canonical.ts +0 -40
  193. package/src/obligations/ctx.ts +0 -64
  194. package/src/prove/prep/defs.ts +0 -33
  195. package/src/prove/prep/elab.ts +0 -156
  196. package/src/prove/prep/enabled.ts +0 -43
  197. package/src/prove/prep/flatten.ts +0 -70
  198. package/src/prove/prep/trivial.ts +0 -22
  199. package/src/prove/smt/axiomatize.ts +0 -69
  200. package/src/prove/smt/simplify.ts +0 -57
  201. package/src/run-cli.ts +0 -1806
  202. package/src/standard-ranges.ts +0 -116
  203. package/src/value-sources.ts +0 -29
  204. /package/src/prove/prep/{pragma.ts → methods.ts} +0 -0
  205. /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
  206. /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
  207. /package/src/{tlc-version.ts → tlc/version.ts} +0 -0
package/src/values.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { TlaEvaluationError, TlaModuleError } from "./errors";
1
+ import { TlaEvaluationError } from "./errors";
2
2
  import { prettyPrint } from "./pretty-print";
3
- import type { TlcVersion } from "./tlc-version";
3
+ import type { TlcVersion } from "./tlc/version";
4
4
 
5
5
  export interface ModelValue {
6
6
  kind: "ModelValue";
@@ -161,6 +161,9 @@ export const isFunctionValue = (value: Value): value is FunctionValue | LazyFunc
161
161
  export const isModelValue = (value: Value): value is ModelValue =>
162
162
  typeof value === "object" && value.kind === "ModelValue";
163
163
 
164
+ export const isEnumeratedSet = (value: Value): value is SetValue | MixedSetValue =>
165
+ typeof value === "object" && (value.kind === "Set" || value.kind === "MixedSet");
166
+
164
167
  export const describeKind = (value: Value) => {
165
168
  if (typeof value === "boolean") return "boolean";
166
169
  if (typeof value === "number") return "integer";
@@ -169,12 +172,8 @@ export const describeKind = (value: Value) => {
169
172
  return isSetValue(value) ? "set" : "function";
170
173
  };
171
174
 
172
- export const checkInteger = (value: number) => {
173
- if (!Number.isInteger(value) || value > MAXIMUM_INTEGER || value < MINIMUM_INTEGER) {
174
- throw new TlaModuleError(`Integer overflow: ${value} is outside TLC's 32-bit range`);
175
- }
176
- return value;
177
- };
175
+ export const isTlcInteger = (value: number) =>
176
+ Number.isInteger(value) && value <= MAXIMUM_INTEGER && value >= MINIMUM_INTEGER;
178
177
 
179
178
  // TLC keeps a record, or a function with string keys that @@ builds, in the order the spec writes
180
179
  // it until it sorts the value to compare or fingerprint it. ToString, Assert, and error messages
@@ -189,7 +188,7 @@ const setWrittenOrder = (functionValue: FunctionValue, keys: Value[]) => {
189
188
 
190
189
  export const getWrittenPairs = (functionValue: FunctionValue): [Value, Value][] => {
191
190
  const keys = functionValue.writtenKeys ?? functionValue.domain;
192
- return keys.map((key) => [key, functionValue.range[findIndex(functionValue.domain, key)]]);
191
+ return keys.map((key) => [key, functionValue.range[findSortedIndex(functionValue.domain, key)]]);
193
192
  };
194
193
 
195
194
  export const createWrittenRecord = (names: Value[], range: Value[], writtenNames: Value[]) =>
@@ -422,7 +421,7 @@ export const compareValues = (left: Value, right: Value): number => {
422
421
 
423
422
  const modelValues = new Map<string, ModelValue>();
424
423
 
425
- // A check ranks every model value's name when it creates the value, and creates its own values.
424
+ // setStringOrder clears the model values, so each check ranks and creates its own.
426
425
  export const createModelValue = (name: string): ModelValue => {
427
426
  const known = modelValues.get(name);
428
427
  if (known) return known;
@@ -544,9 +543,6 @@ export const markFingerprinted = (value: Value): void => {
544
543
  }
545
544
  };
546
545
 
547
- export const createSortedRecord = (names: Value[], range: Value[]) =>
548
- setFunctionClass(createSortedFunction(names, range), "record");
549
-
550
546
  export const valuesEqual = (left: Value, right: Value): boolean => {
551
547
  cacheSet(left);
552
548
  if (left === right) {
@@ -655,7 +651,48 @@ const createSameValueCheck = (isClassSensitive: boolean) => {
655
651
 
656
652
  export const isSameValue = createSameValueCheck(false);
657
653
 
658
- export const isInterchangeableValue = createSameValueCheck(true);
654
+ const isInterchangeableValue = createSameValueCheck(true);
655
+
656
+ const canonicalizeElements = (elements: Value[], canonicalize: (value: Value) => Value) => {
657
+ for (let index = 0; index < elements.length; index++) {
658
+ elements[index] = canonicalize(elements[index]);
659
+ }
660
+ };
661
+
662
+ // Replaces each set and function in a state with the first interchangeable one it has seen, so that
663
+ // the states it keeps share their values.
664
+ export const createCanonicalizer = () => {
665
+ const canonicalValues = new Map<number, Value | Value[]>();
666
+ const canonicalize = (value: Value): Value => {
667
+ if (typeof value !== "object" || (value.kind !== "Set" && value.kind !== "Function")) {
668
+ return value;
669
+ }
670
+ const hash = getValueHash(value);
671
+ const bucket = canonicalValues.get(hash);
672
+ if (bucket !== undefined && !Array.isArray(bucket)) {
673
+ if (bucket === value || isInterchangeableValue(bucket, value)) return bucket;
674
+ }
675
+ if (Array.isArray(bucket)) {
676
+ for (let index = 0; index < bucket.length; index++) {
677
+ if (bucket[index] === value || isInterchangeableValue(bucket[index], value))
678
+ return bucket[index];
679
+ }
680
+ }
681
+ if (value.kind === "Set") canonicalizeElements(value.elements, canonicalize);
682
+ else {
683
+ canonicalizeElements(value.domain, canonicalize);
684
+ canonicalizeElements(value.range, canonicalize);
685
+ }
686
+ if (bucket === undefined) canonicalValues.set(hash, value);
687
+ else if (Array.isArray(bucket)) bucket.push(value);
688
+ else canonicalValues.set(hash, [bucket, value]);
689
+ return value;
690
+ };
691
+ return (state: Value[]) => {
692
+ for (let index = 0; index < state.length; index++) state[index] = canonicalize(state[index]);
693
+ return state;
694
+ };
695
+ };
659
696
 
660
697
  // The comparisons above fail with their own messages. These follow the compareTo and equals
661
698
  // methods of TLC's Java value classes, which word a failure by the class of the left operand, so a
@@ -689,56 +726,25 @@ const toTlcRecord = (value: Value) => {
689
726
  return functionValue.domain.every((key) => typeof key === "string") ? functionValue : undefined;
690
727
  };
691
728
 
729
+ // A model value compared with a value of another kind. The other value is never a model value.
692
730
  const compareModelValueWith = (modelValue: ModelValue, other: Value) => {
693
- if (getModelValueType(modelValue) !== undefined) {
694
- throw new TlaEvaluationError(
695
- `Attempted to compare the typed model value ${formatValue(modelValue)} and the non-model value\n${formatValue(other)}`,
696
- );
697
- }
731
+ checkModelValueTypes(other, modelValue, false);
698
732
  return 1;
699
733
  };
700
734
 
701
735
  const equalsModelValueWith = (modelValue: ModelValue, other: Value) => {
702
- if (getModelValueType(modelValue) !== undefined) {
703
- throw new TlaEvaluationError(
704
- `Attempted to check equality of the typed model value ${formatValue(modelValue)} and the non-model value\n${formatValue(other)}`,
705
- );
706
- }
736
+ checkModelValueTypes(other, modelValue, true);
707
737
  return false;
708
738
  };
709
739
 
710
740
  const compareModelValue = (left: ModelValue, right: Value) => {
711
- const type = getModelValueType(left);
712
- if (type === undefined) return isModelValue(right) ? left.rank - right.rank : -1;
713
- if (!isModelValue(right)) {
714
- throw new TlaEvaluationError(
715
- `Attempted to compare the typed model value ${formatValue(left)} and non-model value\n${formatValue(right)}`,
716
- );
717
- }
718
- const otherType = getModelValueType(right);
719
- if (otherType !== undefined && otherType !== type) {
720
- throw new TlaEvaluationError(
721
- `Attempted to compare the differently-typed model values ${formatValue(left)} and ${formatValue(right)}`,
722
- );
723
- }
724
- return left.rank - right.rank;
741
+ if (left.type !== undefined) checkModelValueTypes(left, right, false);
742
+ return isModelValue(right) ? left.rank - right.rank : -1;
725
743
  };
726
744
 
727
745
  const equalsModelValue = (left: ModelValue, right: Value) => {
728
- const type = getModelValueType(left);
729
- if (type === undefined) return isModelValue(right) && left.name === right.name;
730
- if (!isModelValue(right)) {
731
- throw new TlaEvaluationError(
732
- `Attempted to check equality of typed model value ${formatValue(left)} and non-model value\n${formatValue(right)}`,
733
- );
734
- }
735
- const otherType = getModelValueType(right);
736
- if (otherType !== undefined && otherType !== type) {
737
- throw new TlaEvaluationError(
738
- `Attempted to check equality of the differently-typed model values ${formatValue(left)} and ${formatValue(right)}`,
739
- );
740
- }
741
- return left.name === right.name;
746
+ if (left.type !== undefined) checkModelValueTypes(left, right, true);
747
+ return isModelValue(right) && left.name === right.name;
742
748
  };
743
749
 
744
750
  const SCALAR_KINDS = {
@@ -833,9 +839,6 @@ const compareFunctionLikeTlc = (left: FunctionValue | LazyFunctionValue, right:
833
839
  );
834
840
  };
835
841
 
836
- export const isEnumeratedSet = (value: Value): value is SetValue | MixedSetValue =>
837
- typeof value === "object" && (value.kind === "Set" || value.kind === "MixedSet");
838
-
839
842
  // TLC compares a lazy set, or a set it overrides in Java, through its own class before it compares
840
843
  // elements. The comparisons above already fail as those classes do.
841
844
  const isComparedByClass = (left: ObjectValue, right: Value) =>
@@ -1069,7 +1072,7 @@ export const createEnumeratedSet = (elements: Value[]): SetValue | MixedSetValue
1069
1072
 
1070
1073
  export const EMPTY_SET = createSortedSet([]);
1071
1074
 
1072
- export const differenceSorted = (left: SetValue, right: SetValue): SetValue => {
1075
+ export const getSortedDifference = (left: SetValue, right: SetValue): SetValue => {
1073
1076
  if (left.elements.length === 0 || right.elements.length === 0) return left;
1074
1077
  const leftElements = left.elements;
1075
1078
  const rightElements = right.elements;
@@ -1094,7 +1097,7 @@ export const differenceSorted = (left: SetValue, right: SetValue): SetValue => {
1094
1097
  return kept.length === leftElements.length ? left : createSortedSet(kept);
1095
1098
  };
1096
1099
 
1097
- export const intersectSorted = (left: SetValue, right: SetValue): SetValue => {
1100
+ export const getSortedIntersection = (left: SetValue, right: SetValue): SetValue => {
1098
1101
  const leftElements = left.elements;
1099
1102
  const rightElements = right.elements;
1100
1103
  const kept: Value[] = [];
@@ -1117,7 +1120,7 @@ export const intersectSorted = (left: SetValue, right: SetValue): SetValue => {
1117
1120
  return kept.length === leftElements.length ? left : createSortedSet(kept);
1118
1121
  };
1119
1122
 
1120
- export const unionSorted = (left: SetValue, right: SetValue): SetValue => {
1123
+ export const getSortedUnion = (left: SetValue, right: SetValue): SetValue => {
1121
1124
  if (left.elements.length === 0) return right;
1122
1125
  if (right.elements.length === 0) return left;
1123
1126
  const leftElements = left.elements;
@@ -1242,6 +1245,9 @@ export const createTuple = (elements: Value[]): FunctionValue =>
1242
1245
  export const createRecord = (fields: [string, Value][]): FunctionValue =>
1243
1246
  setFunctionClass(createFunction(fields), "record");
1244
1247
 
1248
+ export const createSortedRecord = (names: Value[], range: Value[]) =>
1249
+ setFunctionClass(createSortedFunction(names, range), "record");
1250
+
1245
1251
  // TLC's Enumerable classes: every set except the ones it implements in Java.
1246
1252
  export const isTlcEnumerable = (value: Value) => isSetValue(value) && !isOverriddenSet(value);
1247
1253
 
@@ -1541,7 +1547,7 @@ const enumerateSet = (
1541
1547
  );
1542
1548
  }
1543
1549
  if (value.operator === "\\cup")
1544
- return unionSorted(toFiniteSet(value.left), toFiniteSet(value.right)).elements;
1550
+ return getSortedUnion(toFiniteSet(value.left), toFiniteSet(value.right)).elements;
1545
1551
  const isLeftEnumerated = value.operator === "\\" || isTlcEnumerable(value.left);
1546
1552
  const enumerated = isLeftEnumerated ? value.left : value.right;
1547
1553
  const other = isLeftEnumerated ? value.right : value.left;
@@ -1729,10 +1735,8 @@ const describeOverflow = (value: Value) =>
1729
1735
  // checking whether one is empty, so an infinite component fails even beside an empty one.
1730
1736
  export const getCardinality = (value: Value, version?: TlcVersion): number => {
1731
1737
  if (typeof value !== "object") {
1732
- const kind =
1733
- typeof value === "number" ? "integer" : typeof value === "string" ? "string" : "boolean";
1734
1738
  throw new TlaEvaluationError(
1735
- `Attempted to compute the number of elements in the ${kind} ${formatValue(value)}.`,
1739
+ `Attempted to compute the number of elements in the ${describeKind(value)} ${formatValue(value)}.`,
1736
1740
  );
1737
1741
  }
1738
1742
  switch (value.kind) {
@@ -1865,7 +1869,7 @@ export const isFiniteSet = (value: Value): boolean => {
1865
1869
  }
1866
1870
  };
1867
1871
 
1868
- const findIndex = (sortedValues: Value[], target: Value, compare = compareValues) => {
1872
+ const findSortedIndex = (sortedValues: Value[], target: Value, compare = compareValues) => {
1869
1873
  const bounds = { low: 0, high: sortedValues.length - 1 };
1870
1874
  while (bounds.low <= bounds.high) {
1871
1875
  const middle = (bounds.low + bounds.high) >> 1;
@@ -1947,7 +1951,8 @@ export const isElementOf = (element: Value, set: Value): boolean => {
1947
1951
  return isElement;
1948
1952
  };
1949
1953
 
1950
- const isInSortedSet = (element: Value, set: SetValue) => findIndex(set.elements, element) !== -1;
1954
+ const isInSortedSet = (element: Value, set: SetValue) =>
1955
+ findSortedIndex(set.elements, element) !== -1;
1951
1956
 
1952
1957
  const isInSortedSetLikeTlc = (element: Value, set: SetValue) =>
1953
1958
  normalizedSets.has(set)
@@ -2022,7 +2027,7 @@ const isElementOfSet = (element: Value, set: Value): boolean => {
2022
2027
  return (
2023
2028
  functionValue.domain.length === set.names.length &&
2024
2029
  set.names.every((name, index) => {
2025
- const position = findIndex(functionValue.domain, name);
2030
+ const position = findSortedIndex(functionValue.domain, name);
2026
2031
  return position !== -1 && isElementOf(functionValue.range[position], set.sets[index]);
2027
2032
  })
2028
2033
  );
@@ -2176,7 +2181,7 @@ const failKeyLikeTlc = (domain: Value[], argument: Value, error: TlaEvaluationEr
2176
2181
  if (valueVersion.is174 || domain.length < LINEAR_SEARCH_LIMIT) {
2177
2182
  domain.forEach((key) => equalsLikeTlc(key, argument));
2178
2183
  } else {
2179
- findIndex(domain, argument, compareLikeTlc);
2184
+ findSortedIndex(domain, argument, compareLikeTlc);
2180
2185
  }
2181
2186
  throw error;
2182
2187
  };
@@ -2203,7 +2208,7 @@ const findKeyIndexLikeTlc = (
2203
2208
  }
2204
2209
  const identical = findIdenticalKey(domain, argument);
2205
2210
  if (identical !== -1) return identical;
2206
- return computeLikeTlcOnFailure(findIndex, failKeyLikeTlc, domain, argument);
2211
+ return computeLikeTlcOnFailure(findSortedIndex, failKeyLikeTlc, domain, argument);
2207
2212
  };
2208
2213
 
2209
2214
  export const applyFunction = (
package/src/worker.ts CHANGED
@@ -22,13 +22,11 @@ interface WebWorker {
22
22
 
23
23
  declare const Worker: new (url: URL, options: { type: "module" }) => WebWorker;
24
24
 
25
- // Whether this runtime runs workers: Web Workers, or Node's.
26
25
  export const isWorkerSupported = () =>
27
26
  typeof Worker === "function" ||
28
27
  (typeof process !== "undefined" && process.versions?.node !== undefined);
29
28
 
30
- // Starts the worker at url, which the caller writes as new URL("./name.js", import.meta.url) for
31
- // bundlers to find. onError receives what the worker threw.
29
+ // The caller writes url as new URL("./name.js", import.meta.url) for bundlers to find.
32
30
  export const spawnWorker = async (
33
31
  url: URL,
34
32
  onMessage: (message: unknown) => void,
@@ -53,7 +51,6 @@ export const spawnWorker = async (
53
51
  };
54
52
  };
55
53
 
56
- // The port a worker receives its messages on and posts its own to.
57
54
  export const getParentPort = async () => {
58
55
  if (typeof (globalThis as { postMessage?: unknown }).postMessage === "function") {
59
56
  return globalThis as unknown as Port;