Forcing inlining of delegates and lazy
FinalEvilution
FinalEvilution at gmail.com
Tue Sep 1 22:09:04 UTC 2026
On Tuesday, 1 September 2026 at 17:07:59 UTC, ABrightLight wrote:
> On Tuesday, 1 September 2026 at 15:58:12 UTC, FinalEvilution
> wrote:
>>
>> If the option doesn't work out would you be able to provide a
>> reduced test case? I've become rather curious as to what's
>> going on.
>
> Actually in your sample, if you go over to godbolt.org and
> compile with LDC and -O5 (or -Oz) you'll see that that
> `expr();` ends up being:
> ```
> mov rdi, r14
> call rbx
> ```
-O5 and -O4 are just aliases and are equivalent to -O3.
I just checked myself on goldbolt and ldc inlines and unrolls the
loop into `_Dmain` without any calls to `times`.
https://godbolt.org/z/sWYzT9sW6
The unused `times` function cannot be eliminated as the binary
hasn't been linked yet.
Here's another version without the noise of the standard library.
Uncomment the `//pragma(inline, false)` to see the difference.
https://godbolt.org/z/4Y5q3nv4e
The `foo` function cannot be inlined as there is no function
body. It is only used for demonstration.
More information about the Digitalmars-d
mailing list