Want reasonable reference counting? Disable automatic sharing of immutable

Walter Bright newshound2 at digitalmars.com
Mon Nov 15 07:05:18 UTC 2021


On 11/14/2021 1:12 PM, Steven Schveighoffer wrote:
> First, I'll note that `__mutable` on its own is perfectly sound.

I don't think so. It produces two kinds of immutability - one with mutable 
members, one with not. Different rules apply.

But then what do you do with opaque types? The compiler doesn't know which kind 
of immutable they are. So it is forced to go with the worst case - immutables 
are mutable. And it all falls apart.


>      2. Qualifiers compound problems with interlocking: mutable data is known to 
> be single-threaded, so no need for interlocking. Immutable data may be 
> multi-threaded, meaning reference counting needs atomic operations. Const data 
> has unknown origin, which means the information of how data originated (mutable 
> or not) must be saved at runtime.

Right.

> We need a change of requirements if we want to give up on immutable reference 
> counting.

Yup.



More information about the Digitalmars-d mailing list