diff --git a/cryptol-remote-api/src/CryptolServer.hs b/cryptol-remote-api/src/CryptolServer.hs index 2bf61679d..051462045 100644 --- a/cryptol-remote-api/src/CryptolServer.hs +++ b/cryptol-remote-api/src/CryptolServer.hs @@ -19,7 +19,7 @@ import Cryptol.ModuleSystem.Env initialModuleEnv, meSearchPath, ModulePath(..)) import Cryptol.ModuleSystem.Fingerprint ( fingerprintFile ) import Cryptol.Parser.AST (ModName) -import Cryptol.TypeCheck( SolverConfig(..) ) +import Cryptol.TypeCheck( defaultSolverConfig ) import qualified Cryptol.TypeCheck.Solver.SMT as SMT import qualified Argo @@ -135,15 +135,6 @@ initialState = s <- SMT.startSolver (defaultSolverConfig (meSearchPath modEnv)) pure (ServerState Nothing modEnv s) -defaultSolverConfig :: [FilePath] -> SolverConfig -defaultSolverConfig searchPath = - SolverConfig - { solverPath = "z3" - , solverArgs = [ "-smt2", "-in" ] - , solverVerbose = 0 - , solverPreludePath = searchPath - } - extendSearchPath :: [FilePath] -> ServerState -> ServerState extendSearchPath paths = over moduleEnv $ \me -> me { meSearchPath = nubOrd $ paths ++ meSearchPath me } diff --git a/src/Cryptol/REPL/Monad.hs b/src/Cryptol/REPL/Monad.hs index cf4c102d0..4004f82bc 100644 --- a/src/Cryptol/REPL/Monad.hs +++ b/src/Cryptol/REPL/Monad.hs @@ -183,13 +183,7 @@ defaultRW :: Bool -> Bool -> Logger -> IO RW defaultRW isBatch callStacks l = do env <- M.initialModuleEnv let searchPath = M.meSearchPath env - let solverConfig = - T.SolverConfig - { T.solverPath = "z3" - , T.solverArgs = [ "-smt2", "-in" ] - , T.solverVerbose = 0 - , T.solverPreludePath = searchPath - } + let solverConfig = T.defaultSolverConfig searchPath return RW { eLoadedMod = Nothing , eEditFile = Nothing diff --git a/src/Cryptol/TypeCheck.hs b/src/Cryptol/TypeCheck.hs index 4043ee9d7..682690f8a 100644 --- a/src/Cryptol/TypeCheck.hs +++ b/src/Cryptol/TypeCheck.hs @@ -15,6 +15,7 @@ module Cryptol.TypeCheck , InferInput(..) , InferOutput(..) , SolverConfig(..) + , defaultSolverConfig , NameSeeds , nameSeeds , Error(..) @@ -49,7 +50,7 @@ import Cryptol.TypeCheck.Monad , io ) import Cryptol.TypeCheck.Infer (inferModule, inferBinds, checkTopDecls) -import Cryptol.TypeCheck.InferTypes(VarType(..), SolverConfig(..)) +import Cryptol.TypeCheck.InferTypes(VarType(..), SolverConfig(..), defaultSolverConfig) import Cryptol.TypeCheck.Solve(proveModuleTopLevel) import Cryptol.TypeCheck.CheckModuleInstance(checkModuleInstance) -- import Cryptol.TypeCheck.Monad(withParamType,withParameterConstraints) diff --git a/src/Cryptol/TypeCheck/InferTypes.hs b/src/Cryptol/TypeCheck/InferTypes.hs index 6b2c814c9..9f8546c3f 100644 --- a/src/Cryptol/TypeCheck/InferTypes.hs +++ b/src/Cryptol/TypeCheck/InferTypes.hs @@ -48,6 +48,18 @@ data SolverConfig = SolverConfig } deriving (Show, Generic, NFData) +-- | A default configuration for using Z3, where +-- the solver prelude is expected to be found +-- in the given search path. +defaultSolverConfig :: [FilePath] -> SolverConfig +defaultSolverConfig searchPath = + SolverConfig + { solverPath = "z3" + , solverArgs = [ "-smt2", "-in" ] + , solverVerbose = 0 + , solverPreludePath = searchPath + } + -- | The types of variables in the environment. data VarType = ExtVar Schema -- ^ Known type diff --git a/src/Cryptol/TypeCheck/Solver/SMT.hs b/src/Cryptol/TypeCheck/Solver/SMT.hs index 1feee08d8..c2fae2362 100644 --- a/src/Cryptol/TypeCheck/Solver/SMT.hs +++ b/src/Cryptol/TypeCheck/Solver/SMT.hs @@ -67,6 +67,7 @@ data Solver = Solver -- ^ For debugging } + -- | Start a fresh solver instance startSolver :: SolverConfig -> IO Solver startSolver SolverConfig { .. } = diff --git a/src/Cryptol/Utils/Ident.hs b/src/Cryptol/Utils/Ident.hs index 47134016b..aff524250 100644 --- a/src/Cryptol/Utils/Ident.hs +++ b/src/Cryptol/Utils/Ident.hs @@ -15,6 +15,7 @@ module Cryptol.Utils.Ident , apPathRoot , modPathCommon , topModuleFor + , modPathSplit , ModName , modNameToText