Persistent list

Lionello Lunesu via Digitalmars-d digitalmars-d at puremagic.com
Mon Nov 16 08:58:22 PST 2015


On 16/11/15 22:45, Andrei Alexandrescu wrote:
> On 11/16/2015 08:51 AM, Marc Schütz wrote:
>> On Monday, 16 November 2015 at 02:26:29 UTC, Andrei Alexandrescu wrote:
>>> Yah, I agree with that argument. Probably @mutable is a more
>>> principled way to go about things.
>>
>> Glad to here that. I think the current transitive const system is really
>> good and shouldn't be watered down beyond necessity. And a @mutable
>> keyword, too, shouldn't just mean "immutability or const-ness end here",
>> thus allowing any kind of mutation. What we actually need for
>> immutable/const refcounting etc. is _non-observable mutation_, i.e.
>> physical mutability, but without observable effects outside of the
>> type's implementation (better yet, restricted to very short parts of it,
>> just like @trusted).
>
> The challenge is proving that a mutation is not observable. Got an
> attack on that? -- Andrei

Forgive me, I haven't followed the RC discussions closely, so I miss a 
lot of context. Feel free to point me to existing threads/articles.

If it's RC we want, then @mutable is an axe when what we need is a scalpel.

The non-observability comes from the fact the refcount is changed when 
the caller has lost its (const) reference and constness is a moot point. 
Changing refcount is fine now, provided the object is not immutable. As 
far as other outstanding const references go, these already expect 
changes to happen.

This is what makes refcount special and provably safe to mutate. As long 
as we can ensure the object is not immutable, the object is allowed to 
change its own refcount. But refcount needs to be special cased, 
somehow, or else we'll end up with some C++ like `mutable`.

Perhaps const-but-not-pure is the solution here. The object must be able 
to store (and have stored) a mutable reference, so it can use that 
reference to change the refcount. (This could be optimized to be a flag, 
since the mutable and const reference would refer to the same instance.) 
It means keeping track of const-but-mutable vs const-and-immutable 
references, and somehow telling the compiler that refcount is special.

L.


More information about the Digitalmars-d mailing list