1. 33
  1.  

  2. 11

    Nice! For the uninitiated, what’s the difference between this project and corrode?

    1. 14

      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.

      1. 3

        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)

        1. 5

          No worries, I joined after you posted this :-)

          1. 1

            glad to see you here, glguy

          2. 3

            glguy came in to IRC asking for an invite after seeing your post.

          3. 2

            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…)

        2. 3

          So the game is to try and input a C program that generates idiomatic rust code.

          1. 6

            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

          2. 2

            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?

            1. 13

              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.

              1. 2

                Ah okay, thanks 👍🏻

                1. 1

                  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.

                  1. 6

                    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.

                    1. 2

                      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.