[Dlang-study] [lifetime] Few root decisions to take on RC classes

Andrei Alexandrescu andrei at erdani.com
Thu Jan 14 17:10:44 PST 2016


On 01/14/2016 06:29 PM, Amaury SECHET wrote:
> The proposed solution is not safe at all. It guarantee that the payload
> is alive, but doesn't guarantee it is not moved.

How do you mean it would be moved?

> The Rust road is to disable whatever is borrowed from in a mutable
> fashion, and const whatever is borrowed from in a const fashion. The
> alternative is to borrow from the copy rather than just root it.
> Alternatively, root the object but [borrow from/pass down] the rooted
> object rather than the original, so effectively to don't pass down twice
> the same thing.

The sketch is attractive indeed, but the devil is in the very many 
details. I think adopting this model would be too large a change for us. 
Also it doesn't seems Rust is taking the world by storm, which makes it 
more risky to copy from it.

> This has a nice added bonus that ref parameters can be considered
> noalias and the optimizer can do more (alias analysis is probably the
> number 1 barrier for modern optimizers). Almost all benchmark where Rust
> beat C++ is due to extra alias informations.

Yah, that is a nice perk.


Andrei



More information about the Dlang-study mailing list