Skip to content

Do not try to re-clone already has origNode on CloningVisitor#1136

Closed
samsonasik wants to merge 1 commit into
nikic:masterfrom
samsonasik:do-not-try-to-re-clone
Closed

Do not try to re-clone already has origNode on CloningVisitor#1136
samsonasik wants to merge 1 commit into
nikic:masterfrom
samsonasik:do-not-try-to-re-clone

Conversation

@samsonasik
Copy link
Copy Markdown
Contributor

@samsonasik samsonasik commented Dec 13, 2025

On CloningVisitor, it always try to clone itself, whenever it already has origNode or not.

This PR try to not re-clone when it already has an origNode attribute, whenever the value is set, it should already no more clone.

I reproduce the re-clone on rector usage when running unit test, it got test that shows it double cloned on rector-src /cc @TomasVotruba

@samsonasik
Copy link
Copy Markdown
Contributor Author

Ready for review 👍

@nikic
Copy link
Copy Markdown
Owner

nikic commented Dec 13, 2025

So rector is running CloningVisitor multiple times on the same AST? What's the reason for that?

@samsonasik
Copy link
Copy Markdown
Contributor Author

samsonasik commented Dec 13, 2025

It just happen on a 1 unit test in rector-src tho (not verify other packages). I guess this may happen when multiple rules apply in a loop to revisit again until no more change.

https://github.com/rectorphp/rector-src/blob/a046e2d2f1c3f688e3ddfe214e600e73e2472344/src/Application/FileProcessor.php#L57-L79

in every iterative, the CloningVisitor always re-executed internally because printing is needed to verify the flag that file has been changed.

@staabm
Copy link
Copy Markdown
Contributor

staabm commented Dec 14, 2025

Adding an additional functional call on every node for a rector specific problem sounds like the wrong fix.

I think either rector should copy and adapt this visitor or fix it in a different way

@samsonasik
Copy link
Copy Markdown
Contributor Author

@staabm Okay, closing then ;)

@samsonasik samsonasik closed this Dec 14, 2025
@samsonasik samsonasik deleted the do-not-try-to-re-clone branch December 14, 2025 10:22
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.

3 participants