tla-ts 0.0.10-dev.a4b81b6d0 → 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 +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +42 -42
- package/dist/prove.js +30 -30
- package/dist/run.cjs +42 -42
- package/dist/run.js +42 -42
- package/dist/transfer.cjs +31 -29
- package/dist/transfer.js +43 -41
- package/dist/worker.cjs +4 -4
- package/dist/worker.js +4 -4
- package/package.json +1 -1
- package/src/ast.ts +10 -1
- package/src/check-failure.ts +5 -6
- package/src/check-trace.ts +4 -4
- package/src/check.ts +78 -90
- package/src/cli/tlc-output.ts +16 -2
- package/src/cli/tlc.ts +2 -2
- package/src/codegen.ts +10 -16
- package/src/coverage.ts +190 -1
- package/src/dependencies.ts +14 -2
- package/src/dfid.ts +80 -27
- package/src/environment.ts +30 -1
- package/src/evaluate.ts +223 -47
- package/src/exit-codes.ts +3 -4
- package/src/instances.ts +11 -1
- package/src/levels.ts +48 -7
- package/src/liveness-checker.ts +123 -70
- 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 +109 -23
- package/src/simulate.ts +114 -124
- package/src/spec-description.ts +3 -0
- package/src/subexpressions.ts +168 -63
- package/src/successors.ts +30 -10
- package/src/tlc/replay.ts +45 -29
- package/src/trace-liveness.ts +529 -0
- package/src/typed-tier.ts +14 -4
- package/src/values.ts +15 -1
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,
|
|
@@ -162,16 +163,16 @@ const createLocal = (generator: Generator) => `local${generator.counter++}`;
|
|
|
162
163
|
const getFreeNames = (expression: Expression, names = new Set<string>()) => {
|
|
163
164
|
const name = getReferencedName(expression);
|
|
164
165
|
if (name !== undefined) names.add(name);
|
|
165
|
-
|
|
166
|
+
if (expression.kind !== "Selection") {
|
|
167
|
+
getChildren(expression).forEach((child) => getFreeNames(child, names));
|
|
168
|
+
}
|
|
166
169
|
return names;
|
|
167
170
|
};
|
|
168
171
|
|
|
169
|
-
const getDelegateContext = (
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
isEveryLocalCaptured = false,
|
|
174
|
-
) => {
|
|
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);
|
|
175
176
|
const freeNames = getFreeNames(expression);
|
|
176
177
|
const captured = [...frame.locals].filter(
|
|
177
178
|
(entry) => isEveryLocalCaptured || freeNames.has(entry[0]),
|
|
@@ -184,13 +185,8 @@ const getDelegateContext = (
|
|
|
184
185
|
return `extend(${frame.context}, ${names}, [${captured.map((entry) => entry[1]).join(", ")}])`;
|
|
185
186
|
};
|
|
186
187
|
|
|
187
|
-
const generateDelegate = (
|
|
188
|
-
generator
|
|
189
|
-
expression: Expression,
|
|
190
|
-
frame: Frame,
|
|
191
|
-
isEveryLocalCaptured = false,
|
|
192
|
-
) =>
|
|
193
|
-
`${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)})`;
|
|
194
190
|
|
|
195
191
|
const generateHelper = (
|
|
196
192
|
generator: Generator,
|
|
@@ -332,8 +328,6 @@ const generateApply = (
|
|
|
332
328
|
const domain = addReference(generator, getDomainOperator(expression));
|
|
333
329
|
return `${domain}(${generateExpression(generator, args[0], frame)})`;
|
|
334
330
|
}
|
|
335
|
-
// TLC caches a constant TLCEval only where no name is bound, so the delegate sees every local.
|
|
336
|
-
if (builtin.name === "TLCEval") return generateDelegate(generator, expression, frame, true);
|
|
337
331
|
if (builtin.name === "\\subseteq" && builtin.evaluateBinary && args.length === 2) {
|
|
338
332
|
const subset = addReference(generator, getSubsetOperator(expression, builtin.evaluateBinary));
|
|
339
333
|
return `${subset}(${generateExpression(generator, args[0], frame)}, ${generateExpression(generator, args[1], frame)})`;
|
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;
|
|
@@ -161,6 +169,7 @@ const collectLocalFacts = (
|
|
|
161
169
|
}
|
|
162
170
|
if (STREAMED_BUILTINS.has(target)) row[0] |= STREAMED;
|
|
163
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
|
|
|
@@ -363,6 +372,9 @@ export const isImpureDefinition = (
|
|
|
363
372
|
effect: keyof typeof EFFECT_FLAGS = "any",
|
|
364
373
|
) => (getRow(definition, environment)[0] & EFFECT_FLAGS[effect]) !== 0;
|
|
365
374
|
|
|
375
|
+
export const isTlcEvalReached = (expression: Expression, environment: Environment) =>
|
|
376
|
+
(getExpressionsRow([expression], environment)[0] & TLC_EVAL) !== 0;
|
|
377
|
+
|
|
366
378
|
export const getDefinitionLevel = (definition: Definition, environment: Environment) => {
|
|
367
379
|
const flags = getRow(definition, environment)[0] & TEMPORAL_LEVEL_FLAGS;
|
|
368
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;
|
package/src/environment.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type Instance,
|
|
10
10
|
type Module,
|
|
11
11
|
type OperatorParam,
|
|
12
|
+
type Proof,
|
|
12
13
|
type SourceLocation,
|
|
13
14
|
} from "./ast";
|
|
14
15
|
import type { ModuleOperator } from "./check";
|
|
@@ -236,6 +237,19 @@ const getSubstitutions = (instances: Instance[]) =>
|
|
|
236
237
|
instance.substitutions.map((substitution) => substitution.expression),
|
|
237
238
|
);
|
|
238
239
|
|
|
240
|
+
const getProofInstances = (proof: Proof | undefined): Instance[] =>
|
|
241
|
+
proof?.kind === "Steps"
|
|
242
|
+
? proof.steps.flatMap((step) => [
|
|
243
|
+
...(step.body.kind === "Instance" ? [step.body] : []),
|
|
244
|
+
...(step.body.kind === "Define"
|
|
245
|
+
? step.body.definitions.flatMap((definition) =>
|
|
246
|
+
definition.kind === "Instance" ? [definition] : [],
|
|
247
|
+
)
|
|
248
|
+
: []),
|
|
249
|
+
...getProofInstances(step.proof),
|
|
250
|
+
])
|
|
251
|
+
: [];
|
|
252
|
+
|
|
239
253
|
const rejectLiterals = (expressions: Expression[]): void =>
|
|
240
254
|
expressions.forEach((expression) => {
|
|
241
255
|
if (expression.kind === "Decimal") throw createRealNumberError(expression);
|
|
@@ -275,9 +289,10 @@ export const createEnvironment = (
|
|
|
275
289
|
const dependencies = new Map<string, Set<string>>();
|
|
276
290
|
const loading: Set<string>[] = [];
|
|
277
291
|
const linking: string[] = [];
|
|
292
|
+
const usedModules = new Set<string>();
|
|
278
293
|
|
|
279
294
|
const useModule = (name: string, used: Iterable<string>) =>
|
|
280
|
-
loading.forEach((closure) => {
|
|
295
|
+
[usedModules, ...loading].forEach((closure) => {
|
|
281
296
|
closure.add(name);
|
|
282
297
|
[...used].forEach((dependency) => closure.add(dependency));
|
|
283
298
|
});
|
|
@@ -896,6 +911,13 @@ export const createEnvironment = (
|
|
|
896
911
|
module.definitions.toReversed().map((definition) => [definition.name, definition]),
|
|
897
912
|
),
|
|
898
913
|
getKey,
|
|
914
|
+
isModuleKnown: (name, location) =>
|
|
915
|
+
name === parsed.name ||
|
|
916
|
+
usedModules.has(name) ||
|
|
917
|
+
scope.modules.has(name) ||
|
|
918
|
+
parsed.modules.some(
|
|
919
|
+
(nested) => nested.name === name && isBefore(nested.location, location),
|
|
920
|
+
),
|
|
899
921
|
instanced,
|
|
900
922
|
facts,
|
|
901
923
|
reports,
|
|
@@ -972,6 +994,13 @@ export const createEnvironment = (
|
|
|
972
994
|
),
|
|
973
995
|
getAvailableDefinitions(visible),
|
|
974
996
|
);
|
|
997
|
+
parsed.theorems
|
|
998
|
+
.flatMap((theorem) => getProofInstances(theorem.proof))
|
|
999
|
+
.filter((instance) => !getVisibleModules().has(instance.module))
|
|
1000
|
+
.forEach(
|
|
1001
|
+
(instance) =>
|
|
1002
|
+
getStandardSymbols(instance.module) ?? getLinkedModule(instance.module, parsed.name),
|
|
1003
|
+
);
|
|
975
1004
|
scope.errors.push(...resolveModule(module, getUnit(module)));
|
|
976
1005
|
module.definitions.forEach((definition) => {
|
|
977
1006
|
const key = getKey(definition);
|