CoreMonad

ghc-8.4.4: The GHC API

Safe Haskell | None
Language | Haskell2010

CoreMonad

Contents

- Configuration of the core-to-core passes
- Plugins
- Counting
- The monad
  - Reading from the monad
  - Writing to the monad
  - Lifting into the monad
  - Global initialization
  - Dealing with annotations
  - Screen output
- Getting `Name`s

Synopsis

- data CoreToDo
  - = CoreDoSimplify Int SimplMode
  - | CoreDoPluginPass String PluginPass
  - | CoreDoFloatInwards
  - | CoreDoFloatOutwards FloatOutSwitches
  - | CoreLiberateCase
  - | CoreDoPrintCore
  - | CoreDoStaticArgs
  - | CoreDoCallArity
  - | CoreDoExitify
  - | CoreDoStrictness
  - | CoreDoWorkerWrapper
  - | CoreDoSpecialising
  - | CoreDoSpecConstr
  - | CoreCSE
  - | CoreDoRuleCheck CompilerPhase String
  - | CoreDoVectorisation
  - | CoreDoNothing
  - | CoreDoPasses [CoreToDo]
  - | CoreDesugar
  - | CoreDesugarOpt
  - | CoreTidy
  - | CorePrep
  - | CoreOccurAnal
- runWhen :: Bool -> CoreToDo -> CoreToDo
- runMaybe :: Maybe a -> (a -> CoreToDo) -> CoreToDo
- data SimplMode = SimplMode {
  - sm_names :: [String]
  - sm_phase :: CompilerPhase
  - sm_dflags :: DynFlags
  - sm_rules :: Bool
  - sm_inline :: Bool
  - sm_case_case :: Bool
  - sm_eta_expand :: Bool
  }
- data FloatOutSwitches = FloatOutSwitches {
  - floatOutLambdas :: Maybe Int
  - floatOutConstants :: Bool
  - floatOutOverSatApps :: Bool
  - floatToTopLevelOnly :: Bool
  }
- pprPassDetails :: CoreToDo -> SDoc
- type PluginPass = ModGuts -> CoreM ModGuts
- bindsOnlyPass :: (CoreProgram -> CoreM CoreProgram) -> ModGuts -> CoreM ModGuts
- data SimplCount
- doSimplTick :: DynFlags -> Tick -> SimplCount -> SimplCount
- doFreeSimplTick :: Tick -> SimplCount -> SimplCount
- simplCountN :: SimplCount -> Int
- pprSimplCount :: SimplCount -> SDoc
- plusSimplCount :: SimplCount -> SimplCount -> SimplCount
- zeroSimplCount :: DynFlags -> SimplCount
- isZeroSimplCount :: SimplCount -> Bool
- hasDetailedCounts :: SimplCount -> Bool
- data Tick
  - = PreInlineUnconditionally Id
  - | PostInlineUnconditionally Id
  - | UnfoldingDone Id
  - | RuleFired FastString
  - | LetFloatFromLet
  - | EtaExpansion Id
  - | EtaReduction Id
  - | BetaReduction Id
  - | CaseOfCase Id
  - | KnownBranch Id
  - | CaseMerge Id
  - | AltMerge Id
  - | CaseElim Id
  - | CaseIdentity Id
  - | FillInCaseDefault Id
  - | BottomFound
  - | SimplifierDone
- data CoreM a
- runCoreM :: HscEnv -> RuleBase -> UniqSupply -> Module -> ModuleSet -> PrintUnqualified -> SrcSpan -> CoreM a -> IO (a, SimplCount)
- getHscEnv :: CoreM HscEnv
- getRuleBase :: CoreM RuleBase
- getModule :: HasModule m => m Module
- getDynFlags :: HasDynFlags m => m DynFlags
- getOrigNameCache :: CoreM OrigNameCache
- getPackageFamInstEnv :: CoreM PackageFamInstEnv
- getVisibleOrphanMods :: CoreM ModuleSet
- getPrintUnqualified :: CoreM PrintUnqualified
- getSrcSpanM :: CoreM SrcSpan
- addSimplCount :: SimplCount -> CoreM ()
- liftIO :: MonadIO m => IO a -> m a
- liftIOWithCount :: IO (SimplCount, a) -> CoreM a
- liftIO1 :: MonadIO m => (a -> IO b) -> a -> m b
- liftIO2 :: MonadIO m => (a -> b -> IO c) -> a -> b -> m c
- liftIO3 :: MonadIO m => (a -> b -> c -> IO d) -> a -> b -> c -> m d
- liftIO4 :: MonadIO m => (a -> b -> c -> d -> IO e) -> a -> b -> c -> d -> m e
- reinitializeGlobals :: CoreM ()
- getAnnotations :: Typeable a => ([Word8] -> a) -> ModGuts -> CoreM (UniqFM [a])
- getFirstAnnotations :: Typeable a => ([Word8] -> a) -> ModGuts -> CoreM (UniqFM a)
- putMsg :: SDoc -> CoreM ()
- putMsgS :: String -> CoreM ()
- errorMsg :: SDoc -> CoreM ()
- errorMsgS :: String -> CoreM ()
- warnMsg :: SDoc -> CoreM ()
- fatalErrorMsg :: SDoc -> CoreM ()
- fatalErrorMsgS :: String -> CoreM ()
- debugTraceMsg :: SDoc -> CoreM ()
- debugTraceMsgS :: String -> CoreM ()
- dumpIfSet_dyn :: DumpFlag -> String -> SDoc -> CoreM ()
- thNameToGhcName :: Name -> CoreM (Maybe Name)

# Configuration of the core-to-core passes

data CoreToDo #

Constructors

CoreDoSimplify Int SimplMode |
CoreDoPluginPass String PluginPass |
CoreDoFloatInwards |
CoreDoFloatOutwards FloatOutSwitches |
CoreLiberateCase |
CoreDoPrintCore |
CoreDoStaticArgs |
CoreDoCallArity |
CoreDoExitify |
CoreDoStrictness |
CoreDoWorkerWrapper |
CoreDoSpecialising |
CoreDoSpecConstr |
CoreCSE |
CoreDoRuleCheck CompilerPhase String |
CoreDoVectorisation |
CoreDoNothing |
CoreDoPasses [CoreToDo] |
CoreDesugar |
CoreDesugarOpt |
CoreTidy |
CorePrep |
CoreOccurAnal |

Instances

Outputable CoreToDo # |
Instance details Defined in CoreMonad Methods ppr :: CoreToDo -> SDoc # pprPrec :: Rational -> CoreToDo -> SDoc #

runWhen :: Bool -> CoreToDo -> CoreToDo #

runMaybe :: Maybe a -> (a -> CoreToDo) -> CoreToDo #

data SimplMode #

Constructors

SimplMode |
Fields sm_names :: [String] sm_phase :: CompilerPhase sm_dflags :: DynFlags sm_rules :: Bool sm_inline :: Bool sm_case_case :: Bool sm_eta_expand :: Bool

Instances

Outputable SimplMode # |
Instance details Defined in CoreMonad Methods ppr :: SimplMode -> SDoc # pprPrec :: Rational -> SimplMode -> SDoc #

data FloatOutSwitches #

Constructors

FloatOutSwitches |
Fields floatOutLambdas :: Maybe Int Just n = float lambdas to top level, if doing so will abstract over n or fewer value variables Nothing = float all lambdas to top level, regardless of how many free variables Just 0 is the vanilla case: float a lambda iff it has no free vars floatOutConstants :: Bool True = float constants to top level, even if they do not escape a lambda floatOutOverSatApps :: Bool True = float out over-saturated applications based on arity information. See Note [Floating over-saturated applications] in SetLevels floatToTopLevelOnly :: Bool Allow floating to the top level only.

Instances

Outputable FloatOutSwitches # |
Instance details Defined in CoreMonad Methods ppr :: FloatOutSwitches -> SDoc # pprPrec :: Rational -> FloatOutSwitches -> SDoc #

pprPassDetails :: CoreToDo -> SDoc #

# Plugins

type PluginPass = ModGuts -> CoreM ModGuts #

A description of the plugin pass itself

bindsOnlyPass :: (CoreProgram -> CoreM CoreProgram) -> ModGuts -> CoreM ModGuts #

# Counting

data SimplCount #

doSimplTick :: DynFlags -> Tick -> SimplCount -> SimplCount #

doFreeSimplTick :: Tick -> SimplCount -> SimplCount #

simplCountN :: SimplCount -> Int #

pprSimplCount :: SimplCount -> SDoc #

plusSimplCount :: SimplCount -> SimplCount -> SimplCount #

zeroSimplCount :: DynFlags -> SimplCount #

isZeroSimplCount :: SimplCount -> Bool #

hasDetailedCounts :: SimplCount -> Bool #

data Tick #

Constructors

PreInlineUnconditionally Id |
PostInlineUnconditionally Id |
UnfoldingDone Id |
RuleFired FastString |
LetFloatFromLet |
EtaExpansion Id |
EtaReduction Id |
BetaReduction Id |
CaseOfCase Id |
KnownBranch Id |
CaseMerge Id |
AltMerge Id |
CaseElim Id |
CaseIdentity Id |
FillInCaseDefault Id |
BottomFound |
SimplifierDone |

Instances

Eq Tick # |
Instance details Defined in CoreMonad Methods (==) :: Tick -> Tick -> Bool # (/=) :: Tick -> Tick -> Bool #
Ord Tick # |
Instance details Defined in CoreMonad Methods compare :: Tick -> Tick -> Ordering # (<) :: Tick -> Tick -> Bool # (<=) :: Tick -> Tick -> Bool # (>) :: Tick -> Tick -> Bool # (>=) :: Tick -> Tick -> Bool # max :: Tick -> Tick -> Tick # min :: Tick -> Tick -> Tick #
Outputable Tick # |
Instance details Defined in CoreMonad Methods ppr :: Tick -> SDoc # pprPrec :: Rational -> Tick -> SDoc #

# The monad

data CoreM a #

The monad used by Core-to-Core passes to access common state, register simplification statistics and so on

Instances

Monad CoreM # |
Instance details Defined in CoreMonad Methods (>>=) :: CoreM a -> (a -> CoreM b) -> CoreM b Source # (>>) :: CoreM a -> CoreM b -> CoreM b Source # return :: a -> CoreM a Source # fail :: String -> CoreM a Source #
Functor CoreM # |
Instance details Defined in CoreMonad Methods fmap :: (a -> b) -> CoreM a -> CoreM b Source # (<$) :: a -> CoreM b -> CoreM a Source #
Applicative CoreM # |
Instance details Defined in CoreMonad Methods pure :: a -> CoreM a Source # (<*>) :: CoreM (a -> b) -> CoreM a -> CoreM b Source # liftA2 :: (a -> b -> c) -> CoreM a -> CoreM b -> CoreM c Source # (*>) :: CoreM a -> CoreM b -> CoreM b Source # (<*) :: CoreM a -> CoreM b -> CoreM a Source #
MonadIO CoreM # |
Instance details Defined in CoreMonad Methods liftIO :: IO a -> CoreM a Source #
Alternative CoreM # |
Instance details Defined in CoreMonad Methods empty :: CoreM a Source # (<|>) :: CoreM a -> CoreM a -> CoreM a Source # some :: CoreM a -> CoreM [a] Source # many :: CoreM a -> CoreM [a] Source #
MonadPlus CoreM # |
Instance details Defined in CoreMonad Methods mzero :: CoreM a Source # mplus :: CoreM a -> CoreM a -> CoreM a Source #
MonadUnique CoreM # |
Instance details Defined in CoreMonad Methods getUniqueSupplyM :: CoreM UniqSupply # getUniqueM :: CoreM Unique # getUniquesM :: CoreM [Unique] #
HasModule CoreM # |
Instance details Defined in CoreMonad Methods getModule :: CoreM Module #
HasDynFlags CoreM # |
Instance details Defined in CoreMonad Methods getDynFlags :: CoreM DynFlags #
MonadThings CoreM # |
Instance details Defined in CoreMonad Methods lookupThing :: Name -> CoreM TyThing # lookupId :: Name -> CoreM Id # lookupDataCon :: Name -> CoreM DataCon # lookupTyCon :: Name -> CoreM TyCon #

runCoreM :: HscEnv -> RuleBase -> UniqSupply -> Module -> ModuleSet -> PrintUnqualified -> SrcSpan -> CoreM a -> IO (a, SimplCount) #

## Reading from the monad

getHscEnv :: CoreM HscEnv #

getRuleBase :: CoreM RuleBase #

getModule :: HasModule m => m Module #

getDynFlags :: HasDynFlags m => m DynFlags #

getOrigNameCache :: CoreM OrigNameCache #

The original name cache is the current mapping from `Module` and `OccName` to a compiler-wide unique `Name`

getPackageFamInstEnv :: CoreM PackageFamInstEnv #

getVisibleOrphanMods :: CoreM ModuleSet #

getPrintUnqualified :: CoreM PrintUnqualified #

getSrcSpanM :: CoreM SrcSpan #

## Writing to the monad

addSimplCount :: SimplCount -> CoreM () #

## Lifting into the monad

liftIO :: MonadIO m => IO a -> m a Source #

Lift a computation from the `IO` monad.

liftIOWithCount :: IO (SimplCount, a) -> CoreM a #

Lift an `IO` operation into `CoreM` while consuming its `SimplCount`

liftIO1 :: MonadIO m => (a -> IO b) -> a -> m b #

Lift an `IO` operation with 1 argument into another monad

liftIO2 :: MonadIO m => (a -> b -> IO c) -> a -> b -> m c #

Lift an `IO` operation with 2 arguments into another monad

liftIO3 :: MonadIO m => (a -> b -> c -> IO d) -> a -> b -> c -> m d #

Lift an `IO` operation with 3 arguments into another monad

liftIO4 :: MonadIO m => (a -> b -> c -> d -> IO e) -> a -> b -> c -> d -> m e #

Lift an `IO` operation with 4 arguments into another monad

## Global initialization

reinitializeGlobals :: CoreM () #

Deprecated: It is not necessary to call reinitializeGlobals. Since GHC 8.2, this function is a no-op and will be removed in GHC 8.4

## Dealing with annotations

getAnnotations :: Typeable a => ([Word8] -> a) -> ModGuts -> CoreM (UniqFM [a]) #

Get all annotations of a given type. This happens lazily, that is no deserialization will take place until the [a] is actually demanded and the [a] can also be empty (the UniqFM is not filtered).

This should be done once at the start of a Core-to-Core pass that uses annotations.

See Note [Annotations]

getFirstAnnotations :: Typeable a => ([Word8] -> a) -> ModGuts -> CoreM (UniqFM a) #

Get at most one annotation of a given type per Unique.

## Screen output

putMsg :: SDoc -> CoreM () #

Output a message to the screen

putMsgS :: String -> CoreM () #

Output a String message to the screen

errorMsg :: SDoc -> CoreM () #

Output an error to the screen. Does not cause the compiler to die.

errorMsgS :: String -> CoreM () #

Output an error to the screen. Does not cause the compiler to die.

warnMsg :: SDoc -> CoreM () #

fatalErrorMsg :: SDoc -> CoreM () #

Output a fatal error to the screen. Does not cause the compiler to die.

fatalErrorMsgS :: String -> CoreM () #

Output a fatal error to the screen. Does not cause the compiler to die.

debugTraceMsg :: SDoc -> CoreM () #

Outputs a debugging message at verbosity level of `-v` or higher

debugTraceMsgS :: String -> CoreM () #

Output a string debugging message at verbosity level of `-v` or higher

dumpIfSet_dyn :: DumpFlag -> String -> SDoc -> CoreM () #

Show some labelled `SDoc` if a particular flag is set or at a verbosity level of `-v -ddump-most` or higher

# Getting `Name`s

thNameToGhcName :: Name -> CoreM (Maybe Name) #

Attempt to convert a Template Haskell name to one that GHC can understand. Original TH names such as those you get when you use the `'foo` syntax will be translated to their equivalent GHC name exactly. Qualified or unqualified TH names will be dynamically bound to names in the module being compiled, if possible. Exact TH names will be bound to the name they represent, exactly.