Want reasonable reference counting? Disable automatic sharing of immutable
Steven Schveighoffer
schveiguy at gmail.com
Sun Nov 14 21:12:48 UTC 2021
On 11/14/21 2:16 AM, Walter Bright wrote:
> On 11/12/2021 4:31 AM, Steven Schveighoffer wrote:
>> One of the prerequisites to doing reference counting is to have a
>> mutable piece of data inside an immutable piece of data.
>
> Or maybe just give up on having immutable ref counted objects. Ref
> counted objects are mutable.
First, I'll note that `__mutable` on its own is perfectly sound. The
biggest problem is that `immutable(T)` no longer would mean "fully
immutable", which removes a lot of optimizations (including strong-pure)
-- even in the case of a type that doesn't have any `__mutable` in sight.
I'm fine with giving up on it. But...
https://forum.dlang.org/post/smc5jb$2u8t$1@digitalmars.com
- work with qualifiers like T[] does, both RCSlice!(qual T) and
qual(RCSlice!T)
...
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.
We need a change of requirements if we want to give up on immutable
reference counting.
-Steve
More information about the Digitalmars-d
mailing list