GHC inliner doesn't
Compile this program
{-# OPTIONS_GHC -O2 -ddump-simpl #-}
module Foo where
class C a where
to' :: a -> Int
from' :: Int -> a
{-# NOINLINE to #-}
to :: (C a) => a -> Int
to = to'
{-# NOINLINE from #-}
from :: (C a) => Int -> a
from = from'
{-# INLINE foo #-}
foo :: (C a) => (Int -> Int) -> a -> a
foo f x = from (f (to x))
bar :: (C a) => (Int -> Int) -> a -> a
bar f = foo f . foo f
Study the output. It contains
...
Foo.foo =
__inline_me (\ (@ a_a6n) ($dC_a6t :: Foo.C a_a6n) ->
...
and
...
Foo.bar =
\ (@ a_a6w) ($dC_a6G :: Foo.C a_a6w) ->
let {
foo1_s7S [ALWAYS Just L] :: (GHC.Base.Int -> GHC.Base.Int) -> a_a6w -> a_a6w
[Str: DmdType]
foo1_s7S = Foo.foo @ a_a6w $dC_a6G
...
Why isn't foo inlined?
Note that if the export list is changed to only export bar, then foo does get inlined.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 6.9 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | lennart@augustsson.net |
| Operating system | Unknown |
| Architecture | Unknown |