tla-ts 0.0.10-dev.11307be75 → 0.0.10-dev.22f7435d3
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/deciders.cjs +31 -31
- package/dist/deciders.js +30 -30
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +68 -68
- package/dist/prove.js +61 -61
- package/dist/run.cjs +42 -42
- package/dist/run.js +44 -44
- package/dist/transfer.cjs +38 -38
- package/dist/transfer.js +29 -29
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/bags.ts +5 -2
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +9 -6
- package/src/check-trace.ts +116 -64
- package/src/check.ts +343 -166
- package/src/cli/tlc-output.ts +1 -0
- package/src/cli/tlc.ts +3 -2
- package/src/codegen.ts +23 -8
- package/src/dependencies.ts +5 -4
- package/src/dfid.ts +13 -8
- package/src/environment.ts +1 -0
- package/src/evaluate.ts +58 -23
- package/src/exit-codes.ts +27 -13
- package/src/java-hash.ts +14 -0
- package/src/liveness-checker.ts +131 -81
- package/src/liveness.ts +48 -10
- package/src/parser.ts +6 -1
- package/src/prover/smt/solver/arith-rewriter.ts +11 -3
- package/src/prover/smt/solver/array-rewriter.ts +12 -2
- package/src/prover/smt/solver/asserted-formulas.ts +109 -63
- package/src/prover/smt/solver/ast.ts +5 -3
- package/src/prover/smt/solver/auf-solver.ts +23 -12
- package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
- package/src/prover/smt/solver/bound-simplifier.ts +10 -11
- package/src/prover/smt/solver/card2bv.ts +34 -15
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -23
- package/src/prover/smt/solver/context.ts +44 -11
- package/src/prover/smt/solver/dependent-expr-state.ts +19 -13
- package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
- package/src/prover/smt/solver/elim-bounds.ts +89 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +1 -1
- package/src/prover/smt/solver/fd-solver.ts +146 -39
- package/src/prover/smt/solver/internalizer.ts +1 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +4 -0
- package/src/prover/smt/solver/maxcore.ts +2 -1
- package/src/prover/smt/solver/maxsmt-base.ts +1 -0
- package/src/prover/smt/solver/model-checker.ts +1 -1
- package/src/prover/smt/solver/model-evaluator.ts +2 -0
- package/src/prover/smt/solver/model-generator.ts +82 -42
- package/src/prover/smt/solver/muz/dl-context.ts +12 -40
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
- package/src/prover/smt/solver/muz/dl-rule.ts +6 -7
- package/src/prover/smt/solver/muz/hnf.ts +2 -2
- package/src/prover/smt/solver/muz/horn-tactic.ts +14 -1
- package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
- package/src/prover/smt/solver/opt-context.ts +12 -4
- package/src/prover/smt/solver/opt-pareto.ts +19 -0
- package/src/prover/smt/solver/opt-solver.ts +4 -3
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- package/src/prover/smt/solver/poly-rewriter.ts +1 -0
- package/src/prover/smt/solver/proto-model.ts +4 -2
- package/src/prover/smt/solver/push-app-ite.ts +37 -0
- package/src/prover/smt/solver/qsat.ts +23 -8
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
- package/src/prover/smt/solver/rewriter.ts +31 -25
- package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +56 -28
- package/src/prover/smt/solver/sat/sat-tactic.ts +13 -4
- package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
- package/src/prover/smt/solver/smt-consequences.ts +1 -1
- package/src/prover/smt/solver/smt-kernel.ts +39 -4
- package/src/prover/smt/solver/smt-setup.ts +28 -4
- package/src/prover/smt/solver/smtlib-parser.ts +31 -4
- package/src/prover/smt/solver/smtlib-script.ts +219 -82
- package/src/prover/smt/solver/solve-eqs.ts +24 -17
- package/src/prover/smt/solver/solver.ts +18 -3
- package/src/prover/smt/solver/tactic.ts +132 -78
- package/src/prover/smt/solver/theory-bv.ts +11 -1
- package/src/prover/smt/solver/theory-fpa.ts +1 -1
- package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +7 -1
- package/src/prover/smt/solver/theory-lra.ts +1 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
- package/src/resolve.ts +242 -80
- package/src/runtime.ts +4 -0
- package/src/search.ts +161 -92
- package/src/simulate.ts +165 -102
- package/src/spec-description.ts +3 -4
- package/src/standard-modules.ts +56 -22
- package/src/subexpressions.ts +71 -16
- package/src/successors.ts +6 -3
- package/src/symmetry.ts +1 -0
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +22 -14
- package/src/tlc/tlc-operators.ts +7 -7
- package/src/tlc/tlcext-operators.ts +26 -10
- package/src/tlc/trace-spec.ts +6 -20
- package/src/typed-tier.ts +9 -4
- package/src/values.ts +95 -57
package/src/subexpressions.ts
CHANGED
|
@@ -30,7 +30,10 @@ import {
|
|
|
30
30
|
nullSelections,
|
|
31
31
|
operatorSelectionErrors,
|
|
32
32
|
selectionErrors,
|
|
33
|
+
selectionArguments,
|
|
33
34
|
selections,
|
|
35
|
+
selectionSources,
|
|
36
|
+
SELECTION_NAME,
|
|
34
37
|
factReferences,
|
|
35
38
|
type NullSelection,
|
|
36
39
|
type SelectionArguments,
|
|
@@ -56,8 +59,6 @@ interface SelectingName {
|
|
|
56
59
|
argumentRanges?: (SourceRange | undefined)[];
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
const SELECTION_NAME = "$subexpression";
|
|
60
|
-
|
|
61
62
|
const declaredArities = new WeakMap<Definition, number>();
|
|
62
63
|
|
|
63
64
|
const setDeclaredArities = (declarations: Declaration[], definitions: Definition[]) =>
|
|
@@ -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,15 +215,18 @@ 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)
|
|
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) => {
|
|
218
226
|
if (!range) throw createError(message, location);
|
|
219
227
|
selectionErrors.set(reference, {
|
|
220
228
|
applications,
|
|
229
|
+
nulls,
|
|
221
230
|
error: { location: formatRange(range), message },
|
|
222
231
|
});
|
|
223
232
|
isFailed = true;
|
|
@@ -259,14 +268,25 @@ const selectSubexpression = (
|
|
|
259
268
|
if (!isOperator || found.args.length !== 0) return report(range, message);
|
|
260
269
|
deferToExpression(range, message);
|
|
261
270
|
}
|
|
271
|
+
found.args.forEach((arg, index) =>
|
|
272
|
+
selectionArguments.set(arg, {
|
|
273
|
+
operator: found.name,
|
|
274
|
+
index,
|
|
275
|
+
range: reference.selectorRanges?.[selectorIndex],
|
|
276
|
+
}),
|
|
277
|
+
);
|
|
262
278
|
if (isLast) return { definition, args: found.args };
|
|
279
|
+
const range = definition.location.range;
|
|
280
|
+
const isUndefined =
|
|
281
|
+
declaredArities.has(definition) &&
|
|
282
|
+
range?.module === location.range?.module &&
|
|
283
|
+
isBefore(location, definition.location);
|
|
263
284
|
applications.push({
|
|
264
285
|
operator: found.name,
|
|
265
286
|
range: reference.selectorRanges?.[selectorIndex],
|
|
266
287
|
args: found.args,
|
|
267
|
-
params: getParamArities(definition),
|
|
288
|
+
params: isUndefined ? Array(arity).fill(0) : getParamArities(definition),
|
|
268
289
|
});
|
|
269
|
-
const range = definition.location.range;
|
|
270
290
|
if (
|
|
271
291
|
definition.isRecursive &&
|
|
272
292
|
range &&
|
|
@@ -321,15 +341,16 @@ const selectSubexpression = (
|
|
|
321
341
|
(current.kind === "Apply" && current.operator.includes("!"))) &&
|
|
322
342
|
(currentRange?.module !== location.range?.module || isBefore(current.location, location))
|
|
323
343
|
) {
|
|
324
|
-
const selected =
|
|
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.`;
|
|
325
348
|
if (selectionErrors.has(selected)) {
|
|
326
|
-
report(
|
|
327
|
-
range,
|
|
328
|
-
`Choosing operand \`${getSelectorName(selector)}' of subexpression with no operands.`,
|
|
329
|
-
);
|
|
349
|
+
report(range, noOperands);
|
|
330
350
|
return;
|
|
331
351
|
}
|
|
332
352
|
if (selections.has(selected) && selected.kind !== "Lambda") {
|
|
353
|
+
checkNull(selected, noOperands, true);
|
|
333
354
|
current =
|
|
334
355
|
selected.kind === "Let" &&
|
|
335
356
|
selected.body.kind === "Apply" &&
|
|
@@ -356,6 +377,13 @@ const selectSubexpression = (
|
|
|
356
377
|
}
|
|
357
378
|
const binder = getBinder(current);
|
|
358
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
|
+
}
|
|
359
387
|
selection.params.push(...binder.names.map((name) => ({ name, arity: 0 })));
|
|
360
388
|
if (selector.kind === "Bound") {
|
|
361
389
|
selection.args.push(...selector.args);
|
|
@@ -400,6 +428,14 @@ const selectSubexpression = (
|
|
|
400
428
|
current = chosen;
|
|
401
429
|
return;
|
|
402
430
|
}
|
|
431
|
+
if (
|
|
432
|
+
current.kind === "Except" &&
|
|
433
|
+
selector.kind === "Operand" &&
|
|
434
|
+
getOperandIndex(selector.operand, current.updates.length + 1) > 0
|
|
435
|
+
) {
|
|
436
|
+
report(range, "Selecting subexpression of an EXCEPT not yet implemented.");
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
403
439
|
const operands = binder ? binder.sets : getOperands(current);
|
|
404
440
|
if (!operands && current.kind !== "Identifier") {
|
|
405
441
|
report(range, "Selecting subexpression of expression that has none.");
|
|
@@ -426,7 +462,11 @@ const selectSubexpression = (
|
|
|
426
462
|
if (selector.kind === "Name") {
|
|
427
463
|
while (current?.kind === "Label") current = current.body;
|
|
428
464
|
if (current?.kind !== "Let") {
|
|
429
|
-
|
|
465
|
+
report(
|
|
466
|
+
reference.selectorRanges?.[selectorIndex - 1],
|
|
467
|
+
"A name selector here must be from a LET clause.",
|
|
468
|
+
);
|
|
469
|
+
return reference;
|
|
430
470
|
}
|
|
431
471
|
selection.lets.push(current.definitions);
|
|
432
472
|
const last = enterDefinition(current.definitions);
|
|
@@ -445,6 +485,11 @@ const selectSubexpression = (
|
|
|
445
485
|
current,
|
|
446
486
|
"Subexpression selection failed, probably due to an error in the selected expression.",
|
|
447
487
|
);
|
|
488
|
+
checkNull(
|
|
489
|
+
current,
|
|
490
|
+
`Choosing operand \`${getSelectorName(selector)}' of subexpression with no operands.`,
|
|
491
|
+
true,
|
|
492
|
+
);
|
|
448
493
|
}
|
|
449
494
|
selectOperand(selector);
|
|
450
495
|
checkNull(
|
|
@@ -500,16 +545,22 @@ const resolveSubexpressions = (
|
|
|
500
545
|
if (expression.recursive) setDeclaredArities(expression.recursive, expression.definitions);
|
|
501
546
|
const local: Lookup = (name) =>
|
|
502
547
|
expression.definitions.find((definition) => definition.name === name) ?? lookup(name);
|
|
503
|
-
const
|
|
548
|
+
const isLocalGoal = (name: string) =>
|
|
549
|
+
!expression.definitions.some((definition) => definition.name === name) && isGoal(name);
|
|
550
|
+
const mapped = mapChildren(expression, (child) =>
|
|
551
|
+
resolveSubexpressions(child, local, isLocalGoal),
|
|
552
|
+
);
|
|
504
553
|
return mapped.kind === "Let" && mapped.instances
|
|
505
554
|
? {
|
|
506
555
|
...mapped,
|
|
507
|
-
instances: mapped.instances.map((instance) =>
|
|
556
|
+
instances: mapped.instances.map((instance) =>
|
|
557
|
+
resolveInstance(instance, local, isLocalGoal),
|
|
558
|
+
),
|
|
508
559
|
}
|
|
509
560
|
: mapped;
|
|
510
561
|
}
|
|
511
562
|
const callee = expression.kind === "Apply" ? lookup(expression.operator) : undefined;
|
|
512
|
-
const
|
|
563
|
+
const rebuilt =
|
|
513
564
|
expression.kind === "Apply"
|
|
514
565
|
? {
|
|
515
566
|
...expression,
|
|
@@ -523,6 +574,10 @@ const resolveSubexpressions = (
|
|
|
523
574
|
),
|
|
524
575
|
}
|
|
525
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;
|
|
526
581
|
const selectors =
|
|
527
582
|
mapped.kind === "Subexpression"
|
|
528
583
|
? mapped.selectors
|
package/src/successors.ts
CHANGED
|
@@ -1204,7 +1204,9 @@ export const isEnabled = (expression: Expression, context: Context): boolean =>
|
|
|
1204
1204
|
);
|
|
1205
1205
|
}
|
|
1206
1206
|
const environment = context.environment;
|
|
1207
|
-
if (environment.callStack
|
|
1207
|
+
if (environment.callStack || (environment.coverage && environment.coverage.current !== -1)) {
|
|
1208
|
+
return replayEnabled(expression, context.scope, state, environment);
|
|
1209
|
+
}
|
|
1208
1210
|
const run: Run = {
|
|
1209
1211
|
environment,
|
|
1210
1212
|
isInit: false,
|
|
@@ -1341,6 +1343,7 @@ export const hasIncompleteSuccessor = (
|
|
|
1341
1343
|
generator: undefined,
|
|
1342
1344
|
successors: 0,
|
|
1343
1345
|
};
|
|
1346
|
+
// TLC's Tool#getState generates every successor of the action before it compares them.
|
|
1344
1347
|
getRunner(expression, environment, false)(
|
|
1345
1348
|
run,
|
|
1346
1349
|
scope,
|
|
@@ -1348,10 +1351,10 @@ export const hasIncompleteSuccessor = (
|
|
|
1348
1351
|
undefined,
|
|
1349
1352
|
false,
|
|
1350
1353
|
(partial) => {
|
|
1351
|
-
if (!isComplete(partial)) run.
|
|
1354
|
+
if (!isComplete(partial)) run.successors++;
|
|
1352
1355
|
},
|
|
1353
1356
|
);
|
|
1354
|
-
return run.
|
|
1357
|
+
return run.successors > 0;
|
|
1355
1358
|
};
|
|
1356
1359
|
|
|
1357
1360
|
export const getSuccessors = (
|
package/src/symmetry.ts
CHANGED
|
@@ -139,6 +139,7 @@ export const getSymmetryGroup = (
|
|
|
139
139
|
`The set${isPlural ? "s" : ""} ${names.join(", and ")} ${isPlural ? "have" : "has"} been defined to be a symmetry set but contain${isPlural ? "" : "s"} less than two elements.`,
|
|
140
140
|
);
|
|
141
141
|
};
|
|
142
|
+
// Deviation from TLC: MVPerms#permutationSubgroup sizes a util.Set one below the number of permutations, which throws for fewer than two.
|
|
142
143
|
if (permutedSets.length >= elements.length) {
|
|
143
144
|
warnSmallSets(permutedSets);
|
|
144
145
|
return undefined;
|
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
|
@@ -61,7 +61,7 @@ interface Replay {
|
|
|
61
61
|
isEnabled: boolean;
|
|
62
62
|
current: Value[] | undefined;
|
|
63
63
|
onState: (state: Value[]) => void;
|
|
64
|
-
onIncomplete: ((state: State) =>
|
|
64
|
+
onIncomplete: ((state: State) => boolean) | undefined;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
const withFrame = <Result>(replay: Replay, expression: Expression, run: () => Result): Result => {
|
|
@@ -216,8 +216,7 @@ const proceedItems = (
|
|
|
216
216
|
): boolean => {
|
|
217
217
|
if (items === undefined) {
|
|
218
218
|
if (isComplete(partial)) return addState(replay, partial, node);
|
|
219
|
-
replay.onIncomplete?.(partial);
|
|
220
|
-
return false;
|
|
219
|
+
return replay.onIncomplete?.(partial) ?? false;
|
|
221
220
|
}
|
|
222
221
|
if (isComplete(partial) && isAssignedShortcut(replay)) {
|
|
223
222
|
return proceedAssigned(replay, items, partial, node);
|
|
@@ -715,6 +714,7 @@ const visitUnchanged = (
|
|
|
715
714
|
if (index !== undefined) {
|
|
716
715
|
const value = replay.current?.[index];
|
|
717
716
|
if (value === undefined) return false;
|
|
717
|
+
if (replay.isEnabled && replay.coverage) countCoverage(replay.coverage, node);
|
|
718
718
|
const assigned = partial[index];
|
|
719
719
|
if (assigned !== undefined && !isEqualLikeTlc(assigned, value)) {
|
|
720
720
|
warnChangedUnchanged(replay.environment, index, expression);
|
|
@@ -779,11 +779,12 @@ const createReplay = (
|
|
|
779
779
|
kind: "init" | "next" | "enabled",
|
|
780
780
|
current: Value[] | undefined,
|
|
781
781
|
onState: (state: Value[]) => void,
|
|
782
|
-
onIncomplete?: (state: State) =>
|
|
782
|
+
onIncomplete?: (state: State) => boolean,
|
|
783
783
|
): Replay => ({
|
|
784
784
|
environment,
|
|
785
785
|
callStack: environment.callStack,
|
|
786
|
-
coverage:
|
|
786
|
+
coverage:
|
|
787
|
+
kind === "enabled" && environment.coverage?.current === -1 ? undefined : environment.coverage,
|
|
787
788
|
isInit: kind === "init",
|
|
788
789
|
isEnabled: kind === "enabled",
|
|
789
790
|
current,
|
|
@@ -799,17 +800,19 @@ export const replayEnabled = (
|
|
|
799
800
|
state: Value[],
|
|
800
801
|
environment: Environment,
|
|
801
802
|
) => {
|
|
802
|
-
const
|
|
803
|
+
const found = () => {
|
|
803
804
|
throw ENABLED_FOUND;
|
|
804
|
-
}
|
|
805
|
+
};
|
|
806
|
+
const node = environment.coverage?.current ?? -1;
|
|
807
|
+
const replay = createReplay(environment, "enabled", state, found, found);
|
|
805
808
|
const callStack = replay.callStack;
|
|
806
809
|
const depth = callStack?.expressions.length ?? 0;
|
|
807
810
|
try {
|
|
808
811
|
if (expression.kind === "AngleAction" && expression.location === expression.action.location) {
|
|
809
|
-
const changed = createItem("Changed", expression.subscript, scope,
|
|
810
|
-
visit(replay, expression.action, changed, scope, getEmptyState(environment),
|
|
812
|
+
const changed = createItem("Changed", expression.subscript, scope, node, undefined);
|
|
813
|
+
visit(replay, expression.action, changed, scope, getEmptyState(environment), node);
|
|
811
814
|
} else {
|
|
812
|
-
visit(replay, expression, undefined, scope, getEmptyState(environment),
|
|
815
|
+
visit(replay, expression, undefined, scope, getEmptyState(environment), node);
|
|
813
816
|
}
|
|
814
817
|
return false;
|
|
815
818
|
} catch (error) {
|
|
@@ -826,7 +829,7 @@ export const replayInitialStates = (
|
|
|
826
829
|
inits: (ReplayAction & { node?: number })[],
|
|
827
830
|
environment: Environment,
|
|
828
831
|
onState: (state: Value[]) => void,
|
|
829
|
-
onIncomplete?: (state: State) =>
|
|
832
|
+
onIncomplete?: (state: State) => boolean,
|
|
830
833
|
) => {
|
|
831
834
|
const [first, ...others] = inits;
|
|
832
835
|
if (first === undefined) return;
|
|
@@ -838,16 +841,21 @@ export const replayInitialStates = (
|
|
|
838
841
|
visit(replay, first.expression, rest, first.scope, getEmptyState(environment), first.node ?? -1);
|
|
839
842
|
};
|
|
840
843
|
|
|
841
|
-
export const replaySuccessors = <Action extends ReplayAction>(
|
|
844
|
+
export const replaySuccessors = <Action extends ReplayAction & { node?: number }>(
|
|
842
845
|
actions: Action[],
|
|
843
846
|
state: Value[],
|
|
844
847
|
environment: Environment,
|
|
845
848
|
onState: (state: Value[], action: Action) => void,
|
|
846
849
|
) => {
|
|
847
850
|
if (actions.some((action) => LITERAL_KINDS.has(action.expression.kind))) return;
|
|
851
|
+
const coverage = environment.coverage;
|
|
848
852
|
actions.forEach((action) => {
|
|
849
853
|
const successors: Value[][] = [];
|
|
850
|
-
|
|
854
|
+
const node = action.node ?? -1;
|
|
855
|
+
walkSuccessors(action, node, state, environment, (next) => {
|
|
856
|
+
if (coverage && node !== -1) coverage.primary[node]++;
|
|
857
|
+
successors.push(next);
|
|
858
|
+
});
|
|
851
859
|
successors.forEach((successor) => onState(successor, action));
|
|
852
860
|
});
|
|
853
861
|
};
|
|
@@ -858,7 +866,7 @@ export const walkSuccessors = (
|
|
|
858
866
|
state: Value[],
|
|
859
867
|
environment: Environment,
|
|
860
868
|
onState: (state: Value[]) => void,
|
|
861
|
-
onIncomplete?: (state: State) =>
|
|
869
|
+
onIncomplete?: (state: State) => boolean,
|
|
862
870
|
) => {
|
|
863
871
|
const replay = createReplay(environment, "next", state, onState, onIncomplete);
|
|
864
872
|
visit(replay, action.expression, undefined, action.scope, getEmptyState(environment), node);
|
package/src/tlc/tlc-operators.ts
CHANGED
|
@@ -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
|
|
67
|
-
|
|
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:
|
|
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) {
|
package/src/tlc/trace-spec.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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 =
|
|
116
|
+
const constantModules = getHashMapOrder([
|
|
131
117
|
"TLC",
|
|
132
118
|
...(teConstants.length > 0 ? [teConstantsModule] : []),
|
|
133
119
|
]);
|
|
134
|
-
const extendedModules =
|
|
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,
|
|
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,
|
|
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
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
findGlobalName,
|
|
29
29
|
getDefinition,
|
|
30
30
|
getStartupValue,
|
|
31
|
+
isUniformPredicate,
|
|
31
32
|
type Environment,
|
|
32
33
|
type Scope,
|
|
33
34
|
} from "./evaluate";
|
|
@@ -607,6 +608,7 @@ const closeType = (type: Type, path: Type[] = []): Type => {
|
|
|
607
608
|
const resolved = resolveType(type);
|
|
608
609
|
// A function built lazily is only applied, never compared or stored.
|
|
609
610
|
if (resolved.kind === "Lambda") return unsupported();
|
|
611
|
+
if (resolved.kind === "Rec" && resolved.shapes.length === 0) return unsupported();
|
|
610
612
|
if (resolved.kind === "Var") {
|
|
611
613
|
const integer = createInt();
|
|
612
614
|
resolved.target = integer;
|
|
@@ -3405,13 +3407,16 @@ const compileValue = (program: Program, expression: Expression, frame: Frame): C
|
|
|
3405
3407
|
compileValue(program, expression.predicate, { ...frame, scope: bounds.scope }),
|
|
3406
3408
|
);
|
|
3407
3409
|
const result = getName(program, "r");
|
|
3410
|
+
const stop = isUniformPredicate(expression, program.environment)
|
|
3411
|
+
? ` else return ${result};`
|
|
3412
|
+
: "";
|
|
3408
3413
|
const type: SetType = { kind: "Set", element: loop.element };
|
|
3409
3414
|
return {
|
|
3410
3415
|
type,
|
|
3411
3416
|
emit: () =>
|
|
3412
3417
|
isMask(type, program.plains)
|
|
3413
|
-
? `(() => { let ${result} = 0; ${bounds.getHeaders()} { if (${predicate.emit()}) ${result} |= H.bit(${loop.name})
|
|
3414
|
-
: `(() => { const ${result} = []; ${bounds.getHeaders()} { if (${predicate.emit()}) ${result}.push(${loop.name})
|
|
3418
|
+
? `(() => { let ${result} = 0; ${bounds.getHeaders()} { if (${predicate.emit()}) ${result} |= H.bit(${loop.name});${stop} } return ${result}; })()`
|
|
3419
|
+
: `(() => { const ${result} = []; ${bounds.getHeaders()} { if (${predicate.emit()}) ${result}.push(${loop.name});${stop} } return ${result}; })()`,
|
|
3415
3420
|
};
|
|
3416
3421
|
}
|
|
3417
3422
|
case "SetMap": {
|
|
@@ -6373,7 +6378,7 @@ const search = (environment: Environment, check: TypedCheck, plains: Plains): Ty
|
|
|
6373
6378
|
return fingerprinter.words[0];
|
|
6374
6379
|
})()),
|
|
6375
6380
|
// The successors of a state the search expanded are all stored.
|
|
6376
|
-
|
|
6381
|
+
forEachActionSuccessors: (_index, state, onSuccessors) => {
|
|
6377
6382
|
const successors: LiveSuccessor<Plain[]>[] = [];
|
|
6378
6383
|
compiled.next(state, (successor) => {
|
|
6379
6384
|
if (!isInModel(successor)) return;
|
|
@@ -6381,7 +6386,7 @@ const search = (environment: Environment, check: TypedCheck, plains: Plains): Ty
|
|
|
6381
6386
|
const index = findState(false);
|
|
6382
6387
|
successors.push({ index: index === -1 ? deopt() : index, state: successor });
|
|
6383
6388
|
});
|
|
6384
|
-
|
|
6389
|
+
onSuccessors(successors);
|
|
6385
6390
|
},
|
|
6386
6391
|
},
|
|
6387
6392
|
environment.runtime.version !== "1.7.4",
|