On Wednesday, 12 November 2014 at 15:57:18 UTC, Nick Treleaven
wrote:
On 11/11/2014 18:01, bearophile wrote:
I agree it's a very important topic (more important/urgent
than the GC,
also because it reduces the need of the GC). But I think
Walter thinks
this kind of change introduces too much complexity in D
(despite it may
eventually become inevitable for D once Rust becomes more
popular and
programmers get used to that kind of static enforcement).
I think Rust's lifetimes would be a huge change if ported to D.
In Rust user types often need annotations as well as function
parameters. People tend to want Rust's guarantees without the
limitations. I think D does need some kind of scope attribute
verification, but we need to throw out some of the guarantees
Rust makes to get an appropriate fit for existing D code.
Have you seen my proposal?
http://wiki.dlang.org/User:Schuetzm/scope
It takes a slightly different approach from Rust. Instead of
specifying lifetimes, it uses owners, and it's also otherwise
more simple than Rust's system. E.g. there is no full blown
borrow checker (and no need for it).
For example, taking a mutable borrowed pointer for a variable
means you can't even *read* the original variable whilst the
pointer lives. I think no one would try to make D do that, but
Rust's reason for adding it is actually memory safety (I don't
quite understand it, but it involves iterator invalidation
apparently). It's possible their feature can be refined, but
basically 'mut' in Rust really means 'unique'.
In my proposal, there's "const borrowing". It still allows access
to the owner, but not mutation. This is necessary for safe
implementation of move semantics, and to guard against iterator
invalidation. It also has other uses, like the problems with
"transient range", e.g. stdin.byLine(), which overwrite their
buffer in popFront(). On the other hand, it's opt-in; by default,
owners are mutable while borrowed references exist.