3 ms·
What about a Rust to C translator? It would produce "safe" C right?
by phkahler 6y ago
What about a Rust to C translator? It would produce "safe" C right?
- zozbot234 6y agoYou would also need to comprehensively annotate the Linux C headers in order to provide the information that Rust expects (e.g. for each ptr instance whether it's a "raw" pointer, a shared/exclusive reference or a piece of "owned" data, whether it can be NULL etc. etc.). This might actually get accepted upstream though. Having the kernel-build itself depend on Rust could be far more problematic, given e.g. the variety of hardware that Linux must support.
- TheDesolate0 6y agoNot only that, but Rust depends on LLVM.
- saagarjha 6y agoIt doesn't have to, but yes, it currently pretty much requires LLVM.
- dijit 6y agoLast time I looked at this comment it was flagged [dead]; I'm glad someone was able to remedy that as I was unable to upvote. I think this is a good criticism, but might not be true forever and is certainly something to keep in mind. As I said in the GP, Rust will not be upstreamed into the kernel- this is one of the reasons why.
- ufmace 6y agoI would think such a thing would be more like "compiling" rust to C. As in the C code would have no means to maintain most of the safety guarantees, rather they would be verified at compile time, and the produced C would be meant to be used unchanged. So as long as nobody ever edits the C manually, it would still presumably be safe.
- phkahler 6y agoThat's what I really meant. Write it in Rust but then output C instead of ASM. The parent is right though. A component/driver would need to use the C headers from the Rust side.
- arcticbull 6y agoThe output of the translator would be right, but messy, and someone would have to go back and clean it up. Doing that work would almost certainly introduce bugs. How many, and whether it outweighs is the question.
- 6c696e7578 6y agohttps://lwn.net/Articles/797828/ https://lwn.net/Articles/797828/ Perhaps the way to do it is to rewrite common bits that get CVEs, just so it doesn't happen again.
- gfs 6y agoThere is a lot of work being done on a translator now [0]. However, the goal is to translate C to equivalent Rust and then allow developers to intervene to migrate to safe Rust. [0]: https://c2rust.com https://c2rust.com EDIT: Oops, read the parent comment backwards.
- zozbot234 6y agoThat's C to Rust, not Rust to C. (mrustc provides something like the latter, but it doesn't actually support full Rust.)