Forcing inlining of delegates and lazy

ABrightLight example at example.com
Tue Sep 1 14:01:40 UTC 2026


On Tuesday, 1 September 2026 at 03:01:00 UTC, FinalEvilution 
wrote:
> On Monday, 31 August 2026 at 17:36:55 UTC, ABrightLight wrote:
>> Hello. I am trying to figure out some way to get delegates or 
>> lazy parameters to get inlined into the function they are 
>> called with. For example, if we take this starting code:
>
> I tried building a simple program with the ldc compiler and 
> optimization and it inlined correctly. At least in this case.
> ```
> import std.stdio : writeln;
>
> void main()
> {
>     int x;
>     3.times(writeln(x++));
> }
>
> pragma(inline, true)
> void times(int n, lazy void exp)
> {
>     while (n--)
>         exp();
> }
> ```
>
> Are you possibly using dmd? It doesn't have the fancy 
> optimizing backends that gdc and ldc have.

I was using LDC and my code would lower to a jump to the 
delegate. I'll see if the llvm specific option works.


More information about the Digitalmars-d mailing list