Opened 8 years ago

Last modified 3 years ago

#5834 new feature request

Allow both INLINE and INLINABLE for the same function

Reported by: rl Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.5
Keywords: inlining Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by bgamari)

Sometimes you really want both. Here is a small example:

module T where

foo :: Num a => a -> a -> a
foo x y = x+y+1
module U where

import T

appl :: (a -> b) -> a -> b
{-# NOINLINE appl #-}
appl f x = f x

bar :: Int -> Int -> Int
bar x y = appl foo x y

If I mark foo as INLINE, then GHC generates this code for bar:

bar1 :: Int -> Int -> Int
bar1 = foo @ Int $fNumInt

bar :: Int -> Int -> Int
bar = \ (x_aa0 :: Int) (y_aa1 :: Int) -> appl @ Int @ (Int -> Int) bar1 x_aa0 y_aa1

Whereas with INLINABLE, we get a nice specialisation but, of course, not guarantees with respect to inlining.

In general, it seems that requiring a function to inline when it is saturated and requiring it to specialise when it isn't are two different things and shouldn't be mutually exclusive.

Change History (11)

comment:1 Changed 8 years ago by igloo

difficulty: Unknown
Milestone: 7.6.1

comment:2 Changed 7 years ago by igloo

Milestone: 7.6.17.6.2

comment:3 Changed 5 years ago by thoughtpolice

Milestone: 7.6.27.10.1

Moving to 7.10.1.

comment:4 Changed 5 years ago by thomie

Type of failure: None/UnknownRuntime performance bug

comment:5 Changed 5 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:6 Changed 4 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

comment:7 Changed 4 years ago by bgamari

Description: modified (diff)

comment:8 Changed 4 years ago by thomie

Milestone: 8.0.1

comment:9 Changed 3 years ago by mpickering

Resolution: invalid
Status: newclosed

I think there is some confusion here. From my understanding the INLINABLE pragma causes the unfolding to be added to the interface file and in addition INLINE makes the cost very cheap to encourage the actual inlining.

If this is wrong then someone please open the ticket.

comment:10 Changed 3 years ago by carter

Resolution: invalid
Status: closednew

Mpickering, I think bgamari's ask/clarification edit of the ticket : namely the ability to inline saturated applications and specialize unsaturated use sites. And that we currently can't quite express that? I may be interpreting this incorrectly.

comment:11 Changed 3 years ago by thomie

Keywords: inlining added
Note: See TracTickets for help on using tickets.