Repository : ssh://darcs.haskell.org//srv/darcs/ghc

On branch  : ghc-7.2

http://hackage.haskell.org/trac/ghc/changeset/b982db15d2a8e105907f85b30bcb2d87a82c3d86

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

commit b982db15d2a8e105907f85b30bcb2d87a82c3d86
Author: Simon Peyton Jones <[email protected]>
Date:   Thu Jul 21 12:54:51 2011 +0100

    Eta expand partial applications
    
    When we have
         x = \v -> map g
    we want to eta-expand to
         x = \v y -> map g y
    
    We weren't doing so, and that led to worse code and,
    perhaps, #5285.  I need to check the latter, but I
    was certainly seeing one similar error.  Anyway
    this looks like a definite improvement

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

 compiler/simplCore/SimplUtils.lhs |   28 ++++++++++++++++++++++++----
 1 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/compiler/simplCore/SimplUtils.lhs 
b/compiler/simplCore/SimplUtils.lhs
index 7d5d764..f01aa56 100644
--- a/compiler/simplCore/SimplUtils.lhs
+++ b/compiler/simplCore/SimplUtils.lhs
@@ -1117,17 +1117,20 @@ tryEtaExpand env bndr rhs
          return (new_arity, new_rhs) }
   where
     try_expand dflags
+      | exprIsTrivial rhs
+      = return (exprArity rhs, rhs)
+
       | sm_eta_expand (getMode env)      -- Provided eta-expansion is on
-      , not (exprIsTrivial rhs)
       , let dicts_cheap = dopt Opt_DictsCheap dflags
             new_arity   = findArity dicts_cheap bndr rhs old_arity
-      , new_arity > rhs_arity
+      , new_arity > manifest_arity     -- And the curent manifest arity isn't 
enough
+                                       -- See Note [Eta expansion to manifes 
arity]
       = do { tick (EtaExpansion bndr)
            ; return (new_arity, etaExpand new_arity rhs) }
       | otherwise
-      = return (rhs_arity, rhs)
+      = return (manifest_arity, rhs)
 
-    rhs_arity  = exprArity rhs
+    manifest_arity = manifestArity rhs
     old_arity  = idArity bndr
     _dmd_arity = length $ fst $ splitStrictSig $ idStrictness bndr
 
@@ -1216,6 +1219,23 @@ because then 'genMap' will inline, and it really 
shouldn't: at least
 as far as the programmer is concerned, it's not applied to two
 arguments!
 
+Note [Eta expansion to manifest arity]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Eta expansion does *not* eta-expand trivial RHSs, like
+    x = y
+because these will get substituted out in short order.  (Indeed
+we *eta-contract* if that yields a trivial RHS.)
+
+Otherwise we eta-expand to produce enough manifest lambdas.
+This *does* eta-expand partial applications.  eg
+      x = map g                -->    x = \v -> map g v
+      y = \_ -> map g  -->    y = \_ v -> map g v
+One benefit this is that in the definition of y there was 
+a danger that full laziness would transform to
+      lvl = map g
+      y = \_ -> lvl
+which is stupid.  This doesn't happen in the eta-expanded form.
+
 Note [Arity analysis]
 ~~~~~~~~~~~~~~~~~~~~~
 The motivating example for arity analysis is this:



_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to