tla-ts 0.0.10-dev.a17d6d9fa → 0.0.10-dev.a5705bfbf
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 +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -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 +64 -64
- package/dist/prove.js +76 -76
- package/dist/run.cjs +42 -42
- package/dist/run.js +44 -44
- package/dist/transfer.cjs +37 -35
- package/dist/transfer.js +43 -41
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +10 -1
- package/src/check-failure.ts +12 -10
- package/src/check-trace.ts +36 -23
- package/src/check.ts +182 -135
- package/src/cli/tlc-output.ts +17 -2
- package/src/cli/tlc.ts +2 -2
- package/src/codegen.ts +15 -19
- package/src/coverage.ts +190 -1
- package/src/dependencies.ts +19 -6
- package/src/dfid.ts +80 -27
- package/src/environment.ts +30 -1
- package/src/evaluate.ts +254 -59
- package/src/exit-codes.ts +25 -13
- package/src/instances.ts +11 -1
- package/src/levels.ts +48 -7
- package/src/liveness-checker.ts +98 -27
- package/src/liveness.ts +4 -1
- package/src/obligations/source.ts +2 -0
- package/src/parser.ts +3 -0
- package/src/prover/smt/solver/card2bv.ts +7 -4
- package/src/prover/smt/solver/context.ts +20 -4
- package/src/prover/smt/solver/dependent-expr-state.ts +18 -12
- package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
- package/src/prover/smt/solver/fd-solver.ts +146 -39
- 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/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 +1 -0
- package/src/prover/smt/solver/opt-solver.ts +1 -1
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- package/src/prover/smt/solver/qsat.ts +7 -2
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +45 -26
- package/src/prover/smt/solver/sat/sat-tactic.ts +4 -2
- 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 +9 -2
- package/src/prover/smt/solver/smtlib-parser.ts +6 -2
- package/src/prover/smt/solver/smtlib-script.ts +197 -73
- package/src/prover/smt/solver/tactic.ts +64 -37
- package/src/resolve.ts +143 -39
- package/src/sany/generator-expressions.ts +2 -0
- package/src/sany/generator-proofs.ts +1 -0
- package/src/search.ts +156 -37
- package/src/simulate.ts +143 -150
- package/src/spec-description.ts +3 -0
- package/src/standard-modules.ts +41 -16
- package/src/subexpressions.ts +168 -63
- package/src/successors.ts +33 -11
- package/src/symmetry.ts +1 -0
- package/src/tlc/replay.ts +64 -41
- package/src/trace-liveness.ts +529 -0
- package/src/typed-tier.ts +20 -6
- package/src/values.ts +15 -1
package/src/cli/tlc-output.ts
CHANGED
|
@@ -472,7 +472,11 @@ const printSuccess = (printer: MessagePrinter, optimistic: number, actual: numbe
|
|
|
472
472
|
].join("\n"),
|
|
473
473
|
);
|
|
474
474
|
|
|
475
|
-
export const printDepthFirst = (
|
|
475
|
+
export const printDepthFirst = (
|
|
476
|
+
printer: MessagePrinter,
|
|
477
|
+
output: DepthFirstOutput,
|
|
478
|
+
startTime: number,
|
|
479
|
+
) => {
|
|
476
480
|
switch (output.kind) {
|
|
477
481
|
case "message":
|
|
478
482
|
printer.print(
|
|
@@ -481,6 +485,9 @@ export const printDepthFirst = (printer: MessagePrinter, output: DepthFirstOutpu
|
|
|
481
485
|
printer.isTool ? output.toolMessage : output.message,
|
|
482
486
|
);
|
|
483
487
|
return;
|
|
488
|
+
case "coverage":
|
|
489
|
+
printCoverage(printer, output.coverage, startTime);
|
|
490
|
+
return;
|
|
484
491
|
case "behavior":
|
|
485
492
|
output.states.forEach((state, index) =>
|
|
486
493
|
output.isInvariant
|
|
@@ -548,6 +555,7 @@ export const printResult = (result: CheckResult, printer: MessagePrinter, timing
|
|
|
548
555
|
printTrace(printer, failure.trace, "error-trace");
|
|
549
556
|
const traceFailure = failure.traceFailure;
|
|
550
557
|
if (traceFailure) {
|
|
558
|
+
printTraceOutput(printer, traceFailure.output);
|
|
551
559
|
print(
|
|
552
560
|
traceFailure.code,
|
|
553
561
|
MESSAGE_LEVEL.error,
|
|
@@ -634,7 +642,11 @@ export const printStartupBanner = (printer: MessagePrinter, args: TlcArguments)
|
|
|
634
642
|
);
|
|
635
643
|
};
|
|
636
644
|
|
|
637
|
-
export const printSimulation = (
|
|
645
|
+
export const printSimulation = (
|
|
646
|
+
printer: MessagePrinter,
|
|
647
|
+
output: SimulationOutput,
|
|
648
|
+
startTime: number,
|
|
649
|
+
) => {
|
|
638
650
|
const print = printer.print;
|
|
639
651
|
switch (output.kind) {
|
|
640
652
|
case "message":
|
|
@@ -644,6 +656,9 @@ export const printSimulation = (printer: MessagePrinter, output: SimulationOutpu
|
|
|
644
656
|
printer.isTool ? output.toolMessage : output.message,
|
|
645
657
|
);
|
|
646
658
|
return;
|
|
659
|
+
case "coverage":
|
|
660
|
+
printCoverage(printer, output.coverage, startTime);
|
|
661
|
+
return;
|
|
647
662
|
case "behavior": {
|
|
648
663
|
const last = output.trace[output.trace.length - 1];
|
|
649
664
|
if (!output.isLastStateOnly) {
|
package/src/cli/tlc.ts
CHANGED
|
@@ -440,7 +440,7 @@ const checkSpec = async (
|
|
|
440
440
|
aril: args.aril,
|
|
441
441
|
isGenerating: args.mode === "generate",
|
|
442
442
|
scheduler: args.scheduler,
|
|
443
|
-
onSimulation: (output) => printSimulation(printer, output),
|
|
443
|
+
onSimulation: (output) => printSimulation(printer, output, timing.startTime),
|
|
444
444
|
});
|
|
445
445
|
printFinished();
|
|
446
446
|
return status;
|
|
@@ -449,7 +449,7 @@ const checkSpec = async (
|
|
|
449
449
|
const status = checkDepthFirst({
|
|
450
450
|
...options,
|
|
451
451
|
maxDepth: args.dfidDepth,
|
|
452
|
-
onOutput: (output) => printDepthFirst(printer, output),
|
|
452
|
+
onOutput: (output) => printDepthFirst(printer, output, timing.startTime),
|
|
453
453
|
});
|
|
454
454
|
printFinished();
|
|
455
455
|
return status;
|
package/src/codegen.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getChildren, getReferencedName, isLocallyResolved, type Expression } from "./ast";
|
|
2
|
+
import { isTlcEvalReached } from "./dependencies";
|
|
2
3
|
import {
|
|
3
4
|
bindValue,
|
|
4
5
|
expectBooleanBody,
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
getFunctionBuilder,
|
|
15
16
|
getLazyFilter,
|
|
16
17
|
isKeptLazy,
|
|
18
|
+
isUniformPredicate,
|
|
17
19
|
getDomainOperator,
|
|
18
20
|
getSubsetOperator,
|
|
19
21
|
getEvaluator,
|
|
@@ -161,16 +163,16 @@ const createLocal = (generator: Generator) => `local${generator.counter++}`;
|
|
|
161
163
|
const getFreeNames = (expression: Expression, names = new Set<string>()) => {
|
|
162
164
|
const name = getReferencedName(expression);
|
|
163
165
|
if (name !== undefined) names.add(name);
|
|
164
|
-
|
|
166
|
+
if (expression.kind !== "Selection") {
|
|
167
|
+
getChildren(expression).forEach((child) => getFreeNames(child, names));
|
|
168
|
+
}
|
|
165
169
|
return names;
|
|
166
170
|
};
|
|
167
171
|
|
|
168
|
-
const getDelegateContext = (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
isEveryLocalCaptured = false,
|
|
173
|
-
) => {
|
|
172
|
+
const getDelegateContext = (generator: Generator, expression: Expression, frame: Frame) => {
|
|
173
|
+
if (frame.locals.size === 0) return frame.context;
|
|
174
|
+
// TLC caches a constant TLCEval only where no name is bound, so a delegate that reaches one sees every local.
|
|
175
|
+
const isEveryLocalCaptured = isTlcEvalReached(expression, generator.environment);
|
|
174
176
|
const freeNames = getFreeNames(expression);
|
|
175
177
|
const captured = [...frame.locals].filter(
|
|
176
178
|
(entry) => isEveryLocalCaptured || freeNames.has(entry[0]),
|
|
@@ -183,13 +185,8 @@ const getDelegateContext = (
|
|
|
183
185
|
return `extend(${frame.context}, ${names}, [${captured.map((entry) => entry[1]).join(", ")}])`;
|
|
184
186
|
};
|
|
185
187
|
|
|
186
|
-
const generateDelegate = (
|
|
187
|
-
generator
|
|
188
|
-
expression: Expression,
|
|
189
|
-
frame: Frame,
|
|
190
|
-
isEveryLocalCaptured = false,
|
|
191
|
-
) =>
|
|
192
|
-
`${addReference(generator, getEvaluator(expression, generator.environment))}(${getDelegateContext(generator, expression, frame, isEveryLocalCaptured)})`;
|
|
188
|
+
const generateDelegate = (generator: Generator, expression: Expression, frame: Frame) =>
|
|
189
|
+
`${addReference(generator, getEvaluator(expression, generator.environment))}(${getDelegateContext(generator, expression, frame)})`;
|
|
193
190
|
|
|
194
191
|
const generateHelper = (
|
|
195
192
|
generator: Generator,
|
|
@@ -279,7 +276,8 @@ const generateSetFilter = (
|
|
|
279
276
|
const lazy = `if (!isReducible(${base})) return ${filterLazily}(${base}, ${getDelegateContext(generator, expression, bodyFrame)});`;
|
|
280
277
|
const set = generateExpression(generator, expression.bound.set, bodyFrame);
|
|
281
278
|
bodyFrame.locals.set(name, element);
|
|
282
|
-
const
|
|
279
|
+
const stop = isUniformPredicate(expression, generator.environment) ? " else break;" : "";
|
|
280
|
+
const test = `if (filterPredicate(${generateExpression(generator, expression.predicate, bodyFrame)}, ${node})) addBounded(${kept}, ${element});${stop}`;
|
|
283
281
|
return `const ${base} = ${set}; ${lazy} const ${list} = ${base}.kind === "Interval" ? ${base} : finiteElements(${base}); const ${kept} = []; ${generateLoop(generator, list, element, test)} return normalizedSet(${kept});`;
|
|
284
282
|
});
|
|
285
283
|
|
|
@@ -330,10 +328,8 @@ const generateApply = (
|
|
|
330
328
|
const domain = addReference(generator, getDomainOperator(expression));
|
|
331
329
|
return `${domain}(${generateExpression(generator, args[0], frame)})`;
|
|
332
330
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if (builtin.name === "\\subseteq" && args.length === 2) {
|
|
336
|
-
const subset = addReference(generator, getSubsetOperator(expression, builtin));
|
|
331
|
+
if (builtin.name === "\\subseteq" && builtin.evaluateBinary && args.length === 2) {
|
|
332
|
+
const subset = addReference(generator, getSubsetOperator(expression, builtin.evaluateBinary));
|
|
337
333
|
return `${subset}(${generateExpression(generator, args[0], frame)}, ${generateExpression(generator, args[1], frame)})`;
|
|
338
334
|
}
|
|
339
335
|
const environment = generator.environment;
|
package/src/coverage.ts
CHANGED
|
@@ -10,7 +10,13 @@ import { formatRange } from "./errors";
|
|
|
10
10
|
import type { Environment, Scope } from "./evaluate";
|
|
11
11
|
import { getJavaHashCode } from "./java-hash";
|
|
12
12
|
import { getTlcFingerprint } from "./tlc/fingerprint";
|
|
13
|
-
import
|
|
13
|
+
import {
|
|
14
|
+
getCardinality,
|
|
15
|
+
isEmptySet,
|
|
16
|
+
isReducibleSet,
|
|
17
|
+
type IntervalValue,
|
|
18
|
+
type Value,
|
|
19
|
+
} from "./values";
|
|
14
20
|
|
|
15
21
|
export type CoverageKind = "init" | "next" | "invariant" | "constraint" | "implied";
|
|
16
22
|
|
|
@@ -49,6 +55,11 @@ export interface CoverageReport {
|
|
|
49
55
|
relations: CoverageRelationReport[];
|
|
50
56
|
}
|
|
51
57
|
|
|
58
|
+
export interface CoverageOutput {
|
|
59
|
+
kind: "coverage";
|
|
60
|
+
coverage: CoverageReport;
|
|
61
|
+
}
|
|
62
|
+
|
|
52
63
|
interface CoverageVariable {
|
|
53
64
|
label: string;
|
|
54
65
|
distinct: number;
|
|
@@ -118,6 +129,17 @@ export const createCoverage = (variableCount: number): Coverage => ({
|
|
|
118
129
|
relations: [],
|
|
119
130
|
});
|
|
120
131
|
|
|
132
|
+
export const createCoverageEnvironment = (
|
|
133
|
+
environment: Environment,
|
|
134
|
+
coverage: Coverage,
|
|
135
|
+
): Environment => ({
|
|
136
|
+
...environment,
|
|
137
|
+
evaluators: new WeakMap(),
|
|
138
|
+
entryEvaluators: new WeakMap(),
|
|
139
|
+
definitionEvaluators: new WeakMap(),
|
|
140
|
+
coverage,
|
|
141
|
+
});
|
|
142
|
+
|
|
121
143
|
const addNode = (
|
|
122
144
|
coverage: Coverage,
|
|
123
145
|
expression: Expression | undefined,
|
|
@@ -380,6 +402,9 @@ export const buildCoverage = (
|
|
|
380
402
|
case "Lambda":
|
|
381
403
|
walk(expression.body, bindNames(expression.params, locals));
|
|
382
404
|
return;
|
|
405
|
+
case "Selection":
|
|
406
|
+
walk(expression.expression, locals);
|
|
407
|
+
return;
|
|
383
408
|
case "Let": {
|
|
384
409
|
const inner = expression.definitions.reduce<Local | undefined>(
|
|
385
410
|
(parent, definition) => ({ name: definition.name, definition, scope: undefined, parent }),
|
|
@@ -602,6 +627,170 @@ export const costCoverage = (coverage: Coverage, value: Value, cost: number) =>
|
|
|
602
627
|
if (node !== undefined) coverage.secondary[node] += cost;
|
|
603
628
|
};
|
|
604
629
|
|
|
630
|
+
export const chargeSetOperation = (
|
|
631
|
+
coverage: Coverage,
|
|
632
|
+
operator: string,
|
|
633
|
+
left: Value,
|
|
634
|
+
right: Value,
|
|
635
|
+
result: Value,
|
|
636
|
+
): Value => {
|
|
637
|
+
const receiver = isReducibleSet(left)
|
|
638
|
+
? left
|
|
639
|
+
: operator !== "\\" && isReducibleSet(right)
|
|
640
|
+
? right
|
|
641
|
+
: undefined;
|
|
642
|
+
if (receiver === undefined || typeof result !== "object") return result;
|
|
643
|
+
const other = receiver === left ? right : left;
|
|
644
|
+
if (operator === "\\cup") {
|
|
645
|
+
if (isEmptySet(receiver) || !isReducibleSet(other)) return result;
|
|
646
|
+
const otherNode = coverage.values.get(other);
|
|
647
|
+
if (otherNode !== undefined) coverage.secondary[otherNode] += getCardinality(other) + 1;
|
|
648
|
+
}
|
|
649
|
+
const node = operator === "\\cup" ? undefined : coverage.values.get(receiver);
|
|
650
|
+
if (coverage.values.get(result) === node) return result;
|
|
651
|
+
const isShared = result === left || result === right || coverage.values.has(result);
|
|
652
|
+
const charged = isShared ? { ...result } : result;
|
|
653
|
+
if (node !== undefined) coverage.values.set(charged, node);
|
|
654
|
+
return charged;
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
interface ChargedEnumerator {
|
|
658
|
+
next: () => boolean;
|
|
659
|
+
reset: () => void;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
const createListEnumerator = (coverage: Coverage, node: number | undefined, size: number) => {
|
|
663
|
+
let position = 0;
|
|
664
|
+
return {
|
|
665
|
+
next: () => {
|
|
666
|
+
if (node !== undefined) coverage.secondary[node]++;
|
|
667
|
+
return position++ < size;
|
|
668
|
+
},
|
|
669
|
+
reset: () => {
|
|
670
|
+
position = 0;
|
|
671
|
+
},
|
|
672
|
+
};
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
const createProductEnumerator = (
|
|
676
|
+
coverage: Coverage,
|
|
677
|
+
node: number,
|
|
678
|
+
sets: Value[],
|
|
679
|
+
): ChargedEnumerator => {
|
|
680
|
+
if (sets.some((set) => isEmptySet(set))) return { next: () => false, reset: () => undefined };
|
|
681
|
+
const enumerators = sets.map((set) =>
|
|
682
|
+
createEnumerator(coverage, set, getCardinality(set), false),
|
|
683
|
+
);
|
|
684
|
+
const advance = () => {
|
|
685
|
+
for (let index = enumerators.length - 1; index > 0; index--) {
|
|
686
|
+
if (enumerators[index].next()) return true;
|
|
687
|
+
enumerators[index].reset();
|
|
688
|
+
enumerators[index].next();
|
|
689
|
+
}
|
|
690
|
+
return enumerators.length > 0 && enumerators[0].next();
|
|
691
|
+
};
|
|
692
|
+
let isDone = !enumerators.every((enumerator) => enumerator.next());
|
|
693
|
+
return {
|
|
694
|
+
next: () => {
|
|
695
|
+
if (isDone) return false;
|
|
696
|
+
coverage.secondary[node] += Math.max(enumerators.length, 1);
|
|
697
|
+
isDone = !advance();
|
|
698
|
+
return true;
|
|
699
|
+
},
|
|
700
|
+
reset: () => {
|
|
701
|
+
enumerators.forEach((enumerator) => {
|
|
702
|
+
enumerator.reset();
|
|
703
|
+
enumerator.next();
|
|
704
|
+
});
|
|
705
|
+
isDone = false;
|
|
706
|
+
},
|
|
707
|
+
};
|
|
708
|
+
};
|
|
709
|
+
|
|
710
|
+
export const createProductSetEnumerator = (coverage: Coverage, set: Value) => {
|
|
711
|
+
const node = typeof set === "object" ? coverage.values.get(set) : undefined;
|
|
712
|
+
if (node === undefined || typeof set !== "object") return undefined;
|
|
713
|
+
if (set.kind === "RecordSet") return createProductEnumerator(coverage, node, set.sets);
|
|
714
|
+
if (set.kind !== "FunctionSet") return undefined;
|
|
715
|
+
return createProductEnumerator(
|
|
716
|
+
coverage,
|
|
717
|
+
node,
|
|
718
|
+
Array.from({ length: getCardinality(set.domain) }, () => set.range),
|
|
719
|
+
);
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
const createEnumerator = (
|
|
723
|
+
coverage: Coverage,
|
|
724
|
+
set: Value,
|
|
725
|
+
size: number,
|
|
726
|
+
isNormalized: boolean,
|
|
727
|
+
): ChargedEnumerator => {
|
|
728
|
+
const node = typeof set === "object" ? coverage.values.get(set) : undefined;
|
|
729
|
+
if (
|
|
730
|
+
typeof set === "object" &&
|
|
731
|
+
(set.kind === "Subset" || (!isNormalized && set.kind === "FilteredSet"))
|
|
732
|
+
) {
|
|
733
|
+
return createListEnumerator(coverage, undefined, size);
|
|
734
|
+
}
|
|
735
|
+
const elements = createProductSetEnumerator(coverage, set);
|
|
736
|
+
if (!elements || node === undefined) return createListEnumerator(coverage, node, size);
|
|
737
|
+
if (!isNormalized) return elements;
|
|
738
|
+
let count = 0;
|
|
739
|
+
while (elements.next()) count++;
|
|
740
|
+
coverage.secondary[node] += count;
|
|
741
|
+
return createListEnumerator(coverage, node, count);
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
export const tagSubset = (coverage: Coverage, set: Value, subset: Value) => {
|
|
745
|
+
const node =
|
|
746
|
+
typeof set === "object" && set.kind === "Subset" ? coverage.values.get(set) : undefined;
|
|
747
|
+
if (node !== undefined && typeof subset === "object") coverage.values.set(subset, node);
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
export const createChargedEnumerator = (
|
|
751
|
+
coverage: Coverage,
|
|
752
|
+
set: Value,
|
|
753
|
+
list: Value[] | IntervalValue,
|
|
754
|
+
isNormalized: boolean,
|
|
755
|
+
) => {
|
|
756
|
+
const size = Array.isArray(list) ? list.length : list.high - list.low + 1;
|
|
757
|
+
if (typeof set !== "object" || set.kind !== "Subset" || !Array.isArray(list)) {
|
|
758
|
+
return createEnumerator(coverage, set, size, isNormalized);
|
|
759
|
+
}
|
|
760
|
+
list.forEach((subset) => tagSubset(coverage, set, subset));
|
|
761
|
+
return createListEnumerator(coverage, undefined, size);
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
const chargeBindings = (enumerators: ChargedEnumerator[]) => {
|
|
765
|
+
enumerators.every((enumerator) => enumerator.next());
|
|
766
|
+
return () => {
|
|
767
|
+
for (let index = 0; index < enumerators.length; index++) {
|
|
768
|
+
if (enumerators[index].next() || index === enumerators.length - 1) return;
|
|
769
|
+
enumerators[index].reset();
|
|
770
|
+
enumerators[index].next();
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
export const chargeContexts = (
|
|
776
|
+
coverage: Coverage,
|
|
777
|
+
sets: Value[],
|
|
778
|
+
lists: (Value[] | IntervalValue)[],
|
|
779
|
+
) =>
|
|
780
|
+
chargeBindings(
|
|
781
|
+
sets.map((set, index) => createChargedEnumerator(coverage, set, lists[index], true)),
|
|
782
|
+
);
|
|
783
|
+
|
|
784
|
+
export const chargeFunctionConstruction = (coverage: Coverage, node: number, sets: Value[]) => {
|
|
785
|
+
const sizes = sets.map((set) => getCardinality(set));
|
|
786
|
+
const advance = chargeBindings(
|
|
787
|
+
sets.map((set, index) => createEnumerator(coverage, set, sizes[index], false)),
|
|
788
|
+
);
|
|
789
|
+
const size = sizes.reduce((product, setSize) => product * setSize, 1);
|
|
790
|
+
for (let index = 0; index < size; index++) advance();
|
|
791
|
+
coverage.secondary[node] += size;
|
|
792
|
+
};
|
|
793
|
+
|
|
605
794
|
const getLeadingZeros = (value: bigint) => {
|
|
606
795
|
const high = Number(value >> 32n);
|
|
607
796
|
return high === 0 ? 32 + Math.clz32(Number(value & 0xffffffffn)) : Math.clz32(high);
|
package/src/dependencies.ts
CHANGED
|
@@ -30,6 +30,7 @@ const ACTION_LEVEL_FLAGS = VARIABLE_LEVEL_FLAGS | 64;
|
|
|
30
30
|
const TEMPORAL_LEVEL_FLAGS = ACTION_LEVEL_FLAGS | 128;
|
|
31
31
|
const RANDOM = 256;
|
|
32
32
|
const ABOVE_CONSTANT_BOUND = 512;
|
|
33
|
+
const TLC_EVAL = 1024;
|
|
33
34
|
|
|
34
35
|
const ACTION_KINDS = new Set<Expression["kind"]>([
|
|
35
36
|
"Prime",
|
|
@@ -106,8 +107,15 @@ const collectLocalFacts = (
|
|
|
106
107
|
}
|
|
107
108
|
return undefined;
|
|
108
109
|
};
|
|
110
|
+
const contexts = new Map<Expression, number>();
|
|
109
111
|
const visit = (node: Expression, isLevelCounted: boolean, isOperatorArgument: boolean) => {
|
|
110
112
|
const kind = node.kind;
|
|
113
|
+
if (kind === "Selection") {
|
|
114
|
+
const seen = contexts.get(node.expression) ?? 0;
|
|
115
|
+
const context = isLevelCounted ? (isOperatorArgument ? 1 : 2) : isOperatorArgument ? 4 : 8;
|
|
116
|
+
if ((seen & context) !== 0) return;
|
|
117
|
+
contexts.set(node.expression, seen | context);
|
|
118
|
+
}
|
|
111
119
|
// TLC's getLevelBound takes an operator argument for a constant.
|
|
112
120
|
const nonconstantFlags = isOperatorArgument ? NONCONSTANT : NONCONSTANT | ABOVE_CONSTANT_BOUND;
|
|
113
121
|
if (
|
|
@@ -134,7 +142,7 @@ const collectLocalFacts = (
|
|
|
134
142
|
const variableIndex = environment.variableIndex.get(name);
|
|
135
143
|
if (
|
|
136
144
|
variableIndex !== undefined ||
|
|
137
|
-
environment.builtins.get(
|
|
145
|
+
environment.builtins.get(target)?.isStateLevel ||
|
|
138
146
|
(definition && environment.variableIndex.has(definition.name))
|
|
139
147
|
) {
|
|
140
148
|
row[0] |= nonconstantFlags;
|
|
@@ -156,11 +164,12 @@ const collectLocalFacts = (
|
|
|
156
164
|
definition.params.length > 0),
|
|
157
165
|
});
|
|
158
166
|
} else {
|
|
159
|
-
if (isImpureBuiltin(
|
|
160
|
-
row[0] |= IMPURE | (
|
|
167
|
+
if (isImpureBuiltin(target, environment)) {
|
|
168
|
+
row[0] |= IMPURE | (target === "Assert" ? 0 : REPEATED_EFFECT);
|
|
161
169
|
}
|
|
162
|
-
if (STREAMED_BUILTINS.has(
|
|
163
|
-
if (RANDOM_BUILTINS.has(
|
|
170
|
+
if (STREAMED_BUILTINS.has(target)) row[0] |= STREAMED;
|
|
171
|
+
if (RANDOM_BUILTINS.has(target)) row[0] |= RANDOM;
|
|
172
|
+
if (target === "TLCEval") row[0] |= TLC_EVAL;
|
|
164
173
|
if (!isOverridden && isImpureBuiltin(target, environment)) row[0] |= READS_IMPURE;
|
|
165
174
|
const builtin = environment.builtins.get(target);
|
|
166
175
|
if (
|
|
@@ -249,7 +258,7 @@ const closeRows = (local: Uint32Array, words: number, edges: Int32Array[], mask:
|
|
|
249
258
|
return closed;
|
|
250
259
|
};
|
|
251
260
|
|
|
252
|
-
const PURITY_MASK = IMPURE | REPEATED_EFFECT | STREAMED | RANDOM;
|
|
261
|
+
const PURITY_MASK = IMPURE | REPEATED_EFFECT | STREAMED | RANDOM | TLC_EVAL;
|
|
253
262
|
const READ_MASK = NONCONSTANT | READS_IMPURE;
|
|
254
263
|
const STARTUP_MASK = NONCONSTANT | ABOVE_CONSTANT_BOUND;
|
|
255
264
|
|
|
@@ -348,6 +357,7 @@ const EFFECT_FLAGS = {
|
|
|
348
357
|
streamed: STREAMED,
|
|
349
358
|
// What a second evaluation shows: output again, or other random draws.
|
|
350
359
|
replayed: REPEATED_EFFECT | RANDOM,
|
|
360
|
+
varying: IMPURE | RANDOM,
|
|
351
361
|
};
|
|
352
362
|
|
|
353
363
|
export const isExpressionImpure = (
|
|
@@ -362,6 +372,9 @@ export const isImpureDefinition = (
|
|
|
362
372
|
effect: keyof typeof EFFECT_FLAGS = "any",
|
|
363
373
|
) => (getRow(definition, environment)[0] & EFFECT_FLAGS[effect]) !== 0;
|
|
364
374
|
|
|
375
|
+
export const isTlcEvalReached = (expression: Expression, environment: Environment) =>
|
|
376
|
+
(getExpressionsRow([expression], environment)[0] & TLC_EVAL) !== 0;
|
|
377
|
+
|
|
365
378
|
export const getDefinitionLevel = (definition: Definition, environment: Environment) => {
|
|
366
379
|
const flags = getRow(definition, environment)[0] & TEMPORAL_LEVEL_FLAGS;
|
|
367
380
|
return flags === TEMPORAL_LEVEL_FLAGS
|
package/src/dfid.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import type { Expression } from "./ast";
|
|
2
2
|
import type { CheckOptions } from "./check";
|
|
3
|
+
import type { CoverageOutput } from "./coverage";
|
|
3
4
|
import {
|
|
4
5
|
getErrorExitCode,
|
|
5
6
|
getUnexpectedException,
|
|
6
7
|
isStackOverflow,
|
|
7
8
|
TlaEvaluationError,
|
|
8
|
-
TlaIncompleteSuccessorError,
|
|
9
9
|
TlaStackOverflowError,
|
|
10
10
|
TlaTooManyStatesError,
|
|
11
11
|
TlaUnsupportedError,
|
|
12
12
|
} from "./errors";
|
|
13
|
-
import { createTracingEnvironment } from "./evaluate";
|
|
13
|
+
import { createTracingEnvironment, type State } from "./evaluate";
|
|
14
14
|
import { EXIT_STATUS, getMessageExitStatus, withLivenessExitCode } from "./exit-codes";
|
|
15
15
|
import { createLivenessChecker } from "./liveness-checker";
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
import {
|
|
17
|
+
addActionCoverage,
|
|
18
|
+
getIncompleteSuccessorMessage,
|
|
19
|
+
prepareSearch,
|
|
20
|
+
reportAssumptionViolation,
|
|
21
|
+
} from "./search";
|
|
22
|
+
import { forEachInitialState, forEachSuccessor, getSuccessors, type Successor } from "./successors";
|
|
19
23
|
import {
|
|
20
24
|
formatNestedMessage,
|
|
21
25
|
formatTlcDate,
|
|
@@ -26,7 +30,8 @@ import {
|
|
|
26
30
|
withUnexpectedException,
|
|
27
31
|
} from "./tlc/messages";
|
|
28
32
|
import { getTlcFingerprint } from "./tlc/fingerprint";
|
|
29
|
-
import {
|
|
33
|
+
import { createJavaRandom } from "./tlc/random";
|
|
34
|
+
import { replayInitialStates, replaySuccessors, walkSuccessors } from "./tlc/replay";
|
|
30
35
|
import { getOptimisticProbability, getActualProbability } from "./tlc/summary";
|
|
31
36
|
import { createModelValue, formatState, getSetBound, isSameValue, type Value } from "./values";
|
|
32
37
|
|
|
@@ -39,6 +44,7 @@ export type DepthFirstOutput =
|
|
|
39
44
|
| { kind: "message"; code: number; isError: boolean; message: string; toolMessage: string }
|
|
40
45
|
| { kind: "behavior"; states: Record<string, Value>[]; isInvariant: boolean }
|
|
41
46
|
| { kind: "nested-expressions"; callStack: Expression[] }
|
|
47
|
+
| CoverageOutput
|
|
42
48
|
| { kind: "success"; optimistic: number; actual: number };
|
|
43
49
|
|
|
44
50
|
interface StateEntry {
|
|
@@ -164,7 +170,10 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
164
170
|
);
|
|
165
171
|
if (assumptionStatus !== undefined) return assumptionStatus;
|
|
166
172
|
|
|
167
|
-
const
|
|
173
|
+
const description = prepared.getDescription();
|
|
174
|
+
const nextActions = description.actions;
|
|
175
|
+
const coverage = prepared.coverage;
|
|
176
|
+
const covered = coverage && addActionCoverage(coverage, environment, description);
|
|
168
177
|
// Deviation from TLC: TLCExt#pickSuccessor casts the DFID checker to ModelChecker and fails, so tla-ts asks as model checking does.
|
|
169
178
|
runtime.getSuccessorAction = (state, next) =>
|
|
170
179
|
nextActions.find((action) =>
|
|
@@ -211,6 +220,8 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
211
220
|
const toRecord = (state: (Value | undefined)[]) =>
|
|
212
221
|
search.toRecord(state.map((value) => value ?? createModelValue("null")));
|
|
213
222
|
const printSummary = () => {
|
|
223
|
+
const report = nextActions.length > 0 ? prepared.getCoverage() : undefined;
|
|
224
|
+
if (report) output({ kind: "coverage", coverage: report });
|
|
214
225
|
const counts = `${generatedCount} states generated, ${statuses.size} distinct states found`;
|
|
215
226
|
if (isTool) {
|
|
216
227
|
message(
|
|
@@ -247,7 +258,13 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
247
258
|
return false;
|
|
248
259
|
};
|
|
249
260
|
const init = search.spec.init;
|
|
250
|
-
if (
|
|
261
|
+
if (covered) {
|
|
262
|
+
replayInitialStates(covered.inits, environment, addGenerated, (partial) =>
|
|
263
|
+
addGenerated([...partial]),
|
|
264
|
+
);
|
|
265
|
+
} else if (init) {
|
|
266
|
+
forEachInitialState(init, environment, addGenerated, search.spec.scope, addGenerated);
|
|
267
|
+
}
|
|
251
268
|
generatedCount = generated.length;
|
|
252
269
|
for (const state of generated) {
|
|
253
270
|
if (!state.every((value) => value !== undefined)) {
|
|
@@ -296,25 +313,56 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
296
313
|
return NO_ERROR;
|
|
297
314
|
};
|
|
298
315
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
316
|
+
let actionSuccessors: Value[][] = [];
|
|
317
|
+
let incompleteSuccessor: State | undefined;
|
|
318
|
+
let actionSuccessorCount = 0;
|
|
319
|
+
const addActionSuccessor = (successor: Value[]) => {
|
|
320
|
+
actionSuccessorCount++;
|
|
321
|
+
if (incompleteSuccessor) return false;
|
|
322
|
+
if (actionSuccessors.length === getSetBound()) throw new TlaTooManyStatesError();
|
|
323
|
+
actionSuccessors.push(successor);
|
|
324
|
+
return false;
|
|
325
|
+
};
|
|
326
|
+
const visitActionSuccessor = (successor: Successor) => addActionSuccessor(successor.state);
|
|
327
|
+
const addIncompleteSuccessor = (partial: State) => {
|
|
328
|
+
actionSuccessorCount++;
|
|
329
|
+
incompleteSuccessor ??= [...partial];
|
|
330
|
+
return true;
|
|
331
|
+
};
|
|
332
|
+
// TLC's Tool#getNextStates generates every successor of the action before DFIDWorker finds an incomplete one.
|
|
333
|
+
const getActionSuccessors = (index: number, state: Value[]) => {
|
|
334
|
+
const action = nextActions[index];
|
|
335
|
+
const coveredAction = covered?.actions[index];
|
|
336
|
+
actionSuccessors = [];
|
|
337
|
+
incompleteSuccessor = undefined;
|
|
338
|
+
actionSuccessorCount = 0;
|
|
339
|
+
if (coverage && coveredAction) {
|
|
340
|
+
walkSuccessors(
|
|
341
|
+
coveredAction,
|
|
342
|
+
coveredAction.node,
|
|
343
|
+
state,
|
|
344
|
+
environment,
|
|
345
|
+
addActionSuccessor,
|
|
346
|
+
addIncompleteSuccessor,
|
|
347
|
+
);
|
|
348
|
+
coverage.primary[coveredAction.node] += actionSuccessorCount;
|
|
349
|
+
} else {
|
|
302
350
|
forEachSuccessor(
|
|
303
351
|
action.expression,
|
|
304
352
|
state,
|
|
305
353
|
environment,
|
|
306
|
-
|
|
307
|
-
if (successors.length === getSetBound()) throw new TlaTooManyStatesError();
|
|
308
|
-
successors.push(successor.state);
|
|
309
|
-
return false;
|
|
310
|
-
},
|
|
354
|
+
visitActionSuccessor,
|
|
311
355
|
action.scope,
|
|
356
|
+
undefined,
|
|
357
|
+
undefined,
|
|
358
|
+
addIncompleteSuccessor,
|
|
312
359
|
);
|
|
313
|
-
return { successors, incomplete: undefined };
|
|
314
|
-
} catch (error) {
|
|
315
|
-
if (!(error instanceof TlaIncompleteSuccessorError)) throw error;
|
|
316
|
-
return { successors, incomplete: error };
|
|
317
360
|
}
|
|
361
|
+
return {
|
|
362
|
+
successors: actionSuccessors,
|
|
363
|
+
incomplete: incompleteSuccessor,
|
|
364
|
+
count: actionSuccessorCount,
|
|
365
|
+
};
|
|
318
366
|
};
|
|
319
367
|
|
|
320
368
|
const findCheckFailure = (state: Value[], successor: Value[], isNew: boolean) => {
|
|
@@ -380,12 +428,12 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
380
428
|
};
|
|
381
429
|
currentState = state;
|
|
382
430
|
try {
|
|
383
|
-
for (
|
|
384
|
-
const
|
|
431
|
+
for (let index = 0; index < nextActions.length; index++) {
|
|
432
|
+
const action = nextActions[index];
|
|
433
|
+
const next = getActionSuccessors(index, state);
|
|
385
434
|
const incomplete = next.incomplete;
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
isDeadlocked &&= count === 0;
|
|
435
|
+
generatedCount += next.count;
|
|
436
|
+
isDeadlocked &&= next.count === 0;
|
|
389
437
|
for (const successor of next.successors) {
|
|
390
438
|
processedSuccessor = successor;
|
|
391
439
|
levels.set(successor, depth + 2);
|
|
@@ -411,11 +459,13 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
411
459
|
if (failure) return report(failure.code, failure.text, !failure.isViolated);
|
|
412
460
|
}
|
|
413
461
|
if (incomplete) {
|
|
414
|
-
processedSuccessor = incomplete
|
|
462
|
+
processedSuccessor = incomplete;
|
|
415
463
|
return report(
|
|
416
464
|
MESSAGE_CODE.incompleteSuccessor,
|
|
417
465
|
getIncompleteSuccessorMessage(
|
|
418
|
-
|
|
466
|
+
environment.variables.filter(
|
|
467
|
+
(_variable, position) => incomplete[position] === undefined,
|
|
468
|
+
),
|
|
419
469
|
action.name,
|
|
420
470
|
nextActions.length,
|
|
421
471
|
options.version,
|
|
@@ -620,6 +670,9 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
620
670
|
);
|
|
621
671
|
fingerprintSet.level++;
|
|
622
672
|
fingerprintSet.leveled = LEVELED - fingerprintSet.leveled;
|
|
673
|
+
// TLC starts a new DFIDWorker thread for each level, whose generator for random values starts over from the seed.
|
|
674
|
+
const random = createJavaRandom(runtime.seed);
|
|
675
|
+
runtime.getRandom = () => random;
|
|
623
676
|
searchLevel(level);
|
|
624
677
|
checker.isDone = false;
|
|
625
678
|
levelCode = checker.isKeepingCallStack ? NO_ERROR : checker.errorCode;
|