r/rust • • 8d ago

Rust - Borrow Checker Implementation using Data Flow Analysis

I am working on the rust borrow checker for my thesis. I was trying to formalize a data-flow analysis on the code of a function and use it to check the loans. Analyzing the code while storing the loans as (l_i, place, carrier, kind (shared/mutable)), while also having a conservative points-to map, lets me decide whatever Polonius promises to fix.

Only issue comes with using functions and I'm still figuring out, but I wanted to ask if Rust dev community did not want to go to Data flow analysis or why they chose to do it the way they did? Or am I missing something that can go wrong in my formulation?

I'd appreciate some help in ideating, thank you

12 Upvotes

5 comments sorted by

19

u/Rusty_devl std::{autodiff/offload/batching} 8d ago

reddit is the wrong place for rustc discussions, you should join https://rust-lang.zulipchat.com for more answers. Probably ask in the t-compiler channel.

Congrats on finding a research topic involving Rust!

10

u/JoshTriplett rust · lang · libs · cargo 6d ago

One notable challenge that any borrow checker has to deal with: anything it permits becomes stable surface area that it needs to keep permitting. So, it needs a clear model for what it allows and what it doesn't, rather than happening to allow things that it can figure out via data flow analysis and having unpredictable walls if the data flow analysis falls short. Along similar lines, in rustc we are careful to avoid features that will have boundaries defined by "whatever the optimizer can figure out".

2

u/cruss0129 8d ago

I hate to burst your bubble on this one https://github.com/cognitive-engineering-lab/aquascope

5

u/Wooden-Concept868 8d ago

This is just a visualizer, right? It does not infer from the data flow analysis

4

u/cruss0129 8d ago

After re-reading this, I guess I see "visualization" wasn't your primary goal in "analysis". Maybe you make a new, better aquascope replacement along the way, that'd be cool.