#7436: Derived Foldable and Traversable instances become extremely inefficient 
due
to eta-expansion
---------------------------------+------------------------------------------
    Reporter:  shachaf           |       Owner:                         
        Type:  bug               |      Status:  patch                  
    Priority:  normal            |   Milestone:                         
   Component:  Compiler          |     Version:  7.6.1                  
    Keywords:                    |          Os:  Unknown/Multiple       
Architecture:  Unknown/Multiple  |     Failure:  Runtime performance bug
  Difficulty:  Unknown           |    Testcase:                         
   Blockedby:                    |    Blocking:                         
     Related:                    |  
---------------------------------+------------------------------------------

Comment(by twanvl@…):

 commit 49ca2a37bef18aa57235ff1dbbf1cc0434979b1e
 {{{
 Author: Twan van Laarhoven <twa...@gmail.com>
 Date:   Fri Nov 23 15:03:45 2012 +0100

     Changed deriving of Functor, Foldable, Traversable to fix #7436. Added
 foldMap to derived Foldable instance.

     The derived instances will no longer eta-expand the function. I.e.
 instead of
         fmap f (Foo a) = Foo (fmap (\x -> f x) a)
     we now derive
         fmap f (Foo a) = Foo (fmap f a)

     Some superflous lambdas are generated as a result. For example
         data X a = X (a,a)
         fmap f (X x) = (\y -> case y of (a,b) -> (f a, f b)) x
     The optimizer should be able to simplify this code, as it is just beta
 reduction.

     The derived Foldable instance now includes foldMap in addition to
 foldr.

  compiler/prelude/PrelNames.lhs    |    9 ++-
  compiler/typecheck/TcGenDeriv.lhs |  178
 ++++++++++++++++++++++---------------
  2 files changed, 114 insertions(+), 73 deletions(-)
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7436#comment:16>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to