tla-ts 0.0.10-dev.1ebc153bd → 0.0.10-dev.22f7435d3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/deciders.cjs +31 -31
- package/dist/deciders.js +30 -30
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +68 -68
- package/dist/prove.js +61 -61
- package/dist/run.cjs +42 -42
- package/dist/run.js +44 -44
- package/dist/transfer.cjs +38 -38
- package/dist/transfer.js +29 -29
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/bags.ts +5 -2
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +9 -6
- package/src/check-trace.ts +116 -64
- package/src/check.ts +343 -166
- package/src/cli/tlc-output.ts +1 -0
- package/src/cli/tlc.ts +3 -2
- package/src/codegen.ts +23 -8
- package/src/dependencies.ts +5 -4
- package/src/dfid.ts +13 -8
- package/src/environment.ts +1 -0
- package/src/evaluate.ts +58 -23
- package/src/exit-codes.ts +27 -13
- package/src/java-hash.ts +14 -0
- package/src/liveness-checker.ts +131 -81
- package/src/liveness.ts +48 -10
- package/src/parser.ts +6 -1
- package/src/prover/smt/solver/arith-rewriter.ts +11 -3
- package/src/prover/smt/solver/array-rewriter.ts +12 -2
- package/src/prover/smt/solver/asserted-formulas.ts +109 -63
- package/src/prover/smt/solver/ast.ts +5 -3
- package/src/prover/smt/solver/auf-solver.ts +23 -12
- package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
- package/src/prover/smt/solver/bound-simplifier.ts +10 -11
- package/src/prover/smt/solver/card2bv.ts +34 -15
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -23
- package/src/prover/smt/solver/context.ts +44 -11
- package/src/prover/smt/solver/dependent-expr-state.ts +19 -13
- package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
- package/src/prover/smt/solver/elim-bounds.ts +89 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +1 -1
- package/src/prover/smt/solver/fd-solver.ts +146 -39
- package/src/prover/smt/solver/internalizer.ts +1 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +4 -0
- package/src/prover/smt/solver/maxcore.ts +2 -1
- package/src/prover/smt/solver/maxsmt-base.ts +1 -0
- package/src/prover/smt/solver/model-checker.ts +1 -1
- package/src/prover/smt/solver/model-evaluator.ts +2 -0
- package/src/prover/smt/solver/model-generator.ts +82 -42
- package/src/prover/smt/solver/muz/dl-context.ts +12 -40
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
- package/src/prover/smt/solver/muz/dl-rule.ts +6 -7
- package/src/prover/smt/solver/muz/hnf.ts +2 -2
- package/src/prover/smt/solver/muz/horn-tactic.ts +14 -1
- package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
- package/src/prover/smt/solver/opt-context.ts +12 -4
- package/src/prover/smt/solver/opt-pareto.ts +19 -0
- package/src/prover/smt/solver/opt-solver.ts +4 -3
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- package/src/prover/smt/solver/poly-rewriter.ts +1 -0
- package/src/prover/smt/solver/proto-model.ts +4 -2
- package/src/prover/smt/solver/push-app-ite.ts +37 -0
- package/src/prover/smt/solver/qsat.ts +23 -8
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
- package/src/prover/smt/solver/rewriter.ts +31 -25
- package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +56 -28
- package/src/prover/smt/solver/sat/sat-tactic.ts +13 -4
- package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
- package/src/prover/smt/solver/smt-consequences.ts +1 -1
- package/src/prover/smt/solver/smt-kernel.ts +39 -4
- package/src/prover/smt/solver/smt-setup.ts +28 -4
- package/src/prover/smt/solver/smtlib-parser.ts +31 -4
- package/src/prover/smt/solver/smtlib-script.ts +219 -82
- package/src/prover/smt/solver/solve-eqs.ts +24 -17
- package/src/prover/smt/solver/solver.ts +18 -3
- package/src/prover/smt/solver/tactic.ts +132 -78
- package/src/prover/smt/solver/theory-bv.ts +11 -1
- package/src/prover/smt/solver/theory-fpa.ts +1 -1
- package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +7 -1
- package/src/prover/smt/solver/theory-lra.ts +1 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
- package/src/resolve.ts +446 -167
- package/src/runtime.ts +4 -0
- package/src/search.ts +161 -92
- package/src/simulate.ts +165 -102
- package/src/spec-description.ts +3 -4
- package/src/standard-modules.ts +56 -22
- package/src/subexpressions.ts +168 -49
- package/src/successors.ts +6 -3
- package/src/symmetry.ts +1 -0
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +22 -14
- package/src/tlc/tlc-operators.ts +7 -7
- package/src/tlc/tlcext-operators.ts +26 -10
- package/src/tlc/trace-spec.ts +6 -20
- package/src/typed-tier.ts +9 -4
- package/src/values.ts +95 -57
|
@@ -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,
|
|
@@ -22,6 +27,7 @@ import { QuantifierHoister } from "./quant-hoist";
|
|
|
22
27
|
import { hasSubterm } from "./recfun-decl-plugin";
|
|
23
28
|
import { RefVector } from "./ref-vector";
|
|
24
29
|
import { SmtKernel } from "./smt-kernel";
|
|
30
|
+
import type { TacticEnvironment } from "./tactic";
|
|
25
31
|
|
|
26
32
|
export const NO_LEVEL = -1;
|
|
27
33
|
|
|
@@ -314,7 +320,10 @@ class Kernel {
|
|
|
314
320
|
private lastAssert = -1;
|
|
315
321
|
private trail: RefVector;
|
|
316
322
|
|
|
317
|
-
constructor(
|
|
323
|
+
constructor(
|
|
324
|
+
private manager: AstManager,
|
|
325
|
+
private isCoreMinimizing: boolean,
|
|
326
|
+
) {
|
|
318
327
|
this.trail = new RefVector(manager);
|
|
319
328
|
}
|
|
320
329
|
|
|
@@ -324,6 +333,7 @@ class Kernel {
|
|
|
324
333
|
mbqiMaxIterations: MBQI_MAX_ITERATIONS,
|
|
325
334
|
isFindingMacros: false,
|
|
326
335
|
relevancyLevel: 0,
|
|
336
|
+
isCoreMinimizing: this.isCoreMinimizing,
|
|
327
337
|
});
|
|
328
338
|
this.lastAssert = -1;
|
|
329
339
|
this.trail.reset();
|
|
@@ -351,7 +361,7 @@ class Kernel {
|
|
|
351
361
|
|
|
352
362
|
getCore(core: RefVector) {
|
|
353
363
|
core.reset();
|
|
354
|
-
|
|
364
|
+
this.solver.getUnsatCore(core);
|
|
355
365
|
}
|
|
356
366
|
|
|
357
367
|
reasonUnknown() {
|
|
@@ -383,10 +393,11 @@ class Qsat {
|
|
|
383
393
|
constructor(
|
|
384
394
|
private manager: AstManager,
|
|
385
395
|
private mode: number,
|
|
396
|
+
isCoreMinimizing: boolean,
|
|
386
397
|
) {
|
|
387
398
|
this.mbp = new Mbproj(manager);
|
|
388
|
-
this.fa = new Kernel(manager);
|
|
389
|
-
this.ex = new Kernel(manager);
|
|
399
|
+
this.fa = new Kernel(manager, isCoreMinimizing);
|
|
400
|
+
this.ex = new Kernel(manager, isCoreMinimizing);
|
|
390
401
|
this.predAbs = new PredAbs(manager);
|
|
391
402
|
this.answer = new RefVector(manager);
|
|
392
403
|
this.asms = new RefVector(manager);
|
|
@@ -536,7 +547,7 @@ class Qsat {
|
|
|
536
547
|
for (const innerVar of vars.items) this.predAbs.hidden.push(manager.decls[innerVar]);
|
|
537
548
|
for (const innerVar of vars.items)
|
|
538
549
|
if (manager.isUninterpretedSort(manager.sorts[innerVar]))
|
|
539
|
-
throw new
|
|
550
|
+
throw new SmtDefaultError("qsat does not apply to uninterpreted sorts");
|
|
540
551
|
}
|
|
541
552
|
|
|
542
553
|
private initializeLevels() {
|
|
@@ -804,8 +815,12 @@ class Qsat {
|
|
|
804
815
|
}
|
|
805
816
|
}
|
|
806
817
|
|
|
807
|
-
export const runQsat = (
|
|
808
|
-
const qsat = new Qsat(
|
|
818
|
+
export const runQsat = (environment: TacticEnvironment, mode: number) => (goal: Goal) => {
|
|
819
|
+
const qsat = new Qsat(
|
|
820
|
+
environment.manager,
|
|
821
|
+
mode,
|
|
822
|
+
environment.parameters.get("smt.core.minimize") === "true",
|
|
823
|
+
);
|
|
809
824
|
try {
|
|
810
825
|
return qsat.apply(goal);
|
|
811
826
|
} finally {
|
|
@@ -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 {
|
|
@@ -92,6 +92,7 @@ export interface RewriterOptions {
|
|
|
92
92
|
readonly localCtxLimit?: number;
|
|
93
93
|
readonly isCoalescingChars?: boolean;
|
|
94
94
|
readonly isSortingStore?: boolean;
|
|
95
|
+
readonly isExpandingSelects?: boolean;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
export const KERNEL_REWRITER_OPTIONS: RewriterOptions = {
|
|
@@ -141,7 +142,7 @@ export class Rewriter extends RewriterTpl {
|
|
|
141
142
|
return typeof result === "number" ? result : result.expr;
|
|
142
143
|
},
|
|
143
144
|
});
|
|
144
|
-
this.array = new ArrayRewriter(manager, options.isSortingStore);
|
|
145
|
+
this.array = new ArrayRewriter(manager, options.isSortingStore, options.isExpandingSelects);
|
|
145
146
|
this.seq = new SeqRewriter(manager, options.isCoalescingChars ?? true, this);
|
|
146
147
|
this.unusedVarsEliminator = new UnusedVarsEliminator(manager);
|
|
147
148
|
this.der = new Der(manager);
|
|
@@ -154,6 +155,17 @@ export class Rewriter extends RewriterTpl {
|
|
|
154
155
|
super.release();
|
|
155
156
|
}
|
|
156
157
|
|
|
158
|
+
// A rewrite that the spent resource limit stops answers its input instead of failing.
|
|
159
|
+
rewrite(expr: number) {
|
|
160
|
+
try {
|
|
161
|
+
return super.rewrite(expr);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (this.manager.limit.inc()) throw error;
|
|
164
|
+
this.manager.incRef(expr);
|
|
165
|
+
return expr;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
157
169
|
private reduceTo(expr: number, depth: number): number {
|
|
158
170
|
const manager = this.manager;
|
|
159
171
|
const frames: ReduceFrame[] = [];
|
|
@@ -465,7 +477,7 @@ export class Rewriter extends RewriterTpl {
|
|
|
465
477
|
const manager = this.manager;
|
|
466
478
|
if (sort === SORT_BOOL && manager.sorts[first] !== SORT_BOOL) {
|
|
467
479
|
if (this.isIte(first)) {
|
|
468
|
-
if (manager.
|
|
480
|
+
if (manager.isValue(second) && manager.getRefCount(first) === 1)
|
|
469
481
|
return this.pullIteCore(decl, first, second, sort, false);
|
|
470
482
|
if (this.isIte(second) && manager.getArg(first, 0) === manager.getArg(second, 0)) {
|
|
471
483
|
const branches = [1, 2].map((index) =>
|
|
@@ -481,15 +493,15 @@ export class Rewriter extends RewriterTpl {
|
|
|
481
493
|
};
|
|
482
494
|
}
|
|
483
495
|
}
|
|
484
|
-
if (this.isIte(second) && manager.
|
|
496
|
+
if (this.isIte(second) && manager.isValue(first) && manager.getRefCount(second) === 1)
|
|
485
497
|
return this.pullIteCore(decl, second, first, sort, true);
|
|
486
498
|
}
|
|
487
499
|
const family = manager.funcDecls[decl].family;
|
|
488
500
|
if (family !== FAMILY_BASIC && family !== FAMILY_ARITH && family !== FAMILY_BV)
|
|
489
501
|
return undefined;
|
|
490
|
-
if (manager.
|
|
502
|
+
if (manager.isValue(first) && this.isIteValueTree(second))
|
|
491
503
|
return this.pullIteCore(decl, second, first, sort, true);
|
|
492
|
-
if (manager.
|
|
504
|
+
if (manager.isValue(second) && this.isIteValueTree(first))
|
|
493
505
|
return this.pullIteCore(decl, first, second, sort, false);
|
|
494
506
|
return undefined;
|
|
495
507
|
}
|
|
@@ -506,7 +518,7 @@ export class Rewriter extends RewriterTpl {
|
|
|
506
518
|
manager.funcDecls[decl].op === OP_EQ
|
|
507
519
|
? branch === value
|
|
508
520
|
? manager.trueExpr
|
|
509
|
-
:
|
|
521
|
+
: manager.areDistinct(branch, value)
|
|
510
522
|
? manager.falseExpr
|
|
511
523
|
: manager.mkEq(branch, value)
|
|
512
524
|
: manager.mkApp(decl, isSwapped ? [value, branch] : [branch, value], sort),
|
|
@@ -521,7 +533,7 @@ export class Rewriter extends RewriterTpl {
|
|
|
521
533
|
for (let ite = todo.pop(); ite !== undefined; ite = todo.pop()) {
|
|
522
534
|
for (const branch of [manager.getArg(ite, 1), manager.getArg(ite, 2)]) {
|
|
523
535
|
if (this.isIte(branch) && manager.getRefCount(branch) === 1) todo.push(branch);
|
|
524
|
-
else if (!manager.
|
|
536
|
+
else if (!manager.isValue(branch)) return false;
|
|
525
537
|
}
|
|
526
538
|
}
|
|
527
539
|
return true;
|
|
@@ -879,9 +891,9 @@ export class Rewriter extends RewriterTpl {
|
|
|
879
891
|
private tryIteEq(ite: number, other: number): Rewrite | undefined {
|
|
880
892
|
const manager = this.manager;
|
|
881
893
|
if (!this.isIte(ite)) return undefined;
|
|
882
|
-
if (manager.getArg(ite, 1) === other &&
|
|
894
|
+
if (manager.getArg(ite, 1) === other && manager.areDistinct(manager.getArg(ite, 2), other))
|
|
883
895
|
return { expr: manager.getArg(ite, 0), depth: 1 };
|
|
884
|
-
if (manager.getArg(ite, 2) === other &&
|
|
896
|
+
if (manager.getArg(ite, 2) === other && manager.areDistinct(manager.getArg(ite, 1), other))
|
|
885
897
|
return { expr: manager.mkNot(manager.getArg(ite, 0)), depth: 1 };
|
|
886
898
|
return undefined;
|
|
887
899
|
}
|
|
@@ -890,15 +902,10 @@ export class Rewriter extends RewriterTpl {
|
|
|
890
902
|
return this.manager.getOp(expr) === OP_ITE;
|
|
891
903
|
}
|
|
892
904
|
|
|
893
|
-
private areDistinct(first: number, second: number) {
|
|
894
|
-
const manager = this.manager;
|
|
895
|
-
return first !== second && manager.isUniqueValue(first) && manager.isUniqueValue(second);
|
|
896
|
-
}
|
|
897
|
-
|
|
898
905
|
private mkIteValueEq(left: number, right: number): number | Rewrite | undefined {
|
|
899
906
|
const manager = this.manager;
|
|
900
|
-
if (this.isIte(left) && manager.
|
|
901
|
-
if (this.isIte(right) && manager.
|
|
907
|
+
if (this.isIte(left) && manager.isValue(right)) return this.tryIteValue(left, right);
|
|
908
|
+
if (this.isIte(right) && manager.isValue(left)) return this.tryIteValue(right, left);
|
|
902
909
|
if (
|
|
903
910
|
!this.isIte(left) ||
|
|
904
911
|
!this.isIte(right) ||
|
|
@@ -907,7 +914,7 @@ export class Rewriter extends RewriterTpl {
|
|
|
907
914
|
manager.getArg(left, 2),
|
|
908
915
|
manager.getArg(right, 1),
|
|
909
916
|
manager.getArg(right, 2),
|
|
910
|
-
].every((arg) => manager.
|
|
917
|
+
].every((arg) => manager.isValue(arg))
|
|
911
918
|
)
|
|
912
919
|
return undefined;
|
|
913
920
|
const mkOr = (args: number[]) => manager.mkApp(OP_OR, args, SORT_BOOL);
|
|
@@ -950,16 +957,16 @@ export class Rewriter extends RewriterTpl {
|
|
|
950
957
|
const mkPlainEq = (branch: number) =>
|
|
951
958
|
branch === value
|
|
952
959
|
? manager.trueExpr
|
|
953
|
-
:
|
|
960
|
+
: manager.areDistinct(branch, value)
|
|
954
961
|
? manager.falseExpr
|
|
955
962
|
: manager.mkEq(branch, value);
|
|
956
963
|
const mkAnd = (first: number, second: number) =>
|
|
957
964
|
manager.mkApp(OP_AND, [first, second], SORT_BOOL);
|
|
958
965
|
const mkOr = (first: number, second: number) =>
|
|
959
966
|
manager.mkApp(OP_OR, [first, second], SORT_BOOL);
|
|
960
|
-
if (
|
|
967
|
+
if (manager.areDistinct(value, elseExpr))
|
|
961
968
|
return { expr: mkAnd(mkBranchEq(thenExpr), condition), depth: 2 };
|
|
962
|
-
if (
|
|
969
|
+
if (manager.areDistinct(value, thenExpr))
|
|
963
970
|
return { expr: mkAnd(mkBranchEq(elseExpr), manager.mkNot(condition)), depth: 2 };
|
|
964
971
|
if (value === thenExpr)
|
|
965
972
|
return value === elseExpr
|
|
@@ -969,8 +976,8 @@ export class Rewriter extends RewriterTpl {
|
|
|
969
976
|
return { expr: mkOr(write(this.mkEq(thenExpr, value)), manager.mkNot(condition)), depth: 2 };
|
|
970
977
|
const isValueIte = (expr: number) =>
|
|
971
978
|
this.isIte(expr) &&
|
|
972
|
-
manager.
|
|
973
|
-
manager.
|
|
979
|
+
manager.isValue(manager.getArg(expr, 1)) &&
|
|
980
|
+
manager.isValue(manager.getArg(expr, 2));
|
|
974
981
|
const getExpr = (result: number | Rewrite) =>
|
|
975
982
|
typeof result === "number" ? result : result.expr;
|
|
976
983
|
const thenEq = isValueIte(thenExpr) ? this.tryIteValue(thenExpr, value) : undefined;
|
|
@@ -995,7 +1002,7 @@ export class Rewriter extends RewriterTpl {
|
|
|
995
1002
|
const expr = todo.pop() ?? ite;
|
|
996
1003
|
if (visited.has(expr)) continue;
|
|
997
1004
|
visited.add(expr);
|
|
998
|
-
if (
|
|
1005
|
+
if (manager.isValue(expr) && manager.areDistinct(expr, value)) continue;
|
|
999
1006
|
if (!this.isIte(expr)) return false;
|
|
1000
1007
|
todo.push(manager.getArg(expr, 1), manager.getArg(expr, 2));
|
|
1001
1008
|
}
|
|
@@ -1014,8 +1021,7 @@ export class Rewriter extends RewriterTpl {
|
|
|
1014
1021
|
private mkEqCore(inputLeft: number, inputRight: number): number | Rewrite | undefined {
|
|
1015
1022
|
const manager = this.manager;
|
|
1016
1023
|
if (inputLeft === inputRight) return manager.trueExpr;
|
|
1017
|
-
if (manager.
|
|
1018
|
-
return manager.falseExpr;
|
|
1024
|
+
if (manager.areDistinct(inputLeft, inputRight)) return manager.falseExpr;
|
|
1019
1025
|
const iteEq = this.tryIteEq(inputLeft, inputRight) ?? this.tryIteEq(inputRight, inputLeft);
|
|
1020
1026
|
if (iteEq !== undefined) return iteEq;
|
|
1021
1027
|
const iteValueEq = this.mkIteValueEq(inputLeft, inputRight);
|
|
@@ -114,7 +114,6 @@ export class Goal2Sat implements SatInternalizer, EufInternalizer {
|
|
|
114
114
|
|
|
115
115
|
private insertAtom(expr: number, boolVar: number) {
|
|
116
116
|
this.atoms.set(expr, boolVar);
|
|
117
|
-
if (this.mkThSolver === null) return;
|
|
118
117
|
this.manager.incRef(expr);
|
|
119
118
|
this.recentAtoms.push(expr);
|
|
120
119
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SmtTacticError, SmtUnsupportedError } from "../../../../errors";
|
|
1
|
+
import { SmtCanceledError, SmtTacticError, SmtUnsupportedError } from "../../../../errors";
|
|
2
2
|
import { type AstManager, OP_AND, OP_EQ, OP_IMPLIES, OP_NOT, OP_OR, SORT_BOOL } from "../ast";
|
|
3
3
|
import { mkNot } from "../ast-util";
|
|
4
4
|
import { BitBlasterRewriter } from "../bit-blast-tactic";
|
|
@@ -7,11 +7,16 @@ import { L_FALSE, L_TRUE, L_UNDEF } from "../lbool";
|
|
|
7
7
|
import { ProtoModel } from "../proto-model";
|
|
8
8
|
import { RefVector } from "../ref-vector";
|
|
9
9
|
import type { ThSolverFactory } from "../euf/euf-solver";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
applyDefinitions,
|
|
12
|
+
convertModel,
|
|
13
|
+
mkIncSatEufPreprocess,
|
|
14
|
+
mkIncSatPreprocess,
|
|
15
|
+
} from "../tactic";
|
|
11
16
|
import type { SatParams } from "./config";
|
|
12
17
|
import { Goal2Sat } from "./goal2sat";
|
|
13
18
|
import { getConsequences } from "./consequences";
|
|
14
|
-
import { isLiteral, sat2goal } from "./sat2goal";
|
|
19
|
+
import { isLiteral, Sat2GoalConverter, sat2goal } from "./sat2goal";
|
|
15
20
|
import { Solver } from "./solver";
|
|
16
21
|
|
|
17
22
|
const BIT_BLAST_PARAMS = {
|
|
@@ -26,6 +31,7 @@ interface Scope {
|
|
|
26
31
|
readonly fmlsSize: number;
|
|
27
32
|
readonly fmlsHead: number;
|
|
28
33
|
readonly namesSize: number;
|
|
34
|
+
readonly hasUninterpreted: boolean;
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
export class IncSatSolver {
|
|
@@ -41,6 +47,7 @@ export class IncSatSolver {
|
|
|
41
47
|
private bitBlaster: BitBlasterRewriter | undefined;
|
|
42
48
|
// m_mcs.back(), the model converters of the preprocessed goals.
|
|
43
49
|
private readonly converters: Goal;
|
|
50
|
+
private readonly satConverter: Sat2GoalConverter;
|
|
44
51
|
private isInternalizedConverted = false;
|
|
45
52
|
private readonly internalized: RefVector;
|
|
46
53
|
private hasUninterpreted = false;
|
|
@@ -68,6 +75,7 @@ export class IncSatSolver {
|
|
|
68
75
|
this.names = new RefVector(manager);
|
|
69
76
|
this.core = new RefVector(manager);
|
|
70
77
|
this.converters = new Goal(manager);
|
|
78
|
+
this.satConverter = new Sat2GoalConverter(manager);
|
|
71
79
|
this.internalized = new RefVector(manager);
|
|
72
80
|
}
|
|
73
81
|
|
|
@@ -109,22 +117,26 @@ export class IncSatSolver {
|
|
|
109
117
|
this.assertExpr(manager.mkApp(OP_IMPLIES, [name, expr], SORT_BOOL));
|
|
110
118
|
}
|
|
111
119
|
|
|
112
|
-
// Outside sat.euf, a scope would also need the scopes of the bit-blaster.
|
|
113
120
|
push() {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
try {
|
|
122
|
+
this.internalizeFormulas();
|
|
123
|
+
} finally {
|
|
124
|
+
this.goal2sat.push();
|
|
125
|
+
this.solver.userPush();
|
|
126
|
+
this.bitBlaster?.push();
|
|
127
|
+
this.scopes.push({
|
|
128
|
+
converters: this.converters.converters,
|
|
129
|
+
fmlsSize: this.fmls.size,
|
|
130
|
+
fmlsHead: this.fmlsHead,
|
|
131
|
+
namesSize: this.names.size,
|
|
132
|
+
hasUninterpreted: this.hasUninterpreted,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
124
135
|
}
|
|
125
136
|
|
|
126
137
|
pop(numScopes: number) {
|
|
127
138
|
const count = Math.min(numScopes, this.scopes.length);
|
|
139
|
+
this.bitBlaster?.pop(count);
|
|
128
140
|
this.goal2sat.pop(count);
|
|
129
141
|
this.solver.userPop(count);
|
|
130
142
|
for (let index = 0; index < count; index++) {
|
|
@@ -133,9 +145,16 @@ export class IncSatSolver {
|
|
|
133
145
|
this.fmlsHead = scope.fmlsHead;
|
|
134
146
|
this.fmls.shrink(scope.fmlsSize);
|
|
135
147
|
this.names.shrink(scope.namesSize);
|
|
148
|
+
this.hasUninterpreted = scope.hasUninterpreted;
|
|
136
149
|
}
|
|
137
150
|
}
|
|
138
151
|
|
|
152
|
+
private getBitBlaster() {
|
|
153
|
+
const bitBlaster = (this.bitBlaster ??= new BitBlasterRewriter(this.manager, BIT_BLAST_PARAMS));
|
|
154
|
+
while (bitBlaster.getNumScopes() < this.scopes.length) bitBlaster.push();
|
|
155
|
+
return bitBlaster;
|
|
156
|
+
}
|
|
157
|
+
|
|
139
158
|
private checkUninterpreted() {
|
|
140
159
|
if (this.goal2sat.unhandledFuns.length === 0) return L_TRUE;
|
|
141
160
|
this.hasUninterpreted = true;
|
|
@@ -155,7 +174,7 @@ export class IncSatSolver {
|
|
|
155
174
|
private internalizeGoal(goal: Goal) {
|
|
156
175
|
this.solver.popToBaseLevel();
|
|
157
176
|
if (this.solver.isInconsistent) return L_FALSE;
|
|
158
|
-
const bitBlaster =
|
|
177
|
+
const bitBlaster = this.getBitBlaster();
|
|
159
178
|
const subgoals = (() => {
|
|
160
179
|
if (this.isCnf) return [goal];
|
|
161
180
|
try {
|
|
@@ -168,8 +187,10 @@ export class IncSatSolver {
|
|
|
168
187
|
return goals;
|
|
169
188
|
} catch (error) {
|
|
170
189
|
this.releaseBitBlaster();
|
|
171
|
-
if (!(error instanceof SmtTacticError)) throw error;
|
|
172
|
-
|
|
190
|
+
if (!(error instanceof SmtTacticError || error instanceof SmtCanceledError)) throw error;
|
|
191
|
+
// The tactics of the preprocessing report a limit that stops their rewriters as a tactic_exception.
|
|
192
|
+
this.reasonUnknown =
|
|
193
|
+
error instanceof SmtCanceledError ? this.manager.limit.getCancelMessage() : error.message;
|
|
173
194
|
return undefined;
|
|
174
195
|
}
|
|
175
196
|
})();
|
|
@@ -230,7 +251,16 @@ export class IncSatSolver {
|
|
|
230
251
|
this.internalizeAssumptions([...literals, ...this.names.items]);
|
|
231
252
|
this.reasonUnknown = "no reason given";
|
|
232
253
|
this.isInternalizedConverted = false;
|
|
233
|
-
const result =
|
|
254
|
+
const result = (() => {
|
|
255
|
+
try {
|
|
256
|
+
return this.solver.check(this.asms);
|
|
257
|
+
} catch (error) {
|
|
258
|
+
if (!(error instanceof SmtCanceledError)) throw error;
|
|
259
|
+
// check_sat_core counts a step to see whether the limit stopped the search.
|
|
260
|
+
manager.limit.inc();
|
|
261
|
+
return L_UNDEF;
|
|
262
|
+
}
|
|
263
|
+
})();
|
|
234
264
|
if (result === L_TRUE && this.hasUninterpreted) {
|
|
235
265
|
this.reasonUnknown = "(sat.giveup has-uninterpreted)";
|
|
236
266
|
return L_UNDEF;
|
|
@@ -263,7 +293,7 @@ export class IncSatSolver {
|
|
|
263
293
|
|
|
264
294
|
getConsequences(assumptions: readonly number[], vars: readonly number[]) {
|
|
265
295
|
const manager = this.manager;
|
|
266
|
-
this.
|
|
296
|
+
this.getBitBlaster();
|
|
267
297
|
this.dep2asm = new Map();
|
|
268
298
|
this.solver.popToBaseLevel();
|
|
269
299
|
const consequences: number[] = [];
|
|
@@ -328,18 +358,15 @@ export class IncSatSolver {
|
|
|
328
358
|
const manager = this.manager;
|
|
329
359
|
if (!this.solver.isModelCurrent || this.fmls.size > this.fmlsHead) return null;
|
|
330
360
|
const euf = this.goal2sat.euf;
|
|
331
|
-
|
|
332
|
-
const model = euf === null ? new ProtoModel(manager) : new ProtoModel(manager).mkModel();
|
|
361
|
+
const model = new ProtoModel(manager).mkModel();
|
|
333
362
|
for (const [expr, boolVar] of this.goal2sat.atoms) {
|
|
334
363
|
if (!manager.isUninterpretedConst(expr)) continue;
|
|
335
364
|
const value = this.solver.model[boolVar];
|
|
336
365
|
if (value === L_TRUE) model.registerConst(manager.decls[expr], manager.trueExpr);
|
|
337
366
|
else if (value === L_FALSE) model.registerConst(manager.decls[expr], manager.falseExpr);
|
|
338
367
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
euf === null ? model.mkModel() : euf.updateModel(model),
|
|
342
|
-
);
|
|
368
|
+
if (this.satConverter.entries.length > 0) applyDefinitions(this.satConverter.entries, model);
|
|
369
|
+
const converted = convertModel(this.converters, euf === null ? model : euf.updateModel(model));
|
|
343
370
|
converted.incRef();
|
|
344
371
|
this.models.push(converted);
|
|
345
372
|
return converted;
|
|
@@ -370,10 +397,9 @@ export class IncSatSolver {
|
|
|
370
397
|
if (this.fmlsHead !== this.fmls.size) return this.fmls.items;
|
|
371
398
|
if (this.isInternalizedConverted) return this.internalized.items;
|
|
372
399
|
const goal = new Goal(this.manager);
|
|
373
|
-
sat2goal(this.manager, this.solver, this.goal2sat.atoms, goal);
|
|
400
|
+
sat2goal(this.manager, this.solver, this.goal2sat.atoms, goal, this.satConverter);
|
|
374
401
|
this.internalized.reset();
|
|
375
402
|
for (const form of goal.forms.items) this.internalized.push(form);
|
|
376
|
-
this.converters.converters = [...this.converters.converters, ...goal.converters];
|
|
377
403
|
this.isInternalizedConverted = true;
|
|
378
404
|
return this.internalized.items;
|
|
379
405
|
}
|
|
@@ -382,7 +408,9 @@ export class IncSatSolver {
|
|
|
382
408
|
// asserted formulas are internalized.
|
|
383
409
|
getConverters(): Goal["converters"] {
|
|
384
410
|
this.getAssertions();
|
|
385
|
-
return this.isInternalizedConverted
|
|
411
|
+
return this.isInternalizedConverted
|
|
412
|
+
? [...this.converters.converters, { definitions: this.satConverter.entries }]
|
|
413
|
+
: [];
|
|
386
414
|
}
|
|
387
415
|
|
|
388
416
|
release() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SmtTacticError } from "../../../../errors";
|
|
1
|
+
import { SmtCanceledError, SmtTacticError } from "../../../../errors";
|
|
2
2
|
import type { AstManager } from "../ast";
|
|
3
3
|
import type { ThSolverFactory } from "../euf/euf-solver";
|
|
4
4
|
import { OVER, type Goal } from "../goal";
|
|
@@ -6,7 +6,7 @@ import { L_FALSE, L_TRUE, L_UNDEF } from "../lbool";
|
|
|
6
6
|
import { ProtoModel } from "../proto-model";
|
|
7
7
|
import type { SatParams } from "./config";
|
|
8
8
|
import { Goal2Sat } from "./goal2sat";
|
|
9
|
-
import { sat2goal } from "./sat2goal";
|
|
9
|
+
import { Sat2GoalConverter, sat2goal } from "./sat2goal";
|
|
10
10
|
import { Solver } from "./solver";
|
|
11
11
|
|
|
12
12
|
// With a theory factory, the sat solver runs the euf solver of sat.euf as its extension.
|
|
@@ -19,7 +19,14 @@ export const createSatTactic =
|
|
|
19
19
|
const goal2sat = new Goal2Sat(manager, solver, params.get("ite_extra") !== false, mkThSolver);
|
|
20
20
|
goal2sat.run(goal.forms.items);
|
|
21
21
|
goal.reset();
|
|
22
|
-
const result =
|
|
22
|
+
const result = (() => {
|
|
23
|
+
try {
|
|
24
|
+
return solver.check();
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (error instanceof SmtCanceledError) throw new SmtTacticError("canceled");
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
})();
|
|
23
30
|
if (result === L_UNDEF) goal.reasonUnknown = solver.reasonUnknown;
|
|
24
31
|
const unhandledFuns = goal2sat.euf?.unhandledFunctions ?? goal2sat.unhandledFuns;
|
|
25
32
|
if (result === L_FALSE) goal.assert(manager.falseExpr);
|
|
@@ -36,7 +43,9 @@ export const createSatTactic =
|
|
|
36
43
|
euf?.validateModel(goal.model);
|
|
37
44
|
} else {
|
|
38
45
|
solver.popToBaseLevel();
|
|
39
|
-
|
|
46
|
+
const converter = new Sat2GoalConverter(manager);
|
|
47
|
+
sat2goal(manager, solver, goal2sat.atoms, goal, converter);
|
|
48
|
+
goal.addDefinitions(converter.entries);
|
|
40
49
|
if (unhandledFuns.length > 0) goal.updatePrecision(OVER);
|
|
41
50
|
}
|
|
42
51
|
goal.depth++;
|
|
@@ -12,9 +12,9 @@ export const isLiteral = (manager: AstManager, expr: number) =>
|
|
|
12
12
|
manager.isUninterpretedConst(expr) ||
|
|
13
13
|
(manager.isNot(expr) && manager.isUninterpretedConst(manager.getArg(expr, 0)));
|
|
14
14
|
|
|
15
|
-
class Sat2GoalConverter {
|
|
15
|
+
export class Sat2GoalConverter {
|
|
16
16
|
readonly smc = new ModelConverter();
|
|
17
|
-
var2expr: number[] = [];
|
|
17
|
+
readonly var2expr: number[] = [];
|
|
18
18
|
readonly entries: Definition[] = [];
|
|
19
19
|
|
|
20
20
|
constructor(private manager: AstManager) {}
|
|
@@ -22,17 +22,21 @@ class Sat2GoalConverter {
|
|
|
22
22
|
private add(expr: number, def: number) {
|
|
23
23
|
const manager = this.manager;
|
|
24
24
|
manager.incRef(def);
|
|
25
|
+
manager.incDeclRef(manager.decls[expr]);
|
|
25
26
|
this.entries.push({ decl: manager.decls[expr], def });
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
hide(expr: number) {
|
|
29
|
-
|
|
30
|
+
const manager = this.manager;
|
|
31
|
+
manager.incDeclRef(manager.decls[expr]);
|
|
32
|
+
this.entries.push({ decl: manager.decls[expr], def: -1 });
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
flushSmc(solver: Solver, atoms: Map<number, number>) {
|
|
33
36
|
this.smc.flush(solver.mc);
|
|
34
|
-
|
|
35
|
-
this.var2expr.
|
|
37
|
+
const numVars = solver.numVars();
|
|
38
|
+
while (this.var2expr.length < numVars) this.var2expr.push(-1);
|
|
39
|
+
this.var2expr.length = numVars;
|
|
36
40
|
for (const [expr, boolVar] of atoms) this.var2expr[boolVar] = expr;
|
|
37
41
|
this.flushGmc();
|
|
38
42
|
}
|
|
@@ -106,12 +110,12 @@ export const sat2goal = (
|
|
|
106
110
|
solver: Solver,
|
|
107
111
|
atoms: Map<number, number>,
|
|
108
112
|
goal: Goal,
|
|
113
|
+
converter: Sat2GoalConverter,
|
|
109
114
|
) => {
|
|
110
115
|
if (solver.atBaseLvl() && solver.isInconsistent) {
|
|
111
116
|
goal.assert(manager.falseExpr);
|
|
112
117
|
return;
|
|
113
118
|
}
|
|
114
|
-
const converter = new Sat2GoalConverter(manager);
|
|
115
119
|
converter.flushSmc(solver, atoms);
|
|
116
120
|
const lit2expr = new Int32Array(2 * solver.numVars()).fill(-1);
|
|
117
121
|
for (const [expr, boolVar] of atoms) {
|
|
@@ -161,5 +165,4 @@ export const sat2goal = (
|
|
|
161
165
|
const formulas: number[] = [];
|
|
162
166
|
solver.ext?.toFormulas(getExpr, formulas);
|
|
163
167
|
for (const formula of formulas) goal.assert(formula);
|
|
164
|
-
goal.addDefinitions(converter.entries);
|
|
165
168
|
};
|
|
@@ -239,7 +239,7 @@ class ConsequenceFinder {
|
|
|
239
239
|
const result = kernel.check(assumptions);
|
|
240
240
|
if (result !== L_TRUE) return result;
|
|
241
241
|
if (context.qmanager.hasQuantifiers()) return L_UNDEF;
|
|
242
|
-
const model = context.
|
|
242
|
+
const model = context.getSatModel();
|
|
243
243
|
for (const variable of vars) {
|
|
244
244
|
const value = model.eval(variable, false);
|
|
245
245
|
trail.pushOwned(value);
|