subtle inlining problem

Hello glasgow-haskell-users, in the following definitions:
{-# INLINE getInteger #-} getInteger = ... -- large definition that will be not inlined -- without pragma
instance Binary Integer where get = getInteger
is Integer.get will be inlined or not? -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

| > {-# INLINE getInteger #-} | > getInteger = ... -- large definition that will be not inlined | > -- without pragma | > | > instance Binary Integer where | > get = getInteger A simpler version is
{-# INLINE getInteger #-} getInteger = ... -- large definition that will be not inlined -- without pragma
get = getInteger
Here, getInteger will be inlined in the RHS of get, but GHC doesn't see any reason that 'get' should be inlined. If you want that, add an INLINE pragma on get. The same thing should work in an instance decl, for the same reason, but I have not tried it recently. And, assuming it does work, it ought to be documented. If you check, and send me draft words, I'll add them to the user manual Simon

Hello Simon, Wednesday, November 8, 2006, 8:41:51 PM, you wrote:
{-# INLINE getInteger #-} getInteger = ... -- large definition that will be not inlined -- without pragma
get = getInteger
Here, getInteger will be inlined in the RHS of get, but GHC doesn't see any reason that 'get' should be inlined.
If you want that, add an INLINE pragma on get.
The same thing should work in an instance decl, for the same reason, but I have not tried it recently. And, assuming it does work, it ought to be documented. If you check, and send me draft words, I'll add them to the user manual
ok, but i don't undertsand what you mean by "it does work"? should i check that without INLINE pragma it's not inlined and with pragma it's inlined? also, that you think about changing implementation to that i implied - any function equivalent to inlined function, should be also inlined? in terms of implementation complexity and whether it will be good or bad change? for my particular program (AltBinary lib) it will allow to remove a couple of INLINE pragmas. and if someone want to create not inlined version of some inlined function, he can easily write get=getInteger {-# NOINLINE get #-} -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

| > The same thing should work in an instance decl, for the same | > reason, but I have not tried it recently. And, assuming it does | > work, it ought to be documented. If you check, and send me draft | > words, I'll add them to the user manual | | ok, but i don't undertsand what you mean by "it does work"? should i | check that without INLINE pragma it's not inlined and with pragma it's | inlined? I meant that I'm not 100% sure that an INLINE pragma in an *instance declaration* will cause the method to be inlined. I think it works, but it'd be worth checking. | also, that you think about changing implementation to that i implied - | any function equivalent to inlined function, should be also inlined? Definitely not. It'd be a strange special case. What about get = id getInteger or get = id (id getInteger) Initially these don't look like "equivalent to inlined function" but they are. What about get = [getInteger] !! 1 Perhaps you could say that something magic happens when you, the programmer write x=y, and y has an INLINE pragma... but my instinct is to keep GHC's simple, rule. Simon

Hello Simon, Thursday, November 9, 2006, 11:29:18 AM, you wrote:
I meant that I'm not 100% sure that an INLINE pragma in an *instance declaration* will cause the method to be inlined. I think it works, but it'd be worth checking.
you may be sure - without this my deeply-classified Streams library will be never such fast :) once i lost INLINE pragma in the middle-level definition and found that execution becomes 200x slower :) altough really there are a several traps and i will try to document them - may be it will be even possible to fix them. but basically it works and it makes possible to write fast polymorhic code. believe it or not, we already widely use this feature: instance Monad IO where {-# INLINE return #-} {-# INLINE (>>) #-} {-# INLINE (>>=) #-} m >> k = m >>= \ _ -> k return x = returnIO x m >>= k = bindIO m k fail s = failIO s
Perhaps you could say that something magic happens when you, the programmer write x=y, and y has an INLINE pragma... but my instinct is to keep GHC's simple, rule.
my intuition says different but this is not very important, after all. i can include this as one more caveat in the above-mentioned list -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
participants (2)
-
Bulat Ziganshin
-
Simon Peyton-Jones