GHC.Types.Unique.DSM

ghc-lib-parser-9.14.1.20251220: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Types.Unique.DSM

Contents

- Threading a deterministic supply
  - UniqDSM and DUniqSupply operations
  - Tag operations
- A transfomer threading a deterministic supply
  - UniqDSMT operations
  - Tags
- Monad class for deterministic supply threading

Synopsis

- data DUniqSupply
- data UniqDSM result where
  - pattern UDSM :: (DUniqSupply -> DUniqResult a) -> UniqDSM a
- type DUniqResult result = (# result, DUniqSupply #)
- pattern DUniqResult :: a -> DUniqSupply -> (# a, DUniqSupply #)
- getUniqueDSM :: UniqDSM Unique
- runUniqueDSM :: DUniqSupply -> UniqDSM a -> (a, DUniqSupply)
- takeUniqueFromDSupply :: DUniqSupply -> (Unique, DUniqSupply)
- initDUniqSupply :: Char -> Word64 -> DUniqSupply
- newTagDUniqSupply :: Char -> DUniqSupply -> DUniqSupply
- getTagDUniqSupply :: DUniqSupply -> Char
- data UniqDSMT (m :: Type -> Type) result where
  - pattern UDSMT :: (DUniqSupply -> m (result, DUniqSupply)) -> UniqDSMT m result
- runUDSMT :: DUniqSupply -> UniqDSMT m a -> m (a, DUniqSupply)
- withDUS :: (DUniqSupply -> IO (a, DUniqSupply)) -> UniqDSMT IO a
- hoistUDSMT :: (forall x. m x -> n x) -> UniqDSMT m a -> UniqDSMT n a
- liftUDSMT :: Functor m => m a -> UniqDSMT m a
- setTagUDSMT :: forall (m :: Type -> Type) a. Monad m => Char -> UniqDSMT m a -> UniqDSMT m a
- class Monad m => MonadGetUnique (m :: Type -> Type) where
  - getUniqueM :: m Unique
- class Monad m => MonadUniqDSM (m :: Type -> Type) where
  - liftUniqDSM :: UniqDSM a -> m a

# Threading a deterministic supply

data DUniqSupply #

data UniqDSM result where #

A monad which just gives the ability to obtain `Unique`s deterministically. There's no splitting.

Bundled Patterns

pattern UDSM :: (DUniqSupply -> DUniqResult a) -> UniqDSM a |

#### Instances

Instances details

Applicative UniqDSM # |
Instance details Defined in GHC.Types.Unique.DSM Methods pure :: a -> UniqDSM a # (<*>) :: UniqDSM (a -> b) -> UniqDSM a -> UniqDSM b # liftA2 :: (a -> b -> c) -> UniqDSM a -> UniqDSM b -> UniqDSM c # (*>) :: UniqDSM a -> UniqDSM b -> UniqDSM b # (<*) :: UniqDSM a -> UniqDSM b -> UniqDSM a #
Functor UniqDSM # |
Instance details Defined in GHC.Types.Unique.DSM Methods fmap :: (a -> b) -> UniqDSM a -> UniqDSM b # (<$) :: a -> UniqDSM b -> UniqDSM a #
Monad UniqDSM # |
Instance details Defined in GHC.Types.Unique.DSM Methods (>>=) :: UniqDSM a -> (a -> UniqDSM b) -> UniqDSM b # (>>) :: UniqDSM a -> UniqDSM b -> UniqDSM b # return :: a -> UniqDSM a #
MonadFix UniqDSM # |
Instance details Defined in GHC.Types.Unique.DSM Methods mfix :: (a -> UniqDSM a) -> UniqDSM a #
MonadGetUnique UniqDSM # |
Instance details Defined in GHC.Types.Unique.DSM Methods getUniqueM :: UniqDSM Unique #
MonadUniqDSM UniqDSM # |
Instance details Defined in GHC.Types.Unique.DSM Methods liftUniqDSM :: UniqDSM a -> UniqDSM a #

type DUniqResult result = (# result, DUniqSupply #) #

pattern DUniqResult :: a -> DUniqSupply -> (# a, DUniqSupply #) #

## UniqDSM and DUniqSupply operations

getUniqueDSM :: UniqDSM Unique #

runUniqueDSM :: DUniqSupply -> UniqDSM a -> (a, DUniqSupply) #

takeUniqueFromDSupply :: DUniqSupply -> (Unique, DUniqSupply) #

initDUniqSupply :: Char -> Word64 -> DUniqSupply #

Initialize a deterministic unique supply with the given Tag and initial unique.

## Tag operations

newTagDUniqSupply :: Char -> DUniqSupply -> DUniqSupply #

Set the tag of uniques generated from this deterministic unique supply

getTagDUniqSupply :: DUniqSupply -> Char #

Get the tag uniques generated from this deterministic unique supply would have

# A transfomer threading a deterministic supply

data UniqDSMT (m :: Type -> Type) result where #

Transformer version of `UniqDSM` to use when threading a deterministic uniq supply over a Monad. Specifically, it is used in the `Stream` of Cmm decls.

Bundled Patterns

pattern UDSMT :: (DUniqSupply -> m (result, DUniqSupply)) -> UniqDSMT m result |

#### Instances

Instances details

MonadIO m => MonadIO (UniqDSMT m) # |
Instance details Defined in GHC.Types.Unique.DSM Methods liftIO :: IO a -> UniqDSMT m a #
Monad m => Applicative (UniqDSMT m) # |
Instance details Defined in GHC.Types.Unique.DSM Methods pure :: a -> UniqDSMT m a # (<*>) :: UniqDSMT m (a -> b) -> UniqDSMT m a -> UniqDSMT m b # liftA2 :: (a -> b -> c) -> UniqDSMT m a -> UniqDSMT m b -> UniqDSMT m c # (*>) :: UniqDSMT m a -> UniqDSMT m b -> UniqDSMT m b # (<*) :: UniqDSMT m a -> UniqDSMT m b -> UniqDSMT m a #
Functor m => Functor (UniqDSMT m) # |
Instance details Defined in GHC.Types.Unique.DSM Methods fmap :: (a -> b) -> UniqDSMT m a -> UniqDSMT m b # (<$) :: a -> UniqDSMT m b -> UniqDSMT m a #
Monad m => Monad (UniqDSMT m) # |
Instance details Defined in GHC.Types.Unique.DSM Methods (>>=) :: UniqDSMT m a -> (a -> UniqDSMT m b) -> UniqDSMT m b # (>>) :: UniqDSMT m a -> UniqDSMT m b -> UniqDSMT m b # return :: a -> UniqDSMT m a #
Monad m => MonadGetUnique (UniqDSMT m) # |
Instance details Defined in GHC.Types.Unique.DSM Methods getUniqueM :: UniqDSMT m Unique #
Monad m => MonadUniqDSM (UniqDSMT m) # |
Instance details Defined in GHC.Types.Unique.DSM Methods liftUniqDSM :: UniqDSM a -> UniqDSMT m a #

## UniqDSMT operations

runUDSMT :: DUniqSupply -> UniqDSMT m a -> m (a, DUniqSupply) #

Like `runUniqueDSM` but for `UniqDSMT`

withDUS :: (DUniqSupply -> IO (a, DUniqSupply)) -> UniqDSMT IO a #

Lift an IO action that depends on, and threads through, a unique supply into UniqDSMT IO.

hoistUDSMT :: (forall x. m x -> n x) -> UniqDSMT m a -> UniqDSMT n a #

Change the monad underyling an applied `UniqDSMT`, i.e. transform a `UniqDSMT m` into a `UniqDSMT n` given `m ~> n`.

liftUDSMT :: Functor m => m a -> UniqDSMT m a #

Lift a monadic action `m a` into an `UniqDSMT m a`

## Tags

setTagUDSMT #

Arguments

:: forall (m :: Type -> Type) a. Monad m |
=> Char | Tag
-> UniqDSMT m a |
-> UniqDSMT m a |

Set the tag of the running `UniqDSMT` supply to the given tag and run an action with it. All uniques produced in the given action will use this tag, until the tag is changed again.

# Monad class for deterministic supply threading

class Monad m => MonadGetUnique (m :: Type -> Type) where #

Get a unique from a monad that can access a unique supply.

Crucially, because `MonadGetUnique` doesn't allow you to get the `UniqSupply` (unlike `MonadUnique`), an instance such as `UniqDSM` can use a deterministic unique supply to return deterministic uniques without allowing for the `UniqSupply` to be shared.

Methods

getUniqueM :: m Unique #

#### Instances

Instances details

MonadGetUnique UniqDSM # |
Instance details Defined in GHC.Types.Unique.DSM Methods getUniqueM :: UniqDSM Unique #
MonadGetUnique UniqSM # |
Instance details Defined in GHC.Types.Unique.DSM Methods getUniqueM :: UniqSM Unique #
Monad m => MonadGetUnique (UniqDSMT m) # |
Instance details Defined in GHC.Types.Unique.DSM Methods getUniqueM :: UniqDSMT m Unique #

class Monad m => MonadUniqDSM (m :: Type -> Type) where #

Methods

liftUniqDSM :: UniqDSM a -> m a #

Lift a pure `UniqDSM` action into a `MonadUniqDSM` such as `UniqDSMT`

#### Instances

Instances details

MonadUniqDSM UniqDSM # |
Instance details Defined in GHC.Types.Unique.DSM Methods liftUniqDSM :: UniqDSM a -> UniqDSM a #
Monad m => MonadUniqDSM (UniqDSMT m) # |
Instance details Defined in GHC.Types.Unique.DSM Methods liftUniqDSM :: UniqDSM a -> UniqDSMT m a #