Repository navigation
PHPStan Pro: analyse again the files changed while an analysis read them - #6949
Merged
Merged
Conversation
A file changed and changed back between two polls of the file monitor looks unchanged to it. When an analysis read the file in between, nothing started another one, and the errors of the code that existed only during the analysis stayed until the next edit. The hashing monitor polls once a second, so this took an undo within a second. Windows always uses it, and so does everybody without FFI. The result cache already knows these files when it saves and records them to be analysed again. The worker now reports them too, and the file monitoring treats that like a change it saw itself, so pausing and waiting for a burst of changes to end apply to it. Something writing to the analysed files during every analysis, like a generator in a bootstrap file, would keep the analyses going, so an analysis started only for this does not start another one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SLV3fAj54R19CE8XoFyu9Z
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.
A file changed and changed back between two polls of the file monitor looks unchanged to it. If an analysis read the file in between, nothing starts another one, and the errors of the code that existed only during the analysis stay until the next edit.
HashingFileMonitorpolls once a second, so an undo within a second is enough. It is what Windows always uses, and what Linux and macOS use without FFI.The change
The result cache already finds these files when it saves, and records them to be analysed again (#6377). Only nothing started that analysis.
FixerWorkerRunnerasksResultCacheManager::getFilesChangedDuringAnalysis()after saving and sendsfilesChangedWhileAnalysedwhen there are any.FixerApplicationtreats that like a change its file monitor saw. It goes through the same poll loop, so pausing and waiting for a burst of changes to end apply to it, and an analysis already about to start clears it instead of adding one more.Something writing to the analysed files during every analysis, like a generator in a bootstrap file, would keep the analyses going. An analysis started only because of this report therefore does not start another one; a change the monitor sees resets that. The cost is that a second change-and-revert during that one follow-up analysis is missed.
Testing
No unit test covers
FixerApplication, the regression test is the existing visual specfile changed and changed back while it is analysed. Run on macOS withPHPSTAN_DISABLE_NATIVE_FILE_MONITOR=1:The failure in both suites is
level changed in the config, which is unrelated:initialData.ruleLevelis sent only once, at startup. Screenshots were not compared on macOS, their baselines are rendered on Linux.A report arriving while PHPStan Pro is paused waits for the resume, because the poll loop returns early while paused. That comes from reading the code, no spec covers it.
phpstan/phpstan-fixer#310 runs the visual tests with both monitors in CI, and adds a spec for the loop above that fails with the guard removed.
🤖 Generated with Claude Code
https://claude.ai/code/session_01SLV3fAj54R19CE8XoFyu9Z