ddc-core-simpl-0.4.3.1: Disciplined Disciple Compiler code transformations.

Safe HaskellNone
LanguageHaskell98

DDC.Core.Transform.Rewrite

Description

Apply rewrite rules.

Synopsis

Documentation

data RewriteRule a n Source #

A rewrite rule. For example:

 RULE [r1 r2 r3 : %] (x : Int r1)
      . addInt  [:r1 r2 r3:] x (0 [r2] ()
      = copyInt [:r1 r3:]    x

Constructors

RewriteRule 

Fields

  • ruleBinds :: [(BindMode, Bind n)]

    Variables bound by the rule.

  • ruleConstraints :: [Type n]

    Extra constraints on the rule. These must all be satisfied for the rule to fire.

  • ruleLeft :: Exp a n

    Left-hand side of the rule. We match on this part.

  • ruleLeftHole :: Maybe (Exp a n)

    Extra part of left-hand side, but allow this bit to be out-of-context.

  • ruleRight :: Exp a n

    Right-hand side of the rule. We replace the matched expression with this part.

  • ruleWeakEff :: Maybe (Effect n)

    Effects that are caused by the left but not the right. When applying the rule we add an effect weakning to ensure the rewritten expression has the same effects.

  • ruleWeakClo :: [Exp a n]

    Closure that the left has that is not present in the right. When applying the rule we add a closure weakening to ensure the rewritten expression has the same closure.

  • ruleFreeVars :: [Bound n]

    References to environment. Used to check whether the rule is shadowed.

Instances

Reannotate RewriteRule Source #

Allow the expressions and anything else with annotations to be reannotated

Methods

reannotate :: (a -> b) -> RewriteRule a n -> RewriteRule b n #

reannotateM :: Monad m => (a -> m b) -> RewriteRule a n -> m (RewriteRule b n) #

(Eq a, Eq n) => Eq (RewriteRule a n) Source # 

Methods

(==) :: RewriteRule a n -> RewriteRule a n -> Bool #

(/=) :: RewriteRule a n -> RewriteRule a n -> Bool #

(Show a, Show n) => Show (RewriteRule a n) Source # 

Methods

showsPrec :: Int -> RewriteRule a n -> ShowS #

show :: RewriteRule a n -> String #

showList :: [RewriteRule a n] -> ShowS #

(Pretty n, Eq n) => Pretty (RewriteRule a n) Source # 

Associated Types

data PrettyMode (RewriteRule a n) :: * #

Methods

pprDefaultMode :: PrettyMode (RewriteRule a n) #

ppr :: RewriteRule a n -> Doc #

pprPrec :: Int -> RewriteRule a n -> Doc #

pprModePrec :: PrettyMode (RewriteRule a n) -> Int -> RewriteRule a n -> Doc #

rewriteModule Source #

Arguments

:: (Show a, Show n, Ord n, Pretty n) 
=> [NamedRewriteRule a n]

Rewrite rule database.

-> Module a n

Rewrite in this module.

-> Module a n 

Apply rewrite rules to a module.

rewriteX Source #

Arguments

:: (Show a, Show n, Ord n, Pretty n) 
=> [NamedRewriteRule a n]

Rewrite rules database.

-> Exp a n

Rewrite in this expression.

-> TransformResult (Exp a n) 

Perform rewrites top-down, repeatedly.