Repository navigation
Add RefasterRuleIndex for single-pass indexed Refaster rule execution. - #6430
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
Applying large suites of `RefasterRule` instances sequentially walks the entire AST once per rule, recomputes `@SuppressWarnings` per rule per declaration, invokes `@Matches` predicates before checking `UFreeIdent` parameter types, and repeats reflective lookups in `Template.infer`. On suites with thousands of rules, AST traversal, suppression checks, and failed `Unifier` allocations dominate runtime. Introduce `RefasterRuleIndex` to execute a collection of `RefasterRule` instances in a single AST pass while preserving `RefasterScanner` semantics, including traversal order, parenthesis skipping, synthetic class-member block matching, comment rejection, and lexical `@SuppressWarnings` / self-suppression. The index runs a conservative per-compilation-unit AST symbol and type-closure pre-filter that tolerates unattributed or error AST nodes, dispatches `ExpressionTemplate` rules by `(Tree.Kind, methodName)` and `BlockTemplate` rules by first-statement `(Tree.Kind, methodName)` plus a required statement-kind `EnumSet` with wildcard fallbacks, and shares a per-compilation-unit `MatchContext` and `VisitorState` across `Unifier` instances. In addition, `UMatches` rejects incompatible `UClassType` parameters before invoking `Matcher` predicates, `BlockTemplate` guards first-statement kind before allocating a `Unifier`, and `Template` caches javac reflection handles. All index structures live outside serialized `RefasterRule` graphs to preserve serialization compatibility. PiperOrigin-RevId: 1030825963
This branch has not been deployed
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.
Add RefasterRuleIndex for single-pass indexed Refaster rule execution.
Applying large suites of
RefasterRuleinstances sequentially walks the entire AST once per rule, recomputes@SuppressWarningsper rule per declaration, invokes@Matchespredicates before checkingUFreeIdentparameter types, and repeats reflective lookups inTemplate.infer. On suites with thousands of rules, AST traversal, suppression checks, and failedUnifierallocations dominate runtime.Introduce
RefasterRuleIndexto execute a collection ofRefasterRuleinstances in a single AST pass while preservingRefasterScannersemantics, including traversal order, parenthesis skipping, synthetic class-member block matching, comment rejection, and lexical@SuppressWarnings/ self-suppression. The index runs a conservative per-compilation-unit AST symbol and type-closure pre-filter that tolerates unattributed or error AST nodes, dispatchesExpressionTemplaterules by(Tree.Kind, methodName)andBlockTemplaterules by first-statement(Tree.Kind, methodName)plus a required statement-kindEnumSetwith wildcard fallbacks, and shares a per-compilation-unitMatchContextandVisitorStateacrossUnifierinstances. In addition,UMatchesrejects incompatibleUClassTypeparameters before invokingMatcherpredicates,BlockTemplateguards first-statement kind before allocating aUnifier, andTemplatecaches javac reflection handles. All index structures live outside serializedRefasterRulegraphs to preserve serialization compatibility.