r/Compilers • u/mashmaro1234 • 22h ago
Memory emulation as an intermediate step in C++ to Rust translation
I'm experimenting with translating large C++ codebases like ROOT to safe Rust.
My current approach is to first translate C++ to run on a checked memory emulator written in Rust, then gradually remove the emulation using static analysis.
I tried this on ROOT's Minuit2 (around 14k lines of C++), and all 13 numerical tests produced identical output. However, only about 3% of the functions have been fully converted to ordinary Rust so far.
I'm wondering how far static analysis can actually take this approach. Is using memory emulation as an intermediate step a reasonable idea, or does it just make ownership recovery more complicated?
I'd also appreciate any suggestions for papers or existing work on similar approaches.
2
u/Discordbothost 22h ago
One aliasing pattern can keep a whole group of functions on the emulator. I'd group failed conversions by the first analysis check that blocks them. Cpp2Rust (PLDI 2026) is worth a look. It starts with runtime checks and uses static analysis to remove some.
1
u/morglod 7h ago
How you will verify algorithmic safety after translation? Because C++ is "also C", and safe rust refuse a lot of C algorithms and approaches
2
u/Far-Championship-883 12h ago
It'd be more productive to hit yourself in the balls with a hammer. IF I was retarded enough nto do this, I'd use the AST from c++ and then transpile to rust, but good fucking luck with that