Live data from Hacker News

Corrode: C to Rust translator written in Haskell

github.com

21–30 of 127 posts

Re: Corrode: C to Rust translator written in Haskell

#21

Time to start sending PRs [1], :P [1] https://github.com/search?utf8=%E2%9C%93&q=language%3Ac

I would hope that when this project is far enough along to feasibly do such a thing, that people don't. It's really rude.

Totally agree, it was a joke.

Re: Corrode: C to Rust translator written in Haskell

#22
post #5

I understand the world play, but perhaps it's a misunderstanding of Rusts name origin ? https://www.reddit.com/r/rust/comments/27jvdt/internet_archa... It's after a fungus https://en.wikipedia.org/wiki/Rust_(fungus)

This is of itself a misunderstanding of the origin: that's one of many reasons it's called Rust, not the only one. There's no single reason for the name.

As is even stated in the parent's linked thread

Re: Corrode: C to Rust translator written in Haskell

#23
post #12
post #5

I understand the world play, but perhaps it's a misunderstanding of Rusts name origin ? https://www.reddit.com/r/rust/comments/27jvdt/internet_archa... It's after a fungus https://en.wikipedia.org/wiki/Rust_(fungus)

Oh great, I can't wait to hear this "well, actually"[1] for the rest of my life. [1] https://www.recurse.com/manual#sub-sec-social-rules

I was going to downvote you for a snarky response (I felt the reply explaining that Rust also has iron/oxidation references was a better response)...

... but that's a really good link that you provided. I've never read that before & it's a great resource for thinking about how to behave socially as a programmer. While I don't agree with all of it, I love their "don't pile-on" and "don't bring negativity from outside" approach. (Plus I'm guilty of the 'feigning surprise' rule.)

+1 for the really excellent link.

Re: Corrode: C to Rust translator written in Haskell

#24

The name "Corrode" doesn't seem very positive given the purpose of this program...

Only if you are talking about iron corrosion. If you own an aluminum Macbook, for instance, it was oxidized (or corroded) during manufacturing, on purpose. This protects the metal from further corrosion.

You could say it's what this project does.

Re: Corrode: C to Rust translator written in Haskell

#25

Earlier quoted context omitted.

> Because the project is still in its early phases, it is not yet > possible to translate most real C programs or libraries. It is currently trying to port over semantics exactly, so the Rust code is far from idiomatic Rust. Doesn't mean it's not useful, just saying that it's trying to be 1:1.

I guess the next stage would involve translating common non-idiomatic patterns into idiomatic Rust. Looks like this could be a job for a community-managed database!

This is best handled on a per-project or per-organization basis. I would have such a project concentrate on the tooling for maintaining and developing such databases.

Re: Corrode: C to Rust translator written in Haskell

#26

as many "transpilers" / compilers, whatever you might name them, it lacks example input output. I want to see how my new rust code base looks light, does it compile with some heuritics, or just 1:1 C to rust primitives?

Here you go. It didn't like my stdio.h. Apparently enums and unions aren't supported, but:

    extern int printf(char *, ...);

    int main(int argc, char argv[]) {
        printf("Hello, world!\n");
        return 0;
    }
Was turned into:

    extern {
        fn printf(arg1 : *mut u8, ...) -> i32;
    }
    #[no_mangle]
    pub unsafe fn main(mut argc : i32, mut argv : *mut u8) -> i32 {
        printf(b"Hello, world!\n\0".as_ptr() as (*mut u8));
        0i32
    }
edit: Also worth noting, it removes all comments. I believe this to be a limitation of language-c [1]

[1] https://hackage.haskell.org/package/language-c

Re: Corrode: C to Rust translator written in Haskell

#27

Earlier quoted context omitted.

I find the name creative, kind of funny and all in all very good.

I guess you could say its ironic in terms of how I think of it anyway.

> ironic

I don't even know what is and what isn't a pun anymore.

Re: Corrode: C to Rust translator written in Haskell

#28
post #12

Earlier quoted context omitted.

Oh great, I can't wait to hear this "well, actually"[1] for the rest of my life. [1] https://www.recurse.com/manual#sub-sec-social-rules

I was going to downvote you for a snarky response (I felt the reply explaining that Rust also has iron/oxidation references was a better response)... ... but that's a really good link that you provided. I've never read that before & it's a great resource for thinking about how to behave socially as a programmer. While I don't agree with all of it, I love their "don't pile-on" and "don't bring negativity from outside"…

Why are they talking specifically about _feigning_ surprise? Isn't the effect the same even if you're honestly surprised?

Re: Corrode: C to Rust translator written in Haskell

#29

Earlier quoted context omitted.

> Because the project is still in its early phases, it is not yet > possible to translate most real C programs or libraries. It is currently trying to port over semantics exactly, so the Rust code is far from idiomatic Rust. Doesn't mean it's not useful, just saying that it's trying to be 1:1.

I guess the next stage would involve translating common non-idiomatic patterns into idiomatic Rust. Looks like this could be a job for a community-managed database!

On the rust subreddit someone tongue-in-cheek suggested `cargo clippy | rustfix` to be used in conjunction with this tool for better rust code.

But that actually could work! Clippy has a ton of lints that make your code more idiomatic, and rustfix basically takes diagnostic output and applies suggestions (still WIP).

Clippy is geared towards making human-written unidiomatic code better, so it might not catch some silly things in this tool's output but or certainly could be extended to do that.

Re: Corrode: C to Rust translator written in Haskell

#30
It's too bad this is written in Haskell. I don't have anything against Haskell, it is just not as popular a language as others.[1] Any ANTLR target language would have been a solid choice.[2] This way more of the community could contribute. This is an invaluable tool if we're truly going to see a shift from C (or C++) to Rust.

[1] http://pypl.github.io/PYPL.html

[2] http://www.antlr.org/download.html

Post reply on HN