Skip to content

Commit e6587bd

Browse files
author
BaierD
committed
Add API for requesting new prover environments with a dedicated prover shutdown notifier + default implementation
1 parent 843b0ee commit e6587bd

File tree

2 files changed

+125
-13
lines changed

2 files changed

+125
-13
lines changed

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package org.sosy_lab.java_smt.api;
1010

1111
import com.google.common.collect.ImmutableMap;
12+
import org.sosy_lab.common.ShutdownNotifier;
1213
import org.sosy_lab.java_smt.SolverContextFactory.Solvers;
1314

1415
/**
@@ -65,6 +66,28 @@ enum ProverOptions {
6566
*/
6667
ProverEnvironment newProverEnvironment(ProverOptions... options);
6768

69+
/**
70+
* Create a fresh new {@link ProverEnvironment} which encapsulates an assertion stack and can be
71+
* used to check formulas for unsatisfiability. Allows the shutdown of the prover instance
72+
* returned with the given {@link ShutdownNotifier}, without stopping other provers of the context
73+
* calling this (except for provers also connected via the given {@link ShutdownNotifier}).
74+
*
75+
* @param pProverShutdownNotifier a {@link ShutdownNotifier} that stops the prover returned by
76+
* this method. The prover is not usable anymore after a shutdown has been requested and only
77+
* ever returns {@link InterruptedException}s. The context can be used normally and new
78+
* provers can be created and used. If a {@link ShutdownNotifier} has been given to the
79+
* context that is used to call this method, both notifiers can be used to stop the prover
80+
* returned by this method. Note that once a shutdown-request has been given to the contexts
81+
* {@link ShutdownNotifier}, no prover can ever be used again on that context instance.
82+
* Solvers that don't support isolated prover shutdown throw a {@link
83+
* UnsupportedOperationException} for this method and {@link
84+
* #newProverEnvironment(ProverOptions...)} should be used instead.
85+
* @param options Options specified for the prover environment. All the options specified in
86+
* {@link ProverOptions} are turned off by default.
87+
*/
88+
ProverEnvironment newProverEnvironment(
89+
ShutdownNotifier pProverShutdownNotifier, ProverOptions... options);
90+
6891
/**
6992
* Create a fresh new {@link InterpolatingProverEnvironment} which encapsulates an assertion stack
7093
* and allows generating and retrieve interpolants for unsatisfiable formulas. If the SMT solver
@@ -76,6 +99,31 @@ enum ProverOptions {
7699
*/
77100
InterpolatingProverEnvironment<?> newProverEnvironmentWithInterpolation(ProverOptions... options);
78101

102+
/**
103+
* Create a fresh new {@link InterpolatingProverEnvironment} which encapsulates an assertion stack
104+
* and allows generating and retrieve interpolants for unsatisfiable formulas. If the SMT solver
105+
* is able to handle satisfiability tests with assumptions please consider implementing the {@link
106+
* InterpolatingProverEnvironment} interface, and return an Object of this type here. Allows the
107+
* shutdown of the prover instance returned with the given {@link ShutdownNotifier}, without
108+
* stopping other provers of the context calling this (except for provers also connected via the
109+
* given {@link ShutdownNotifier}).
110+
*
111+
* @param pProverShutdownNotifier a {@link ShutdownNotifier} that stops the prover returned by
112+
* this method. The prover is not usable anymore after a shutdown has been requested and only
113+
* ever returns {@link InterruptedException}s. The context can be used normally and new
114+
* provers can be created and used. If a {@link ShutdownNotifier} has been given to the
115+
* context that is used to call this method, both notifiers can be used to stop the prover
116+
* returned by this method. Note that once a shutdown-request has been given to the contexts
117+
* {@link ShutdownNotifier}, no prover can ever be used again on that context instance.
118+
* Solvers that don't support isolated prover shutdown throw a {@link
119+
* UnsupportedOperationException} for this method and {@link
120+
* #newProverEnvironment(ProverOptions...)} should be used instead.
121+
* @param options Options specified for the prover environment. All the options specified in
122+
* {@link ProverOptions} are turned off by default.
123+
*/
124+
InterpolatingProverEnvironment<?> newProverEnvironmentWithInterpolation(
125+
ShutdownNotifier pProverShutdownNotifier, ProverOptions... options);
126+
79127
/**
80128
* Create a fresh new {@link OptimizationProverEnvironment} which encapsulates an assertion stack
81129
* and allows solving optimization queries.
@@ -85,6 +133,28 @@ enum ProverOptions {
85133
*/
86134
OptimizationProverEnvironment newOptimizationProverEnvironment(ProverOptions... options);
87135

136+
/**
137+
* Create a fresh new {@link OptimizationProverEnvironment} which encapsulates an assertion stack
138+
* and allows solving optimization queries. Allows the shutdown of the prover instance returned
139+
* with the given {@link ShutdownNotifier}, without stopping other provers of the context calling
140+
* this (except for provers also connected via the given {@link ShutdownNotifier}).
141+
*
142+
* @param pProverShutdownNotifier a {@link ShutdownNotifier} that stops the prover returned by
143+
* this method. The prover is not usable anymore after a shutdown has been requested and only
144+
* ever returns {@link InterruptedException}s. The context can be used normally and new
145+
* provers can be created and used. If a {@link ShutdownNotifier} has been given to the
146+
* context that is used to call this method, both notifiers can be used to stop the prover
147+
* returned by this method. Note that once a shutdown-request has been given to the contexts
148+
* {@link ShutdownNotifier}, no prover can ever be used again on that context instance.
149+
* Solvers that don't support isolated prover shutdown throw a {@link
150+
* UnsupportedOperationException} for this method and {@link
151+
* #newProverEnvironment(ProverOptions...)} should be used instead.
152+
* @param options Options specified for the prover environment. All the options specified in
153+
* {@link ProverOptions} are turned off by default.
154+
*/
155+
OptimizationProverEnvironment newOptimizationProverEnvironment(
156+
ShutdownNotifier pProverShutdownNotifier, ProverOptions... options);
157+
88158
/**
89159
* Get version information out of the solver.
90160
*

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

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.util.List;
1515
import java.util.Set;
1616
import java.util.function.Consumer;
17+
import org.checkerframework.checker.nullness.qual.Nullable;
18+
import org.sosy_lab.common.ShutdownNotifier;
1719
import org.sosy_lab.java_smt.api.FormulaManager;
1820
import org.sosy_lab.java_smt.api.InterpolatingProverEnvironment;
1921
import org.sosy_lab.java_smt.api.OptimizationProverEnvironment;
@@ -38,43 +40,83 @@ public final FormulaManager getFormulaManager() {
3840
@SuppressWarnings("resource")
3941
@Override
4042
public final ProverEnvironment newProverEnvironment(ProverOptions... options) {
41-
ProverEnvironment out = newProverEnvironment0(toSet(options));
43+
ProverEnvironment out = newProverEnvironment0(null, toSet(options));
44+
return wrapProverEnvironmentWithAssumptionsWrapper(out);
45+
}
46+
47+
@SuppressWarnings("resource")
48+
@Override
49+
public final ProverEnvironment newProverEnvironment(
50+
ShutdownNotifier pProverShutdownNotifier, ProverOptions... options) {
51+
ProverEnvironment out = newProverEnvironment0(pProverShutdownNotifier, toSet(options));
52+
return wrapProverEnvironmentWithAssumptionsWrapper(out);
53+
}
54+
55+
// TODO: switch to 2 methods with a default exception for pProverShutdownNotifier?
56+
protected abstract ProverEnvironment newProverEnvironment0(
57+
@Nullable ShutdownNotifier pProverShutdownNotifier, Set<ProverOptions> options);
58+
59+
private ProverEnvironment wrapProverEnvironmentWithAssumptionsWrapper(
60+
ProverEnvironment pProverEnvironment) {
4261
if (!supportsAssumptionSolving()) {
4362
// In the case we do not already have a prover environment with assumptions,
4463
// we add a wrapper to it
45-
out = new ProverWithAssumptionsWrapper(out);
64+
return new ProverWithAssumptionsWrapper(pProverEnvironment);
4665
}
47-
return out;
66+
return pProverEnvironment;
4867
}
4968

50-
protected abstract ProverEnvironment newProverEnvironment0(Set<ProverOptions> options);
51-
5269
@SuppressWarnings("resource")
5370
@Override
5471
public final InterpolatingProverEnvironment<?> newProverEnvironmentWithInterpolation(
5572
ProverOptions... options) {
5673

57-
InterpolatingProverEnvironment<?> out = newProverEnvironmentWithInterpolation0(toSet(options));
74+
InterpolatingProverEnvironment<?> out =
75+
newProverEnvironmentWithInterpolation0(null, toSet(options));
76+
return wrapProverEnvironmentWithAssumptionsWrapper(out);
77+
}
78+
79+
@SuppressWarnings("resource")
80+
@Override
81+
public final InterpolatingProverEnvironment<?> newProverEnvironmentWithInterpolation(
82+
ShutdownNotifier pProverShutdownNotifier, ProverOptions... options) {
83+
84+
InterpolatingProverEnvironment<?> out =
85+
newProverEnvironmentWithInterpolation0(pProverShutdownNotifier, toSet(options));
86+
return wrapProverEnvironmentWithAssumptionsWrapper(out);
87+
}
88+
89+
// TODO: switch to 2 methods with a default exception for pProverShutdownNotifier?
90+
protected abstract InterpolatingProverEnvironment<?> newProverEnvironmentWithInterpolation0(
91+
@Nullable ShutdownNotifier pProverShutdownNotifier, Set<ProverOptions> pSet);
92+
93+
private InterpolatingProverEnvironment<?> wrapProverEnvironmentWithAssumptionsWrapper(
94+
InterpolatingProverEnvironment<?> pInterpolatingProverEnvironment) {
5895
if (!supportsAssumptionSolving()) {
5996
// In the case we do not already have a prover environment with assumptions,
6097
// we add a wrapper to it
61-
out = new InterpolatingProverWithAssumptionsWrapper<>(out, fmgr);
98+
return new InterpolatingProverWithAssumptionsWrapper<>(pInterpolatingProverEnvironment, fmgr);
6299
}
63-
return out;
100+
return pInterpolatingProverEnvironment;
64101
}
65102

66-
protected abstract InterpolatingProverEnvironment<?> newProverEnvironmentWithInterpolation0(
67-
Set<ProverOptions> pSet);
68-
69103
@SuppressWarnings("resource")
70104
@Override
71105
public final OptimizationProverEnvironment newOptimizationProverEnvironment(
72106
ProverOptions... options) {
73-
return newOptimizationProverEnvironment0(toSet(options));
107+
return newOptimizationProverEnvironment0(null, toSet(options));
108+
}
109+
110+
@SuppressWarnings("resource")
111+
@Override
112+
public final OptimizationProverEnvironment newOptimizationProverEnvironment(
113+
ShutdownNotifier pProverShutdownNotifier, ProverOptions... options) {
114+
return newOptimizationProverEnvironment0(pProverShutdownNotifier, toSet(options));
74115
}
75116

117+
// TODO: switch to 2 methods with a default exception for pProverShutdownNotifier?
76118
protected abstract OptimizationProverEnvironment newOptimizationProverEnvironment0(
77-
Set<ProverOptions> pSet);
119+
@Nullable ShutdownNotifier pProverShutdownNotifier, Set<ProverOptions> pSet);
78120

79121
/**
80122
* Whether the solver supports solving under some given assumptions (with all corresponding

0 commit comments

Comments
 (0)