Repository navigation
AST-based rule generation, #ifdef coverage, decision-oriented output - #10
Merged
Merged
Conversation
Use clang -ast-dump=json to extract all declarations from stable headers. Eliminates fragile regex patterns that missed noexcept, const returns, and multi-line signatures. What changed: - extract_functions: FunctionDecl nodes, filtered by namespace and includedFrom to exclude transitively included helpers - extract_methods: CXXMethodDecl from Tensor/Device/StableLibrary - extract_enum_constants: EnumConstantDecl from ScalarType/DeviceType - kStableMethodWhitelist: auto-generated (was hand-maintained) - kNamespaceRules: derived from include rules (at::cuda:: mapping) Only macro detection stays as text search (invisible to AST). Exact namespace matching prevents false matches on similar names. JSON parse errors produce clear diagnostics.
Two changes that strengthen the catch-all system: 1. Split FindingKind::Flag into UnstableType, UnstableRef, and UnstableMethod. Each catch-all now has its own kind, making findings filterable by category (UTYPE/UREF/UMETH in JSON). The overloaded Flag name (both a kind and an action) is resolved. 2. Override PPCallbacks::SourceRangeSkipped to detect unstable API inside #ifdef/#if blocks not compiled. Patterns derived from Rules.h tables at runtime — adapts when gen_rules.py regenerates. Handles all preprocessor conditions via a single callback. Fixes false "0 flags" on files with code behind #ifdef USE_ROCM.
Redesign text output to answer the user's question: "what do I need to fix by hand?" - Flags listed first (user's problem), rewrites summarized by kind (tool's problem) with human-readable names - Relative paths when --project-root is set - "ready for --mode=rewrite" when no flags remain - (#ifdef) annotation on findings from skipped preprocessor regions - Scanner patterns fully derived from rule tables — data_ptr added to kMethodRenameRules, template-arg variants (.method<) generated for all methods - New tests: method-catch-all (exact count), ifdef-skipped-scan - JSON output unchanged
cleonard530
reviewed
Jun 10, 2026
cleonard530
approved these changes
Jun 10, 2026
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
gen_rules.py: regex → clang AST. All rule tables derived from stable headers via
clang -ast-dump=json. Zero hand-maintained lists. When PyTorch adds stable APIs, regeneratingRules.hpicks them up automatically.#ifdef coverage.
PPCallbacks::SourceRangeSkippedscans preprocessor-skipped regions for unstable patterns derived from rule tables. Fixes false "0 flags, PASS" on files with code behind#ifdef USE_ROCM. Handles all preprocessor conditions.Decision-oriented audit output. Flags first (user's problem), rewrites summarized by kind with human-readable names (tool's problem). Relative paths. "ready for --mode=rewrite" when no flags remain.
Also:
FindingKind::Flagsplit intoUnstableType/UnstableRef/UnstableMethod, disjointness check in gen_rules.py, filter transitively included functions from ops extraction,kNamespaceRulestable.Test plan
ninja -C build -j30builds cleanifdef-skipped-scanandmethod-catch-allpython3 scripts/gen_rules.py /path/to/pytorch src/Rules.hregenerates correctlycustom_quickreduce.cufinds unstable API inside#ifdef USE_ROCM