Valen's Borrow Checker Lets Multiple References Mutate the Same Data

Valen's Memory Safety: A New Kind of Borrow Checking

Valen introduces a flexible borrow checker based on group borrowing, which relaxes the shared-xor-mutable rule to only prevent use-after-free. The compiler tracks where each reference points, allowing patterns like multiple mutable references to the same object—common in C++ but previously impossible to check at compile time. This approach has already influenced Carbon, Ante, and other languages, and Valen aims to interoperate with Rust.

But group borrowing actually resolves the conflict, by relaxing "shared-xor-mutable" to "no use-after-free".
  1. kvark

    It sounds more like "path" borrowing than "group" borrowing to me, but the idea is great! Quite eye opening!

    One minor thing is that I'm not sure why they had to have "in" keyword for sub-borrows. Wouldn't it be more consistent to see "entity &world.entities[?]" instead of "entity in world.entities[]"? We'd consistently get the borrow "&" symbol and open the door for some contracts on what index (range) is affected.

  2. zamalek

    > Borrow checking has the "shared-xor-mutable" restriction: if you hold a reference to an object, nobody else can change the object.

    The article makes this sound like a problem. It isn't. This restriction frees you from thinking about certain classes of bugs in concurrent code; it's where the "fearless concurrency" comes from. R^w isn't about lifetimes - you could, in spirit (not sure about practice), remove it from Rust without affecting use-after-free at all.

    Of course, it means you can't write many completely valid programs, and so we'd hope there's a better solution, but removing it is not one.

    If you want to have to think about that (and potentially introduce bugs), that's perfectly fine. The flexibility of not requiring r^w is extremely useful. I'm just clearing up this mis-attribution.

  3. SleepyMyroslav

    This looks cool for code-driven systems where code has static knowledge of every path in the system. It might be strictly better for things like rendering where types of rendering are code-driven. Like your world can have skybox and such. The examples assuming gamedev 'world' and 'entity' are completely misleading though. Because I think everyone has moved on to data-driven worlds. Think of entity 'advance' from the code examples as an 'entity blueprint execute'.

  4. melodyogonna

    Mojo's origin can represent a lot of these semantics. I think a lot was learned from Nick's proposal, even if it wasn't directly implemented. Here is an example of how you could represent the first snippet, where two references can update the same list: https://godbolt.org/z/78bhzWjYM

  5. verdagon

    Also, as I was writing this, a couple things occurred to me:

    * We _could_ use the function parameter syntax `entities: &world.entities[]` instead of `entities in world.entities[]`.

    * "Groups" aren't really central to understanding the idea, so Path Borrowing might be a better name than Group Borrowing.

    Opinions welcome =)

More from this day

2026-10-11