[GHC] #8099: Alternate syntax for indicating when a function is "fully applied" for purposes of inlining

GHC ghc-devs at haskell.org
Wed Jul 31 22:28:36 CEST 2013


#8099: Alternate syntax for indicating when a function is "fully applied" for
purposes of inlining
-------------------------------------+------------------------------------
        Reporter:  jberryman         |            Owner:
            Type:  feature request   |           Status:  new
        Priority:  normal            |        Milestone:
       Component:  Compiler          |          Version:  7.6.3
      Resolution:                    |         Keywords:
Operating System:  Unknown/Multiple  |     Architecture:  Unknown/Multiple
 Type of failure:  None/Unknown      |       Difficulty:  Unknown
       Test Case:                    |       Blocked By:
        Blocking:                    |  Related Tickets:
-------------------------------------+------------------------------------

Comment (by ekmett):

 Replying to [comment:9 simonpj]:
 > PS: Edward, could you offer a couple of concrete examples?

 This issue I mentioned is up on github at
 https://github.com/ekmett/lens/issues/183

 We have a lot of code like

 {{{
 over l f = runIdentity #. l (Identity #. f)
 }}}

 In that you can read (#.) as if it were (.), but if we switch it to

 {{{
 over l = \f -> runIdentity #. l (Identity #. f)
 }}}

 then GHC can inline it better in a call like

 {{{
 foo :: (a -> b) -> [a] -> [b]
 foo = over mapped
 }}}

 For reference:

 {{{
 mapped f = Identity #. fmap (runIdentity #. f)
 }}}

 Unfortunately, this means that the 'f' argument isn't in scope for where
 clauses, etc. which makes a lot of function implementations a lot uglier
 when they have more structure than this trivial example.

 {{{
 scanr1Of l f = snd . mapAccumROf l step Nothing where
   step Nothing a  = (Just a, a)
   step (Just s) a = let r = f a s in (Just r, r)
 }}}

 There because f is referenced in the where clause step becomes explicitly
 parameterized on f, so we wind up having to either plumb the f argument in
 to step or we have to define step inside of a let clause inside of the
 lambda that takes f cluttering things up considerably.

 You can find dozens of examples by skimming through
 http://hackage.haskell.org/packages/archive/lens/3.9.0.2/doc/html/src
 /Control-Lens-Traversal.html#mapMOf or
 http://hackage.haskell.org/packages/archive/lens/3.9.0.2/doc/html/src
 /Control-Lens-Fold.html#foldrOf

 Almost any combinator with a name that ends in "Of" which currently takes
 more than one argument on the left hand side of the equal sign is a
 candidate. Our current plan is to just bite the bullet and move all the
 code around to get better inlining, because we've found it makes an
 difference in quality of the resulting core.

 -Edward

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




More information about the ghc-tickets mailing list