Skip to content

Re-offer Class_ node to rules after children traversed - #8836

Closed
TomasVotruba wants to merge 2 commits into
mainfrom
tv-class-reoffer-convergence
Closed

TomasVotruba wants to merge 2 commits into
mainfrom
tv-class-reoffer-convergence

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Why

The rule traverser (RectorNodeTraverser) is pre-order: a Class_ rule runs before the class children are visited. So a rule whose precondition is only met by a descendant change - an emptied method body, or a rename that now duplicates an implements - cannot see it in a single traversal.

Today this converges only because FileProcessor re-runs the whole tree in a do-while loop until stable. That whole-tree reprint loop is the target of ongoing single-pass perf work; once it is dropped, Class_ rules stop converging (e.g. RemoveEmptyClassMethodRector leaves an empty constructor behind after RemoveAlwaysTrueIfConditionRector empties it).

What

After a Class_'s children are traversed, re-offer the class to its rules once, now that the children are settled. This substitutes the former whole-tree loop with a targeted, far cheaper step: it re-runs only Class_ rules, only on classes, exactly once - instead of re-running every rule on every node until stable.

Impact

  • Green on main as-is (do-while still present): no double-apply, no behavior change - full suite passes unchanged.
  • Enables correct single-pass convergence for Class_ rules once the do-while loop is removed.
  • Bench bench/rerun_class_rectors_bench.php isolates the added per-class cost; it is a fraction of one extra whole-tree pass.

@TomasVotruba
TomasVotruba marked this pull request as draft October 25, 2026 22:17
@TomasVotruba
TomasVotruba deleted the tv-class-reoffer-convergence branch October 25, 2026 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants