r/ProgrammingLanguages • • Oct 19 '26

Borrow Checking Zero-Cost Cyclic Mutability

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

8 comments sorted by

View all comments

Show parent comment

1

u/RndmPrsn11 Oct 19 '26

I'd push back on any of the rules for loops or closures being hacky. They follow rules for moves 1:1 so I think they're quite clean actually. The rules for effect handlers are a bit hacky I think, but also not yet finalized from a design standpoint. I hope to have time again soon to find a cleaner solution there.

Creating a reference to p! would introduce an obligation that p itself must not be mutated for the lifetime of that reference

The relationship is already encoded in the unstable place so I don't think a new trait would be necessary (Mutate itself is also technically unnecessary with polymorphic refs).

should require immutability of an abstract field representing the parent's shape

The invalidation rules already model the immutability rule you mention. Abstract places would be a useful thing to have, I mention them in footnote 6, but they're currently unimplemented. Thankfully, most commonly used types in the stdlib don't require this. Something like Vec for example is fine with loaning elements as 'v! without a dedicated 'v.elements! since there is no other source of unstable refs it needs to differentiate from.

1

u/initial-algebra Oct 19 '26 edited Oct 19 '26

I'd push back on any of the rules for loops or closures being hacky. They follow rules for moves 1:1 so I think they're quite clean actually.

Maybe those ones aren't "hacky" per se, but reasoning about "when can a p! exist" and "when can p be mutated" in terms of sets of program points that must be disjoint (and then making the leap to abstraction over sets of program points) is a unifying semantic principle vs. having ad-hoc syntactic rules for those constructs.

The relationship is already encoded in the unstable place so I don't think a new trait would be necessary

Currently, you could infer Stabilize p from the mention of p!, but, in general, a function would still need to mention Stabilize p even if it only ever creates and uses p! references internally, to prevent a concurrent Mutate p from existing.

The invalidation rules already model the immutability rule you mention.

Yes, but the point of reframing stability as immutability of a special field is to generalize to immutability for other purposes, such as multi-threading.