Rebooting the __metada/__mutable discussion

Timon Gehr timon.gehr at gmx.ch
Wed Apr 6 17:48:50 UTC 2022


On 06.04.22 13:43, IGotD- wrote:
> On Wednesday, 6 April 2022 at 09:41:52 UTC, RazvanN wrote:
>>
>> We need this to be able to implement generic reference counting. So 
>> our main
>> problem is how do we reference count immutable/const objects. Timon's 
>> original
>> proposal tried to implement __metadata in a way that does not affect 
>> purity
>> based optimizations. I think that this could be done:
> 
> Immutable and mutable variables don't mix well at all. With immutable 
> there is a high probability that it ends up in read only memory so any 
> poking around there will cause the program to crash.

The decision whether or not to place `immutable`-qualified data in 
read-only memory is made at a point where the memory layout of that type 
is known. Just don't do it if there are any `__mutable` fields.

> Also reference counting with immutable objects doesn't make any sense.
> ...

That's not so clear.

> When it comes changing data on const objects such as reference counting, 
> I think that this is low level code that works under the hood of the 
> actual language.

Yes, this is all in the realm of @system code.

> This means that you will cast away whatever you need in 
> order to get the job done.
> 

That's disallowed by existing language rules, hence the need to make 
some modifications to the specification.


More information about the Digitalmars-d mailing list