Want reasonable reference counting? Disable automatic sharing of immutable

Steven Schveighoffer schveiguy at gmail.com
Fri Nov 12 19:22:35 UTC 2021


On 11/12/21 1:12 PM, 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.

I'm not going to fight for this, I just wanted to bring it up. But I 
think it's pointless to try for reference counting of immutable data 
(the long RCSlice thread), when it's obviously not immutable data.

The only solution is to make it not mean the same as immutable does now 
(i.e. possibly shared). The fact that `shared(immutable)` would mean the 
same thing as `immutable` does now is a path forward, but I can 
understand if nobody wants to do that. I happen to think most cases 
people are not sharing their immutable data, just like they mostly 
aren't sharing thread-local data.

-Steve


More information about the Digitalmars-d mailing list