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

Safe HaskellNone

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

Allow the expressions and anything else with annotations to be reannotated

(Eq a, Eq n) => Eq (RewriteRule a n) 
(Show a, Show n) => Show (RewriteRule a n) 
(Pretty n, Eq n) => Pretty (RewriteRule a n) 

rewriteModuleSource

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.

rewriteXSource

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.