diff options
author | Facundo DomÃnguez <facundo.dominguez@tweag.io> | 2017-09-21 18:04:56 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-09-21 20:13:04 -0400 |
commit | 175586908963a6d438cf3c28922a38191f4eaa66 (patch) | |
tree | c481ea2193d5b15aba917e201869ba0772510dec /compiler/main/HscMain.hs | |
parent | a9d417dab21e0b677f13c2ba99244162a8fffe3e (diff) | |
download | haskell-175586908963a6d438cf3c28922a38191f4eaa66.tar.gz |
Implement TH addCorePlugin.
This allows template-haskell code to add plugins to the compilation
pipeline. Otherwise, the user would have to pass -fplugin=... to ghc.
For now, plugin modules in the current package can't be used. This is
because when TH runs, it is too late to let GHC know that the plugin
modules needed to be compiled first.
Test Plan: ./validate
Reviewers: simonpj, bgamari, austin, goldfire
Reviewed By: bgamari
Subscribers: angerman, rwbarton, mboes, thomie
GHC Trac Issues: #13608
Differential Revision: https://phabricator.haskell.org/D3821
Diffstat (limited to 'compiler/main/HscMain.hs')
-rw-r--r-- | compiler/main/HscMain.hs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/compiler/main/HscMain.hs b/compiler/main/HscMain.hs index f7a7933db4..8040b1dfb2 100644 --- a/compiler/main/HscMain.hs +++ b/compiler/main/HscMain.hs @@ -85,6 +85,7 @@ module HscMain import GhcPrelude import Data.Data hiding (Fixity, TyCon) +import DynFlags (addPluginModuleName) import Id import GHCi ( addSptEntry ) import GHCi.RemoteTypes ( ForeignHValue ) @@ -753,7 +754,8 @@ finish hsc_env summary tc_result mb_old_hash = do -- and generate a simple interface. then mk_simple_iface else do - desugared_guts <- hscSimplify' desugared_guts0 + plugins <- liftIO $ readIORef (tcg_th_coreplugins tc_result) + desugared_guts <- hscSimplify' plugins desugared_guts0 (iface, changed, details, cgguts) <- liftIO $ hscNormalIface hsc_env desugared_guts mb_old_hash return (iface, changed, details, HscRecomp cgguts summary) @@ -1188,14 +1190,18 @@ hscGetSafeMode tcg_env = do -- Simplifiers -------------------------------------------------------------- -hscSimplify :: HscEnv -> ModGuts -> IO ModGuts -hscSimplify hsc_env modguts = runHsc hsc_env $ hscSimplify' modguts +hscSimplify :: HscEnv -> [String] -> ModGuts -> IO ModGuts +hscSimplify hsc_env plugins modguts = + runHsc hsc_env $ hscSimplify' plugins modguts -hscSimplify' :: ModGuts -> Hsc ModGuts -hscSimplify' ds_result = do +hscSimplify' :: [String] -> ModGuts -> Hsc ModGuts +hscSimplify' plugins ds_result = do hsc_env <- getHscEnv + let hsc_env_with_plugins = hsc_env + { hsc_dflags = foldr addPluginModuleName (hsc_dflags hsc_env) plugins + } {-# SCC "Core2Core" #-} - liftIO $ core2core hsc_env ds_result + liftIO $ core2core hsc_env_with_plugins ds_result -------------------------------------------------------------- -- Interface generators @@ -1578,7 +1584,9 @@ hscDeclsWithLocation hsc_env0 str source linenumber = ds_result <- hscDesugar' iNTERACTIVELoc tc_gblenv {- Simplify -} - simpl_mg <- liftIO $ hscSimplify hsc_env ds_result + simpl_mg <- liftIO $ do + plugins <- readIORef (tcg_th_coreplugins tc_gblenv) + hscSimplify hsc_env plugins ds_result {- Tidy -} (tidy_cg, mod_details) <- liftIO $ tidyProgram hsc_env simpl_mg |