Safe Haskell | None |
---|---|
Language | Haskell2010 |
Simple code motion transformation performing common sub-expression elimination and variable hoisting. Note that the implementation is very inefficient.
The code is based on an implementation by Gergely Dévai.
Synopsis
- data InjDict sym a b = InjDict {}
- data CodeMotionInterface sym = Interface {}
- defaultInterface :: forall binding sym symT. (binding :<: sym, Let :<: sym, symT ~ Typed sym) => (forall a. Typeable a => Name -> binding (Full a)) -> (forall a b. Typeable a => Name -> binding (b :-> Full (a -> b))) -> (forall a b. ASTF symT a -> ASTF symT b -> Bool) -> (forall a. ASTF symT a -> Bool) -> CodeMotionInterface symT
- defaultInterfaceDecor :: forall binding sym symI info. (binding :<: sym, Let :<: sym, symI ~ (sym :&: info)) => (forall a b. info a -> info b -> Maybe (Dict (a ~ b))) -> (forall a b. info a -> info b -> info (a -> b)) -> (forall a. info a -> Name -> binding (Full a)) -> (forall a b. info a -> info b -> Name -> binding (b :-> Full (a -> b))) -> (forall a b. ASTF symI a -> ASTF symI b -> Bool) -> (forall a. ASTF symI a -> Bool) -> CodeMotionInterface symI
- codeMotion :: forall sym m a. (Equality sym, BindingDomain sym) => CodeMotionInterface sym -> ASTF sym a -> ASTF sym a
Interface
Interface for injecting binding constructs
data CodeMotionInterface sym Source #
Code motion interface
Interface | |
|
:: (binding :<: sym, Let :<: sym, symT ~ Typed sym) | |
=> (forall a. Typeable a => Name -> binding (Full a)) | |
-> (forall a b. Typeable a => Name -> binding (b :-> Full (a -> b))) | |
-> (forall a b. ASTF symT a -> ASTF symT b -> Bool) | Can the expression represented by the first argument be shared in the second argument? |
-> (forall a. ASTF symT a -> Bool) | Can we hoist over this expression? |
-> CodeMotionInterface symT |
Default CodeMotionInterface
for domains of the form
.Typed
(... :+:
Binding
:+:
...)
defaultInterfaceDecor Source #
:: (binding :<: sym, Let :<: sym, symI ~ (sym :&: info)) | |
=> (forall a b. info a -> info b -> Maybe (Dict (a ~ b))) | Construct a type equality witness |
-> (forall a b. info a -> info b -> info (a -> b)) | Construct info for a function, given info for the argument and the result |
-> (forall a. info a -> Name -> binding (Full a)) | Variable constructor |
-> (forall a b. info a -> info b -> Name -> binding (b :-> Full (a -> b))) | Lambda constructor |
-> (forall a b. ASTF symI a -> ASTF symI b -> Bool) | Can the expression represented by the first argument be shared in the second argument? |
-> (forall a. ASTF symI a -> Bool) | Can we hoist over this expression? |
-> CodeMotionInterface symI |
Default CodeMotionInterface
for domains of the form
(...
, where :&:
info)info
can be used to witness type casting
Code motion
codeMotion :: forall sym m a. (Equality sym, BindingDomain sym) => CodeMotionInterface sym -> ASTF sym a -> ASTF sym a Source #
Perform common sub-expression elimination and variable hoisting