Add #undef support with two-pass headertree discovery#6
Merged
Conversation
Invariant cache now recomputes updated_macros with current input state instead of using stale cached state. Pass 2 only clears variant caches, preserving invariant results which are truly macro-independent.
This is due to the different methods used to determine includes.
# Conflicts: # src/compiletools/headerdeps.py # src/compiletools/magicflags.py # src/compiletools/preprocessing_cache.py
- Track file_undefs in preprocessing cache for correct macro state propagation across files (#undef no longer silently ignored) - Add two-pass macro convergence to ct-headertree (matching hunter) so both tools agree on conditionally-included headers - Make file_undefs computation input-independent (active #undef directive targets) to preserve invariant caching for files with only #undef and no conditionals - Add undef_targets static field to FileAnalysisResult - Add leaked-macro-pkg.pc fixture and pkgconfig_env to undef tests
Owner
Author
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
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.
Summary
#undeftracking to the preprocessing cache so macros cleaned up via#undefno longer silently persist and break subsequent conditional compilationct-headertree(matching hunter's existing approach) so both tools agree on conditionally-included headersCache design: input-independent
file_undefsThe naive approach of adding
'undef'to_extract_conditional_macrosworks but is semantically wrong --#undefdoes not affect active lines, it only mutates output macro state. This demotes files from invariant to variant caching unnecessarily, causing extra cache misses on codebases with#undefdirectives.Instead,
file_undefsis computed from active#undefdirective targets (input-independent) rather than diffing input vs output macro state (input-dependent).MacroState.without_keys()handles the intersection with the caller's variable macros at cache-hit time, so invariant caching is preserved for files that only have#undefwithout conditionals.Supporting changes:
undef_targetsstatic field toFileAnalysisResultwithout_keys()method toMacroStateleaked-macro-pkg.pctest fixture andpkgconfig_envto undef testsTest plan
test_undef_bug_samplevalidates #undef is correctly processed across file boundariestest_headertree_hunter_agreementvalidates headertree and hunter agree on all sample cases (empty_macro_bug, undef_bug, macro_state_dependency)test_preprocessing_cachevalidates cache behavior with undefs