What does 'inline' mean?

Iain Buclaw ibuclaw at gdcproject.org
Sun Jun 21 22:42:54 UTC 2020


On Saturday, 13 June 2020 at 18:24:18 UTC, Andrei Alexandrescu 
wrote:
> On 6/13/20 7:31 AM, Johannes Pfau wrote:
>> 
>> So basically all that's missing for Manu's inline case would 
>> be to emit
>> pragma(inlne) functions from non-root modules. Probably a 
>> 1-line change.
>
> Should that go in bugzilla?

I don't see why there should not be a bugzilla for it.

@Manu, pardon my skipping the 11 pages of replies between the 
first and last posts, so if it's already been said, please ignore.

I think trying to impose the C/C++ notion of inline as a linkage 
modifier into D is at odds with modules.  I'm going to make a 
potentially disagreeable statement and say that there is no 
external or internal linkage in D.  Rather there's language 
linkage, e.g: `extern(C++)`; and then there's module linkage, 
where a given declaration resolves to the same symbol across all 
TUs that import its residing module, but otherwise not strictly 
visible outside that.

To address your laments, it may be wise to pay attention to the 
direction that `inline` is heading in C++ modules.

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1498r1.html#inline
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1779r3.html

Notably the sentence: "Within interface units of modules, we 
suggest converging on an interperation more firmly rooted in the 
semantics: an inline entity (function definition or variable 
initialization) is semantically incorporated into (or inlined 
into) the interface of a module."

Which I interpret as, given:

     module mod;
     pragma(inline, true) void fun() { ... }

Any module that imports `mod` (called non-root),  will have the 
`fun` emitted into the module as well.  This would be implemented 
using the support of weak (ELF) or selectany (COFF), so the 
linker will throw away all duplicated definitions.

However, to satisfy your "emit to the binary only when it is 
called" constraint, it will also have to be discard-able at 
compile-time.  But I'm not sure whether that really a desirable 
feature to have.  At the very least, it should only extend to 
non-root modules, so there's always one copy in the root module 
it was declared, to avoid linker errors.


More information about the Digitalmars-d mailing list