80 points · by my123 · 5y ago · 62 comments
This is not a compiler for developing Rust programs. This is a compiler to let platforms unsupported by Rust/LLVM build rust programs from source. So it takes a Rust program which already exists, assumes it can be compiled by rustc, and translates it to C so it can be handed off to your local compiler. Skipping the burrow checker probably lets this execute in environments which are more constrained than what rustc can fit into.
Of course there's a question of how much of Rust's safety survive translation into C. Certainly some. E.g. the emitted program would include bounds checks where not specifically elided in Rust, and references are statically guaranteed to be non-null before being lowered into pointers. But there could be gaps, especially in cases where Rust semantics mismatch with C in ways that LLVM hasn't exposed yet.
Could you elaborate on what potential mismatches there currently are between the semantics of Rust and C? Where particularly do you think there might be issues/dragons hiding in the semantics of a translation?
Float integer conversions (overflows are defined to saturate in rust, are undefined behavior in C).
Maybe things like how pointer casts are treated in correct (but unsafe) rust vs C. Or similarly in transmute. Generally it wouldn't surprise me if rust was standardizing a memory model that was subtly different from C.
I'm sure the list goes on, but "that sort of thing".
I would assume that borrow checking uses far less memory than the actual compilation after the compiler has proven the program to be in concordance with the borrow rules.
It more so seems that it is something they did not bother to put too much effort into, as it wasn't necessary, than a legitimate way to reduce a compiler's memory footprint
As currently implemented in rustc, it operates on an intermediate representation that has already had name resolution and some simplification done. As such, i think it would be rather hard to separate from the rest of the compiler.
That alone would make rust a much easier language for newbies.
I wonder how these two projects compare.
There's a bunch of corporate/.gov envs that don't allow binaries to enter their system. All new code has to be compiled from source, on the target system (or at least on that side of the process firewall, it might be an airgapped cluster that can share code). They have C and C++ compilers that they've been compiling from source since the dawn of time, but they don't have a rust compiler. This gives them a mechanism to begin using rust within their process.
This takes very long and is error-prone, so having a compiler that can build even an intermediate version is already a big help.