tla-ts 0.0.3-dev.07eab97 → 0.0.3-dev.0ad0249
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.
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +160 -46
- package/dist/index.d.ts +160 -46
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +1351 -22
- package/dist/run-cli.js +1351 -22
- package/dist/transfer.cjs +83 -33
- package/dist/transfer.js +83 -33
- package/package.json +4 -1
- package/src/ast.ts +42 -5
- package/src/bags.ts +4 -7
- package/src/builtins.ts +29 -17
- package/src/bundled-modules.ts +3 -3
- package/src/canonical.ts +4 -3
- package/src/check.ts +1296 -429
- package/src/cli.ts +8 -1
- package/src/codegen.ts +68 -21
- package/src/config.ts +225 -206
- package/src/environment.ts +388 -115
- package/src/errors.ts +155 -18
- package/src/evaluate.ts +713 -259
- package/src/exit-codes.ts +6 -24
- package/src/fingerprints.ts +1 -2
- package/src/index.ts +1 -0
- package/src/instances.ts +3 -1
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +37 -27
- package/src/lexer.ts +14 -1
- package/src/live-check.ts +204 -148
- package/src/liveness.ts +191 -122
- package/src/obligation-expression.ts +2 -2
- package/src/obligation-source.ts +2 -0
- package/src/parallel-worker.ts +6 -1
- package/src/parallel.ts +57 -6
- package/src/parser.ts +369 -115
- package/src/pcal-ast.ts +770 -0
- package/src/pcal-parse.ts +1523 -0
- package/src/pcal-tokenize.ts +516 -0
- package/src/pcal-translate.ts +1230 -0
- package/src/pcal-validate.ts +454 -0
- package/src/randomization.ts +24 -7
- package/src/resolve.ts +1332 -453
- package/src/run-cli.ts +1161 -196
- package/src/runtime.ts +16 -0
- package/src/sany-builtins.ts +147 -0
- package/src/sany-generator.ts +3112 -0
- package/src/sany-levels.ts +1208 -0
- package/src/sany-lexer.ts +545 -0
- package/src/sany-linter.ts +122 -0
- package/src/sany-modules.ts +1398 -0
- package/src/sany-nodes.ts +463 -0
- package/src/sany-parse-error.ts +2161 -0
- package/src/sany-report.ts +354 -0
- package/src/sany-selectors.ts +738 -0
- package/src/sany-source.ts +248 -0
- package/src/sany-xml.ts +1017 -0
- package/src/spec-description.ts +25 -5
- package/src/standard-modules.ts +172 -129
- package/src/standard-ranges.ts +116 -0
- package/src/state-graph.ts +29 -6
- package/src/subexpressions.ts +221 -161
- package/src/successors.ts +141 -173
- package/src/symmetry.ts +168 -50
- package/src/tableau.ts +3 -1
- package/src/tlc-ext.ts +13 -17
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +49 -21
- package/src/tlc-modules.ts +0 -4
- package/src/tlc-order.ts +55 -9
- package/src/tlc-random.ts +28 -3
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-version.ts +18 -0
- package/src/transfer.ts +15 -3
- package/src/values.ts +664 -317
package/src/liveness.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { isLocallyResolved, type Definition, type Expression } from "./ast";
|
|
2
|
-
import {
|
|
3
|
-
import { EXIT_STATUS, getOwnExitCode, setExitCode } from "./exit-codes";
|
|
1
|
+
import { isLocallyResolved, type Bound, type Definition, type Expression } from "./ast";
|
|
2
|
+
import { getUnexpectedException, TlaEvaluationError, TlaStackOverflowError } from "./errors";
|
|
4
3
|
import {
|
|
5
|
-
|
|
4
|
+
describeNode,
|
|
6
5
|
describeRange,
|
|
7
6
|
bindDefinitions,
|
|
8
7
|
bindOperatorArguments,
|
|
9
8
|
evaluate,
|
|
10
9
|
expectBoolean,
|
|
11
10
|
forEachBinding,
|
|
11
|
+
forEachBoundElement,
|
|
12
|
+
getBoundElements,
|
|
12
13
|
getDefinition,
|
|
13
14
|
lookupScope,
|
|
14
15
|
resolveApplyOperator,
|
|
@@ -22,6 +23,8 @@ import {
|
|
|
22
23
|
import { mapChildren } from "./instances";
|
|
23
24
|
import { ACTION_LEVEL, TEMPORAL_LEVEL } from "./levels";
|
|
24
25
|
import { isEnabled } from "./successors";
|
|
26
|
+
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
27
|
+
import { isEvalException } from "./tlc-messages";
|
|
25
28
|
import {
|
|
26
29
|
createBoolean,
|
|
27
30
|
createJunction,
|
|
@@ -38,8 +41,10 @@ export interface ScopedExpression {
|
|
|
38
41
|
scope: Scope | undefined;
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
// A part of a temporal formula, with the name TLC gives the part when the formula is a property:
|
|
45
|
+
// a conjunct's location, or the name of the definition the part is the body of.
|
|
46
|
+
interface ExpandedExpression extends ScopedExpression {
|
|
47
|
+
name: string | undefined;
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
export interface TemporalProperty extends ScopedExpression {
|
|
@@ -48,6 +53,15 @@ export interface TemporalProperty extends ScopedExpression {
|
|
|
48
53
|
|
|
49
54
|
const MAXIMUM_EXPANSION_DEPTH = 100;
|
|
50
55
|
|
|
56
|
+
export const createTautologyError = () =>
|
|
57
|
+
setExitCode(
|
|
58
|
+
new TlaEvaluationError("Temporal formula is a tautology (its negation is unsatisfiable)."),
|
|
59
|
+
EXIT_STATUS.livenessEvaluationFailure,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// TLC expands a temporal formula that refers to itself until Java's stack overflows.
|
|
63
|
+
const createStackOverflowError = () => setExitCode(new TlaStackOverflowError(), EXIT_STATUS.error);
|
|
64
|
+
|
|
51
65
|
const TEMPORAL_OPERATORS = new Set(["~>", "-+->"]);
|
|
52
66
|
|
|
53
67
|
const definitionLevels = new WeakMap<Definition, number>();
|
|
@@ -61,26 +75,10 @@ const getConstantContext = (environment: Environment, scope: Scope | undefined):
|
|
|
61
75
|
next: undefined,
|
|
62
76
|
});
|
|
63
77
|
|
|
64
|
-
// TLC
|
|
65
|
-
|
|
66
|
-
const evaluateConstant = (expression: Expression, context: Context) => {
|
|
67
|
-
try {
|
|
68
|
-
return evaluate(expression, context);
|
|
69
|
-
} catch (error) {
|
|
70
|
-
if (!(error instanceof TlaEvaluationError) || error instanceof TlaModuleError) throw error;
|
|
71
|
-
const code = getOwnExitCode(error);
|
|
72
|
-
throw code === undefined
|
|
73
|
-
? setExitCode(
|
|
74
|
-
new TlaEvaluationError(`${UNEXPECTED_EXCEPTION}${error.message}`, error),
|
|
75
|
-
EXIT_STATUS.error,
|
|
76
|
-
)
|
|
77
|
-
: setExitCode(error, code);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const createCannotHandleError = (expression: Expression) =>
|
|
78
|
+
// TLC adds the message of the error that stopped it, when it has one.
|
|
79
|
+
const createCannotHandleError = (expression: Expression, inner?: string) =>
|
|
82
80
|
new TlaEvaluationError(
|
|
83
|
-
`TLC cannot handle the temporal formula
|
|
81
|
+
`TLC cannot handle the temporal formula ${describeRange(expression)}${inner === undefined ? "" : `:\n${inner}`}`,
|
|
84
82
|
);
|
|
85
83
|
|
|
86
84
|
export const getLevel = (
|
|
@@ -103,7 +101,7 @@ export const getLevel = (
|
|
|
103
101
|
const definition = getDefinition(name, environment);
|
|
104
102
|
if (definition) return getDefinitionLevel(definition, environment);
|
|
105
103
|
const builtin = environment.builtins.get(environment.substitutions.get(name) ?? name);
|
|
106
|
-
return builtin ? (builtin.isStateLevel ? 1 : 0) : undefined;
|
|
104
|
+
return builtin ? (builtin.isStateLevel && !builtin.isLevelConstant ? 1 : 0) : undefined;
|
|
107
105
|
};
|
|
108
106
|
const getNameLevel = (name: string, node: Expression) => {
|
|
109
107
|
if (shadowed.has(name)) return 0;
|
|
@@ -167,25 +165,51 @@ const getDefinitionLevel = (definition: Definition, environment: Environment) =>
|
|
|
167
165
|
return level;
|
|
168
166
|
};
|
|
169
167
|
|
|
170
|
-
|
|
168
|
+
// TLC leaves a formula whose sets it fails to enumerate, and doesn't expect an EvalException.
|
|
169
|
+
const getUnrolledElements = (bounds: Bound[], context: Context) => {
|
|
170
|
+
try {
|
|
171
|
+
return getBoundElements(bounds, context);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
174
|
+
if (!isEvalException(error)) return undefined;
|
|
175
|
+
throw setExitCode(
|
|
176
|
+
new TlaEvaluationError(
|
|
177
|
+
`${getUnexpectedException("tlc2.tool.EvalException")}${error.message}`,
|
|
178
|
+
),
|
|
179
|
+
EXIT_STATUS.error,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
171
183
|
|
|
172
|
-
// TLC names each part of a property after the operator it expands, or after the location of the
|
|
173
|
-
// conjunct or quantifier body it splits off.
|
|
174
184
|
export const expandTemporal = (
|
|
175
185
|
expression: Expression,
|
|
176
186
|
scope: Scope | undefined,
|
|
177
187
|
environment: Environment,
|
|
188
|
+
// Whether TLC expands the formula as a property, which unrolls each \A over a constant set.
|
|
178
189
|
isProperty: boolean,
|
|
179
|
-
name = "",
|
|
180
190
|
expanding = new Set<Definition>(),
|
|
181
|
-
|
|
191
|
+
// Whether the expansion entered the body of an instance's definition. Like TLC, it then no
|
|
192
|
+
// longer expands an operator applied to arguments.
|
|
193
|
+
isSubstituted = false,
|
|
194
|
+
name?: string,
|
|
195
|
+
): ExpandedExpression[] => {
|
|
182
196
|
const expand = (
|
|
183
197
|
child: Expression,
|
|
184
198
|
childScope: Scope | undefined,
|
|
185
199
|
childName = name,
|
|
186
200
|
childExpanding = expanding,
|
|
187
|
-
|
|
188
|
-
|
|
201
|
+
definition?: Definition,
|
|
202
|
+
): ExpandedExpression[] =>
|
|
203
|
+
expandTemporal(
|
|
204
|
+
child,
|
|
205
|
+
childScope,
|
|
206
|
+
environment,
|
|
207
|
+
isProperty,
|
|
208
|
+
childExpanding,
|
|
209
|
+
isSubstituted ||
|
|
210
|
+
(definition !== undefined && environment.substitutedDefinitions.has(definition)),
|
|
211
|
+
childName,
|
|
212
|
+
);
|
|
189
213
|
if (expression.kind === "And") {
|
|
190
214
|
return expression.operands.flatMap((operand) => expand(operand, scope, describeRange(operand)));
|
|
191
215
|
}
|
|
@@ -208,26 +232,25 @@ export const expandTemporal = (
|
|
|
208
232
|
getDefinitionLevel(definition, environment) > 0
|
|
209
233
|
) {
|
|
210
234
|
if (expanding.has(definition)) {
|
|
211
|
-
throw
|
|
235
|
+
throw createStackOverflowError();
|
|
212
236
|
}
|
|
213
|
-
|
|
237
|
+
return expand(
|
|
214
238
|
definition.body,
|
|
215
239
|
undefined,
|
|
216
|
-
|
|
240
|
+
definition.name,
|
|
217
241
|
new Set([...expanding, definition]),
|
|
242
|
+
definition,
|
|
218
243
|
);
|
|
219
|
-
// TLC takes the body of a state-level definition in a specification as one initial predicate.
|
|
220
|
-
return !isProperty && getDefinitionLevel(definition, environment) < ACTION_LEVEL
|
|
221
|
-
? [{ expression: definition.body, scope: undefined, name: expression.name }]
|
|
222
|
-
: expanded;
|
|
223
244
|
}
|
|
224
245
|
}
|
|
225
246
|
const context = getConstantContext(environment, scope);
|
|
226
|
-
//
|
|
227
|
-
// specification only
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
247
|
+
// TLC 1.7.4 never expands an operator applied to arguments. A property expands every one it
|
|
248
|
+
// applies, but a specification only the temporal ones.
|
|
249
|
+
if (
|
|
250
|
+
expression.kind === "Apply" &&
|
|
251
|
+
environment.runtime.version !== "1.7.4" &&
|
|
252
|
+
(isProperty || getLevel(expression, scope, environment) === TEMPORAL_LEVEL)
|
|
253
|
+
) {
|
|
231
254
|
const operator = resolveApplyOperator(expression, context);
|
|
232
255
|
const definition = isLocallyResolved(expression)
|
|
233
256
|
? undefined
|
|
@@ -235,12 +258,15 @@ export const expandTemporal = (
|
|
|
235
258
|
const isExpandable =
|
|
236
259
|
operator?.kind === "Closure" &&
|
|
237
260
|
operator.params.length === expression.args.length &&
|
|
238
|
-
!definition?.isRecursive
|
|
261
|
+
!definition?.isRecursive &&
|
|
262
|
+
!isSubstituted;
|
|
239
263
|
if (isExpandable) {
|
|
240
264
|
return expand(
|
|
241
265
|
operator.body,
|
|
242
266
|
bindOperatorArguments(operator, expression.args, context),
|
|
243
267
|
expression.operator,
|
|
268
|
+
expanding,
|
|
269
|
+
definition,
|
|
244
270
|
);
|
|
245
271
|
}
|
|
246
272
|
}
|
|
@@ -248,21 +274,14 @@ export const expandTemporal = (
|
|
|
248
274
|
isProperty &&
|
|
249
275
|
expression.kind === "Forall" &&
|
|
250
276
|
expression.bounds.every((bound) => getLevel(bound.set, scope, environment) === 0);
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
bindings.count++;
|
|
277
|
+
const sets = isUnrolled ? getUnrolledElements(expression.bounds, context) : undefined;
|
|
278
|
+
if (isUnrolled && sets) {
|
|
279
|
+
const expanded: ExpandedExpression[] = [];
|
|
280
|
+
forEachBoundElement(expression.bounds, sets, scope, (boundScope) => {
|
|
256
281
|
expanded.push(...expand(expression.body, boundScope, describeRange(expression.body)));
|
|
257
282
|
return false;
|
|
258
283
|
});
|
|
259
|
-
|
|
260
|
-
if (bindings.count === 0) {
|
|
261
|
-
throw setExitCode(
|
|
262
|
-
new TlaEvaluationError(TAUTOLOGY_MESSAGE),
|
|
263
|
-
EXIT_STATUS.livenessEvaluationFailure,
|
|
264
|
-
);
|
|
265
|
-
}
|
|
284
|
+
if (expanded.length === 0) throw createTautologyError();
|
|
266
285
|
return expanded;
|
|
267
286
|
}
|
|
268
287
|
return [{ expression, scope, name }];
|
|
@@ -292,17 +311,19 @@ export const toLiveExpression = (
|
|
|
292
311
|
rootScope: Scope | undefined,
|
|
293
312
|
environment: Environment,
|
|
294
313
|
): LiveExpression => {
|
|
314
|
+
const is174 = environment.runtime.version === "1.7.4";
|
|
295
315
|
const toAtom = (
|
|
296
316
|
expression: Expression,
|
|
297
317
|
scope: Scope | undefined,
|
|
298
318
|
level: number,
|
|
299
319
|
): LiveExpression => {
|
|
300
|
-
|
|
320
|
+
// TLC after 1.7.4 bounds the level of a formula whose parts are constant by the formula's own.
|
|
321
|
+
const atomLevel = level === 0 && !is174 ? getLevel(expression, scope, environment) : level;
|
|
301
322
|
if (atomLevel === 0) {
|
|
302
|
-
const value =
|
|
323
|
+
const value = evaluate(expression, getConstantContext(environment, scope));
|
|
303
324
|
if (typeof value !== "boolean") {
|
|
304
325
|
throw new TlaEvaluationError(
|
|
305
|
-
`TLC expected a boolean
|
|
326
|
+
`TLC expected a boolean value, but did not find one. ${describeNode(expression)}`,
|
|
306
327
|
);
|
|
307
328
|
}
|
|
308
329
|
return createBoolean(value);
|
|
@@ -320,7 +341,7 @@ export const toLiveExpression = (
|
|
|
320
341
|
scope: Scope | undefined,
|
|
321
342
|
) => {
|
|
322
343
|
if (expansion.depth >= MAXIMUM_EXPANSION_DEPTH) {
|
|
323
|
-
throw
|
|
344
|
+
throw createStackOverflowError();
|
|
324
345
|
}
|
|
325
346
|
expansion.depth++;
|
|
326
347
|
const result = convert(body, bodyScope);
|
|
@@ -340,7 +361,9 @@ export const toLiveExpression = (
|
|
|
340
361
|
? lookupScope(scope, name)
|
|
341
362
|
: undefined;
|
|
342
363
|
if (binding?.kind === "Thunk" && definitionThunks.has(binding)) {
|
|
343
|
-
return
|
|
364
|
+
return expandCall(expression, () =>
|
|
365
|
+
expand(binding.expression, binding.scope, expression, scope),
|
|
366
|
+
);
|
|
344
367
|
}
|
|
345
368
|
const operator =
|
|
346
369
|
binding?.kind === "Operator"
|
|
@@ -352,66 +375,102 @@ export const toLiveExpression = (
|
|
|
352
375
|
: resolveGlobalOperator(name, environment);
|
|
353
376
|
if (operator?.kind !== "Closure") throw createCannotHandleError(expression);
|
|
354
377
|
const args = expression.kind === "Apply" ? expression.args : [];
|
|
355
|
-
|
|
378
|
+
const isRecursive =
|
|
379
|
+
!isLocallyResolved(expression) && getDefinition(name, environment)?.isRecursive === true;
|
|
380
|
+
return expandCall(
|
|
381
|
+
expression,
|
|
382
|
+
() => {
|
|
383
|
+
// TLC 1.7.4 evaluates the arguments of an operator it expands.
|
|
384
|
+
if (is174) {
|
|
385
|
+
args
|
|
386
|
+
.filter((arg) => arg.kind !== "Lambda" && arg.kind !== "OperatorReference")
|
|
387
|
+
.forEach((arg) => evaluate(arg, context));
|
|
388
|
+
}
|
|
389
|
+
return expand(
|
|
390
|
+
operator.body,
|
|
391
|
+
bindOperatorArguments(operator, args, context),
|
|
392
|
+
expression,
|
|
393
|
+
scope,
|
|
394
|
+
);
|
|
395
|
+
},
|
|
396
|
+
isRecursive,
|
|
397
|
+
);
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
// TLC takes an application of an operator whose expansion fails for a formula it can't handle,
|
|
401
|
+
// except that TLC after 1.7.4 fails as the expansion of a recursive operator does.
|
|
402
|
+
const expandCall = (
|
|
403
|
+
expression: Expression,
|
|
404
|
+
expandBody: () => LiveExpression,
|
|
405
|
+
isRecursive = false,
|
|
406
|
+
) => {
|
|
407
|
+
try {
|
|
408
|
+
return expandBody();
|
|
409
|
+
} catch (error) {
|
|
410
|
+
const isRethrown = error instanceof TlaStackOverflowError || (isRecursive && !is174);
|
|
411
|
+
if (!(error instanceof TlaEvaluationError) || isRethrown) throw error;
|
|
412
|
+
throw createCannotHandleError(expression);
|
|
413
|
+
}
|
|
356
414
|
};
|
|
357
415
|
|
|
358
416
|
const convertQuantifier = (
|
|
359
417
|
expression: Expression & { kind: "Forall" | "Exists" },
|
|
360
418
|
scope: Scope | undefined,
|
|
361
419
|
) => {
|
|
420
|
+
const level = getLevel(expression, scope, environment);
|
|
362
421
|
const isConstant = expression.bounds.every(
|
|
363
422
|
(bound) => getLevel(bound.set, scope, environment) === 0,
|
|
364
423
|
);
|
|
365
|
-
if (!isConstant)
|
|
424
|
+
if (!isConstant) {
|
|
425
|
+
if (level <= ACTION_LEVEL) return toAtom(expression, scope, level);
|
|
426
|
+
throw createCannotHandleError(expression);
|
|
427
|
+
}
|
|
366
428
|
const operands: LiveExpression[] = [];
|
|
367
|
-
forEachBinding(expression.bounds, getConstantContext(environment, scope), (boundScope) => {
|
|
368
|
-
operands.push(convert(expression.body, boundScope));
|
|
369
|
-
return false;
|
|
370
|
-
});
|
|
371
429
|
const isForall = expression.kind === "Forall";
|
|
430
|
+
// TLC takes a quantified formula whose body fails for one it can't handle, and under \A it adds
|
|
431
|
+
// the message of a failure that isn't an EvalException.
|
|
432
|
+
try {
|
|
433
|
+
forEachBinding(expression.bounds, getConstantContext(environment, scope), (boundScope) => {
|
|
434
|
+
operands.push(convert(expression.body, boundScope));
|
|
435
|
+
return false;
|
|
436
|
+
});
|
|
437
|
+
} catch (error) {
|
|
438
|
+
if (!(error instanceof TlaEvaluationError) || error instanceof TlaStackOverflowError) {
|
|
439
|
+
throw error;
|
|
440
|
+
}
|
|
441
|
+
if (level <= ACTION_LEVEL) return toAtom(expression, scope, level);
|
|
442
|
+
throw createCannotHandleError(
|
|
443
|
+
expression,
|
|
444
|
+
isForall && !isEvalException(error) ? error.message : undefined,
|
|
445
|
+
);
|
|
446
|
+
}
|
|
372
447
|
if (operands.length === 0) return createBoolean(isForall);
|
|
373
|
-
|
|
374
|
-
const level = getLiveLevel(result);
|
|
375
|
-
return level > ACTION_LEVEL ? result : toAtom(expression, scope, level);
|
|
448
|
+
return toWhole(expression, scope, createJunction(isForall ? "And" : "Or", operands));
|
|
376
449
|
};
|
|
377
450
|
|
|
378
|
-
// TLC
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
case "Label":
|
|
383
|
-
convert(expression.body, scope);
|
|
384
|
-
return;
|
|
385
|
-
case "Let":
|
|
386
|
-
convert(expression.body, bindLetDefinitions(expression, scope, environment));
|
|
387
|
-
return;
|
|
388
|
-
case "And":
|
|
389
|
-
case "Or":
|
|
390
|
-
for (const operand of expression.operands) convert(operand, scope);
|
|
391
|
-
return;
|
|
392
|
-
case "Apply":
|
|
393
|
-
if (
|
|
394
|
-
expression.operator === "=>" ||
|
|
395
|
-
(expression.operator === "~" && !isLocallyResolved(expression))
|
|
396
|
-
) {
|
|
397
|
-
for (const operand of expression.args) convert(operand, scope);
|
|
398
|
-
}
|
|
399
|
-
return;
|
|
400
|
-
case "If": {
|
|
401
|
-
const condition = convert(expression.condition, scope);
|
|
402
|
-
const branches =
|
|
403
|
-
condition.kind === "Boolean"
|
|
404
|
-
? [condition.value ? expression.consequent : expression.alternative]
|
|
405
|
-
: [expression.consequent, expression.alternative];
|
|
406
|
-
for (const branch of branches) convert(branch, scope);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
451
|
+
// TLC takes a formula whose translated parts are below temporal level whole, at their level.
|
|
452
|
+
const toWhole = (expression: Expression, scope: Scope | undefined, parts: LiveExpression) => {
|
|
453
|
+
const level = getLiveLevel(parts);
|
|
454
|
+
return level > ACTION_LEVEL ? parts : toAtom(expression, scope, level);
|
|
409
455
|
};
|
|
410
456
|
|
|
457
|
+
// The formulas below temporal level whose parts TLC's Liveness.astToLive translates, as one
|
|
458
|
+
// that is constant, such as a quantifier over the empty set, can make the formula constant.
|
|
459
|
+
const isTranslatedWhole = (expression: Expression) =>
|
|
460
|
+
expression.kind === "Label" ||
|
|
461
|
+
expression.kind === "Let" ||
|
|
462
|
+
expression.kind === "And" ||
|
|
463
|
+
expression.kind === "Or" ||
|
|
464
|
+
expression.kind === "Forall" ||
|
|
465
|
+
expression.kind === "Exists" ||
|
|
466
|
+
expression.kind === "If" ||
|
|
467
|
+
(expression.kind === "Apply" &&
|
|
468
|
+
((expression.operator === "~" && !isLocallyResolved(expression)) ||
|
|
469
|
+
expression.operator === "=>"));
|
|
470
|
+
|
|
411
471
|
const convert = (expression: Expression, scope: Scope | undefined): LiveExpression => {
|
|
412
472
|
const level = getLevel(expression, scope, environment);
|
|
413
|
-
if (level <= ACTION_LEVEL) {
|
|
414
|
-
convertOperands(expression, scope);
|
|
473
|
+
if (level <= ACTION_LEVEL && !isTranslatedWhole(expression)) {
|
|
415
474
|
return toAtom(expression, scope, level);
|
|
416
475
|
}
|
|
417
476
|
switch (expression.kind) {
|
|
@@ -434,41 +493,51 @@ export const toLiveExpression = (
|
|
|
434
493
|
);
|
|
435
494
|
}
|
|
436
495
|
if (expression.operator === "~" && !isLocallyResolved(expression)) {
|
|
437
|
-
return createUnary("Not", convert(args[0], scope));
|
|
496
|
+
return toWhole(expression, scope, createUnary("Not", convert(args[0], scope)));
|
|
438
497
|
}
|
|
439
498
|
if (expression.operator === "=>") {
|
|
440
|
-
return
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
convert(args[1], scope),
|
|
499
|
+
return toWhole(
|
|
500
|
+
expression,
|
|
501
|
+
scope,
|
|
502
|
+
createPair("Or", createUnary("Not", convert(args[0], scope)), convert(args[1], scope)),
|
|
444
503
|
);
|
|
445
504
|
}
|
|
446
505
|
return convertCall(expression, scope);
|
|
447
506
|
}
|
|
448
507
|
case "And":
|
|
449
508
|
case "Or":
|
|
450
|
-
return
|
|
451
|
-
expression
|
|
452
|
-
|
|
509
|
+
return toWhole(
|
|
510
|
+
expression,
|
|
511
|
+
scope,
|
|
512
|
+
createJunction(
|
|
513
|
+
expression.kind,
|
|
514
|
+
expression.operands.map((operand) => convert(operand, scope)),
|
|
515
|
+
),
|
|
453
516
|
);
|
|
454
517
|
case "Forall":
|
|
455
518
|
case "Exists":
|
|
456
519
|
return convertQuantifier(expression, scope);
|
|
457
520
|
case "If": {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
getConstantContext(environment, scope),
|
|
462
|
-
);
|
|
521
|
+
// TLC 1.7.4 translates both branches whatever the guard.
|
|
522
|
+
if (!is174 && getLevel(expression.condition, scope, environment) === 0) {
|
|
523
|
+
const condition = evaluate(expression.condition, getConstantContext(environment, scope));
|
|
463
524
|
if (typeof condition === "boolean") {
|
|
464
525
|
return convert(condition ? expression.consequent : expression.alternative, scope);
|
|
465
526
|
}
|
|
466
527
|
}
|
|
467
528
|
const condition = convert(expression.condition, scope);
|
|
468
|
-
return
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
createPair(
|
|
529
|
+
return toWhole(
|
|
530
|
+
expression,
|
|
531
|
+
scope,
|
|
532
|
+
createPair(
|
|
533
|
+
"Or",
|
|
534
|
+
createPair("And", condition, convert(expression.consequent, scope)),
|
|
535
|
+
createPair(
|
|
536
|
+
"And",
|
|
537
|
+
createUnary("Not", condition),
|
|
538
|
+
convert(expression.alternative, scope),
|
|
539
|
+
),
|
|
540
|
+
),
|
|
472
541
|
);
|
|
473
542
|
}
|
|
474
543
|
case "Always":
|
|
@@ -874,7 +874,7 @@ export const mapSelectorArgs = (selector: Selector, map: (arg: Expr) => Expr): S
|
|
|
874
874
|
? { ...selector, args: selector.args.map(map) }
|
|
875
875
|
: selector;
|
|
876
876
|
|
|
877
|
-
|
|
877
|
+
const mapExceptSpecs = (specs: ExceptSpec[], map: (inner: Expr) => Expr): ExceptSpec[] =>
|
|
878
878
|
specs.map((spec) => {
|
|
879
879
|
const value = map(spec.value);
|
|
880
880
|
const trail = spec.trail.map((point): ExceptPoint =>
|
|
@@ -883,7 +883,7 @@ export const mapExceptSpecs = (specs: ExceptSpec[], map: (inner: Expr) => Expr):
|
|
|
883
883
|
return { trail, value };
|
|
884
884
|
});
|
|
885
885
|
|
|
886
|
-
|
|
886
|
+
const mapDefnBody = (definition: Defn, map: (body: Expr) => Expr): Defn =>
|
|
887
887
|
definition.kind === "Operator" || definition.kind === "Bpragma"
|
|
888
888
|
? { ...definition, body: map(definition.body) }
|
|
889
889
|
: definition;
|
package/src/obligation-source.ts
CHANGED
|
@@ -609,6 +609,8 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
609
609
|
);
|
|
610
610
|
case "ExceptAt":
|
|
611
611
|
return at({ kind: "At", isExcept }, { location });
|
|
612
|
+
case "Bracket":
|
|
613
|
+
throw new TlaProofError("Unexpected [ without a function or subscript");
|
|
612
614
|
case "FunctionApplication":
|
|
613
615
|
return at(
|
|
614
616
|
{
|
package/src/parallel-worker.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { getSuccessors, type Successor } from "./successors";
|
|
|
18
18
|
import { getTlcStringOrder, getTlcDeclarationOrder } from "./tlc-order";
|
|
19
19
|
import { OUT_DEGREE_BUCKETS } from "./tlc-summary";
|
|
20
20
|
import { createStateDecoder, createStateEncoder, type EncodedStates } from "./transfer";
|
|
21
|
-
import { getRankedStringCount, setStringOrder, type Value } from "./values";
|
|
21
|
+
import { getRankedStringCount, setStringOrder, setValueVersion, type Value } from "./values";
|
|
22
22
|
|
|
23
23
|
const WORKER_THREADS_MODULE = "node:worker_threads";
|
|
24
24
|
const LOCKED = -1;
|
|
@@ -51,6 +51,7 @@ const run = (start: StartMessage, parent: Port) => {
|
|
|
51
51
|
const loadModule = (name: string) => modules.get(name);
|
|
52
52
|
const classes = new Map(start.classes);
|
|
53
53
|
setStringOrder(getTlcStringOrder(start.source, start.config, loadModule));
|
|
54
|
+
setValueVersion(start.version);
|
|
54
55
|
const startupStrings = getRankedStringCount();
|
|
55
56
|
const specification = createEnvironment(start.config, {
|
|
56
57
|
source: start.source,
|
|
@@ -58,6 +59,10 @@ const run = (start: StartMessage, parent: Port) => {
|
|
|
58
59
|
loadClass: (name) => classes.get(name),
|
|
59
60
|
print: () => {},
|
|
60
61
|
files: { readFile: undefined, writeFile: undefined },
|
|
62
|
+
isTool: start.isTool,
|
|
63
|
+
isTraceRecorded: start.isTraceRecorded,
|
|
64
|
+
isWarningEnabled: start.isWarningEnabled,
|
|
65
|
+
version: start.version,
|
|
61
66
|
});
|
|
62
67
|
const environment = specification.environment;
|
|
63
68
|
const search = createSearch(start.config, environment, () =>
|