Re-queue reference dependents when removing a declaration#715
Merged
Conversation
Two fixes for singleton classes being lost after file deletion: 1. When invalidate_declaration removes a declaration, it unresolves the declaration's names and cascades structurally to ChildName/NestedName dependents. Reference dependents of those names were not re-queued, so constant references from surviving files would stay permanently unresolved. 2. Constant references that resolve to Unresolved(None) during delete-phase resolution were terminally dropped. With incremental invalidation this is temporary — the parent namespace may be re-added. Treat Unresolved(None) as Retry so references survive to the next resolve() call.
f7c987f to
77efbe6
Compare
alexcrocha
reviewed
Apr 2, 2026
vinistock
approved these changes
Apr 2, 2026
| match self.resolve_constant_internal(*constant_ref.name_id()) { | ||
| Outcome::Retry(None) => { | ||
| // There might be dependencies we haven't figured out yet, so we need to retry | ||
| Outcome::Retry(None) | Outcome::Unresolved(None) => { |
Member
There was a problem hiding this comment.
This is fine for now, but I think we need to review if Retry is still applicable or if we should just be re-enqueueing unresolved items.
Maybe that will simplify a lot.
Member
Author
There was a problem hiding this comment.
The distinction is still needed in definition cases AFAICT. Just that for constant references they now should be processed the same way.
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.
Summary
Found by the incremental consistency testing tool.
When
invalidate_declarationremoves a declaration, it unresolves the declaration's names and cascades structurally to ChildName/NestedName dependents. But Reference dependents of those names were not re-queued — constant references from surviving files that depended on the removed name would stay permanently unresolved. Additionally, references that did get re-queued but resolved toUnresolved(None)during delete-phase resolution were terminally dropped instead of retried.This caused singleton classes to be lost after file deletion when a
.newcall was nested inside a compact-notation class sharing the same parent namespace (e.g.Parent::Target.newinsideclass Parent::Caller).Reproduction
When
parent.rbandtarget.rbare both deleted and re-added:parent.rbremoves theParentdeclarationParent::TargetandParent::Callernames are unresolved (ChildName dependents)Parent::Targetincaller.rbis a Reference dependent of theParent::Targetname — but the removal path only cascaded structural dependents (ChildName/NestedName), not Reference dependents. The reference was never re-queued.resolve()it resolves toUnresolved(None)(parent doesn't exist yet) and gets terminally dropped instead of retried.Parent::Targetis recreated but the.newreference fromcaller.rbis gone — the singleton<Target>is never recreated.