←back to thread

Eurydice: a Rust to C compiler

(jonathan.protzenko.fr)
185 points todsacerdoti | 1 comments | | HN request time: 0.001s | source
Show context
Surac ◴[] No.46181827[source]
I was always told rust uses llvm tokens not produceable by c code to do its magic. Was I informed wrong?
replies(2): >>46182005 #>>46182624 #
SAI_Peregrinus ◴[] No.46182624[source]
You probably misunderstood. C can represent any program's semantics, since it's Turing-complete (modulo finite memory). C can't encode the lifetimes Rust uses, but those get erased during compilation to MIR. This takes MIR from rustc (where borrow checking has been completed and lifetime annotations erased) and outputs C with the same semantics. LLVM doesn't use tokens not produceable by C, but rustc does.
replies(2): >>46182806 #>>46191253 #
Grikbdl ◴[] No.46182806[source]
I think it's a reference to certain optimizations possible due to aliasing rules in Rust that are not possible (or maybe only "not straight forward", I'm not sure) in C. So a transpiled program while keeping its semantics might not still compile to equally optimized assembly.
replies(1): >>46183723 #
1. SAI_Peregrinus ◴[] No.46183723[source]
IIRC C can do the same things with correct usage of `restrict`, but that's extremely difficult by hand. So difficult that LLVM's `restrict` support was very buggy when Rust first started using the capabilities. Those bugs got fixed, but it's still impractical to use in handwritten C.