|
|
Subscribe / Log in / New account

Automated translation from C to Rust

Automated translation from C to Rust

Posted Feb 14, 2025 13:52 UTC (Fri) by farnz (subscriber, #17727)
In reply to: A lot of good stuff in there by smurf
Parent article: New leadership for Asahi Linux

Automated large-scale code translation from C to Rust is likely to look a lot like C2Rust with a set of rewrite rules that target obvious deficiencies in the output Rust (in the same way that cargo clippy --fix has rewrite rules that target obvious deficiencies in human-written Rust).

As Rust code goes, the output of C2Rust is pretty awful today. The open question is whether it's going to be easier to manually rewrite all the C that benefits from rewriting into good Rust, or to put together Rust → Rust rewrite rules that fix the faults in C2Rust's output; if fixing C2Rust's output is easier than rewriting C into Rust, then people will prefer automatic translation.

Note, too, that there's the possibility of semi-automated rewriting of C2Rust's output - have the human identify useful properties (e.g. "this function's return value is an OwnedFd, not a libc::c_int") and have the rewrite tool do conversions of code based on what you've just told it (in this case, changing the return type to OwnedFd, then adjusting all function parameters that "obviously" borrow to BorrowedFd and those that look like they consume it to OwnedFd, leaving unclear cases as RawFd for the human to fix).

Of course, none of this will happen unless interested parties make it happen.


to post comments


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds