Compile-Time Borrow Checker with Stateful Metaprogramming
summary
Claim is that a Rust‑style borrow checker can run entirely at compile time in C++ by recording a MIR‑like IR via stateful metaprogramming and analyzing it with constexpr NLL algorithms. Implementation uses friend injection, a metastate recorder, expression‑proxy wrappers, liveness analysis, fixed‑point region inference and loan conflict checks; result is a ~1.5k‑line header‑only prototype that produces identical assembly and zero runtime cost but causes large compile‑time overhead and is practical only for small scopes today. Future C++26 reflection reduces boilerplate.
AI-written summary · about
chapters (9)
- 0:00Memory safety and borrow checkers
- 10:02Borrow checker rules and lifetimes
- 17:11Stateful metaprogramming
- 29:55Compile-time borrow checker design
- 49:19Region inference and loan analysis
- 52:10Demo of borrow checker
- 1:00:38C++26 reflection for improvements
- 1:07:37Summary and applications
- 1:13:22Q&A
related talks
17mFoundations for a Rust-Like Borrow Checker for C
37mMemory Safety Everywhere with Both Rust and Carbon
28mBorrow checking Hylo
58m(Almost) Everything You Should Know About The Compiler Frontend
15mPermchecker: A Toolchain for Debugging Memory Managers with Typestate
01h 01mExpressive Compile Time Parsers
16mFrom Linearity to Borrowing
35mLet’s Talk About Rust
