Skip to content

Commit fe8e5ce

Browse files
committed
Fix bug where non-incremental would run even when interrupted
1 parent bbcdaed commit fe8e5ce

File tree

1 file changed

+42
-28
lines changed

1 file changed

+42
-28
lines changed

src/main/scala/inox/solvers/combinators/NonIncrementalSolver.scala

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,55 @@ trait NonIncrementalSolver extends AbstractSolver { self =>
2525
def assertCnstr(expression: Trees): Unit = assertions += expression
2626
def reset(): Unit = assertions.clear()
2727
def free(): Unit = for (solver <- currentSolver) solver.free()
28-
def interrupt(): Unit = for (solver <- currentSolver) solver.interrupt()
28+
29+
var interrupted = false
30+
31+
def interrupt(): Unit = {
32+
interrupted = true
33+
for (solver <- currentSolver) solver.interrupt()
34+
}
2935

3036
override def check(config: CheckConfiguration): config.Response[Model, Assumptions] = {
31-
assert(currentSolver.isEmpty,
32-
"`currentSolver` should be empty when invoking `check` in NonIncrementalSolver")
33-
val newSolver = underlying()
34-
try {
35-
currentSolver = Some(newSolver)
36-
for (expression <- assertions)
37-
newSolver.assertCnstr(expression)
38-
val res = newSolver.check(config)
39-
currentSolver = None
40-
res
41-
} finally {
42-
newSolver.free()
37+
if (!interrupted) {
38+
assert(currentSolver.isEmpty,
39+
"`currentSolver` should be empty when invoking `check` in NonIncrementalSolver")
40+
val newSolver = underlying()
41+
try {
42+
currentSolver = Some(newSolver)
43+
for (expression <- assertions)
44+
newSolver.assertCnstr(expression)
45+
val res = newSolver.check(config)
46+
currentSolver = None
47+
res
48+
} finally {
49+
newSolver.free()
50+
}
51+
} else {
52+
config.cast(SolverResponses.Unknown)
4353
}
4454
}
4555

4656
override def checkAssumptions(config: Configuration)
4757
(assumptions: Set[Trees]): config.Response[Model, Assumptions] = {
48-
assert(currentSolver.isEmpty,
49-
"`currentSolver` should be empty when invoking `checkAssumptions` in NonIncrementalSolver")
50-
val newSolver = underlying()
51-
try {
52-
currentSolver = Some(newSolver)
53-
for (expression <- assertions)
54-
newSolver.assertCnstr(expression)
55-
// we assert the assumptions to address: https://github.com/Z3Prover/z3/issues/5257
56-
for (assumption <- assumptions)
57-
newSolver.assertCnstr(assumption)
58-
val res = newSolver.checkAssumptions(config)(Set())
59-
currentSolver = None
60-
res
61-
} finally {
62-
newSolver.free()
58+
if (!interrupted) {
59+
assert(currentSolver.isEmpty,
60+
"`currentSolver` should be empty when invoking `checkAssumptions` in NonIncrementalSolver")
61+
val newSolver = underlying()
62+
try {
63+
currentSolver = Some(newSolver)
64+
for (expression <- assertions)
65+
newSolver.assertCnstr(expression)
66+
// we assert the assumptions to address: https://github.com/Z3Prover/z3/issues/5257
67+
for (assumption <- assumptions)
68+
newSolver.assertCnstr(assumption)
69+
val res = newSolver.checkAssumptions(config)(Set())
70+
currentSolver = None
71+
res
72+
} finally {
73+
newSolver.free()
74+
}
75+
} else {
76+
config.cast(SolverResponses.Unknown)
6377
}
6478
}
6579

0 commit comments

Comments
 (0)