Skip to content

Commit 7659db3

Browse files
author
BaierD
committed
Add InterruptedExceptions to model generation and catch Z3s solver specific exception when model generation is interrupted and throw a InterruptedExceptions
1 parent 7fd6aa7 commit 7659db3

30 files changed

+153
-114
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
90+
Model getModel() throws SolverException, InterruptedException;
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 SolverException {
98+
default Evaluator getEvaluator() throws InterruptedException, SolverException {
9999
return getModel();
100100
}
101101

@@ -107,7 +107,8 @@ default Evaluator getEvaluator() throws 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() throws SolverException {
110+
default ImmutableList<Model.ValueAssignment> getModelAssignments()
111+
throws SolverException, InterruptedException {
111112
try (Model model = getModel()) {
112113
return model.asList();
113114
}

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

Lines changed: 9 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);
50+
@Nullable <T extends Formula> T eval(T formula) throws InterruptedException;
5151

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

7474
/**
7575
* Type-safe evaluation for rational formulas.
7676
*
7777
* <p>The formula does not need to be a variable, we also allow complex expression.
7878
*/
79-
@Nullable Rational evaluate(RationalFormula formula);
79+
@Nullable Rational evaluate(RationalFormula formula) throws InterruptedException;
8080

8181
/**
8282
* Type-safe evaluation for boolean formulas.
8383
*
8484
* <p>The formula does not need to be a variable, we also allow complex expression.
8585
*/
86-
@Nullable Boolean evaluate(BooleanFormula formula);
86+
@Nullable Boolean evaluate(BooleanFormula formula) throws InterruptedException;
8787

8888
/**
8989
* Type-safe evaluation for bitvector formulas.
9090
*
9191
* <p>The formula does not need to be a variable, we also allow complex expression.
9292
*/
93-
@Nullable BigInteger evaluate(BitvectorFormula formula);
93+
@Nullable BigInteger evaluate(BitvectorFormula formula) throws InterruptedException;
9494

9595
/**
9696
* Type-safe evaluation for string formulas.
9797
*
9898
* <p>The formula does not need to be a variable, we also allow complex expression.
9999
*/
100-
@Nullable String evaluate(StringFormula formula);
100+
@Nullable String evaluate(StringFormula formula) throws InterruptedException;
101101

102102
/**
103103
* Type-safe evaluation for enumeration formulas.
104104
*
105105
* <p>The formula does not need to be a variable, we also allow complex expression.
106106
*/
107-
@Nullable String evaluate(EnumerationFormula formula);
107+
@Nullable String evaluate(EnumerationFormula formula) throws InterruptedException;
108108

109109
/**
110110
* Type-safe evaluation for floating-point formulas.
111111
*
112112
* <p>The formula does not need to be a variable, we also allow complex expression.
113113
*/
114-
@Nullable FloatingPointNumber evaluate(FloatingPointFormula formula);
114+
@Nullable FloatingPointNumber evaluate(FloatingPointFormula formula) throws InterruptedException;
115115

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

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

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

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

6165
/**
6266
* 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;
71+
Model getModel() throws SolverException, InterruptedException;
7272

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

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,22 @@ protected AbstractEvaluator(
4040
@SuppressWarnings("unchecked")
4141
@Nullable
4242
@Override
43-
public final <T extends Formula> T eval(T f) {
43+
public final <T extends Formula> T eval(T f) throws InterruptedException {
4444
Preconditions.checkState(!isClosed());
4545
TFormulaInfo evaluation = evalImpl(creator.extractInfo(f));
4646
return evaluation == null ? null : (T) creator.encapsulateWithTypeOf(evaluation);
4747
}
4848

4949
@Nullable
5050
@Override
51-
public final BigInteger evaluate(IntegerFormula f) {
51+
public final BigInteger evaluate(IntegerFormula f) throws InterruptedException {
5252
Preconditions.checkState(!isClosed());
5353
return (BigInteger) evaluateImpl(creator.extractInfo(f));
5454
}
5555

5656
@Nullable
5757
@Override
58-
public Rational evaluate(RationalFormula f) {
58+
public Rational evaluate(RationalFormula f) throws InterruptedException {
5959
Object value = evaluateImpl(creator.extractInfo(f));
6060
if (value instanceof BigInteger) {
6161
// We simplified the value internally. Here, we need to convert it back to Rational.
@@ -67,41 +67,42 @@ public Rational evaluate(RationalFormula f) {
6767

6868
@Nullable
6969
@Override
70-
public final Boolean evaluate(BooleanFormula f) {
70+
public final Boolean evaluate(BooleanFormula f) throws InterruptedException {
7171
Preconditions.checkState(!isClosed());
7272
return (Boolean) evaluateImpl(creator.extractInfo(f));
7373
}
7474

7575
@Nullable
7676
@Override
77-
public final String evaluate(StringFormula f) {
77+
public final String evaluate(StringFormula f) throws InterruptedException {
7878
Preconditions.checkState(!isClosed());
7979
return (String) evaluateImpl(creator.extractInfo(f));
8080
}
8181

8282
@Nullable
8383
@Override
84-
public final String evaluate(EnumerationFormula f) {
84+
public final String evaluate(EnumerationFormula f) throws InterruptedException {
8585
Preconditions.checkState(!isClosed());
8686
return (String) evaluateImpl(creator.extractInfo(f));
8787
}
8888

8989
@Override
90-
public final @Nullable FloatingPointNumber evaluate(FloatingPointFormula f) {
90+
public final @Nullable FloatingPointNumber evaluate(FloatingPointFormula f)
91+
throws InterruptedException {
9192
Preconditions.checkState(!isClosed());
9293
return (FloatingPointNumber) evaluateImpl(creator.extractInfo(f));
9394
}
9495

9596
@Nullable
9697
@Override
97-
public final BigInteger evaluate(BitvectorFormula f) {
98+
public final BigInteger evaluate(BitvectorFormula f) throws InterruptedException {
9899
Preconditions.checkState(!isClosed());
99100
return (BigInteger) evaluateImpl(creator.extractInfo(f));
100101
}
101102

102103
@Nullable
103104
@Override
104-
public final Object evaluate(Formula f) {
105+
public final Object evaluate(Formula f) throws InterruptedException {
105106
Preconditions.checkState(!isClosed());
106107
Preconditions.checkArgument(
107108
!(f instanceof ArrayFormula),
@@ -114,15 +115,15 @@ public final Object evaluate(Formula f) {
114115
* set in the model and evaluation aborts, return <code>null</code>.
115116
*/
116117
@Nullable
117-
protected abstract TFormulaInfo evalImpl(TFormulaInfo formula);
118+
protected abstract TFormulaInfo evalImpl(TFormulaInfo formula) throws InterruptedException;
118119

119120
/**
120121
* Simplify the given formula and replace all symbols with their model values. If a symbol is not
121122
* set in the model and evaluation aborts, return <code>null</code>. Afterwards convert the
122123
* formula into a Java object as far as possible, i.e., try to match a primitive or simple type.
123124
*/
124125
@Nullable
125-
protected final Object evaluateImpl(TFormulaInfo f) {
126+
protected final Object evaluateImpl(TFormulaInfo f) throws InterruptedException {
126127
Preconditions.checkState(!isClosed());
127128
TFormulaInfo evaluatedF = evalImpl(f);
128129
return evaluatedF == null ? null : creator.convertValue(f, evaluatedF);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,6 @@ private <R> void iterateOverAllPredicateCombinations(
154154
*
155155
* @throws SolverException if model can not be constructed.
156156
*/
157-
protected abstract Evaluator getEvaluatorWithoutChecks() throws SolverException;
157+
protected abstract Evaluator getEvaluatorWithoutChecks()
158+
throws SolverException, InterruptedException;
158159
}

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public CachingModel(Model pDelegate) {
3535
}
3636

3737
@Override
38-
public ImmutableList<ValueAssignment> asList() {
38+
public ImmutableList<ValueAssignment> asList() throws InterruptedException {
3939
if (modelAssignments == null) {
4040
modelAssignments = delegate.asList();
4141
}
@@ -48,47 +48,48 @@ public void close() {
4848
}
4949

5050
@Override
51-
public <T extends Formula> @Nullable T eval(T formula) {
51+
public <T extends Formula> @Nullable T eval(T formula) throws InterruptedException {
5252
return delegate.eval(formula);
5353
}
5454

5555
@Override
56-
public @Nullable Object evaluate(Formula formula) {
56+
public @Nullable Object evaluate(Formula formula) throws InterruptedException {
5757
return delegate.evaluate(formula);
5858
}
5959

6060
@Override
61-
public @Nullable BigInteger evaluate(IntegerFormula formula) {
61+
public @Nullable BigInteger evaluate(IntegerFormula formula) throws InterruptedException {
6262
return delegate.evaluate(formula);
6363
}
6464

6565
@Override
66-
public @Nullable Rational evaluate(RationalFormula formula) {
66+
public @Nullable Rational evaluate(RationalFormula formula) throws InterruptedException {
6767
return delegate.evaluate(formula);
6868
}
6969

7070
@Override
71-
public @Nullable Boolean evaluate(BooleanFormula formula) {
71+
public @Nullable Boolean evaluate(BooleanFormula formula) throws InterruptedException {
7272
return delegate.evaluate(formula);
7373
}
7474

7575
@Override
76-
public @Nullable BigInteger evaluate(BitvectorFormula formula) {
76+
public @Nullable BigInteger evaluate(BitvectorFormula formula) throws InterruptedException {
7777
return delegate.evaluate(formula);
7878
}
7979

8080
@Override
81-
public @Nullable String evaluate(StringFormula formula) {
81+
public @Nullable String evaluate(StringFormula formula) throws InterruptedException {
8282
return delegate.evaluate(formula);
8383
}
8484

8585
@Override
86-
public @Nullable String evaluate(EnumerationFormula formula) {
86+
public @Nullable String evaluate(EnumerationFormula formula) throws InterruptedException {
8787
return delegate.evaluate(formula);
8888
}
8989

9090
@Override
91-
public @Nullable FloatingPointNumber evaluate(FloatingPointFormula formula) {
91+
public @Nullable FloatingPointNumber evaluate(FloatingPointFormula formula)
92+
throws InterruptedException {
9293
return delegate.evaluate(formula);
9394
}
9495

src/org/sosy_lab/java_smt/basicimpl/withAssumptionsWrapper/BasicProverWithAssumptionsWrapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ public boolean isUnsatWithAssumptions(Collection<BooleanFormula> assumptions)
8080
protected void registerPushedFormula(@SuppressWarnings("unused") T pPushResult) {}
8181

8282
@Override
83-
public Model getModel() throws SolverException {
83+
public Model getModel() throws SolverException, InterruptedException {
8484
return delegate.getModel();
8585
}
8686

8787
@Override
88-
public ImmutableList<Model.ValueAssignment> getModelAssignments() throws SolverException {
88+
public ImmutableList<Model.ValueAssignment> getModelAssignments()
89+
throws SolverException, InterruptedException {
8990
return delegate.getModelAssignments();
9091
}
9192

src/org/sosy_lab/java_smt/delegate/debugging/DebuggingBasicProverEnvironment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public boolean isUnsatWithAssumptions(Collection<BooleanFormula> assumptions)
7272

7373
@SuppressWarnings("resource")
7474
@Override
75-
public Model getModel() throws SolverException {
75+
public Model getModel() throws SolverException, InterruptedException {
7676
debugging.assertThreadLocal();
7777
return new DebuggingModel(delegate.getModel(), debugging);
7878
}

0 commit comments

Comments
 (0)