2 ms·
> 9. Without a C compiler, we're stuck with, wedded to, and beholden to libclang. > I wouldn't be surprised that the eventual cost of adapting ourselves to >
by AndyKelley 5y ago
> 9. Without a C compiler, we're stuck with, wedded to, and beholden to libclang.
> I wouldn't be surprised that the eventual cost of adapting ourselves to
> libclang will exceed the cost of doing our own C compiler.
This is a really insightful point. I had to learn this the hard way :)
We might follow your lead on this, as we have done with so many other great ideas implemented in D.
Ironically, Vexu started from the other side as you, with the preprocessor mostly done, but the backend left to-do: https://github.com/Vexu/arocc https://github.com/Vexu/arocc
One thing that might make libclang worth the cost, however, is its ability to compile C++ code as well. On Zig's end of things, all we have to do is provide libcxx, libcxxabi, libunwind, compiler-rt, and linking, and then libclang is really pulling a lot of weight by compiling C++ code into object files. Sadly this ability is just too useful in practice to ignore. For example, LLVM itself is C++ so if Zig wants to be able to bootstrap itself, it needs this capability.
Still, I think your maneuver here is the best long-term approach to tackle this problem, and I imagine as time goes on we'll start to migrate towards D's solution here. Maybe someday the Zig distribution that does not have LLVM extensions enabled will be the more popular one.
I'll be watching the evolution of this new feature in D with great interest!
- WalterBright 5y agoI agree that this technique of writing my own C compiler isn't going to work so well with C++: 1. Even though I have written a C++ compiler, it's a C++98 compiler and C++, like the Winchester House, accretes new features constantly, meaning keeping it up to date is impractical. 2. C++ semantics are different enough from D that it is impractical to mechanically map C++ to D. You can do bits and pieces, and dpp does that, but seamlessly doing the bulk of it isn't going to work. (C can be mapped nearly 100% to D.) dpp uses libclang to try and map what it can to D.