What does 'inline' mean?

kinke noone at nowhere.com
Wed Jun 10 20:10:56 UTC 2020


On Wednesday, 10 June 2020 at 19:20:55 UTC, Steven Schveighoffer 
wrote:
> My understanding with -allinst is that the compiler is supposed 
> to instantiate all templates even if it thinks a dependent 
> library has already done it.
>
> But I'm happy to defer to you as an actual developer of the 
> compiler, I'm not. I have had experience as a user with the 
> compiler making wrong decisions about whether it should emit 
> code for a template instance or not.
>
> In any case, my point is that just making it a template isn't 
> the equivalent as has been suggested.

You're spot-on, except for the fact that a template instance is 
emitted into at most 1 object file per compiler command-line. So 
if you compile a static lib with 100 modules in one go, and each 
module instantiates some common template, it's emitted into 
exactly one object file when using -allinst (and possibly 
-unittest too, I don't remember exactly), and *might* be emitted 
into a (single) object file without -allinst (because as you 
said, if the compiler sees another non-compiled imported module 
instantiating it, the compiler elides its codegen and depends on 
that external definition later when linking).

TLDR: Templates, with the current emission scheme, can definitely 
not be used to emit a function into every referencing CU.


More information about the Digitalmars-d mailing list