Store mutable indirections in immutable data with this one weird trick!

Timon Gehr timon.gehr at gmx.ch
Sat Nov 13 09:37:41 UTC 2021


On 11/13/21 10:06 AM, tsbockman wrote:
> On Saturday, 13 November 2021 at 08:32:42 UTC, Timon Gehr wrote:
>> On 13.11.21 09:30, tsbockman wrote:
>>>>
>>>
>>> That's a compiler bug.
>>
>> Nonsense. Results of strongly pure function calls implicitly convert 
>> to immutable. Your "fix" just avoided purity inference.
> 
> I see. This does not appear to be documented anywhere in the spec at the 
> moment.
> 
> I found definitions for "strongly pure" and "pure factory function", but 
> nothing about exceptions to the normal implicit conversion rules. After 
> being defined, the latter term is never used again in the spec.
> 
> There is also no mention of this in the "Creating Immutable Data" section:
>      https://dlang.org/spec/const3.html#creating_immutable_data

Yes, the documentation around qualifiers is pretty incomplete in 
general, which is one of the problems plaguing this discussion. The 
specification does clearly state that Paul's trick is not allowed though.

NB: This is the relevant bit of DMD source code:
https://github.com/dlang/dmd/blob/master/src/dmd/dcast.d#L856-L872


More information about the Digitalmars-d mailing list