[Issue 24838] @nogc lambda shouldn't allocate closure when lambda refers only to 'this'

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 30 21:48:27 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24838

--- Comment #5 from anonymous4 <dfj1esp02 at sneakemail.com> ---
Lowering could be something like
---
struct Context
{
        T* ref_capture; //normal capture
}

void Closure(Context* ctx)
{
        bool oneref=false; //change this
        T* local_ref;
        if(oneref)local_ref=cast(T*)ctx;
        else local_ref=ctx.ref_capture;
        //call
        local_ref.method();
}
---

If one reference is captured, `oneref` variable could be changed(?)
accordingly, and argument would be different, then backend will optimize it.

--


More information about the Digitalmars-d-bugs mailing list