# Valen's borrow checker walks functions backwards to catch use-after-free

Original title: A new way to think about borrow checking (in reverse)

> Hacker News story 50140383 · language: en · submitted 2026-10-18
> Web version: https://zeli.app/story/50140383
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 132 · by [verdagon](<https://news.ycombinator.com/user?id=verdagon>) · 💬 19
[original](<https://verdagon.dev/blog/reverse-borrow-checking>) · [HN discussion](<https://news.ycombinator.com/item?id=50140383>)

## Summary

Valen, an experimental language that makes shared-xor-mutable optional and allows memory-safe calls into Rust, checks memory safety in reverse. After parsing, typing, and static grouping, its fourth phase scans each function from the last statement upward, tracking which references will be used later and flagging any mutation that invalidates them. The author argues the backwards walk helps with last-use analysis, loops, and speed, and asks readers to poke holes in the approach.

## Key quote

> This is weird because, as far as I know, it's the only borrow checker whose safety check goes backwards.

## HN discussion (19 comments)

### [Animats](<https://news.ycombinator.com/item?id=50148685>)

> Interesting.
>
> In Hoare-type proof of correctness work, it's normal to work backwards from the proof goal (such as an assert statement) back upwards through the program, adding info about code that affects the variables in the assertion. This approach to borrow checking follows that model. You want some state at some point, and you work backwards to see if the preceding code gets you there. Makes a lot of sense for lifetimes.
>
> The main problem with doing this inside a compiler is performance. You backtrack for each thing you need to prove, going through the same code more than once. I used to think that compilers should use more verification technology, but people start screaming about compile times.

### [verdagon](<https://news.ycombinator.com/item?id=50140433>)

> Figuring out how to make this was a pretty wild ride. I had zero clue how to approach this, so I went into the mountains with pencil and paper until I figured something out.
>
> I started with a sort of "compile-time generational references" approach, where every reference would also remember when it was made, at compile-time. Then that evolved into a couple more things until I finally figured out this reverse approach. We'll see if it sticks.
>
> Hope you all enjoy!

### [gnarlouse](<https://news.ycombinator.com/item?id=50147174>)

> I have no help to offer, but as a bystander who loves Rust I am very hopeful good things come of this for you @verdagon!

---

## Cite

- Page: https://zeli.app/story/50140383
- Date: 2026-10-18
- Source: verdagon.dev (https://verdagon.dev/blog/reverse-borrow-checking)
- Hacker News: https://news.ycombinator.com/item?id=50140383

## Other languages

- zh: https://zeli.app/zh/story/50140383 · markdown: https://zeli.app/zh/story/50140383.md
- ja: https://zeli.app/ja/story/50140383 · markdown: https://zeli.app/ja/story/50140383.md
- ko: https://zeli.app/ko/story/50140383 · markdown: https://zeli.app/ko/story/50140383.md
- de: https://zeli.app/de/story/50140383 · markdown: https://zeli.app/de/story/50140383.md
- es: https://zeli.app/es/story/50140383 · markdown: https://zeli.app/es/story/50140383.md
- ru: https://zeli.app/ru/story/50140383 · markdown: https://zeli.app/ru/story/50140383.md
