futhark-0.25.32: An optimising compiler for a functional, array-oriented language.

Safe Haskell | None
Language | GHC2021

Futhark.MonadFreshNames

Description

This module provides a monadic facility similar (and built on top of) Futhark.FreshNames. The removes the need for a (small) amount of boilerplate, at the cost of using some GHC extensions. The idea is that if your compiler pass runs in a monad that is an instance of `MonadFreshNames`, you can automatically use the name generation functions exported by this module.

Synopsis

- class Monad m => MonadFreshNames (m :: Type -> Type) where
  - getNameSource :: m VNameSource
  - putNameSource :: VNameSource -> m ()
- modifyNameSource :: MonadFreshNames m => (VNameSource -> (a, VNameSource)) -> m a
- newName :: MonadFreshNames m => VName -> m VName
- newNameFromString :: MonadFreshNames m => String -> m VName
- newVName :: MonadFreshNames m => String -> m VName
- newIdent :: MonadFreshNames m => String -> Type -> m Ident
- newIdent' :: MonadFreshNames m => (String -> String) -> Ident -> m Ident
- newParam :: MonadFreshNames m => String -> dec -> m (Param dec)
- data VNameSource
- blankNameSource :: VNameSource
- newNameSource :: Int -> VNameSource

# Documentation

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

A monad that stores a name source. The following is a good instance for a monad in which the only state is a `NameSource vn`:

     instance MonadFreshNames vn MyMonad where
       getNameSource = get
       putNameSource = put

Methods

getNameSource :: m VNameSource Source #

putNameSource :: VNameSource -> m () Source #

#### Instances

Instances details

MonadFreshNames ADM Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods getNameSource :: ADM VNameSource Source # putNameSource :: VNameSource -> ADM () Source #
MonadFreshNames InternaliseM Source # |
Instance details Defined in Futhark.Internalise.Monad Methods getNameSource :: InternaliseM VNameSource Source # putNameSource :: VNameSource -> InternaliseM () Source #
MonadFreshNames PassM Source # |
Instance details Defined in Futhark.Pass Methods getNameSource :: PassM VNameSource Source # putNameSource :: VNameSource -> PassM () Source #
MonadFreshNames FutharkM Source # |
Instance details Defined in Futhark.Pipeline Methods getNameSource :: FutharkM VNameSource Source # putNameSource :: VNameSource -> FutharkM () Source #
MonadFreshNames RenameM Source # |
Instance details Defined in Futhark.Transform.Rename Methods getNameSource :: RenameM VNameSource Source # putNameSource :: VNameSource -> RenameM () Source #
MonadFreshNames (RuleM rep) Source # |
Instance details Defined in Futhark.Optimise.Simplify.Rule Methods getNameSource :: RuleM rep VNameSource Source # putNameSource :: VNameSource -> RuleM rep () Source #
MonadFreshNames m => MonadFreshNames (MaybeT m) Source # |
Instance details Defined in Futhark.MonadFreshNames Methods getNameSource :: MaybeT m VNameSource Source # putNameSource :: VNameSource -> MaybeT m () Source #
MonadFreshNames (State RState) Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods getNameSource :: State RState VNameSource Source # putNameSource :: VNameSource -> State RState () Source #
MonadFreshNames m => MonadFreshNames (BuilderT rep m) Source # |
Instance details Defined in Futhark.Builder Methods getNameSource :: BuilderT rep m VNameSource Source # putNameSource :: VNameSource -> BuilderT rep m () Source #
MonadFreshNames (CompilerM op s) Source # |
Instance details Defined in Futhark.CodeGen.Backends.GenericC.Monad Methods getNameSource :: CompilerM op s VNameSource Source # putNameSource :: VNameSource -> CompilerM op s () Source #
MonadFreshNames (CompilerM op s) Source # |
Instance details Defined in Futhark.CodeGen.Backends.GenericPython Methods getNameSource :: CompilerM op s VNameSource Source # putNameSource :: VNameSource -> CompilerM op s () Source #
MonadFreshNames (SimpleM rep) Source # |
Instance details Defined in Futhark.Optimise.Simplify.Engine Methods getNameSource :: SimpleM rep VNameSource Source # putNameSource :: VNameSource -> SimpleM rep () Source #
MonadFreshNames (AllocM fromrep torep) Source # |
Instance details Defined in Futhark.Pass.ExplicitAllocations Methods getNameSource :: AllocM fromrep torep VNameSource Source # putNameSource :: VNameSource -> AllocM fromrep torep () Source #
MonadFreshNames m => MonadFreshNames (DistNestT rep m) Source # |
Instance details Defined in Futhark.Pass.ExtractKernels.DistributeNests Methods getNameSource :: DistNestT rep m VNameSource Source # putNameSource :: VNameSource -> DistNestT rep m () Source #
MonadFreshNames m => MonadFreshNames (ExceptT e m) Source # |
Instance details Defined in Futhark.MonadFreshNames Methods getNameSource :: ExceptT e m VNameSource Source # putNameSource :: VNameSource -> ExceptT e m () Source #
MonadFreshNames m => MonadFreshNames (ReaderT s m) Source # |
Instance details Defined in Futhark.MonadFreshNames Methods getNameSource :: ReaderT s m VNameSource Source # putNameSource :: VNameSource -> ReaderT s m () Source #
Monad im => MonadFreshNames (StateT VNameSource im) Source # |
Instance details Defined in Futhark.MonadFreshNames Methods getNameSource :: StateT VNameSource im VNameSource Source # putNameSource :: VNameSource -> StateT VNameSource im () Source #
Monad im => MonadFreshNames (StateT VNameSource im) Source # |
Instance details Defined in Futhark.MonadFreshNames Methods getNameSource :: StateT VNameSource im VNameSource Source # putNameSource :: VNameSource -> StateT VNameSource im () Source #
(MonadFreshNames m, Monoid s) => MonadFreshNames (WriterT s m) Source # |
Instance details Defined in Futhark.MonadFreshNames Methods getNameSource :: WriterT s m VNameSource Source # putNameSource :: VNameSource -> WriterT s m () Source #
(MonadFreshNames m, Monoid s) => MonadFreshNames (WriterT s m) Source # |
Instance details Defined in Futhark.MonadFreshNames Methods getNameSource :: WriterT s m VNameSource Source # putNameSource :: VNameSource -> WriterT s m () Source #
MonadFreshNames (ImpM rep r op) Source # |
Instance details Defined in Futhark.CodeGen.ImpGen Methods getNameSource :: ImpM rep r op VNameSource Source # putNameSource :: VNameSource -> ImpM rep r op () Source #
(Monad im, Monoid w) => MonadFreshNames (RWST r w VNameSource im) Source # |
Instance details Defined in Futhark.MonadFreshNames Methods getNameSource :: RWST r w VNameSource im VNameSource Source # putNameSource :: VNameSource -> RWST r w VNameSource im () Source #
(Monad im, Monoid w) => MonadFreshNames (RWST r w VNameSource im) Source # |
Instance details Defined in Futhark.MonadFreshNames Methods getNameSource :: RWST r w VNameSource im VNameSource Source # putNameSource :: VNameSource -> RWST r w VNameSource im () Source #

modifyNameSource :: MonadFreshNames m => (VNameSource -> (a, VNameSource)) -> m a Source #

Run a computation needing a fresh name source and returning a new one, using `getNameSource` and `putNameSource` before and after the computation.

newName :: MonadFreshNames m => VName -> m VName Source #

Produce a fresh name, using the given name as a template.

newNameFromString :: MonadFreshNames m => String -> m VName Source #

As `newName`, but takes a `String` for the name template.

newVName :: MonadFreshNames m => String -> m VName Source #

Produce a fresh `VName`, using the given base name as a template.

newIdent :: MonadFreshNames m => String -> Type -> m Ident Source #

Produce a fresh `Ident`, using the given name as a template.

newIdent' :: MonadFreshNames m => (String -> String) -> Ident -> m Ident Source #

Produce a fresh `Ident`, using the given `Ident` as a template, but possibly modifying the name.

newParam :: MonadFreshNames m => String -> dec -> m (Param dec) Source #

Produce a fresh `Param`, using the given name as a template.

data VNameSource Source #

A name source is conceptually an infinite sequence of names with no repeating entries. In practice, when asked for a name, the name source will return the name along with a new name source, which should then be used in place of the original.

The `Ord` instance is based on how many names have been extracted from the name source.

#### Instances

Instances details

Monoid VNameSource Source # |
Instance details Defined in Futhark.FreshNames Methods mempty :: VNameSource Source # mappend :: VNameSource -> VNameSource -> VNameSource Source # mconcat :: [VNameSource] -> VNameSource Source #
Semigroup VNameSource Source # |
Instance details Defined in Futhark.FreshNames Methods (<>) :: VNameSource -> VNameSource -> VNameSource Source # sconcat :: NonEmpty VNameSource -> VNameSource Source # stimes :: Integral b => b -> VNameSource -> VNameSource Source #
Eq VNameSource Source # |
Instance details Defined in Futhark.FreshNames Methods (==) :: VNameSource -> VNameSource -> Bool Source # (/=) :: VNameSource -> VNameSource -> Bool Source #
Ord VNameSource Source # |

Instance details

Defined in Futhark.FreshNames

Methods

compare :: VNameSource -> VNameSource -> Ordering Source #

(<) :: VNameSource -> VNameSource -> Bool Source #

(<=) :: VNameSource -> VNameSource -> Bool Source #

(>) :: VNameSource -> VNameSource -> Bool Source #

(>=) :: VNameSource -> VNameSource -> Bool Source #

max :: VNameSource -> VNameSource -> VNameSource Source #

min :: VNameSource -> VNameSource -> VNameSource Source #

Lift VNameSource Source # |
Instance details Defined in Futhark.FreshNames Methods lift :: Quote m => VNameSource -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => VNameSource -> Code m VNameSource Source #
Monad im => MonadFreshNames (StateT VNameSource im) Source # |
Instance details Defined in Futhark.MonadFreshNames Methods getNameSource :: StateT VNameSource im VNameSource Source # putNameSource :: VNameSource -> StateT VNameSource im () Source #
Monad im => MonadFreshNames (StateT VNameSource im) Source # |
Instance details Defined in Futhark.MonadFreshNames Methods getNameSource :: StateT VNameSource im VNameSource Source # putNameSource :: VNameSource -> StateT VNameSource im () Source #
MonadState (VNameSource, Bool, Certs) (SimpleM rep) Source # |
Instance details Defined in Futhark.Optimise.Simplify.Engine Methods get :: SimpleM rep (VNameSource, Bool, Certs) Source # put :: (VNameSource, Bool, Certs) -> SimpleM rep () Source # state :: ((VNameSource, Bool, Certs) -> (a, (VNameSource, Bool, Certs))) -> SimpleM rep a Source #
(Monad im, Monoid w) => MonadFreshNames (RWST r w VNameSource im) Source # |
Instance details Defined in Futhark.MonadFreshNames Methods getNameSource :: RWST r w VNameSource im VNameSource Source # putNameSource :: VNameSource -> RWST r w VNameSource im () Source #
(Monad im, Monoid w) => MonadFreshNames (RWST r w VNameSource im) Source # |
Instance details Defined in Futhark.MonadFreshNames Methods getNameSource :: RWST r w VNameSource im VNameSource Source # putNameSource :: VNameSource -> RWST r w VNameSource im () Source #

blankNameSource :: VNameSource Source #

A blank name source.

newNameSource :: Int -> VNameSource Source #

A new name source that starts counting from the given number.