4 ms·
I'm a big corrode fan and I used it (plus a really simple python script https://github.com/dropbox/rust-brotli/blob/master/uncorrode.py https://github.com/dropb
by daniel_rh 8y ago
I'm a big corrode fan and I used it (plus a really simple python script https://github.com/dropbox/rust-brotli/blob/master/uncorrode.py https://github.com/dropbox/rust-brotli/blob/master/uncorrode... ) to help translate the brotli encoder https://github.com/google/brotli/tree/master/c/enc https://github.com/google/brotli/tree/master/c/enc to safe, almost-idiomatic rust.
My initial attempts used top of tree corrode, but I found that the relooper got in the way of writing idiomatic rust, so I restarted my translation efforts and actually pinned corrode to before the relooper and backported a lot of the improvements that happened since the relooping effort https://github.com/danielrh/corrode/tree/unprocessed_loops https://github.com/danielrh/corrode/tree/unprocessed_loops
On one hand I'm very glad corrode supported the relooper: it got me excited about the capabilities of corrode, but in the end I think any serious port of a project is going to need to think about idiomatic control flow and will require a minor rewrite of the C code. The improvements to the C brotli encoder happened here https://github.com/danielrh/brotli/commits/corrode https://github.com/danielrh/brotli/commits/corrode to remove the gotos and some negative array access.
All in all, the process to get the brotli encoder into rust was very smooth. Much of it may be due to the google engineers being extremely careful about memory ownership and design.
Anyhow I'm excited about c2rust, but am nervous that corrode may be de-emphasized since I know it worked well for me.
If you want to know more about the experience of porting a large existing project to rust, I posted about the rust brotli decoder here https://blogs.dropbox.com/tech/2016/06/lossless-compression-with-brotli/ https://blogs.dropbox.com/tech/2016/06/lossless-compression-... (subsection "The Port")
- harpocrates 8y agoFWIW we've spent a lot of time trying to re-engineer the control-flow translation to be heuristic-friendly in c2rust. We've extended and tweaked the Relooper algorithm in hopes of preserving more of the initial control flow. It still isn't great, but it is getting better. Offhand, here are some sizeable additions: * Keep track of some extra information from the C source about what basic blocks were in loops or branch points, then use than information to try to extract back out similar looking Rust * Support translating `switch` to `match`, complete with collapsing some patterns together * Properly handle initialization That said, c2rust can be invoked _without_ relooper enabled if you so wish. In that case, it will simply refuse to translate code with goto's.
- daniel_rh 8y agoI love that the relooper can be disabled! I think that option will be really useful while the heuristics are being tuned, since many codebases avoid goto as a matter of style and can probably be translated without it, or with minor tweaks.
- voidmain 8y agoI have no idea what I'm talking about, but if you have a control flow translation pass that is intended to translate constructs like goto and produces "uglier" code, why not automatically disable it for functions (or whatever granularity works) with no such constructs?