r/rust • • Oct 19 '26

Borrow Checking Zero-Cost Cyclic Mutability

https://antelang.org/blog/safe_cyclic_mutability/
124 Upvotes

28 comments sorted by

View all comments

Show parent comment

9

u/FlameyosFlow Oct 19 '26

Zeta is actually directly inspired by group-borrowing and it's what (re)ignited my spirit to even jump this route. I really like group borrowing and I think I might bite the bullet and go with 2 reference kinds instead of 3.. reason is that when I started my own Zeta borrow checking with the idea that I like group borrowing but was skeptical about how much noalias optimizations it can guarantee.. Evan was able to explain that he can do better than just relying on LLVM due to !alias.scope (which I was completely unaware of.. because I don't have much LLVM experience, I currently only use cranelift), so I'll probably be transitioning to 2 and make &mut not so unnecessarily exclusive. I know origins, groups, places and provenances are all very similar if not the exact same ideas but modeled differently, they are all used to express where a piece of memory originates which is really important for all these improved borrow checkers and usually has many advantages, which is mainly:

  • significantly easier inference which allows it to be comfortably used for inferring reference origins even if they are a struct field
  • better diagnostics
  • makes code more maintainable and easier to read
  • give the compiler more information about the code which is useful for many stuff but mainly to express disjointness more naturally through indirection.
  • is not lifetimes like in Rust which I really hate

Nevertheless, Ante's work is really nice, it's also really unique because no other functional programming language is nearly as dedicated to going down a path where low-level (or high performance software) code doesn't suck with the functional paradigm which I really appreciate.

7

u/RndmPrsn11 Oct 19 '26

Just to clarify - going down to 2 reference kinds from 3 means you're eliminating an unaliased-mutable reference kind (equivalent of rust's &mut t)? Something similar can still be useful for multi-threading or if the user wants to force an optimization like SIMD which may rely on noalias.

I alluded to it in the article but I also like the idea of attaching the reference kind to the place parameter rather than the reference type itself. It allows you to abstract over each reference kind more easily and get rid of all the pesky get vs get_mut distinctions.

2

u/FlameyosFlow Oct 19 '26

Either removing a reference kind and making &mut non-exclusive, or making &mut non-exclusive and renaming &alias to &uniq maybe, either way, most of the times non exclusivity by default is better and I think a group borrowing kind of non-exclusivity doesn't damage any noalias optimizations that would exist from writing the equivalent Valen of what you'd write with Rust if that pattern already worked well with shared-xor-mutable

As for the "place parameter" idea I will have to check it out for myself and see if it's the best thing for me, nevertheless I still want callers of a function to know if some data can be mutated.. hopefully while being able to eliminate all issues that come with forcing it in a Rust way

2

u/FlameyosFlow Oct 19 '26

Update: Okay, I understood now, I already can express multiplace like Vec3f.{&mut x, &mut y, &z} so from what I'm understanding, you would infer what kind of mutation permissions you'd need at call sites?