4 ms·
Rust using the LLVM toolchain is a real plus, which Clang also uses in the C++ world. The Clang and Rust compilers are basically frontends to LLVM, and any lan
by jdlyga 7y ago
Rust using the LLVM toolchain is a real plus, which Clang also uses in the C++ world. The Clang and Rust compilers are basically frontends to LLVM, and any language that compiles using LLVM is translated to IR (intermediate representation). All code optimization is done on the IR code itself in LLVM, which both Rust and C++ compile down to before being compiled further into assembly. That means that the same effort that goes into optimization in the C++ world for Clang is shared by the Rust community too, and any other compiler that uses LLVM.
- steveklabnik 7y agoWe have started doing our own optimizations too: https://blog.rust-lang.org/inside-rust/2019/12/02/const-prop-on-by-default.html https://blog.rust-lang.org/inside-rust/2019/12/02/const-prop... Your overall point is absolutely correct though. We couldn’t have done this without LLVM.
- galangalalgol 7y agoCan you comment on the current state of non-aliased related optimizations? The issue tracker is byzantine on that one and i can't tell if or to what degree those optimizations are now done.
- shepmaster 7y agoI don't know the current state, but I hang out in the Zulip room dedicated to the work on the optimizations - https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt https://rust-lang.zulipchat.com/#narrow/stream/189540-t-comp...
- steveklabnik 7y agoThey’re not on right now.
- kibwen 7y agoRight now they're disabled, pending patches on the LLVM side. You can keep track here: https://github.com/rust-lang/rust/issues/54878 https://github.com/rust-lang/rust/issues/54878
- ncmncm 7y agoYes, Rust has the potential to be faster than C, or even C++. But the compilers' implementations of such optimizations are far too buggy to turn on.
- galangalalgol 7y agoAll the usual caveats apply, but benchmark game has rusts median already better than c++, but not as good as c. They are all so close that performance shouldn't really be a consideration between them I think. You can see g++ vs clang++ now too.
- SAI_Peregrinus 7y agoThe other nice part of using LLVM is that you don't have to write a new Rust compiler for a new target, you just need to write the LLVM backend to convert LLVM IR to the target's assembly. That's substantially easier to do. So while LLVM doesn't support as many architectures as GCC yet it's far easier to add new architectures to it.
- Jasper_ 7y agoThis is a broad over-simplification of compiler engineering. LLVM IR is a very leaky abstraction, and there are plenty of optimization passes which make sense for one but not the other. Plenty of optimization passes can and do assume that the LLVM IR is "roughly clang-shaped".
- kibwen 7y agoThis is the reason that (last I checked) Rust (by default) runs LLVM optimization passes in the same order and quantity as Clang, and even seeks to have the frontend produce LLVM IR that resembles what Clang would produce. However, modulo LLVM bugs, the worst to be expected from a frontend selecting a different set or order of LLVM passes would be a loss of codegen quality, which may not be particularly crucial for non-C++-shaped languages.