Skip to content

Commit bd41343

Browse files
author
BaierD
committed
Add changes to non-usable solvers for prover based shutdown (Boolector, CVC5 and SMTInterpol, SMTInterpol might be usable with some work)
1 parent 8632bf7 commit bd41343

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

src/org/sosy_lab/java_smt/solvers/boolector/BoolectorAbstractProver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected BoolectorAbstractProver(
4949
this.manager = manager;
5050
this.creator = creator;
5151
this.btor = btor;
52-
terminationCallback = shutdownNotifier::shouldShutdown;
52+
terminationCallback = proverShutdownManager.getNotifier()::shouldShutdown;
5353
terminationCallbackHelper = addTerminationCallback();
5454

5555
isAnyStackAlive = pIsAnyStackAlive;

src/org/sosy_lab/java_smt/solvers/cvc5/CVC5AbstractProver.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public boolean isUnsat() throws InterruptedException, SolverException {
203203

204204
/* Shutdown currently not possible in CVC5. */
205205
Result result = solver.checkSat();
206-
shutdownNotifier.shutdownIfNecessary();
206+
proverShutdownManager.getNotifier().shutdownIfNecessary();
207207
return convertSatResult(result);
208208
}
209209

@@ -251,4 +251,10 @@ public void close() {
251251
}
252252
super.close();
253253
}
254+
255+
/* TODO: revisit once CVC5 supports interruption
256+
@Override
257+
protected ShutdownManager getShutdownManagerForProverImpl() throws UnsupportedOperationException {
258+
return proverShutdownManager;
259+
}*/
254260
}

src/org/sosy_lab/java_smt/solvers/smtinterpol/SmtInterpolAbstractProver.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ abstract class SmtInterpolAbstractProver<T> extends AbstractProver<T> {
5252
protected final FormulaCreator<Term, Sort, Script, FunctionSymbol> creator;
5353
protected final SmtInterpolFormulaManager mgr;
5454
protected final Deque<PersistentMap<String, BooleanFormula>> annotatedTerms = new ArrayDeque<>();
55-
protected final ShutdownNotifier shutdownNotifier;
5655

5756
private static final String PREFIX = "term_"; // for termnames
5857
private static final UniqueIdGenerator termIdGenerator =
@@ -63,11 +62,10 @@ abstract class SmtInterpolAbstractProver<T> extends AbstractProver<T> {
6362
Script pEnv,
6463
Set<ProverOptions> options,
6564
ShutdownNotifier pShutdownNotifier) {
66-
super(options);
65+
super(pShutdownNotifier, options);
6766
mgr = pMgr;
6867
creator = pMgr.getFormulaCreator();
6968
env = pEnv;
70-
shutdownNotifier = pShutdownNotifier;
7169
annotatedTerms.add(PathCopyingPersistentTreeMap.of());
7270
}
7371

@@ -109,7 +107,7 @@ public boolean isUnsat() throws InterruptedException {
109107
// by using a shutdown listener. However, SmtInterpol resets the
110108
// mStopEngine flag in DPLLEngine before starting to solve,
111109
// so we check here, too.
112-
shutdownNotifier.shutdownIfNecessary();
110+
proverShutdownManager.getNotifier().shutdownIfNecessary();
113111

114112
LBool result = env.checkSat();
115113
switch (result) {
@@ -127,7 +125,9 @@ public boolean isUnsat() throws InterruptedException {
127125
// SMTInterpol catches OOM, but we want to have it thrown.
128126
throw new OutOfMemoryError("Out of memory during SMTInterpol operation");
129127
case CANCELLED:
130-
shutdownNotifier.shutdownIfNecessary(); // expected if we requested termination
128+
proverShutdownManager
129+
.getNotifier()
130+
.shutdownIfNecessary(); // expected if we requested termination
131131
throw new SMTLIBException("checkSat returned UNKNOWN with unexpected reason " + reason);
132132
default:
133133
throw new SMTLIBException("checkSat returned UNKNOWN with unexpected reason " + reason);
@@ -244,10 +244,17 @@ public <R> R allSat(AllSatCallback<R> callback, List<BooleanFormula> important)
244244
// by using a shutdown listener. However, SmtInterpol resets the
245245
// mStopEngine flag in DPLLEngine before starting to solve,
246246
// so we check here, too.
247-
shutdownNotifier.shutdownIfNecessary();
247+
proverShutdownManager.getNotifier().shutdownIfNecessary();
248248
for (Term[] model : env.checkAllsat(importantTerms)) {
249249
callback.apply(Collections3.transformedImmutableListCopy(model, creator::encapsulateBoolean));
250250
}
251251
return callback.getResult();
252252
}
253+
254+
/* TODO: the shutdownNotifier is bound to the Script. But this is done in the context. It seems
255+
like it might be re-usable after a shutdown.
256+
@Override
257+
protected ShutdownManager getShutdownManagerForProverImpl() throws UnsupportedOperationException {
258+
return proverShutdownManager;
259+
}*/
253260
}

src/org/sosy_lab/java_smt/solvers/smtinterpol/SmtInterpolInterpolatingProver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public List<BooleanFormula> getTreeInterpolants(
100100
}
101101
} catch (SMTLIBException e) {
102102
if ("Timeout exceeded".equals(e.getMessage())) {
103-
shutdownNotifier.shutdownIfNecessary();
103+
proverShutdownManager.getNotifier().shutdownIfNecessary();
104104
}
105105
throw new AssertionError(e);
106106
}

0 commit comments

Comments
 (0)