Re:Corrode: C to Rust translator written in Haskell
by kerkeslager on Friday July 08, 2016 @04:44PM
(#12058508)
I think that keeping an exact one-to-one mapping makes this tool a lot more useful. There's no telling what code depends on C idioms that would be broken by using a Rust idiom instead. Generating 100% equivalent code means that programmers can make intelligent decisions about when to switch over to Rust idioms as they continue developing the program.
Re:Corrode: C to Rust translator written in Haskell
by Retra on Friday July 08, 2016 @07:16PM
(#12059243)
Yeah, once you've got equivalent Rust, the rest is just optimization that should probably be implemented in the Rust compiler. No reason to put that stuff in the niche transpiler.
Re:Corrode: C to Rust translator written in Haskell
by masklinn on Friday July 08, 2016 @03:01PM
(#12057865)
> Anyone know how easy it is to recognize and code for such cases in the transpiler? Edit: It looks like they might have opposite design goals
Yes the author has explicitly noted that they want a compiler as syntax-directed as possible, semantics change would go against that grain. In that spirit, idiomatic alterations would be the domain of rust-land fixers and linters (e.g. `cargo wololo` or `cargo clippy | rustfix`)
Re:Corrode: C to Rust translator written in Haskell
by SilasX on Friday July 08, 2016 @03:17PM
(#12057967)
So you could chain Corrode with one of those to get a C-to-idiomatic-Rust converter?
FWIW, I googled those; Clippy and rustfix just seemed to be linters that can't detect things like "you're not mutating this so drop `mut`", and I couldn't find wololo.
Re:Corrode: C to Rust translator written in Haskell
by pshc on Friday July 08, 2016 @01:40PM
(#12057286)
1. A special case could be added for `main`, but it's no big deal.
2. This seems difficult as the C arguments were mutable; the algorithm would have to start doing analysis rather than direct translation.
3. Quite difficult to "know" that this printf doesn't write to its arguments, especially since the printf is manually declared.
1. Rust fn:main doesn't need to return something.
2. The arguments to main aren't mutated, so Rust doesn't need to declare them as mutable.
3. Ditto for the argument to printf.
Anyone know how easy it is to recognize and code for such cases in the transpiler?
Edit: It looks like they might have opposite design goals [1]: "Corrode aims to produce Rust source code which behaves exactly the same way that the original C source behaved, if the input is free of undefined and implementation-defined behavior. ... If a programmer went to the trouble to put something in, I want it in the translated output; if it's not necessary, we can let the Rust compiler warn about it." (Edit2: cleaned up and numbered)
[1] https://github.com/jameysharp/corrode#design-principles