4 ms·
Self Hosting your own compiler traditionally was the "end-game" of making a compile-able language. It's a sort of proof of fitness that the language can literal
by merlincorey 3y ago
Self Hosting your own compiler traditionally was the "end-game" of making a compile-able language.
It's a sort of proof of fitness that the language can literally stand on its own.
This article about Zig achieving self-hosted status in 2022[0] points out that they gained many advantages at the cost of a lot of time and effort through this process.
Incidentally, they decided to self-host while also supporting LLVM because of deficiencies in LLVM (mainly speed and target limitations).
This flexibility includes a separate "C" backend to compile Zig to C in order to target for example game consoles that require a specific C compiler be used.
> You say that like it's a critical goal of the Rust project rather than a trivia item.
In my opinion, you are overly minimizing the potential benefits to Rust and the Rust community for Rust to be self-hosted.
Of course, practically, right now it doesn't matter because most people are more than happy to use the already working system.
[0] https://kristoff.it/blog/zig-self-hosted-now-what/ https://kristoff.it/blog/zig-self-hosted-now-what/
- dralley 3y agoAs I said, the cranelift backend exists, and it provides many of the same benefits such as improved compilation speed. And it's written in Rust. But it still feels like a trivia item. C compilers written in C exist, but almost nobody actually uses them. They use GCC, Clang, and MSVC, written in C++. Everybody knows that it's possible to self-host C, so the benefit of actually doing so in practice is minimal. It's obviously possible to write a Rust compiler in Rust end-to-end. Acting like it's a second tier language because actively doing so not a top focus of the community is gatekeep-y and ridiculous.
- zer8k 3y agoExcept gluing yourself to LLVM has it's own problems. Like, for example, any platform that LLVM doesn't support you can't support either. LLVM is great. The monoculture and smug elitism it produces is not. > Acting like it's a second tier language because actively doing so not a top focus of the community is gatekeep-y and ridiculous. It is probably one of the major reasons we won't see a Rust compiler shipped with an operating system for a very long time. That doesn't make it second tier. However, Rust fans seem to want to stick their head in the sand when their baby is criticized. I am a Rust (language) fan myself. I am just willing to criticize the language. I do not understand why the Rust community has such a volatile response to honest, valid, criticism.
- learn-forever 3y agoit's a ridiculous criticism, and the insult doesn't make it less ridiculous
- dralley 3y ago>It is probably one of the major reasons we won't see a Rust compiler shipped with an operating system for a very long time. Even most linux distros don't ship with GCC out of the box... much less MacOS and Windows with their respective compilers. If your standard is "Gentoo and FreeBSD will never ship it out of the box" then I'm going to 100% stand by my statement that this is weird and gatekeep-y. Especially when the Windows kernel and userspace system libraries both have Rust in them. https://www.bleepingcomputer.com/news/microsoft/new-windows-11-build-ships-with-more-rust-based-kernel-features/ https://www.bleepingcomputer.com/news/microsoft/new-windows-... https://www.thurrott.com/windows/282471/microsoft-is-rewriting-parts-of-the-windows-kernel-in-rust https://www.thurrott.com/windows/282471/microsoft-is-rewriti...
- tialaramex 3y ago> we won't see a Rust compiler shipped with an operating system for a very long time. I can't figure out what this constraint means. My Windows laptop doesn't seem to have provided a C compiler, so, maybe that's a problem for Windows? Huh, well I guess I can buy or download a third party compiler, that's easy enough, but then, I can do that for Rust too, so, doesn't seem like a difference. Meanwhile on this Fedora machine, the Rust compiler came with the OS. So, is this not an operating system? Maybe the stuff it comes with isn't "shipped with" it somehow? And so there's no C compiler "shipped with" this operating system either, although GCC was installed too ? I just don't know what to make of such a criticism.
- merlincorey 3y ago> Acting like it's a second tier language because actively doing so not a top focus of the community is gatekeep-y and ridiculous. Here's where I think you are quite a bit off target, personally. I certainly was not and I don't believe the GP you originally responded to was saying that "Rust is a second tier language due to [lack of self-hosted compiler]", so hopefully we can set that statement aside and ignore it now. Let's instead focus on your first statement, which is directly related to what GP and I were arguing: > It's obviously possible to write a Rust compiler in Rust end-to-end. It is certainly possible but actually doing so is completely non-obvious because the grammar for Rust is much more complicated than C, and Rust has no formal language specification (let alone an international standard). While Python does not have an international standard, it does have a formal language specification, which is what allows for things like PyPy to exist. Meanwhile, to truly understand Rust, one must be an expert in C and learn the `rustc` code base. It seems like, practically, knowing C and being able to write compilers in C is quite useful if you want to make an impact in Rust or maybe try your hand at making some future Rust replacement (hopefully with a language specification that others can follow).
- dralley 3y ago> It is certainly possible but actually doing so is completely non-obvious because the grammar for Rust is much more complicated than C, and Rust has no formal language specification (let alone an international standard). The Rust compiler frontend is written in Rust. It doesn't matter how non-trivial writing a Rust frontend is if you can restrict the problem domain to writing a new backend for the existing compiler frontend. And you can. As it stands there is the LLVM backend that everyone is familiar with, the GCC backend which is nearing completion, and the Cranelift backend which is written in Rust. Zig is similar. Yes, they are going to replace LLVM by default, but they're not getting rid of their LLVM backend entirely. The main difference between Rust and Zig here is a matter of defaults, where Rust defaults to using LLVM while Zig will default to their self-hosted compiler. > Meanwhile, to truly understand Rust, one must be an expert in C and learn the `rustc` code base. Are you under the impression that the "rustc" codebase is written in C/C++? It is not... It uses LLVM, yes, but it's written in Rust. > I certainly was not and I don't believe the GP you originally responded to was saying that "Rust is a second tier language due to [lack of self-hosted compiler]", so hopefully we can set that statement aside and ignore it now. The discussion started with the statement that Rust will never replace unsafe languages without the ability to self-host, and then continued with the statement that "Self Hosting your own compiler traditionally was the "end-game" of making a compile-able language. It's a sort of proof of fitness that the language can literally stand on its own." I don't think that was a completely unfair reading of these statements. The implication is that Rust is "not a fit language" because it "cannot stand on its own" and therefore "will never replace unsafe languages".