Want reasonable reference counting? Disable automatic sharing of immutable

Dukc ajieskola at gmail.com
Sat Nov 13 18:32:02 UTC 2021


On Friday, 12 November 2021 at 12:31:03 UTC, Steven Schveighoffer 
wrote:
> I've come to the conclusion, in order to fix this situation, so 
> `__mutable` really means mutable and `shared` is an orthogonal 
> piece, you need to remove the implicit sharing of `immutable`. 
> While it can make sense, the conflation of the two concepts 
> causes impossible-to-fix issues. Not just mutable, things like 
> thread-local garbage collection might be easier if you have to 
> explicitly share things.
>
> -Steve

I'd rather keep `immutable` fully transitive. That's how it's 
designed to work, and does at least some things well, like 
allowing multithearded access. With some mutable gaps it's going 
to have many of the problems of C++ `const`, and also more 
complicated. Plus no changes needed.

I do not think having an immutable counted reference is 
necessary. With present `immutable` we can still have a mutable 
counted reference to immutable payload. It does mean some extra 
complications if the reference is itself stored in immutable 
data, but the cure would be worse than the disease I think.

If we drop the immutability requirement from the reference, we 
can have `@safe pure @nogc` reference counting, or can we?


More information about the Digitalmars-d mailing list