On Monday, 21 July 2025 at 02:03:54 UTC, Paul Backus wrote:
>On Monday, 21 July 2025 at 00:31:10 UTC, Richard (Rikki) Andrew Cattermole wrote:
>Problem is, some people believe it shouldn't. Hence this proposal to give those that want that "reliability" control to make it so.
If there are people who believe that (a) the struct instance should be allocated with the GC, but (b) the GC should not be responsible for its cleanup, then those people are wrong, plain and simple.
On the other hand, if people want to assume control over both the allocation and the cleanup, that's already possible with existing language features.
Not calling destructors at the end of the scope that a variable is declared in is a recipe for disaster.
For example:
{
auto conn = lockConnection();
arr.map!(val => conn.send(val)).each; // allocates `conn` into a closure, because reasons.
}
{
auto conn2 = lockConnection(); // if conn.dtor not run, then this is a deadlock.
}
The better option is to not make arbitrary decisions that affect semantics of RAII.
My suggestion for fixing this problem is to explicitly allocate the struct on the heap, and allow the compiler to merge that into a closure if you want to optimize that allocation (probably not worth it, but if you feel it's important, go for it).
Note that erroring when allocating a struct with a destructor used to be an error, but was made not an error with a "hack" that was supposed to be temporary, but just was left there.
-Steve