1. ← Home
Login
Valen's memory safety: a new kind of borrow checking
~devprogramming languages
verdagon.dev 2 weeks ago

Summary

From the article:

This post mainly focuses on the first piece: Valen's more relaxed borrow checker.

So in this post, I'll talk about what it is, what it can do, and how it works.

[...]

Every piece of data has only one owner (because single ownership), so every object has one path. 36

[...]

The compiler uses paths to detect use-after-free; it detects when we're dereferencing a reference that is pointing at data that has already been destroyed.

It does this with these two rules:

  • When we modify an object, we mark any reference pointing inside that object as "invalidated".

  • When we try to use an "invalidated" reference, the compiler shows an error.

[...]

We're receiving two parameter references, where we can mutate through the more specific one, and we can't mutate anything outside of it.

Valen adds this so that we don't have to do the classic borrow-checking pattern of taking in the entire world mutably.