Skip to content

Commit 4f81e8d

Browse files
committed
Princess: disable collection of model constraints if model generation is disabled.
1 parent a58cc80 commit 4f81e8d

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
public abstract class AbstractProver<T> implements BasicProverEnvironment<T> {
3131

32-
private final boolean generateModels;
33-
private final boolean generateAllSat;
32+
protected final boolean generateModels;
33+
protected final boolean generateAllSat;
3434
protected final boolean generateUnsatCores;
3535
private final boolean generateUnsatCoresOverAssumptions;
3636
protected final boolean enableSL;

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.List;
3030
import java.util.Optional;
3131
import java.util.Set;
32+
import java.util.concurrent.Callable;
3233
import org.sosy_lab.common.ShutdownNotifier;
3334
import org.sosy_lab.common.UniqueIdGenerator;
3435
import org.sosy_lab.common.collect.PathCopyingPersistentTreeMap;
@@ -53,7 +54,7 @@ abstract class PrincessAbstractProver<E> extends AbstractProverWithAllSat<E> {
5354
* Values returned by {@link Model#evaluate(Formula)}.
5455
*
5556
* <p>We need to record these to make sure that the values returned by the evaluator are
56-
* consistant. Calling {@link #isUnsat()} will reset this list as the underlying model has been
57+
* consistent. Calling {@link #isUnsat()} will reset this list as the underlying model has been
5758
* updated.
5859
*/
5960
protected final Set<IFormula> evaluatedTerms = new LinkedHashSet<>();
@@ -92,7 +93,10 @@ public boolean isUnsat() throws SolverException {
9293
final Value result = api.checkSat(true);
9394
if (result.equals(SimpleAPI.ProverStatus$.MODULE$.Sat())) {
9495
wasLastSatCheckSat = true;
95-
evaluatedTerms.add(api.partialModelAsFormula());
96+
if (this.generateModels || this.generateAllSat) {
97+
// we only build the model if we have set the correct options
98+
evaluatedTerms.add(callOrThrow(api::partialModelAsFormula));
99+
}
96100
return false;
97101
} else if (result.equals(SimpleAPI.ProverStatus$.MODULE$.Unsat())) {
98102
return true;
@@ -148,6 +152,9 @@ protected void popImpl() {
148152
* extend the original model.
149153
*/
150154
Collection<IFormula> getEvaluatedTerms() {
155+
Preconditions.checkState(
156+
this.generateModels || this.generateAllSat,
157+
"Model generation was not enabled, no evaluated terms available.");
151158
return Collections.unmodifiableCollection(evaluatedTerms);
152159
}
153160

@@ -168,22 +175,22 @@ public Model getModel() throws SolverException {
168175
@SuppressWarnings("resource")
169176
@Override
170177
protected PrincessModel getEvaluatorWithoutChecks() throws SolverException {
171-
final PartialModel partialModel;
172-
try {
173-
partialModel = partialModel();
174-
} catch (SimpleAPIException ex) {
175-
throw new SolverException(ex.getMessage(), ex);
176-
}
178+
final PartialModel partialModel = callOrThrow(api::partialModel);
177179
return registerEvaluator(new PrincessModel(this, partialModel, creator, api));
178180
}
179181

180182
/**
181-
* This method only exists to allow catching the exception from Scala in Java.
183+
* This method only exists to allow catching some exceptions from Scala in Java.
182184
*
183-
* @throws SimpleAPIException if model can not be constructed.
185+
* @throws SolverException if the callable throws an Exception (including {@link
186+
* SimpleAPIException})
184187
*/
185-
private PartialModel partialModel() throws SimpleAPIException {
186-
return api.partialModel();
188+
private <T> T callOrThrow(Callable<T> callable) throws SolverException {
189+
try {
190+
return callable.call();
191+
} catch (Exception pException) { // mainly for catching SimpleAPIException
192+
throw new SolverException(pException.getMessage(), pException);
193+
}
187194
}
188195

189196
@Override

src/org/sosy_lab/java_smt/test/ModelTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,11 +2234,6 @@ public void arrayTest4() throws SolverException, InterruptedException {
22342234
requireIntegers();
22352235
requireBitvectors();
22362236

2237-
assume()
2238-
.withMessage("Solver runs out memory while generating the model")
2239-
.that(solverToUse())
2240-
.isNotEqualTo(Solvers.PRINCESS);
2241-
22422237
BooleanFormula formula = context.getFormulaManager().parse(ARRAY_QUERY_BV);
22432238
checkModelIteration(formula, false);
22442239
}

0 commit comments

Comments
 (0)