Remix.run Logo
▲ A new way to think about borrow checking (in reverse)(verdagon.dev)
41 points by verdagon 17 hours ago | 5 comments
▲Animats 2 minutes ago | parent | next [-]

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 17 hours ago | parent | prev | next [-]

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 4 hours ago | parent | prev | next [-]

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!

▲CoalitionOfPity 17 hours ago | parent | prev [-]

I just wanted to take the time to compliment this note in your blog: > My stance: if you want someone to take the time to read something, take the time to write it by hand.

▲verdagon 17 hours ago | parent [-]

Thank you! I pretty strongly believe this. If we take the time to write for each other, then the internet stays a place where humans connect with each other. Otherwise we get lost in the noise and it becomes a place where machines talk to each other through humans. Fingers crossed the world figures this out.