Live data from Hacker News

Zig self hosted compiler is now capable of building itself

github.com

71–80 of 285 posts

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

#71

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.).

See https://dwheeler.com/trusting-trust/

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

#72
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).

So you start with a C++ compiler written in C. Hence bootstrap, rather than compile from source.

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

#73

Earlier quoted context omitted.

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?

From talking to a Googler the reason why Google devotes resources to Kotlin is that there was and still is a large external demand from the Android development community for Kotlin.

Kotlin adoption was triggered from inside, with some anti-Java attitude.

https://talkingkotlin.com/the-first-kotlin-commit-in-android...

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

#74
post #29

Earlier quoted context omitted.

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 j…

> 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). I don't really feel this is the case in Rust.

No post body was provided.

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

#75

Earlier quoted context omitted.

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

Why do you trust the assembler you got from somewhere any more than a compiler?

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

#76

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.).

Rice's Theorem makes the Ken Thompson hack impossible in general. He only executed his hack in a single short-term demonstration against a specific target, but it's not possible to make a "long-con" against an open-source project with lots of activity and lots of people building it even if you find a way to infect nearly all of those people.

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

#77
post #36

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 all the context. Curious to know more about the concept/design of the DAW.

Seconded.

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

#78

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…

Can you clarify about the union part? Did you meant that zig allowed you replacing what would be untagged union in C++ with tagged union in zig? Or does the zig compiler has some kind of debug sanitizer mode which automatically turns untagged unions into tagged unions with checks?

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

#79

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…

It's funny i came to Rust from Go, Python, NodeJS, etc after a combined .. 15 years or so. I've been using Rust full time (work & home) for ~2 years now.

Obviously i'm biased, but i quite enjoy it. I find i am more efficient now than before, because it manages to give me the ease of the "easier" languages quite often with a rich set of tooling when i need to go deeper.

Personally i feel the concern over the borrow checker is way overblown. 95% of the time the borrow checker is very simple. The common worst case i experience is "oh, i'm borrowing all of `foo` when i really want `foo.bar` - which is quite easily solved by borrowing just the `.bar` in a higher scope.

The lifetime jazz is rarely even worth using when compared to "easier" languages. Throw a reference count around the data and you get similar behavior to that of them and you never had to worry about a single lifetime. Same goes for clones/etc.

I often advocate this. For beginners to use the language like it was a GC'd language. A clone or reference count is often not a big deal and can significantly simplify your life. Then, when you're deeper into the language you can test the waters of lifetimes.

So yea. Your mileage will vary i'm sure. But i find Rust to be closer to GC'd languages than actual manual languages, in UX at least. You won't screw up and leak or introduce undefined behavior, which is quite a big UX concern imo.

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

#80

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…

If the union is untagged, how can it be determined (at runtime) that you've accessed the wrong field?
Post reply on HN