Simplify FiniteTypeSet - #6229
Conversation
There was a problem hiding this comment.
Pull request overview
Simplifies FiniteTypeSet by removing class-string member tracking and broadening finite-union intersection optimization.
Changes:
- Removes cached class-string detection.
- Removes the corresponding bailout and tests.
- Allows class-string members through the finite-union fast path.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Type/FiniteTypeSet.php |
Removes class-string tracking. |
src/Type/TypeCombinator.php |
Removes the class-string fast-path guard. |
tests/PHPStan/Type/FiniteTypeSetTest.php |
Removes class-string detection tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| return null; | ||
| } | ||
|
|
||
| return $finiteTypeSet->getMembers(); |
There was a problem hiding this comment.
@copilot how does a nsrt test look like which is affected by the mentioned regression?
|
@SanderMuller could you try to come up with a my feeling is that this PR only violates a halucinated/not relevant unit tests, but does not affect real world logic/projects |
|
Short answer: no, I could not build one, and I looked hard. But the PR does change real behaviour — it turns the phpstan-doctrine extension test job red — so I'd not merge it as it stands. There is a one-line variant that keeps the whole simplification, below. No nsrt case existsI instrumented base so that whenever the class-string guard makes Across I also wrote 11 probe constructs aimed straight at it (in_array narrowing against a with It does change third-party output
That job is green on #6235 and #6236, which share this PR's exact base commit I could not reproduce it locally — running the extension's The one-line variantThe guard exists because $common = [];
foreach ($membersA as $key => $member) {
if (!array_key_exists($key, $membersB)) {
continue;
}
- $common[] = $member;
+ // Hand back $b's member, which is what the general algorithm below picks: two members
+ // sharing a key are equals() but not necessarily identical - a constant string that is
+ // also a class-string is not interchangeable with a same-valued one that is not - so
+ // the fast path must not swap one for the other.
+ $common[] = $membersB[$key];
}With that on top of your branch:
That keeps your -73 lines, and the fast path now also covers the class-string unions it used to bail on. Two notes:
|
re-running the job made it pass, without further changes |
|
This pull request has been marked as ready for review. |
|
I think the PR is fine, because we did not have a separate class-string case before introducing |
No description provided.