@@ -16,7 +16,7 @@ module Booster.SMT.Interface (
16
16
import Control.Exception (Exception , throw )
17
17
import Control.Monad
18
18
import Control.Monad.Trans.Class
19
- import Control.Monad.Trans.Maybe
19
+ import Control.Monad.Trans.Except
20
20
import Data.ByteString.Char8 qualified as BS
21
21
import Data.Coerce
22
22
import Data.Either (isLeft )
@@ -68,9 +68,6 @@ throwSMT = throw . GeneralSMTError
68
68
throwSMT' :: String -> a
69
69
throwSMT' = throwSMT . pack
70
70
71
- throwUnknown :: Text -> Set Predicate -> Set Predicate -> a
72
- throwUnknown reason premises preds = throw $ SMTSolverUnknown reason premises preds
73
-
74
71
smtTranslateError :: Text -> a
75
72
smtTranslateError = throw . SMTTranslationError
76
73
@@ -266,14 +263,14 @@ checkPredicates ::
266
263
Set Predicate ->
267
264
Map Variable Term ->
268
265
Set Predicate ->
269
- io (Maybe Bool )
266
+ io (Either SMTError Bool )
270
267
checkPredicates ctxt givenPs givenSubst psToCheck
271
- | null psToCheck = pure $ Just True -- or Nothing?
268
+ | null psToCheck = pure $ Right True
272
269
| Left errMsg <- translated = Log. withContext " smt" $ do
273
270
Log. logErrorNS " booster" $ " SMT translation error: " <> errMsg
274
271
Log. logMessage $ " SMT translation error: " <> errMsg
275
- pure Nothing
276
- | Right ((smtGiven, sexprsToCheck), transState) <- translated = Log. withContext " smt" $ runSMT ctxt . runMaybeT $ do
272
+ pure . Left . SMTTranslationError $ errMsg
273
+ | Right ((smtGiven, sexprsToCheck), transState) <- translated = Log. withContext " smt" $ runSMT ctxt . runExceptT $ do
277
274
Log. logMessage $
278
275
Text. unwords
279
276
[ " Checking"
@@ -302,8 +299,9 @@ checkPredicates ctxt givenPs givenSubst psToCheck
302
299
consistent <- smtRun CheckSat
303
300
when (consistent /= Sat ) $ do
304
301
void $ smtRun Pop
305
- Log. logMessage (" Inconsistent ground truth, check returns Nothing" :: Text )
306
- fail " returns nothing"
302
+ let errMsg = (" Inconsistent ground truth, check returns Nothing" :: Text )
303
+ Log. logMessage errMsg
304
+ throwE $ GeneralSMTError errMsg
307
305
308
306
-- save ground truth for 2nd check
309
307
smtRun_ Push
@@ -324,22 +322,22 @@ checkPredicates ctxt givenPs givenSubst psToCheck
324
322
325
323
case (positive, negative) of
326
324
(Unsat , Unsat ) -> throwSMT " Inconsistent ground truth: should have been caught above"
327
- (Sat , Sat ) -> fail " Implication not determined"
325
+ (Sat , Sat ) -> throwE $ GeneralSMTError " Implication not determined"
328
326
(Sat , Unsat ) -> pure True
329
327
(Unsat , Sat ) -> pure False
330
328
(Unknown , _) -> do
331
329
smtRun GetReasonUnknown >>= \ case
332
- ReasonUnknown reason -> throwUnknown reason givenPs psToCheck
330
+ ReasonUnknown reason -> throwE $ SMTSolverUnknown reason givenPs psToCheck
333
331
other -> throwSMT' $ " Unexpected result while calling ':reason-unknown': " <> show other
334
332
(_, Unknown ) -> do
335
333
smtRun GetReasonUnknown >>= \ case
336
- ReasonUnknown reason -> throwUnknown reason givenPs psToCheck
334
+ ReasonUnknown reason -> throwE $ SMTSolverUnknown reason givenPs psToCheck
337
335
other -> throwSMT' $ " Unexpected result while calling ':reason-unknown': " <> show other
338
336
other -> throwSMT' $ " Unexpected result while checking a condition: " <> show other
339
337
where
340
- smtRun_ :: SMTEncode c => c -> MaybeT (SMT io ) ()
338
+ smtRun_ :: SMTEncode c => c -> ExceptT SMTError (SMT io ) ()
341
339
smtRun_ = lift . SMT. runCmd_
342
- smtRun :: SMTEncode c => c -> MaybeT (SMT io ) Response
340
+ smtRun :: SMTEncode c => c -> ExceptT SMTError (SMT io ) Response
343
341
smtRun = lift . SMT. runCmd
344
342
345
343
translated = SMT. runTranslator $ do
0 commit comments