What does 'inline' mean?
kinke
noone at nowhere.com
Thu Jun 11 15:42:48 UTC 2020
On Thursday, 11 June 2020 at 10:05:14 UTC, Walter Bright wrote:
> On 6/10/2020 1:10 PM, kinke wrote:
>> TLDR: Templates, with the current emission scheme, can
>> definitely not be used to emit a function into every
>> referencing CU.
>
> Yes, but in Manu's case the idea is to not need to link with a
> library.
I know, just saying that the workaround suggested by Stefan
('just make it a dummy template') doesn't work in general - it
*can* work, but only when using -allinst in combination with
compiling a single object file per compiler invocation, basically
excluding all static libraries compiled in one cmdline (dub
default, right?).
In the linked LDC PR, I'm experimenting with a different template
emission scheme, emitting each referenced template stuff into
each referencing CU/object file, using linkonce_odr linkage. As a
side effect, that would enable the template workaround (or open
the door for some other syntactic way of emitting regular
non-templated functions the same way), without -allinst or having
to take care of how the compiler is invoked.
My interest in this wasn't triggered by wanting to enforce
particular functions to be emitted into each referencing CU, but
by
a) the current emission scheme requiring LTO in order to inline
suited little templated functions when compiling static libs in
one go,
b) being able to use linkonce_odr instead of weak_odr linkage for
template stuff, meaning potentially less work for the linker, and
potentially quite a bit less work for the optimizer. Compiling an
optimized dub (a single object file) with LDC using
-linkonce-templates reduces the total compile+optimize times by
roughly 25%, simply because LLVM inlines most little template
stuff and can then discard the unused linkonce_odr functions
early in the process, without uselessly optimizing them to death
(as it currently cannot discard it, as other libraries/objects
might depend on some template instances as mentioned earlier).
More information about the Digitalmars-d
mailing list