ghc-9.6.3: The GHC API

Safe Haskell | Safe-Inferred
Language | Haskell2010

GHC.Types.Unique.Supply

Contents

- Main data type
  - Operations on supplies
- Unique supply monad and its abstraction
  - Operations on the monad
- Set supply strategy

Synopsis

- data UniqSupply
- uniqFromSupply :: UniqSupply -> Unique
- uniqsFromSupply :: UniqSupply -> [Unique]
- takeUniqFromSupply :: UniqSupply -> (Unique, UniqSupply)
- uniqFromMask :: Char -> IO Unique
- mkSplitUniqSupply :: Char -> IO UniqSupply
- splitUniqSupply :: UniqSupply -> (UniqSupply, UniqSupply)
- listSplitUniqSupply :: UniqSupply -> [UniqSupply]
- data UniqSM result
- class Monad m => MonadUnique m where
  - getUniqueSupplyM :: m UniqSupply
  - getUniqueM :: m Unique
  - getUniquesM :: m [Unique]
- initUs :: UniqSupply -> UniqSM a -> (a, UniqSupply)
- initUs_ :: UniqSupply -> UniqSM a -> a
- initUniqSupply :: Word -> Int -> IO ()

# Main data type

data UniqSupply Source #

Unique Supply

A value of type `UniqSupply` is unique, and it can supply one distinct `Unique`. Also, from the supply, one can also manufacture an arbitrary number of further `UniqueSupply` values, which will be distinct from the first and from all others.

## Operations on supplies

uniqFromSupply :: UniqSupply -> Unique Source #

Obtain the `Unique` from this particular `UniqSupply`

uniqsFromSupply :: UniqSupply -> [Unique] Source #

Obtain an infinite list of `Unique` that can be generated by constant splitting of the supply

takeUniqFromSupply :: UniqSupply -> (Unique, UniqSupply) Source #

Obtain the `Unique` from this particular `UniqSupply`, and a new supply

uniqFromMask :: Char -> IO Unique Source #

mkSplitUniqSupply :: Char -> IO UniqSupply Source #

Create a unique supply out of thin air. The "mask" (Char) supplied is purely cosmetic, making it easier to figure out where a Unique was born. See Note [Uniques and masks].

The payload part of the Uniques allocated from this UniqSupply are guaranteed distinct wrt all other supplies, regardless of their "mask". This is achieved by allocating the payload part from a single source of Uniques, namely `genSym`, shared across all UniqSupply's.

splitUniqSupply :: UniqSupply -> (UniqSupply, UniqSupply) Source #

Build two `UniqSupply` from a single one, each of which can supply its own `Unique`.

listSplitUniqSupply :: UniqSupply -> [UniqSupply] Source #

Create an infinite list of `UniqSupply` from a single one

# Unique supply monad and its abstraction

data UniqSM result Source #

A monad which just gives the ability to obtain `Unique`s

#### Instances

Instances details

MonadFail UniqSM Source # |
Instance details Defined in GHC.Types.Unique.Supply Methods fail :: String -> UniqSM a Source #
MonadFix UniqSM Source # |
Instance details Defined in GHC.Types.Unique.Supply Methods mfix :: (a -> UniqSM a) -> UniqSM a Source #
Applicative UniqSM Source # |
Instance details Defined in GHC.Types.Unique.Supply Methods pure :: a -> UniqSM a Source # (<*>) :: UniqSM (a -> b) -> UniqSM a -> UniqSM b Source # liftA2 :: (a -> b -> c) -> UniqSM a -> UniqSM b -> UniqSM c Source # (*>) :: UniqSM a -> UniqSM b -> UniqSM b Source # (<*) :: UniqSM a -> UniqSM b -> UniqSM a Source #
Functor UniqSM Source # |
Instance details Defined in GHC.Types.Unique.Supply Methods fmap :: (a -> b) -> UniqSM a -> UniqSM b Source # (<$) :: a -> UniqSM b -> UniqSM a Source #
Monad UniqSM Source # |
Instance details Defined in GHC.Types.Unique.Supply Methods (>>=) :: UniqSM a -> (a -> UniqSM b) -> UniqSM b Source # (>>) :: UniqSM a -> UniqSM b -> UniqSM b Source # return :: a -> UniqSM a Source #
MonadUnique UniqSM Source # |
Instance details Defined in GHC.Types.Unique.Supply Methods getUniqueSupplyM :: UniqSM UniqSupply Source # getUniqueM :: UniqSM Unique Source # getUniquesM :: UniqSM [Unique] Source #

class Monad m => MonadUnique m where Source #

A monad for generating unique identifiers

Minimal complete definition

getUniqueSupplyM

Methods

getUniqueSupplyM :: m UniqSupply Source #

Get a new UniqueSupply

getUniqueM :: m Unique Source #

Get a new unique identifier

getUniquesM :: m [Unique] Source #

Get an infinite list of new unique identifiers

#### Instances

Instances details

MonadUnique NatM Source # |
Instance details Defined in GHC.CmmToAsm.Monad Methods getUniqueSupplyM :: NatM UniqSupply Source # getUniqueM :: NatM Unique Source # getUniquesM :: NatM [Unique] Source #
MonadUnique LlvmM Source # |
Instance details Defined in GHC.CmmToLlvm.Base Methods getUniqueSupplyM :: LlvmM UniqSupply Source # getUniqueM :: LlvmM Unique Source # getUniquesM :: LlvmM [Unique] Source #
MonadUnique CoreM Source # |
Instance details Defined in GHC.Core.Opt.Monad Methods getUniqueSupplyM :: CoreM UniqSupply Source # getUniqueM :: CoreM Unique Source # getUniquesM :: CoreM [Unique] Source #
MonadUnique SimplM Source # |
Instance details Defined in GHC.Core.Opt.Simplify.Monad Methods getUniqueSupplyM :: SimplM UniqSupply Source # getUniqueM :: SimplM Unique Source # getUniquesM :: SimplM [Unique] Source #
MonadUnique NullCollapseViz Source # |
Instance details Defined in GHC.Data.Graph.Collapse Methods getUniqueSupplyM :: NullCollapseViz UniqSupply Source # getUniqueM :: NullCollapseViz Unique Source # getUniquesM :: NullCollapseViz [Unique] Source #
MonadUnique LiftM Source # |
Instance details Defined in GHC.Stg.Lift.Monad Methods getUniqueSupplyM :: LiftM UniqSupply Source # getUniqueM :: LiftM Unique Source # getUniquesM :: LiftM [Unique] Source #
MonadUnique CmmParse Source # |
Instance details Defined in GHC.StgToCmm.ExtCode Methods getUniqueSupplyM :: CmmParse UniqSupply Source # getUniqueM :: CmmParse Unique Source # getUniquesM :: CmmParse [Unique] Source #
MonadUnique FCode Source # |
Instance details Defined in GHC.StgToCmm.Monad Methods getUniqueSupplyM :: FCode UniqSupply Source # getUniqueM :: FCode Unique Source # getUniquesM :: FCode [Unique] Source #
MonadUnique TcS Source # |
Instance details Defined in GHC.Tc.Solver.Monad Methods getUniqueSupplyM :: TcS UniqSupply Source # getUniqueM :: TcS Unique Source # getUniquesM :: TcS [Unique] Source #
MonadUnique UniqSM Source # |
Instance details Defined in GHC.Types.Unique.Supply Methods getUniqueSupplyM :: UniqSM UniqSupply Source # getUniqueM :: UniqSM Unique Source # getUniquesM :: UniqSM [Unique] Source #
MonadUnique (IOEnv (Env gbl lcl)) Source # |
Instance details Defined in GHC.Tc.Utils.Monad Methods getUniqueSupplyM :: IOEnv (Env gbl lcl) UniqSupply Source # getUniqueM :: IOEnv (Env gbl lcl) Unique Source # getUniquesM :: IOEnv (Env gbl lcl) [Unique] Source #

## Operations on the monad

initUs :: UniqSupply -> UniqSM a -> (a, UniqSupply) Source #

Run the `UniqSM` action, returning the final `UniqSupply`

initUs_ :: UniqSupply -> UniqSM a -> a Source #

Run the `UniqSM` action, discarding the final `UniqSupply`

# Set supply strategy

initUniqSupply :: Word -> Int -> IO () Source #