pragma(inline, true) errors?

Steven Schveighoffer schveiguy at gmail.com
Fri Apr 2 17:00:35 UTC 2021


On 4/2/21 12:27 PM, Johan Engelen wrote:
> On Friday, 2 April 2021 at 14:40:00 UTC, Steven Schveighoffer wrote:
>>
>> pragma(inline, true)
>>
>> means nothing in the current compiler. Well, it doesn't mean nothing, 
>> it only means that in the case of configuring the compiler to treat 
>> warnings as informational-only, you will get an informational warning. 
>> In the case that warnings are treated as an error, your code always 
>> compiles, and the function is only inlined based on implementation 
>> definitions.
>>
>> Technically, this is according to spec, as it says what the compiler 
>> does if a pragma(inline, true) function cannot be inlined is 
>> implementation defined. But it does say "an error message is typical". 
>> Given that there is only one front end, the typical (and in fact 
>> universal) behavior now is, do nothing.
> 
> I'm pretty sure LDC will _never_ give any warning or error on this pragma.
> It will almost always inline the function into the caller (I don't know 
> of cases where it can't).

So technically for LDC it will never encounter this case.

> I question the value of knowing whether a function was inlined or not.

I don't really care about inlining or not, but I'm forced to reckon with 
this, because I've taken over maintenance of a package that puts 
"pragma(inline, true):" at the top of a module, and therefore warnings 
are being spat out. So I want to ask the question, is this a bug? What 
is the expectation? Should we just change the description to "issue a 
informational warning in some cases when the function cannot be inlined"?

Does LDC make any inlining decisions based on this flag?

> Note that `pragma(inline)` is very different functionality from "not 
> emitting a function to object file", which _is_ useful functionality but 
> there is no method to do that in D that I know of (and should not be 
> called "inline").

Yeah, I'm not necessarily invested in a debate about the feature, I just 
want to know what it really means, so I can make a decision whether to 
yank the attribute or not.

-Steve


More information about the Digitalmars-d mailing list