3 ms·
Yes. We really need a usable C to Rust translator. The existing "transpilers" just turn C with pointer arithmetic into Rust with pointer arithmetic. The output
by Animats 6y ago
Yes. We really need a usable C to Rust translator. The existing "transpilers" just turn C with pointer arithmetic into Rust with pointer arithmetic. The output is awful.[1]
This is a hard problem, but not impossible. There are people who say it's impossible. The usual excuses are obfuscated code, undecidablity, need to maintain binary compatibility, etc. Those are not show-stoppers. What's needed is something that converts C to ideomatic safe Rust most of the time, and to fat-pointer slow but safe Rust when the converter can't figure out what the code is doing.
This is a job comparable to an optimizing compiler, and that's a big project. It will take money.
More detailed comments on Rust forums: [2]
Trying to patch up C is not promising. It's been tried, many times. The thesis shows most of the approaches that have been tried. GCC used to have a "fat pointer" option with checking, but it was rarely used, and has, I think, been deprecated. Putting extra info in the high bits of pointers has been tried. Memory allocation where all allocations in a block are the same size and you can look up the size of by block has been tried. Syntax changes to C have been proposed; I've been down that road.
[1] https://c2rust.com/ https://c2rust.com/
[2] https://users.rust-lang.org/t/c-to-rust-translator/55381/14 https://users.rust-lang.org/t/c-to-rust-translator/55381/14
- moonchild 6y ago> Trying to patch up C is not promising. It's been tried, many times Isn't it? It looks like the author is cherry-picking approaches that haven't worked. Isabelle and verifast do very well at making c secure, for instance.
- yholio 6y agoPatching up C has been attempted many times, with great success. Problem is, once the patch-up is completed, the language and memory layout of things like stacks, structures etc. that you end up with makes that secure language no longer C. You lose the ability to recompile billions of lines of legacy code, you lose binary compatibility and/or require compatibility and emulation layers or stupid "unsafe" modes that negate the benefit. What you end up with is a silly new language that inherits the awkward syntax of something designed in the 60s and lacks the rich expressivity and idioms of newer languages. At that point, it makes little sense to not start from scratch and work with a completely new language adequate for your application - such as Rust or Java.