tla-ts 0.0.8-dev.d9bffda → 0.0.9-dev.0dd11f695

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 (119) hide show
  1. package/README.md +30 -0
  2. package/dist/compile.cjs +23 -0
  3. package/dist/compile.js +23 -0
  4. package/dist/deciders.cjs +15 -15
  5. package/dist/deciders.js +40 -40
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +80 -10
  8. package/dist/index.d.ts +80 -10
  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 +116 -36
  15. package/dist/prove.js +116 -36
  16. package/dist/run.cjs +143 -31
  17. package/dist/run.js +143 -31
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +1 -1
  20. package/dist/transfer.cjs +128 -103
  21. package/dist/transfer.js +128 -103
  22. package/dist/worker.cjs +7 -7
  23. package/dist/worker.js +7 -7
  24. package/package.json +3 -1
  25. package/src/ast.ts +7 -21
  26. package/src/bags.ts +99 -99
  27. package/src/builtins.ts +44 -75
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +605 -311
  30. package/src/cli/options.ts +12 -3
  31. package/src/cli/run.ts +2 -2
  32. package/src/cli/runtime-invariants.ts +135 -0
  33. package/src/cli/shared.ts +20 -9
  34. package/src/cli/tlc-arguments.ts +646 -0
  35. package/src/cli/tlc-usage.ts +362 -0
  36. package/src/cli/tlc.ts +571 -185
  37. package/src/cli/typescript.ts +26 -0
  38. package/src/cli/xml-exporter.ts +4 -10
  39. package/src/codegen.ts +190 -46
  40. package/src/config.ts +101 -68
  41. package/src/coverage.ts +855 -0
  42. package/src/dependencies.ts +20 -28
  43. package/src/dfid.ts +636 -0
  44. package/src/environment.ts +266 -98
  45. package/src/errors.ts +142 -45
  46. package/src/evaluate.ts +632 -298
  47. package/src/exit-codes.ts +37 -1
  48. package/src/index.ts +3 -0
  49. package/src/instances.ts +85 -9
  50. package/src/java-overrides.ts +2 -12
  51. package/src/json-reader.ts +456 -0
  52. package/src/json.ts +262 -139
  53. package/src/levels.ts +2 -3
  54. package/src/lexer.ts +17 -26
  55. package/src/liveness-checker.ts +10 -18
  56. package/src/liveness.ts +121 -49
  57. package/src/parallel-worker.ts +14 -10
  58. package/src/parallel.ts +41 -17
  59. package/src/parser.ts +436 -90
  60. package/src/pcal/ast.ts +7 -28
  61. package/src/pcal/parse.ts +11 -39
  62. package/src/pcal/tokenize.ts +4 -20
  63. package/src/pcal/translate.ts +10 -42
  64. package/src/pcal/validate.ts +3 -21
  65. package/src/pretty-print.ts +1 -2
  66. package/src/prover/smt/solver/solver.ts +31 -27
  67. package/src/randomization.ts +84 -35
  68. package/src/resolve.ts +18 -60
  69. package/src/runtime.ts +11 -4
  70. package/src/sany/builtins.ts +3 -4
  71. package/src/sany/generator.ts +128 -176
  72. package/src/sany/levels.ts +6 -30
  73. package/src/sany/lexer.ts +7 -23
  74. package/src/sany/linter.ts +31 -29
  75. package/src/sany/modules.ts +1 -5
  76. package/src/sany/nodes.ts +4 -28
  77. package/src/sany/parse-error.ts +44 -100
  78. package/src/sany/report.ts +25 -40
  79. package/src/sany/selectors.ts +8 -22
  80. package/src/sany/source.ts +8 -15
  81. package/src/sany/xml.ts +11 -42
  82. package/src/search.ts +547 -144
  83. package/src/simulate.ts +694 -0
  84. package/src/spec-description.ts +166 -48
  85. package/src/standard-definitions.ts +2 -3
  86. package/src/standard-modules.ts +264 -68
  87. package/src/state-graph.ts +51 -18
  88. package/src/subexpressions.ts +31 -5
  89. package/src/successors.ts +267 -77
  90. package/src/symmetry.ts +31 -8
  91. package/src/tableau.ts +1 -2
  92. package/src/tlc/fingerprint.ts +183 -61
  93. package/src/tlc/jar-data.ts +113 -6
  94. package/src/tlc/messages.ts +122 -37
  95. package/src/tlc/order.ts +33 -38
  96. package/src/tlc/random.ts +16 -16
  97. package/src/tlc/replay.ts +563 -211
  98. package/src/tlc/summary.ts +2 -4
  99. package/src/tlc/tlc-operators.ts +81 -36
  100. package/src/tlc/tlcext-operators.ts +138 -117
  101. package/src/tlc/trace-spec.ts +273 -0
  102. package/src/tlc/value-stream.ts +143 -0
  103. package/src/tlc/version.ts +2 -4
  104. package/src/typescript/actions.ts +494 -0
  105. package/src/typescript/collections.ts +615 -0
  106. package/src/typescript/compile.ts +70 -0
  107. package/src/typescript/context.ts +106 -0
  108. package/src/typescript/emit.ts +122 -0
  109. package/src/typescript/expressions.ts +508 -0
  110. package/src/typescript/formula.ts +160 -0
  111. package/src/typescript/functions.ts +295 -0
  112. package/src/typescript/model.ts +164 -0
  113. package/src/typescript/names.ts +116 -0
  114. package/src/typescript/program.ts +51 -0
  115. package/src/typescript/properties.ts +148 -0
  116. package/src/typescript/scope.ts +117 -0
  117. package/src/typescript/steps.ts +175 -0
  118. package/src/typescript/types.ts +178 -0
  119. package/src/values.ts +832 -255
@@ -1,7 +1,6 @@
1
1
  import { TlaEvaluationError } from "./errors";
2
2
  import { hasRepeatedEffects, type Environment } from "./evaluate";
3
3
  import {
4
- createTautologyError,
5
4
  evaluateLive,
6
5
  evaluateOnLasso,
7
6
  toLiveExpression,
@@ -28,8 +27,8 @@ export interface LiveSuccessor {
28
27
  export interface Lasso {
29
28
  prefix: number[];
30
29
  cycle: number[];
31
- // Whether the solution that the lasso violates constrains the cycle, as a liveness property does.
32
- // TLC warns that a stuttering counterexample to one may come from a missing fairness constraint.
30
+ // TLC warns that a stuttering counterexample to a liveness property may come from a missing
31
+ // fairness constraint.
33
32
  isCycleConstrained: boolean;
34
33
  }
35
34
 
@@ -62,10 +61,8 @@ interface Pool<Data extends Int32Array | Uint8Array> {
62
61
  create: (length: number) => Data;
63
62
  }
64
63
 
65
- // TLC's behavior graph for one solution: a node per state, or per state and tableau node.
66
64
  interface BehaviorGraph {
67
65
  solution: Solution;
68
- // One id per distinct action check across the solutions.
69
66
  actionIds: Int32Array;
70
67
  nodeStates: number[];
71
68
  nodeTableaux: number[];
@@ -104,7 +101,6 @@ const containsAlways = (expression: LiveExpression): boolean => {
104
101
  }
105
102
  };
106
103
 
107
- // TLC's OrderOfSolution#hasEmptyPEMAndBoxFreePromises, negated.
108
104
  const isCycleConstrained = (solution: Solution) =>
109
105
  solution.promises.some((promise) => containsAlways(promise.body)) ||
110
106
  solution.models.some(
@@ -178,7 +174,6 @@ const getStateResult = (behavior: BehaviorGraph, node: number, position: number)
178
174
  behavior.nodeStates[node] * behavior.solution.stateChecks.length + position
179
175
  ] === 1;
180
176
 
181
- // A node owns one entry in each per-node array of its graph.
182
177
  const pushNode = (behavior: BehaviorGraph, state: number, tableauNode: number) => {
183
178
  behavior.nodeStates.push(state);
184
179
  behavior.nodeTableaux.push(tableauNode);
@@ -225,9 +220,6 @@ export const createLivenessChecker = (
225
220
  const formula =
226
221
  fairness.length === 0 ? violation : createJunction("And", [...fairness, violation]);
227
222
  const solutions = getSolutions(formula);
228
- if (solutions.length === 0) {
229
- throw createTautologyError();
230
- }
231
223
  const actionIds = new Map<string, number>();
232
224
  const behaviors = solutions.map((solution): BehaviorGraph => ({
233
225
  solution,
@@ -268,11 +260,14 @@ export const createLivenessChecker = (
268
260
  return cache;
269
261
  };
270
262
  // TLCGet("level") reads the level of the state whose successors the checks run on.
263
+ // A check that fails leaves no source, so the failure's trace reads the levels of the search.
271
264
  const evaluateFrom = <Result>(source: number | undefined, evaluate: () => Result) => {
272
265
  environment.runtime.setLivenessSource(source);
273
- const result = evaluate();
274
- environment.runtime.setLivenessSource(undefined);
275
- return result;
266
+ try {
267
+ return evaluate();
268
+ } finally {
269
+ environment.runtime.setLivenessSource(undefined);
270
+ }
276
271
  };
277
272
  const evaluateState = (predicate: LiveExpression, state: Value[]) =>
278
273
  evaluateLive(
@@ -439,7 +434,6 @@ export const createLivenessChecker = (
439
434
  return table.slots.filter((entry): entry is LiveSuccessor => entry !== undefined);
440
435
  };
441
436
 
442
- // TLC's TableauLiveChecker#addNextState for a node it finds after it expanded the node's state.
443
437
  const expandLate = (
444
438
  behavior: BehaviorGraph,
445
439
  tableau: Tableau,
@@ -551,7 +545,6 @@ export const createLivenessChecker = (
551
545
  writeNode(behavior, index, successors, actions, stateResults);
552
546
  };
553
547
 
554
- // The shortest path from an initial node to the node, last node first, as TLC's getPath finds it.
555
548
  const getPath = (behavior: BehaviorGraph, target: number) => {
556
549
  if (behavior.initial.includes(target)) return [target];
557
550
  const parents = new Map<number, number>();
@@ -635,8 +628,8 @@ export const createLivenessChecker = (
635
628
  return getLasso(root, members, membersByState);
636
629
  };
637
630
 
638
- // TLC's LiveWorker#printTrace: a prefix to the root, a greedy walk through the component
639
- // until it satisfies every check, and a breadth-first path back to the root.
631
+ // TLC's LiveWorker#printTrace: a prefix to the root, a greedy walk through the component until it
632
+ // satisfies every check, and a breadth-first path back to the root.
640
633
  const getLasso = (
641
634
  root: number,
642
635
  members: Set<number>,
@@ -733,7 +726,6 @@ export const createLivenessChecker = (
733
726
  };
734
727
  };
735
728
 
736
- // TLC's LiveWorker#bfsPostFix, the states from the walk's end back to the root, last first.
737
729
  const getClosingPath = (
738
730
  root: number,
739
731
  end: number,
package/src/liveness.ts CHANGED
@@ -12,11 +12,11 @@ import {
12
12
  bindDefinitions,
13
13
  bindOperatorArguments,
14
14
  evaluate,
15
- expectBoolean,
16
15
  forEachBinding,
17
16
  forEachBoundElement,
18
17
  getBoundElements,
19
18
  getDefinition,
19
+ getStartupValue,
20
20
  lookupScope,
21
21
  resolveApplyOperator,
22
22
  resolveGlobalOperator,
@@ -40,17 +40,17 @@ import {
40
40
  type LiveEnabled,
41
41
  type LiveExpression,
42
42
  } from "./tableau";
43
- import type { Value } from "./values";
43
+ import { isEqualLikeTlc, type Value } from "./values";
44
44
 
45
45
  export interface ScopedExpression {
46
46
  expression: Expression;
47
47
  scope: Scope | undefined;
48
48
  }
49
49
 
50
- // A part of a temporal formula, with the name TLC gives the part when the formula is a property:
51
- // a conjunct's location, or the name of the definition the part is the body of.
50
+ // The name TLC gives a part of a property: a conjunct's location or the enclosing definition.
52
51
  interface ExpandedExpression extends ScopedExpression {
53
52
  name: string | undefined;
53
+ path: string[];
54
54
  }
55
55
 
56
56
  export interface TemporalProperty extends ScopedExpression {
@@ -69,6 +69,11 @@ const TEMPORAL_OPERATORS = new Set(["~>", "-+->"]);
69
69
 
70
70
  const definitionThunks = new WeakSet<Thunk>();
71
71
 
72
+ const JUNCTIONS = new Map<string, "And" | "Or">([
73
+ ["/\\", "And"],
74
+ ["\\/", "Or"],
75
+ ]);
76
+
72
77
  const getConstantContext = (environment: Environment, scope: Scope | undefined): Context => ({
73
78
  environment,
74
79
  scope,
@@ -87,15 +92,28 @@ export const getLevel = (
87
92
  scope: Scope | undefined,
88
93
  environment: Environment,
89
94
  shadowed = new Set<string>(),
95
+ visiting = new Set<object>(),
90
96
  ): number => {
97
+ const getBodyLevel = (binding: object, body: Expression, bodyScope: Scope | undefined) => {
98
+ // A recursive call adds nothing, as SANY's level never decreases while it iterates.
99
+ if (visiting.has(binding)) return CONSTANT_LEVEL;
100
+ visiting.add(binding);
101
+ const level = getLevel(body, bodyScope, environment, new Set(), visiting);
102
+ visiting.delete(binding);
103
+ return level;
104
+ };
91
105
  const getBindingLevel = (name: string) => {
92
106
  const binding = lookupScope(scope, name);
93
107
  if (!binding) return undefined;
94
108
  if (binding.kind === "Value") return CONSTANT_LEVEL;
95
- if (binding.kind === "Thunk") return getLevel(binding.expression, binding.scope, environment);
109
+ if (binding.kind === "Thunk") {
110
+ return binding.isReleased
111
+ ? CONSTANT_LEVEL
112
+ : getBodyLevel(binding, binding.expression, binding.scope);
113
+ }
96
114
  const operator = binding.operator;
97
115
  return operator.kind === "Closure"
98
- ? getLevel(operator.body, operator.scope, environment)
116
+ ? getBodyLevel(operator, operator.body, operator.scope)
99
117
  : CONSTANT_LEVEL;
100
118
  };
101
119
  const getGlobalLevel = (name: string) => {
@@ -105,6 +123,7 @@ export const getLevel = (
105
123
  if (definition) return getDefinitionLevel(definition, environment);
106
124
  const builtin = environment.builtins.get(environment.substitutions.get(name) ?? name);
107
125
  if (!builtin) return undefined;
126
+ if (builtin.isActionLevel) return ACTION_LEVEL;
108
127
  return builtin.isStateLevel && !builtin.isLevelConstant ? VARIABLE_LEVEL : CONSTANT_LEVEL;
109
128
  };
110
129
  const getNameLevel = (name: string, node: Expression) => {
@@ -124,6 +143,7 @@ export const getLevel = (
124
143
  scope,
125
144
  environment,
126
145
  bound.length === 0 ? shadowed : new Set([...shadowed, ...bound]),
146
+ visiting,
127
147
  ),
128
148
  );
129
149
  return child;
@@ -149,10 +169,29 @@ export const getLevel = (
149
169
  return getNameLevel(expression.name, expression);
150
170
  case "OperatorReference":
151
171
  return getNameLevel(expression.operator, expression);
152
- case "Apply":
172
+ case "Apply": {
153
173
  if (TEMPORAL_OPERATORS.has(expression.operator)) return TEMPORAL_LEVEL;
154
174
  if (expression.operator === "\\cdot") return ACTION_LEVEL;
155
- return Math.max(getNameLevel(expression.operator, expression), getChildrenLevel(expression));
175
+ const operatorLevel = getNameLevel(expression.operator, expression);
176
+ const level = Math.max(operatorLevel, getChildrenLevel(expression));
177
+ const operator = isLocallyResolved(expression)
178
+ ? undefined
179
+ : resolveGlobalOperator(expression.operator, environment);
180
+ if (
181
+ level === operatorLevel ||
182
+ operator?.kind !== "Closure" ||
183
+ operator.params.length !== expression.args.length
184
+ ) {
185
+ return level;
186
+ }
187
+ // SANY counts an argument only where the definition's level depends on its parameter, so
188
+ // ENABLED of an operator argument stays a state predicate.
189
+ return getBodyLevel(
190
+ operator,
191
+ operator.body,
192
+ bindOperatorArguments(operator, expression.args, getConstantContext(environment, scope)),
193
+ );
194
+ }
156
195
  default:
157
196
  return getChildrenLevel(expression);
158
197
  }
@@ -179,10 +218,10 @@ export const expandTemporal = (
179
218
  // Whether TLC expands the formula as a property, which unrolls each \A over a constant set.
180
219
  isProperty: boolean,
181
220
  expanding = new Set<Definition>(),
182
- // Whether the expansion entered the body of an instance's definition. Like TLC, it then no
183
- // longer expands an operator applied to arguments.
221
+ // Whether the expansion entered an instance's definition, after which TLC expands no call.
184
222
  isSubstituted = false,
185
223
  name?: string,
224
+ path: string[] = [],
186
225
  ): ExpandedExpression[] => {
187
226
  const expand = (
188
227
  child: Expression,
@@ -200,6 +239,9 @@ export const expandTemporal = (
200
239
  isSubstituted ||
201
240
  (definition !== undefined && environment.substitutedDefinitions.has(definition)),
202
241
  childName,
242
+ definition?.kind === "Operator" && definition.params.length === 0
243
+ ? [...path, definition.name]
244
+ : path,
203
245
  );
204
246
  if (expression.kind === "And") {
205
247
  return expression.operands.flatMap((operand) => expand(operand, scope, describeRange(operand)));
@@ -210,33 +252,39 @@ export const expandTemporal = (
210
252
  }
211
253
  if (expression.kind === "Identifier") {
212
254
  const binding = isLocallyResolved(expression) ? lookupScope(scope, expression.name) : undefined;
213
- if (binding?.kind === "Thunk") {
214
- return expand(binding.expression, binding.scope);
255
+ if (binding?.kind === "Thunk" && !binding.isReleased) {
256
+ return expand(
257
+ binding.expression,
258
+ binding.scope,
259
+ definitionThunks.has(binding) ? expression.name : name,
260
+ );
215
261
  }
216
262
  const definition = environment.constants.has(expression.name)
217
263
  ? undefined
218
264
  : getDefinition(expression.name, environment);
265
+ // TLC expands a definition it didn't compute at startup, even a constant one.
219
266
  if (
220
267
  !binding &&
221
268
  definition?.kind === "Operator" &&
222
269
  definition.params.length === 0 &&
223
- getDefinitionLevel(definition, environment) > CONSTANT_LEVEL
270
+ (getDefinitionLevel(definition, environment) > CONSTANT_LEVEL ||
271
+ getStartupValue(definition, environment) === undefined)
224
272
  ) {
225
273
  if (expanding.has(definition)) {
226
274
  throw createStackOverflowError();
227
275
  }
276
+ // TLC names a part after the operator as the spec writes it, as I!Op outside the instance.
228
277
  return expand(
229
278
  definition.body,
230
279
  undefined,
231
- definition.name,
280
+ (!isSubstituted && environment.instanceNames.get(expression.name)) || definition.name,
232
281
  new Set([...expanding, definition]),
233
282
  definition,
234
283
  );
235
284
  }
236
285
  }
237
286
  const context = getConstantContext(environment, scope);
238
- // TLC 1.7.4 never expands an operator applied to arguments. A property expands every one it
239
- // applies, but a specification only the temporal ones.
287
+ // TLC 1.7.4 expands no call, a property every one, and a specification only temporal ones.
240
288
  if (
241
289
  expression.kind === "Apply" &&
242
290
  environment.runtime.version !== "1.7.4" &&
@@ -246,16 +294,21 @@ export const expandTemporal = (
246
294
  const definition = isLocallyResolved(expression)
247
295
  ? undefined
248
296
  : getDefinition(expression.operator, environment);
297
+ // An instance's definition that takes only the instance's parameters takes no arguments in
298
+ // TLC, which expands it even within the instance.
299
+ const isOwnArgumentFree =
300
+ operator?.kind === "Closure" &&
301
+ operator.params.every((param) => environment.instanceParams.has(param));
249
302
  const isExpandable =
250
303
  operator?.kind === "Closure" &&
251
304
  operator.params.length === expression.args.length &&
252
305
  !definition?.isRecursive &&
253
- !isSubstituted;
306
+ (!isSubstituted || isOwnArgumentFree);
254
307
  if (isExpandable) {
255
308
  return expand(
256
309
  operator.body,
257
310
  bindOperatorArguments(operator, expression.args, context),
258
- expression.operator,
311
+ isSubstituted && definition ? definition.name : expression.operator,
259
312
  expanding,
260
313
  definition,
261
314
  );
@@ -275,7 +328,7 @@ export const expandTemporal = (
275
328
  if (expanded.length === 0) throw createTautologyError();
276
329
  return expanded;
277
330
  }
278
- return [{ expression, scope, name }];
331
+ return [{ expression, scope, name, path }];
279
332
  };
280
333
 
281
334
  const bindLetDefinitions = (
@@ -314,7 +367,16 @@ export const toLiveExpression = (
314
367
  return createBoolean(value);
315
368
  }
316
369
  if (atomLevel === VARIABLE_LEVEL) return { kind: "State", expression, scope };
317
- return { kind: "Action", expression, unchanged: undefined, scope };
370
+ // TLC checks <<A>>_v's subscript before it evaluates A.
371
+ if (expression.kind === "AngleAction") {
372
+ return {
373
+ kind: "Action",
374
+ expression: expression.action,
375
+ subscript: expression.subscript,
376
+ scope,
377
+ };
378
+ }
379
+ return { kind: "Action", expression, subscript: undefined, scope };
318
380
  };
319
381
 
320
382
  const expansion = { depth: 0 };
@@ -332,7 +394,11 @@ export const toLiveExpression = (
332
394
  const result = convert(body, bodyScope);
333
395
  expansion.depth--;
334
396
  const level = getLiveLevel(result);
335
- return level > ACTION_LEVEL ? result : toAtom(expression, scope, level);
397
+ // For a constant body, Liveness#astToLive bounds the level of a temporal call by its own and
398
+ // takes the call for an action, which classifyExpr rejects. tla-ts keeps the constant.
399
+ const isConstantTemporal =
400
+ level === CONSTANT_LEVEL && getLevel(expression, scope, environment) > ACTION_LEVEL;
401
+ return level > ACTION_LEVEL || isConstantTemporal ? result : toAtom(expression, scope, level);
336
402
  };
337
403
 
338
404
  const convertCall = (
@@ -345,7 +411,7 @@ export const toLiveExpression = (
345
411
  isLocallyResolved(expression) || getDefinition(name, environment) === undefined
346
412
  ? lookupScope(scope, name)
347
413
  : undefined;
348
- if (binding?.kind === "Thunk" && definitionThunks.has(binding)) {
414
+ if (binding?.kind === "Thunk" && !binding.isReleased && definitionThunks.has(binding)) {
349
415
  return expandCall(expression, () =>
350
416
  expand(binding.expression, binding.scope, expression, scope),
351
417
  );
@@ -358,8 +424,16 @@ export const toLiveExpression = (
358
424
  : isLocallyResolved(expression)
359
425
  ? resolveOperator(name, context)
360
426
  : resolveGlobalOperator(name, environment);
361
- if (operator?.kind !== "Closure") throw createCannotHandleError(expression);
362
427
  const args = expression.kind === "Apply" ? expression.args : [];
428
+ // An operator constant can be substituted by a conjunction or disjunction, whose arguments
429
+ // TLC translates as it translates its operands.
430
+ const junction =
431
+ operator?.kind === "Builtin" && args.length === 2 ? JUNCTIONS.get(operator.name) : undefined;
432
+ if (junction) {
433
+ const operands = args.map((arg) => convert(arg, scope));
434
+ return toWhole(expression, scope, createJunction(junction, operands));
435
+ }
436
+ if (operator?.kind !== "Closure") throw createCannotHandleError(expression);
363
437
  const isRecursive =
364
438
  !isLocallyResolved(expression) && getDefinition(name, environment)?.isRecursive === true;
365
439
  return expandCall(
@@ -382,8 +456,8 @@ export const toLiveExpression = (
382
456
  );
383
457
  };
384
458
 
385
- // TLC takes an application of an operator whose expansion fails for a formula it can't handle,
386
- // except that TLC after 1.7.4 fails as the expansion of a recursive operator does.
459
+ // TLC can't handle a call whose expansion fails, except that after 1.7.4 it fails as a
460
+ // recursive operator's expansion does.
387
461
  const expandCall = (
388
462
  expression: Expression,
389
463
  expandBody: () => LiveExpression,
@@ -403,17 +477,9 @@ export const toLiveExpression = (
403
477
  scope: Scope | undefined,
404
478
  ) => {
405
479
  const level = getLevel(expression, scope, environment);
406
- const isConstant = expression.bounds.every(
407
- (bound) => getLevel(bound.set, scope, environment) === CONSTANT_LEVEL,
408
- );
409
- if (!isConstant) {
410
- if (level <= ACTION_LEVEL) return toAtom(expression, scope, level);
411
- throw createCannotHandleError(expression);
412
- }
413
480
  const operands: LiveExpression[] = [];
414
481
  const isForall = expression.kind === "Forall";
415
- // TLC takes a quantified formula whose body fails for one it can't handle, and under \A it adds
416
- // the message of a failure that isn't an EvalException.
482
+ // TLC can't handle a quantifier whose body fails, and under \A adds another failure's message.
417
483
  try {
418
484
  forEachBinding(expression.bounds, getConstantContext(environment, scope), (boundScope) => {
419
485
  operands.push(convert(expression.body, boundScope));
@@ -439,8 +505,7 @@ export const toLiveExpression = (
439
505
  return level > ACTION_LEVEL ? parts : toAtom(expression, scope, level);
440
506
  };
441
507
 
442
- // The formulas below temporal level whose parts TLC's Liveness.astToLive translates, as one
443
- // that is constant, such as a quantifier over the empty set, can make the formula constant.
508
+ // A constant translated part, such as a quantifier over {}, can make the whole formula constant.
444
509
  const isTranslatedWhole = (expression: Expression) =>
445
510
  expression.kind === "Label" ||
446
511
  expression.kind === "Let" ||
@@ -541,11 +606,7 @@ export const toLiveExpression = (
541
606
  const taken: LiveExpression = {
542
607
  kind: "Action",
543
608
  expression: expression.action,
544
- unchanged: {
545
- kind: "Unchanged",
546
- expression: expression.subscript,
547
- location: step.location,
548
- },
609
+ subscript: expression.subscript,
549
610
  scope,
550
611
  enabled,
551
612
  };
@@ -586,22 +647,33 @@ export const evaluateLive = (
586
647
  const cached = stateCache.get(expression);
587
648
  if (cached !== undefined) return cached;
588
649
  const context = { environment, scope: expression.scope, state, next: undefined };
589
- const result =
650
+ const value =
590
651
  expression.kind === "State"
591
- ? expectBoolean(evaluate(expression.expression, context), "a temporal property predicate")
652
+ ? evaluate(expression.expression, context)
592
653
  : isEnabled(expression.step, context);
593
- stateCache.set(expression, result);
594
- return result;
654
+ if (typeof value !== "boolean") {
655
+ throw new TlaEvaluationError("A state predicate was evaluated to a non-boolean value.");
656
+ }
657
+ stateCache.set(expression, value);
658
+ return value;
595
659
  }
596
660
  case "Action": {
597
661
  if (expression.enabled && stateCache.get(expression.enabled) === false) return false;
598
- const context = { environment, scope: expression.scope, state, next };
662
+ const scope = expression.scope;
663
+ const subscript = expression.subscript;
599
664
  if (
600
- expression.unchanged &&
601
- expectBoolean(evaluate(expression.unchanged, context), "a subscript")
665
+ subscript &&
666
+ isEqualLikeTlc(
667
+ evaluate(subscript, { environment, scope, state, next: undefined }),
668
+ evaluate(subscript, { environment, scope, state: next, next: undefined }),
669
+ )
602
670
  )
603
671
  return false;
604
- return expectBoolean(evaluate(expression.expression, context), "an action predicate");
672
+ const value = evaluate(expression.expression, { environment, scope, state, next });
673
+ if (typeof value !== "boolean") {
674
+ throw new TlaEvaluationError("Encountered an action predicate that's not a boolean.");
675
+ }
676
+ return value;
605
677
  }
606
678
  case "Not":
607
679
  return !recurse(expression.body);
@@ -5,17 +5,19 @@ import {
5
5
  isSharedFingerprintsFull,
6
6
  writeStateFingerprint,
7
7
  } from "./fingerprints";
8
- import type { CoordinatorMessage, LevelMessage, StartMessage, WorkerMessage } from "./parallel";
8
+ import type { CoordinatorMessage, StartMessage, WorkerMessage } from "./parallel";
9
9
  import { createSearch } from "./search";
10
10
  import { getSuccessors, type Successor } from "./successors";
11
+ import { setFingerprintPolynomial } from "./tlc/fingerprint";
11
12
  import { createTlcOrder } from "./tlc/order";
12
13
  import { OUT_DEGREE_BUCKETS } from "./tlc/summary";
13
14
  import { createStateDecoder, createStateEncoder, type EncodedStates } from "./transfer";
14
15
  import {
15
16
  createCanonicalizer,
16
- getRankedStringCount,
17
+ freezeStringOrder,
18
+ getUnorderedString,
17
19
  setStringOrder,
18
- setValueVersion,
20
+ setValueOptions,
19
21
  type Value,
20
22
  } from "./values";
21
23
  import { createBreak, getParentPort, type Port } from "./worker";
@@ -43,22 +45,23 @@ const runWorker = (start: StartMessage, parent: Port) => {
43
45
  const classes = new Map(start.classes);
44
46
  const order = createTlcOrder(start.source, loadModule);
45
47
  setStringOrder(order.getStringOrder(start.config));
46
- setValueVersion(start.version);
47
- const startupStrings = getRankedStringCount();
48
+ setValueOptions(start);
49
+ setFingerprintPolynomial(start.fingerprintPolynomial ?? 0);
50
+ freezeStringOrder();
48
51
  const specification = createEnvironment(start.config, {
49
52
  source: start.source,
50
53
  loadModule,
51
54
  order,
52
55
  loadClass: (name) => classes.get(name),
53
56
  print: () => {},
54
- files: { readFile: undefined, writeFile: undefined },
57
+ files: { readFile: undefined, writeFile: undefined, makeDirectory: undefined },
55
58
  isTool: start.isTool,
56
- isTraceRecorded: start.isTraceRecorded,
59
+ traceFile: start.traceFile,
57
60
  isWarningEnabled: start.isWarningEnabled,
58
61
  version: start.version,
59
62
  });
60
63
  const environment = specification.environment;
61
- const search = createSearch(start.config, environment, () =>
64
+ const search = createSearch(start.config, environment, specification.variableLocations, () =>
62
65
  order.getDeclarationOrder("variable"),
63
66
  );
64
67
  const nextAction = search?.spec.next;
@@ -188,7 +191,7 @@ const runWorker = (start: StartMessage, parent: Port) => {
188
191
  const report = (message: WorkerMessage) =>
189
192
  parent.postMessage(message, message.type === "level" ? [message.fingerprints.buffer] : []);
190
193
 
191
- const runLevel = async (): Promise<LevelMessage | undefined> => {
194
+ const runLevel = async (): Promise<WorkerMessage | undefined> => {
192
195
  const expansion: Expansion = {
193
196
  states: frontier.states,
194
197
  origin: 0,
@@ -222,7 +225,8 @@ const runWorker = (start: StartMessage, parent: Port) => {
222
225
  }
223
226
  if (!(await steal(expansion))) break;
224
227
  }
225
- if (getRankedStringCount() !== startupStrings) return undefined;
228
+ const unorderedString = getUnorderedString();
229
+ if (unorderedString !== undefined) return { type: "abort", string: unorderedString };
226
230
  frontier.states = expansion.next;
227
231
  Atomics.store(remaining, workerIndex, frontier.states.length);
228
232
  return {