Skip to content

[perf] Skip scope fetch in TypeDeclaration return-type rules when return type already set or body empty - #8582

Merged
TomasVotruba merged 1 commit into
mainfrom
perf-typedecl-cheap-guards
Oct 10, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
perf-typedecl-cheap-guards

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Across the TypeDeclaration return-type family, refactor() fetched the PHPStan scope as its first statement, then immediately checked $node->returnType instanceof Node / empty stmts - directly or inside a shouldSkip() whose opening lines ignore the scope.

Those node-only checks skip the overwhelming majority of inputs (any already-typed or empty-bodied method), so they now run before ScopeFetcher::fetch(). Where the cheap checks lived inside shouldSkip(), they are moved up into refactor() so the scope is pulled only once a candidate survives them.

Rules touched:

  • ReturnTypeFromReturnNewRector
  • ReturnTypeFromReturnDirectArrayRector
  • ReturnTypeFromStrictTypedCallRector
  • ReturnTypeFromMockObjectRector
  • ReturnTypeFromStrictFluentReturnRector
  • ReturnTypeFromStrictConstantReturnRector
  • ReturnNullableTypeRector
  • AddReturnTypeFromTryCatchTypeRector
  • AddReturnTypeDeclarationFromYieldsRector
  • NumericReturnTypeFromStrictScalarReturnsRector
  • NumericReturnTypeFromStrictReturnsRector
  • ReturnTypeFromStrictTernaryRector
  • BoolReturnTypeFromBooleanConstReturnsRector
  • BoolReturnTypeFromBooleanStrictReturnsRector
  • BoolReturnTypeFromBooleanConstAndStrictReturnsRector
  • ReturnTypeFromStrictNewArrayRector

Behavior is unchanged - same guards, earlier bail. Follows the same shape as #8579.

@TomasVotruba
TomasVotruba merged commit 81b00ad into main Oct 10, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the perf-typedecl-cheap-guards branch October 10, 2026 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant