summaryrefslogtreecommitdiff
path: root/compiler/main/GhcMonad.hs
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2011-12-19 15:50:47 +0000
committerIan Lynagh <igloo@earth.li>2011-12-19 15:57:22 +0000
commit06c6d9709fb73cbaf9c0e1da337c5467c2839f0a (patch)
tree6ceb4241e5b8167d791100f29866447ab6b16ea8 /compiler/main/GhcMonad.hs
parent0c047a8357551b002b76b76859b748fb51f64633 (diff)
downloadhaskell-06c6d9709fb73cbaf9c0e1da337c5467c2839f0a.tar.gz
Add a class HasDynFlags(getDynFlags)
We no longer have many separate, clashing getDynFlags functions I've given each GhcMonad its own HasDynFlags instance, rather than using UndecidableInstances to make a GhcMonad m => HasDynFlags m instance.
Diffstat (limited to 'compiler/main/GhcMonad.hs')
-rw-r--r--compiler/main/GhcMonad.hs9
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler/main/GhcMonad.hs b/compiler/main/GhcMonad.hs
index 816cc4b922..6b8c7bacdf 100644
--- a/compiler/main/GhcMonad.hs
+++ b/compiler/main/GhcMonad.hs
@@ -46,11 +46,10 @@ import Data.IORef
-- If you do not use 'Ghc' or 'GhcT', make sure to call 'GHC.initGhcMonad'
-- before any call to the GHC API functions can occur.
--
-class (Functor m, MonadIO m, ExceptionMonad m) => GhcMonad m where
+class (Functor m, MonadIO m, ExceptionMonad m, HasDynFlags m) => GhcMonad m where
getSession :: m HscEnv
setSession :: HscEnv -> m ()
-
-- | Call the argument with the current session.
withSession :: GhcMonad m => (HscEnv -> m a) -> m a
withSession f = getSession >>= f
@@ -120,6 +119,9 @@ instance ExceptionMonad Ghc where
in
unGhc (f g_restore) s
+instance HasDynFlags Ghc where
+ getDynFlags = getSessionDynFlags
+
instance GhcMonad Ghc where
getSession = Ghc $ \(Session r) -> readIORef r
setSession s' = Ghc $ \(Session r) -> writeIORef r s'
@@ -176,6 +178,9 @@ instance ExceptionMonad m => ExceptionMonad (GhcT m) where
in
unGhcT (f g_restore) s
+instance (Functor m, ExceptionMonad m, MonadIO m) => HasDynFlags (GhcT m) where
+ getDynFlags = getSessionDynFlags
+
instance (Functor m, ExceptionMonad m, MonadIO m) => GhcMonad (GhcT m) where
getSession = GhcT $ \(Session r) -> liftIO $ readIORef r
setSession s' = GhcT $ \(Session r) -> liftIO $ writeIORef r s'