Skip to content

Do not count a moved symbol as a new one in the result cache - #6728

Open
SanderMuller wants to merge 1 commit into
phpstan:2.3.xfrom
SanderMuller:result-cache-symbol-order
Open

SanderMuller wants to merge 1 commit into
phpstan:2.3.xfrom
SanderMuller:result-cache-symbol-order

Conversation

@SanderMuller

Copy link
Copy Markdown
Contributor

compareExportedNodes() compared the symbol names of a changed file as ordered lists. When a file swapped two define() calls or two classes, restore() saw a new symbol and re-analysed every file with errors.

The symbols are now grouped by type and name. When a file declares the same symbol twice, the two declarations still compare in the order of the file.

WordPress/wordpress-develop@7111d25 moves define( 'ABSPATH' ) in setup-config.php. I ran WordPress's tests/phpstan/base.neon with phpstan-phpunit at level 5, without its baseline, and with a warm cache from the parent commit. 2.3.x at 184d34e re-analyses 311 files, and this branch re-analyses 1. Both report the same 1487 errors, and so does a run with an empty cache.

The new e2e fixture result-cache-reordered-symbols swaps two define() calls and two classes, and expects 1 file to analyse. Without the source change it gets 2.

I also checked these cases with a file that reads the constant and a separate file that has an error. In each one the warm run reports the same errors as a cold run.

  • A reorder together with a changed constant value re-analyses the changed file and the file that reads the constant. A value change without a reorder does the same.
  • A reorder together with a new class or a removed define() still re-analyses every file with errors.
  • Two top-level define() calls with the same name and swapped values re-analyse the file that reads the constant.

🤖 Generated with Claude Code

compareExportedNodes() compared the symbol names of a file as ordered
lists, so swapping two define() calls or two classes looked like a new
symbol. That re-analysed every file with errors. The symbols are now
grouped by type and name, and only the order within the same symbol
still counts.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.

1 participant