Live data from Hacker News

Zig self hosted compiler is now capable of building itself

github.com

21–30 of 285 posts

Re: Zig self hosted compiler is now capable of building itself

#21

Hello HN! Here is some context to decorate this announcement: The Zig self-hosted compiler codebase consists of 197,549 lines of code. There are several different backends, each at varying levels of completion. Here is how many behavior tests are passing: LLVM: 1101/1138 (97%) WASM: 919/1138 (81%) C: 740/1138 (65%) x86_64: 725/1138 (64%) arm: 490/1138 (43%) aarch64: 411/1138 (36%) As you might guess, the one that thi…

Congratulations with the milestone! Does using Zig over C++ lead to "less memory, and represents a modest performance"? Or was the C++ implementation a bit sloppy? (lacking data oriented design for instance) Also, what specifically are you most excited using Zig for?

Thanks :)

The new Zig implementation is certainly more well designed than the C++ implementation, for several reasons:

* It's the second implementation of the language

* It did not have to survive as much evolution and language churn

* I leveled up as a programmer over the last 7 years

* The Zig language safety and debugging features make it possible to do things I would never dream of attempting in C++ for fear of footguns. A lot of the data-oriented design stuff, for example, makes use of untagged unions, which are nightmarish to debug in C++ but trivial in Zig. In C++, accessing the wrong union field means you later end up trying to figure out where your memory became corrupted; in Zig it immediately crashes with a stack trace. This is just one example.

* Zig makes certain data structures comfortable and ergonomic such as MultiArrayList. In C++ it's too hard, you end up making performance compromises to keep your sanity.

Generally, I would say that C++ and Zig are in the same performance ballbark, but my (obviously biased) position is that the Zig language guides you away from bad habits where as C++ encourages them (such as smart pointers and reference counting).

As for less memory, I think this is simply a clear win for Zig. No other modern languages compete with the tiny memory footprints of Zig software.

Some of the projects I am exited to use Zig for:

* rewriting Groove Basin (a music player server) in zig and adding more features

* a local multiplayer arcade game that runs bare metal on a raspberry pi

* a Digital Audio Workstation

Re: Zig self hosted compiler is now capable of building itself

#22

Earlier quoted context omitted.

C?

You're commenting on an article about Zig which became self-hosted and can compile C. (There's also lots of other C compilers available)

Zig compiles C/C++ by deferring the vast majority of the work to libclang, which is written in C++. Also note Zig is self-hosted when using the LLVM backend, which means deferring to C++ for much of the code generation. There is no "end-to-end Zig" self-hosted compiler yet, because the Zig native backends are not as near completion. See the creator's comment about the breakdown: https://news.ycombinator.com/item?id=31052234. (I'm excited about this progress, so this is not meant as any kind of knock on Zig, which I think is quite impressive)

But you're right that C is not a good example.

Re: Zig self hosted compiler is now capable of building itself

#23

Earlier quoted context omitted.

Congratulations with the milestone! Does using Zig over C++ lead to "less memory, and represents a modest performance"? Or was the C++ implementation a bit sloppy? (lacking data oriented design for instance) Also, what specifically are you most excited using Zig for?

Thanks :) The new Zig implementation is certainly more well designed than the C++ implementation, for several reasons: * It's the second implementation of the language * It did not have to survive as much evolution and language churn * I leveled up as a programmer over the last 7 years * The Zig language safety and debugging features make it possible to do things I would never dream of attempting in C++ for fear of f…

Thanks for the detailed answer! I have more questions, if you'll indulge me:

If I understood it correctly, you think smart pointers and reference counting are bad habits. Why? Especially the smart pointers bit.

Why does Zig use less memory than other languages? Is it inherent to Zig, or can it be reproduced in other languages?

Re: Zig self hosted compiler is now capable of building itself

#24
post #16
post #8

Earlier quoted context omitted.

Zig as the “Kotlin of C” makes it very appealing. Kotlin has seen fantastic adoption in JVM projects because you can convert files one at a time from .java to .kt, with only a modicum of one-time build system shenanigans up front. Then your team can gain experience gradually, fill in missing pieces like linters over time, all without redesigning your software. What zig offers is even better - because zig included a C…

Kotlin has seen fantastic adoption in Android projects, because of the way Google pushes it, while stagnating Android Java on purpose. On the JVM world not really. https://www.infoq.com/news/2022/03/jrebel-report-2022/

Are they pushing? Most documentation for Android dev is still Java. Or by default Java. It's only the Intelij guys pushing for Kotlin by creating a lockin in their IDE. One reason I refuse to use it.

Re: Zig self hosted compiler is now capable of building itself

#25
post #16

Earlier quoted context omitted.

Kotlin has seen fantastic adoption in Android projects, because of the way Google pushes it, while stagnating Android Java on purpose. On the JVM world not really. https://www.infoq.com/news/2022/03/jrebel-report-2022/

As someone not familiar with android development, this is somewhat confusing because I always thought Google was pushing dart/flutter for mobile these days? Or is it both at once?

Dart/Flutter is their React Native competitor. It’s in the same space as Xamarin - A secondary language and UI toolkit who’s selling point is rapid development for multiple platforms.

Kotlin is to Java (on Android) as Swift is to Objective-C (on Apple) - the successor primary platform language.

Re: Zig self hosted compiler is now capable of building itself

#26
post #16

Earlier quoted context omitted.

Kotlin has seen fantastic adoption in Android projects, because of the way Google pushes it, while stagnating Android Java on purpose. On the JVM world not really. https://www.infoq.com/news/2022/03/jrebel-report-2022/

Are they pushing? Most documentation for Android dev is still Java. Or by default Java. It's only the Intelij guys pushing for Kotlin by creating a lockin in their IDE. One reason I refuse to use it.

You have missed all the Kotlin only Jetpack libraries, NDK documentation now using Kotlin, Jetpack libraries originally released in Java now rewritten in Kotlin.

They are still using Android Java on the system layers, because they aren't rewriting the whole stack.

Even the update for Java 11 LTS subset on Android 13 is mostly likely caused by the Java ecosystem moving forward, than the willingness of Android team to support anything other than what can be desugared into Java 8 / DEX somehow.

You are right in relation to JetBrains, they even acknowledge it on their blog post introducing Kotlin.

https://blog.jetbrains.com/kotlin/2011/08/why-jetbrains-need...

"And while the development tools for Kotlin itself are going to be free and open-source, the support for the enterprise development frameworks and tools will remain part of IntelliJ IDEA Ultimate, the commercial version of the IDE. And of course the framework support will be fully integrated with Kotlin."

Re: Zig self hosted compiler is now capable of building itself

#27

Are there any languages out there that can only be compiled by a compiler written in their own language? Presumably because the original pre-dogfood compiler stopped being maintained years ago. So that if we somehow lost all binaries of the current compiler, that language would effectively be lost?

C?

A lot of popular C compilers are actually written (at least partially) in C++ these days.

Re: Zig self hosted compiler is now capable of building itself

#28

Earlier quoted context omitted.

Congratulations with the milestone! Does using Zig over C++ lead to "less memory, and represents a modest performance"? Or was the C++ implementation a bit sloppy? (lacking data oriented design for instance) Also, what specifically are you most excited using Zig for?

Thanks :) The new Zig implementation is certainly more well designed than the C++ implementation, for several reasons: * It's the second implementation of the language * It did not have to survive as much evolution and language churn * I leveled up as a programmer over the last 7 years * The Zig language safety and debugging features make it possible to do things I would never dream of attempting in C++ for fear of f…

Great, thanks for those details! I primarily develop using C++ and avoiding pitfalls (smart pointers, exceptions, unintended memory allocations) takes a lot of effort.

I enjoy synthesizers (including Eurorack) and looking forward playing with a Zig DAW!

Re: Zig self hosted compiler is now capable of building itself

#29

Earlier quoted context omitted.

Thanks :) The new Zig implementation is certainly more well designed than the C++ implementation, for several reasons: * It's the second implementation of the language * It did not have to survive as much evolution and language churn * I leveled up as a programmer over the last 7 years * The Zig language safety and debugging features make it possible to do things I would never dream of attempting in C++ for fear of f…

Thanks for the detailed answer! I have more questions, if you'll indulge me: If I understood it correctly, you think smart pointers and reference counting are bad habits. Why? Especially the smart pointers bit. Why does Zig use less memory than other languages? Is it inherent to Zig, or can it be reproduced in other languages?

I think Zig prefers explicit memory management, because allocations may fail and should be handled explicitly, and because automatic deallocations lead to hard-to-predict lifetimes (excess memory usage, and bugs for resource handles that are destructed at hard to predict moments).

These are things that a "systems language" programmer should put in the work to do correctly/near-optimally, and not ask the compiler to just do something "good enough", like Python would.

Re: Zig self hosted compiler is now capable of building itself

#30

Hello HN! Here is some context to decorate this announcement: The Zig self-hosted compiler codebase consists of 197,549 lines of code. There are several different backends, each at varying levels of completion. Here is how many behavior tests are passing: LLVM: 1101/1138 (97%) WASM: 919/1138 (81%) C: 740/1138 (65%) x86_64: 725/1138 (64%) arm: 490/1138 (43%) aarch64: 411/1138 (36%) As you might guess, the one that thi…

> written in Zig instead of C++, uses significantly less memory, and represents a modest performance improvement

That's particularly interesting considering the rust compiler in rust has never been as fast as the original OCaml one

Post reply on HN