Helping with __mutable (which will be renamed to __metadata)
Timon Gehr
timon.gehr at gmx.ch
Sat Apr 13 08:56:57 UTC 2019
On 13.04.19 02:45, Andrei Alexandrescu wrote:
> Razvan Nitu is working on the DIP initiated by Timon Gehr,
(Disclaimer: Note that the current state of the DIP is significantly
different from my original proposal, and I would not argue for
acceptance of the current state of the DIP even though I am listed as an
author.)
> known
> colloquially as the one that introduces __mutable - i.e. a mechanism for
> allowing controlled changes to immutable data. Here's a draft:
>
> https://github.com/RazvanN7/DIPs/blob/Mutable_Dip/DIPs/DIP1xxx-rn.md
>
> We figured that we're dealing a misnomer - we don't want __mutable, but
> instead __metadata - information that is nominally part of the object
> but needs certain leeway from the type system. Typical use cases are:
>
> * reference counting of immutable data structures
For that you need the more general (originally supported using __mutable
functions):
* manual allocation and deallocation of immutable data
> * caching
> * lazy evaluation
>
> We got stuck at the interaction of __mutable with const parent objects
> (unclear whether the parent object originated as immutable or
> unqualified),
I think we got that one sorted out.
> and how pure functions should deal with __mutable. The few
> solutions we are toying with are either incomplete or too complicated
> (or both).
>
> The help of a few PL and compiler specialists would be very valuable
> here. I'm cc'ing a few, if anyone wants to help please let us know.
If the principled approach is too complicated, the feature is not worth
it. My original proposal was to define a set of rewrites that is based
on the function signature alone which is semantics-preserving if there
is no __metadata (except possibly reference identity of immutable data),
and then say that this set of rewrites is still permissible even if
there are __metadata annotations. If complexity of the DIP is a concern,
I guess we could simplify this by just saying that any rewrite based on
the function signature alone that is sound without __metadata will
remain permissible with it.
More information about the Digitalmars-d
mailing list