Live data from Hacker News

Rust to C compiler – 95.9% test pass rate, odd platforms

fractalfir.github.io

101–110 of 264 posts

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#101

Earlier quoted context omitted.

Rust is much easier to learn due to C/C++ books all being paid (even cmake wants you to buy their book) whereas Rust documentation is free. I bet more and more people are choosing to learn Rust over C/C++ for this reason, and the number of C/C++ devs will be decreasing.

what a weird take to me... C has DECADES of high quality teaching material in form of books, university courses, plenty of which is freely available with a bit of searching. And, if we discount the fact that "buying" a book is such a big hurdle, even more high quality academic text books and papers to boost; anything from embedded on the weirdest platforms, basic parsing, writing compilers, language design, high perf…

> edit2: networking, signal processing, automotive, learning about industry protocols and devices of any sort...

I admit there is many great products that are written in C that aren’t going anywhere any time soon, notably SQLite, but there is no reason to write new software in C or C++.

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#102

Earlier quoted context omitted.

what a weird take to me... C has DECADES of high quality teaching material in form of books, university courses, plenty of which is freely available with a bit of searching. And, if we discount the fact that "buying" a book is such a big hurdle, even more high quality academic text books and papers to boost; anything from embedded on the weirdest platforms, basic parsing, writing compilers, language design, high perf…

> C has DECADES of high quality teaching material in form of books, university courses, plenty of which is freely available with a bit of searching. Which means all that high quality teaching material is DECADES old. Rust development is centralised and therefore the docs are always up-to-date, unlike C/C++ which is a big big mess.

Oh my... Are you serious? I'm almost triggered by this. A book about algorithms or data structures from 20 years ago has nothing more to teach? 3D game engine design from 20 years ago has nothing more to teach? No point in looking at the source code of Quake, reading k&r, and Knuth's TAOCP Volume 1 was published in 1968 so it's obviously irrelevant garbage!

I could spurr into an essay of what kind of lack of understanding you just portrayed about the world, but I won't.... I won't...

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#103
post #87
post #42

Earlier quoted context omitted.

’Extern c’ still uses Rust. You want to skip Rust and call C from other languages directly.

Rust doesn't have a runtime so it looks just like C in compiled form. c-bindgen even spits out a c header. I’m not sure what skipping C practically means even if you can argue there’s a philosophical skip happening.

You can't apply all of the hacks C programmers apply, like calling private methods, because Rust's internal ABI is different in some annoying spots.

Of course you shouldn't do that, but it's a problem rust-to-c conversion would solve.

Another reason I could think of is the desire to take something licensed in a way you don't like, written in Rust, for which you'd like to call into the private API in your production code, but don't want the legal obligations that come with modifying the source code to expose the methods the normal way.

I don't think either use case is worth the trouble, but there are theoretically some use cases where this makes sense.

It's also something I might expect someone who doesn't know much about Rust or FFIs outside of their own language might do. Not every language supports exporting methods to the C FFI, and if you're coming from one of those and looking to integrate Rust into your C you might think that translation is the only way to do it.

Most likely, it's a way rust haters can use rust code without feeling like the "other side" has won.

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#104

Earlier quoted context omitted.

How can one be assured that all of the compile-time safety features of Java are is still in effect in bytecode?

The JVM class loader verifies the bytecode: https://stackoverflow.com/questions/755005/how-does-bytecode...

It verifies bytecode for bytecode rules violations, not that it matches original Java source code or whether original source code is safe.

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#105

Very cool. C to Rust would be fantastic.

Tools like those exist. The problem with them is that they use unsafe blocks a lot, and the code usually isn't very idiomatic. Translating global variable state machines into more idiomatic Rust state machines based on things like named enums, for instance, would be very difficult.

With the help of powerful enough AI we might be able to get a tool like this, but as AI still very much sucks at actually doing what it's supposed to do, I don't think we're quite ready yet. I imagine you'd also need enough memory to keep the entire C and Rust code base inside of your context window, which would quickly require very expensive hardware once your code grows beyond a certain threshold. If you don't, you end up like many code assisting LLMs, generating code independently that's incompatible with itself.

Still, if you're looking to take a C project and extend it in Rust, or perhaps slowly rewrite it piece by piece, https://c2rust.com/ is ready for action.

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#106
post #15
post #13

Is it LLVM IR --> C? Or Rust AST to C?

Found the answer in the project readme. > My representation of .NETs IR maps nicely to C, which means that I was able to add support for compiling Rust to C in 2-3K LOC. Almost all of the codebase is reused, with the C and .NET specific code only present in the very last stage of compilation

Which might also allow one to use tools that work on .NET bytecode. They include verification, optimization, debugging, and other transpilers. You might also get a grant or job offer from MS Research. :)

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#107
post #34

At first I read it as C to rust compiler. What is the point of compiling rust to C?

To use rust in places where you can only use C. I imagine there are quite a few obscure microcontrollers that would benefit greatly from this pipeline.

Hell, you might finally be able to get Rust into the Linux kernel. Just don't tell them the code was originally written in Rust to calm their nerves.

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#108
post #40
post #7

Lots of interesting use cases for this. First one that comes to mind is better interop with other languages, like Python.

The interop is already great via PyO3, except when people want to build the Rust part from source, but are grumpy about having to install the Rust compiler. This hack is a Rust compiler back-end. Backends get platform-specific instructions as an input, so non-trivial generated C code won't be portable. Users will need to either get pre-generated platform-specific source, or install the Rust compiler and this back-end…

They are grumpy about having to install the Rust compiler for a good reason. You can’t compile for Rust on Windows without using MSVC via Visual Studio Build Tools, which has a restrictive license.

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#109
post #79
post #72

Earlier quoted context omitted.

> CPUs get microcode updates all the time, too. To fix bugs, sure. They don't generally get updates that contain new optimizations that radically break existing machine code, justifying this by saying that the existing code violated some spec.

>To fix bugs, sure. Maybe your program worked due to the bug they fixed.

Extremely unlikely. CPU bugs generally halt the CPU or fail to write the result or something like that. The Pentium FDIV bug where it would give a plausible but wrong result was a once in a lifetime thing.

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#110

Earlier quoted context omitted.

> C has DECADES of high quality teaching material in form of books, university courses, plenty of which is freely available with a bit of searching. Which means all that high quality teaching material is DECADES old. Rust development is centralised and therefore the docs are always up-to-date, unlike C/C++ which is a big big mess.

Oh my... Are you serious? I'm almost triggered by this. A book about algorithms or data structures from 20 years ago has nothing more to teach? 3D game engine design from 20 years ago has nothing more to teach? No point in looking at the source code of Quake, reading k&r, and Knuth's TAOCP Volume 1 was published in 1968 so it's obviously irrelevant garbage! I could spurr into an essay of what kind of lack of understa…

We’re talking about C/C++, not algorithms or data structures.
Post reply on HN