Earlier quoted context omitted.
Zig actually bundles LLVM's Clang, which it uses to compile C with the `zig cc` command. But the long term goal seems to not be so tightly coupled to LLVM, so I'm expecting that to move elsewhere. They still do some clever stuff around compiler-rt, allowing it to be better at cross-compilation than raw Clang, but the bulk of it is mostly just Clang. There is also another C compiler written in Zig, Aro[1], which seems…
They're not planning on dropping Clang.
Writing a C Compiler, in Zig (2025)
51–60 of 74 posts
Re: Writing a C Compiler, in Zig (2025)
#52I'm not sure why people seem to be under the impression that writing a compiler means that the language the compiler is implemented in should have "low level" features. A compiler is just a text -> text translation tool if you can leverage other tools such as an assembler and never needs to access machine level instructions. E.g., Pascal compilers have traditionally been written in Pascal, hardly a language which con…
> I'm not sure why people seem to be under the impression that writing a compiler means that the language the compiler is implemented in should have "low level" features. Performance. You definitely can write a compiler in a high-level language and given the choice I certainly prefer to on my hobby projects. Having a garbage collector makes so many compiler algorithms and data structures easier. But I also accept tha…
I promise that he knows a thing or two about compilers and performance!
For what it's worth, I agree with him. A recent example is the porting of the TypeScript compiler to Go: it hasn't been fully released yet, but people are already going wild for its performance improvement over the original in-TS compiler.
Of course, it took them over a decade to reach the point where a port was necessary - so it's up to you to decide when that decision makes sense for your language.
Re: Writing a C Compiler, in Zig (2025)
#53Earlier quoted context omitted.
I think Rust is "higher level" than C or Zig in the sense that there are most abstractions than C or Zig. Its not Javascript, but it is possible to program Rust without worrying too much about low level concerns.
Except if you need to expose or consume a C API, or you need to use some obscure performance improvement.
Re: Writing a C Compiler, in Zig (2025)
#54Earlier quoted context omitted.
The author was fed up with not having data structures already provided, and needing to roll his own
Not really understanding what this would be though, zig has all the basic stuff you would expect in its stdlib (hashmap, queues, lists etc) just like Rust
Re: Writing a C Compiler, in Zig (2025)
#55Re: Writing a C Compiler, in Zig (2025)
#56Earlier quoted context omitted.
They're just removing the obligate dependency. I'm pretty sure they will keep it around as a first-class supported backend target for compilation.
No, the whole point is to eliminate dependencies that they have to maintain. "not obligate" really doesn't mean anything if it's available as a backend--the obligation is on the Zig developers to keep it working, and they want to eliminate that obligation. And the original question was "how will they reivent the wheel on the man-years of optimization work went into LLVM to their own compiler infrastructure?" -- the a…
That's exactly wrong.
> There are a whole lot of misstatements about Zig and other matters in the comments here by people who don't have much knowledge about what they are talking about.
Well spoken. You should look in the mirror.
Re: Writing a C Compiler, in Zig (2025)
#57Earlier quoted context omitted.
Feels like maybe something lost in translation with their explanation - they say they were fed up of data structures etc. but they returned to Rust? I’m assuming there’s something a bit more nuanced about what they got tired of with Zig
Rust is a world away from Zig as far as being low-level. Rust does not have manual memory management and revolves around RAII which hides a great deal of complexity from you. Moreover it is not unusual for a Rust project to have 300+ dependencies that deal with data structures, synchronization, threading etc. Zig has a rich std lib, but is otherwise very bare and expects you to implement the things you actually want.
Re: Writing a C Compiler, in Zig (2025)
#58I'm not sure why people seem to be under the impression that writing a compiler means that the language the compiler is implemented in should have "low level" features. A compiler is just a text -> text translation tool if you can leverage other tools such as an assembler and never needs to access machine level instructions. E.g., Pascal compilers have traditionally been written in Pascal, hardly a language which con…
This comment started out strong, but then: > Pascal compilers have traditionally been written in Pascal, hardly a language which conjures up a "low level" image. It may be the case that it doesn't conjure up such an image, but Pascal is approximately on the same rung as Zig or D—lower level than Go, higher level than assembly. If folks have a different impression, the problem is just that: their impression.
Re: Writing a C Compiler, in Zig (2025)
#59I'm not sure why people seem to be under the impression that writing a compiler means that the language the compiler is implemented in should have "low level" features. A compiler is just a text -> text translation tool if you can leverage other tools such as an assembler and never needs to access machine level instructions. E.g., Pascal compilers have traditionally been written in Pascal, hardly a language which con…
It's because a compiler is supposed to be high-level to low-level; you already have a lower-level language to write in it, and not a higher-level one. Writing a C compiler in a higher-level language than C is going backwards. E.g., Pascal compilers have traditionally been written in Pascal, hardly a language which conjures up a "low level" image. How could the first Pascal compiler be compiled if it was written in Pa…
Therein lies the magic of bootstrapping a language compiler written in the same language. Look it up.
Re: Writing a C Compiler, in Zig (2025)
#60Earlier quoted context omitted.
It's because a compiler is supposed to be high-level to low-level; you already have a lower-level language to write in it, and not a higher-level one. Writing a C compiler in a higher-level language than C is going backwards. E.g., Pascal compilers have traditionally been written in Pascal, hardly a language which conjures up a "low level" image. How could the first Pascal compiler be compiled if it was written in Pa…
> How could the first Pascal compiler be compiled if it was written in Pascal, but a Pascal compiler didn't yet exist? Therein lies the magic of bootstrapping a language compiler written in the same language. Look it up.