make aro-based translate-c lazily built from source #19122
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Depends on #19114.
Part of #19063.
The Big Change
Primarily, this moves Aro from deps/ to lib/compiler/ so that it can be
lazily compiled from source. src/aro_translate_c.zig is moved to
lib/compiler/aro_translate_c.zig and some of Zig CLI logic moved to a
main() function there.
aro_translate_c.zig becomes the "common" import for clang-based
translate-c.
Not all of the compiler was able to be detangled from Aro, however, so
it still, for now, remains being compiled with the main compiler
sources due to the clang-based translate-c depending on it. Once
aro-based translate-c achieves feature parity with the clang-based
translate-c implementation, the clang-based one can be removed from Zig, making
Aro source only compiled in the case that C translation features are required.
Aro's .def files and multiple Zig module requirements make things cumbersome.
I looked at the .def files and made these observations:
regenerating the .def files in Aro.
and check those into Aro.
generated .zig files can be made many times smaller, without
compromising type safety in the usage of the data.
This would make things much easier on Zig as downstream project,
particularly we could remove those pesky stubs when bootstrapping.
I have gone ahead with these changes since they unblock me. Opening this PR to ask @Vexu for feedback.
Results
I'm measuring 9s for
ZIG_DEBUG_CMD=1 stage3/bin/zig translate-c -fno-clang simple.c
after making changes to aro_translate_c.zig.This also lets you directly do
stage3/bin/zig run --dep aro -Mroot=../lib/compiler/aro_translate_c.zig -Maro=../lib/compiler/aro/aro.zig -- simple.c
which means you can choose to additionally pass-fno-llvm -fno-lld
which I'm clocking at 2.4s.Follow-Up Work
Improve the test harness
The aro-enabled test-run-translated-c cases look broken. I don't think any of these are being run:
Move caching to the build system
Currently the build system unconditionally executes
zig translate-c ...
and this subcommand in zig does caching. Instead, I think the zig CLI subcommand should always run the translation, andstd.Build.Step.TranslateC
should be doing the caching. At least for the aro-based one.Current status is that even after making changes to the translate-c sources, the translate-c binary gets rebuilt, but then it gets a cache hit on the input C code and produces the same result as before even though the translate-c binary might have different behavior.
To work around this, contributors can use the
zig run ...
trick I mentioned above.