DIP56 - inlining

Zach the Mystic via Digitalmars-d digitalmars-d at puremagic.com
Thu Feb 5 08:14:39 PST 2015


On Thursday, 5 February 2015 at 14:43:40 UTC, Steven 
Schveighoffer wrote:
> On 2/4/15 1:46 AM, Zach the Mystic wrote:
>> It's a bikeshed argument, but why not:
>>
>> pragma(inline, always);  // warn if unable to inline
>> pragma(inline, never);
>> pragma(inline);        // revert to default behavior
>>
>> ....?
>>
>> I know `true` and `false` are keywords, but why confuse 
>> people? What is
>> a "true" inline?
>
> enum always = true;
> enum never = false;
>
> -Steve

Actually, the better reason is that, as subsequently clarified, 
the pragma accepts a boolean expression, rather than just `true` 
or `false`, allowing for greater flexibility. Accepting an 
integer, for 3+ inlining strategies, would allow even more, but 
it might not carry its own weight (same with enum always = true;, 
because of namespace pollution). My gut says that an integer is 
better, but I don't know if there really are more than 3 good 
inlining strategies.

A more general approach would be:

enum {
   inlineOff,
   inlineOn,
   inlineDefault,
   codePathHot,
   codePathCold
}

pragma(optimize, inlineOn);
pragma(optimize, codePathHot);

You'd get everything here, with options to add more later. Note 
that codePathCold/Hot need not cancel inlineOff/On/Default, as 
they could be implemented as orthogonally.


More information about the Digitalmars-d mailing list