[commit: ghc] master: Note [Eta expansion in match] (a4450ec)

git at git.haskell.org git at git.haskell.org
Mon Feb 10 14:46:25 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/a4450ece29ee42f6d04cdd6baf4c48ff596b687d/ghc

>---------------------------------------------------------------

commit a4450ece29ee42f6d04cdd6baf4c48ff596b687d
Author: Joachim Breitner <mail at joachim-breitner.de>
Date:   Mon Feb 10 14:46:14 2014 +0000

    Note [Eta expansion in match]


>---------------------------------------------------------------

a4450ece29ee42f6d04cdd6baf4c48ff596b687d
 compiler/specialise/Rules.lhs |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/compiler/specialise/Rules.lhs b/compiler/specialise/Rules.lhs
index b88888c..7fdf12c 100644
--- a/compiler/specialise/Rules.lhs
+++ b/compiler/specialise/Rules.lhs
@@ -682,6 +682,7 @@ match renv subst (Lam x1 e1) (Lam x2 e2)
 -- It's important that this is *after* the let rule,
 -- so that      (\x.M)  ~  (let y = e in \y.N)
 -- does the let thing, and then gets the lam/lam rule above
+-- See Note [Eta expansion in match]
 match renv subst (Lam x1 e1) e2
   = match renv' subst e1 (App e2 (varToCoreExpr new_x))
   where
@@ -998,6 +999,24 @@ at all.
 That is why the 'lookupRnInScope' call in the (Var v2) case of 'match'
 is so important.
 
+Note [Eta expansion in match]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+At a first glance, this (eta-expansion of the thing to match if the template
+contains a lambda) might waste work. For example
+    {-# RULES "f/expand" forall n. f (\x -> foo n x) = \x -> foo n x #-}
+(for a non-inlined "f = id") will turn
+    go n = app (f (foo n))
+into
+    go n = app (\x -> foo n x)
+and if foo had arity 1 and app calls its argument many times, are wasting work.
+
+In practice this does not occur (or at least I could not tickle this "bug")
+because CSE turns it back into
+    go n = let lvl = foo n in app (\x -> lvl x)
+which is fine.
+
+
+
 %************************************************************************
 %*                                                                      *
                    Rule-check the program



More information about the ghc-commits mailing list