#2420: Multi-method classes are inlined/specialized better than single-method
classes for strict types
-----------------------+----------------------------------------------------
 Reporter:  sedillard  |          Owner:             
     Type:  bug        |         Status:  new        
 Priority:  normal     |      Milestone:  6.10 branch
Component:  Compiler   |        Version:  6.8.3      
 Severity:  normal     |     Resolution:             
 Keywords:             |     Difficulty:  Unknown    
 Testcase:             |   Architecture:  Unknown    
       Os:  Linux      |  
-----------------------+----------------------------------------------------
Comment (by simonpj):

 I know something about what is going on here.

 First, there's nothing very bad happening.  The code ''looks'' worse, but
 at any call to `squarepd`, the whole definition will be inlined, and then
 `$WPair` will be inlined, and it'll all turn out like the previous case.
 So efficiency should be similar either way.

 Why the difference between the two cases?  Because the details of inlining
 are regrettably delicate.  The `__inline_me__` note makes the enclosed
 expression look small, so that it'll be keen to  inline. When it ''is''
 inlined at an application, the `__inline_me__` wrapper is removed.  But in
 your example you have
 {{{
 squarepd = square
 }}}
 where `square` in this case is the `Pair` instance function, which is
 marked `INLINE`.  This isn't an application of `square`; rather it's more
 like a renaming, so we end up with an `__inline_me__` around the
 `squarepd` RHS.

 Inside `__inline_me__` GHC is very reluctant to do any inlining at all; it
 just blows up the thing to be inlined.  Leave it until it ''is'' inlined.

 If you instead wrote
 {{{
 squarepd x = square x
 }}}
 now it looks like a ''call'' of `square`, so the thing it inlined and the
 `__inline_me__` is stripped off, and then `$WPair` can get inlined.

 That's the general idea.  For 6.10 I have two changes in the works that
 will affect this: (a) a new way of treating INLINE pragmas, and (b) a new
 way of treating instance declarations.  So I'm not going to pursue this
 further until I've done that.  I'll leave it open to remind me to take
 another look then.

 Meanwhile: do you think the difference has a performance impact (contrary
 to my claim)?

 Simon

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2420#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to