summaryrefslogtreecommitdiff
path: root/compiler/typecheck/TcRnDriver.lhs
diff options
context:
space:
mode:
authorAdam Gundry <adam@well-typed.com>2014-11-20 13:32:26 +0000
committerAdam Gundry <adam@well-typed.com>2014-11-20 16:54:44 +0000
commit64cb49686457c233d0f58e5cfa324ad28a5453a3 (patch)
tree7037ca2fa8ad2702b1f2e73b7f3598a790afded4 /compiler/typecheck/TcRnDriver.lhs
parentcce6318e8fdb086a8501a0c81ae1ee02eed67835 (diff)
downloadhaskell-64cb49686457c233d0f58e5cfa324ad28a5453a3.tar.gz
Implement typechecker plugins
Summary: See https://ghc.haskell.org/trac/ghc/wiki/Plugins/TypeChecker This is based on work by Iavor Diatchki and Eric Seidel. Test Plan: validate Reviewers: simonpj, austin Reviewed By: austin Subscribers: gridaphobe, yav, thomie, carter Differential Revision: https://phabricator.haskell.org/D489 Conflicts: docs/users_guide/7.10.1-notes.xml
Diffstat (limited to 'compiler/typecheck/TcRnDriver.lhs')
-rw-r--r--compiler/typecheck/TcRnDriver.lhs48
1 files changed, 44 insertions, 4 deletions
diff --git a/compiler/typecheck/TcRnDriver.lhs b/compiler/typecheck/TcRnDriver.lhs
index 32113bb976..0b1601bc3a 100644
--- a/compiler/typecheck/TcRnDriver.lhs
+++ b/compiler/typecheck/TcRnDriver.lhs
@@ -20,7 +20,7 @@ module TcRnDriver (
tcRnLookupName,
tcRnGetInfo,
tcRnModule, tcRnModuleTcRnM,
- tcTopSrcDecls
+ tcTopSrcDecls,
) where
#ifdef GHCI
@@ -93,6 +93,8 @@ import RnExpr
import MkId
import TidyPgm ( globaliseAndTidyId )
import TysWiredIn ( unitTy, mkListTy )
+import DynamicLoading ( loadPlugins )
+import Plugins ( tcPlugin )
#endif
import TidyPgm ( mkBootModDetailsTc )
@@ -134,8 +136,11 @@ tcRnModule hsc_env hsc_src save_rn_syntax
Just (L mod_loc mod) -- The normal case
-> (mkModule this_pkg mod, mod_loc) } ;
- ; initTc hsc_env hsc_src save_rn_syntax this_mod $
- tcRnModuleTcRnM hsc_env hsc_src parsedModule pair }
+ ; res <- initTc hsc_env hsc_src save_rn_syntax this_mod $
+ withTcPlugins hsc_env $
+ tcRnModuleTcRnM hsc_env hsc_src parsedModule pair
+ ; return res
+ }
-- To be called at the beginning of renaming hsig files.
-- If we're processing a signature, load up the RdrEnv
@@ -1380,7 +1385,7 @@ runTcInteractive :: HscEnv -> TcRn a -> IO (Messages, Maybe a)
-- Initialise the tcg_inst_env with instances from all home modules.
-- This mimics the more selective call to hptInstances in tcRnImports
runTcInteractive hsc_env thing_inside
- = initTcInteractive hsc_env $
+ = initTcInteractive hsc_env $ withTcPlugins hsc_env $
do { traceTc "setInteractiveContext" $
vcat [ text "ic_tythings:" <+> vcat (map ppr (ic_tythings icxt))
, text "ic_insts:" <+> vcat (map (pprBndr LetBind . instanceDFunId) ic_insts)
@@ -2090,3 +2095,38 @@ ppr_tydecls tycons
where
ppr_tycon tycon = vcat [ ppr (tyThingToIfaceDecl (ATyCon tycon)) ]
\end{code}
+
+
+********************************************************************************
+
+Type Checker Plugins
+
+********************************************************************************
+
+
+\begin{code}
+withTcPlugins :: HscEnv -> TcM a -> TcM a
+withTcPlugins hsc_env m =
+ do plugins <- liftIO (loadTcPlugins hsc_env)
+ case plugins of
+ [] -> m -- Common fast case
+ _ -> do (solvers,stops) <- unzip `fmap` mapM startPlugin plugins
+ res <- updGblEnv (\e -> e { tcg_tc_plugins = solvers }) m
+ mapM_ runTcPluginM stops
+ return res
+ where
+ startPlugin (TcPlugin start solve stop) =
+ do s <- runTcPluginM start
+ return (solve s, stop s)
+
+loadTcPlugins :: HscEnv -> IO [TcPlugin]
+#ifndef GHCI
+loadTcPlugins _ = return []
+#else
+loadTcPlugins hsc_env =
+ do named_plugins <- loadPlugins hsc_env
+ return $ catMaybes $ map load_plugin named_plugins
+ where
+ load_plugin (_, plug, opts) = tcPlugin plug opts
+#endif
+\end{code}