Challenge: write a reference counted slice that works as much as possible like a built-in slice

Andrei Alexandrescu SeeWebsiteForEmail at erdani.com
Thu Nov 11 23:22:43 UTC 2021


On 2021-11-09 0:30, H. S. Teoh wrote:
> On Mon, Nov 08, 2021 at 10:38:59PM -0500, Steven Schveighoffer via Digitalmars-d wrote:
>> On 11/8/21 8:04 PM, deadalnix wrote:
>>> On Monday, 8 November 2021 at 22:40:03 UTC, Andrei Alexandrescu wrote:
>>>> On 2021-11-08 17:26, rikki cattermole wrote:
>>>>> a reference counted struct should never be const
>>>>
>>>> So then we're toast. If that's the case we're looking at the most
>>>> important challenge to the D language right now.
>>>
>>> Not necessarily, but this is in fact the same problem as the head
>>> mutable problem.
>>>
>>> If `const RCSlice!(const T)` can convert to `RCSlice!(const T)`,
>>> which it should to have the same semantic as slice.
>>>
>>> The reference counting problem goes away if you can mutate the head.
>>
>> The reference count cannot be in the head, it has to be in the block.
>> So this conversion is actually unsound.
> [...]
> 
> It could work if the block has a mutable counter at the top and the rest
> is immutable/const.  But the current type system cannot express such a
> thing; if the head is const, then it's const all the way down.

The mutable counter can be at a negative address that is not accessible 
to the "normal" type system. There's nothing wrong with having a piece 
of mutable data next to a piece of immutable data.



More information about the Digitalmars-d mailing list