Rebooting the __metada/__mutable discussion

Timon Gehr timon.gehr at gmx.ch
Sun Apr 10 15:35:05 UTC 2022


On 10.04.22 17:04, Alexandru Ermicioi wrote:
> On Friday, 8 April 2022 at 18:00:14 UTC, rikki cattermole wrote:
>> Here is my test code that I used to determine what I needed to do to 
>> make const RC types useless (and hopefully safe).
>> ...
> 
> Isn't better then to try and find design patterns or rules for use with 
> mutable RC structures?
> 
> All the talk across the years was basically about trying to eat the 
> pancake and also at same time trying to keep it for later, and neither 
> is done after all deliberation across the years. Perhaps it would be 
> best to just break the existing immutable system, and redefine it to 
> allow rc features found in C++ or other languages, or just have a 
> limited version of rcs in D (compared to C++ or other languages 
> employing them), and workaround those restrictions through some well 
> defined rules and design patterns.
> 
> And when mentioning breaking the immutable system, I really mean 
> breaking it, by removing the transitiveness it has, or some other major 
> change, like not being really immutable, and therefore safe to put in 
> readonly memory.
> 
> 

I think the solution of this particular issue should come down to one of:

- accept that `immutable` means immutable, only use it where it actually 
makes sense to enforce that restriction, derive valid compiler 
optimizations from a specification based on UB. No immutable RC is 
allowed. `immutable` values can always be put in readonly memory, simple 
story for CTFE accessing immutable values.

- accept that there could potentially be mutable parts in `immutable` 
structures exclusively for low-level purposes, separate `immutable` and 
`shared immutable`, explicitly specify valid compiler optimizations 
based on nondeterministic semantics. Immutable RC is a thing. Whether or 
not `immutable` values can be put in readonly memory depends on the 
particular type, more complicated story for CTFE accessing immutable values.

Anyway, this is by far not the only issue with qualifiers applied to 
user-defined types. Built-in slices and pointer types have magical 
interactions with qualifiers that user-defined types cannot reproduce.


More information about the Digitalmars-d mailing list