Skip to content

Add RefasterRuleIndex for single-pass indexed Refaster rule execution. - #6430

Open
copybara-service[bot] wants to merge 1 commit into
masterfrom
test_1030825963
Open

copybara-service[bot] wants to merge 1 commit into
masterfrom
test_1030825963

Conversation

@copybara-service

Copy link
Copy Markdown
Contributor

Add RefasterRuleIndex for single-pass indexed Refaster rule execution.

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.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant