Skip to content

Commit aa22475

Browse files
authored
Booster: Only check SMT prelude in initSolver (#4040)
Fixes #4036
1 parent f1d156f commit aa22475

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

booster/library/Booster/JsonRpc/Utils.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ diffJson file1 file2 =
5252
-- useful when comparing responses of `kore-rpc` and `kore-rpc-booster`
5353
(contents1@(RpcResponse (Execute res1)), RpcResponse (Execute res2))
5454
| sameModuloBranchOrder res1 res2 -> Identical $ rpcTypeOf contents1
55+
-- special case for GetModel results: only compare the satisfiable fields,
56+
-- ignore variable assignments if present
57+
(contents1@(RpcResponse (GetModel res1)), RpcResponse (GetModel res2))
58+
| sameModuloModel res1 res2 -> Identical $ rpcTypeOf contents1
5559
(contents1, contents2)
5660
| contents1 == contents2 ->
5761
Identical $ rpcTypeOf contents1
@@ -78,6 +82,9 @@ diffJson file1 file2 =
7882
_ -> False
7983
| otherwise = False
8084

85+
sameModuloModel :: GetModelResult -> GetModelResult -> Bool
86+
sameModuloModel res1 res2 = res1.satisfiable == res2.satisfiable
87+
8188
data DiffResult
8289
= Identical KoreRpcType
8390
| DifferentType KoreRpcType KoreRpcType

booster/library/Booster/SMT/Interface.hs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import Booster.SMT.Base as SMT
5757
import Booster.SMT.Runner as SMT
5858
import Booster.SMT.Translate as SMT
5959
import Booster.Syntax.Json.Externalise (externaliseTerm)
60+
import Booster.Util (Flag (..))
6061

6162
data SMTError
6263
= GeneralSMTError Text
@@ -98,7 +99,7 @@ initSolver def smtOptions = Log.withContext Log.CtxSMT $ do
9899
Log.logMessage ("Starting new SMT solver" :: Text)
99100
ctxt <- mkContext smtOptions prelude
100101

101-
evalSMT ctxt checkPrelude
102+
evalSMT ctxt (runPrelude CheckSMTPrelude)
102103
Log.logMessage ("Successfully initialised SMT solver with " <> (Text.pack . show $ smtOptions))
103104
pure ctxt
104105

@@ -130,7 +131,7 @@ hardResetSolver = do
130131
liftIO $ do
131132
writeIORef solverRef solver
132133
writeIORef ctxt.solverClose $ Backend.close handle
133-
checkPrelude
134+
runPrelude NoCheckSMTPrelude
134135

135136
-- | Retry the action `cb`, first decreasing the retry counter and increasing the timeout limit, unless the retry limit has already been reached, in which case call `onTimeout`
136137
retry :: Log.LoggerMIO io => SMT io a -> SMT io a -> SMT io a
@@ -155,21 +156,28 @@ translatePrelude def =
155156
throwSMT $ "Unable to translate elements of the definition to SMT: " <> err
156157
Right decls -> pure decls
157158

158-
checkPrelude :: Log.LoggerMIO io => SMT io ()
159-
checkPrelude = do
159+
pattern CheckSMTPrelude, NoCheckSMTPrelude :: Flag "CheckSMTPrelude"
160+
pattern CheckSMTPrelude = Flag True
161+
pattern NoCheckSMTPrelude = Flag False
162+
163+
runPrelude :: Log.LoggerMIO io => Flag "CheckSMTPrelude" -> SMT io ()
164+
runPrelude doCheck = do
160165
ctxt <- SMT get
161166
-- set the user defined timeout for queries
162167
setTimeout ctxt.options.timeout
163168
Log.logMessage ("Checking definition prelude" :: Text)
164169
-- send the commands from the definition's SMT prelude
165-
check <- mapM_ runCmd ctxt.prelude >> runCmd CheckSat
166-
case check of
167-
Sat -> pure ()
168-
other -> do
169-
Log.logMessage $ "Initial SMT definition check returned " <> pack (show other)
170-
closeContext ctxt
171-
throwSMT' $
172-
"Aborting due to potentially-inconsistent SMT setup: Initial check returned " <> show other
170+
mapM_ runCmd ctxt.prelude
171+
-- optionally check the prelude for consistency
172+
when (coerce doCheck) $ do
173+
check <- runCmd CheckSat
174+
case check of
175+
Sat -> pure ()
176+
other -> do
177+
Log.logMessage $ "Initial SMT definition check returned " <> pack (show other)
178+
closeContext ctxt
179+
throwSMT' $
180+
"Aborting due to potentially-inconsistent SMT setup: Initial check returned " <> show other
173181
where
174182
setTimeout timeout = do
175183
Log.logMessage $ "Setting SMT timeout to: " <> show timeout

0 commit comments

Comments
 (0)