Re:DARPA: Translating All C to Rust (Tractor)
by mike_hearn on Wednesday July 31, 2024 @03:56AM
(#41117199)
Yes, this is similar to what IntelliJ does for Java->Kotlin. Do a first pass that's extremely non-idiomatic and mechanical, then do lots of automated refactoring to bring it closer to idiomatic.
But if you're going to do it that way, the right place to start is probably to a safer form of C++ not Rust. That way code can be ported file-at-a-time or even function-at-a-time, and so you'll have a chance to run the assertions in the context of the original code. Which of course may not have good test coverage, as C codebases often don't, so you'll have to be testing your assertions in production.
Re:DARPA: Translating All C to Rust (Tractor)
by Animats on Wednesday July 31, 2024 @01:23PM
(#41121157)
> But if you're going to do it that way, the right place to start is probably to a safer form of C++ not Rust.
There's something to be said for that. You're going to need at least an internal representation that's a safe C/C++.
That might not be too bad.
A combination of a formal system and an LLM might work here. Suppose we see a C function
First question: is "buf" a pointer to an array, or a pointer to a single char? That can be answered by looking at what the function does with "buf", and what callers pass to it.If it's an array, how big is it? We don't have enough info to know that yet. But a reasonable guess, and one than an LLM might make, is that the length of buf is "n".
Following that assumption, it's reasonable to translate this to Rust as
and, if n is needed within the function, use The next step is to validate that guess. The run-time approach is to write all calls to "somefn" with Maybe formal methods can prove the assert true, and we can take it out. Or if a SAT solver or a fuzz tester can generate a counterexample, we know that the guess was wrong and this has to be done the hard way, as implying more subscript checks inside "somefn".The idea is to recognize common C idioms and do clean translations to Rust for them. This should handle a high percentage of cases.