logoalt Hacker News

0c3ca83 • yesterday at 7:15 PM • 1 reply • view on HN

This only works if you make every allocation its own plane, and scope all borrows to the lifetime of the plane, with a move terminating all borrows, at which point this is equivalent to rust, just with confusing jargon.


Replies

jordan_bonecut • yesterday at 8:48 PM

Correct, every allocation is its own plane. The nice thing about this model is that you don't need to explicitly call out lifetimes. I also believe that lifetimes aren't really a good model of what actually happens in memory. This model is more powerful because it understands relationships between planes in memory, which Rust's model doesn't. This is why it requires mutable borrows to be unique which is oftentimes overly restrictive. For instance this is not valid Rust:

let x = vec![1, 2, 3]; let a = &mut x[0]; let b = &mut x[1]; swap(a, b);

Because Rust doesn't really know the difference between the whole Vec an element within the vec. Therefore it treats any mutation as one that could potentially invalidate anything with the same lifetime and doesn't compile. So I believe the plane model to be strictly better because it allows for this and still prevents the real scary thing:

let x = vec![1, 2]; let a = &mut x[0]; x.push(3); a = a + 1;

➕ show 1 reply