Skip to content

Commit cc809d2

Browse files
committed
#407: Revert API changes introducing InterruptedException in more methods
In #407, we introduced a more detailed specification of exceptions for solvers, including InterruptedException and SolverException, to better handle model evaluation and prover operations. However, based on user feedback and internal discussion, these changes caused significant disruption. To address this, we are reverting these API changes to restore the previous behavior and reduce the impact on users. We will still handle these exceptions internally, but will now throw them as RuntimeException to avoid changes in the API.
1 parent e41fac8 commit cc809d2

39 files changed

+188
-249
lines changed

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

Lines changed: 6 additions & 7 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, SolverException {
35+
default T push(BooleanFormula f) throws InterruptedException {
3636
push();
3737
return addConstraint(f);
3838
}
@@ -46,7 +46,7 @@ default T push(BooleanFormula f) throws InterruptedException, SolverException {
4646
/** Add a constraint to the latest backtracking point. */
4747
@Nullable
4848
@CanIgnoreReturnValue
49-
T addConstraint(BooleanFormula constraint) throws InterruptedException, SolverException;
49+
T addConstraint(BooleanFormula constraint) throws InterruptedException;
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, SolverException {
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, SolverException;
58+
void push() throws InterruptedException;
5959

6060
/**
6161
* Get the number of backtracking points/levels on the current stack.
@@ -87,15 +87,15 @@ boolean isUnsatWithAssumptions(Collection<BooleanFormula> assumptions)
8787
* <p>A model might contain additional symbols with their evaluation, if a solver uses its own
8888
* temporary symbols. There should be at least a value-assignment for each free symbol.
8989
*/
90-
Model getModel() throws SolverException, InterruptedException;
90+
Model getModel() throws SolverException;
9191

9292
/**
9393
* Get a temporary view on the current satisfying assignment. This should be called only
9494
* immediately after an {@link #isUnsat()} call that returned <code>false</code>. The evaluator
9595
* should no longer be used as soon as any constraints are added to, pushed, or popped from the
9696
* prover stack.
9797
*/
98-
default Evaluator getEvaluator() throws InterruptedException, SolverException {
98+
default Evaluator getEvaluator() throws SolverException {
9999
return getModel();
100100
}
101101

@@ -107,8 +107,7 @@ default Evaluator getEvaluator() throws InterruptedException, SolverException {
107107
* <p>Note that if you need to iterate multiple times over the model it may be more efficient to
108108
* use this method instead of {@link #getModel()} (depending on the solver).
109109
*/
110-
default ImmutableList<Model.ValueAssignment> getModelAssignments()
111-
throws SolverException, InterruptedException {
110+
default ImmutableList<Model.ValueAssignment> getModelAssignments() throws SolverException {
112111
try (Model model = getModel()) {
113112
return model.asList();
114113
}

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

Lines changed: 9 additions & 13 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, SolverException;
50+
@Nullable <T extends Formula> T eval(T formula);
5151

5252
/**
5353
* Evaluate a given formula substituting the values from the model.
@@ -62,60 +62,56 @@ 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, SolverException;
65+
@Nullable Object evaluate(Formula formula);
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)
73-
throws InterruptedException, SolverException;
72+
@Nullable BigInteger evaluate(IntegerFormula formula);
7473

7574
/**
7675
* Type-safe evaluation for rational formulas.
7776
*
7877
* <p>The formula does not need to be a variable, we also allow complex expression.
7978
*/
80-
@Nullable Rational evaluate(RationalFormula formula) throws InterruptedException, SolverException;
79+
@Nullable Rational evaluate(RationalFormula formula);
8180

8281
/**
8382
* Type-safe evaluation for boolean formulas.
8483
*
8584
* <p>The formula does not need to be a variable, we also allow complex expression.
8685
*/
87-
@Nullable Boolean evaluate(BooleanFormula formula) throws InterruptedException, SolverException;
86+
@Nullable Boolean evaluate(BooleanFormula formula);
8887

8988
/**
9089
* Type-safe evaluation for bitvector formulas.
9190
*
9291
* <p>The formula does not need to be a variable, we also allow complex expression.
9392
*/
94-
@Nullable BigInteger evaluate(BitvectorFormula formula)
95-
throws InterruptedException, SolverException;
93+
@Nullable BigInteger evaluate(BitvectorFormula formula);
9694

9795
/**
9896
* Type-safe evaluation for string formulas.
9997
*
10098
* <p>The formula does not need to be a variable, we also allow complex expression.
10199
*/
102-
@Nullable String evaluate(StringFormula formula) throws InterruptedException, SolverException;
100+
@Nullable String evaluate(StringFormula formula);
103101

104102
/**
105103
* Type-safe evaluation for enumeration formulas.
106104
*
107105
* <p>The formula does not need to be a variable, we also allow complex expression.
108106
*/
109-
@Nullable String evaluate(EnumerationFormula formula)
110-
throws InterruptedException, SolverException;
107+
@Nullable String evaluate(EnumerationFormula formula);
111108

112109
/**
113110
* Type-safe evaluation for floating-point formulas.
114111
*
115112
* <p>The formula does not need to be a variable, we also allow complex expression.
116113
*/
117-
@Nullable FloatingPointNumber evaluate(FloatingPointFormula formula)
118-
throws InterruptedException, SolverException;
114+
@Nullable FloatingPointNumber evaluate(FloatingPointFormula formula);
119115

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

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,11 @@ public interface Model extends Evaluator, Iterable<ValueAssignment>, AutoCloseab
5252
*/
5353
@Override
5454
default Iterator<ValueAssignment> iterator() {
55-
try {
56-
return asList().iterator();
57-
} catch (InterruptedException | SolverException e) {
58-
throw new RuntimeException(e);
59-
}
55+
return asList().iterator();
6056
}
6157

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

6561
/**
6662
* Pretty-printing of the model values.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public interface OptimizationProverEnvironment extends BasicProverEnvironment<Vo
6868
* (epsilon is irrelevant here and can be zero). The model returns the optimal assignment x=9.
6969
*/
7070
@Override
71-
Model getModel() throws SolverException, InterruptedException;
71+
Model getModel() throws SolverException;
7272

7373
/** Status of the optimization problem. */
7474
enum OptStatus {

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
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;
2625
import org.sosy_lab.java_smt.api.StringFormula;
2726

2827
@SuppressWarnings("ClassTypeParameterName")
@@ -41,22 +40,22 @@ protected AbstractEvaluator(
4140
@SuppressWarnings("unchecked")
4241
@Nullable
4342
@Override
44-
public final <T extends Formula> T eval(T f) throws InterruptedException, SolverException {
43+
public final <T extends Formula> T eval(T f) {
4544
Preconditions.checkState(!isClosed());
4645
TFormulaInfo evaluation = evalImpl(creator.extractInfo(f));
4746
return evaluation == null ? null : (T) creator.encapsulateWithTypeOf(evaluation);
4847
}
4948

5049
@Nullable
5150
@Override
52-
public final BigInteger evaluate(IntegerFormula f) throws InterruptedException, SolverException {
51+
public final BigInteger evaluate(IntegerFormula f) {
5352
Preconditions.checkState(!isClosed());
5453
return (BigInteger) evaluateImpl(creator.extractInfo(f));
5554
}
5655

5756
@Nullable
5857
@Override
59-
public Rational evaluate(RationalFormula f) throws InterruptedException, SolverException {
58+
public Rational evaluate(RationalFormula f) {
6059
Object value = evaluateImpl(creator.extractInfo(f));
6160
if (value instanceof BigInteger) {
6261
// We simplified the value internally. Here, we need to convert it back to Rational.
@@ -68,43 +67,41 @@ public Rational evaluate(RationalFormula f) throws InterruptedException, SolverE
6867

6968
@Nullable
7069
@Override
71-
public final Boolean evaluate(BooleanFormula f) throws InterruptedException, SolverException {
70+
public final Boolean evaluate(BooleanFormula f) {
7271
Preconditions.checkState(!isClosed());
7372
return (Boolean) evaluateImpl(creator.extractInfo(f));
7473
}
7574

7675
@Nullable
7776
@Override
78-
public final String evaluate(StringFormula f) throws InterruptedException, SolverException {
77+
public final String evaluate(StringFormula f) {
7978
Preconditions.checkState(!isClosed());
8079
return (String) evaluateImpl(creator.extractInfo(f));
8180
}
8281

8382
@Nullable
8483
@Override
85-
public final String evaluate(EnumerationFormula f) throws InterruptedException, SolverException {
84+
public final String evaluate(EnumerationFormula f) {
8685
Preconditions.checkState(!isClosed());
8786
return (String) evaluateImpl(creator.extractInfo(f));
8887
}
8988

9089
@Override
91-
public final @Nullable FloatingPointNumber evaluate(FloatingPointFormula f)
92-
throws InterruptedException, SolverException {
90+
public final @Nullable FloatingPointNumber evaluate(FloatingPointFormula f) {
9391
Preconditions.checkState(!isClosed());
9492
return (FloatingPointNumber) evaluateImpl(creator.extractInfo(f));
9593
}
9694

9795
@Nullable
9896
@Override
99-
public final BigInteger evaluate(BitvectorFormula f)
100-
throws InterruptedException, SolverException {
97+
public final BigInteger evaluate(BitvectorFormula f) {
10198
Preconditions.checkState(!isClosed());
10299
return (BigInteger) evaluateImpl(creator.extractInfo(f));
103100
}
104101

105102
@Nullable
106103
@Override
107-
public final Object evaluate(Formula f) throws InterruptedException, SolverException {
104+
public final Object evaluate(Formula f) {
108105
Preconditions.checkState(!isClosed());
109106
Preconditions.checkArgument(
110107
!(f instanceof ArrayFormula),
@@ -117,16 +114,15 @@ public final Object evaluate(Formula f) throws InterruptedException, SolverExcep
117114
* set in the model and evaluation aborts, return <code>null</code>.
118115
*/
119116
@Nullable
120-
protected abstract TFormulaInfo evalImpl(TFormulaInfo formula)
121-
throws InterruptedException, SolverException;
117+
protected abstract TFormulaInfo evalImpl(TFormulaInfo formula);
122118

123119
/**
124120
* Simplify the given formula and replace all symbols with their model values. If a symbol is not
125121
* set in the model and evaluation aborts, return <code>null</code>. Afterwards convert the
126122
* formula into a Java object as far as possible, i.e., try to match a primitive or simple type.
127123
*/
128124
@Nullable
129-
protected final Object evaluateImpl(TFormulaInfo f) throws InterruptedException, SolverException {
125+
protected final Object evaluateImpl(TFormulaInfo f) {
130126
Preconditions.checkState(!isClosed());
131127
TFormulaInfo evaluatedF = evalImpl(f);
132128
return evaluatedF == null ? null : creator.convertValue(f, evaluatedF);

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

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

3130
public abstract class AbstractProver<T> implements BasicProverEnvironment<T> {
3231

@@ -89,13 +88,13 @@ public int size() {
8988
}
9089

9190
@Override
92-
public final void push() throws InterruptedException, SolverException {
91+
public final void push() throws InterruptedException {
9392
checkState(!closed);
9493
pushImpl();
9594
assertedFormulas.add(LinkedHashMultimap.create());
9695
}
9796

98-
protected abstract void pushImpl() throws InterruptedException, SolverException;
97+
protected abstract void pushImpl() throws InterruptedException;
9998

10099
@Override
101100
public final void pop() {
@@ -109,16 +108,15 @@ public final void pop() {
109108

110109
@Override
111110
@CanIgnoreReturnValue
112-
public final @Nullable T addConstraint(BooleanFormula constraint)
113-
throws InterruptedException, SolverException {
111+
public final @Nullable T addConstraint(BooleanFormula constraint) throws InterruptedException {
114112
checkState(!closed);
115113
T t = addConstraintImpl(constraint);
116114
Iterables.getLast(assertedFormulas).put(constraint, t);
117115
return t;
118116
}
119117

120118
protected abstract @Nullable T addConstraintImpl(BooleanFormula constraint)
121-
throws InterruptedException, SolverException;
119+
throws InterruptedException;
122120

123121
protected ImmutableSet<BooleanFormula> getAssertedFormulas() {
124122
ImmutableSet.Builder<BooleanFormula> builder = ImmutableSet.builder();

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.sosy_lab.java_smt.api.Model;
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;
2625
import org.sosy_lab.java_smt.api.StringFormula;
2726

2827
public class CachingModel implements Model {
@@ -36,7 +35,7 @@ public CachingModel(Model pDelegate) {
3635
}
3736

3837
@Override
39-
public ImmutableList<ValueAssignment> asList() throws InterruptedException, SolverException {
38+
public ImmutableList<ValueAssignment> asList() {
4039
if (modelAssignments == null) {
4140
modelAssignments = delegate.asList();
4241
}
@@ -49,55 +48,47 @@ public void close() {
4948
}
5049

5150
@Override
52-
public <T extends Formula> @Nullable T eval(T formula)
53-
throws InterruptedException, SolverException {
51+
public <T extends Formula> @Nullable T eval(T formula) {
5452
return delegate.eval(formula);
5553
}
5654

5755
@Override
58-
public @Nullable Object evaluate(Formula formula) throws InterruptedException, SolverException {
56+
public @Nullable Object evaluate(Formula formula) {
5957
return delegate.evaluate(formula);
6058
}
6159

6260
@Override
63-
public @Nullable BigInteger evaluate(IntegerFormula formula)
64-
throws InterruptedException, SolverException {
61+
public @Nullable BigInteger evaluate(IntegerFormula formula) {
6562
return delegate.evaluate(formula);
6663
}
6764

6865
@Override
69-
public @Nullable Rational evaluate(RationalFormula formula)
70-
throws InterruptedException, SolverException {
66+
public @Nullable Rational evaluate(RationalFormula formula) {
7167
return delegate.evaluate(formula);
7268
}
7369

7470
@Override
75-
public @Nullable Boolean evaluate(BooleanFormula formula)
76-
throws InterruptedException, SolverException {
71+
public @Nullable Boolean evaluate(BooleanFormula formula) {
7772
return delegate.evaluate(formula);
7873
}
7974

8075
@Override
81-
public @Nullable BigInteger evaluate(BitvectorFormula formula)
82-
throws InterruptedException, SolverException {
76+
public @Nullable BigInteger evaluate(BitvectorFormula formula) {
8377
return delegate.evaluate(formula);
8478
}
8579

8680
@Override
87-
public @Nullable String evaluate(StringFormula formula)
88-
throws InterruptedException, SolverException {
81+
public @Nullable String evaluate(StringFormula formula) {
8982
return delegate.evaluate(formula);
9083
}
9184

9285
@Override
93-
public @Nullable String evaluate(EnumerationFormula formula)
94-
throws InterruptedException, SolverException {
86+
public @Nullable String evaluate(EnumerationFormula formula) {
9587
return delegate.evaluate(formula);
9688
}
9789

9890
@Override
99-
public @Nullable FloatingPointNumber evaluate(FloatingPointFormula formula)
100-
throws InterruptedException, SolverException {
91+
public @Nullable FloatingPointNumber evaluate(FloatingPointFormula formula) {
10192
return delegate.evaluate(formula);
10293
}
10394

0 commit comments

Comments
 (0)