ADFA-5231: Add pin-scoped live KtFile acquisition - #1744
Open
itsaky-adfa wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
dara-abijo-adfa
approved these changes
Aug 26, 2026
itsaky-adfa
force-pushed
the
ADFA-5231-pin-api
branch
from
August 26, 2026 15:33
c6d9dc2 to
399e25b
Compare
itsaky-adfa
force-pushed
the
ADFA-5231-pin-api
branch
from
August 27, 2026 09:06
399e25b to
3a8d1ad
Compare
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.
Stack 2 of 5 for ADFA-5231. Adds the mechanism only - nothing consumes it yet and the raw accessors stay public, so this layer changes no behaviour. Consumers arrive in the next PR.
The bug this exists to fix
ADFA-4165 established the invariant one live
KtFileper open path. ADFA-3322 (#1484) replaced its enforcement with the per-versioncurrentFilescache and reintroduced the bug:KtSymbolIndexmints a freshKtFilewhenever a caller observes a new document version, whileDeclarationProvider.ktFilesForPackageresolves a path to whatever the newest instance is. An analysis that started against an older instance therefore sees every declaration twice - once as its own PSI, once through the provider - and FIR reports the file as conflicting with itself.What this adds
LiveKtFile, aninternal sealed interfacewhose only implementation isprivatetoKtSymbolIndex, so the only way to obtain one iswithLiveKtFile/withLiveKtFileAsync. While a pin is held, both doors into the index -getCurrentVersionedKtFileand thegetKtFilethe Analysis API service providers use - resolve that one instance. A version bump during a pin is recorded and the refresh is launched when the last scope closes, so freshness is deferred rather than dropped.The handle deliberately never exposes the
KtFileas a value: PSI access and analysis are members taking a lambda, and returning the file directly from a block is rejected at runtime.Notes for review:
FileManager, soisStalecannot report fresh for a stale instance. An earlier revision got this wrong and it is worth a look.Pin.refreshOwedis@Volatilebecause it is written outside thecomputesection and read inside it;count, mutated only under the bin lock, is deliberately plain.Testing
LiveKtFilePinTest- identity stability under a concurrent version bump, reentrancy, the deferred refresh,isStale, and the escape guard. Both new pin branches were mutation-tested: disabling either fails a specific test. The suite is fully green at this layer.