Copyright | (C) 2012-2016 University of Twente 2016 Myrtle Software Ltd 2017 Google Inc. |
---|---|
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.
Synopsis
- 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 -> TmName
- mkEnv :: [CoreContext] -> RewriteMonad extra (Gamma, Delta)
- mkTmBinderFor :: (Fresh m, MonadUnique m) => HashMap TyConOccName TyCon -> Name a -> Term -> m (Id, Term)
- mkBinderFor :: (Monad m, MonadUnique m, Fresh m) => HashMap TyConOccName TyCon -> Name a -> Either Term Type -> m (Either (Id, Term) (TyVar, Type))
- mkInternalVar :: (Monad m, MonadUnique m) => TmName -> KindOrType -> m (Id, Term)
- inlineBinders :: (Term -> LetBinding -> RewriteMonad extra Bool) -> Rewrite extra
- isJoinPointIn :: Id -> Term -> Bool
- tailCalls :: Id -> Term -> Maybe Int
- isVoidWrapper :: Term -> Bool
- substituteBinders :: [LetBinding] -> [LetBinding] -> Term -> ([LetBinding], Term)
- localFreeIds :: (Applicative f, Contravariant f) => RewriteMonad extra ((TmOccName -> f TmOccName) -> Term -> f Term)
- inlineOrLiftBinders :: (LetBinding -> RewriteMonad extra Bool) -> (Term -> LetBinding -> RewriteMonad extra Bool) -> Rewrite extra
- liftBinding :: Gamma -> Delta -> LetBinding -> RewriteMonad extra LetBinding
- mkFunction :: TmName -> SrcSpan -> InlineSpec -> Term -> RewriteMonad extra (TmName, Type)
- addGlobalBind :: TmName -> Type -> SrcSpan -> InlineSpec -> Term -> RewriteMonad extra ()
- cloneVar :: (Monad m, MonadUnique m) => Name a -> m (Name a)
- isLocalVar :: Term -> RewriteMonad extra Bool
- isUntranslatable :: Bool -> Term -> RewriteMonad extra Bool
- isUntranslatableType :: Bool -> Type -> RewriteMonad extra Bool
- isLambdaBodyCtx :: CoreContext -> Bool
- mkWildValBinder :: (Monad m, MonadUnique m) => Type -> m Id
- mkSelectorCase :: (Functor m, Monad m, MonadUnique m, Fresh m) => String -> HashMap TyConOccName TyCon -> Term -> Int -> Int -> m Term
- specialise :: Lens' extra (Map (TmOccName, Int, Either Term Type) (TmName, Type)) -> Lens' extra (HashMap TmOccName Int) -> Lens' extra Int -> Rewrite extra
- specialise' :: Lens' extra (Map (TmOccName, Int, Either Term Type) (TmName, Type)) -> Lens' extra (HashMap TmOccName Int) -> Lens' extra Int -> [CoreContext] -> Term -> (Term, [Either Term Type]) -> Either Term Type -> RewriteMonad extra Term
- normalizeTermTypes :: HashMap TyConOccName TyCon -> Term -> Term
- normalizeId :: HashMap TyConOccName TyCon -> Id -> Id
- 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 -> TmName Source #
mkEnv :: [CoreContext] -> RewriteMonad extra (Gamma, Delta) Source #
Create a complete type and kind context out of the global binders and the transformation context
:: (Fresh m, MonadUnique m) | |
=> HashMap TyConOccName TyCon | TyCon cache |
-> Name a | Name of the new binder |
-> Term | Term to bind |
-> m (Id, Term) |
Make a new binder and variable reference for a term
:: (Monad m, MonadUnique m, Fresh m) | |
=> HashMap TyConOccName TyCon | TyCon cache |
-> Name a | 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
:: (Monad m, MonadUnique m) | |
=> TmName | 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.
isVoidWrapper :: Term -> Bool Source #
Determines whether a function has the following shape:
\(w :: Void) -> f a b c
i.e. is a wrapper around a (partially) applied function f
, where the
introduced argument w
is not used by f
:: [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 ((TmOccName -> f TmOccName) -> Term -> f Term) Source #
Calculate the local free variable of an expression: the free variables that are not bound in the global environment.
:: (LetBinding -> RewriteMonad extra Bool) | Property test |
-> (Term -> LetBinding -> RewriteMonad extra Bool) | Test whether to lift or inline
|
-> Rewrite extra |
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 |
-> SrcSpan | |
-> InlineSpec | |
-> 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 -> SrcSpan -> InlineSpec -> Term -> RewriteMonad extra () Source #
Add a function to the set of global binders
cloneVar :: (Monad m, MonadUnique m) => Name a -> m (Name a) 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
:: Bool | String representable |
-> Term | |
-> RewriteMonad extra Bool |
Determine if a term cannot be represented in hardware
:: Bool | String representable |
-> Type | |
-> RewriteMonad extra Bool |
Determine if a type cannot be represented in hardware
isLambdaBodyCtx :: CoreContext -> Bool Source #
Is the Context a Lambda/Term-abstraction context?
mkWildValBinder :: (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 TyConOccName 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 (TmOccName, Int, Either Term Type) (TmName, Type)) | Lens into previous specialisations |
-> Lens' extra (HashMap TmOccName 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 (TmOccName, Int, Either Term Type) (TmName, Type)) | Lens into previous specialisations |
-> Lens' extra (HashMap TmOccName 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
normalizeTermTypes :: HashMap TyConOccName TyCon -> Term -> Term Source #
normalizeId :: HashMap TyConOccName TyCon -> Id -> Id Source #
specArgBndrsAndVars :: [CoreContext] -> Either Term Type -> RewriteMonad extra ([Either Id TyVar], [Either Term Type]) Source #
Create binders and variable references for free variables in specArg