Want reasonable reference counting? Disable automatic sharing of immutable
tsbockman
thomas.bockman at gmail.com
Fri Nov 12 19:22:57 UTC 2021
On Friday, 12 November 2021 at 18:12:14 UTC, Andrei Alexandrescu
wrote:
> On 2021-11-12 8:03, Timon Gehr wrote:
>> On 12.11.21 13:31, 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`.
>>
>> I agree, that would be much better.
>
> We discussed this a couple of times. It's interesting. Sadly at
> this point implicit thread sharing of immutable is so baked
> into the language, it would take a lot of care to extricate. It
> would be very difficult even for Timon or Paul.
Just track whether an RC target needs atomic RC operations at
compile time, using the template parameters of RC types. No
changes to language semantics are necessary.
For example, reject attempts to assign an `RCPtr!(immutable T)`
to an `RCPtr!(const T)`, while allowing assignment to a
`RCPtr!(shared const T)`. Borrowed payloads can and should follow
the normal D qualifier conversion rules.
Or, if more granularity is needed, use a separate template
parameter:
```D
struct RCPtr(T, bool sharedMeta = is(T == shared))
```
More information about the Digitalmars-d
mailing list