Live data from Hacker News

Zig self hosted compiler is now capable of building itself

github.com

221–230 of 285 posts

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

#221

Earlier quoted context omitted.

* What kind of tests are these "behavior test"? * Is that a list of compilation targets? * If not all behavior tests pass, does that not mean that the compiler fails to compile programs correctly? Please indulge those of us who are not familiar with self-hosting compiler engineering.

> What kind of tests are these "behavior test"? Snippets of zig code that use language features and then make sure those features did the right thing. You can find them here: https://github.com/ziglang/zig/tree/master/test/behavior > Is that a list of compilation targets? Mostly. Pedantically, it's a list of code generation backends, each of which may have multiple compilation targets. So for example the LLVM backend…

To add to what Spex said: also some of those tests check language features that the compiler code doesn't exercise, like async/await. This means that the compiler is able to build itself, but is not able to build every possible valid Zig program. We're getting there though :^)

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

#222

Earlier quoted context omitted.

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

Suppose I wanted to try learning Rust again; is there a resource for someone with a lot of (hobbyist) programming experience, and experience with low level languages and memory management (e.g. C), but not complicated low-level languages, like C++?

When I tried to work with Rust a few years ago I found it utterly impenetrable. I just had no idea what the borrow checker was doing, did not understand what the error messages meant, and honestly couldn't even understand the documentation or the tutorials on the subject. Understanding what is happening in C or Zig is pretty easy; in Rust it's always been a nightmare for me. I just really don't grok the "lifetime" concept at all, it feels like I'm trying to learn academic computer science instead of a programming language.

Rust feels to me like a powerful, expressive language for professional programmers at the top of their game. That's a complement for any language. But it comes at the cost of mind-numbing complexity for anyone who's not an expert.

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

#223

Earlier quoted context omitted.

Sort of left it to the readers and hopefully encourage people to investigate for themselves. It's far too easy to get into "this benchmark vs this benchmark", etc. Memory usage is overall a complicated topic, which I think Andrew's comment doesn't do justice to. Granted the Zig team has done some impressive work, much of the memory usage & bloat in the C++ world comes from real world programs and libraries and the in…

Zig has a few extra tricks up their sleeves compared to most languages. The ones that come to mind are * MultiArrayList * arbitrary size-integers that make it easy to pack data very tightly * easy access to several special purpose allocators which reduce the need for strategies like reference counting

Perhaps, though nothing there that's not been available for a while. To be fair Zig has integrated some of these features well.

* MultiArrayList is convenient and easy to do in Rust, D, Nim. Odin seems built around it. * Arbitrary bit-size integers seem more gimmicky than anything and similar to struct bitfields in other languages (except Rust oddly). Most compilers don't even pack uint8/uint16's for performance reasons. * Special purpose allocators are a bit more interesting. Still they don't provide actual memory safety AFAICT and can have fragmentation and performance penalties.

It'll be interesting to see larger Zig code bases emerge in different fields and see how the memory footprint compares in practice.

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

#224

Earlier quoted context omitted.

Zig has a few extra tricks up their sleeves compared to most languages. The ones that come to mind are * MultiArrayList * arbitrary size-integers that make it easy to pack data very tightly * easy access to several special purpose allocators which reduce the need for strategies like reference counting

Perhaps, though nothing there that's not been available for a while. To be fair Zig has integrated some of these features well. * MultiArrayList is convenient and easy to do in Rust, D, Nim. Odin seems built around it. * Arbitrary bit-size integers seem more gimmicky than anything and similar to struct bitfields in other languages (except Rust oddly). Most compilers don't even pack uint8/uint16's for performance reas…

What? 8- and 16-bit are never 32-bit aligned nor sized.

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

#225

Earlier quoted context omitted.

I don't understand why people want fast compile speeds so much. My day job is/was writing C on something that requires 30+ minutes for one compilation run. It feels like people want fast compilation speeds because they need to keep running their software for some reason. Fast compilation speeds are a nice to have but basically irrelevant for normal developing of software in my experience.

I like knowing what compiler errors I've made in near real time feedback. Also useful for running tests on save.

That's something of a double edged sword here.

Somehow like having live orthographic checker always on while writing some prose: it can't easily distract the mind from focusing on the expression of ideas. And even if you try to ignore all these hints of early micro fixes, the brain is at very least spending resources at filtering avoidable noise.

Thus said, as long as this is an option that can easily switched, the possibility to limit notifications of these issues can be isolated into dedicated sessions.

I guess it might also greatly depend on each individual, how they appreciate to work, and how it impacts their workflow.

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

#226
post #220

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 haven’t tried Zig yet, but I liked Common Lisp better than Go and Rust for fast CLI apps/scripts. You need to dump an image with all your deps already loaded, and then you can run small scripts with instant compilation very fast. It’s an ergonomic language with good IDE support in emacs. There are some rough edges around (inconsistent API design, the package manager not using HTTPS, …), but tolerable.

Common Lisp doesn't offer features like sum types right? I am under the impression that it is a dynamically typed language like most Lisps, but I could be wrong.

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

#228
post #167

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…

Nim strikes a great balance. No need for a low level language for cli and general software. I liked crystal but the lack of support on windows and lackluster dev experience made me stick to Nim. Nim also can double as a web language by transpiling to JS.

I would not recommend Nim.

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

#229
post #93

Earlier quoted context omitted.

Sorry I may have missed the sarcasm. Your day job project takes half an hour to compile and you don't see the point in speeding that up?

It wasn't sarcasm. My "irrelevant" point meant "it's irrelevant for a factor in picking a language", as in "it doesn't significantly contribute to whether a project is possible in the long term". If compile times are longer you just compile less often and write larger portions of code at a time and you generally keep writing code while it compiles.

Works when you've been using a minimal language like C for over a decade and you're an expert. For people learning a new language they constantly need to be recompiling to check their assumptions are correct, that's why it's so important for the masses.

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

#230

Earlier quoted context omitted.

I think what he's saying is there is a way to carelessly use smart pointers in rust. pub enum List { Empty, Elem(i32, Box ), } instead of : pub struct List { head: Link, } enum Link { Empty, Some(Box ), } struct Node { elem: i32, next: Link, }

Can you explain the difference between these approaches? Is it just that the first example allocates an extra u16 (tag of the tagged union) (ignoring any overhead)?

Notice that if I make this alleged "List" with a single data item in it, my data lives in the List object I just made (probably on the stack), but an empty List gets allocated on the heap.

I thought Aria's "Entirely Too Many Lists" tutorial actually tries to build this, but it actually doesn't, she draws you the resulting "list" and then is like, OK, that's clearly not what we want, let's build an actual (bad, slow, wasteful) linked list as our first attempt.

Post reply on HN