Earlier quoted context omitted.
> a given C compiler + platform will behave completetly deterministically and you can test the output and see what it does, regardless of UB or not. Sure[1], but that doesn't mean it's safe to publish that C code - the next version of that same compiler on that same platform might do something very different. With machine code (especially x86, with its very friendly memory model) that's unlikely. (There are cases lik…
It is not terribly hard to generate C code that does not use undefined behavior.
Rust to C compiler – 95.9% test pass rate, odd platforms
71–80 of 264 posts
Re: Rust to C compiler – 95.9% test pass rate, odd platforms
#72Earlier quoted context omitted.
> a given C compiler + platform will behave completetly deterministically and you can test the output and see what it does, regardless of UB or not. Sure[1], but that doesn't mean it's safe to publish that C code - the next version of that same compiler on that same platform might do something very different. With machine code (especially x86, with its very friendly memory model) that's unlikely. (There are cases lik…
CPUs get microcode updates all the time, too. Nothing is safe from bitrot unless you’re dedicated to 100% reproducible builds and build on the exact same box you’re running on. (…I’m not, for the record - but the more, the merrier.)
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.
Re: Rust to C compiler – 95.9% test pass rate, odd platforms
#73Is it LLVM IR --> C? Or Rust AST to C?
It started as a .NET backend but they found that their approach could easily support C code generation as well so they added that. They do this by turning what rustc gives them into their own IR.
Re: Rust to C compiler – 95.9% test pass rate, odd platforms
#74Originally, the rustc_codegen_gcc project made this promise but never fulfilled it.
Re: Rust to C compiler – 95.9% test pass rate, odd platforms
#75Earlier quoted context omitted.
If the transpilation itself is bug-free, why not? For static guarantees, provided we transpile Rust code that already compiles on a normal Rust compiler, the guarantees are already checked and there, and the dynamic ones such as bounds checking can be implemented runtime in C with no problems.
this assumes the rusty guarantees are transitive. There's no reason to believe it isn't, but it'd be nice to see some sort of proof, or at least an argument for it.
Then the machine code generated by LLVM is not run directly by modern CPUs and is translated into internal representation first. And the future CPUs will behave like JIT-compilers with even more complex transformations.
The intermediate C code generated by this project just adds yet another transformation not fundamentally different from any of the above.
Re: Rust to C compiler – 95.9% test pass rate, odd platforms
#76Re: Rust to C compiler – 95.9% test pass rate, odd platforms
#77Earlier quoted context omitted.
> C to Rust would be fantastic. This would have to go into one big unsafe block for any nontrivial program. C doesn’t convey all of the explicit things you need to know about the code to make it even compile in Rust.
I once implemented a WASM to Rust compiler that due to WASM's safety compiles to fully safe Rust. So I was able to compile C -> WASM -> Rust and ended up with fully safe code. Though of course, just like in WASM, the C code is still able to corrupt its own linear memory, just can't escape the "sandbox". Firefox has employed a similar strategy: https://hacks.mozilla.org/2020/02/securing-firefox-with-weba...
Re: Rust to C compiler – 95.9% test pass rate, odd platforms
#78Earlier quoted context omitted.
Borrow checker, and more generally any type checkers, are essentially terminating programs ran during compilation process, thus safety guarantees given by them are ensured before the code is transformed into some target language.
Thats assuming lossless transpilation though
Re: Rust to C compiler – 95.9% test pass rate, odd platforms
#79Earlier quoted context omitted.
CPUs get microcode updates all the time, too. Nothing is safe from bitrot unless you’re dedicated to 100% reproducible builds and build on the exact same box you’re running on. (…I’m not, for the record - but the more, the merrier.)
> 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.
Maybe your program worked due to the bug they fixed.
Re: Rust to C compiler – 95.9% test pass rate, odd platforms
#80At first I read it as C to rust compiler. What is the point of compiling rust to C?
I think there are probably C compilers for more platforms than there are rust compilers. So, if you want to compile your rust project on some obscure platform that doesn’t have a rust compiler for it yet, you could compile to C and then compile the resulting C code for that platform? Just a guess.
“ The project aims to provide a way to easily use Rust libraries in .NET. It comes with a Rust/.NET interop layer, which allows you to easily interact with .NET code from Rust
[…]
While .NET is the main focus of my work, this project can also be used to compile Rust to C, by setting the C_MODE enviroment flag to 1.
This may seem like a strange and unrelated feature, but the project was written in such a way that this is not only possible, but relatively easy.”
It also doesn’t mention for which version of C it produces code. That may or may not hinder attempts to use this to run rust on obscure platforms.