Skip to content

Commit 1d5d78a

Browse files
committed
Do not hard-reset the solver when updating timeout
1 parent 5ede3d6 commit 1d5d78a

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

booster/library/Booster/SMT/Interface.hs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Booster.SMT.Interface (
1111
finaliseSolver,
1212
getModelFor,
1313
checkPredicates,
14+
hardResetSolver,
1415
) where
1516

1617
import Control.Exception (Exception, throw)
@@ -82,19 +83,24 @@ initSolver def smtOptions = Log.withContext "smt" $ do
8283
Log.logMessage ("Successfully initialised SMT solver with " <> (Text.pack . show $ smtOptions))
8384
pure ctxt
8485

85-
restartSolver :: forall io. Log.LoggerMIO io => SMTOptions -> SMT io ()
86-
restartSolver smtOptions = do
86+
-- | Hot-swap @SMTOptions@ in the active @SMTContext@, update the query timeout
87+
swapSmtOptions :: forall io. Log.LoggerMIO io => SMTOptions -> SMT io ()
88+
swapSmtOptions smtOptions = do
89+
ctxt <- SMT get
90+
Log.logMessage ("Updating solver options with " <> (Text.pack . show $ smtOptions))
91+
SMT $ put ctxt{options = smtOptions}
92+
runCmd_ $ SetTimeout smtOptions.timeout
93+
94+
-- | Stop the solver, initialise a new one and put in the @SMTContext@
95+
hardResetSolver :: forall io. Log.LoggerMIO io => SMTOptions -> SMT io ()
96+
hardResetSolver smtOptions = do
8797
Log.logMessage ("Starting new SMT solver" :: Text)
8898
ctxt <- SMT get
8999
liftIO ctxt.solverClose
90100
(solver, handle) <- connectToSolver
91-
SMT $ put ctxt{solver, solverClose = Backend.close handle, options = smtOptions}
92-
101+
SMT $ put ctxt{solver, solverClose = Backend.close handle}
93102
checkPrelude
94-
Log.logMessage ("Successfully re-initialised SMT solver with " <> (Text.pack . show $ smtOptions))
95-
96-
-- set timeout value for the general queries
97-
runCmd_ $ SetTimeout smtOptions.timeout
103+
swapSmtOptions smtOptions
98104

99105
translatePrelude :: Log.LoggerMIO io => KoreDefinition -> io [DeclareCommand]
100106
translatePrelude def =
@@ -179,7 +185,7 @@ getModelFor ctxt ps subst
179185
case opts.retryLimit of
180186
Just x | x > 0 -> do
181187
let newOpts = opts{timeout = 2 * opts.timeout, retryLimit = Just $ x - 1}
182-
restartSolver newOpts
188+
swapSmtOptions newOpts
183189
solve smtAsserts transState
184190
_ -> getReasonUnknown
185191
r@ReasonUnknown{} ->
@@ -364,7 +370,7 @@ checkPredicates ctxt givenPs givenSubst psToCheck
364370
case opts.retryLimit of
365371
Just x | x > 0 -> do
366372
let newOpts = opts{timeout = 2 * opts.timeout, retryLimit = Just $ x - 1}
367-
restartSolver newOpts
373+
swapSmtOptions newOpts
368374
solve smtGiven sexprsToCheck transState
369375
_ -> runMaybeT failBecauseUnknown
370376

0 commit comments

Comments
 (0)