Allocator-aware @safe reference counting is still not possible

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Tue Jan 24 14:57:52 UTC 2023


On 25/01/2023 3:39 AM, Dukc wrote:
> I'm afraid it's more complicated than you think.

I expect it will be complicated. DFA for this sort of thing always is.

> `thing` might have its destructor called before the end of `got` 
> lifetime. The language could pretty trivially prevent doing that 
> directly, but what if you have a `scope` pointer to `thing` and call the 
> destructor via it? or a `scope SumType!(Thing*, int*)[5]` variable, that 
> may contain both references to both `thing`s and ints?

Yes, you need to track the 'real' owner for memory and ensure the right 
order of variable destruction.

> These are probably solvable, but the solution is going to be at least as 
> complex as `@live`, if not more so.

Considering @live isn't complete, I'd argue implementing @live is more 
complicated than @live ;)

The singular difference is @live is opt-in, function by function. This 
on the other hand isn't, which means its guarantees are actually real 
for memory safety.


More information about the Digitalmars-d mailing list