Skip to content

Commit

Permalink
Fixes #1167
Browse files Browse the repository at this point in the history
This requires newer version simple-smt, which supports calling back into
the program when the solver exits
  • Loading branch information
yav authored and robdockins committed Jul 21, 2021
1 parent ce647eb commit 816523d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cryptol.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ library
pretty >= 1.1,
process >= 1.2,
sbv >= 8.6 && < 8.15,
simple-smt >= 0.7.1,
simple-smt >= 0.9.7,
stm >= 2.4,
strict,
text >= 1.1,
Expand Down Expand Up @@ -231,6 +231,7 @@ executable cryptol
, directory
, filepath
, haskeline >= 0.7 && < 0.9
, exceptions
, monad-control
, text
, transformers
Expand Down
7 changes: 6 additions & 1 deletion src/Cryptol/REPL/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,18 @@ getPrompt = mkPrompt `fmap` getRW
getCallStacks :: REPL Bool
getCallStacks = eCallStacks <$> getRW

clearTCSolverAction :: REPL (IO ())
clearTCSolverAction =
REPL (\ref -> pure (modifyIORef ref (\rw -> rw { eTCSolver = Nothing })))

getTCSolver :: REPL SMT.Solver
getTCSolver =
do rw <- getRW
case eTCSolver rw of
Just s -> return s
Nothing ->
do s <- io (SMT.startSolver (eTCConfig rw))
do onExit <- clearTCSolverAction
s <- io (SMT.startSolver onExit (eTCConfig rw))
modifyRW_ (\rw' -> rw'{ eTCSolver = Just s })
return s

Expand Down
11 changes: 6 additions & 5 deletions src/Cryptol/TypeCheck/Solver/SMT.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ data Solver = Solver


-- | Start a fresh solver instance
startSolver :: SolverConfig -> IO Solver
startSolver SolverConfig { .. } =
startSolver :: IO () -> SolverConfig -> IO Solver
startSolver onExit SolverConfig { .. } =
do logger <- if solverVerbose > 0 then SMT.newLogger 0

else return quietLogger
let smtDbg = if solverVerbose > 1 then Just logger else Nothing
solver <- SMT.newSolver solverPath solverArgs smtDbg
solver <- SMT.newSolverNotify
solverPath solverArgs smtDbg (Just (const onExit))
_ <- SMT.setOptionMaybe solver ":global-decls" "false"
-- SMT.setLogic solver "QF_LIA"
let sol = Solver { .. }
Expand All @@ -95,8 +96,8 @@ stopSolver :: Solver -> IO ()
stopSolver s = void $ SMT.stop (solver s)

-- | Execute a computation with a fresh solver instance.
withSolver :: SolverConfig -> (Solver -> IO a) -> IO a
withSolver cfg = bracket (startSolver cfg) stopSolver
withSolver :: IO () -> SolverConfig -> (Solver -> IO a) -> IO a
withSolver onExit cfg = bracket (startSolver onExit cfg) stopSolver

-- | Load the definitions used for type checking.
loadTcPrelude :: Solver -> [FilePath] {- ^ Search in this paths -} -> IO ()
Expand Down

0 comments on commit 816523d

Please sign in to comment.