Rebooting the __metada/__mutable discussion

rikki cattermole rikki at cattermole.co.nz
Wed Apr 6 12:08:44 UTC 2022


On 06/04/2022 11:43 PM, 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. Also reference 
> counting with immutable objects doesn't make any sense.
> 
> 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. This means that you will cast away whatever you need in 
> order to get the job done.

There are alternatives: 
https://forum.dlang.org/post/t2eo0t$mg7$1@digitalmars.com

It is my opinion that a purpose built escape hatch will be better than a 
generic escape hatch. Far less code that you need to review.


More information about the Digitalmars-d mailing list