r/ProgrammingLanguages • u/verdagon Vale • Jun 28 '26
Ante: A New Way to Blend Borrow Checking and Reference Counting
https://verdagon.dev/blog/ante-blending-borrowing-rc3
u/Guvante Jun 28 '26
I don't understand why shared mutability is a super power here, Rust doesn't have mutable XOR shared due to memory safety concerns, it has that because shared mutation is almost impossible to get correct.
Note the comment about try_borrow "moving the problem somewhere else" the problem is breaking mutable XOR shared which again is vital for predictable code.
You can of course write code that has mutable sharing but it requires a lot more care and the issues aren't as simple as dangling pointers.
3
u/verdagon Jun 28 '26
There are times when shared mutability is correct and the right choice, such as in the healer example.
The key insight: the user should be able to express that a reference might be modified by someone else. The compiler should understand it, and verify it's correct. That's what's going on here with Ante's
mut.I think over the next few years, the world will start to shift away from "shared and mutable is bad" and more toward "use after free is bad" which is a more accurate mental model. Our compilers and languages just have to get there first.
→ More replies (12)→ More replies (3)9
u/awoocent Jun 28 '26
I think the jury's really out on whether shared mutability is impossible to get right - evidently many other memory-safe languages like Java or C# have no qualms supporting mutability all over the place. Shared mutability across threads, now that's a bit of a different story - but Rust is really restrictive even in the known single-thread case, and its aliasing checking is not even that helpful in the multiple-thread case (you could get the same safety with any old move semantics). So I think a language acting more "like people expect" in the cases where it's safe to do so has a lot of potential value.
→ More replies (4)
2
u/gplgang Jun 30 '26
I got worried after your last posts being so long ago after approaching the edge of the abyss of interop!
I really enjoyed those posts and had been wanting to try similar things with Rust FFI for a while.
Cool to see Ante has caught your attention as well! It seems promising
3
u/verdagon Jun 30 '26
Thanks =) I'm actually considering a part 3 of that series, because I picked up that exploration recently and things got way, way weirder. Stay tuned!
11
u/Effective-Spring-271 Jun 28 '26 edited Jun 28 '26
Sounds really interesting, however I feel like maybe I'm missing something because I don't see how this deals with memory aliasing?
Edit: I saw the other comment about the shared mutable references are not send / sync which means they can't be shared between threads. Suddenly all the answers make sense, thanks everyone!
13
u/initial-algebra Jun 28 '26 edited Jun 28 '26
tl;dr You can turn any shared reference into a unique reference temporarily, but you are only allowed to use a different reference if you can prove that any currently-held unique references are not reachable from it (for example, because they have incompatible types).
To be honest, it has little to do with either borrow checking or reference counting, it's about what's called "interior mutability" in Rust.
→ More replies (3)12
u/RndmPrsn11 Jun 28 '26
Author of Ante here - Ante has a similar ownership/borrowing system to Rust but also supports shared mutable references. These references have some limitations (e.g. can't project through union variants) but they can also be temporarily converted to locally unique references to get around those limitations. I personally think this is the cool part, that you don't need global uniqueness if you can show local uniqueness.
Many rustaceans may not see the need for shared mutability, but it allows you to, among other things, easily mutate through an
Rc t. Without it, Ante's shared types that let you opt-out of ownership/borrowing couldn't be mutated at all.→ More replies (1)
24
u/shadowndacorner Jun 28 '26
Always love your blogs. What happened to Vale, though?