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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SmtCanceledError } from "../../../errors";
|
|
1
|
+
import { SmtCanceledError, SmtTacticError } from "../../../errors";
|
|
2
2
|
import {
|
|
3
3
|
type AstManager,
|
|
4
4
|
KIND_APP,
|
|
@@ -7,27 +7,29 @@ import {
|
|
|
7
7
|
OP_AND,
|
|
8
8
|
OP_EQ,
|
|
9
9
|
OP_IMPLIES,
|
|
10
|
+
OP_OR,
|
|
10
11
|
OP_UBV2INT,
|
|
11
12
|
OP_ULEQ,
|
|
12
13
|
SORT_BOOL,
|
|
13
14
|
SORT_INT,
|
|
14
15
|
} from "./ast";
|
|
16
|
+
import { mkNot } from "./ast-util";
|
|
15
17
|
import { BoundManager } from "./bound-manager";
|
|
16
18
|
import { mkBvApp } from "./bv-decl-plugin";
|
|
17
19
|
import { Bv2IntContext, Bv2IntRewriter } from "./bv2int-rewriter";
|
|
18
|
-
import {
|
|
20
|
+
import { createCard2Bv } from "./card2bv";
|
|
21
|
+
import { DependentExprState } from "./dependent-expr-state";
|
|
19
22
|
import { runEnum2Bv } from "./dt2bv-tactic";
|
|
23
|
+
import { release } from "./expr-ref";
|
|
20
24
|
import { ExprSafeReplace } from "./expr-safe-replace";
|
|
21
25
|
import { type Definition, Goal } from "./goal";
|
|
22
|
-
import {
|
|
23
|
-
import { L_FALSE, L_TRUE } from "./lbool";
|
|
26
|
+
import { L_FALSE, L_TRUE, L_UNDEF } from "./lbool";
|
|
24
27
|
import { RefVector } from "./ref-vector";
|
|
25
28
|
import { Rewriter } from "./rewriter";
|
|
26
29
|
import { convertModel, getRewriterOptions } from "./tactic";
|
|
27
30
|
import { UINT_MAX } from "./sat/clause";
|
|
28
31
|
import type { SatParams } from "./sat/config";
|
|
29
32
|
import { IncSatSolver } from "./sat/inc-sat-solver";
|
|
30
|
-
import { SubstReplacer } from "./solve-eqs";
|
|
31
33
|
|
|
32
34
|
const getNumBits = (value: bigint) => {
|
|
33
35
|
let bound = 1n;
|
|
@@ -50,9 +52,10 @@ const collectBounds = (manager: AstManager, bounds: BoundManager, form: number)
|
|
|
50
52
|
// bounded_int2bv_simplifier: an integer constant between two bounds becomes an unsigned
|
|
51
53
|
// bit-vector plus the lower bound.
|
|
52
54
|
const runBoundedInt2Bv = (manager: AstManager, goal: Goal) => {
|
|
55
|
+
const state = new DependentExprState(manager, goal);
|
|
53
56
|
const bounds = new BoundManager(manager);
|
|
54
|
-
|
|
55
|
-
const substitution = new
|
|
57
|
+
state.forEachIndex((index) => collectBounds(manager, bounds, goal.forms.items[index]));
|
|
58
|
+
const substitution = new ExprSafeReplace(manager);
|
|
56
59
|
const trail = new RefVector(manager);
|
|
57
60
|
const sideConditions = new RefVector(manager);
|
|
58
61
|
const definitions: Definition[] = [];
|
|
@@ -77,7 +80,6 @@ const runBoundedInt2Bv = (manager: AstManager, goal: Goal) => {
|
|
|
77
80
|
const replacement = offset.isZero()
|
|
78
81
|
? unsigned
|
|
79
82
|
: manager.mkApp(OP_ADD, [unsigned, manager.mkNumeral(offset.num)], SORT_INT);
|
|
80
|
-
trail.push(replacement);
|
|
81
83
|
definitions.push(
|
|
82
84
|
{ decl: manager.decls[bits], def: -1 },
|
|
83
85
|
{ decl: manager.decls[expr], def: replacement },
|
|
@@ -86,36 +88,118 @@ const runBoundedInt2Bv = (manager: AstManager, goal: Goal) => {
|
|
|
86
88
|
sideConditions.push(
|
|
87
89
|
mkBvApp(manager, OP_ULEQ, [bits, manager.mkBvNumeral(domainSize - 1n, numBits)]),
|
|
88
90
|
);
|
|
89
|
-
substitution.
|
|
91
|
+
substitution.insert(expr, replacement);
|
|
90
92
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
try {
|
|
94
|
+
if (substitution.sources.size > 0) {
|
|
95
|
+
const context = new Bv2IntContext(manager, UINT_MAX);
|
|
96
|
+
const rewriter = new Bv2IntRewriter(manager, context);
|
|
97
|
+
let replaced = -1;
|
|
98
|
+
let result = -1;
|
|
99
|
+
try {
|
|
100
|
+
state.forEachIndex((index) => {
|
|
101
|
+
const form = goal.forms.items[index];
|
|
102
|
+
const nextReplaced = substitution.apply(form);
|
|
103
|
+
release(manager, replaced);
|
|
104
|
+
replaced = nextReplaced;
|
|
105
|
+
const nextResult = rewriter.rewrite(replaced);
|
|
106
|
+
release(manager, result);
|
|
107
|
+
result = nextResult;
|
|
108
|
+
if (result !== form) goal.update(index, result);
|
|
109
|
+
});
|
|
110
|
+
} finally {
|
|
111
|
+
release(manager, result);
|
|
112
|
+
release(manager, replaced);
|
|
113
|
+
rewriter.release();
|
|
114
|
+
context.release();
|
|
115
|
+
}
|
|
102
116
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
117
|
+
for (const condition of sideConditions.items) goal.assert(condition);
|
|
118
|
+
if (definitions.length > 0) goal.addDefinitions(definitions);
|
|
119
|
+
} finally {
|
|
120
|
+
substitution.release();
|
|
121
|
+
sideConditions.reset();
|
|
122
|
+
trail.reset();
|
|
106
123
|
}
|
|
107
|
-
for (const condition of sideConditions.items) goal.assert(condition);
|
|
108
|
-
if (definitions.length > 0) goal.addDefinitions(definitions);
|
|
109
|
-
sideConditions.reset();
|
|
110
|
-
trail.reset();
|
|
111
124
|
};
|
|
112
125
|
|
|
126
|
+
class SolverFormulas extends Goal {
|
|
127
|
+
override assert(form: number) {
|
|
128
|
+
if (this.manager.isFalse(form)) this.isInconsistent = true;
|
|
129
|
+
this.forms.push(form);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
override update(index: number, form: number) {
|
|
133
|
+
if (this.manager.isFalse(form)) this.isInconsistent = true;
|
|
134
|
+
this.forms.set(index, form);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
flattenSuffix() {
|
|
138
|
+
const manager = this.manager;
|
|
139
|
+
const forms = this.forms;
|
|
140
|
+
const seen = new Set<number>();
|
|
141
|
+
const pinned = new RefVector(manager);
|
|
142
|
+
let kept = 0;
|
|
143
|
+
for (let index = 0; index < forms.size; index++) {
|
|
144
|
+
const form = forms.items[index];
|
|
145
|
+
pinned.push(form);
|
|
146
|
+
if (seen.has(form)) continue;
|
|
147
|
+
seen.add(form);
|
|
148
|
+
if (manager.isTrue(form)) continue;
|
|
149
|
+
if (manager.getOp(form) === OP_AND) {
|
|
150
|
+
const numArgs = manager.getNumArgs(form);
|
|
151
|
+
for (let argIndex = 0; argIndex < numArgs; argIndex++)
|
|
152
|
+
this.assert(manager.getArg(form, argIndex));
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (manager.isNot(form) && manager.getOp(manager.getArg(form, 0)) === OP_OR) {
|
|
156
|
+
const disjunction = manager.getArg(form, 0);
|
|
157
|
+
const numArgs = manager.getNumArgs(disjunction);
|
|
158
|
+
for (let argIndex = 0; argIndex < numArgs; argIndex++)
|
|
159
|
+
this.assert(mkNot(manager, manager.getArg(disjunction, argIndex)));
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (index !== kept) forms.set(kept, form);
|
|
163
|
+
kept++;
|
|
164
|
+
}
|
|
165
|
+
while (forms.size > kept) forms.pop();
|
|
166
|
+
pinned.reset();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
113
170
|
const runFdSimplifier = (manager: AstManager, forms: readonly number[]) => {
|
|
114
|
-
const fmls = new
|
|
171
|
+
const fmls = new SolverFormulas(manager);
|
|
115
172
|
for (const form of forms) fmls.assert(form);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
173
|
+
if (fmls.forms.size === 0) return fmls;
|
|
174
|
+
const state = new DependentExprState(manager, fmls);
|
|
175
|
+
const simplifiers = [
|
|
176
|
+
() => runBoundedInt2Bv(manager, fmls),
|
|
177
|
+
() => {
|
|
178
|
+
const simplifier = createCard2Bv(manager, getRewriterOptions(manager, new Map()))(state);
|
|
179
|
+
try {
|
|
180
|
+
simplifier.reduce();
|
|
181
|
+
} finally {
|
|
182
|
+
simplifier.release();
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
() => runEnum2Bv(manager, fmls, (visit) => state.forEachIndex(visit)),
|
|
186
|
+
];
|
|
187
|
+
try {
|
|
188
|
+
if (!fmls.isInconsistent && manager.limit.inc())
|
|
189
|
+
for (const simplify of simplifiers) {
|
|
190
|
+
if (fmls.isInconsistent || !manager.limit.inc()) break;
|
|
191
|
+
try {
|
|
192
|
+
simplify();
|
|
193
|
+
} catch (error) {
|
|
194
|
+
if (!(error instanceof SmtCanceledError)) throw error;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
fmls.flattenSuffix();
|
|
198
|
+
}
|
|
199
|
+
} finally {
|
|
200
|
+
state.release();
|
|
201
|
+
}
|
|
202
|
+
if (!manager.limit.inc()) fmls.reset();
|
|
119
203
|
return fmls;
|
|
120
204
|
};
|
|
121
205
|
|
|
@@ -176,7 +260,6 @@ export const getFdConsequences = (
|
|
|
176
260
|
const solver = new IncSatSolver(manager, params);
|
|
177
261
|
try {
|
|
178
262
|
for (const form of fmls.forms.items) solver.assertExpr(form);
|
|
179
|
-
if (fmls.isInconsistent) solver.assertExpr(manager.falseExpr);
|
|
180
263
|
const found = solver.getConsequences(asms1, queryVars);
|
|
181
264
|
const coreReplace = new ExprSafeReplace(manager);
|
|
182
265
|
asms1.forEach((assumption, index) => coreReplace.insert(assumption, assumptions[index]));
|
|
@@ -244,18 +327,16 @@ export const createFdTactic = (manager: AstManager, params: SatParams) => (goal:
|
|
|
244
327
|
const solver = new IncSatSolver(manager, params, false);
|
|
245
328
|
try {
|
|
246
329
|
for (const form of fmls.forms.items) solver.assertExpr(form);
|
|
247
|
-
const result =
|
|
330
|
+
const result = solver.check();
|
|
248
331
|
goal.reset();
|
|
249
332
|
if (result === L_TRUE) {
|
|
250
333
|
const model = solver.getModel();
|
|
251
|
-
model
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
goal.model = model;
|
|
255
|
-
}
|
|
334
|
+
const converted = model === null ? null : convertModel(fmls, model);
|
|
335
|
+
converted?.incRef();
|
|
336
|
+
if (converted !== null) goal.model = converted;
|
|
256
337
|
} else if (result === L_FALSE) goal.assert(manager.falseExpr);
|
|
257
338
|
else {
|
|
258
|
-
if (!manager.limit.inc()) throw new
|
|
339
|
+
if (!manager.limit.inc()) throw new SmtTacticError("canceled");
|
|
259
340
|
for (const form of solver.getAssertions()) goal.assert(form);
|
|
260
341
|
goal.converters = [...goal.converters, ...fmls.converters, ...solver.getConverters()];
|
|
261
342
|
}
|
|
@@ -265,3 +346,29 @@ export const createFdTactic = (manager: AstManager, params: SatParams) => (goal:
|
|
|
265
346
|
solver.release();
|
|
266
347
|
}
|
|
267
348
|
};
|
|
349
|
+
|
|
350
|
+
export const checkFdSolver = (manager: AstManager, params: SatParams, forms: readonly number[]) => {
|
|
351
|
+
const fmls = runFdSimplifier(manager, forms);
|
|
352
|
+
const solver = new IncSatSolver(manager, params);
|
|
353
|
+
const limit = manager.limit;
|
|
354
|
+
const wasSuspended = limit.isSuspended;
|
|
355
|
+
try {
|
|
356
|
+
for (const form of fmls.forms.items) solver.assertExpr(form);
|
|
357
|
+
const result = (() => {
|
|
358
|
+
try {
|
|
359
|
+
return solver.check();
|
|
360
|
+
} catch (error) {
|
|
361
|
+
if (!(error instanceof SmtCanceledError)) throw error;
|
|
362
|
+
return L_UNDEF;
|
|
363
|
+
}
|
|
364
|
+
})();
|
|
365
|
+
const model = result === L_TRUE ? solver.getModel() : null;
|
|
366
|
+
limit.isSuspended = true;
|
|
367
|
+
const converted = model === null ? undefined : convertModel(fmls, model);
|
|
368
|
+
converted?.incRef();
|
|
369
|
+
return { result, model: converted, reasonUnknown: solver.reasonUnknown };
|
|
370
|
+
} finally {
|
|
371
|
+
limit.isSuspended = wasSuspended;
|
|
372
|
+
solver.release();
|
|
373
|
+
}
|
|
374
|
+
};
|
|
@@ -274,10 +274,11 @@ export class Maxcore extends MaxsmtSolverBase {
|
|
|
274
274
|
const upper = this.getCost(model);
|
|
275
275
|
if (upper.compare(this.upper) > 0) return;
|
|
276
276
|
if (!this.context.verifyModel(this.index, model, upper)) return;
|
|
277
|
+
const numAssertions = this.solver.getNumAssertions();
|
|
277
278
|
this.model = model;
|
|
278
279
|
this.context.modelUpdated(model);
|
|
279
280
|
for (const soft of this.soft) soft.value = this.isTrueIn(model, soft.expr) ? L_TRUE : L_UNDEF;
|
|
280
|
-
this.upper = upper;
|
|
281
|
+
if (numAssertions === this.solver.getNumAssertions()) this.upper = upper;
|
|
281
282
|
}
|
|
282
283
|
|
|
283
284
|
private removeSoft(core: readonly number[]) {
|
|
@@ -10,6 +10,7 @@ export interface MaxsatSolver {
|
|
|
10
10
|
checkSat(assumptions: readonly number[]): number;
|
|
11
11
|
getModel(): ProtoModel | null;
|
|
12
12
|
getUnsatCore(): readonly number[];
|
|
13
|
+
getNumAssertions(): number;
|
|
13
14
|
findMutexes(vars: readonly number[]): { status: number; mutexes: number[][] };
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -55,7 +55,7 @@ class AuxContext {
|
|
|
55
55
|
const context = this.context;
|
|
56
56
|
context.popToBaseLevel();
|
|
57
57
|
const result = context.checkResearching(this.asserted, []);
|
|
58
|
-
return result === L_TRUE ? context.
|
|
58
|
+
return result === L_TRUE ? context.getSatModel() : result === L_FALSE ? "unsat" : "unknown";
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -10,16 +10,16 @@ import {
|
|
|
10
10
|
SORT_SIZE_INFINITE,
|
|
11
11
|
} from "../ast";
|
|
12
12
|
import type { Definition } from "../goal";
|
|
13
|
-
import {
|
|
14
|
-
import { FuncInterp, type ProtoModel } from "../proto-model";
|
|
13
|
+
import type { ProtoModel } from "../proto-model";
|
|
15
14
|
import { type RewriterOptions, Rewriter } from "../rewriter";
|
|
16
15
|
import { RefVector } from "../ref-vector";
|
|
17
16
|
import { applyQeLiteToConjuncts } from "../qe-lite";
|
|
17
|
+
import { applyDefinitions } from "../tactic";
|
|
18
18
|
import { BindVariables, mkExists, type Rule, RuleManager, getUsedVars } from "./dl-rule";
|
|
19
19
|
import { RuleSet } from "./dl-rule-set";
|
|
20
20
|
import { RuleProperties } from "./rule-properties";
|
|
21
21
|
|
|
22
|
-
const ENGINE_DATALOG = 0;
|
|
22
|
+
export const ENGINE_DATALOG = 0;
|
|
23
23
|
export const ENGINE_SPACER = 1;
|
|
24
24
|
const ENGINE_BMC = 2;
|
|
25
25
|
const ENGINE_QBMC = 3;
|
|
@@ -63,40 +63,6 @@ export class FpParams {
|
|
|
63
63
|
|
|
64
64
|
export type ModelConverter = (model: ProtoModel) => ProtoModel;
|
|
65
65
|
|
|
66
|
-
// generic_model_converter::operator() over predicates, where a definition of -1 hides the
|
|
67
|
-
// declaration.
|
|
68
|
-
const applyDefinitions = (definitions: readonly Definition[], model: ProtoModel) => {
|
|
69
|
-
const manager = model.manager;
|
|
70
|
-
let evaluator = new ModelEvaluator(manager, model);
|
|
71
|
-
evaluator.setModelCompletion(true);
|
|
72
|
-
for (let index = definitions.length - 1; index >= 0; index--) {
|
|
73
|
-
const definition = definitions[index];
|
|
74
|
-
if (definition.def === -1) {
|
|
75
|
-
model.unregisterDecl(definition.decl);
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
const value = evaluator.rewrite(definition.def);
|
|
79
|
-
const arity = manager.funcDecls[definition.decl].domain.length;
|
|
80
|
-
const oldInterp = model.funcInterps.get(definition.decl);
|
|
81
|
-
const old = arity === 0 ? model.constInterps.get(definition.decl) : oldInterp?.elseExpr;
|
|
82
|
-
if (old !== value) {
|
|
83
|
-
if (arity === 0) model.registerConst(definition.decl, value);
|
|
84
|
-
else {
|
|
85
|
-
const interp = new FuncInterp(manager, arity);
|
|
86
|
-
interp.setElse(value);
|
|
87
|
-
model.registerFunc(definition.decl, interp);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
manager.decRef(value);
|
|
91
|
-
if (old === value || (arity === 0 ? old === undefined : oldInterp === undefined)) continue;
|
|
92
|
-
evaluator.release();
|
|
93
|
-
evaluator = new ModelEvaluator(manager, model);
|
|
94
|
-
evaluator.setModelCompletion(true);
|
|
95
|
-
}
|
|
96
|
-
evaluator.release();
|
|
97
|
-
return model;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
66
|
export interface Engine {
|
|
101
67
|
query(query: number): number;
|
|
102
68
|
getModel(): ProtoModel;
|
|
@@ -112,7 +78,7 @@ export class DatalogContext {
|
|
|
112
78
|
private isBindingVariables = true;
|
|
113
79
|
ruleSet: RuleSet;
|
|
114
80
|
private ruleFmls: number[] = [];
|
|
115
|
-
private ruleNames: string[] = [];
|
|
81
|
+
private ruleNames: (string | undefined)[] = [];
|
|
116
82
|
private ruleFmlsHead = 0;
|
|
117
83
|
readonly background: number[] = [];
|
|
118
84
|
private isClosed = false;
|
|
@@ -181,7 +147,7 @@ export class DatalogContext {
|
|
|
181
147
|
return result;
|
|
182
148
|
}
|
|
183
149
|
|
|
184
|
-
addRule(fml: number, name
|
|
150
|
+
addRule(fml: number, name?: string) {
|
|
185
151
|
this.manager.incRef(fml);
|
|
186
152
|
this.ruleFmls.push(fml);
|
|
187
153
|
this.ruleNames.push(name);
|
|
@@ -217,7 +183,13 @@ export class DatalogContext {
|
|
|
217
183
|
const properties = this.ruleProperties;
|
|
218
184
|
switch (this.getEngine()) {
|
|
219
185
|
case ENGINE_DATALOG:
|
|
220
|
-
|
|
186
|
+
properties.collect(rules);
|
|
187
|
+
properties.checkQuantifierFree();
|
|
188
|
+
properties.checkUninterpretedFree();
|
|
189
|
+
properties.checkNestedFree();
|
|
190
|
+
properties.checkInfiniteSorts();
|
|
191
|
+
properties.checkBackgroundFree();
|
|
192
|
+
break;
|
|
221
193
|
case ENGINE_SPACER:
|
|
222
194
|
properties.collect(rules);
|
|
223
195
|
properties.checkExistentialTail();
|
|
@@ -91,7 +91,7 @@ export class MkCoiFilter implements RuleTransformerPlugin {
|
|
|
91
91
|
newTail.push(rule.tail[index]);
|
|
92
92
|
newNegated.push(false);
|
|
93
93
|
}
|
|
94
|
-
result.addRule(this.context.ruleManager.mk(rule.head, newTail, newNegated,
|
|
94
|
+
result.addRule(this.context.ruleManager.mk(rule.head, newTail, newNegated, undefined, false));
|
|
95
95
|
}
|
|
96
96
|
if (result.rules.length === source.rules.length) return undefined;
|
|
97
97
|
result.close();
|
|
@@ -47,7 +47,7 @@ export class Rule {
|
|
|
47
47
|
readonly isNegated: boolean[],
|
|
48
48
|
readonly uninterpretedSize: number,
|
|
49
49
|
readonly positiveSize: number,
|
|
50
|
-
readonly name: string,
|
|
50
|
+
readonly name: string | undefined,
|
|
51
51
|
) {}
|
|
52
52
|
|
|
53
53
|
getDecl(manager: AstManager) {
|
|
@@ -64,9 +64,8 @@ export class Rule {
|
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
// symbol::str of the name, where the empty name is the null symbol.
|
|
68
67
|
getNameText() {
|
|
69
|
-
return this.name
|
|
68
|
+
return this.name ?? "<null>";
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
display(context: DatalogContext) {
|
|
@@ -225,20 +224,20 @@ export class RuleManager {
|
|
|
225
224
|
return expr;
|
|
226
225
|
}
|
|
227
226
|
|
|
228
|
-
mkRule(fml: number, rules: RuleSet, name
|
|
227
|
+
mkRule(fml: number, rules: RuleSet, name?: string) {
|
|
229
228
|
const bound = this.context.bindVars(fml, true);
|
|
230
229
|
if (this.manager.hasLabelFlags[bound]) throw new SmtUnsupportedError("labels in Horn rules");
|
|
231
230
|
this.mkRuleCore(bound, rules, name);
|
|
232
231
|
}
|
|
233
232
|
|
|
234
|
-
private mkRuleCore(fml: number, rules: RuleSet, name: string) {
|
|
233
|
+
private mkRuleCore(fml: number, rules: RuleSet, name: string | undefined) {
|
|
235
234
|
this.hnf.setName(name);
|
|
236
235
|
const fmls = this.hnf.apply(fml);
|
|
237
236
|
for (const predicate of this.hnf.freshPredicates) this.context.registerPredicate(predicate);
|
|
238
237
|
for (const horn of fmls) this.mkHornRule(horn, rules, name);
|
|
239
238
|
}
|
|
240
239
|
|
|
241
|
-
private mkHornRule(fml: number, rules: RuleSet, name: string) {
|
|
240
|
+
private mkHornRule(fml: number, rules: RuleSet, name: string | undefined) {
|
|
242
241
|
const manager = this.manager;
|
|
243
242
|
const body: number[] = [];
|
|
244
243
|
const extracted = this.extractHorn(fml, body);
|
|
@@ -307,7 +306,7 @@ export class RuleManager {
|
|
|
307
306
|
head: number,
|
|
308
307
|
tail: readonly number[],
|
|
309
308
|
isNegated: readonly boolean[],
|
|
310
|
-
name
|
|
309
|
+
name?: string,
|
|
311
310
|
isNormalizing = true,
|
|
312
311
|
) {
|
|
313
312
|
const manager = this.manager;
|
|
@@ -17,7 +17,7 @@ import { L_FALSE, L_TRUE } from "../lbool";
|
|
|
17
17
|
import { RefVector } from "../ref-vector";
|
|
18
18
|
import type { RewriterOptions } from "../rewriter";
|
|
19
19
|
import { getFreeVarSorts } from "../var-subst";
|
|
20
|
-
import { DatalogContext, ENGINE_SPACER, FpParams } from "./dl-context";
|
|
20
|
+
import { DatalogContext, ENGINE_DATALOG, ENGINE_SPACER, FpParams } from "./dl-context";
|
|
21
21
|
import { mkForall, mkPp } from "./dl-rule";
|
|
22
22
|
import { SpacerDlInterface } from "./spacer-dl-interface";
|
|
23
23
|
|
|
@@ -27,6 +27,19 @@ export const createDatalogContext = (
|
|
|
27
27
|
rewriterOptions: RewriterOptions,
|
|
28
28
|
) =>
|
|
29
29
|
new DatalogContext(manager, new FpParams(parameters), rewriterOptions, (context, engine) => {
|
|
30
|
+
if (engine === ENGINE_DATALOG)
|
|
31
|
+
return {
|
|
32
|
+
// rel_context::query checks the rules with the query's before the saturation the port lacks.
|
|
33
|
+
query: (query) => {
|
|
34
|
+
context.ruleManager.mkQuery(query, context.getRules());
|
|
35
|
+
context.ensureClosed();
|
|
36
|
+
context.getRules();
|
|
37
|
+
throw new SmtUnsupportedError("the datalog engine");
|
|
38
|
+
},
|
|
39
|
+
getModel: () => {
|
|
40
|
+
throw new SmtUnsupportedError("the datalog engine");
|
|
41
|
+
},
|
|
42
|
+
};
|
|
30
43
|
if (engine !== ENGINE_SPACER) throw new SmtUnsupportedError("the bmc engine");
|
|
31
44
|
return new SpacerDlInterface(context);
|
|
32
45
|
});
|
|
@@ -277,6 +277,28 @@ export class RuleProperties {
|
|
|
277
277
|
);
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
+
checkQuantifierFree() {
|
|
281
|
+
const first = this.quantifiers.entries().next();
|
|
282
|
+
if (first.done !== true)
|
|
283
|
+
throw new SmtTacticError(
|
|
284
|
+
`cannot process quantifier in rule ${first.value[1].display(this.context)}`,
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
checkNestedFree() {
|
|
289
|
+
const rules = this.interpretedPredicateRules;
|
|
290
|
+
if (rules.length > 0)
|
|
291
|
+
throw new SmtTacticError(`Rule contains nested predicates ${rules[0].display(this.context)}`);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
checkInfiniteSorts() {
|
|
295
|
+
const rules = this.infiniteSortRules;
|
|
296
|
+
if (rules.length > 0)
|
|
297
|
+
throw new SmtTacticError(
|
|
298
|
+
`Rule contains infinite sorts in rule ${rules[rules.length - 1].display(this.context)}`,
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
280
302
|
checkExistsFree() {
|
|
281
303
|
for (const entry of this.quantifiers)
|
|
282
304
|
if (this.manager.getQuantifier(entry[0]).kind === QUANTIFIER_EXISTS)
|
|
@@ -128,7 +128,7 @@ export class IucSolver {
|
|
|
128
128
|
const result = kernel.check(this.assumptions);
|
|
129
129
|
this.lastModel = undefined;
|
|
130
130
|
if (result === L_TRUE) {
|
|
131
|
-
this.lastModel = kernel.context.
|
|
131
|
+
this.lastModel = kernel.context.getSatModel();
|
|
132
132
|
this.lastModel.incRef();
|
|
133
133
|
}
|
|
134
134
|
this.lastCore = result === L_FALSE ? [...kernel.context.unsatCore] : [];
|
|
@@ -260,6 +260,7 @@ export class OptContext {
|
|
|
260
260
|
checkSat: (assumptions) => getSolver().check(assumptions),
|
|
261
261
|
getModel: () => getSolver().getModel(),
|
|
262
262
|
getUnsatCore: () => getSolver().getUnsatCore(),
|
|
263
|
+
getNumAssertions: () => getSolver().getAssertions().length,
|
|
263
264
|
findMutexes: (vars) => ({ status: L_TRUE, mutexes: getSolver().findMutexes(vars) }),
|
|
264
265
|
};
|
|
265
266
|
return {
|
|
@@ -113,7 +113,7 @@ class ParallelSolver {
|
|
|
113
113
|
this.context.maxConflicts = this.threadsMaxConflicts;
|
|
114
114
|
const result = this.kernel.check([...this.assumptions, ...cube]);
|
|
115
115
|
if (result === L_TRUE) {
|
|
116
|
-
this.setSat(this.context.
|
|
116
|
+
this.setSat(this.context.getSatModel());
|
|
117
117
|
return false;
|
|
118
118
|
}
|
|
119
119
|
if (result === L_FALSE) {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
SmtDefaultError,
|
|
3
|
+
SmtInvariantError,
|
|
4
|
+
SmtTacticError,
|
|
5
|
+
SmtUnsupportedError,
|
|
6
|
+
} from "../../../errors";
|
|
2
7
|
import {
|
|
3
8
|
type AstManager,
|
|
4
9
|
FAMILY_BASIC,
|
|
@@ -542,7 +547,7 @@ class Qsat {
|
|
|
542
547
|
for (const innerVar of vars.items) this.predAbs.hidden.push(manager.decls[innerVar]);
|
|
543
548
|
for (const innerVar of vars.items)
|
|
544
549
|
if (manager.isUninterpretedSort(manager.sorts[innerVar]))
|
|
545
|
-
throw new
|
|
550
|
+
throw new SmtDefaultError("qsat does not apply to uninterpreted sorts");
|
|
546
551
|
}
|
|
547
552
|
|
|
548
553
|
private initializeLevels() {
|
|
@@ -121,13 +121,14 @@ class RewriterCore {
|
|
|
121
121
|
this.scopes = [];
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
protected
|
|
124
|
+
protected releaseCore() {
|
|
125
125
|
for (const cache of this.caches) cache.reset();
|
|
126
|
+
this.numFrames = 0;
|
|
127
|
+
this.shrinkResults(0);
|
|
126
128
|
}
|
|
127
129
|
|
|
128
130
|
protected cleanupCore() {
|
|
129
|
-
this.
|
|
130
|
-
this.shrinkResults(0);
|
|
131
|
+
this.releaseCore();
|
|
131
132
|
this.caches = [new ActCache(this.manager, this.manager.getNumAsts())];
|
|
132
133
|
this.frames = [];
|
|
133
134
|
this.numFrames = 0;
|
|
@@ -247,7 +248,7 @@ abstract class VarShifterCore extends RewriterCore {
|
|
|
247
248
|
}
|
|
248
249
|
|
|
249
250
|
release() {
|
|
250
|
-
this.
|
|
251
|
+
this.releaseCore();
|
|
251
252
|
}
|
|
252
253
|
}
|
|
253
254
|
|
|
@@ -389,7 +390,7 @@ class RewriterEngine extends SubstCore {
|
|
|
389
390
|
this.setLastResult(-1);
|
|
390
391
|
this.invShifter.release();
|
|
391
392
|
this.shifter.release();
|
|
392
|
-
this.
|
|
393
|
+
this.releaseCore();
|
|
393
394
|
}
|
|
394
395
|
|
|
395
396
|
rewrite(expr: number): number {
|
|
@@ -859,7 +860,7 @@ export class BetaReducer extends SubstCore {
|
|
|
859
860
|
release() {
|
|
860
861
|
this.setLastResult(-1);
|
|
861
862
|
this.shifter.release();
|
|
862
|
-
this.
|
|
863
|
+
this.releaseCore();
|
|
863
864
|
}
|
|
864
865
|
|
|
865
866
|
rewrite(expr: number): number {
|