Allocator-aware @safe reference counting is still not possible

Paul Backus snarwin at gmail.com
Sun Sep 25 17:19:45 UTC 2022


On Sunday, 25 September 2022 at 17:04:51 UTC, Sebastiaan Koppe 
wrote:
> On Sunday, 25 September 2022 at 14:23:22 UTC, Paul Backus wrote:
>> If you have `isolated`, the deallocator can be made `@safe` by 
>> having it take an `isolated` pointer as its argument.
>
> That would be nice, but doesn't that tantamount to only being 
> able to deallocate something when you can proof there are no 
> other aliases?

That's a necessary condition for being able to deallocate memory 
in `@safe` code, period. You can only do it if it doesn't create 
any dangling pointers.

> At which point you might as well use that proof and have the 
> compiler call deallocate for you ;)

Not necessarily. The proof is allowed to rely on runtime 
information, like reference counts, which the compiler does not 
necessarily know about. In these cases, the programmer can cast 
the pointer to `isolated` in `@trusted` code (similar to how you 
can cast away `shared` in `@trusted` code after locking a mutex).


More information about the Digitalmars-d mailing list