Repository navigation
Do not export what is declared inside a function or method body - #6699
Merged
ondrejmirtes merged 1 commit intoOct 7, 2026
Merged
Conversation
A define() or a class declared inside a function or method body is not found from other files, and ExportedNodeVisitor does not look inside function bodies. Exporting it during the analysis made every edit of its file look like a symbol disappeared, so all files with errors were re-analysed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Member
|
Thank you! |
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.
DependencyResolverexported adefine()or a class declared inside a function or method body. The result cache restore reads the exported nodes again withExportedNodeVisitor, which does not look inside function bodies. So after any edit of such a file, the restore saw a symbol disappear and re-analysed every file with errors.f30b81c added this guard for a function declared inside another function. This change extends it to everything inside a function or method body. None of it is a symbol that other files can use. On 2.3.x, other files get
constant.notFoundfor a constant defined withdefine()inside a function or a method, also inside anif (!defined())check. They getclass.notFoundfor a class declared inside a function.I found this on wordpress-develop, which calls
define()inside many functions, for exampleGETID3_TEMP_DIRinwp-admin/includes/media.php. At level 9 without a baseline, 2,333 files there have errors, so each such edit re-analysed about 2,290 files.Verification:
New e2e test
result-cache-define-in-function, modelled onresult-cache-inner-function. One file callsdefine()inside a function and inside a method, and another file has an error. After a body-only edit of the first file,result-cache-inforeports 1 file to analyse. The step fails on 2.3.x, where it reports 2. It also fails when the guard covers functions but not methods.On wordpress-develop, I appended a newline to every analysed file except one file with errors. That makes the restore compare the exported nodes of all 3,215 changed files. With this change, none of them looked like a symbol appeared or disappeared. On 2.3.x,
class-wp-filesystem-ftpext.phpalready did.I replayed the last 300 trunk commits of wordpress-develop, each run with the cache of the commit before, on 2.3.0 and with this change. The files re-analysed in total went from 78,462 to 59,182, and the runs that re-analysed more than 1,000 files went from 34 to 26. Ten commits changed, and each of them edits a file with a
define()inside a function. After the last commit, the incremental result matches a cold run, apart from 4 files with__()errors that also differ without this change.make phpstanreports no errors, phpcs passes onDependencyResolver.php, andmake testspasses (22,503 tests, 74 skipped).Performance on wordpress-develop at level 9, from source without Turbo, on an M4 Pro. Base is
e840006d7, the parent of this change. The cold and hot runs are at r63669. Each value is the median of 3 alternating rounds, with the range in brackets.media.php(r63670, with the cache from r63669)resultCache.php🤖 Generated with Claude Code