Want reasonable reference counting? Disable automatic sharing of immutable

user1234 user1234 at 12.de
Mon Nov 15 12:35:12 UTC 2021


On Monday, 15 November 2021 at 11:40:45 UTC, Danni Coy wrote:
> On Mon, Nov 15, 2021 at 9:50 PM Elronnd via Digitalmars-d 
> <digitalmars-d at puremagic.com> wrote:
>>
>> On Monday, 15 November 2021 at 09:28:41 UTC, Danni Coy wrote:
>> > rather than punching a hole in const/immutable
>> >
>> > struct S
>> > meta {
>> > int refCount;
>> > ....
>> > }
>> > do {
>> >  int payload;
>> > ....
>> > }
>> >
>> > Immutable S s is now conceptually an immutable object and a
>> > mutable
>> > object with metadata behind the scenes
>> > that feels like a single object from a user perspective?
>>
>> That is functionally the same thing as '__mutable int 
>> refCount', discussed elsethread.
>
>>From an implementation point of view maybe. It has the 
>>advantage of
> having the linguistic model match what the compiler is doing 
> behind the scenes (making it easier to reason about / 
> conceptualise).
>
> Would it be possible to limit operation of the writeable 
> components to a small subset of the language which would allow 
> the necessary operations but remove a lot of the complications?

Yes using special case in the compiler, special case in the type 
system.
(looks like "meta" is a bit like "__mutable", which's been 
discussed previously).

In the domain of special cases I'd prefer a built-in reference 
counted
"type next", e.g like `[]` `*`, that says rather than an 
attribute created _just to have the library solution to work_.






More information about the Digitalmars-d mailing list