3 ms·
I was always told rust uses llvm tokens not produceable by c code to do its magic. Was I informed wrong?
by Surac 10mo ago
I was always told rust uses llvm tokens not produceable by c code to do its magic. Was I informed wrong?
- mmastrac 10mo agoThere are multiple stages of IR in the compiler, basically
- SAI_Peregrinus 10mo agoYou 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.
- Grikbdl 10mo agoI 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.
- SAI_Peregrinus 10mo agoIIRC 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.
- 1718627440 10mo agoC still has lifetime rules. It just has no syntax for them. What people are bitten with is that they violate the lifetime rules, but their compiler doesn't tell them.