Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

further reduce bootstrapping dependencies by making stage1 output C rather than LLVM IR #5246

Closed
andrewrk opened this issue May 1, 2020 · 6 comments · Fixed by #13560
Closed
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented May 1, 2020

Related but different: #3772

This issue is to delete the Clang, LLVM, and LLD dependencies of stage1. It will make it possible to bootstrap a fully self-hosted zig without ever touching the LLVM project.

This issue depends on the self-hosted compiler being completely done (#89).

Further, the next step after that will be to stop using C++ features in stage1, making it pure C, with no dependency on a C++ compiler or libc++.

The self-hosted Zig compiler will have an optional dependency on Clang, LLVM, and LLD. The bootstrapping process will look like the following, if this issue is implemented:

  • Use system C compiler to compile .c source files into zig1 executable
  • Use zig1 executable to compile .zig source files into .c generated files
  • Use system C compiler to compile .c source files + generated .c files into zig2 executable
  • Use zig2 executable to compile .zig source files into zig executable

Any further recompiling of zig would yield the same binary. E.g. using the final zig executable to compile the .zig source files would result in the same zig executable.

On the final step it would be possible to select any desired target (cross compiling) as well as selecting the option of enabling LLVM features.

@andrewrk andrewrk added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. stage1 The process of building from source via WebAssembly and the C backend. labels May 1, 2020
@andrewrk andrewrk added this to the 1.1.0 milestone May 1, 2020
@Rocknest
Copy link
Contributor

Rocknest commented May 1, 2020

Will stage2 be able to output c code? Will then stage1 source be autogenerated from stage2 source? What about cImport? That feature is core zig and depends on clang, right? If clang was optional then cImport would be downgraded to second-class feature.

@andrewrk
Copy link
Member Author

andrewrk commented May 1, 2020

Will stage2 be able to output c code?

#3772

Will then stage1 source be autogenerated from stage2 source?

No, see the discussion on #853

What about cImport?

cimport, translate-c, zig cc features as well as additional target support are unlocked when the optional LLVM/Clang/LLD dependencies are enabled.

If clang was optional then cImport would be downgraded to second-class feature.

The C extensions to zig have always been planned to be an optional extension to the language in the specification, and likewise the c compiler toolchain features is not a required part of a conforming zig compiler.

@mikdusan
Copy link
Member

mikdusan commented May 2, 2020

cimport, translate-c, zig cc features as well as additional target support are unlocked when

I thought we could unlock these features with Z-Bucks 😉

@wizzard0
Copy link

wizzard0 commented May 8, 2020

hmm, speaking of "minimalistic self-contained toolchain", I think it makes sense to also consider TCC (Bellard's Tiny C Compiler) for at least some targets. Maybe some parts of TCC can also be repurposed for cImport?

@andrewrk andrewrk added the accepted This proposal is planned. label Sep 1, 2020
@andrewrk andrewrk modified the milestones: 1.1.0, 0.8.0 Sep 1, 2020
@andrewrk
Copy link
Member Author

andrewrk commented Sep 1, 2020

The plan for this is now to, at some strategic moment, utilize the C backend of stage2 to do a one time thing where we delete stage1 and replace it with the C backend output of stage2. The reason this won't be problematic for bootstrapping (#853) is that we won't keep doing it. The new stage1 C code will then get manually cleaned up and reorganized, and start being manually maintained to keep up with stage2, therefore granting it "source" status rather than "generated file" status.

@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 20, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
andrewrk added a commit that referenced this issue Oct 23, 2022
This option can be used to produce a C backend build of the self-hosted
compiler, which only has the C backend enabled. Once the C backend is
capable of self-hosting, this will be a way for us to replace our stage1
codebase with a C backend build of self-hosted, which we can then use
for bootstrapping. See #5246 for more details.

Using this option right now results in a crash because the C backend is
not yet passing all the behavior tests.
andrewrk added a commit that referenced this issue Oct 23, 2022
This option can be used to produce a C backend build of the self-hosted
compiler, which only has the C backend enabled. Once the C backend is
capable of self-hosting, this will be a way for us to replace our stage1
codebase with a C backend build of self-hosted, which we can then use
for bootstrapping. See #5246 for more details.

Using this option right now results in a crash because the C backend is
not yet passing all the behavior tests.
andrewrk added a commit that referenced this issue Oct 24, 2022
This option can be used to produce a C backend build of the self-hosted
compiler, which only has the C backend enabled. Once the C backend is
capable of self-hosting, this will be a way for us to replace our stage1
codebase with a C backend build of self-hosted, which we can then use
for bootstrapping. See #5246 for more details.

Using this option right now results in a crash because the C backend is
not yet passing all the behavior tests.
@tauoverpi
Copy link
Contributor

Having a zig interpreter (AST-based or similar) written in C that's just enough to run stage2 could also work and would satisfy the bootstrap requirement while avoiding the issues of the number of instances generated by generics. This would then make it c compiler -> interpreter -> stage2 -> stage3 at the cost of likely being slower but I think the lower complexity in maintaining it would be worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants