3 ms·
Good to see this. "There is another theme running through here: moving the borrow checker analysis out from the compiler’s mind and into types that can be expr
by Animats 2y ago
Good to see this.
"There is another theme running through here: moving the borrow checker analysis out from the compiler’s mind and into types that can be expressed. Right now, all types always represent fully initialized, unborrowed values. There is no way to express a type that captures the state of being in the midst of iterating over something or having moved one or two fields but not all of them. These changes address that gap."
I have some misgivings about trying to do everything with types. That leads to having to perform complex, hard to understand operations on types, as you add and remove restrictions. Keeping borrowing orthogonal from types may be clearer. Not sure about this, though.
I'd like to see back references addressed, so structs can have references to their owners.
General concept: when possible, do statically what Rc, Weak, and .borrow() can do for backlinks at run time. Such static analysis seems possible for non-mutable references.
Mutable is going to be tough, though. It's a lot like compile-time single-lock deadlock detection, where you try to check that the same lock is never locked twice in nested contexts.
- gpm 2y agoImmutable back references seem limiting... because how are you inserting things if you have a reference saying the thing you are inserting it into can't mutate. If you're willing to use locks or something for interior immutability though... I think it should already be possible. It works in a toy example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=faed8b1f5298ccf0f9a9a8f86bbbc6e1 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- Animats 2y agoRight. You can also do that with Rc and borrow. When nothing in the call tree is using the parent link, it should be OK to add children. That's potentially checkable at compile time.
- Animats 2y agoThinking about this some more, that example has a mutex in a single thread program. If it's ever reached while locked, the program is stuck. This is a demonstration that the backlink problem and single-thread deadlock detection are equivalent. Work on compile time deadlock detection for Rust is underway.[1] It's complicated, but do-able. [1] https://github.com/hlisdero/cargo-check-deadlock https://github.com/hlisdero/cargo-check-deadlock
- pas 2y agoAs far as I understand lifetimes are already in the types, just elided most of the time. (That said, the type system is already full of marker traits, so keeping complexity from growing more and more is always an important goal. Hooweeever, this also means that people are pretty used to markers, so their individual cost is amortized over all of them basically. And adding one more might make sense, especially if it can be elided in general.)