{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
module What4.Solver.STP
( STP(..)
, stpAdapter
, stpPath
, stpTimeout
, stpOptions
, stpFeatures
, runSTPInOverride
, withSTP
) where
import Data.Bits
import What4.BaseTypes
import What4.Concrete
import What4.Config
import What4.Expr.Builder
import What4.Expr.GroundEval
import What4.Interface
import What4.ProblemFeatures
import What4.Protocol.Online
import qualified What4.Protocol.SMTLib2 as SMT2
import What4.Protocol.SMTLib2.Response ( strictSMTParseOpt )
import What4.SatResult
import What4.Solver.Adapter
import What4.Utils.Process
data STP = STP deriving Int -> STP -> ShowS
[STP] -> ShowS
STP -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [STP] -> ShowS
$cshowList :: [STP] -> ShowS
show :: STP -> String
$cshow :: STP -> String
showsPrec :: Int -> STP -> ShowS
$cshowsPrec :: Int -> STP -> ShowS
Show
stpPath :: ConfigOption (BaseStringType Unicode)
stpPath :: ConfigOption (BaseStringType Unicode)
stpPath = forall (tp :: BaseType).
BaseTypeRepr tp -> String -> ConfigOption tp
configOption forall k (f :: k -> Type) (ctx :: k). KnownRepr f ctx => f ctx
knownRepr String
"solver.stp.path"
stpPathOLD :: ConfigOption (BaseStringType Unicode)
stpPathOLD :: ConfigOption (BaseStringType Unicode)
stpPathOLD = forall (tp :: BaseType).
BaseTypeRepr tp -> String -> ConfigOption tp
configOption forall k (f :: k -> Type) (ctx :: k). KnownRepr f ctx => f ctx
knownRepr String
"stp_path"
stpTimeout :: ConfigOption BaseIntegerType
stpTimeout :: ConfigOption BaseIntegerType
stpTimeout = forall (tp :: BaseType).
BaseTypeRepr tp -> String -> ConfigOption tp
configOption forall k (f :: k -> Type) (ctx :: k). KnownRepr f ctx => f ctx
knownRepr String
"solver.stp.timeout"
stpRandomSeed :: ConfigOption BaseIntegerType
stpRandomSeed :: ConfigOption BaseIntegerType
stpRandomSeed = forall (tp :: BaseType).
BaseTypeRepr tp -> String -> ConfigOption tp
configOption forall k (f :: k -> Type) (ctx :: k). KnownRepr f ctx => f ctx
knownRepr String
"solver.stp.random-seed"
stpRandomSeedOLD :: ConfigOption BaseIntegerType
stpRandomSeedOLD :: ConfigOption BaseIntegerType
stpRandomSeedOLD = forall (tp :: BaseType).
BaseTypeRepr tp -> String -> ConfigOption tp
configOption forall k (f :: k -> Type) (ctx :: k). KnownRepr f ctx => f ctx
knownRepr String
"stp.random-seed"
stpStrictParsing :: ConfigOption BaseBoolType
stpStrictParsing :: ConfigOption BaseBoolType
stpStrictParsing = forall (tp :: BaseType).
BaseTypeRepr tp -> String -> ConfigOption tp
configOption forall k (f :: k -> Type) (ctx :: k). KnownRepr f ctx => f ctx
knownRepr String
"solver.stp.strict_parsing"
intWithRangeOpt :: ConfigOption BaseIntegerType -> Integer -> Integer -> ConfigDesc
intWithRangeOpt :: ConfigOption BaseIntegerType -> Integer -> Integer -> ConfigDesc
intWithRangeOpt ConfigOption BaseIntegerType
nm Integer
lo Integer
hi = forall (tp :: BaseType).
ConfigOption tp
-> OptionStyle tp
-> Maybe (Doc Void)
-> Maybe (ConcreteVal tp)
-> ConfigDesc
mkOpt ConfigOption BaseIntegerType
nm OptionStyle BaseIntegerType
sty forall a. Maybe a
Nothing forall a. Maybe a
Nothing
where sty :: OptionStyle BaseIntegerType
sty = Bound Integer -> Bound Integer -> OptionStyle BaseIntegerType
integerWithRangeOptSty (forall r. r -> Bound r
Inclusive Integer
lo) (forall r. r -> Bound r
Inclusive Integer
hi)
stpOptions :: [ConfigDesc]
stpOptions :: [ConfigDesc]
stpOptions =
let mkPath :: ConfigOption (BaseStringType Unicode) -> ConfigDesc
mkPath ConfigOption (BaseStringType Unicode)
co = forall (tp :: BaseType).
ConfigOption tp
-> OptionStyle tp
-> Maybe (Doc Void)
-> Maybe (ConcreteVal tp)
-> ConfigDesc
mkOpt ConfigOption (BaseStringType Unicode)
co
OptionStyle (BaseStringType Unicode)
executablePathOptSty
(forall a. a -> Maybe a
Just Doc Void
"Path to STP executable.")
(forall a. a -> Maybe a
Just (forall (si :: StringInfo).
StringLiteral si -> ConcreteVal ('BaseStringType si)
ConcreteString StringLiteral Unicode
"stp"))
p1 :: ConfigDesc
p1 = ConfigOption (BaseStringType Unicode) -> ConfigDesc
mkPath ConfigOption (BaseStringType Unicode)
stpPath
randbitval :: Integer
randbitval = Integer
2forall a b. (Num a, Integral b) => a -> b -> a
^(Int
30 :: Int)forall a. Num a => a -> a -> a
-Integer
1
r1 :: ConfigDesc
r1 = ConfigOption BaseIntegerType -> Integer -> Integer -> ConfigDesc
intWithRangeOpt ConfigOption BaseIntegerType
stpRandomSeed (forall a. Num a => a -> a
negate Integer
randbitval) Integer
randbitval
in [ ConfigDesc
p1, ConfigDesc
r1
, (Text -> Text) -> ConfigDesc -> ConfigDesc
copyOpt (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (tp :: BaseType). ConfigOption tp -> Text
configOptionText ConfigOption BaseBoolType
stpStrictParsing) ConfigDesc
strictSMTParseOpt
, [ConfigDesc] -> ConfigDesc -> ConfigDesc
deprecatedOpt [ConfigDesc
p1] forall a b. (a -> b) -> a -> b
$ ConfigOption (BaseStringType Unicode) -> ConfigDesc
mkPath ConfigOption (BaseStringType Unicode)
stpPathOLD
, [ConfigDesc] -> ConfigDesc -> ConfigDesc
deprecatedOpt [ConfigDesc
r1] forall a b. (a -> b) -> a -> b
$ ConfigOption BaseIntegerType -> Integer -> Integer -> ConfigDesc
intWithRangeOpt ConfigOption BaseIntegerType
stpRandomSeedOLD
(forall a. Num a => a -> a
negate Integer
randbitval) Integer
randbitval
, forall (tp :: BaseType).
ConfigOption tp
-> OptionStyle tp
-> Maybe (Doc Void)
-> Maybe (ConcreteVal tp)
-> ConfigDesc
mkOpt ConfigOption BaseIntegerType
stpTimeout OptionStyle BaseIntegerType
integerOptSty (forall a. a -> Maybe a
Just Doc Void
"Per-check timeout in milliseconds (zero is none)")
(forall a. a -> Maybe a
Just (Integer -> ConcreteVal BaseIntegerType
ConcreteInteger Integer
0))
] forall a. Semigroup a => a -> a -> a
<> [ConfigDesc]
SMT2.smtlib2Options
stpAdapter :: SolverAdapter st
stpAdapter :: forall (st :: Type -> Type). SolverAdapter st
stpAdapter =
SolverAdapter
{ solver_adapter_name :: String
solver_adapter_name = String
"stp"
, solver_adapter_config_options :: [ConfigDesc]
solver_adapter_config_options = [ConfigDesc]
stpOptions
, solver_adapter_check_sat :: forall t fs a.
ExprBuilder t st fs
-> LogData
-> [BoolExpr t]
-> (SatResult (GroundEvalFn t, Maybe (ExprRangeBindings t)) ()
-> IO a)
-> IO a
solver_adapter_check_sat = forall t (st :: Type -> Type) fs a.
ExprBuilder t st fs
-> LogData
-> [BoolExpr t]
-> (SatResult (GroundEvalFn t, Maybe (ExprRangeBindings t)) ()
-> IO a)
-> IO a
runSTPInOverride
, solver_adapter_write_smt2 :: forall t fs. ExprBuilder t st fs -> Handle -> [BoolExpr t] -> IO ()
solver_adapter_write_smt2 =
forall a t (st :: Type -> Type) fs.
SMTLib2Tweaks a =>
a
-> String
-> ProblemFeatures
-> Maybe (ConfigOption BaseBoolType)
-> ExprBuilder t st fs
-> Handle
-> [BoolExpr t]
-> IO ()
SMT2.writeDefaultSMT2 STP
STP String
"STP" ProblemFeatures
defaultWriteSMTLIB2Features
(forall a. a -> Maybe a
Just ConfigOption BaseBoolType
stpStrictParsing)
}
instance SMT2.SMTLib2Tweaks STP where
smtlib2tweaks :: STP
smtlib2tweaks = STP
STP
instance SMT2.SMTLib2GenericSolver STP where
defaultSolverPath :: forall t (st :: Type -> Type) fs.
STP -> ExprBuilder t st fs -> IO String
defaultSolverPath STP
_ = ConfigOption (BaseStringType Unicode) -> Config -> IO String
findSolverPath ConfigOption (BaseStringType Unicode)
stpPath forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall sym. IsExprBuilder sym => sym -> Config
getConfiguration
defaultSolverArgs :: forall t (st :: Type -> Type) fs.
STP -> ExprBuilder t st fs -> IO [String]
defaultSolverArgs STP
_ ExprBuilder t st fs
_ = forall (m :: Type -> Type) a. Monad m => a -> m a
return [String
"--SMTLIB2"]
defaultFeatures :: STP -> ProblemFeatures
defaultFeatures STP
_ = ProblemFeatures
stpFeatures
setDefaultLogicAndOptions :: forall t. WriterConn t (Writer STP) -> IO ()
setDefaultLogicAndOptions WriterConn t (Writer STP)
writer = do
forall a t.
SMTLib2Tweaks a =>
WriterConn t (Writer a) -> Bool -> IO ()
SMT2.setProduceModels WriterConn t (Writer STP)
writer Bool
True
forall a t.
SMTLib2Tweaks a =>
WriterConn t (Writer a) -> Logic -> IO ()
SMT2.setLogic WriterConn t (Writer STP)
writer Logic
SMT2.qf_bv
stpFeatures :: ProblemFeatures
stpFeatures :: ProblemFeatures
stpFeatures = ProblemFeatures
useIntegerArithmetic forall a. Bits a => a -> a -> a
.|. ProblemFeatures
useBitvectors
runSTPInOverride
:: ExprBuilder t st fs
-> LogData
-> [BoolExpr t]
-> (SatResult (GroundEvalFn t, Maybe (ExprRangeBindings t)) () -> IO a)
-> IO a
runSTPInOverride :: forall t (st :: Type -> Type) fs a.
ExprBuilder t st fs
-> LogData
-> [BoolExpr t]
-> (SatResult (GroundEvalFn t, Maybe (ExprRangeBindings t)) ()
-> IO a)
-> IO a
runSTPInOverride = forall a t (st :: Type -> Type) fs b.
SMTLib2GenericSolver a =>
a
-> AcknowledgementAction t (Writer a)
-> ProblemFeatures
-> Maybe (ConfigOption BaseBoolType)
-> ExprBuilder t st fs
-> LogData
-> [BoolExpr t]
-> (SatResult (GroundEvalFn t, Maybe (ExprRangeBindings t)) ()
-> IO b)
-> IO b
SMT2.runSolverInOverride STP
STP forall t h. AcknowledgementAction t h
SMT2.nullAcknowledgementAction
(forall a. SMTLib2GenericSolver a => a -> ProblemFeatures
SMT2.defaultFeatures STP
STP) (forall a. a -> Maybe a
Just ConfigOption BaseBoolType
stpStrictParsing)
withSTP
:: ExprBuilder t st fs
-> FilePath
-> LogData
-> (SMT2.Session t STP -> IO a)
-> IO a
withSTP :: forall t (st :: Type -> Type) fs a.
ExprBuilder t st fs
-> String -> LogData -> (Session t STP -> IO a) -> IO a
withSTP = forall a t (st :: Type -> Type) fs b.
SMTLib2GenericSolver a =>
a
-> AcknowledgementAction t (Writer a)
-> ProblemFeatures
-> Maybe (ConfigOption BaseBoolType)
-> ExprBuilder t st fs
-> String
-> LogData
-> (Session t a -> IO b)
-> IO b
SMT2.withSolver STP
STP forall t h. AcknowledgementAction t h
SMT2.nullAcknowledgementAction
(forall a. SMTLib2GenericSolver a => a -> ProblemFeatures
SMT2.defaultFeatures STP
STP) (forall a. a -> Maybe a
Just ConfigOption BaseBoolType
stpStrictParsing)
setInteractiveLogicAndOptions ::
SMT2.SMTLib2Tweaks a =>
SMT2.WriterConn t (SMT2.Writer a) ->
IO ()
setInteractiveLogicAndOptions :: forall a t. SMTLib2Tweaks a => WriterConn t (Writer a) -> IO ()
setInteractiveLogicAndOptions WriterConn t (Writer a)
writer = do
forall a t.
SMTLib2Tweaks a =>
WriterConn t (Writer a) -> Text -> Text -> IO ()
SMT2.setOption WriterConn t (Writer a)
writer Text
"print-success" Text
"true"
forall a t.
SMTLib2Tweaks a =>
WriterConn t (Writer a) -> Text -> Text -> IO ()
SMT2.setOption WriterConn t (Writer a)
writer Text
"produce-models" Text
"true"
instance OnlineSolver (SMT2.Writer STP) where
startSolverProcess :: forall scope (st :: Type -> Type) fs.
ProblemFeatures
-> Maybe Handle
-> ExprBuilder scope st fs
-> IO (SolverProcess scope (Writer STP))
startSolverProcess ProblemFeatures
feat Maybe Handle
mbIOh ExprBuilder scope st fs
sym = do
SolverGoalTimeout
timeout <- Integer -> SolverGoalTimeout
SolverGoalTimeout forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$>
(forall (tp :: BaseType) a. Opt tp a => OptionSetting tp -> IO a
getOpt forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (tp :: BaseType).
ConfigOption tp -> Config -> IO (OptionSetting tp)
getOptionSetting ConfigOption BaseIntegerType
stpTimeout (forall sym. IsExprBuilder sym => sym -> Config
getConfiguration ExprBuilder scope st fs
sym))
forall a t (st :: Type -> Type) fs.
SMTLib2GenericSolver a =>
a
-> AcknowledgementAction t (Writer a)
-> (WriterConn t (Writer a) -> IO ())
-> SolverGoalTimeout
-> ProblemFeatures
-> Maybe (ConfigOption BaseBoolType)
-> Maybe Handle
-> ExprBuilder t st fs
-> IO (SolverProcess t (Writer a))
SMT2.startSolver STP
STP forall t a. AcknowledgementAction t (Writer a)
SMT2.smtAckResult
forall a t. SMTLib2Tweaks a => WriterConn t (Writer a) -> IO ()
setInteractiveLogicAndOptions
SolverGoalTimeout
timeout
ProblemFeatures
feat
(forall a. a -> Maybe a
Just ConfigOption BaseBoolType
stpStrictParsing) Maybe Handle
mbIOh ExprBuilder scope st fs
sym
shutdownSolverProcess :: forall scope.
SolverProcess scope (Writer STP) -> IO (ExitCode, Text)
shutdownSolverProcess = forall a t.
SMTLib2GenericSolver a =>
a -> SolverProcess t (Writer a) -> IO (ExitCode, Text)
SMT2.shutdownSolver STP
STP