Copyright | (C) 2012-2016, University of Twente |
---|---|
License | BSD2 (see the file LICENSE) |
Maintainer | Christiaan Baaij <christiaan.baaij@gmail.com> |
Safe Haskell | None |
Language | Haskell2010 |
Utilities for rewriting: e.g. inlining, specialisation, etc.
- zoomExtra :: State extra a -> RewriteMonad extra a
- apply :: String -> Rewrite extra -> Rewrite extra
- runRewrite :: String -> Rewrite extra -> Term -> RewriteMonad extra Term
- runRewriteSession :: RewriteEnv -> RewriteState extra -> RewriteMonad extra a -> a
- setChanged :: RewriteMonad extra ()
- changed :: a -> RewriteMonad extra a
- contextEnv :: [CoreContext] -> (Gamma, Delta)
- closestLetBinder :: [CoreContext] -> Maybe Id
- mkDerivedName :: [CoreContext] -> String -> String
- mkEnv :: [CoreContext] -> RewriteMonad extra (Gamma, Delta)
- mkTmBinderFor :: (Functor m, Fresh m, MonadUnique m) => HashMap TyConName TyCon -> String -> Term -> m (Id, Term)
- mkBinderFor :: (Functor m, Monad m, MonadUnique m, Fresh m) => HashMap TyConName TyCon -> String -> Either Term Type -> m (Either (Id, Term) (TyVar, Type))
- mkInternalVar :: (Functor m, Monad m, MonadUnique m) => String -> KindOrType -> m (Id, Term)
- inlineBinders :: (Term -> LetBinding -> RewriteMonad extra Bool) -> Rewrite extra
- isJoinPointIn :: Id -> Term -> Bool
- tailCalls :: Id -> Term -> Maybe Int
- substituteBinders :: [LetBinding] -> [LetBinding] -> Term -> ([LetBinding], Term)
- localFreeIds :: (Applicative f, Contravariant f) => RewriteMonad extra ((TmName -> f TmName) -> Term -> f Term)
- liftBinders :: (Term -> LetBinding -> RewriteMonad extra Bool) -> Rewrite extra
- liftBinding :: Gamma -> Delta -> LetBinding -> RewriteMonad extra LetBinding
- mkFunction :: TmName -> Term -> RewriteMonad extra (TmName, Type)
- addGlobalBind :: TmName -> Type -> Term -> RewriteMonad extra ()
- cloneVar :: TmName -> RewriteMonad extra TmName
- isLocalVar :: Term -> RewriteMonad extra Bool
- isUntranslatable :: Term -> RewriteMonad extra Bool
- isUntranslatableType :: Type -> RewriteMonad extra Bool
- isLambdaBodyCtx :: CoreContext -> Bool
- mkWildValBinder :: (Functor m, Monad m, MonadUnique m) => Type -> m Id
- mkSelectorCase :: (Functor m, Monad m, MonadUnique m, Fresh m) => String -> HashMap TyConName TyCon -> Term -> Int -> Int -> m Term
- specialise :: Lens' extra (Map (TmName, Int, Either Term Type) (TmName, Type)) -> Lens' extra (HashMap TmName Int) -> Lens' extra Int -> Rewrite extra
- specialise' :: Lens' extra (Map (TmName, Int, Either Term Type) (TmName, Type)) -> Lens' extra (HashMap TmName Int) -> Lens' extra Int -> [CoreContext] -> Term -> (Term, [Either Term Type]) -> Either Term Type -> RewriteMonad extra Term
- specArgBndrsAndVars :: [CoreContext] -> Either Term Type -> RewriteMonad extra ([Either Id TyVar], [Either Term Type])
Documentation
zoomExtra :: State extra a -> RewriteMonad extra a Source
Lift an action working in the _extra
state to the RewriteMonad
Record if a transformation is succesfully applied
:: String | Name of the transformation |
-> Rewrite extra | Transformation to perform |
-> Term | Term to transform |
-> RewriteMonad extra Term |
Perform a transformation on a Term
runRewriteSession :: RewriteEnv -> RewriteState extra -> RewriteMonad extra a -> a Source
Evaluate a RewriteSession to its inner monad
setChanged :: RewriteMonad extra () Source
Notify that a transformation has changed the expression
changed :: a -> RewriteMonad extra a Source
Identity function that additionally notifies that a transformation has changed the expression
contextEnv :: [CoreContext] -> (Gamma, Delta) Source
Create a type and kind context out of a transformation context
closestLetBinder :: [CoreContext] -> Maybe Id Source
mkDerivedName :: [CoreContext] -> String -> String Source
mkEnv :: [CoreContext] -> RewriteMonad extra (Gamma, Delta) Source
Create a complete type and kind context out of the global binders and the transformation context
:: (Functor m, Fresh m, MonadUnique m) | |
=> HashMap TyConName TyCon | TyCon cache |
-> String | Name of the new binder |
-> Term | Term to bind |
-> m (Id, Term) |
Make a new binder and variable reference for a term
:: (Functor m, Monad m, MonadUnique m, Fresh m) | |
=> HashMap TyConName TyCon | TyCon cache |
-> String | Name of the new binder |
-> Either Term Type | Type or Term to bind |
-> m (Either (Id, Term) (TyVar, Type)) |
Make a new binder and variable reference for either a term or a type
:: (Functor m, Monad m, MonadUnique m) | |
=> String | Name of the identifier |
-> KindOrType | |
-> m (Id, Term) |
Make a new, unique, identifier and corresponding variable reference
:: (Term -> LetBinding -> RewriteMonad extra Bool) | Property test |
-> Rewrite extra |
Inline the binders in a let-binding that have a certain property
Determine whether a binder is a join-point created for a complex case expression.
A join-point is when a local function only occurs in tail-call positions, and when it does, more than once.
Count the number of (only) tail calls of a function in an expression.
Nothing
indicates that the function was used in a non-tail call position.
:: [LetBinding] | Let-binders to substitute |
-> [LetBinding] | Let-binders where substitution takes place |
-> Term | Expression where substitution takes place |
-> ([LetBinding], Term) |
Substitute the RHS of the first set of Let-binders for references to the first set of Let-binders in: the second set of Let-binders and the additional term
localFreeIds :: (Applicative f, Contravariant f) => RewriteMonad extra ((TmName -> f TmName) -> Term -> f Term) Source
Calculate the local free variable of an expression: the free variables that are not bound in the global environment.
:: (Term -> LetBinding -> RewriteMonad extra Bool) | Property test |
-> Rewrite extra |
Lift the binders in a let-binding to a global function that have a certain property
liftBinding :: Gamma -> Delta -> LetBinding -> RewriteMonad extra LetBinding Source
Create a global function for a Let-binding and return a Let-binding where the RHS is a reference to the new global function applied to the free variables of the original RHS
:: TmName | Name of the function |
-> Term | Term bound to the function |
-> RewriteMonad extra (TmName, Type) | Name with a proper unique and the type of the function |
Make a global function for a name-term tuple
addGlobalBind :: TmName -> Type -> Term -> RewriteMonad extra () Source
Add a function to the set of global binders
cloneVar :: TmName -> RewriteMonad extra TmName Source
Create a new name out of the given name, but with another unique
isLocalVar :: Term -> RewriteMonad extra Bool Source
Test whether a term is a variable reference to a local binder
isUntranslatable :: Term -> RewriteMonad extra Bool Source
Determine if a term cannot be represented in hardware
isUntranslatableType :: Type -> RewriteMonad extra Bool Source
Determine if a type cannot be represented in hardware
isLambdaBodyCtx :: CoreContext -> Bool Source
Is the Context a Lambda/Term-abstraction context?
mkWildValBinder :: (Functor m, Monad m, MonadUnique m) => Type -> m Id Source
Make a binder that should not be referenced
:: (Functor m, Monad m, MonadUnique m, Fresh m) | |
=> String | Name of the caller of this function |
-> HashMap TyConName TyCon | TyCon cache |
-> Term | Subject of the case-composition |
-> Int | |
-> Int | |
-> m Term |
Make a case-decomposition that extracts a field out of a (Sum-of-)Product type
:: Lens' extra (Map (TmName, Int, Either Term Type) (TmName, Type)) | Lens into previous specialisations |
-> Lens' extra (HashMap TmName Int) | Lens into the specialisation history |
-> Lens' extra Int | Lens into the specialisation limit |
-> Rewrite extra |
Specialise an application on its argument
:: Lens' extra (Map (TmName, Int, Either Term Type) (TmName, Type)) | Lens into previous specialisations |
-> Lens' extra (HashMap TmName Int) | Lens into specialisation history |
-> Lens' extra Int | Lens into the specialisation limit |
-> [CoreContext] | |
-> Term | Original term |
-> (Term, [Either Term Type]) | Function part of the term, split into root and applied arguments |
-> Either Term Type | Argument to specialize on |
-> RewriteMonad extra Term |
Specialise an application on its argument
specArgBndrsAndVars :: [CoreContext] -> Either Term Type -> RewriteMonad extra ([Either Id TyVar], [Either Term Type]) Source
Create binders and variable references for free variables in specArg