Reinitialize GHC session when options change
This commit is contained in:
parent
503562b9b6
commit
8b8f947b5e
@ -92,34 +92,33 @@ initSession :: IOish m
|
|||||||
initSession opts mdf = do
|
initSession opts mdf = do
|
||||||
s <- gmsGet
|
s <- gmsGet
|
||||||
case gmGhcSession s of
|
case gmGhcSession s of
|
||||||
Just GmGhcSession {..} -> do
|
Just GmGhcSession {..} -> when (gmgsOptions /= opts) $ putNewSession s
|
||||||
if gmgsOptions == opts
|
Nothing -> putNewSession s
|
||||||
then return ()
|
|
||||||
else error "TODO: reload stuff"
|
|
||||||
Nothing -> do
|
|
||||||
Cradle { cradleTempDir } <- cradle
|
|
||||||
ghc <- liftIO $ runGhc (Just libdir) $ do
|
|
||||||
let setDf df =
|
|
||||||
setTmpDir cradleTempDir <$> (mdf =<< addCmdOpts opts df)
|
|
||||||
_ <- setSessionDynFlags =<< setDf =<< getSessionDynFlags
|
|
||||||
getSession
|
|
||||||
|
|
||||||
rghc <- liftIO $ newIORef ghc
|
where
|
||||||
gmsPut s { gmGhcSession = Just $ GmGhcSession opts rghc }
|
putNewSession s = do
|
||||||
|
rghc <- (liftIO . newIORef =<< newSession =<< cradle)
|
||||||
|
gmsPut s { gmGhcSession = Just $ GmGhcSession opts rghc }
|
||||||
|
|
||||||
|
newSession Cradle { cradleTempDir } = liftIO $ do
|
||||||
|
runGhc (Just libdir) $ do
|
||||||
|
let setDf df = setTmpDir cradleTempDir <$> (mdf =<< addCmdOpts opts df)
|
||||||
|
_ <- setSessionDynFlags =<< setDf =<< getSessionDynFlags
|
||||||
|
getSession
|
||||||
|
|
||||||
|
dropSession :: IOish m => GhcModT m ()
|
||||||
|
dropSession = do
|
||||||
|
s <- gmsGet
|
||||||
|
case gmGhcSession s of
|
||||||
|
Just (GmGhcSession _opts ref) -> do
|
||||||
|
-- TODO: This is still not enough, there seem to still be references to
|
||||||
|
-- GHC's state around afterwards.
|
||||||
|
liftIO $ writeIORef ref (error "HscEnv: session was dropped")
|
||||||
|
liftIO $ setUnsafeGlobalDynFlags (error "DynFlags: session was dropped")
|
||||||
|
|
||||||
|
|
||||||
-- $ do
|
Nothing -> return ()
|
||||||
-- dflags <- getSessionDynFlags
|
gmsPut s { gmGhcSession = Nothing }
|
||||||
-- defaultCleanupHandler dflags $ do
|
|
||||||
-- initializeFlagsWithCradle opt (gmCradle env)
|
|
||||||
--
|
|
||||||
|
|
||||||
-- initSession :: GhcMonad m => Options -> [GHCOption] -> m ()
|
|
||||||
-- initSession Options {..} ghcOpts = do
|
|
||||||
-- df <- G.getSessionDynFlags
|
|
||||||
-- void $
|
|
||||||
-- ( setModeSimple -- $ setEmptyLogger
|
|
||||||
-- df)
|
|
||||||
|
|
||||||
runGmlT :: IOish m => [Either FilePath ModuleName] -> GmlT m a -> GhcModT m a
|
runGmlT :: IOish m => [Either FilePath ModuleName] -> GmlT m a -> GhcModT m a
|
||||||
runGmlT fns action = runGmlT' fns return action
|
runGmlT fns action = runGmlT' fns return action
|
||||||
|
Loading…
Reference in New Issue
Block a user