Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
GHC.Driver.Monad
Contents
Synopsis
- class (Functor m, ExceptionMonad m, HasDynFlags m, HasLogger m) => GhcMonad m where
- getSession :: m HscEnv
- setSession :: HscEnv -> m ()
- newtype Ghc a = Ghc {}
- newtype GhcT m a = GhcT {}
- liftGhcT :: m a -> GhcT m a
- reflectGhc :: Ghc a -> Session -> IO a
- reifyGhc :: (Session -> IO a) -> Ghc a
- getSessionDynFlags :: GhcMonad m => m DynFlags
- liftIO :: MonadIO m => IO a -> m a
- data Session = Session !(IORef HscEnv)
- withSession :: GhcMonad m => (HscEnv -> m a) -> m a
- modifySession :: GhcMonad m => (HscEnv -> HscEnv) -> m ()
- modifySessionM :: GhcMonad m => (HscEnv -> m HscEnv) -> m ()
- withTempSession :: GhcMonad m => (HscEnv -> HscEnv) -> m a -> m a
- modifyLogger :: GhcMonad m => (Logger -> Logger) -> m ()
- pushLogHookM :: GhcMonad m => (LogAction -> LogAction) -> m ()
- popLogHookM :: GhcMonad m => m ()
- putLogMsgM :: GhcMonad m => MessageClass -> SrcSpan -> SDoc -> m ()
- putMsgM :: GhcMonad m => SDoc -> m ()
- withTimingM :: GhcMonad m => SDoc -> (b -> ()) -> m b -> m b
- logDiagnostics :: GhcMonad m => Messages GhcMessage -> m ()
- printException :: (HasLogger m, MonadIO m, HasDynFlags m) => SourceError -> m ()
- type WarnErrLogger = forall m. (HasDynFlags m, MonadIO m, HasLogger m) => Maybe SourceError -> m ()
- defaultWarnErrLogger :: WarnErrLogger
Ghc
monad stuff
class (Functor m, ExceptionMonad m, HasDynFlags m, HasLogger m) => GhcMonad m where #
A monad that has all the features needed by GHC API calls.
In short, a GHC monad
- allows embedding of IO actions,
- can log warnings,
- allows handling of (extensible) exceptions, and
- maintains a current session.
If you do not use Ghc
or GhcT
, make sure to call initGhcMonad
before any call to the GHC API functions can occur.
Instances
GhcMonad Ghc # | |
Defined in GHC.Driver.Monad | |
ExceptionMonad m => GhcMonad (GhcT m) # | |
Defined in GHC.Driver.Monad |
A minimal implementation of a GhcMonad
. If you need a custom monad,
e.g., to maintain additional state consider wrapping this monad or using
GhcT
.
Instances
MonadFail Ghc # | |
Defined in GHC.Driver.Monad | |
MonadFix Ghc # | |
Defined in GHC.Driver.Monad | |
MonadIO Ghc # | |
Defined in GHC.Driver.Monad | |
Applicative Ghc # | |
Functor Ghc # | |
Monad Ghc # | |
MonadCatch Ghc # | |
Defined in GHC.Driver.Monad | |
MonadMask Ghc # | |
Defined in GHC.Driver.Monad Methods mask :: HasCallStack => ((forall a. Ghc a -> Ghc a) -> Ghc b) -> Ghc b uninterruptibleMask :: HasCallStack => ((forall a. Ghc a -> Ghc a) -> Ghc b) -> Ghc b generalBracket :: HasCallStack => Ghc a -> (a -> ExitCase b -> Ghc c) -> (a -> Ghc b) -> Ghc (b, c) | |
MonadThrow Ghc # | |
Defined in GHC.Driver.Monad Methods throwM :: (HasCallStack, Exception e) => e -> Ghc a | |
HasDynFlags Ghc # | |
Defined in GHC.Driver.Monad Methods getDynFlags :: Ghc DynFlags # | |
GhcMonad Ghc # | |
Defined in GHC.Driver.Monad | |
HasLogger Ghc # | |
Defined in GHC.Driver.Monad |
A monad transformer to add GHC specific features to another monad.
Note that the wrapped monad must support IO and handling of exceptions.
Instances
MonadFail m => MonadFail (GhcT m) # | |
Defined in GHC.Driver.Monad | |
MonadFix m => MonadFix (GhcT m) # | |
Defined in GHC.Driver.Monad | |
MonadIO m => MonadIO (GhcT m) # | |
Defined in GHC.Driver.Monad | |
Applicative m => Applicative (GhcT m) # | |
Functor m => Functor (GhcT m) # | |
Monad m => Monad (GhcT m) # | |
MonadCatch m => MonadCatch (GhcT m) # | |
Defined in GHC.Driver.Monad | |
MonadMask m => MonadMask (GhcT m) # | |
Defined in GHC.Driver.Monad Methods mask :: HasCallStack => ((forall a. GhcT m a -> GhcT m a) -> GhcT m b) -> GhcT m b uninterruptibleMask :: HasCallStack => ((forall a. GhcT m a -> GhcT m a) -> GhcT m b) -> GhcT m b generalBracket :: HasCallStack => GhcT m a -> (a -> ExitCase b -> GhcT m c) -> (a -> GhcT m b) -> GhcT m (b, c) | |
MonadThrow m => MonadThrow (GhcT m) # | |
Defined in GHC.Driver.Monad Methods throwM :: (HasCallStack, Exception e) => e -> GhcT m a | |
MonadIO m => HasDynFlags (GhcT m) # | |
Defined in GHC.Driver.Monad Methods getDynFlags :: GhcT m DynFlags # | |
ExceptionMonad m => GhcMonad (GhcT m) # | |
Defined in GHC.Driver.Monad | |
MonadIO m => HasLogger (GhcT m) # | |
Defined in GHC.Driver.Monad |
reflectGhc :: Ghc a -> Session -> IO a #
Reflect a computation in the Ghc
monad into the IO
monad.
You can use this to call functions returning an action in the Ghc
monad
inside an IO
action. This is needed for some (too restrictive) callback
arguments of some library functions:
libFunc :: String -> (Int -> IO a) -> IO a ghcFunc :: Int -> Ghc a ghcFuncUsingLibFunc :: String -> Ghc a -> Ghc a ghcFuncUsingLibFunc str = reifyGhc $ \s -> libFunc $ \i -> do reflectGhc (ghcFunc i) s
getSessionDynFlags :: GhcMonad m => m DynFlags #
Grabs the DynFlags from the Session
The Session is a handle to the complete state of a compilation session. A compilation session consists of a set of modules constituting the current program or library, the context for interactive evaluation, and various caches.
withSession :: GhcMonad m => (HscEnv -> m a) -> m a #
Call the argument with the current session.
modifySession :: GhcMonad m => (HscEnv -> HscEnv) -> m () #
Set the current session to the result of applying the current session to the argument.
modifySessionM :: GhcMonad m => (HscEnv -> m HscEnv) -> m () #
Set the current session to the result of applying the current session to the argument.
withTempSession :: GhcMonad m => (HscEnv -> HscEnv) -> m a -> m a #
Call an action with a temporarily modified Session.
Logger
modifyLogger :: GhcMonad m => (Logger -> Logger) -> m () #
Modify the logger
pushLogHookM :: GhcMonad m => (LogAction -> LogAction) -> m () #
Push a log hook on the stack
popLogHookM :: GhcMonad m => m () #
Pop a log hook from the stack
putLogMsgM :: GhcMonad m => MessageClass -> SrcSpan -> SDoc -> m () #
Put a log message
withTimingM :: GhcMonad m => SDoc -> (b -> ()) -> m b -> m b #
Time an action
Diagnostics
logDiagnostics :: GhcMonad m => Messages GhcMessage -> m () #
A monad that allows logging of diagnostics.
printException :: (HasLogger m, MonadIO m, HasDynFlags m) => SourceError -> m () #
Print the all diagnostics in a SourceError
. Useful inside exception
handlers.
type WarnErrLogger = forall m. (HasDynFlags m, MonadIO m, HasLogger m) => Maybe SourceError -> m () #
A function called to log warnings and errors.