Skip to content

Local functions lose their unfoldings

I'm attaching 2 modules, both should be compiled with -O2. Let's look at the inteface of Foo:

  foo :: (GHC.Types.Int, GHC.Types.Int)
         -> [GHC.Types.Int]
         -> [GHC.Types.Int]
    {- Arity: 2, Strictness: U(U(L)U(L))L, Inline: INLINE (sat-args=2),
       Unfolding: InlineRule (2, False, False)
                  (\ ds :: (GHC.Types.Int, GHC.Types.Int) xs :: [GHC.Types.Int] ->
                   case @ [GHC.Types.Int] ds of wild { (i, n) ->
                   let {
                     step :: forall t.
                             ([t], GHC.Types.Int, GHC.Types.Int)
                             -> Data.Maybe.Maybe (([t], GHC.Types.Int, GHC.Types.Int), t)
                       {- Inline: INLINE[0] (sat-args=1) -}
                     = ...

Note how step, which is local to foo, has an INLINE pragma but no unfolding. Now, let's look at Bar. For some reason, GHC only inlines foo into bar in phase 1. This is probably unrelated but still surprising. The main problem, though, is that step, not having an unfolding, doesn't get inlined at all despite the INLINE pragma.

Trac metadata
Trac field Value
Version 7.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information