session
Update 13: The borrow checker
Region inference already prevented use-after-free. This update adds the other half of memory soundness: aliasing discipline, enforced at compile time, deliberately without lifetime parameters, variance, or Send/Sync traits.
Three rules, checked in a dedicated pass after typechecking:
- One
&mutborrow at a time. - Any number of
&borrows, but not while a&mutexists. - No mutation of a value while it is borrowed.
What makes it pleasant rather than painful:
- Field-wise borrows:
&s.xand&mut s.ycoexist; borrowing one field does not lock the whole struct. - Two-phase borrows: call arguments reserve first and activate later, so the common
v.push(v.len())pattern just works. - Non-lexical lifetimes (NLL): a borrow ends at its last use, not at the end of the scope, so
val r = &v; print(*r); v = 20;compiles. - No annotations: there are no
'aparameters anywhere in the language. Regions stay inferred. - Controlled by
--borrowck=off|warn|on.
Also in this update: val immutability is now a hard type error on reassignment and on struct-field mutation, and @send/@sync checks landed for thread-safety annotations.