~Here's the plan:~ See https://github.com/zig-lang/zig/issues/89#issuecomment-328214707
~Every time zig releases a new major version, the compiler source code is updated to the version of zig just released.~
~Currently no major versions have been released, therefore, the compiler is written in C++. When 1.0.0 is released, the self-hosting process will begin. zig 1.0.0 will be able to build the 2.0.0 release, 2.0.0 will be able to build the 3.0.0 release, and so on.~
~Hopefully this will be friendly toward package managers and make the bootstrapping process simple to understand and execute.~
When we release zig 1.0.0, we'll actually have the self hosted compiler built and ready to go, passing all tests. Both projects will be maintained until 2.0.0.
There are some compelling reasons to self-host:
We still want the bootstrapping process to be simple though. So here's another proposal. We get a self-hosted compiler going right now. It's the official zig compiler. However the C++ implementation must be able to build the official zig compiler. As long as that remains true, bootstrapping is 1 step process.
ConstExprValue right now has a lot of footguns built into it,
and it wastes memory. The new data layout should accomplish
these things:
@sizeOf(error), this@typeOf(@sizeOf(error)) without causing the lazy expr toWe'll have LLVM spitting out .o files before the last source file has been tokenized.
How will this work with name resolution? You can't compile a file that depends on a file that hasn't been parsed yet.
Here's an example:
You can see from this example we would get better parallelism if we prioritized analysis of functions since that creates jobs for the pipeline - it would make thread 2 have something to do while thread 1 analyzes baz(). But this should illustrate the idea.
0.3.0 ... seemed so close 馃槂
Yeah. I couldn't make the deadline. 0.3.0 is two weeks away and I think those two weeks can best be spent on:
building master always anyway 馃憤
Something that I would like to see with a self-hosted compiler is the ability to import the compiler as a library within my application to compile and link new code while running. For example, https://github.com/anael-seghezzi/CToy embeds tcc and provides a creative coding environment that does not require a restart when modifying code.
Is such a thing possible already when importing std.build?
Something that I would like to see with a self-hosted compiler is the ability to import the compiler as a library within my application to compile and link new code while running.
Unfortunately that's not ever going to be possible, because of the LLVM and clang dependency. Zig compiler ships with LLVM and clang libraries built into the zig compiler. And Zig supports cross compiling for many targets. To import the compiler as a library would require that LLVM and clang were available in source form (written in zig) so that they could be cross compiled for the target. To give up LLVM/clang and code our own code generator in zig would be giving up state-of-the-art optimizations and a very active community of people working on it.
However, the parts of the compiler that do not depend on LLVM and clang are available in the standard library, for example the parser and formatter. std.zig.parse and std.zig.render.
As for a coding environment that does not require a restart when modifying code, see #68.
Having LLVM/Clang written in C++ shouldn't prevent the compiler from being used as a library. Just like zig programs can link to and use C libraries even though they aren't in Zig.
To import the compiler as a library would require that LLVM and clang were available in source form
I think they meant a library as in a DLL, SO or archive, etc.
Something that I would like to see with a self-hosted compiler is the ability to import the compiler as a library within my application to compile and link new code while running.
It would be cool if you could take the idea of a comptime function and extended it to a just-in-time function. So you could take a function fn regex(comptime re: []const u8, str: []u8) bool, give it a runtime-known string for re, and then libzig.so would give you a function pointer to a JIT compiled version that your program could call.
It'd be a pretty niche feature, so I'm not suggesting it should be included. However, I don't think it's been done before in a statically compiled language, so it'd be really unique feature if it wasn't too hard to implement. Although I don't know too much about compilers, so maybe I'm grossly underestimating the difficult.
Most helpful comment
There are some compelling reasons to self-host:
We still want the bootstrapping process to be simple though. So here's another proposal. We get a self-hosted compiler going right now. It's the official zig compiler. However the C++ implementation must be able to build the official zig compiler. As long as that remains true, bootstrapping is 1 step process.