Skip to content

Commit d9414d8

Browse files
committed
Z3: convert each unchecked Z3Exception into a checked SolverException.
This is a larger API change, because Z3 can throw such an exception in several places.
1 parent 0776041 commit d9414d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+260
-178
lines changed

src/org/sosy_lab/java_smt/api/BasicProverEnvironment.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public interface BasicProverEnvironment<T> extends AutoCloseable {
3232
*/
3333
@Nullable
3434
@CanIgnoreReturnValue
35-
default T push(BooleanFormula f) throws InterruptedException {
35+
default T push(BooleanFormula f) throws InterruptedException, SolverException {
3636
push();
3737
return addConstraint(f);
3838
}
@@ -46,7 +46,7 @@ default T push(BooleanFormula f) throws InterruptedException {
4646
/** Add a constraint to the latest backtracking point. */
4747
@Nullable
4848
@CanIgnoreReturnValue
49-
T addConstraint(BooleanFormula constraint) throws InterruptedException;
49+
T addConstraint(BooleanFormula constraint) throws InterruptedException, SolverException;
5050

5151
/**
5252
* Create a new backtracking point, i.e., a new level on the assertion stack. Each level can hold
@@ -55,7 +55,7 @@ default T push(BooleanFormula f) throws InterruptedException {
5555
* <p>If formulas are added before creating the first backtracking point, they can not be removed
5656
* via a POP-operation.
5757
*/
58-
void push() throws InterruptedException;
58+
void push() throws InterruptedException, SolverException;
5959

6060
/**
6161
* Get the number of backtracking points/levels on the current stack.

src/org/sosy_lab/java_smt/api/Evaluator.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public interface Evaluator extends AutoCloseable {
4747
* @return evaluation of the given formula or <code>null</code> if the solver does not provide a
4848
* better evaluation.
4949
*/
50-
@Nullable <T extends Formula> T eval(T formula) throws InterruptedException;
50+
@Nullable <T extends Formula> T eval(T formula) throws InterruptedException, SolverException;
5151

5252
/**
5353
* Evaluate a given formula substituting the values from the model.
@@ -62,56 +62,60 @@ public interface Evaluator extends AutoCloseable {
6262
* @return Either of: - Number (Rational/Double/BigInteger/Long/Integer) - Boolean
6363
* @throws IllegalArgumentException if a formula has unexpected type, e.g. Array.
6464
*/
65-
@Nullable Object evaluate(Formula formula) throws InterruptedException;
65+
@Nullable Object evaluate(Formula formula) throws InterruptedException, SolverException;
6666

6767
/**
6868
* Type-safe evaluation for integer formulas.
6969
*
7070
* <p>The formula does not need to be a variable, we also allow complex expression.
7171
*/
72-
@Nullable BigInteger evaluate(IntegerFormula formula) throws InterruptedException;
72+
@Nullable BigInteger evaluate(IntegerFormula formula)
73+
throws InterruptedException, SolverException;
7374

7475
/**
7576
* Type-safe evaluation for rational formulas.
7677
*
7778
* <p>The formula does not need to be a variable, we also allow complex expression.
7879
*/
79-
@Nullable Rational evaluate(RationalFormula formula) throws InterruptedException;
80+
@Nullable Rational evaluate(RationalFormula formula) throws InterruptedException, SolverException;
8081

8182
/**
8283
* Type-safe evaluation for boolean formulas.
8384
*
8485
* <p>The formula does not need to be a variable, we also allow complex expression.
8586
*/
86-
@Nullable Boolean evaluate(BooleanFormula formula) throws InterruptedException;
87+
@Nullable Boolean evaluate(BooleanFormula formula) throws InterruptedException, SolverException;
8788

8889
/**
8990
* Type-safe evaluation for bitvector formulas.
9091
*
9192
* <p>The formula does not need to be a variable, we also allow complex expression.
9293
*/
93-
@Nullable BigInteger evaluate(BitvectorFormula formula) throws InterruptedException;
94+
@Nullable BigInteger evaluate(BitvectorFormula formula)
95+
throws InterruptedException, SolverException;
9496

9597
/**
9698
* Type-safe evaluation for string formulas.
9799
*
98100
* <p>The formula does not need to be a variable, we also allow complex expression.
99101
*/
100-
@Nullable String evaluate(StringFormula formula) throws InterruptedException;
102+
@Nullable String evaluate(StringFormula formula) throws InterruptedException, SolverException;
101103

102104
/**
103105
* Type-safe evaluation for enumeration formulas.
104106
*
105107
* <p>The formula does not need to be a variable, we also allow complex expression.
106108
*/
107-
@Nullable String evaluate(EnumerationFormula formula) throws InterruptedException;
109+
@Nullable String evaluate(EnumerationFormula formula)
110+
throws InterruptedException, SolverException;
108111

109112
/**
110113
* Type-safe evaluation for floating-point formulas.
111114
*
112115
* <p>The formula does not need to be a variable, we also allow complex expression.
113116
*/
114-
@Nullable FloatingPointNumber evaluate(FloatingPointFormula formula) throws InterruptedException;
117+
@Nullable FloatingPointNumber evaluate(FloatingPointFormula formula)
118+
throws InterruptedException, SolverException;
115119

116120
/**
117121
* Free resources associated with this evaluator (existing {@link Formula} instances stay valid,

src/org/sosy_lab/java_smt/api/FormulaManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ <T extends Formula> T makeApplication(
162162
* Apply a tactic which performs formula transformation. The available tactics depend on the used
163163
* solver.
164164
*/
165-
BooleanFormula applyTactic(BooleanFormula input, Tactic tactic) throws InterruptedException;
165+
BooleanFormula applyTactic(BooleanFormula input, Tactic tactic)
166+
throws InterruptedException, SolverException;
166167

167168
/**
168169
* Simplify an input formula, while ensuring equivalence.
@@ -172,7 +173,7 @@ <T extends Formula> T makeApplication(
172173
* @param input The input formula
173174
* @return Simplified version of the formula
174175
*/
175-
<T extends Formula> T simplify(T input) throws InterruptedException;
176+
<T extends Formula> T simplify(T input) throws InterruptedException, SolverException;
176177

177178
/**
178179
* Visit the formula with a given visitor.

src/org/sosy_lab/java_smt/api/Model.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ public interface Model extends Evaluator, Iterable<ValueAssignment>, AutoCloseab
5454
default Iterator<ValueAssignment> iterator() {
5555
try {
5656
return asList().iterator();
57-
} catch (InterruptedException pE) {
58-
throw new RuntimeException(pE);
57+
} catch (InterruptedException | SolverException e) {
58+
throw new RuntimeException(e);
5959
}
6060
}
6161

6262
/** Build a list of assignments that stays valid after closing the model. */
63-
ImmutableList<ValueAssignment> asList() throws InterruptedException;
63+
ImmutableList<ValueAssignment> asList() throws InterruptedException, SolverException;
6464

6565
/**
6666
* Pretty-printing of the model values.

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.sosy_lab.java_smt.api.Formula;
2323
import org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula;
2424
import org.sosy_lab.java_smt.api.NumeralFormula.RationalFormula;
25+
import org.sosy_lab.java_smt.api.SolverException;
2526
import org.sosy_lab.java_smt.api.StringFormula;
2627

2728
@SuppressWarnings("ClassTypeParameterName")
@@ -40,22 +41,22 @@ protected AbstractEvaluator(
4041
@SuppressWarnings("unchecked")
4142
@Nullable
4243
@Override
43-
public final <T extends Formula> T eval(T f) throws InterruptedException {
44+
public final <T extends Formula> T eval(T f) throws InterruptedException, SolverException {
4445
Preconditions.checkState(!isClosed());
4546
TFormulaInfo evaluation = evalImpl(creator.extractInfo(f));
4647
return evaluation == null ? null : (T) creator.encapsulateWithTypeOf(evaluation);
4748
}
4849

4950
@Nullable
5051
@Override
51-
public final BigInteger evaluate(IntegerFormula f) throws InterruptedException {
52+
public final BigInteger evaluate(IntegerFormula f) throws InterruptedException, SolverException {
5253
Preconditions.checkState(!isClosed());
5354
return (BigInteger) evaluateImpl(creator.extractInfo(f));
5455
}
5556

5657
@Nullable
5758
@Override
58-
public Rational evaluate(RationalFormula f) throws InterruptedException {
59+
public Rational evaluate(RationalFormula f) throws InterruptedException, SolverException {
5960
Object value = evaluateImpl(creator.extractInfo(f));
6061
if (value instanceof BigInteger) {
6162
// We simplified the value internally. Here, we need to convert it back to Rational.
@@ -67,42 +68,43 @@ public Rational evaluate(RationalFormula f) throws InterruptedException {
6768

6869
@Nullable
6970
@Override
70-
public final Boolean evaluate(BooleanFormula f) throws InterruptedException {
71+
public final Boolean evaluate(BooleanFormula f) throws InterruptedException, SolverException {
7172
Preconditions.checkState(!isClosed());
7273
return (Boolean) evaluateImpl(creator.extractInfo(f));
7374
}
7475

7576
@Nullable
7677
@Override
77-
public final String evaluate(StringFormula f) throws InterruptedException {
78+
public final String evaluate(StringFormula f) throws InterruptedException, SolverException {
7879
Preconditions.checkState(!isClosed());
7980
return (String) evaluateImpl(creator.extractInfo(f));
8081
}
8182

8283
@Nullable
8384
@Override
84-
public final String evaluate(EnumerationFormula f) throws InterruptedException {
85+
public final String evaluate(EnumerationFormula f) throws InterruptedException, SolverException {
8586
Preconditions.checkState(!isClosed());
8687
return (String) evaluateImpl(creator.extractInfo(f));
8788
}
8889

8990
@Override
9091
public final @Nullable FloatingPointNumber evaluate(FloatingPointFormula f)
91-
throws InterruptedException {
92+
throws InterruptedException, SolverException {
9293
Preconditions.checkState(!isClosed());
9394
return (FloatingPointNumber) evaluateImpl(creator.extractInfo(f));
9495
}
9596

9697
@Nullable
9798
@Override
98-
public final BigInteger evaluate(BitvectorFormula f) throws InterruptedException {
99+
public final BigInteger evaluate(BitvectorFormula f)
100+
throws InterruptedException, SolverException {
99101
Preconditions.checkState(!isClosed());
100102
return (BigInteger) evaluateImpl(creator.extractInfo(f));
101103
}
102104

103105
@Nullable
104106
@Override
105-
public final Object evaluate(Formula f) throws InterruptedException {
107+
public final Object evaluate(Formula f) throws InterruptedException, SolverException {
106108
Preconditions.checkState(!isClosed());
107109
Preconditions.checkArgument(
108110
!(f instanceof ArrayFormula),
@@ -115,15 +117,16 @@ public final Object evaluate(Formula f) throws InterruptedException {
115117
* set in the model and evaluation aborts, return <code>null</code>.
116118
*/
117119
@Nullable
118-
protected abstract TFormulaInfo evalImpl(TFormulaInfo formula) throws InterruptedException;
120+
protected abstract TFormulaInfo evalImpl(TFormulaInfo formula)
121+
throws InterruptedException, SolverException;
119122

120123
/**
121124
* Simplify the given formula and replace all symbols with their model values. If a symbol is not
122125
* set in the model and evaluation aborts, return <code>null</code>. Afterwards convert the
123126
* formula into a Java object as far as possible, i.e., try to match a primitive or simple type.
124127
*/
125128
@Nullable
126-
protected final Object evaluateImpl(TFormulaInfo f) throws InterruptedException {
129+
protected final Object evaluateImpl(TFormulaInfo f) throws InterruptedException, SolverException {
127130
Preconditions.checkState(!isClosed());
128131
TFormulaInfo evaluatedF = evalImpl(f);
129132
return evaluatedF == null ? null : creator.convertValue(f, evaluatedF);

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.sosy_lab.java_smt.api.IntegerFormulaManager;
4141
import org.sosy_lab.java_smt.api.RationalFormulaManager;
4242
import org.sosy_lab.java_smt.api.SLFormulaManager;
43+
import org.sosy_lab.java_smt.api.SolverException;
4344
import org.sosy_lab.java_smt.api.StringFormulaManager;
4445
import org.sosy_lab.java_smt.api.Tactic;
4546
import org.sosy_lab.java_smt.api.visitors.FormulaTransformationVisitor;
@@ -358,7 +359,8 @@ public final TFormulaInfo extractInfo(Formula f) {
358359
}
359360

360361
@Override
361-
public BooleanFormula applyTactic(BooleanFormula f, Tactic tactic) throws InterruptedException {
362+
public BooleanFormula applyTactic(BooleanFormula f, Tactic tactic)
363+
throws InterruptedException, SolverException {
362364
switch (tactic) {
363365
case ACKERMANNIZATION:
364366
return applyUFEImpl(f);
@@ -389,7 +391,8 @@ protected BooleanFormula applyUFEImpl(BooleanFormula pF) throws InterruptedExcep
389391
*
390392
* @throws InterruptedException Can be thrown by the native code.
391393
*/
392-
protected BooleanFormula applyQELightImpl(BooleanFormula pF) throws InterruptedException {
394+
protected BooleanFormula applyQELightImpl(BooleanFormula pF)
395+
throws InterruptedException, SolverException {
393396

394397
// Returning the untouched formula is valid according to QE_LIGHT contract.
395398
// TODO: substitution-based implementation.
@@ -402,7 +405,8 @@ protected BooleanFormula applyQELightImpl(BooleanFormula pF) throws InterruptedE
402405
* @param pF Input to apply the CNF transformation to.
403406
* @throws InterruptedException Can be thrown by the native code.
404407
*/
405-
protected BooleanFormula applyCNFImpl(BooleanFormula pF) throws InterruptedException {
408+
protected BooleanFormula applyCNFImpl(BooleanFormula pF)
409+
throws InterruptedException, SolverException {
406410

407411
// TODO: generic implementation.
408412
throw new UnsupportedOperationException(
@@ -414,12 +418,13 @@ protected BooleanFormula applyCNFImpl(BooleanFormula pF) throws InterruptedExcep
414418
*
415419
* @throws InterruptedException Can be thrown by the native code.
416420
*/
417-
protected BooleanFormula applyNNFImpl(BooleanFormula input) throws InterruptedException {
421+
protected BooleanFormula applyNNFImpl(BooleanFormula input)
422+
throws InterruptedException, SolverException {
418423
return getBooleanFormulaManager().transformRecursively(input, new NNFVisitor(this));
419424
}
420425

421426
@Override
422-
public <T extends Formula> T simplify(T f) throws InterruptedException {
427+
public <T extends Formula> T simplify(T f) throws InterruptedException, SolverException {
423428
return formulaCreator.encapsulate(formulaCreator.getFormulaType(f), simplify(extractInfo(f)));
424429
}
425430

@@ -430,7 +435,7 @@ public <T extends Formula> T simplify(T f) throws InterruptedException {
430435
*
431436
* @throws InterruptedException Can be thrown by the native code.
432437
*/
433-
protected TFormulaInfo simplify(TFormulaInfo f) throws InterruptedException {
438+
protected TFormulaInfo simplify(TFormulaInfo f) throws InterruptedException, SolverException {
434439
return f;
435440
}
436441

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.sosy_lab.java_smt.api.BooleanFormula;
2626
import org.sosy_lab.java_smt.api.Evaluator;
2727
import org.sosy_lab.java_smt.api.SolverContext.ProverOptions;
28+
import org.sosy_lab.java_smt.api.SolverException;
2829

2930
public abstract class AbstractProver<T> implements BasicProverEnvironment<T> {
3031

@@ -87,13 +88,13 @@ public int size() {
8788
}
8889

8990
@Override
90-
public final void push() throws InterruptedException {
91+
public final void push() throws InterruptedException, SolverException {
9192
checkState(!closed);
9293
pushImpl();
9394
assertedFormulas.add(LinkedHashMultimap.create());
9495
}
9596

96-
protected abstract void pushImpl() throws InterruptedException;
97+
protected abstract void pushImpl() throws InterruptedException, SolverException;
9798

9899
@Override
99100
public final void pop() {
@@ -107,15 +108,16 @@ public final void pop() {
107108

108109
@Override
109110
@CanIgnoreReturnValue
110-
public final @Nullable T addConstraint(BooleanFormula constraint) throws InterruptedException {
111+
public final @Nullable T addConstraint(BooleanFormula constraint)
112+
throws InterruptedException, SolverException {
111113
checkState(!closed);
112114
T t = addConstraintImpl(constraint);
113115
Iterables.getLast(assertedFormulas).put(constraint, t);
114116
return t;
115117
}
116118

117119
protected abstract @Nullable T addConstraintImpl(BooleanFormula constraint)
118-
throws InterruptedException;
120+
throws InterruptedException, SolverException;
119121

120122
protected ImmutableSet<BooleanFormula> getAssertedFormulas() {
121123
ImmutableSet.Builder<BooleanFormula> builder = ImmutableSet.builder();

0 commit comments

Comments
 (0)