What does HackerNews think of rustc_codegen_cranelift?

Cranelift based backend for rustc

Language: Rust

#8 in Compiler
#2 in JavaScript
#25 in Rust
> When this happens, it seems like it'll be possible to get the LLVM bits out of the bootstrap process and lead to a fully self-hosted Rust.

What do you mean by "when this happens"? GP's point is that this has already happened: the Cranelift backend is feature-complete from the perspective of the language [0], except for inline assembly and unwinding on panic. It was merged into the upstream compiler in 2020 [1], and a Cranelift-based Rust compiler is perfectly capable of bootstrapping another Rust compiler (with some config changes).

[0] https://github.com/bjorn3/rustc_codegen_cranelift

[1] https://github.com/rust-lang/rust/pull/77975

> Vale-specific pre-optimizer, similar to Rust's Cranelift

I think this might instead be MIR, mid-level IR, there’s a good blog post here: https://blog.rust-lang.org/2016/04/19/MIR.html

Cranelift is a compiler backend, mainly focused on JIT, but theoretically could replace LLVM, there’s an alternative backend being worked on but has limitations: https://github.com/bjorn3/rustc_codegen_cranelift

Cranelift is not used for debug builds by default. I think that's probably a goal (although I'm not actually 100% sure about that just because I'm not dialed into what the compiler team is doing). Even the OP mentions this:

> We were able to benchmark bjorn3's cranelift codegen backend on full crates as well as on the build dependencies specifically (since they're also built for cargo check builds, and are always built without optimizations): there were no issues, and it performed impressively. It's well on its way to becoming a viable alternative to the LLVM backend for debug builds.

And the Cranelift codegen backend itself is also clear about it not being ready yet: https://github.com/bjorn3/rustc_codegen_cranelift

(To be clear, I am super excited about using Cranelift for debug builds. I just want to clarify that it isn't actually used by default yet.)

Bjorn3 for all their work on cranelift and working towards getting it to be a better debug compiler for rust.[1]

cwfitzgerald for wgpu. He took over as the head maintainer after kvark left Mozilla to go to Tesla.

winit maintainers, they're a core ecosystem crate but don't get that much support because windowing isn't flashy.

[1] https://github.com/bjorn3/rustc_codegen_cranelift

There are some open issues and features like inline assembly that aren't supported, but a moderately complete backend exists now:

https://github.com/bjorn3/rustc_codegen_cranelift

The compiler frontend is already written in Rust.

Yes, I guess?: Cranelift, which is a LLVM-like library written in Rust. This could be used for faster debug builds in the future. There's a Rust backend using Cranelift [2].

If you mean addressing the poor quality of LLVM IR directly, then I don't know.

[1]: https://github.com/bytecodealliance/wasmtime/blob/main/crane... [2]: https://github.com/bjorn3/rustc_codegen_cranelift

There's a Cranelift backend, which is apparently faster at creating debug builds than LLVM: https://github.com/bjorn3/rustc_codegen_cranelift
There is work on integrating Cranelift into rustc (https://github.com/bjorn3/rustc_codegen_cranelift) so that rustc can compile to bytecode for the Cranelift JIT.
Strictly speaking rustc has a dependency on LLVM, which is in C++, but you could use the rustc_codegen_cranelift backend [1] and get pretty much everything to be pure Rust. Unless you count the libc dependency, in which case, um, I guess you could use relibc [2]? And if you think relying on OS syscalls implemented in not-Rust is cheating, then you could just use Redox directly ;)

[1] https://github.com/bjorn3/rustc_codegen_cranelift

[2] https://github.com/redox-os/relibc