DMD and GDC are unnecessarily using heap allocations for closures

Nicholas Wilson iamthewilsonator at hotmail.com
Mon May 30 10:40:33 UTC 2022


On Monday, 30 May 2022 at 10:24:12 UTC, Siarhei Siamashka wrote:
> So far I'm quite happy about the quality of the code generated 
> by LDC and it has never failed me. But I wonder if the @nogc 
> attribute can play a bit nicer with the GC2Stack IR 
> optimization pass? For example, somehow postpone the error 
> reporting in the frontend and only fail if GC2Stack is actually 
> unable to eliminate all GC allocations in the @nogc code. Maybe 
> I can report this to LDC developers.

(LDC dev) I doubt this will be able to be fixed. @nogc is a 
frontend construct and would be difficult, if not impossible, to 
have it depend on the ability of backend optimisation passes that 
may or may not be able to remove all calls to the GC (if they are 
enabled at all).

LDC does have some specific semantic analysis passes but all of 
them are done after DMD's ones. GC2stack is an IR level 
optimisation not a frontend one and IR is only generated after 
all frontend semantic analysis is completed without error.



More information about the Digitalmars-d mailing list