Repository navigation
fix(build): key the PCH cache on compiler flags, validate the PCH build command - #3813
Merged
Merged
Conversation
…ld command
Two guards for the same failure: a PCH built under one include spelling
gets reused under another, clang re-parses headers the PCH already
contains, #pragma once fails to dedupe, and the build dies with
"redefinition of 'hsv8'".
1. compile_pch.py short-circuited on the input-file hash alone. That hash
cannot see a changed include spelling -- the resolved dependency set is
byte-identical either way, so the digest is identical and the stale PCH
is silently reused. Compiler args were excluded deliberately, and the
stated reason ("Meson/Ninja already tracks flag changes via build.ninja
regeneration") does not hold: the build tool does reschedule the target
on a command-line change, but compile_pch.py then vetoes the rebuild.
That veto was the bug.
Add a .flags_hash sidecar, hashed from the raw argument vector and
deliberately NOT normalized -- normalizing would collapse exactly the
difference that must invalidate. Kept separate from the input hash,
which invalidate_stale_pch also computes without ever seeing the args;
mixing them is what previously deleted every freshly built PCH.
A PCH with no flags sidecar is treated as untrustworthy and discarded,
so trees already poisoned self-heal on the next build.
2. find_strict_path_violations scanned only compile_commands.json. The PCH
is a Meson custom target, so its build command appears there zero times
while the consuming -include-pch flags appear 365 times: the flags a PCH
is consumed with were validated, the flags it was built with were not.
Scan build.ninja too -- the only generated file containing that command.
Verified end to end against the real generated command: unchanged flags
still skip compilation (no cache regression), while respelling a single -I
now reports "PCH compiler flags changed - rebuilding" where it previously
reported "inputs unchanged - skipping". Zero pre-existing violations in
either build dir, so the new scan enforces at zero tolerance.
Co-Authored-By: Claude <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe CI changes add compiler-argument hashes to PCH cache validation and scan generated Ninja commands for strict-path violations. Regression tests cover hash behavior, path formats, and missing Ninja files. ChangesCI validation updates
Estimated code review effort: 3 (Moderate) | ~20 minutes ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
zackees
added a commit
that referenced
this pull request
Oct 16, 2026
* docs(skills): add /pch-debug skill and pch_probe.py
A skill that auto-activates on PCH failures ('redefinition of',
'redefines default argument', 'modified since the precompiled header',
tests that pass only after --clean). It explains the identity model
(#pragma once fails early; include guards hide the double read), the two
mechanisms in FastLED's history (path-spelling drift: #2685/zccache#619,
#3813; stale PCH accepted: #4839, #4437, #2995/zccache#710), and a
probe-before-clean procedure.
pch_probe.py: 'inputs' dumps what the PCH recorded (falls back to scanning
the PCH bytes when clang refuses a stale PCH) and flags odd spellings,
duplicate spellings and stale inputs; 'tu' runs a real compile_commands
entry with -H (optionally through zccache) and lists project headers
re-opened from disk next to their PCH spelling.
* pch_probe: llvm-bcanalyzer input records; repo-root-based project-header check (#4860 review)
- inputs: read the PCH with llvm-bcanalyzer -dump when available (PATH or
LLVM_BCANALYZER): exact recorded spelling, size and mtime per input,
without clang's stale-PCH validation; stale = size/mtime differ from the
record (clang's own check). Falls back to -module-file-info / byte scan.
- Project headers are now classified by resolving under the repo root
(derived from the script location), not by matching /src/ or /tests/ in
the raw spelling: relative recorded entries like tests/... count, and any
--build-dir location works.
* pch_probe: resolve relative recorded inputs against the build dir (#4860 review)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes the recurring
error: redefinition of 'hsv8'PCH poisoning, which until now was only survivable by hand-deleting the PCH and its sidecars.What I found — one correction to the premise
The starting theory was un-normalized paths. The paths turn out to be fine:
ci/meson/path_normalization.pypost-processes bothbuild.ninjaandcompile_commands.json, and a scan of the live build dirs finds zero strict-path violations. Every-Iis already forward-slash absolute.The path spelling was still the right thread, though — just one step removed. The poisoning does not come from a bad spelling; it comes from the PCH cache being blind to the spelling changing.
1. The cache key omitted the compiler flags
ci/compile_pch.pyskipped compilation whenever the input-file hash matched:That hash cannot see a changed include spelling. The resolved dependency set is byte-identical either way, so the digest is identical, and the PCH built under the old spelling is handed to a TU resolving headers under the new one.
#pragma oncefails to dedupe and the build dies.Args were excluded deliberately, and the docstring gave the reason:
That reasoning doesn't hold. The build tool does reschedule the target when the command line changes — and then
compile_pch.pyvetoes the rebuild. The veto was the bug.The rest of the docstring records a real constraint I had to respect:
invalidate_stale_pchcomputes the same hash and never sees the args, so folding args into it made the two disagree and deleted every freshly built PCH. Hence a separate.flags_hashsidecar rather than a changed input hash.Two deliberate choices:
C:/x/srcandC:\x\srcmust not compare equal.The sibling
ci/wasm_compile_pch.pyhas hashed its flags all along (compute_flags_hash), so this brings the native path in line with a pattern already proven in-repo.2. The strict-path validator could not see the PCH build command
find_strict_path_violationsscanned onlycompile_commands.json. The PCH is a Meson custom target, so it isn't there:compile_commands.jsoncompile_pch.py(the build command)-include-pch(the consume flags)So the flags a PCH is consumed with were validated, and the flags it is built with were not — even though a mismatch between those two is the entire failure mode. Now
build.ninjais scanned as well, being the only generated file that contains that command.Measured 0 pre-existing violations in both
meson-quickandmeson-debugbefore wiring it in, so it enforces at zero tolerance with no baseline.Verification
Both guards are only worth having if they fire, so I proved each does.
End-to-end, against the real generated PCH command:
Run 2 is the bug: it previously printed "inputs unchanged - skipping" and handed the build a poisoned PCH. Run 1 confirms there's no cache regression — unchanged builds still skip.
Self-heal, on the actually-poisoned tree that prompted this:
ci/tests/test_pch_staleness_guards.py— 9 new tests, including that the two separator spellings hash differently, that arg boundaries are unambiguous (['-IC:/a','-IC:/b']must not hash like['-IC:/a-IC:/b']), and that a backslash / relative / dot-component-Iin abuild.ninjaPCH command is caught.bash test --clean --cppuv run python -m pytest ci/tests/test_pch_staleness_guards.py ci/tests/test_meson_private_include_normalization.pybash lintLeft alone deliberately
ci/lint_meson/has two checkers,BackslashPathCheckerandPathNormJoinChecker, that give contradictory advice about whether Meson's/operator is safe on Windows. The generatedbuild.ninjasupportsBackslashPathChecker's premise. That contradiction wants resolving, but it is not what caused this bug and folding it in here would muddy the diff — worth a follow-up.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests