add INLINEABLE to maybe, either, bool

Austin Seipp austin at well-typed.com
Mon Sep 16 23:56:54 CEST 2013


A serious question: if you don't even trust GHC to inline 'bool',
'maybe' or 'either', given their triviality, do you trust it to ever
inline anything at all? I'm being completely honest here.

It still ignores the question of *why* the inliner is failing to do
what you want. If the type inferencer fails to infer the type of an
utterly trivial function - let's again say 'bool :: a -> a -> Bool ->
a', as it's type is about as trivial as it's definition - it is almost
certainly broken. By the same token, GHC not inlining 'bool' under -O
would almost certainly be a bug too, in my eyes. The definition is
trivial to the point where we should not ask "what if it doesn't
inline" - we should figure out WHY it does not do so. Maybe INLINE
would be a justified way of fixing it, but in this case it's just
unnecessary and has been verified as such.

By the same token, we also don't encourage people to wildly put `seq`
everywhere, or make everything on earth strict just because it makes
them feel good.

A compiler must work on a broad range of programs for a broad range of
use cases. There are certainly some cases that the compiler is *not*
tuned for. In some of these cases, we work to make them more
efficient. We patch the compiler to make it better where-ever
possible. But this case? This is nothing but a premature optimization
in my eyes - and one that even people like Edward or myself are guilty
of, for sure.* And I am repenting by rejecting the "INLINE school of
thought" (or INLINE school of hammers, as it were.)

If you want to make the argument that 'bool' - or something else even
- should be INLINE, by all means do so. But if you're going to do so
without any empirical cases, or examples of why it should be so
(especially when we have already checked the interface files,) and
just say it lets you sleep better at night? I simply do not buy it.


On Mon, Sep 16, 2013 at 3:59 PM, Dan Burton <danburton.email at gmail.com> wrote:
> I'm wary of "let's not mark it as INLINE because we want the compiler to
> automagically inline it for us." This seems like saying we should not have
> type signatures, because we want the type inferencer to figure it out for
> us. (If you want to test the auto-inliner's wisdom, then just add a setting
> that ignores INLINE pragmas and see if it inlines the same thing that humans
> do?)
>
> I don't really care how it's accomplished, but I do think that we should
> make sure that maybe, either, and bool are inlined, and the most obvious way
> to accomplish this is to directly mark them INLINE, is it not?
>
> -- Dan Burton
>
>
> On Mon, Sep 16, 2013 at 1:33 PM, Edward Kmett <ekmett at gmail.com> wrote:
>>
>> Contrary to appearances, I fully agree. =)
>>
>>
>> On Mon, Sep 16, 2013 at 4:12 PM, Austin Seipp <austin at well-typed.com>
>> wrote:
>>>
>>> I'm strongly opposed to this.
>>>
>>> Being INLINE happy is not a good thing, it is a bad thing. More often
>>> than not, I see people stuffing INLINE all over the place for things
>>> that would trivially be unfolded and put in the interface file anyway.
>>> This is bad, and it teaches people to just use the INLINE hammer
>>> everywhere instead of understanding the actual implications of what
>>> the inliner does. It also makes it impossible to actually observe how
>>> the inliner behaves and see where it needs tuning: if we just mark
>>> everything INLINE, we might as well not have it and make it
>>> unconditional.
>>>
>>> There are some particular cases where GHC is hesitant to inline small
>>> things if it would lead to work duplication, or where the inliner
>>> behavior is tweaked and you may want to force it across multiple
>>> versions to be sure (lens is a good example of this.) But this is far
>>> more rare, and this case is not that. In particular, Joachim checked
>>> the 'bool' commit. As expected, the unfolding for bool was put into
>>> the interface file for Data.Bool, meaning if you use -O (or just -O0
>>> -fno-ignore-interface-pragmas,) it should be inlined at call sites
>>> appropriately when it is used.
>>>
>>> If we're going to INLINE things, we need to make sure it actually has
>>> an empirical benefit, by looking at the core, and seeing where the
>>> inliner is failing. Not just attach it to things because it seems like
>>> a good idea. This also helps drive feedback into the inliner so we can
>>> see where it fails.
>>>
>>> On Mon, Sep 16, 2013 at 2:59 PM, Carter Schonwald
>>> <carter.schonwald at gmail.com> wrote:
>>> > Its come to my attention that maybe, either, and its new sibling bool,
>>> > all
>>> > lack the
>>> > INLINEABLE attribute, or its more aggressive sibling INLINE
>>> >
>>> > this seems like one of those operations where inlining in client use
>>> > sites
>>> > is a good option to have, and currently not possible!
>>> >
>>> > theres probably other stuff that would benefit from an INLINEABLE
>>> > pragma in
>>> > base,
>>> > but this is an obvious, simple, "easy win" that I noticed when Oliver's
>>> > patch got merged into base.
>>> >
>>> > Thoughts?
>>> > Time scale: sometime this week? (ghc 7.8 merge window is landing!)
>>> >
>>> > cheers
>>> >
>>> > _______________________________________________
>>> > Libraries mailing list
>>> > Libraries at haskell.org
>>> > http://www.haskell.org/mailman/listinfo/libraries
>>> >
>>>
>>>
>>>
>>> --
>>> Austin Seipp, Haskell Consultant
>>> Well-Typed LLP, http://www.well-typed.com/
>>> _______________________________________________
>>> Libraries mailing list
>>> Libraries at haskell.org
>>> http://www.haskell.org/mailman/listinfo/libraries
>>
>>
>>
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://www.haskell.org/mailman/listinfo/libraries
>>
>



-- 
Austin Seipp, Haskell Consultant
Well-Typed LLP, http://www.well-typed.com/



More information about the Libraries mailing list