From ecfd0278cb811c93853c176fe5df60222d1a8fb5 Mon Sep 17 00:00:00 2001 From: Sylvain Henry Date: Tue, 3 Nov 2020 12:04:53 +0100 Subject: Move Plugins into HscEnv (#17957) Loaded plugins have nothing to do in DynFlags so this patch moves them into HscEnv (session state). "DynFlags plugins" become "Driver plugins" to still be able to register static plugins. Bump haddock submodule --- compiler/GHC.hs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'compiler/GHC.hs') diff --git a/compiler/GHC.hs b/compiler/GHC.hs index 13d8ba5ec7..cc8f93bba0 100644 --- a/compiler/GHC.hs +++ b/compiler/GHC.hs @@ -313,6 +313,7 @@ import GHC.Driver.Monad import GHC.Driver.Ppr import GHC.ByteCode.Types +import GHC.Runtime.Loader import GHC.Runtime.Eval import GHC.Runtime.Eval.Types import GHC.Runtime.Interpreter @@ -729,6 +730,8 @@ getProgramDynFlags :: GhcMonad m => m DynFlags getProgramDynFlags = getSessionDynFlags -- | Set the 'DynFlags' used to evaluate interactive expressions. +-- Also initialise (load) plugins. +-- -- Note: this cannot be used for changes to packages. Use -- 'setSessionDynFlags', or 'setProgramDynFlags' and then copy the -- 'unitState' into the interactive @DynFlags@. @@ -736,7 +739,22 @@ setInteractiveDynFlags :: GhcMonad m => DynFlags -> m () setInteractiveDynFlags dflags = do dflags' <- checkNewDynFlags dflags dflags'' <- checkNewInteractiveDynFlags dflags' - modifySession $ \h -> h{ hsc_IC = (hsc_IC h) { ic_dflags = dflags'' }} + modifySessionM $ \hsc_env0 -> do + let ic0 = hsc_IC hsc_env0 + + -- Initialise (load) plugins in the interactive environment with the new + -- DynFlags + plugin_env <- liftIO $ initializePlugins $ mkInteractiveHscEnv $ + hsc_env0 { hsc_IC = ic0 { ic_dflags = dflags'' }} + + -- Update both plugins cache and DynFlags in the interactive context. + return $ hsc_env0 + { hsc_IC = ic0 + { ic_plugins = hsc_plugins plugin_env + , ic_dflags = hsc_dflags plugin_env + } + } + -- | Get the 'DynFlags' used to evaluate interactive expressions. getInteractiveDynFlags :: GhcMonad m => m DynFlags -- cgit v1.2.1