How Dada Enables Internal References
This post dives deep into Dada, a new language that aims to improve upon Rust's borrow checker by introducing 'place-based permissions,' making self-referential data structures much more ergonomic. It demonstrates how Dada's unique reference model, which treats references as shallow copies rather than pointers, allows for previously borrowed data to be moved and automatically re-referenced. The author, a notable Rust contributor, suggests that these innovative concepts could potentially influence future Rust development, sparking interest in programming language design circles.
The Lowdown
The author introduces Dada's permission system, a novel approach to managing data ownership and borrowing that aims to surpass Rust's capabilities. Unlike Rust's lifetime system, Dada employs 'place-based permissions,' which explicitly link borrowed data to the variable it originated from, opening up new possibilities for structuring data.
- Rust's Challenge: The article highlights a common Rust ergonomic issue: creating a struct that holds both an owned value (e.g., a
String) and references to parts of that same value (e.g., aVec<&str>). Rust's borrow checker typically prevents this due to rules around moving borrowed data. - Dada's Solution: Dada addresses this by naming the place a reference comes from (e.g.,
ref[list] Stringinstead of a lifetime parameter). This allows for aMessagestruct to safely contain aStringandVecof&strs that refer to itsStringfield. - References as Values: In Dada, references are not raw pointers but shallow copies of the value. Moving the original variable does not invalidate these references because they don't point to the stack location of the original variable, but rather track the underlying heap data.
- Strong Updates: Dada's type system uses 'strong updates,' meaning that when a value is moved (e.g., from
chtoch1), any references borrowed fromchautomatically update their type to reflect being borrowed fromch1. - Application to Rust: The author believes many of Dada's concepts, particularly place-based permissions, could be adapted for Rust, especially with ongoing work like 'Field Projections,' which aims to enhance self-referential patterns within Rust's existing memory model.
While the full implementation of these advanced features in Dada is still a work in progress (currently modeled in dada-model), the demonstrated concepts offer a compelling vision for how programming languages can evolve to provide greater flexibility and safety in managing complex data structures.