Fix infinite hang when analysing src/wp-includes/user.php in wordpress-develop#5485
Merged
ondrejmirtes merged 2 commits into2.1.xfrom Apr 16, 2026
Merged
Fix infinite hang when analysing src/wp-includes/user.php in wordpress-develop#5485ondrejmirtes merged 2 commits into2.1.xfrom
src/wp-includes/user.php in wordpress-develop#5485ondrejmirtes merged 2 commits into2.1.xfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Skip expensive type operations on complex union types to prevent exponential HasOffsetValueType growth.
When a variable has type array|object (common in WordPress) and the code does repeated
empty($data['key']) ternary checks, each check forks the object branch of the union into with/without
HasOffsetValueType variants. The array branch is absorbed by isSuperTypeOf, but the object branch is
not — creating 2^N union members after N checks. Combined with impure function calls (e.g. WordPress's
apply_filters) that create conditional expressions carrying this huge type, every subsequent
addTypeToExpression/removeTypeFromExpression call must operate on the massive union, causing analysis
to hang.
The fix introduces isComplexUnionType() which detects unions with >8 members containing
IntersectionType members — the signature of this combinatorial growth. Three call sites skip expensive
operations on such types:
Reproduces with WordPress's wp_insert_user() (471-line function with @param array|object $userdata, ~17
empty() checks, and ~15 impure apply_filters calls). Before: infinite hang. After: ~11 seconds.
Standalone benchmark included: array|object parameter + instanceof narrowing + empty() ternaries +
impure apply_filters calls. Before: >60s. After: 1.8s.