Skip to content

Commit b048f56

Browse files
author
BaierD
committed
Add default implementation of isUnsat() to centralize checks (closed, shut-down etc.) and add more shutdown checks in the abstract prover
1 parent 92f2f60 commit b048f56

13 files changed

+26
-19
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.sosy_lab.java_smt.api.BooleanFormula;
2929
import org.sosy_lab.java_smt.api.Evaluator;
3030
import org.sosy_lab.java_smt.api.SolverContext.ProverOptions;
31+
import org.sosy_lab.java_smt.api.SolverException;
3132

3233
public abstract class AbstractProver<T> implements BasicProverEnvironment<T> {
3334

@@ -95,9 +96,20 @@ public int size() {
9596
return assertedFormulas.size() - 1;
9697
}
9798

99+
@Override
100+
public final boolean isUnsat() throws SolverException, InterruptedException {
101+
checkState(!closed);
102+
closeAllEvaluators(); // TODO: needed?
103+
proverShutdownNotifier.shutdownIfNecessary();
104+
return isUnsatImpl();
105+
}
106+
107+
protected abstract boolean isUnsatImpl() throws SolverException, InterruptedException;
108+
98109
@Override
99110
public final void push() throws InterruptedException {
100111
checkState(!closed);
112+
proverShutdownNotifier.shutdownIfNecessary();
101113
pushImpl();
102114
assertedFormulas.add(LinkedHashMultimap.create());
103115
}
@@ -118,6 +130,7 @@ public final void pop() {
118130
@CanIgnoreReturnValue
119131
public final @Nullable T addConstraint(BooleanFormula constraint) throws InterruptedException {
120132
checkState(!closed);
133+
proverShutdownNotifier.shutdownIfNecessary();
121134
T t = addConstraintImpl(constraint);
122135
Iterables.getLast(assertedFormulas).put(constraint, t);
123136
return t;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private boolean readSATResult(Result resultValue) throws SolverException, Interr
129129

130130
/** Check whether the conjunction of all formulas on the stack is unsatisfiable. */
131131
@Override
132-
public boolean isUnsat() throws SolverException, InterruptedException {
132+
protected boolean isUnsatImpl() throws SolverException, InterruptedException {
133133
Preconditions.checkState(!closed);
134134
wasLastSatCheckSat = false;
135135
final Result result = env.check_sat();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void close() {
8181
* Boolector should throw its own exceptions that tell you what went wrong!
8282
*/
8383
@Override
84-
public boolean isUnsat() throws SolverException, InterruptedException {
84+
protected boolean isUnsatImpl() throws SolverException, InterruptedException {
8585
Preconditions.checkState(!closed);
8686
wasLastSatCheckSat = false;
8787
final int result = BtorJNI.boolector_sat(btor);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ public ImmutableList<ValueAssignment> getModelAssignments() throws SolverExcepti
192192

193193
@Override
194194
@SuppressWarnings("try")
195-
public boolean isUnsat() throws InterruptedException, SolverException {
196-
Preconditions.checkState(!closed);
197-
closeAllEvaluators();
195+
protected boolean isUnsatImpl() throws InterruptedException, SolverException {
198196
changedSinceLastSatQuery = false;
199197
if (!incremental) {
200198
for (BooleanFormula f : getAssertedFormulas()) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ public ImmutableList<ValueAssignment> getModelAssignments() throws SolverExcepti
193193

194194
@Override
195195
@SuppressWarnings("try")
196-
public boolean isUnsat() throws InterruptedException, SolverException {
197-
Preconditions.checkState(!closed);
198-
closeAllEvaluators();
196+
public boolean isUnsatImpl() throws InterruptedException, SolverException {
199197
changedSinceLastSatQuery = false;
200198
if (!incremental) {
201199
getAssertedFormulas().forEach(f -> solver.assertFormula(creator.extractInfo(f)));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private long buildConfig(Set<ProverOptions> opts) {
9595
protected abstract void createConfig(Map<String, String> pConfig);
9696

9797
@Override
98-
public boolean isUnsat() throws InterruptedException, SolverException {
98+
protected boolean isUnsatImpl() throws InterruptedException, SolverException {
9999
Preconditions.checkState(!closed);
100100

101101
final long hook = msat_set_termination_callback(curEnv, getTerminationTest());

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,7 @@ protected String getReasonFromSolverFeatures(
225225

226226
@Override
227227
@SuppressWarnings("try") // ShutdownHook is never referenced, and this is correct.
228-
public boolean isUnsat() throws InterruptedException, SolverException {
229-
Preconditions.checkState(!closed);
230-
closeAllEvaluators();
228+
protected boolean isUnsatImpl() throws InterruptedException, SolverException {
231229
changedSinceLastSatQuery = false;
232230

233231
sstat result;

src/org/sosy_lab/java_smt/solvers/princess/PrincessAbstractProver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected PrincessAbstractProver(
8585
* SAT or UNSAT.
8686
*/
8787
@Override
88-
public boolean isUnsat() throws SolverException {
88+
protected boolean isUnsatImpl() throws SolverException {
8989
Preconditions.checkState(!closed);
9090
wasLastSatCheckSat = false;
9191
evaluatedTerms.clear();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ public <R> R allSat(AllSatCallback<R> callback, List<BooleanFormula> predicates)
9090
}
9191

9292
@Override
93-
public boolean isUnsat() throws InterruptedException {
93+
protected boolean isUnsatImpl() throws InterruptedException {
9494
out.print("(check-sat)");
95-
boolean isUnsat = super.isUnsat();
95+
boolean isUnsat = super.isUnsatImpl();
9696
out.println(" ; " + (isUnsat ? "UNSAT" : "SAT"));
9797
return isUnsat;
9898
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ protected String addConstraint0(BooleanFormula constraint) {
100100
}
101101

102102
@Override
103-
public boolean isUnsat() throws InterruptedException {
103+
protected boolean isUnsatImpl() throws InterruptedException {
104104
checkState(!closed);
105105

106106
// We actually terminate SmtInterpol during the analysis

0 commit comments

Comments
 (0)