-
Notifications
You must be signed in to change notification settings - Fork 44
Abort on "Unknown" side conditions, don't crash #3907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ module Booster.SMT.Interface ( | |
import Control.Exception (Exception, throw) | ||
import Control.Monad | ||
import Control.Monad.Trans.Class | ||
import Control.Monad.Trans.Maybe | ||
import Control.Monad.Trans.Except | ||
import Data.ByteString.Char8 qualified as BS | ||
import Data.Coerce | ||
import Data.Either (isLeft) | ||
|
@@ -68,9 +68,6 @@ throwSMT = throw . GeneralSMTError | |
throwSMT' :: String -> a | ||
throwSMT' = throwSMT . pack | ||
|
||
throwUnknown :: Text -> Set Predicate -> Set Predicate -> a | ||
throwUnknown reason premises preds = throw $ SMTSolverUnknown reason premises preds | ||
|
||
smtTranslateError :: Text -> a | ||
smtTranslateError = throw . SMTTranslationError | ||
|
||
|
@@ -266,14 +263,14 @@ checkPredicates :: | |
Set Predicate -> | ||
Map Variable Term -> | ||
Set Predicate -> | ||
io (Maybe Bool) | ||
io (Either SMTError Bool) | ||
checkPredicates ctxt givenPs givenSubst psToCheck | ||
| null psToCheck = pure $ Just True -- or Nothing? | ||
| null psToCheck = pure $ Right True | ||
| Left errMsg <- translated = Log.withContext "smt" $ do | ||
Log.logErrorNS "booster" $ "SMT translation error: " <> errMsg | ||
Log.logMessage $ "SMT translation error: " <> errMsg | ||
pure Nothing | ||
| Right ((smtGiven, sexprsToCheck), transState) <- translated = Log.withContext "smt" $ runSMT ctxt . runMaybeT $ do | ||
pure . Left . SMTTranslationError $ errMsg | ||
| Right ((smtGiven, sexprsToCheck), transState) <- translated = Log.withContext "smt" $ runSMT ctxt . runExceptT $ do | ||
Log.logMessage $ | ||
Text.unwords | ||
[ "Checking" | ||
|
@@ -302,8 +299,9 @@ checkPredicates ctxt givenPs givenSubst psToCheck | |
consistent <- smtRun CheckSat | ||
when (consistent /= Sat) $ do | ||
void $ smtRun Pop | ||
Log.logMessage ("Inconsistent ground truth, check returns Nothing" :: Text) | ||
fail "returns nothing" | ||
let errMsg = ("Inconsistent ground truth, check returns Nothing" :: Text) | ||
Log.logMessage errMsg | ||
throwE $ GeneralSMTError errMsg | ||
Comment on lines
+302
to
+304
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not really an "error", rather a defensive strategy to avoid jumping to unjustified conclusions |
||
|
||
-- save ground truth for 2nd check | ||
smtRun_ Push | ||
|
@@ -324,22 +322,22 @@ checkPredicates ctxt givenPs givenSubst psToCheck | |
|
||
case (positive, negative) of | ||
(Unsat, Unsat) -> throwSMT "Inconsistent ground truth: should have been caught above" | ||
(Sat, Sat) -> fail "Implication not determined" | ||
(Sat, Sat) -> throwE $ GeneralSMTError "Implication not determined" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, this is actually a result (neither |
||
(Sat, Unsat) -> pure True | ||
(Unsat, Sat) -> pure False | ||
(Unknown, _) -> do | ||
smtRun GetReasonUnknown >>= \case | ||
ReasonUnknown reason -> throwUnknown reason givenPs psToCheck | ||
ReasonUnknown reason -> throwE $ SMTSolverUnknown reason givenPs psToCheck | ||
other -> throwSMT' $ "Unexpected result while calling ':reason-unknown': " <> show other | ||
(_, Unknown) -> do | ||
smtRun GetReasonUnknown >>= \case | ||
ReasonUnknown reason -> throwUnknown reason givenPs psToCheck | ||
ReasonUnknown reason -> throwE $ SMTSolverUnknown reason givenPs psToCheck | ||
other -> throwSMT' $ "Unexpected result while calling ':reason-unknown': " <> show other | ||
other -> throwSMT' $ "Unexpected result while checking a condition: " <> show other | ||
where | ||
smtRun_ :: SMTEncode c => c -> MaybeT (SMT io) () | ||
smtRun_ :: SMTEncode c => c -> ExceptT SMTError (SMT io) () | ||
smtRun_ = lift . SMT.runCmd_ | ||
smtRun :: SMTEncode c => c -> MaybeT (SMT io) Response | ||
smtRun :: SMTEncode c => c -> ExceptT SMTError (SMT io) Response | ||
smtRun = lift . SMT.runCmd | ||
|
||
translated = SMT.runTranslator $ do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably restrict this to the
SMTSolverUnknown
case. AnSMTTranslationError
is an entirely different case (and theGeneral
error was meant to cover infrastructure issues).