tla-ts 0.0.10-dev.96638cd93 → 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 (89) hide show
  1. package/dist/deciders.cjs +30 -30
  2. package/dist/deciders.js +30 -30
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.cts +1 -1
  5. package/dist/index.d.ts +1 -1
  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 +60 -60
  10. package/dist/prove.js +73 -73
  11. package/dist/run.cjs +42 -42
  12. package/dist/run.js +42 -42
  13. package/dist/transfer.cjs +34 -34
  14. package/dist/transfer.js +29 -29
  15. package/dist/worker.cjs +1 -1
  16. package/dist/worker.js +1 -1
  17. package/package.json +1 -1
  18. package/src/bags.ts +5 -2
  19. package/src/builtins.ts +4 -3
  20. package/src/check-failure.ts +1 -1
  21. package/src/check-trace.ts +90 -51
  22. package/src/check.ts +251 -133
  23. package/src/cli/tlc.ts +3 -2
  24. package/src/codegen.ts +18 -5
  25. package/src/dfid.ts +13 -8
  26. package/src/environment.ts +1 -0
  27. package/src/evaluate.ts +25 -9
  28. package/src/exit-codes.ts +1 -0
  29. package/src/java-hash.ts +14 -0
  30. package/src/liveness-checker.ts +63 -31
  31. package/src/liveness.ts +48 -10
  32. package/src/parser.ts +6 -1
  33. package/src/prover/smt/solver/arith-rewriter.ts +11 -3
  34. package/src/prover/smt/solver/array-rewriter.ts +12 -2
  35. package/src/prover/smt/solver/asserted-formulas.ts +109 -63
  36. package/src/prover/smt/solver/ast.ts +5 -3
  37. package/src/prover/smt/solver/auf-solver.ts +23 -12
  38. package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
  39. package/src/prover/smt/solver/bound-simplifier.ts +10 -11
  40. package/src/prover/smt/solver/card2bv.ts +31 -15
  41. package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -23
  42. package/src/prover/smt/solver/context.ts +24 -7
  43. package/src/prover/smt/solver/dependent-expr-state.ts +1 -1
  44. package/src/prover/smt/solver/elim-bounds.ts +89 -0
  45. package/src/prover/smt/solver/elim-uncnstr.ts +1 -1
  46. package/src/prover/smt/solver/internalizer.ts +1 -1
  47. package/src/prover/smt/solver/lp/lp-settings.ts +4 -0
  48. package/src/prover/smt/solver/model-evaluator.ts +2 -0
  49. package/src/prover/smt/solver/model-generator.ts +82 -42
  50. package/src/prover/smt/solver/opt-context.ts +11 -4
  51. package/src/prover/smt/solver/opt-pareto.ts +19 -0
  52. package/src/prover/smt/solver/opt-solver.ts +3 -2
  53. package/src/prover/smt/solver/poly-rewriter.ts +1 -0
  54. package/src/prover/smt/solver/proto-model.ts +4 -2
  55. package/src/prover/smt/solver/push-app-ite.ts +37 -0
  56. package/src/prover/smt/solver/qsat.ts +16 -6
  57. package/src/prover/smt/solver/rewriter.ts +31 -25
  58. package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
  59. package/src/prover/smt/solver/sat/inc-sat-solver.ts +13 -4
  60. package/src/prover/smt/solver/sat/sat-tactic.ts +9 -2
  61. package/src/prover/smt/solver/smt-kernel.ts +30 -2
  62. package/src/prover/smt/solver/smt-setup.ts +28 -4
  63. package/src/prover/smt/solver/smtlib-parser.ts +26 -3
  64. package/src/prover/smt/solver/smtlib-script.ts +34 -21
  65. package/src/prover/smt/solver/solve-eqs.ts +24 -17
  66. package/src/prover/smt/solver/solver.ts +18 -3
  67. package/src/prover/smt/solver/tactic.ts +68 -41
  68. package/src/prover/smt/solver/theory-bv.ts +11 -1
  69. package/src/prover/smt/solver/theory-fpa.ts +1 -1
  70. package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
  71. package/src/prover/smt/solver/theory-lra-internalize.ts +1 -0
  72. package/src/prover/smt/solver/theory-lra-propagate.ts +7 -1
  73. package/src/prover/smt/solver/theory-lra.ts +1 -0
  74. package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
  75. package/src/resolve.ts +120 -52
  76. package/src/runtime.ts +4 -0
  77. package/src/search.ts +117 -81
  78. package/src/simulate.ts +110 -50
  79. package/src/spec-description.ts +3 -4
  80. package/src/standard-modules.ts +15 -6
  81. package/src/subexpressions.ts +34 -9
  82. package/src/successors.ts +3 -2
  83. package/src/tlc/random.ts +2 -1
  84. package/src/tlc/replay.ts +3 -2
  85. package/src/tlc/tlc-operators.ts +7 -7
  86. package/src/tlc/tlcext-operators.ts +26 -10
  87. package/src/tlc/trace-spec.ts +6 -20
  88. package/src/typed-tier.ts +3 -2
  89. package/src/values.ts +95 -57
@@ -13,7 +13,6 @@ import { substitutionFrames, withSubstitutionFrames } from "./instances";
13
13
  import type { InstanceAction } from "./environment";
14
14
  import { formatRange, TlaError, TlaEvaluationError, UNEXPECTED_EXCEPTION } from "./errors";
15
15
  import {
16
- bindDefinitions,
17
16
  bindOperatorArguments,
18
17
  describeNode,
19
18
  evaluate,
@@ -26,7 +25,7 @@ import {
26
25
  type Scope,
27
26
  } from "./evaluate";
28
27
  import { ACTION_LEVEL, CONSTANT_LEVEL, TEMPORAL_LEVEL, VARIABLE_LEVEL } from "./levels";
29
- import { getLevel } from "./liveness";
28
+ import { bindLetDefinitions, getLevel } from "./liveness";
30
29
  import { createRecord, createSet, createTuple, formatValue, type Value } from "./values";
31
30
  import { LITERAL_KINDS } from "./tlc/replay";
32
31
  import type { TlcVersion } from "./tlc/version";
@@ -176,7 +175,7 @@ const unwrapBinding = (
176
175
  if (expression.kind === "Let") {
177
176
  return {
178
177
  expression: expression.body,
179
- scope: bindDefinitions(expression.definitions, getConstantContext(environment, scope)),
178
+ scope: bindLetDefinitions(expression, scope, environment),
180
179
  };
181
180
  }
182
181
  const thunk = getThunk(expression, scope);
@@ -268,7 +267,7 @@ const getActions = (
268
267
  case "Let":
269
268
  return getActions(
270
269
  expression.body,
271
- bindDefinitions(expression.definitions, getConstantContext(environment, scope)),
270
+ bindLetDefinitions(expression, scope, environment),
272
271
  closure,
273
272
  environment,
274
273
  instanceActions,
@@ -18,6 +18,7 @@ import {
18
18
  overrideWithJava,
19
19
  } from "./builtins";
20
20
  import type { Builtin, BuiltinArgument, Context } from "./evaluate";
21
+ import { prettyPrint } from "./pretty-print";
21
22
  import type { CheckerRuntime } from "./runtime";
22
23
  import { createBagsOperators } from "./bags";
23
24
  import { createIoUtilsOperators, createJsonOperators, type FileSystem } from "./json";
@@ -40,6 +41,7 @@ import {
40
41
  formatValue,
41
42
  getCardinality,
42
43
  getDomain,
44
+ getFunctionClass,
43
45
  getSortedIntersection,
44
46
  someStreamedElement,
45
47
  isElementOf,
@@ -376,7 +378,7 @@ const INTEGERS_OPERATORS = [
376
378
  const getSequenceArgument = (args: BuiltinArgument[], index: number, message: string) => {
377
379
  const value = getValue(args, index, message);
378
380
  const elements = getSequenceElements(value);
379
- if (!elements) throw new TlaModuleError(`${message}\n${formatValue(value)}`);
381
+ if (!elements) throw new TlaModuleError(`${message}\n${prettyPrint(formatValue(value))}`);
380
382
  return elements;
381
383
  };
382
384
 
@@ -425,12 +427,19 @@ const createSequencesOperators = (version: TlcVersion) =>
425
427
  const left = getSequenceOrString(args, 0, getEvaluatingMessage("s \\o t", "sequence"));
426
428
  if (typeof left !== "string") {
427
429
  const right = getSequenceArgument(args, 1, getEvaluatingMessage("t \\o s", "sequence"));
430
+ const kept =
431
+ left.length === 0
432
+ ? getValue(args, 1, "\\o")
433
+ : right.length === 0
434
+ ? getValue(args, 0, "\\o")
435
+ : undefined;
436
+ if (kept !== undefined && getFunctionClass(kept) === "tuple") return kept;
428
437
  return createTuple([...left, ...right]);
429
438
  }
430
439
  const right = getValue(args, 1, "\\o");
431
440
  if (typeof right !== "string") {
432
441
  throw new TlaModuleError(
433
- `${getEvaluatingMessage("t \\o s", "string")}\n${formatValue(right)}`,
442
+ `${getEvaluatingMessage("t \\o s", "string")}\n${prettyPrint(formatValue(right))}`,
434
443
  );
435
444
  }
436
445
  return rankString(left + right);
@@ -470,7 +479,7 @@ const createSequencesOperators = (version: TlcVersion) =>
470
479
  : undefined;
471
480
  if (outOfDomain) {
472
481
  throw new TlaModuleError(
473
- `The ${outOfDomain.position} argument of SubSeq must be in the domain of its first argument:\n${formatValue(getValue(args, 0, "SubSeq"))}\n, but instead it is\n${outOfDomain.value}`,
482
+ `The ${outOfDomain.position} argument of SubSeq must be in the domain of its first argument:\n${prettyPrint(formatValue(getValue(args, 0, "SubSeq")))}\n, but instead it is\n${outOfDomain.value}`,
474
483
  );
475
484
  }
476
485
  return sliceSequence(sequence, start - 1, end);
@@ -503,7 +512,7 @@ const createFiniteSetsOperators = (version: TlcVersion) =>
503
512
  (typeof set === "object" && (set.kind === "InfiniteSet" || set.kind === "SequenceSet"))
504
513
  ) {
505
514
  throw new TlaModuleError(
506
- `Attempted to compute cardinality of the value\n${formatValue(set)}`,
515
+ `Attempted to compute cardinality of the value\n${prettyPrint(formatValue(set))}`,
507
516
  );
508
517
  }
509
518
  return getCardinality(set, version);
@@ -516,7 +525,7 @@ const TRANSITIVE_CLOSURE_OPERATORS = [
516
525
  const relation = getValue(args, 0, "Warshall");
517
526
  if (!isSetValue(relation) || isOverriddenSet(relation)) {
518
527
  throw new TlaModuleError(
519
- `Applying TransitiveClosure to the following value,\nwhich is not an enumerable set:\n${formatValue(relation)}`,
528
+ `Applying TransitiveClosure to the following value,\nwhich is not an enumerable set:\n${prettyPrint(formatValue(relation))}`,
520
529
  );
521
530
  }
522
531
  // TLC sizes the relation, which normalizes it.
@@ -536,7 +545,7 @@ const TRANSITIVE_CLOSURE_OPERATORS = [
536
545
  const ends = getSequenceElements(edge);
537
546
  if (ends?.length !== 2) {
538
547
  throw new TlaModuleError(
539
- `Attempted to apply TransitiveClosure to a set containing\nthe following value:\n${formatValue(edge)}`,
548
+ `Attempted to apply TransitiveClosure to a set containing\nthe following value:\n${prettyPrint(formatValue(edge))}`,
540
549
  );
541
550
  }
542
551
  return [getNodeIndex(ends[0]), getNodeIndex(ends[1])];
@@ -32,6 +32,7 @@ import {
32
32
  selectionErrors,
33
33
  selectionArguments,
34
34
  selections,
35
+ selectionSources,
35
36
  SELECTION_NAME,
36
37
  factReferences,
37
38
  type NullSelection,
@@ -121,7 +122,12 @@ const wrapLets = (body: Expression, lets: Definition[][], location: SourceLocati
121
122
  const createApplication = (selection: Selection, body: Expression): Expression => {
122
123
  const location = selection.location;
123
124
  const wrapped = wrapLets(body, selection.lets, location);
124
- if (selection.params.length === 0) return wrapped;
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
+ }
125
131
  if (selection.args.length === 0) {
126
132
  if (selection.params.some((param) => param.arity > 0)) {
127
133
  throw createError("Selected an operator with operator parameters as an argument", location);
@@ -209,9 +215,11 @@ const selectSubexpression = (
209
215
  const deferToExpression = (range: SourceRange | undefined, message: string) => {
210
216
  if (!expressionError && range) expressionError = { location: formatRange(range), message };
211
217
  };
212
- const checkNull = (node: Expression | undefined, message: string) => {
218
+ const checkNull = (node: Expression | undefined, message: string, isEmpty = false) => {
213
219
  const range = reference.selectorRanges?.[selectorIndex];
214
- if (node && range) nulls.push({ node, error: { location: formatRange(range), message } });
220
+ if (node && range) {
221
+ nulls.push({ node, error: { location: formatRange(range), message }, isEmpty });
222
+ }
215
223
  };
216
224
 
217
225
  const report = (range: SourceRange | undefined, message: string) => {
@@ -333,15 +341,16 @@ const selectSubexpression = (
333
341
  (current.kind === "Apply" && current.operator.includes("!"))) &&
334
342
  (currentRange?.module !== location.range?.module || isBefore(current.location, location))
335
343
  ) {
336
- const selected = resolveSubexpressions(current, lookup, isGoal);
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.`;
337
348
  if (selectionErrors.has(selected)) {
338
- report(
339
- range,
340
- `Choosing operand \`${getSelectorName(selector)}' of subexpression with no operands.`,
341
- );
349
+ report(range, noOperands);
342
350
  return;
343
351
  }
344
352
  if (selections.has(selected) && selected.kind !== "Lambda") {
353
+ checkNull(selected, noOperands, true);
345
354
  current =
346
355
  selected.kind === "Let" &&
347
356
  selected.body.kind === "Apply" &&
@@ -368,6 +377,13 @@ const selectSubexpression = (
368
377
  }
369
378
  const binder = getBinder(current);
370
379
  if (binder && (selector.kind === "Bound" || selector.kind === "At")) {
380
+ if (selector.kind === "Bound" && selector.args.length !== binder.names.length) {
381
+ report(
382
+ range,
383
+ `Selector with ${selector.args.length} argument(s) used for quantifier with ${binder.names.length} bound identifier(s).`,
384
+ );
385
+ return;
386
+ }
371
387
  selection.params.push(...binder.names.map((name) => ({ name, arity: 0 })));
372
388
  if (selector.kind === "Bound") {
373
389
  selection.args.push(...selector.args);
@@ -469,6 +485,11 @@ const selectSubexpression = (
469
485
  current,
470
486
  "Subexpression selection failed, probably due to an error in the selected expression.",
471
487
  );
488
+ checkNull(
489
+ current,
490
+ `Choosing operand \`${getSelectorName(selector)}' of subexpression with no operands.`,
491
+ true,
492
+ );
472
493
  }
473
494
  selectOperand(selector);
474
495
  checkNull(
@@ -539,7 +560,7 @@ const resolveSubexpressions = (
539
560
  : mapped;
540
561
  }
541
562
  const callee = expression.kind === "Apply" ? lookup(expression.operator) : undefined;
542
- const mapped =
563
+ const rebuilt =
543
564
  expression.kind === "Apply"
544
565
  ? {
545
566
  ...expression,
@@ -553,6 +574,10 @@ const resolveSubexpressions = (
553
574
  ),
554
575
  }
555
576
  : mapChildren(expression, (child) => resolveSubexpressions(child, lookup, isGoal));
577
+ const children = getChildren(expression);
578
+ const mapped = getChildren(rebuilt).every((child, index) => child === children[index])
579
+ ? expression
580
+ : rebuilt;
556
581
  const selectors =
557
582
  mapped.kind === "Subexpression"
558
583
  ? mapped.selectors
package/src/successors.ts CHANGED
@@ -1341,6 +1341,7 @@ export const hasIncompleteSuccessor = (
1341
1341
  generator: undefined,
1342
1342
  successors: 0,
1343
1343
  };
1344
+ // TLC's Tool#getState generates every successor of the action before it compares them.
1344
1345
  getRunner(expression, environment, false)(
1345
1346
  run,
1346
1347
  scope,
@@ -1348,10 +1349,10 @@ export const hasIncompleteSuccessor = (
1348
1349
  undefined,
1349
1350
  false,
1350
1351
  (partial) => {
1351
- if (!isComplete(partial)) run.isStopped = true;
1352
+ if (!isComplete(partial)) run.successors++;
1352
1353
  },
1353
1354
  );
1354
- return run.isStopped;
1355
+ return run.successors > 0;
1355
1356
  };
1356
1357
 
1357
1358
  export const getSuccessors = (
package/src/tlc/random.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { toEnumeratedSet } from "../builtins";
2
2
  import { TlaEvaluationError } from "../errors";
3
+ import { prettyPrint } from "../pretty-print";
3
4
  import type { TlcVersion } from "./version";
4
5
  import {
5
6
  createRecord,
@@ -226,7 +227,7 @@ export const getRandomElement = (set: Value, random: JavaRandom): Value => {
226
227
  const offset = Math.floor(random.nextDouble() * size);
227
228
  if (offset >= size) {
228
229
  throw new TlaEvaluationError(
229
- `Attempted to retrieve out-of-bounds element from the interval value ${formatValue(set)}.`,
230
+ `Attempted to retrieve out-of-bounds element from the interval value ${prettyPrint(formatValue(set))}.`,
230
231
  );
231
232
  }
232
233
  return set.low + offset;
package/src/tlc/replay.ts CHANGED
@@ -799,9 +799,10 @@ export const replayEnabled = (
799
799
  state: Value[],
800
800
  environment: Environment,
801
801
  ) => {
802
- const replay = createReplay(environment, "enabled", state, () => {
802
+ const found = () => {
803
803
  throw ENABLED_FOUND;
804
- });
804
+ };
805
+ const replay = createReplay(environment, "enabled", state, found, found);
805
806
  const callStack = replay.callStack;
806
807
  const depth = callStack?.expressions.length ?? 0;
807
808
  try {
@@ -16,12 +16,13 @@ import {
16
16
  toEnumeratedSet,
17
17
  } from "../builtins";
18
18
  import { getNamedRegisters, NAMED_REGISTER_PREFIX, type CheckerRuntime } from "../runtime";
19
- import { createActionRecord, setTlcValue } from "./tlcext-operators";
19
+ import { createActionRecord, createTlcRecord, setTlcValue } from "./tlcext-operators";
20
20
  import { getRandomElement } from "./random";
21
21
  import {
22
22
  ANY_SET,
23
23
  createFunction,
24
24
  createSet,
25
+ createSortedFunction,
25
26
  createTuple,
26
27
  createWrittenFunction,
27
28
  formatNormalizedCopies,
@@ -34,7 +35,6 @@ import {
34
35
  toFiniteSet,
35
36
  type Value,
36
37
  rankString,
37
- setFunctionClass,
38
38
  } from "../values";
39
39
  import { getFingerprintPolynomial } from "./fingerprint";
40
40
  import { zeroPad } from "./messages";
@@ -47,9 +47,6 @@ const getRegisterFunction = <Key extends Value>(registers: Map<Key, Value>) =>
47
47
  [...registers].map((entry): [Value, Value] => [entry[0], createTuple([entry[1]])]),
48
48
  );
49
49
 
50
- const createTlcRecord = (fields: [string, Value][]) =>
51
- setFunctionClass(createWrittenFunction(fields), "record");
52
-
53
50
  const CHECKER_KEYS = new Set(["diameter", "generated", "distinct", "queue", "stats", "config"]);
54
51
  const TLC_174_KEYS = new Set(["diameter", "distinct", "queue", "duration", "level"]);
55
52
  const CHECKER_KEYS_174 = new Set(["diameter", "distinct", "queue", "level"]);
@@ -135,7 +132,7 @@ const getTlcValue = (runtime: CheckerRuntime, key: Value, context: Context | und
135
132
  }
136
133
  if (typeof key !== "string") {
137
134
  throw new TlaModuleError(
138
- `The argument of TLCGet should be a nonnegative integer, but instead it is:\n${formatValue(key)}`,
135
+ `The argument of TLCGet should be a nonnegative integer, but instead it is:\n${prettyPrint(formatValue(key))}`,
139
136
  );
140
137
  }
141
138
  return getRuntimeValue(runtime, key, context?.state);
@@ -162,8 +159,11 @@ const normalizeDeeply = (value: Value): void => {
162
159
  const convertLikeTlcEval = (value: Value): Value => {
163
160
  if (typeof value !== "object") return value;
164
161
  switch (value.kind) {
165
- case "ModelValue":
166
162
  case "Function":
163
+ return value.functionClass === undefined
164
+ ? value
165
+ : createSortedFunction(value.domain, value.range);
166
+ case "ModelValue":
167
167
  case "MixedSet":
168
168
  case "InfiniteSet":
169
169
  case "SequenceSet":
@@ -15,6 +15,7 @@ import {
15
15
  TlaUnsupportedError,
16
16
  } from "../errors";
17
17
  import { getTlcFingerprint } from "./fingerprint";
18
+ import { prettyPrint } from "../pretty-print";
18
19
  import { formatMessage, formatNestedMessage, MESSAGE_CODE, MESSAGE_LEVEL } from "./messages";
19
20
  import {
20
21
  describeRange,
@@ -37,11 +38,14 @@ import {
37
38
  createRecord,
38
39
  createSet,
39
40
  createTuple,
41
+ createWrittenFunction,
40
42
  formatState,
41
43
  formatValue,
42
44
  getFingerprintError,
43
45
  getSequenceElements,
44
46
  getValueKey,
47
+ rankString,
48
+ setFunctionClass,
45
49
  toFiniteSet,
46
50
  type Value,
47
51
  } from "../values";
@@ -63,19 +67,31 @@ export const createActionRecord = (action: string | undefined) =>
63
67
 
64
68
  const counterExamples = new WeakSet<Value & object>();
65
69
 
66
- const createCounterExampleRecord = (action: Value[], states: Value[]) => {
67
- const counterExample = createRecord([
70
+ export const createTlcRecord = (fields: [string, Value][]) =>
71
+ setFunctionClass(createWrittenFunction(fields), "record");
72
+
73
+ const createCounterExampleRecord = (action: Value[], states: Value[], isConsole = true) => {
74
+ // TLC's CounterExample interns its field names as the class loads, which orders them as strings.
75
+ ["state", "action", "console"].forEach(rankString);
76
+ const fields: [string, Value][] = [
68
77
  ["action", createSet(action)],
69
78
  ["state", createSet(states)],
70
- ]);
79
+ ];
80
+ const counterExample = createTlcRecord(isConsole ? fields : [...fields, ["console", false]]);
71
81
  counterExamples.add(counterExample);
72
82
  return counterExample;
73
83
  };
74
84
 
85
+ export interface CounterExampleLoop {
86
+ start: number;
87
+ action: Value;
88
+ }
89
+
75
90
  export const createCounterExample = (
76
91
  stateRecords: Record<string, Value>[],
77
92
  actions: Value[],
78
- loop: { start: number; action: Value } | undefined,
93
+ loop: CounterExampleLoop | undefined,
94
+ isConsole = true,
79
95
  ) => {
80
96
  const states = stateRecords.map((state, index) =>
81
97
  createTuple([index + 1, createRecord(Object.entries(state))]),
@@ -86,7 +102,7 @@ export const createCounterExample = (
86
102
  const closing = loop
87
103
  ? [createTuple([states[states.length - 1], loop.action, states[loop.start]])]
88
104
  : [];
89
- return createCounterExampleRecord([...steps, ...closing], states);
105
+ return createCounterExampleRecord([...steps, ...closing], states, isConsole);
90
106
  };
91
107
 
92
108
  const getRegister = (runtime: CheckerRuntime, key: Value) => {
@@ -126,7 +142,7 @@ export const setTlcValue = (
126
142
  return;
127
143
  }
128
144
  throw new TlaModuleError(
129
- `The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${formatValue(key)}`,
145
+ `The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${prettyPrint(formatValue(key))}`,
130
146
  );
131
147
  };
132
148
 
@@ -232,7 +248,7 @@ export const createTlcExtOperators = (
232
248
  const counterExample = getValue(args, 0, "ToTrace");
233
249
  if (typeof counterExample !== "object" || !counterExamples.has(counterExample)) {
234
250
  throw new TlaModuleError(
235
- `The argument of ToTrace should be a CounterExample, but instead it is:\n${formatValue(counterExample)}`,
251
+ `The argument of ToTrace should be a CounterExample, but instead it is:\n${prettyPrint(formatValue(counterExample))}`,
236
252
  );
237
253
  }
238
254
  const states = toFiniteSet(applyFunction(counterExample, "state")).elements.map(
@@ -246,7 +262,7 @@ export const createTlcExtOperators = (
246
262
  const name = getValue(args, 0, "TLCModelValue");
247
263
  if (typeof name !== "string") {
248
264
  throw new TlaModuleError(
249
- `The argument of ModelValue should be a string, but instead it is:\n${formatValue(name)}`,
265
+ `The argument of ModelValue should be a string, but instead it is:\n${prettyPrint(formatValue(name))}`,
250
266
  );
251
267
  }
252
268
  return createModelValue(name);
@@ -361,7 +377,7 @@ export const createTlcExtOperators = (
361
377
  const name = getThunk(args, 0, "TLCEvalDefinition")();
362
378
  if (typeof name !== "string") {
363
379
  throw new TlaModuleError(
364
- `The argument of TLCEvalDefinition should be a string, but instead it is:\n${formatValue(name)}`,
380
+ `The argument of TLCEvalDefinition should be a string, but instead it is:\n${prettyPrint(formatValue(name))}`,
365
381
  );
366
382
  }
367
383
  const definition = context ? getDefinition(name, context.environment) : undefined;
@@ -369,7 +385,7 @@ export const createTlcExtOperators = (
369
385
  if (builtin?.arity === 0) return builtin.evaluate([], context);
370
386
  if (!definition || !context) {
371
387
  throw new TlaModuleError(
372
- `The argument of TLCEvalDefinition should be a name of a definition reachable from the root module, but instead it is:\n${formatValue(name)}`,
388
+ `The argument of TLCEvalDefinition should be a name of a definition reachable from the root module, but instead it is:\n${prettyPrint(formatValue(name))}`,
373
389
  );
374
390
  }
375
391
  if (definition.kind === "Operator" && definition.params.length > 0) {
@@ -1,4 +1,4 @@
1
- import { getJavaHashCode } from "../java-hash";
1
+ import { getHashMapOrder } from "../java-hash";
2
2
  import { formatValue, type Value } from "../values";
3
3
  import { zeroPad } from "./messages";
4
4
 
@@ -18,20 +18,6 @@ const CLOSING_TAG = `${"=".repeat(77)}\n`;
18
18
  const LASSO_START = "_TTraceLassoStart";
19
19
  const LASSO_END = "_TTraceLassoEnd";
20
20
 
21
- const getHashMapHash = (text: string) => {
22
- const hash = getJavaHashCode(text);
23
- return hash ^ (hash >>> 16);
24
- };
25
-
26
- const getHashOrder = (names: string[]) => {
27
- const unique = [...new Set(names)];
28
- const capacity = 2 ** Math.max(4, Math.ceil(Math.log2(unique.length / 0.75)));
29
- return unique
30
- .map((name, index) => ({ name, index, bucket: getHashMapHash(name) & (capacity - 1) }))
31
- .sort((left, right) => left.bucket - right.bucket || left.index - right.index)
32
- .map((entry) => entry.name);
33
- };
34
-
35
21
  const formatJavaDate = (date: Date) => {
36
22
  const getPart = (options: Intl.DateTimeFormatOptions, type: Intl.DateTimeFormatPartTypes) =>
37
23
  new Intl.DateTimeFormat("en-US", options).formatToParts(date).find((part) => part.type === type)
@@ -102,7 +88,7 @@ ${examples}`;
102
88
  export const writeTraceSpec = (input: TraceSpecInput) => {
103
89
  const loopStart = input.loopStart;
104
90
  const states = input.states.map((state) =>
105
- getHashOrder(Object.keys(state)).map((name): [string, string] => [
91
+ getHashMapOrder(Object.keys(state)).map((name): [string, string] => [
106
92
  name,
107
93
  formatValue(state[name]),
108
94
  ]),
@@ -127,11 +113,11 @@ export const writeTraceSpec = (input: TraceSpecInput) => {
127
113
  ...(isLasso ? [LASSO_START, LASSO_END] : []),
128
114
  ];
129
115
  const teConstantsModule = `${specName}_TEConstants`;
130
- const constantModules = getHashOrder([
116
+ const constantModules = getHashMapOrder([
131
117
  "TLC",
132
118
  ...(teConstants.length > 0 ? [teConstantsModule] : []),
133
119
  ]);
134
- const extendedModules = getHashOrder([
120
+ const extendedModules = getHashMapOrder([
135
121
  "Toolbox",
136
122
  "TLCExt",
137
123
  "Naturals",
@@ -187,7 +173,7 @@ ${lassoStep}${variables
187
173
  definition: `\n_view ==\n${INDENT}<<${variables.join(", ")}, IF TLCGet("level") = ${LASSO_END} + 1 THEN ${LASSO_START} ELSE TLCGet("level")>>\n`,
188
174
  }
189
175
  : { config: "", definition: "" };
190
- const deserializedTrace = `\n${getPrimer(traceModule, getHashOrder(["IOUtils", ...constantModules, specName]))}trace == IODeserialize("${input.module}.bin", TRUE)\n\n${CLOSING_TAG}`;
176
+ const deserializedTrace = `\n${getPrimer(traceModule, getHashMapOrder(["IOUtils", ...constantModules, specName]))}trace == IODeserialize("${input.module}.bin", TRUE)\n\n${CLOSING_TAG}`;
191
177
  const traceFunction = `${INDENT}<<\n${states
192
178
  .map(
193
179
  (state) =>
@@ -218,7 +204,7 @@ ${lassoStep}${variables
218
204
  " In this case, it is advised to uncomment the module below to deserialize the\n",
219
205
  " trace from a generated binary file.\n",
220
206
  `\n\\*${deserializedTrace.replaceAll("\n", "\n\\*")}\n\n`,
221
- getPrimer(traceModule, getHashOrder([...constantModules, specName])),
207
+ getPrimer(traceModule, getHashMapOrder([...constantModules, specName])),
222
208
  `trace == \n${traceFunction}\n`,
223
209
  ...(teConstants.length > 0
224
210
  ? [
package/src/typed-tier.ts CHANGED
@@ -607,6 +607,7 @@ const closeType = (type: Type, path: Type[] = []): Type => {
607
607
  const resolved = resolveType(type);
608
608
  // A function built lazily is only applied, never compared or stored.
609
609
  if (resolved.kind === "Lambda") return unsupported();
610
+ if (resolved.kind === "Rec" && resolved.shapes.length === 0) return unsupported();
610
611
  if (resolved.kind === "Var") {
611
612
  const integer = createInt();
612
613
  resolved.target = integer;
@@ -6373,7 +6374,7 @@ const search = (environment: Environment, check: TypedCheck, plains: Plains): Ty
6373
6374
  return fingerprinter.words[0];
6374
6375
  })()),
6375
6376
  // The successors of a state the search expanded are all stored.
6376
- getSuccessors: (_index, state) => {
6377
+ forEachActionSuccessors: (_index, state, onSuccessors) => {
6377
6378
  const successors: LiveSuccessor<Plain[]>[] = [];
6378
6379
  compiled.next(state, (successor) => {
6379
6380
  if (!isInModel(successor)) return;
@@ -6381,7 +6382,7 @@ const search = (environment: Environment, check: TypedCheck, plains: Plains): Ty
6381
6382
  const index = findState(false);
6382
6383
  successors.push({ index: index === -1 ? deopt() : index, state: successor });
6383
6384
  });
6384
- return successors;
6385
+ onSuccessors(successors);
6385
6386
  },
6386
6387
  },
6387
6388
  environment.runtime.version !== "1.7.4",