Live data from Hacker News

Zig self hosted compiler is now capable of building itself

github.com

161–170 of 285 posts

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

#161
post #131

Earlier quoted context omitted.

Any kind of problem? So how do you solve SIMD with C, without language extensions? C is not a special snowflake.

SIMD is not a problem, it's hardware. Compilers tend to take advantage of the CPU-specific SIMD registers and instructions, or you can use them explicitly. Writing generic SIMD code is more portable. C has libraries, and Zig also has vector primitives available through built-in functions.

Any language can have libraries, C is not special here, nor is Zig.

In fact, a few GC enabled languages have explicit SIMD support.

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

#162
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/

Huh. I read about this the other day as well - https://news.ycombinator.com/item?id=30842602 : > If only [Oracle] hadn't sued Google, Java would still have been the pre-eminent language for Android development. Sadly Android is stuck at legacy Java 8 permanently now. So, modern Java is stuck as a server-side language with dozens of competitors. A reply argued that Android is on Java 11 now, and then you noted (hi!) t…

The set of Java 11 LTS features and standard library missing from Android 13 is left as exercise for the reader, they are relatively easy to find out, hence subset.

You can check the Javadoc for the standard library, and the JVM specification. Then compare with DEX/ART and the Android documentation for Java APIs.

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

#163

Earlier quoted context omitted.

Sure, I didn't say they didn't. Are you refuting what I said and implying that a compiler is not self-hosted if it doesn't compile to machine code?

> I didn't say they didn't You said 'that's no longer the case'. Isn't that the same as saying they don't?

In the context of the question, it is no longer the case that a compiler has to compile to machine code to be considered self-hosting. I thought this was clear, but I guess it wasn't

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

#164
post #95

Earlier quoted context omitted.

And as we know from C, every developer is quite capable of taking care of use after free possible bugs.

The point of C and Zig is that you can solve any kind of problems with them. In particular there is much more to memory reclamation than garbage collectors or Rust's borrow checker. Some of the reclamation schemes offer wait-freedom, or efficiently support linearizable operations.

What can C and Zig do that Rust can't?

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

#165
post #89

Earlier quoted context omitted.

I believe GP used assembler to refer to the program which reads your hand-written assembly and produces a binary. That program was presumably given to you so you need to trust it. No, the only way to solve this problem is to start with a computer entirely devoid of code and bit-bang your assembler into the machine with switches, the way the first users of the MITS Altair did it.

You can also bootstrap the way lisp did and write the fist compiler in the language and get a bunch of grad students to hand-compile it. But, yeah if you don't have a bunch of grad students at the ready, an assembler hand-written in machine code is the only option if you want to trust the entire stack. Though I'm not sure what that would get you. I don't know of any higher language compilers that are written directly…

There was a C compiler written in assembly posted on HN 4 years ago [1]!

So yeah, if you wanted to, you could bit-bang an assembler capable of assembling a simple C compiler, then in your simple subset of C you could implement a full C compiler, and from there you can do anything you want!

The grad student approach also sounds interesting. A basic Lisp interpreter can easily fit on a single letter-sized sheet of paper. A single person could hand-compile that, it would just take longer. But, if you're living alone in a cabin in the woods with your own hand-built computer and a personal library of computer books in hard copy, that would be a totally feasible project.

[1] https://news.ycombinator.com/item?id=17851311

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

#166
post #109

Earlier quoted context omitted.

The general purpose allocator in the zig standard library has protections against use after free bugs.

By quarantining all memory forever. This is not a scalable solution because keeping one allocation in a 4kB page alive will leak the whole rest of the page. And if you don't quarantine all memory forever then use after free comes back. If it were that easy to solve UAF then C++ would have solved it by now. There is a scalable solution for UAF that doesn't involve introducing a lifetime/region system: garbage collecti…

The problem of a single allocation keeping a 4 KB page alive is something that you might commonly find with the C++ or Rust way of programming that encourages allocating many individual objects on the heap, but in Zig land this is pretty rare. In fact, compare a Zig implementation of a given application with an equivalent in any other language and you will find there is no contest with respect to the size of the memory footprint.

There are many cool possibilities that C++ has never explored and frankly I find your argument unimaginative.

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

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

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

#168

Earlier quoted context omitted.

The point of C and Zig is that you can solve any kind of problems with them. In particular there is much more to memory reclamation than garbage collectors or Rust's borrow checker. Some of the reclamation schemes offer wait-freedom, or efficiently support linearizable operations.

What can C and Zig do that Rust can't?

Nothing if unsafe Rust is considered, though Zig does not require you to fight the language nearly as much. This is especially obvious with embedded. Zig's philosophy of no hidden control flow or allocation makes things simple. Simplicity is power.

For certain problems you would want a TLA+ specification for safety and especially liveness either way. It's not like Rust absolutely guarantees correctness in all cases.

Rust sits in a sweet spot between C/Zig and languages like Java, but it's not an appropriate replacement for either of them.

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

#169

Earlier quoted context omitted.

You can also bootstrap the way lisp did and write the fist compiler in the language and get a bunch of grad students to hand-compile it. But, yeah if you don't have a bunch of grad students at the ready, an assembler hand-written in machine code is the only option if you want to trust the entire stack. Though I'm not sure what that would get you. I don't know of any higher language compilers that are written directly…

There was a C compiler written in assembly posted on HN 4 years ago [1]! So yeah, if you wanted to, you could bit-bang an assembler capable of assembling a simple C compiler, then in your simple subset of C you could implement a full C compiler, and from there you can do anything you want! The grad student approach also sounds interesting. A basic Lisp interpreter can easily fit on a single letter-sized sheet of pape…

I wasn't aware that there were any existing C compilers made in asm for modern architectures. I guess I shouldn't be too surprised.

That's cool, thanks for showing me.

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

#170

I think Zig’s compatibility with C is such a valuable feature. I also wish we could rewrite everything in a modern language, but the reality is that we can’t and that if we could, it would take a LONG time. The ability to start new projects, or extend existing ones, with a modern and more ergonomic language—Zig—and be able to seamlessly work with C is incredible. I look forward to the self-hosted compiler being compl…

Zig is not the only one. Other newer languages like Vlang, Odin, Rust, Nim... offer strong C interop.
Post reply on HN