Nice! For the uninitiated, what’s the difference between this project and corrode?
Corrode is completely implemented in Haskell and handles a smaller set of code. This project uses Clang to handle parsing, pre-processing, and type-checking the code. It also takes advantage of Clang’s libtooling library so that we can understand all of the clang command-line flags when processing a C file. This allows us to handle a lot more code.
I ran across your tweet but would have mentioned you in the post if I’d known you were a lobster! (I probably should have checked the user list first)
No worries, I joined after you posted this :-)
glad to see you here, glguy
glguy came in to IRC asking for an invite after seeing your post.
Makes sense, thanks for the reply! (In fact, I believe this is the same method that rust-bindgen uses, and, as far as I know, rust-bindgen works pretty well, so it’s a good idea…)
So the game is to try and input a C program that generates idiomatic rust code.
Or the opposite: submit compiling C code that doesn’t compile in Rust (or is otherwise broken) so that we can fix the translator to handle that case.
See the known limitations page: https://github.com/immunant/c2rust/wiki/Known-Limitations-of-Translation
Cool project 👍🏻. I’m wondering is it “correct” to say that “now we can write safer c” if the C code is transpiled to Rust?
The resulting Rust code is only slightly safer. Some things like array bounds that were not previously checked will be checked. For the most part this translation is just the first step in enabling more substantial refactoring from which the benefits from Rust can start to shine.
Ah okay, thanks 👍🏻
Why is the resulting rust code only slightly safer? Rust as a language is a lot more memory safe than C. If you’re talking about current transcompilers, then improving those should lead to improvements in C.
It’s translating to mostly-unsafe Rust (so does corrode, the other project that does this)
This means you still have the same burden of checking most of the invariants involved.
One use case for tools like these is an easy way to start converting a codebase from C to Rust, doing away with a bunch of the tedium.
Ah, I’ve misread that. I was referring to Rust -> C compilers which are useful to create if only to understand the domain well enough to bring improvements to C.