Thread overview
Forcing inline functions (again) - groan
Jul 15, 2020
Cecil Ward
Jul 15, 2020
Stefan Koch
Jul 15, 2020
kinke
July 15, 2020
I recently noticed
    pragma(inline, true)
which looks extremely useful. A couple of questions :

1. Is this cross-compiler compatible?

2. Can I declare a function in one module and have it _inlined_ in another module at the call site?

I’m looking to write functions that expand to approx one or even zero machine instructions and having the overhead of a function call would be disastrous; in some cases would make it pointless having the function due to the slowdown.
July 15, 2020
On Wednesday, 15 July 2020 at 13:38:34 UTC, Cecil Ward wrote:
> I recently noticed
>     pragma(inline, true)
> which looks extremely useful. A couple of questions :
>
> 1. Is this cross-compiler compatible?
>
> 2. Can I declare a function in one module and have it _inlined_ in another module at the call site?
>
> I’m looking to write functions that expand to approx one or even zero machine instructions and having the overhead of a function call would be disastrous; in some cases would make it pointless having the function due to the slowdown.

pragma inline will work for dmd.
and it used to fail if it couldn't inline.
Now it just generates a warning.
So with -w it will still fail.

Afaik other compilers cannot warn if the in-lining fails but I might be wrong.
And ldc/gdc should be able to inline most code which makes sense to inline.
July 15, 2020
On Wednesday, 15 July 2020 at 13:38:34 UTC, Cecil Ward wrote:
> I recently noticed
>     pragma(inline, true)
> which looks extremely useful. A couple of questions :
>
> 1. Is this cross-compiler compatible?

Works for LDC and DMD, not sure about GDC, but if it doesn't support it, it's definitely on Iain's list.

> 2. Can I declare a function in one module and have it _inlined_ in another module at the call site?

For LDC, this works in all cases (i.e., also if compiling multiple object files in a single cmdline) since v1.22.

While you cannot force LLVM to actually inline, I haven't come across a case yet where it doesn't.