Prevent struct going into heap memory

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Mon Jul 21 00:31:10 UTC 2025


On 21/07/2025 12:00 PM, Paul Backus wrote:
> On Sunday, 20 July 2025 at 17:04:11 UTC, Richard (Rikki) Andrew 
> Cattermole wrote:
>> In response to some concerns around the situation for RAII structs 
>> going into closures, I am proposing a resolution to this that will be 
>> a language-wide guarantee, not an ultra-specific, not-a-guarantee 
>> solution.
>>
>> https://github.com/dlang/dmd/issues/18704
>>
>> If a struct destructor is annotated with an attribute ``@stackonly`` 
>> it may only be called if the ``this`` pointer is allocated on the 
>> stack. It does not overload.
> 
> Isn't the obvious solution to this bug (and related ones like [issue 
> #19119][1]) to simply skip the end-of-scope destructor call for structs 
> that are allocated in heap closures? Why introduce this weird, special- 
> purpose hack instead of fixing the root cause of the problem?
> 
> [1]: https://github.com/dlang/dmd/issues/19119

Ah see, I am arguing that the GC should handle cleanup.

Problem is, some people believe it shouldn't. Hence this proposal to 
give those that want that "reliability" control to make it so.



More information about the dip.ideas mailing list