-
Notifications
You must be signed in to change notification settings - Fork 584
Fix preprocessor cache mode + (distributed compilation || -MD dependency scanning) #2392
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2392 +/- ##
==========================================
- Coverage 71.58% 70.94% -0.64%
==========================================
Files 65 65
Lines 36214 35523 -691
==========================================
- Hits 25923 25203 -720
- Misses 10291 10320 +29 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
nice |
100c577
to
422cf17
Compare
This seems really annoying to auto-test, and to be honest, I haven't even tested it manually yet ;) |
422cf17
to
d97d906
Compare
So I did do some practical testing and ran into another blocker for preprocessor cache mode, this time that it didn't work with -MD (which is used by at least Make and Ninja backends of CMake, so very widely I'd say). It is curious that |
6004164
to
c30cfb7
Compare
c30cfb7
to
3576a2b
Compare
ded3235
to
5296730
Compare
Well, that cherry-pick didn't fix the tests. |
b44b158
to
5296730
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors compiler hasher APIs to support mutable state, enhances preprocessor cache behavior to preserve dependency files (.d
), and updates tests and language-specific compilers to emit and handle dependency artifacts.
- Change
generate_hash_key
andget_cached_or_compile
to take&mut self
and propagate mutability to callers - Add logic to filter out or restore the
.d
dependency file based onis_locally_preprocessed
- Extend NVHPC, NVCC, and GCC compiler backends and tests to include
.d
artifacts
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/server.rs | Marked hasher argument as mut to match new signature |
src/compiler/rust.rs | Refactored generate_hash_key to use &mut self and replaced destructuring with self references |
src/compiler/nvhpc.rs | Added .d dependency descriptor in test outputs |
src/compiler/nvcc.rs | Added .d dependency descriptor in test outputs |
src/compiler/gcc.rs | Tracked dep_path , inserted "d" artifact, updated tests |
src/compiler/compiler.rs | Switched to &mut self , filtered .d in cached outputs, added is_locally_preprocessed |
src/compiler/c.rs | Added is_locally_preprocessed field, updated generate_hash_key , introduced poison constant |
Comments suppressed due to low confidence (3)
src/compiler/compiler.rs:515
- Fix spelling: change "informaiton" to "information."
outputs
src/compiler/gcc.rs:293
- [nitpick] The variable
dep_path
is somewhat ambiguous; consider renaming it todep_file_path
ordependency_file_path
for clarity.
let mut dep_path = None;
src/compiler/compiler.rs:3386
- Reusing the same
hasher
instance across multipleget_cached_or_compile
calls may carry over mutable state between tests. Consider cloning the hasher for each invocation to ensure isolation.
Some((
d1a8e71
to
73f9766
Compare
nice, green builds :) Could you please add tests ? |
73f9766
to
bf29f51
Compare
For dependency files (-MD etc) with preprocessor cache mode, I have it easy: when preprocessor cache mode was disabled in case of -MD etc detected: c0a0b6e, there were tests added which I kept, and they failed in builds without the "dist" feature, which was required to make the new logic work before 60b826b. For distributed compilation with preprocessor cache mode, I will actually need to write the tests. |
58b98bd
to
16e05e8
Compare
Ugh. I always have to reload a lot of context when getting back to this. In fact, there are existing tests covering that part, quoting from my updated commit message:
And I did! |
16e05e8
to
e064474
Compare
6784fca
to
d7daa50
Compare
c2a88a3
to
4897573
Compare
It will need to call itself (in the next commit), and the "moves values out of the instance and consumes them" model doesn't work for that.
Under the following conditions: - Build with preprocessor cache mode enabled - Distributed build - Preprocessor cache hit - Main cache miss the compile that was run as "fallback" after the cache miss did not have preprocessed sources passed to it since skipping the preprocessing step is the whole point of preprocessor cache mode. But local preprocessing is what enables distributed compilation. To fix this, when the problem occurs, recursively re-invoke get_cached_or_compile() with ForceRecache so that the preprocessor cache hit is (mostly) ignored, which makes get_cached_or_compile() invoke the local preprocessing codepath, which yields code suitable for distributed compilation.
This reverts the "main" code changes of commit c0a0b6e but keeps the added test. That commit fixed getting wrong dep files from cache in non preprocessor cache mode, but made it impossible to support dep files in preprocessor cache mode. We can do better.
It works as follows: - Always store the dep file when committing entries to cache. Pprobably not actually necessary in non-pp cache mode because cache entries between the modes are "incompatible", or are they - but dep file are relatively tiny anyway and this is simpler. - Cache hit in non-preprocessor cache mode: This is based on preprocessed file contents, so it can confuse cache entries with same preprocessed contents but different dependency file names. Do not restore the dep file. It could be for another source file, and restoring it is not necessary because local preprocessing (to get the preprocessed source file contents!) will produce the dep file. - Cache hit in preprocessor cache mode: This cache key is made up of input file names and hashes and preprocessing is skipped. In this case, restoring the dep file from cache is both safe and necessary, so do it. CMake's dependency scanning in C[++] at least with GCC and Clang is based on dep files, so this enables preprocessor cache mode in that pretty common build setup. This is covered by the existing test test_sccache_command( preprocessor_cache_mode = true) -> run_sccache_command_tests() -> test_gcc_clang_depfile().
4897573
to
f9f181c
Compare
The ordering of commits follows a red-green pattern now: first break the tests by removing workarounds, then fix them again by fixing the bugs "properly". |
No description provided.