Skip to content

Commit 2b81ac8

Browse files
author
BaierD
committed
Allow and use direct access to prover specific ShutdownNotifier
1 parent 5af69e6 commit 2b81ac8

File tree

12 files changed

+27
-33
lines changed

12 files changed

+27
-33
lines changed

src/org/sosy_lab/java_smt/basicimpl/AbstractProver.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public abstract class AbstractProver<T> implements BasicProverEnvironment<T> {
4949

5050
private static final String TEMPLATE = "Please set the prover option %s.";
5151

52-
// Do we even need this?
53-
private final ShutdownNotifier contextShutdownNotifier;
52+
protected final ShutdownNotifier proverShutdownNotifier;
5453
protected final ShutdownManager proverShutdownManager;
5554

5655
protected AbstractProver(ShutdownNotifier pShutdownNotifier, Set<ProverOptions> pOptions) {
@@ -63,8 +62,8 @@ protected AbstractProver(ShutdownNotifier pShutdownNotifier, Set<ProverOptions>
6362

6463
assertedFormulas.add(LinkedHashMultimap.create());
6564

66-
contextShutdownNotifier = pShutdownNotifier;
67-
proverShutdownManager = ShutdownManager.createWithParent(contextShutdownNotifier);
65+
proverShutdownManager = ShutdownManager.createWithParent(pShutdownNotifier);
66+
proverShutdownNotifier = proverShutdownManager.getNotifier();
6867
}
6968

7069
protected final void checkGenerateModels() {

src/org/sosy_lab/java_smt/basicimpl/AbstractProverWithAllSat.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private <R> void iterateOverAllModels(
6666
AllSatCallback<R> callback, List<BooleanFormula> importantPredicates)
6767
throws SolverException, InterruptedException {
6868
while (!isUnsat()) {
69-
proverShutdownManager.getNotifier().shutdownIfNecessary();
69+
proverShutdownNotifier.shutdownIfNecessary();
7070

7171
ImmutableList.Builder<BooleanFormula> valuesOfModel = ImmutableList.builder();
7272
try (Evaluator evaluator = getEvaluatorWithoutChecks()) {
@@ -86,11 +86,11 @@ private <R> void iterateOverAllModels(
8686

8787
final ImmutableList<BooleanFormula> values = valuesOfModel.build();
8888
callback.apply(values);
89-
proverShutdownManager.getNotifier().shutdownIfNecessary();
89+
proverShutdownNotifier.shutdownIfNecessary();
9090

9191
BooleanFormula negatedModel = bmgr.not(bmgr.and(values));
9292
addConstraint(negatedModel);
93-
proverShutdownManager.getNotifier().shutdownIfNecessary();
93+
proverShutdownNotifier.shutdownIfNecessary();
9494
}
9595
}
9696

@@ -111,7 +111,7 @@ private <R> void iterateOverAllPredicateCombinations(
111111
Deque<BooleanFormula> valuesOfModel)
112112
throws SolverException, InterruptedException {
113113

114-
proverShutdownManager.getNotifier().shutdownIfNecessary();
114+
proverShutdownNotifier.shutdownIfNecessary();
115115

116116
if (isUnsat()) {
117117
return;

src/org/sosy_lab/java_smt/solvers/bitwuzla/BitwuzlaTheoremProver.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ class BitwuzlaTheoremProver extends AbstractProverWithAllSat<Void> implements Pr
3939
new Terminator() {
4040
@Override
4141
public boolean terminate() {
42-
return proverShutdownManager
43-
.getNotifier()
44-
.shouldShutdown();
42+
return proverShutdownNotifier.shouldShutdown();
4543
}
4644
};
4745
private final Bitwuzla env;
@@ -122,8 +120,7 @@ private boolean readSATResult(Result resultValue) throws SolverException, Interr
122120
return false;
123121
} else if (resultValue == Result.UNSAT) {
124122
return true;
125-
} else if (resultValue == Result.UNKNOWN
126-
&& proverShutdownManager.getNotifier().shouldShutdown()) {
123+
} else if (resultValue == Result.UNKNOWN && proverShutdownNotifier.shouldShutdown()) {
127124
throw new InterruptedException();
128125
} else {
129126
throw new SolverException("Bitwuzla returned UNKNOWN.");

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 = proverShutdownManager.getNotifier()::shouldShutdown;
52+
terminationCallback = proverShutdownNotifier::shouldShutdown;
5353
terminationCallbackHelper = addTerminationCallback();
5454

5555
isAnyStackAlive = pIsAnyStackAlive;

src/org/sosy_lab/java_smt/solvers/cvc4/CVC4TheoremProver.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,11 @@ public boolean isUnsat() throws InterruptedException, SolverException {
203203
}
204204

205205
Result result;
206-
try (ShutdownHook hook =
207-
new ShutdownHook(proverShutdownManager.getNotifier(), smtEngine::interrupt)) {
208-
proverShutdownManager.getNotifier().shutdownIfNecessary();
206+
try (ShutdownHook hook = new ShutdownHook(proverShutdownNotifier, smtEngine::interrupt)) {
207+
proverShutdownNotifier.shutdownIfNecessary();
209208
result = smtEngine.checkSat();
210209
}
211-
proverShutdownManager.getNotifier().shutdownIfNecessary();
210+
proverShutdownNotifier.shutdownIfNecessary();
212211
return convertSatResult(result);
213212
}
214213

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

Lines changed: 1 addition & 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-
proverShutdownManager.getNotifier().shutdownIfNecessary();
206+
proverShutdownNotifier.shutdownIfNecessary();
207207
return convertSatResult(result);
208208
}
209209

src/org/sosy_lab/java_smt/solvers/mathsat5/Mathsat5AbstractProver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public boolean isUnsat() throws InterruptedException, SolverException {
113113
*/
114114
private TerminationCallback getTerminationTest() {
115115
return () -> {
116-
proverShutdownManager.getNotifier().shutdownIfNecessary();
116+
proverShutdownNotifier.shutdownIfNecessary();
117117
return false;
118118
};
119119
}
@@ -283,7 +283,7 @@ class MathsatAllSatCallback<T> implements AllSatModelCallback {
283283

284284
@Override
285285
public void callback(long[] model) throws InterruptedException {
286-
proverShutdownManager.getNotifier().shutdownIfNecessary();
286+
proverShutdownNotifier.shutdownIfNecessary();
287287
clientCallback.apply(
288288
Collections.unmodifiableList(
289289
Lists.transform(Longs.asList(model), creator::encapsulateBoolean)));

src/org/sosy_lab/java_smt/solvers/opensmt/OpenSmtAbstractProver.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,8 @@ public boolean isUnsat() throws InterruptedException, SolverException {
231231
changedSinceLastSatQuery = false;
232232

233233
sstat result;
234-
try (ShutdownHook listener =
235-
new ShutdownHook(proverShutdownManager.getNotifier(), osmtSolver::stop)) {
236-
proverShutdownManager.getNotifier().shutdownIfNecessary();
234+
try (ShutdownHook listener = new ShutdownHook(proverShutdownNotifier, osmtSolver::stop)) {
235+
proverShutdownNotifier.shutdownIfNecessary();
237236
try {
238237
result = osmtSolver.check();
239238
} catch (Exception e) {
@@ -252,7 +251,7 @@ public boolean isUnsat() throws InterruptedException, SolverException {
252251
throw new SolverException("OpenSMT crashed while checking satisfiability.", e);
253252
}
254253
}
255-
proverShutdownManager.getNotifier().shutdownIfNecessary();
254+
proverShutdownNotifier.shutdownIfNecessary();
256255
}
257256

258257
if (result.equals(sstat.Error())) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public boolean isUnsat() throws InterruptedException {
107107
// by using a shutdown listener. However, SmtInterpol resets the
108108
// mStopEngine flag in DPLLEngine before starting to solve,
109109
// so we check here, too.
110-
proverShutdownManager.getNotifier().shutdownIfNecessary();
110+
proverShutdownNotifier.shutdownIfNecessary();
111111

112112
LBool result = env.checkSat();
113113
switch (result) {
@@ -244,7 +244,7 @@ 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-
proverShutdownManager.getNotifier().shutdownIfNecessary();
247+
proverShutdownNotifier.shutdownIfNecessary();
248248
for (Term[] model : env.checkAllsat(importantTerms)) {
249249
callback.apply(Collections3.transformedImmutableListCopy(model, creator::encapsulateBoolean));
250250
}

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-
proverShutdownManager.getNotifier().shutdownIfNecessary();
103+
proverShutdownNotifier.shutdownIfNecessary();
104104
}
105105
throw new AssertionError(e);
106106
}

0 commit comments

Comments
 (0)