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/instances.ts
CHANGED
|
@@ -219,6 +219,8 @@ export const mapChildren = (
|
|
|
219
219
|
};
|
|
220
220
|
case "Label":
|
|
221
221
|
return { ...expression, body: mapUnbound(expression.body) };
|
|
222
|
+
case "Selection":
|
|
223
|
+
return { ...expression, expression: mapUnbound(expression.expression) };
|
|
222
224
|
case "Subexpression":
|
|
223
225
|
return {
|
|
224
226
|
...expression,
|
|
@@ -262,6 +264,7 @@ interface Rewrite {
|
|
|
262
264
|
mode: RewriteMode;
|
|
263
265
|
modes: Map<RewriteMode, Rewrite>;
|
|
264
266
|
bindings?: Map<string, Expression>;
|
|
267
|
+
selections: Map<Expression, Expression>;
|
|
265
268
|
}
|
|
266
269
|
|
|
267
270
|
const getSubstitutionName = (name: string) => `${name}@SUBSTITUTION`;
|
|
@@ -548,6 +551,12 @@ const substitute = (
|
|
|
548
551
|
bound: Map<string, string>,
|
|
549
552
|
): Expression => {
|
|
550
553
|
const recurse = (node: Expression) => substitute(node, rewrite, bound);
|
|
554
|
+
if (expression.kind === "Selection" && [...bound].every((entry) => entry[0] === entry[1])) {
|
|
555
|
+
const selected = expression.expression;
|
|
556
|
+
const substituted = rewrite.selections.get(selected) ?? recurse(selected);
|
|
557
|
+
rewrite.selections.set(selected, substituted);
|
|
558
|
+
return { ...expression, expression: substituted };
|
|
559
|
+
}
|
|
551
560
|
const instantiation = rewrite.instantiation;
|
|
552
561
|
const params = instantiation.params;
|
|
553
562
|
const isFree = (name: string) => !bound.has(name) && !isLocallyResolved(expression);
|
|
@@ -731,7 +740,7 @@ const copyDefinition = (rewrite: Rewrite, key: string): string => {
|
|
|
731
740
|
const bindings = new Map<string, Expression>();
|
|
732
741
|
const bodyRewrite =
|
|
733
742
|
definition.kind === "Operator" && rewrite.mode === "Normal"
|
|
734
|
-
? { ...rewrite, bindings }
|
|
743
|
+
? { ...rewrite, bindings, selections: new Map<Expression, Expression>() }
|
|
735
744
|
: rewrite;
|
|
736
745
|
const mapped = renameParams(
|
|
737
746
|
mapDefinition(definition, (child, bound) =>
|
|
@@ -777,6 +786,7 @@ export const createInstantiation = (instantiation: Instantiation) => {
|
|
|
777
786
|
copies: new Map<string, string>(),
|
|
778
787
|
mode,
|
|
779
788
|
modes,
|
|
789
|
+
selections: new Map<Expression, Expression>(),
|
|
780
790
|
};
|
|
781
791
|
modes.set(mode, created);
|
|
782
792
|
return created;
|
package/src/levels.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type Definition,
|
|
6
6
|
type Expression,
|
|
7
7
|
type Module,
|
|
8
|
+
type NewSymbol,
|
|
8
9
|
type OperatorParam,
|
|
9
10
|
type Proof,
|
|
10
11
|
type ProofStep,
|
|
@@ -48,7 +49,7 @@ interface LevelContext {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
type ScopeEntry =
|
|
51
|
-
| { kind: "Formal"; arity: number }
|
|
52
|
+
| { kind: "Formal"; arity: number; level: number }
|
|
52
53
|
| { kind: "Let"; definition: Definition; scope: Scope };
|
|
53
54
|
|
|
54
55
|
export type Scope = Map<string, ScopeEntry>;
|
|
@@ -67,6 +68,14 @@ export const VARIABLE_LEVEL = 1;
|
|
|
67
68
|
export const ACTION_LEVEL = 2;
|
|
68
69
|
export const TEMPORAL_LEVEL = 3;
|
|
69
70
|
|
|
71
|
+
const NEW_SYMBOL_LEVELS = {
|
|
72
|
+
Constant: CONSTANT_LEVEL,
|
|
73
|
+
Variable: VARIABLE_LEVEL,
|
|
74
|
+
State: VARIABLE_LEVEL,
|
|
75
|
+
Action: ACTION_LEVEL,
|
|
76
|
+
Temporal: TEMPORAL_LEVEL,
|
|
77
|
+
} satisfies Record<NewSymbol["level"], number>;
|
|
78
|
+
|
|
70
79
|
const SEPARATOR = "\u0000";
|
|
71
80
|
|
|
72
81
|
export const getArgumentKey = (operator: string, index: number) =>
|
|
@@ -208,7 +217,7 @@ const bindFormals = (scope: Scope, formals: OperatorParam[]) =>
|
|
|
208
217
|
...scope,
|
|
209
218
|
...formals.map((formal): [string, ScopeEntry] => [
|
|
210
219
|
formal.name,
|
|
211
|
-
{ kind: "Formal", arity: formal.arity },
|
|
220
|
+
{ kind: "Formal", arity: formal.arity, level: CONSTANT_LEVEL },
|
|
212
221
|
]),
|
|
213
222
|
]);
|
|
214
223
|
|
|
@@ -228,11 +237,12 @@ const isOperatorApplication = (expression: Expression) =>
|
|
|
228
237
|
|
|
229
238
|
export const createLevelAnalyzer = (context: LevelContext) => {
|
|
230
239
|
const definitionLevels = new Map<Definition, OperatorLevels>();
|
|
240
|
+
const selectionLevels = new Map<Expression, LevelData>();
|
|
231
241
|
|
|
232
242
|
const resolve = (name: string, scope: Scope): Resolved => {
|
|
233
243
|
const entry = scope.get(name);
|
|
234
244
|
if (entry?.kind === "Formal") {
|
|
235
|
-
return { kind: "Declared", name, level:
|
|
245
|
+
return { kind: "Declared", name, level: entry.level, arity: entry.arity };
|
|
236
246
|
}
|
|
237
247
|
if (entry?.kind === "Let") {
|
|
238
248
|
return { kind: "Defined", levels: analyzeDefinition(entry.definition, entry.scope) };
|
|
@@ -739,6 +749,14 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
739
749
|
);
|
|
740
750
|
case "Label":
|
|
741
751
|
return analyze(expression.body, scope);
|
|
752
|
+
case "Selection": {
|
|
753
|
+
const selected = expression.expression;
|
|
754
|
+
const known = selectionLevels.get(selected);
|
|
755
|
+
if (known) return known;
|
|
756
|
+
const data = analyze(selected, scope);
|
|
757
|
+
selectionLevels.set(selected, data);
|
|
758
|
+
return data;
|
|
759
|
+
}
|
|
742
760
|
case "Subexpression":
|
|
743
761
|
return createData();
|
|
744
762
|
}
|
|
@@ -772,6 +790,7 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
772
790
|
return names;
|
|
773
791
|
case "Lambda":
|
|
774
792
|
case "Let":
|
|
793
|
+
case "Selection":
|
|
775
794
|
return names;
|
|
776
795
|
case "Prime":
|
|
777
796
|
case "Unchanged":
|
|
@@ -808,7 +827,10 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
808
827
|
const inner = bindFormals(scope, formals);
|
|
809
828
|
const data = analyze(body, inner);
|
|
810
829
|
const isFormal = (param: string) => formals.some((formal) => formal.name === param);
|
|
811
|
-
const nonLeibnizNames = getNonLeibnizNames(
|
|
830
|
+
const nonLeibnizNames = getNonLeibnizNames(
|
|
831
|
+
body.kind === "Selection" ? body.expression : body,
|
|
832
|
+
inner,
|
|
833
|
+
);
|
|
812
834
|
const levels: OperatorLevels = {
|
|
813
835
|
...createData(data.level),
|
|
814
836
|
name,
|
|
@@ -889,17 +911,29 @@ export const analyzeAssumeProve = (
|
|
|
889
911
|
assumeProve: AssumeProve,
|
|
890
912
|
scope: Scope,
|
|
891
913
|
analyzer: ReturnType<typeof createLevelAnalyzer>,
|
|
914
|
+
errors: SanyError[] = [],
|
|
892
915
|
): LevelData => {
|
|
893
916
|
const inner = new Map(scope);
|
|
894
917
|
const parts = assumeProve.assumptions.flatMap((assumption) => {
|
|
895
918
|
if (assumption.kind === "NewSymbol") {
|
|
896
919
|
const set = assumption.set && analyzer.analyze(assumption.set, inner);
|
|
897
|
-
|
|
920
|
+
const range = assumption.location.range;
|
|
921
|
+
if (set?.level === TEMPORAL_LEVEL && range) {
|
|
922
|
+
errors.push({
|
|
923
|
+
location: formatRange(range),
|
|
924
|
+
message: "Level error:\nTemporal formula used as set.",
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
inner.set(assumption.name, {
|
|
928
|
+
kind: "Formal",
|
|
929
|
+
arity: assumption.arity,
|
|
930
|
+
level: NEW_SYMBOL_LEVELS[assumption.level],
|
|
931
|
+
});
|
|
898
932
|
return set ? [set] : [];
|
|
899
933
|
}
|
|
900
934
|
return [
|
|
901
935
|
assumption.kind === "AssumeProve"
|
|
902
|
-
? analyzeAssumeProve(assumption, inner, analyzer)
|
|
936
|
+
? analyzeAssumeProve(assumption, inner, analyzer, errors)
|
|
903
937
|
: analyzer.analyze(assumption, inner),
|
|
904
938
|
];
|
|
905
939
|
});
|
|
@@ -964,6 +998,10 @@ export const checkModuleLevels = (
|
|
|
964
998
|
? []
|
|
965
999
|
: proof.steps.flatMap((step) => {
|
|
966
1000
|
const body = step.body;
|
|
1001
|
+
const newSymbolErrors: SanyError[] = [];
|
|
1002
|
+
if (body.kind === "Assert" && body.statement.kind === "AssumeProve") {
|
|
1003
|
+
analyzeAssumeProve(body.statement, new Map(), analyzer, newSymbolErrors);
|
|
1004
|
+
}
|
|
967
1005
|
const isTemporal = () => getStepLevel(step) === TEMPORAL_LEVEL;
|
|
968
1006
|
const pickErrors =
|
|
969
1007
|
body.kind === "Pick" && body.bounds.length > 0 && isTemporal()
|
|
@@ -981,6 +1019,7 @@ export const checkModuleLevels = (
|
|
|
981
1019
|
)
|
|
982
1020
|
: [];
|
|
983
1021
|
return [
|
|
1022
|
+
...newSymbolErrors,
|
|
984
1023
|
...checkProof(step.proof),
|
|
985
1024
|
...pickErrors,
|
|
986
1025
|
...(step.proof?.kind === "Steps" && isTemporal() ? checkTemporalGoal(step.proof) : []),
|
|
@@ -1010,11 +1049,13 @@ export const checkModuleLevels = (
|
|
|
1010
1049
|
...module.theorems.map((theorem) => ({
|
|
1011
1050
|
location: theorem.location,
|
|
1012
1051
|
check: () => {
|
|
1052
|
+
const newSymbolErrors: SanyError[] = [];
|
|
1013
1053
|
const data =
|
|
1014
1054
|
theorem.statement.kind === "AssumeProve"
|
|
1015
|
-
? analyzeAssumeProve(theorem.statement, new Map(), analyzer)
|
|
1055
|
+
? analyzeAssumeProve(theorem.statement, new Map(), analyzer, newSymbolErrors)
|
|
1016
1056
|
: analyzer.analyze(theorem.statement, new Map());
|
|
1017
1057
|
const errors = [
|
|
1058
|
+
...newSymbolErrors,
|
|
1018
1059
|
...checkProof(theorem.proof),
|
|
1019
1060
|
...(data.level === TEMPORAL_LEVEL ? checkTemporalGoal(theorem.proof) : []),
|
|
1020
1061
|
];
|
package/src/liveness-checker.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
type Solution,
|
|
23
23
|
type Tableau,
|
|
24
24
|
} from "./tableau";
|
|
25
|
+
import { findTraceLasso, type TraceLasso } from "./trace-liveness";
|
|
25
26
|
import { isSameValue, type Value } from "./values";
|
|
26
27
|
|
|
27
28
|
export interface LiveSuccessor<State = Value[]> {
|
|
@@ -51,6 +52,16 @@ export interface LivenessChecker {
|
|
|
51
52
|
getViolatedProperties: (path: Value[][], cycleStart: number) => string[];
|
|
52
53
|
}
|
|
53
54
|
|
|
55
|
+
export interface TraceViolation extends TraceLasso {
|
|
56
|
+
properties: string[];
|
|
57
|
+
failures: TlaEvaluationError[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface LivenessChecks {
|
|
61
|
+
solutions: Solution[];
|
|
62
|
+
findTraceViolation: (trace: Value[][], fingerprints: bigint[]) => TraceViolation | undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
54
65
|
export interface LiveGraph<State> {
|
|
55
66
|
branches: number;
|
|
56
67
|
addInitialState: (index: number, state: State) => void;
|
|
@@ -72,9 +83,15 @@ export interface SearchGraph<State> {
|
|
|
72
83
|
index: number,
|
|
73
84
|
state: State,
|
|
74
85
|
onSuccessors: (successors: LiveSuccessor<State>[]) => void,
|
|
86
|
+
replay?: Environment,
|
|
75
87
|
) => void;
|
|
76
88
|
}
|
|
77
89
|
|
|
90
|
+
interface Tracing {
|
|
91
|
+
atoms: LiveAtoms<Value[]>;
|
|
92
|
+
replay: Environment | undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
78
95
|
export interface LiveEvaluation<State> {
|
|
79
96
|
atoms: LiveAtoms<State>;
|
|
80
97
|
// Whether a check's result for a state holds for every step from it.
|
|
@@ -256,13 +273,14 @@ const getLiveFormula = (
|
|
|
256
273
|
const fairness = temporals.map((item) =>
|
|
257
274
|
toLiveExpression(item.expression, item.scope, environment),
|
|
258
275
|
);
|
|
259
|
-
const
|
|
260
|
-
|
|
276
|
+
const checks = properties.map((property) =>
|
|
277
|
+
toLiveExpression(property.expression, property.scope, environment),
|
|
261
278
|
);
|
|
279
|
+
const negations = checks.map((check) => createUnary("Not", check));
|
|
262
280
|
const violation = negations.length === 1 ? negations[0] : createJunction("Or", negations);
|
|
263
281
|
const formula =
|
|
264
282
|
fairness.length === 0 ? violation : createJunction("And", [...fairness, violation]);
|
|
265
|
-
return { formula,
|
|
283
|
+
return { formula, checks };
|
|
266
284
|
};
|
|
267
285
|
|
|
268
286
|
export type LiveAtom = LiveState | LiveEnabled | LiveAction;
|
|
@@ -317,28 +335,83 @@ export const getLiveExpressions = (solutions: Solution[]) =>
|
|
|
317
335
|
getAtomExpressions(atom).map((item) => item.expression),
|
|
318
336
|
);
|
|
319
337
|
|
|
320
|
-
|
|
321
|
-
properties: TemporalProperty[],
|
|
322
|
-
temporals: ScopedExpression[],
|
|
323
|
-
environment: Environment,
|
|
324
|
-
search: SearchGraph<Value[]>,
|
|
325
|
-
): LivenessChecker | undefined => {
|
|
326
|
-
if (properties.length === 0) return undefined;
|
|
327
|
-
const live = getLiveFormula(properties, temporals, environment);
|
|
328
|
-
// A check evaluated once for a state shows what TLC shows when no check repeats an effect. A
|
|
329
|
-
// definition TLC evaluates as it starts repeats nothing, but a scope can bind any definition.
|
|
338
|
+
const isSharingResults = (formula: LiveExpression, environment: Environment) => {
|
|
330
339
|
const formulaAtoms = new Set<LiveAtom>();
|
|
331
|
-
collectAtoms(
|
|
340
|
+
collectAtoms(formula, formulaAtoms);
|
|
332
341
|
const checked = [...formulaAtoms].flatMap(getAtomExpressions);
|
|
333
|
-
|
|
342
|
+
return checked.every((item) => item.scope === undefined)
|
|
334
343
|
? !isExpressionImpure(
|
|
335
344
|
checked.map((item) => item.expression),
|
|
336
345
|
environment,
|
|
337
346
|
"repeated",
|
|
338
347
|
)
|
|
339
348
|
: !hasRepeatedEffects(environment);
|
|
340
|
-
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
const getViolatedProperties = (
|
|
352
|
+
properties: TemporalProperty[],
|
|
353
|
+
checks: LiveExpression[],
|
|
354
|
+
path: Value[][],
|
|
355
|
+
cycleStart: number,
|
|
356
|
+
environment: Environment,
|
|
357
|
+
failures?: TlaEvaluationError[],
|
|
358
|
+
) => [
|
|
359
|
+
...new Set(
|
|
360
|
+
properties
|
|
361
|
+
.filter((_property, position) => {
|
|
362
|
+
try {
|
|
363
|
+
return !evaluateOnLasso(checks[position], path, cycleStart, 0, environment);
|
|
364
|
+
} catch (error) {
|
|
365
|
+
if (!failures || !(error instanceof TlaEvaluationError)) throw error;
|
|
366
|
+
failures.push(error);
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
})
|
|
370
|
+
.map((property) => property.name),
|
|
371
|
+
),
|
|
372
|
+
];
|
|
373
|
+
|
|
374
|
+
export const createLivenessChecks = (
|
|
375
|
+
properties: TemporalProperty[],
|
|
376
|
+
temporals: ScopedExpression[],
|
|
377
|
+
environment: Environment,
|
|
378
|
+
): LivenessChecks | undefined => {
|
|
379
|
+
if (properties.length === 0) return undefined;
|
|
380
|
+
const live = getLiveFormula(properties, temporals, environment);
|
|
381
|
+
const solutions = getSolutions(live.formula);
|
|
382
|
+
const atoms = getInterpretedAtoms(environment);
|
|
383
|
+
const isShared = isSharingResults(live.formula, environment);
|
|
384
|
+
return {
|
|
385
|
+
solutions,
|
|
386
|
+
findTraceViolation: (trace, fingerprints) => {
|
|
387
|
+
const lasso = findTraceLasso(trace, fingerprints, solutions, atoms, isShared);
|
|
388
|
+
if (!lasso) return undefined;
|
|
389
|
+
// Liveness#findViolatedProperties reports a property it fails to evaluate on the lasso and goes on.
|
|
390
|
+
const failures: TlaEvaluationError[] = [];
|
|
391
|
+
const violated = getViolatedProperties(
|
|
392
|
+
properties,
|
|
393
|
+
live.checks,
|
|
394
|
+
lasso.positions.map((position) => trace[position]),
|
|
395
|
+
lasso.cyclePosition - 1,
|
|
396
|
+
environment,
|
|
397
|
+
failures,
|
|
398
|
+
);
|
|
399
|
+
return { ...lasso, properties: violated, failures };
|
|
400
|
+
},
|
|
401
|
+
};
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
export const createLivenessChecker = (
|
|
405
|
+
properties: TemporalProperty[],
|
|
406
|
+
temporals: ScopedExpression[],
|
|
407
|
+
environment: Environment,
|
|
408
|
+
search: SearchGraph<Value[]>,
|
|
409
|
+
): LivenessChecker | undefined => {
|
|
410
|
+
if (properties.length === 0) return undefined;
|
|
411
|
+
const live = getLiveFormula(properties, temporals, environment);
|
|
412
|
+
const isShared = isSharingResults(live.formula, environment);
|
|
341
413
|
const solutions = getSolutions(live.formula);
|
|
414
|
+
const tracing: Tracing = { atoms: getInterpretedAtoms(environment), replay: undefined };
|
|
342
415
|
const graph = createLiveGraph(
|
|
343
416
|
solutions,
|
|
344
417
|
{
|
|
@@ -357,16 +430,22 @@ export const createLivenessChecker = (
|
|
|
357
430
|
}
|
|
358
431
|
},
|
|
359
432
|
},
|
|
360
|
-
|
|
433
|
+
{
|
|
434
|
+
getFingerprint: search.getFingerprint,
|
|
435
|
+
forEachActionSuccessors: (index, state, onSuccessors) =>
|
|
436
|
+
search.forEachActionSuccessors(index, state, onSuccessors, tracing.replay),
|
|
437
|
+
},
|
|
361
438
|
environment.runtime.version !== "1.7.4",
|
|
362
439
|
);
|
|
363
440
|
const traceWith = <Result>(replay: Environment | undefined, run: () => Result) => {
|
|
364
441
|
if (replay === undefined) return run();
|
|
365
442
|
tracing.atoms = getInterpretedAtoms(replay);
|
|
443
|
+
tracing.replay = replay;
|
|
366
444
|
try {
|
|
367
445
|
return run();
|
|
368
446
|
} finally {
|
|
369
447
|
tracing.atoms = getInterpretedAtoms(environment);
|
|
448
|
+
tracing.replay = undefined;
|
|
370
449
|
}
|
|
371
450
|
};
|
|
372
451
|
return {
|
|
@@ -379,16 +458,8 @@ export const createLivenessChecker = (
|
|
|
379
458
|
storeState: graph.storeState,
|
|
380
459
|
getStateCounts: graph.getStateCounts,
|
|
381
460
|
findViolation: graph.findViolation,
|
|
382
|
-
getViolatedProperties: (path, cycleStart) =>
|
|
383
|
-
|
|
384
|
-
properties
|
|
385
|
-
.filter(
|
|
386
|
-
(_property, position) =>
|
|
387
|
-
!evaluateOnLasso(live.negations[position].body, path, cycleStart, 0, environment),
|
|
388
|
-
)
|
|
389
|
-
.map((property) => property.name),
|
|
390
|
-
),
|
|
391
|
-
],
|
|
461
|
+
getViolatedProperties: (path, cycleStart) =>
|
|
462
|
+
getViolatedProperties(properties, live.checks, path, cycleStart, environment),
|
|
392
463
|
};
|
|
393
464
|
};
|
|
394
465
|
|
package/src/liveness.ts
CHANGED
|
@@ -244,6 +244,7 @@ export const expandTemporal = (
|
|
|
244
244
|
return expression.operands.flatMap((operand) => expand(operand, scope, describeRange(operand)));
|
|
245
245
|
}
|
|
246
246
|
if (expression.kind === "Label") return expand(expression.body, scope);
|
|
247
|
+
if (expression.kind === "Selection") return expand(expression.expression, scope);
|
|
247
248
|
if (expression.kind === "Let") {
|
|
248
249
|
return expand(expression.body, bindLetDefinitions(expression, scope, environment));
|
|
249
250
|
}
|
|
@@ -539,6 +540,8 @@ export const toLiveExpression = (
|
|
|
539
540
|
switch (expression.kind) {
|
|
540
541
|
case "Label":
|
|
541
542
|
return convert(expression.body, scope);
|
|
543
|
+
case "Selection":
|
|
544
|
+
return convert(expression.expression, scope);
|
|
542
545
|
case "Let":
|
|
543
546
|
return convert(expression.body, bindLetDefinitions(expression, scope, environment));
|
|
544
547
|
case "Apply": {
|
|
@@ -674,7 +677,7 @@ export const getInterpretedAtoms = (environment: Environment): LiveAtoms<Value[]
|
|
|
674
677
|
},
|
|
675
678
|
});
|
|
676
679
|
|
|
677
|
-
const evaluateLive = <State>(
|
|
680
|
+
export const evaluateLive = <State>(
|
|
678
681
|
expression: LiveExpression,
|
|
679
682
|
state: State,
|
|
680
683
|
next: State | undefined,
|
|
@@ -643,6 +643,8 @@ export const createModuleConverter = (
|
|
|
643
643
|
},
|
|
644
644
|
{ location },
|
|
645
645
|
);
|
|
646
|
+
case "Selection":
|
|
647
|
+
return recurse(expression.expression);
|
|
646
648
|
case "Subexpression": {
|
|
647
649
|
const [head, ...selectors] = expression.selectors;
|
|
648
650
|
if (head.kind !== "Name") throw new TlaProofError("Unexpected subexpression reference");
|
package/src/parser.ts
CHANGED
|
@@ -478,6 +478,8 @@ const getOperatorApplication = (
|
|
|
478
478
|
}
|
|
479
479
|
};
|
|
480
480
|
|
|
481
|
+
export const parenthesizedRanges = new WeakMap<Expression, SourceRange>();
|
|
482
|
+
|
|
481
483
|
export const extractModule = (source: string, name: string) => {
|
|
482
484
|
const header = new RegExp(`^-{4,}\\s*MODULE\\s+${name}\\s*-{3,}$`);
|
|
483
485
|
const lines = source.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
@@ -1344,6 +1346,7 @@ const parse = (
|
|
|
1344
1346
|
case "(": {
|
|
1345
1347
|
const expression = withBracketLayout(() => parseExpression());
|
|
1346
1348
|
expect(")");
|
|
1349
|
+
parenthesizedRanges.set(expression, getRange(start));
|
|
1347
1350
|
return expression;
|
|
1348
1351
|
}
|
|
1349
1352
|
case "[":
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
import type { Goal } from "./goal";
|
|
18
18
|
import { Rational } from "./rational";
|
|
19
19
|
import { Rewriter, type RewriterOptions } from "./rewriter";
|
|
20
|
-
import { runSimplifier } from "./dependent-expr-state";
|
|
20
|
+
import { type DependentExprState, runSimplifier } from "./dependent-expr-state";
|
|
21
21
|
import { RewriterTpl } from "./rewriter-tpl";
|
|
22
22
|
|
|
23
23
|
interface Bound {
|
|
@@ -99,8 +99,8 @@ class CardPbRewriter extends RewriterTpl {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
export const
|
|
103
|
-
|
|
102
|
+
export const createCard2Bv =
|
|
103
|
+
(manager: AstManager, options: RewriterOptions) => (state: DependentExprState) => {
|
|
104
104
|
const rewriter = new Rewriter(manager, options);
|
|
105
105
|
const pbRewriter = new CardPbRewriter(manager);
|
|
106
106
|
let simplified = -1;
|
|
@@ -121,4 +121,7 @@ export const card2bv = (manager: AstManager, goal: Goal, options: RewriterOption
|
|
|
121
121
|
pbRewriter.release();
|
|
122
122
|
},
|
|
123
123
|
};
|
|
124
|
-
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const card2bv = (manager: AstManager, goal: Goal, options: RewriterOptions) =>
|
|
127
|
+
runSimplifier(goal, false, createCard2Bv(manager, options));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SmtInvariantError } from "../../../errors";
|
|
1
2
|
import type { AssertedFormulas } from "./asserted-formulas";
|
|
2
3
|
import {
|
|
3
4
|
AstManager,
|
|
@@ -1286,6 +1287,9 @@ export class Context extends Internalizer {
|
|
|
1286
1287
|
}
|
|
1287
1288
|
|
|
1288
1289
|
private mkProtoModel() {
|
|
1290
|
+
const failure = this.lastSearchFailure;
|
|
1291
|
+
if (this.hasCaseSplits() || failure === FAILURE_CANCELED || failure === FAILURE_NUM_CONFLICTS)
|
|
1292
|
+
return undefined;
|
|
1289
1293
|
if (this.modelState.kind !== "none") this.modelState.generated.model.decRef();
|
|
1290
1294
|
const generated = mkModel(this);
|
|
1291
1295
|
generated.model.incRef();
|
|
@@ -1328,9 +1332,11 @@ export class Context extends Internalizer {
|
|
|
1328
1332
|
}
|
|
1329
1333
|
|
|
1330
1334
|
getModel() {
|
|
1335
|
+
if (this.isInconsistent()) return undefined;
|
|
1331
1336
|
if (this.modelState.kind === "final") return this.modelState.model;
|
|
1332
1337
|
const generated =
|
|
1333
1338
|
this.modelState.kind === "proto" ? this.modelState.generated : this.mkProtoModel();
|
|
1339
|
+
if (generated === undefined) return undefined;
|
|
1334
1340
|
const model = generated.model.mkModel();
|
|
1335
1341
|
model.addRecFuns();
|
|
1336
1342
|
model.incRef();
|
|
@@ -1338,6 +1344,12 @@ export class Context extends Internalizer {
|
|
|
1338
1344
|
return model;
|
|
1339
1345
|
}
|
|
1340
1346
|
|
|
1347
|
+
getSatModel() {
|
|
1348
|
+
const model = this.getModel();
|
|
1349
|
+
if (model === undefined) throw new SmtInvariantError("a sat answer without a model");
|
|
1350
|
+
return model;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1341
1353
|
validateModel(model: ProtoModel) {
|
|
1342
1354
|
const manager = this.manager;
|
|
1343
1355
|
for (const literal of this.assignedLiterals) {
|
|
@@ -1367,7 +1379,10 @@ export class Context extends Internalizer {
|
|
|
1367
1379
|
)
|
|
1368
1380
|
return status;
|
|
1369
1381
|
const generated = this.mkProtoModel();
|
|
1370
|
-
if (
|
|
1382
|
+
if (
|
|
1383
|
+
generated === undefined ||
|
|
1384
|
+
qmanager.checkModel(generated.model, generated.root2value) !== CHECK_MODEL_RESTART
|
|
1385
|
+
)
|
|
1371
1386
|
return status;
|
|
1372
1387
|
this.lastSearchFailure = FAILURE_OK;
|
|
1373
1388
|
status = L_UNDEF;
|
|
@@ -1377,9 +1392,10 @@ export class Context extends Internalizer {
|
|
|
1377
1392
|
if (status === L_TRUE && qmanager.quantifiers.length === 0) return L_TRUE;
|
|
1378
1393
|
if (status === L_TRUE) {
|
|
1379
1394
|
const generated = this.mkProtoModel();
|
|
1380
|
-
const result =
|
|
1381
|
-
|
|
1382
|
-
|
|
1395
|
+
const result =
|
|
1396
|
+
generated !== undefined && qmanager.isModelBased()
|
|
1397
|
+
? qmanager.checkModel(generated.model, generated.root2value)
|
|
1398
|
+
: CHECK_MODEL_UNKNOWN;
|
|
1383
1399
|
if (result === CHECK_MODEL_SAT) return L_TRUE;
|
|
1384
1400
|
if (result === CHECK_MODEL_UNKNOWN) {
|
|
1385
1401
|
this.lastSearchFailure = FAILURE_QUANTIFIERS;
|
|
@@ -36,15 +36,18 @@ export class DependentExprState {
|
|
|
36
36
|
const manager = this.manager;
|
|
37
37
|
const goal = this.goal;
|
|
38
38
|
let rewritten = -1;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
try {
|
|
40
|
+
this.forEachIndex((index) => {
|
|
41
|
+
const form = this.get(index);
|
|
42
|
+
const next = rewrite(form);
|
|
43
|
+
if (next === -1) return;
|
|
44
|
+
if (rewritten !== -1) manager.decRef(rewritten);
|
|
45
|
+
rewritten = next;
|
|
46
|
+
if (rewritten !== form) goal.update(index, rewritten, goal.getDependency(index));
|
|
47
|
+
});
|
|
48
|
+
} finally {
|
|
43
49
|
if (rewritten !== -1) manager.decRef(rewritten);
|
|
44
|
-
|
|
45
|
-
if (rewritten !== form) goal.update(index, rewritten, goal.getDependency(index));
|
|
46
|
-
});
|
|
47
|
-
if (rewritten !== -1) manager.decRef(rewritten);
|
|
50
|
+
}
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
hasQuantifiers() {
|
|
@@ -79,8 +82,11 @@ export const runSimplifier = (
|
|
|
79
82
|
) => {
|
|
80
83
|
const state = new DependentExprState(goal.manager, goal);
|
|
81
84
|
const simplifier = create(state);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
try {
|
|
86
|
+
if (!goal.isProofsEnabled || isSupportingProofs) simplifier.reduce();
|
|
87
|
+
finishSimplifier(goal);
|
|
88
|
+
} finally {
|
|
89
|
+
simplifier.release();
|
|
90
|
+
state.release();
|
|
91
|
+
}
|
|
86
92
|
};
|
|
@@ -228,33 +228,49 @@ export const createDt2BvTactic = (manager: AstManager) => {
|
|
|
228
228
|
else argsCannotBeFd(expr);
|
|
229
229
|
}
|
|
230
230
|
for (const sort of nonFdSorts) fdSorts.delete(sort);
|
|
231
|
-
if (fdSorts.size > 0)
|
|
231
|
+
if (fdSorts.size > 0)
|
|
232
|
+
runEnum2Bv(
|
|
233
|
+
manager,
|
|
234
|
+
goal,
|
|
235
|
+
(visit) => {
|
|
236
|
+
const size = goal.forms.size;
|
|
237
|
+
for (let index = 0; index < size && !goal.isInconsistent; index++) visit(index);
|
|
238
|
+
},
|
|
239
|
+
fdSorts,
|
|
240
|
+
);
|
|
232
241
|
goal.depth++;
|
|
233
242
|
return [goal];
|
|
234
243
|
};
|
|
235
244
|
};
|
|
236
245
|
|
|
237
|
-
export const runEnum2Bv = (
|
|
246
|
+
export const runEnum2Bv = (
|
|
247
|
+
manager: AstManager,
|
|
248
|
+
goal: Goal,
|
|
249
|
+
forEachIndex: (visit: (index: number) => void) => void,
|
|
250
|
+
fdSorts?: Set<number>,
|
|
251
|
+
) => {
|
|
238
252
|
const rewriter = new Enum2BvRewriter(manager, fdSorts);
|
|
239
253
|
let rewritten = -1;
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
254
|
+
try {
|
|
255
|
+
forEachIndex((index) => {
|
|
256
|
+
const next = rewriter.rewrite(goal.forms.items[index]);
|
|
257
|
+
release(manager, rewritten);
|
|
258
|
+
rewritten = next;
|
|
259
|
+
goal.update(index, rewritten);
|
|
260
|
+
});
|
|
261
|
+
const bounds = new RefVector(manager);
|
|
262
|
+
for (const bound of rewriter.bounds.items) bounds.push(bound);
|
|
263
|
+
rewriter.bounds.reset();
|
|
264
|
+
for (const bound of bounds.items) goal.assert(bound);
|
|
265
|
+
const definitions: Definition[] = [];
|
|
266
|
+
for (const entry of rewriter.enumIndexes)
|
|
267
|
+
definitions.push({ decl: rewriter.enumBvs[entry[1]], def: -1 });
|
|
268
|
+
for (const entry of rewriter.enumIndexes)
|
|
269
|
+
definitions.push({ decl: entry[0], def: rewriter.enumDefs.items[entry[1]] });
|
|
270
|
+
if (definitions.length > 0) goal.addDefinitions(definitions);
|
|
271
|
+
bounds.reset();
|
|
272
|
+
} finally {
|
|
243
273
|
release(manager, rewritten);
|
|
244
|
-
|
|
245
|
-
goal.update(index, rewritten);
|
|
274
|
+
rewriter.release();
|
|
246
275
|
}
|
|
247
|
-
const bounds = new RefVector(manager);
|
|
248
|
-
for (const bound of rewriter.bounds.items) bounds.push(bound);
|
|
249
|
-
rewriter.bounds.reset();
|
|
250
|
-
for (const bound of bounds.items) goal.assert(bound);
|
|
251
|
-
const definitions: Definition[] = [];
|
|
252
|
-
for (const entry of rewriter.enumIndexes)
|
|
253
|
-
definitions.push({ decl: rewriter.enumBvs[entry[1]], def: -1 });
|
|
254
|
-
for (const entry of rewriter.enumIndexes)
|
|
255
|
-
definitions.push({ decl: entry[0], def: rewriter.enumDefs.items[entry[1]] });
|
|
256
|
-
if (definitions.length > 0) goal.addDefinitions(definitions);
|
|
257
|
-
bounds.reset();
|
|
258
|
-
release(manager, rewritten);
|
|
259
|
-
rewriter.release();
|
|
260
276
|
};
|