HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleghc-9.10.3GHC2021

GHC.Core.Opt.Monad

  • 2 types
  • 23 values
  • Packageghc-9.10.3
  • Exports28
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceMonad.hs

Types used in core-to-core passes

1 declaration
datadata FloatOutSwitches
#

Constructors

  • FloatOutSwitches
    • 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 GHC.Core.Opt.SetLevels

    • floatToTopLevelOnly :: Bool

      Allow floating to the top level only.

Instances1Outputable

The monad

4 declarations
newtypenewtype CoreM a
#

The monad used by Core-to-Core passes to register simplification statistics. Also used to have common state (in the form of UniqueSupply) for generating Uniques.

Instances11Monad, Functor, Applicative, Alternative, MonadPlus, MonadIO, …

Reading from the monad

Writing to the monad

Lifting into the monad

methodliftIO :: IO a -> m a
#

Lift a computation from the IO monad. This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations (i.e. IO is the base monad for the stack).

Example
import Control.Monad.Trans.State -- from the "transformers" library

printState :: Show s => StateT s IO ()
printState = do
  state <- get
  liftIO $ print state

Had we omitted liftIO, we would have ended up with this error:

• Couldn't match type ‘IO’ with ‘StateT s IO’
 Expected type: StateT s IO ()
   Actual type: IO ()

The important part here is the mismatch between StateT s IO () and IO ().

Luckily, we know of a function that takes an IO a and returns an (m a): liftIO, enabling us to run the program and see the expected results:

> evalStateT printState "hello"
"hello"

> evalStateT printState 3
3

Dealing with annotations

valuegetAnnotations
  1. :: Typeable a
  2. => [Word8] -> a
  3. -> ModGuts
  4. -> CoreM (ModuleEnv [a], NameEnv [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]

Screen output

valueerrorMsg :: SDoc -> CoreM ()
#

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

valuefatalErrorMsg :: SDoc -> CoreM ()
#

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