Skip to content

Clean up synthetic declarations during incremental resolution#739

Closed
st0012 wants to merge 0 commit intodefer-cleanup-emptied-declarationsfrom
cleanup-synthetic-declarations
Closed

Clean up synthetic declarations during incremental resolution#739
st0012 wants to merge 0 commit intodefer-cleanup-emptied-declarationsfrom
cleanup-synthetic-declarations

Conversation

@st0012
Copy link
Copy Markdown
Member

@st0012 st0012 commented Apr 14, 2026

Summary

Stacked on #736.

  • Wraps resolve() in a two-level convergence loop: the inner fixpoint resolves pending units, the outer loop runs cleanup_empty_declarations and re-enters resolution if cleanup produced new work
  • Extends cleanup_empty_declarations to sweep orphaned singleton classes (no definitions, no members, no constant references, no live descendants) alongside the existing TODO cleanup
  • Adds detach_from_ancestors to the REMOVE path of invalidate_declaration — cleans up stale descendant pointers so the singleton sweep can accurately identify unused singletons
  • Re-enqueues owner declarations for cleanup when a child is removed and the owner becomes empty (handles TODO parents losing their last child, singletons losing all members)
  • Updates has_no_backing_definitions to treat empty singletons (no definitions AND no members) as removable, while keeping populated singletons alive

Example

Given class A::B::C; class << self; def run; end; end; end, the indexer creates TODO declarations for A and A::B, plus a singleton A::B::C::<C>. If the file is deleted:

  1. Invalidation removes definitions from A::B::C and detaches them from A::B::C::<C>
  2. A::B::C becomes empty → removed, cascading to its singleton and parent TODOs
  3. The convergence loop re-runs cleanup until no declarations are removed and no new work is generated

Without this change, the TODO parents and singleton would persist as orphans after deletion.

@st0012 st0012 force-pushed the cleanup-synthetic-declarations branch from 1c585c2 to 9e7d776 Compare April 14, 2026 15:03
@st0012 st0012 force-pushed the defer-cleanup-emptied-declarations branch from 0d94164 to 4810117 Compare April 14, 2026 15:26
@st0012 st0012 closed this Apr 14, 2026
@st0012 st0012 force-pushed the cleanup-synthetic-declarations branch from 9e7d776 to 4810117 Compare April 14, 2026 15:26
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