What is the Status of __mutable ?

Nicholas Wilson iamthewilsonator at hotmail.com
Thu Dec 20 12:16:05 UTC 2018

On Thursday, 20 December 2018 at 10:47:18 UTC, Vijay Nayar wrote:
> During the DConf of 2018, there was a talk about possibly 
> introducing __mutable into the D Language, which has utility in 
> allowing synchronization objects like locks, reference counts, 
> and lazy initialization to be used for objects that are 
> otherwise const or immutable. It was also stated that reference 
> counts are already being maintained by the "monitor", which I 
> know little about other than that it's built into the language 
> and that user code does not have the same privileges.
> However, the __mutable feature could open up problems in terms 
> of the compiler's ability to optimize generated code and 
> knowing which CPU L1/L2 caches are valid or not.
> What is the current status of this work? Have there been any 
> significant or unexpected hurdles that have come up? Any major 
> accomplishments?
> The most significant reason for my question is my own ignorance 
> of the normal communication channels in use. Apologies for the 
> spam if this information has already been shared elsewhere, but 
> a link to that information would be appreciated.

There is an implementation laying about in the PR queue: 

IIRC the motivating examples for __mutable were:
* Monitor for immutable classes
* Refcount fields for RC objects
* References to allocators in immutable containers

Immutable monitors can use a singleton mutex.
For RC objects I'd rather see opHeadMutable implemented (const 
T!B <-> T!(const B) ).
I'm not convinced of the utility of immutable containers (not to 
be confused with containers with immutable elements which are 
useful), see also opHeadMutable.

More information about the Digitalmars-d mailing list