Live data from Hacker News

Zig is now self–hosted by default

github.com

81–90 of 115 posts

Re: Zig is now self–hosted by default

#82
post #40

Earlier quoted context omitted.

It's possible to bootstrap GCC starting from only a 357-byte binary seed: https://github.com/fosslinux/live-bootstrap

This work is impressive, but ... that's still a binary blob, and isn't the system it has to be run on kind of one as well?

Yeah, it's a binary blob, but it's small enough to be easily auditable. Anyone with some knowledge of x86 assembly can read the annotated version [1] and verify that it does what it claims (which is to convert ASCII hex with comments into binary).

You're right, it also requires a Linux kernel, and of course, you also have to trust the hardware you're running it on. Still, it reduces the amount of stuff we have to take for granted as trusted, which I think is a good thing. (I'm not involved in the project, just an admirer).

[1]: https://github.com/oriansj/bootstrap-seeds/blob/b09a8b8cbcb6...

Re: Zig is now self–hosted by default

#83
post #44

I never understood why "self-hosting" is considered a good thing. Sure, the compiler developers can write in their favorite language and I guess it means the language is stable enough to be used in a complex project; however requiring an (older) compiler to build the compiler seems a significant complication for software distributions. You either have to set up an ever increasing chain of compilers, as the complexity…

I believe Andy noted that it's way easier to find contributors for the self hosted compiler. If someone is passionate about the language, they want to write the language, not C++. And specifically for languages like Rust and Zig, the explicit orthodoxy is that the language is a better successor to C++/C. If you're spending your time telling people that they shouldn't write C++/C and should instead write your language…

PyPy is written in pure python and transpiled to C++

Re: Zig is now self–hosted by default

#84
Congrats to the zig team! This is a big milestone and they must have put an enormous amount of work into making it happen.

At the same time, the reason this milestone seems so significant is because the language is already quite complex. It seems likely to get even more complex over time. Some metrics of complexity that jump out are the amount of compiler source code, compiler compilation time and required resources (cpu/memory). There are other languages that have simpler and more efficient bootstrap compilers.

Ideally, a self hosting compiler contains only the minimum amount of information that is strictly necessary to compile itself. It is possible to write one for a simple, imperative, javascript style language in at most a few thousand lines of code in pretty much any reasonable turing complete language (something like lisp with barely any syntax can be done even more succinctly). Because the simple language is so small, the implementation can also be written in a high level language that targets that same high level language, i.e. the bootstrap compiler could be a transpiler to javascript written in javascript. There is little point in compiling to native assembly during the bootstrap process because the language is so small that a good javascript implementation should be capable of compiling the bootstrap source in under 200ms on a decent laptop. Once the compiler can compile itself, then one can add more features to it, such as a more robust type system, a native backend or automatic memory management without gc. A positive feedback loop emerges because these features are implemented as optimizations to the compiler itself. It gets faster as more features are added to it but it is always fast because it was fast from the beginning. With good benchmarking in place, it should never get slower at compiling itself.

Such a compiler/language would be very minimal by design but a more batteries included language can be built on top of it, much like how an os kernel is extended by user space programs.

A historical example of this kind of self-hosting compiler is Forth. It is easy to bootstrap (see e.g. JonesForth). Derived programs are written by extending the compiler with a new vocabulary specific to the problem at hand. Development is often done in a REPL environment for fast feedback. REPL sessions can be saved as source files once the program works as expected. Forth syntax is unfortunately inscrutable to most and the stack based design is not great for every problem so I wouldn't recommend actually using it, but it contains important ideas that can be adopted into more modern languages.

What the zig team has done strikes me as very, very difficult, so I tip my cap for the effort it must have required. In the long run though, it feels almost inevitable that a simpler language with the more desirable high level properties described above will eat its lunch. As painful as it would be, I believe the best thing the zig team could do to ensure the language's long term survival would be to completely rewrite the language from scratch (zag?) using the knowledge that they've gained during their initial bootstrap process to distill zig to its essence.

Re: Zig is now self–hosted by default

#85

Earlier quoted context omitted.

There's a third option that you missed which is what Zig does. It has a "bootstrap" compiler, written in C, which is kept in sync with the self-hosted compiler. Features are implemented twice, once in the bootstrap compiler, once in the self-hosted compiler. So the build process involves a fixed set of steps - stage1, stage2, stage3 - and the chain never grows more than this. No pre-existing binaries are required.

> No pre-existing binaries are required. Except for of course a c compiler.

Which is…self-hosted.

Re: Zig is now self–hosted by default

#87
post #3

Earlier quoted context omitted.

Congratulations. This is an important milestone.

For Andrew it must feel he's now on the home stretch towards 1.0, finally!

In a previous presentation I think he mentions they are still aiming at something like 2025.

Re: Zig is now self–hosted by default

#88
post #83

Earlier quoted context omitted.

I believe Andy noted that it's way easier to find contributors for the self hosted compiler. If someone is passionate about the language, they want to write the language, not C++. And specifically for languages like Rust and Zig, the explicit orthodoxy is that the language is a better successor to C++/C. If you're spending your time telling people that they shouldn't write C++/C and should instead write your language…

PyPy is written in pure python and transpiled to C++

Pypy is mostly written in a restricted dialect of Python (rpython), not pure python. They're substantively different.

Re: Zig is now self–hosted by default

#89
post #28

Earlier quoted context omitted.

Maybe the runtime safety in debug builds? Like for out of bounds, int overflows, etc. In my zig projects those checks have saved me from using a debugger or valgrind in many cases.

I guess I don't call runtime safety features "debug tooling"? But maybe that's the disconnect here

I think it's funny that I got downvoted for this! For full clarity: I wasn't suggesting that they _shouldn't_ be called debug tooling, just that it's not what I would call that class of feature, and it seems that other people do call it that.

Re: Zig is now self–hosted by default

#90

Earlier quoted context omitted.

> having better debug tooling What debug tooling are you referring to? It seems like people just use lldb to debug zig programs? I'm honestly interested, and searching doesn't turn up good tools as far as I can tell.

Here are some features of Zig that make debugging much easier than C++: * safety checks (equivalent to UBSAN) when triggered, print stack traces that include source code lines and point to the relevant line/column * one of the safety checks is using the wrong field of an untagged union. This one is so underappreciated. Wrong union field access costs so much time to debug in C++ but it is a breeze in zig, you get a cr…

Thanks!
Post reply on HN