Skip to content

fix: OOM crash in RemoveUnusedVariableAssignRector#7964

Merged
samsonasik merged 1 commit intorectorphp:mainfrom
calebdw:calebdw/push-lukultmnpvzx
Apr 7, 2026
Merged

fix: OOM crash in RemoveUnusedVariableAssignRector#7964
samsonasik merged 1 commit intorectorphp:mainfrom
calebdw:calebdw/push-lukultmnpvzx

Conversation

@calebdw
Copy link
Copy Markdown
Contributor

@calebdw calebdw commented Apr 7, 2026

Closes rectorphp/rector#9733

Problem

The NoDiscard attribute check used AstResolver::resolveClassMethodOrFunctionFromCall() which, for each call expression, would:

  1. Parse the target class's source file into a full AST
  2. Run PHPStan scope analysis on every node (attaching heavy MutatingScope objects)
  3. If the method wasn't found directly, recursively parse ALL traits via getTraits(true)
  4. Retain all parsed ASTs in memory indefinitely via $parsedFileNodes cache
    For classes like Carbon\CarbonPeriod with deep trait hierarchies, this caused unbounded memory growth leading to OOM.

Fix

I replaced the expensive AST-based resolution with PHPStan's lightweight ReflectionProvider API, this checks NoDiscard via PHPStan's reflection layer without parsing any source files.

@samsonasik
Copy link
Copy Markdown
Member

@calebdw could you rebase latest main branch so all e2e test can green, thank you.

@calebdw calebdw force-pushed the calebdw/push-lukultmnpvzx branch from 22300d6 to 7f8dca4 Compare April 7, 2026 17:22
Copy link
Copy Markdown
Member

@samsonasik samsonasik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more change :)

#7964 (review)

@calebdw calebdw force-pushed the calebdw/push-lukultmnpvzx branch from 7f8dca4 to e43f02a Compare April 7, 2026 18:05
@samsonasik
Copy link
Copy Markdown
Member

Thank you @calebdw

@samsonasik samsonasik merged commit 07fce83 into rectorphp:main Apr 7, 2026
61 checks passed
@calebdw calebdw deleted the calebdw/push-lukultmnpvzx branch April 7, 2026 18:10
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.

Excessive memory usage during analysis

2 participants