HN
Today

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.

10
Score
2
Comments
#11
Highest Rank
3h
on Front Page
First Seen
Mar 1, 7:00 PM
Last Seen
Mar 1, 9:00 PM
Rank Over Time
111323

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., a Vec<&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] String instead of a lifetime parameter). This allows for a Message struct to safely contain a String and Vec of &strs that refer to its String field.
  • 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 ch to ch1), any references borrowed from ch automatically update their type to reflect being borrowed from ch1.
  • 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.