Thread overview
[Issue 24838] @nogc lambda shouldn't allocate closure when lambda refers only to 'this'
2 days ago
Manu
2 days ago
Tim
2 days ago
Manu
1 day ago
anonymous4
2 days ago
https://issues.dlang.org/show_bug.cgi?id=24838

Richard (Rikki) Andrew Cattermole <alphaglosined@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |alphaglosined@gmail.com
         Resolution|---                         |WONTFIX

--- Comment #1 from Richard (Rikki) Andrew Cattermole <alphaglosined@gmail.com> ---
This is a misunderstanding of what ``@nogc`` is.

It is a linting tool. It guarantees that no GC allocation will take place within the function.

The reason why the compiler is not putting the closure on the stack is because it could escape the call stack. Mark the delegate parameter in ``acceptsCallback`` as ``scope`` and this will work.

Without the escaping guarantees, using the GC is the correct solution in this situation, and therefore should error.

--
2 days ago
https://issues.dlang.org/show_bug.cgi?id=24838

--- Comment #2 from Manu <turkeyman@gmail.com> ---
Please think that through.

--
2 days ago
https://issues.dlang.org/show_bug.cgi?id=24838

Tim <tim.dlang@t-online.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tim.dlang@t-online.de

--- Comment #3 from Tim <tim.dlang@t-online.de> ---
This is independent of @nogc. Code not marked @nogc would also benefit from this.

--
2 days ago
https://issues.dlang.org/show_bug.cgi?id=24838

--- Comment #4 from Manu <turkeyman@gmail.com> ---
Correct, all code will benefit.
I just made the point because it's just particularly important for @nogc code,
where it is currently impossible to implement event-based systems conveniently.

--
1 day ago
https://issues.dlang.org/show_bug.cgi?id=24838

--- Comment #5 from anonymous4 <dfj1esp02@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.

--
1 day ago
https://issues.dlang.org/show_bug.cgi?id=24838

timon.gehr@gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |timon.gehr@gmx.ch
         Resolution|WONTFIX                     |---

--- Comment #6 from timon.gehr@gmx.ch ---
This is a valid enhancement request.

--