summaryrefslogtreecommitdiff
path: root/compiler/GHC/Runtime/Loader.hs
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2023-03-27 13:20:26 +0100
committerMatthew Pickering <matthewtpickering@gmail.com>2023-05-05 09:43:40 +0100
commitaf51225b02bc2e45184df685e87d8be74936db6e (patch)
tree7a9acaf29e5733bd85dfc94b6261e5f2d3b5efb9 /compiler/GHC/Runtime/Loader.hs
parentf6d990aebf50015f5ea0b3e40c19f868a9124661 (diff)
downloadhaskell-wip/plugin-init.tar.gz
docs: Add Note [Timing of plugin initialization]wip/plugin-init
Diffstat (limited to 'compiler/GHC/Runtime/Loader.hs')
-rw-r--r--compiler/GHC/Runtime/Loader.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/compiler/GHC/Runtime/Loader.hs b/compiler/GHC/Runtime/Loader.hs
index 3349ed0020..5617376f60 100644
--- a/compiler/GHC/Runtime/Loader.hs
+++ b/compiler/GHC/Runtime/Loader.hs
@@ -76,6 +76,29 @@ import Data.List (unzip4)
import GHC.Iface.Errors.Ppr
import GHC.Driver.Monad
+{- Note [Timing of plugin initialization]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Plugins needs to be initialised as soon as possible in the pipeline. This is because
+driver plugins are executed immediately after being loaded, which can modify anything
+in the HscEnv, including the logger and DynFlags (for example #21279). For example,
+in ghc/Main.hs the logger is used almost immediately after the session has been initialised
+and so if a user overwrites the logger expecting all output to go there then unless
+the plugins are initialised before that point then unexpected things will happen.
+
+We initialise plugins in ghc/Main.hs for the main ghc executable.
+
+When people are using the GHC API, they also need to initialise plugins
+at the highest level possible for things to work as expected. We keep
+some defensive calls to plugin initialisation in functions like `load'` and `oneshot`
+to catch cases where API users have not initialised their own plugins.
+
+In addition to this, there needs to be an initialisation call for each module
+just in case the user has enabled a plugin just for that module using OPTIONS_GHC
+pragma.
+
+-}
+
-- | Initialise plugins specified by the current DynFlags and update the session.
initializeSessionPlugins :: GhcMonad m => m ()
initializeSessionPlugins = getSession >>= liftIO . initializePlugins >>= setSession