From af0a6aae3cc6ccc13319a9fbe0076e65374e9fe7 Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Sun, 31 Jul 2011 10:26:52 -0500 Subject: Add plugin documentation for reinitializeGlobals --- docs/users_guide/extending_ghc.xml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/users_guide/extending_ghc.xml b/docs/users_guide/extending_ghc.xml index 11cd75d898..1bce3fa7b4 100644 --- a/docs/users_guide/extending_ghc.xml +++ b/docs/users_guide/extending_ghc.xml @@ -173,12 +173,16 @@ plugin = defaultPlugin { install :: [CommandLineOption] -> [CoreToDo] -> CoreM [CoreToDo] install _ todo = do + reinitializeGlobals putMsgS "Hello!" return todo Provided you compiled this plugin and registered it in a package (with cabal for instance,) you can then use it by just specifying -fplugin=DoNothing.Plugin on the command line, and during the compilation you should see GHC say 'Hello'. + Note carefully the reinitializeGlobals call at the beginning of the installation function. Due to bugs in the windows linker dealing with libghc, this call is necessary to properly ensure compiler plugins have the same global state as GHC at the time of invocation. Without reinitializeGlobals, compiler plugins can crash at runtime because they may require state that hasn't otherwise been initialized. + + In the future, when the linking bugs are fixed, reinitializeGlobals will be deprecated with a warning, and changed to do nothing. <literal>CoreToDo</literal> in more detail @@ -217,7 +221,9 @@ plugin = defaultPlugin { } install :: [CommandLineOption] -> [CoreToDo] -> CoreM [CoreToDo] -install _ todo = return (CoreDoPluginPass "Say name" pass : todo) +install _ todo = do + reinitializeGlobals + return (CoreDoPluginPass "Say name" pass : todo) pass :: ModGuts -> CoreM ModGuts pass = bindsOnlyPass (mapM printBind) @@ -252,7 +258,9 @@ plugin = defaultPlugin { } install :: [CommandLineOption] -> [CoreToDo] -> CoreM [CoreToDo] -install _ todo = return (CoreDoPluginPass "Say name" pass : todo) +install _ todo = do + reinitializeGlobals + return (CoreDoPluginPass "Say name" pass : todo) pass :: ModGuts -> CoreM ModGuts pass g = mapM_ (printAnn g) (mg_binds g) >> return g -- cgit v1.2.1