News for hackers. Stuff that matters.
Re:The Next Step for Generics by erik_seaberg on Tuesday June 16, 2020 @07:56PM (#23545867)
Refcounting is GC; it automatically detects at runtime that an object has no references. It also adds a substantial cost that Rust is trying to avoid, often by copying immutable objects (which have better cache locality than random access to refcounts everywhere).
Re:The Next Step for Generics by bcrosby95 on Tuesday June 16, 2020 @08:02PM (#23545920)
I'm not talking about GC. I'm talking about Rust references:

https://doc.rust-lang.org/book/ch04-02-references-and-borrow...

> At any given time, you can have either one mutable reference or any number of immutable references.

Re:The Next Step for Generics by erik_seaberg on Tuesday June 16, 2020 @08:34PM (#23546221)
Oh, I get it, you're suggesting all references could be mutable, but still limited to the lifetime of the object. I guess the downside would be that you can't design an API like iterator invalidation that relies on "some (mutable) methods can't be called while any other (immutable) references exist".
Re:The Next Step for Generics by comex on Tuesday June 16, 2020 @08:51PM (#23546355)
It would mean that, once you obtain a derived pointer – say, if you start with a Vec<Foo>, a pointer to Foo that refers to the first element – you would have to throw away that pointer as soon as you made any function call whatsoever. After all, that function call might mutate the Vec<Foo> and cause the backing storage to be reallocated.

In practice, this is unworkable enough that it would basically forces you to reference count the Foo, so you could preserve pointers across calls by incrementing the reference count.

On the other hand, Rust's approach is suboptimal in cases where you're using reference counting anyway, or are willing to pay the cost of reference counting.