Live data from Hacker News

Zig self hosted compiler is now capable of building itself

github.com

61–70 of 285 posts

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

#61

Probably a stupid question, but is LLVM a sort of cheat for "self compiling"? Shouldn't you need to compile LLVM as well?

They’re working towards having native backends for x86-64, aarch64, etc., that are all written in Zig, making LLVM an optional dependency, and eliminating literally all uses of non-Zig code (including no mandatory use of C standard library, for example) for those builds. https://news.ycombinator.com/item?id=31052234

I’m assuming these will primarily be for super fast debug builds (at least to start), and LLVM (and maybe C backend too) will still be the favored backend(s) for release builds.

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

#62

Andrew how will the self hosted compiler maintain a known trust back to assembly? i.e how can someone look at a self hosted zig compiler and build it themself from source, never needing to download blobs from the internet? Otherwise you lose the ability to trust anything you build.

Checkout the video Andrew linked in this thread. He talks about this in detail.

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

#63

Andrew how will the self hosted compiler maintain a known trust back to assembly? i.e how can someone look at a self hosted zig compiler and build it themself from source, never needing to download blobs from the internet? Otherwise you lose the ability to trust anything you build.

Zig specifics aside… build it from source using what? Another compiler. Okay, so you can compile that one from source. But what does that? Another compiler.

Unless you’re recording memory contents and executing instructions by hand, you’ve just discovered the Ken Thompson hack. At some point the pragmatic thing is to trust some bits from a trusted source (e.g. downloaded from an official repo w/ a known cert, etc.).

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

#64

I was thinking of learning Rust but it seems a bit overkill due to manual memory management as compared to languages with similar speed like Nim, Zig, and Crystal. How would one compare these languages? Is it worth learning Rust or Zig and dealing with the borrow checker or manual memory management in general, or are GC languages like Nim or Crystal good enough? I'm not doing any embedded programming by the way, just…

I've found that Go is not elegant enough for me and Rust is too difficult to write (I started using Rust in 2015 and after years of trying I eventually realized Rust doesn't make sense for most apps), so I'm all in on Crystal. Despite not having much prior Ruby experience, I absolutely love the language.

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

#65
post #31

D has a C compiler built-in now, I wonder if we could bootstrap all the toolchain now.

Don't most toolchains have a rather large C++ component?

Just parsing C++ is a rather large undertaking (my understanding is that it's syntax is turing complete).

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

#66
post #42

Earlier quoted context omitted.

> 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

Well, OCaml Rust compiler also didn't use LLVM and used its own lightweight code generator and I think self-hosted Rust compiler frontend was in fact faster than OCaml Rust compiler frontend.

With both projects, how much of the improvement is simply building for the second time?

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

#67
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?

Not sure where you got that impression from, the Android team has never pushed, let alone mentioned, Dart/Flutter, ever. All the Flutter advertising you hear is from the Flutter team.

Kotlin and Java are the main languages supported on Android.

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

#68

Andrew how will the self hosted compiler maintain a known trust back to assembly? i.e how can someone look at a self hosted zig compiler and build it themself from source, never needing to download blobs from the internet? Otherwise you lose the ability to trust anything you build.

Zig specifics aside… build it from source using what ? Another compiler. Okay, so you can compile that one from source. But what does that? Another compiler. Unless you’re recording memory contents and executing instructions by hand, you’ve just discovered the Ken Thompson hack. At some point the pragmatic thing is to trust some bits from a trusted source (e.g. downloaded from an official repo w/ a known cert, etc.).

You just need 1 compiler written in assembly, and work your way up from there.

C17 -> assembly of your choice, written in assembly

Zig -> C17 “transpiler”, written in C17

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

#69

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?

GHC is nearly impossible to bootstrap if you don't consider the vendored transpiled C code to be source. Versions of GHC not dependent on GHC were never public AFAIK.

https://elephly.net/posts/2017-01-09-bootstrapping-haskell-p...

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

#70

I was thinking of learning Rust but it seems a bit overkill due to manual memory management as compared to languages with similar speed like Nim, Zig, and Crystal. How would one compare these languages? Is it worth learning Rust or Zig and dealing with the borrow checker or manual memory management in general, or are GC languages like Nim or Crystal good enough? I'm not doing any embedded programming by the way, just…

I've found that Go is not elegant enough for me and Rust is too difficult to write (I started using Rust in 2015 and after years of trying I eventually realized Rust doesn't make sense for most apps), so I'm all in on Crystal. Despite not having much prior Ruby experience, I absolutely love the language.

Modern Rust is much more straightforward than it was in 2015. It's effectively two different languages, albeit maintaining backward compatibility (i.e. code written for Rust 1.0 should still compile today, with proper edition settings).
Post reply on HN