Comment by bjourne
2 years ago
Two issues here. The first is code generation and the other is bootstrapping.
Ime, the optimizing passes of a compiler are easy and fun to write. You have to read research papers to understand how register allocation and ssa form works, but it's fun code to write. You just send the ir through various optimizing passes, each refining it in some way. You can write high-quality optimization passes without llvm. But then you want to linearize your ir into machine code. This step is boring and mundane to write unless you care about all the different ways x86-32/64 can encode a "mov [eax+8*ebx], 123" instruction. If you are optimizing for binary size, do you want to bother measuring on which platforms "push eax; push eax; push eax" is shorter than "add rsp,12"? And this is just for x86. Multiply it tenfold for all the other non-x86 architectures irrelevant to most developers. The chance of having major bugs in the code generator for obscure architectures that stay undetected for years is very high.
The second issue is bootstrapping. What compiles the Zig compiler written in Zig? You could, for example, have a non-optimizing minimal Zig compiler written in C that compiles the Zig compiler. But since it's non-optimizing, the Zig compiler would need to be recompiled with the optimizing Zig compiler. Not unsolvable problems, but ime long and complicated build processes risk driving away potential contributors.
I think this blog post addresses the bootstrapping issue: https://ziglang.org/news/goodbye-cpp/
Suppose you are implementing a new feature, how do you test it? First you compile the bootstrapping compiler. Then you use the bootstrapping compiler to compile an unoptimized optimizing compiler. Then you use the optimizing compiler to compile an optimized optimizing compiler. If the compiler doesn't rely on llvm then there will be more code to compile which will make this procedure slower. Especially since the bootstrapping compiler probably isn't very fast (though idk if this is the case with Zig).
No. Bootstrap is involved only if you are making a breaking change. For normal development, this doesn't change anything.
1 reply →
Zig already bootstraps from its C backend, so the second issue is not a problem.
Wasm, I believe.