<div dir="ltr"><div dir="ltr">On Mon, Jun 8, 2020 at 6:50 PM Basile B. via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Monday, 8 June 2020 at 06:14:44 UTC, Manu wrote:<br>
> Inline has been bugging me forever, it's usually not what I <br>
> want. The spec says this-or-that, but I think we should take a <br>
> step back, ignore what's written there, look at the problem <br>
> space, determine the set of things that we want, and then make <br>
> sure they're expressed appropriately.<br>
><br>
> I think a first part of the conversation to understand, is that <br>
> since D doesn't really have first-class `inline` (just a <br>
> pragma, assumed to be low-level compiler control), I think most <br>
> people bring their conceptual definition over from C/C++, and <br>
> that definition is a little odd (although it is immensely <br>
> useful), but it's not like what D does.<br>
><br>
> In C/C++, inline says that a function will be emit to the <br>
> binary only when<br>
> it is called, and the function is marked with internal linkage <br>
> (it is not<br>
> visible to the linker from the symbol table)<br>
> By this definition; what inline REALLY means is that the <br>
> function is not<br>
> placed in the binary where it is defined, it is placed in the <br>
> binary where<br>
> it is CALLED, and each CU that calls an inline function <br>
> receives their own<br>
> copy of the function. From here; optimisers will typically <br>
> inline the call<br>
> if they determine it's an advantage to do so.<br>
><br>
> Another take on inline, and perhaps a more natural take (if <br>
> your mind is not poisoned by other native languages), is that <br>
> the function is not actually emit to an object anywhere, it is <br>
> rather wired directly inline into the AST instead of 'called'. <br>
> Essentially a form of AST macro.<br>
<br>
No. I rather see "inline" as a hint for the backend.<br>
DMD is peculiar with its way of inlining.<br>
<br>
> I reach for inline in C/C++ for various different reasons at <br>
> different times, and I'd like it if we were able to express <br>
> each of them:<br>
><br>
> 1. I only want the function to be present in the CALLING <br>
> binary. I do not want an inline function present in the local <br>
> binary where it was defined (unless it was called internally). <br>
> I do not want a linker to see the inline function symbols and <br>
> be able to link to them externally. [This is about linkage and <br>
> controlling the binary or distribution environment]<br>
<br>
what if the function address is took in a delegate ?<br>
It still needs to be there, in the object matching to the CU <br>
where it is declared, otherwise there will be surprises, e.g <br>
&func in a CU and &func in another will have different addresses.</blockquote><div><br></div><div>Right. This is fine and normal.</div></div></div>