Do not load both preload files when both conditions hold - #8478
Do not load both preload files when both conditions hold#8478SanderMuller wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
|
||
| // require rector-src on split packages | ||
| if (file_exists(__DIR__ . '/../preload-split-package.php') && is_dir(__DIR__ . '/../../../../vendor')) { | ||
| } elseif (file_exists(__DIR__ . '/../preload-split-package.php') && is_dir(__DIR__ . '/../../../../vendor')) { |
There was a problem hiding this comment.
Nice. In addition its one less IO operation in the hot path
|
TBH we might not need preload file anymore. Could you give it a go? |
|
Gave it a go. Inside this repository you are right, and I found one thing that argues the other way for the The suite does not need it. I removed both On php-parser being identical. PHPStan's phar still carries unprefixed What argues against removing it.
That is about a consuming project's vendor against the prefixed one, and The full surface, in case you want it gone. Three of these I missed on a first pass, so it is wider than
If the phpdoc-parser case is obsolete too, say so and I will push the removal here and drop the |
|
And what's your human take on it? |
The current PR is an easy small fix, stripping it out completely could have more impact than I can oversee. |
|
Is there any case the |
|
No, and the Where each file ships:
So the split file never appears on its own. The second half matters more, because it does not depend on that table. I checked that rather than assume it. In a temp layout with The marker is a temporary |
|
Sorry, I'll need a human replies, this feels like talking to chatbot 👎 |
As far as I can see, no there is no case the file |
|
Thanks for your pull request to Rector! I appreciate you taking the time to submit this; however, it appears this contribution may have been primarily AI-generated without careful human review and consideration. We've found that AI-generated code often doesn't align well with Rector's conventions, architectural decisions, and the specific context of what we're trying to accomplish with the framework. Quality contributions require thoughtful human insight into the codebase. If you're interested in contributing to Rector, I'd encourage you to familiarize yourself with the existing codebase, engage with the community, and submit PRs that reflect your own understanding and careful consideration of the problem you're solving. |
bin/rector.phppicks a preload file from two conditions, written as two separateifstatements:Each condition describes a layout, and they read as alternatives. The first is "I have my own
vendor/", soa monorepo checkout. The second is "I sit inside a project's
vendor/". Because they are separateifstatements, a checkout that answers yes to both loads both files. Both declare
isPHPStanTestPreloaded(), so that is a fatal error.Neither file's own
returnguard can stop it. A top-level function is declared when the file compiles,before any of its statements run.
Both intended layouts are unaffected, which I checked by installing
rector/rector-srcas a dependency:is_dir(../vendor)is_dir(../../../../vendor)vendor/rector/rector-srcinstallThe overlap needs a monorepo checkout that has its own
vendor/and sits three levels below anothervendor/. phpstan/phpstan clones this repository intoe2e/integration/repofor an integration test, sofour levels above
bin/is phpstan's ownvendor/. Every spawnedbin/rectorthere writes nothing, andtests/Bin/RectorTestfails with empty output. See phpstan/phpstan#15156, which works around it for now bydeleting the file after cloning.
elseifsays what the two conditions already mean.tests/Bin/PreloadTest.phpbuilds the overlapping layout in a temp directory. It uses the realbin/rector.phpand both real preload files, and asserts the spawned run does not reportCannot redeclare. It fails before the change and passes after.vendor/is symlinked twice so both preload files find the php-parserpaths they require, otherwise the run stops earlier for an unrelated reason.
Full suite:
OK (5273 tests, 6319 assertions). ECS is clean.