Persistent list
Marc Schütz via Digitalmars-d
digitalmars-d at puremagic.com
Tue Nov 17 01:43:38 PST 2015
On Monday, 16 November 2015 at 14:45:35 UTC, Andrei Alexandrescu
wrote:
> The challenge is proving that a mutation is not observable. Got
> an attack on that? -- Andrei
Here's what I wrote a few days ago, without having read the
current discussion, so it's not a perfect fit:
http://wiki.dlang.org/DIP85
For the case of lazy initialization, assigning a member exactly
once is safe, if it hasn't been read and returned before. The
compiler can check this by automatically inserting a few asserts.
The rules in the DIP aren't completely water-tight, but they are
a good approximation.
But for members that have to be mutated several times (e.g.
refcount), this obviously isn't useful. I think we can make this
@system, thereby forcing implementors to write @trusted code and
(hopefully) consider the consequences thoroughly. But the
compiler can also assist with that. For example, it could detect
whether a "privately mutable" value, or something depending on
it, is returned from the function, and reject that.
Maybe the implementation for the two kinds of use-cases (write
once vs write multiple times) can be unified, too.
More information about the Digitalmars-d
mailing list