Add unresolve functions and declaration_to_names reverse index#627
Add unresolve functions and declaration_to_names reverse index#627
declaration_to_names reverse index#627Conversation
vinistock
left a comment
There was a problem hiding this comment.
The changes look good, just trying to understand if we got the right data structure
3bc96fb to
4980e3b
Compare
| } | ||
|
|
||
| /// Removes a name from the graph entirely. | ||
| fn remove_name(&mut self, name_id: NameId) { |
There was a problem hiding this comment.
Creating this method as we'll also update name_dependents here in follow up PRs.
vinistock
left a comment
There was a problem hiding this comment.
Yeah, let's start without any auxiliary maps and implement the simplest version.
We can iterate on performance once we have something that works and that we fully understand
| } | ||
|
|
||
| for ref_id in document.constant_references() { | ||
| self.unresolve_reference(*ref_id); |
There was a problem hiding this comment.
This is okay for now, but be careful with mixing the removal and the invalidation of the data.
The fact that a constant reference was removed doesn't necessarily mean that the NameRef needs to become unresolved. For example:
# file1.rb
class Foo
# NameRef(CONST, parent_scope: None, nesting: Foo)
CONST
end
# Delete
# file2.rb
class Foo
# NameRef(CONST, parent_scope: None, nesting: Foo)
CONST
endThere was a problem hiding this comment.
My plan is for this and #589 to ALWAYS unresolve CONST when a Foo definition is removed to make sure this will be correct:
class Foo
include Bar # Bar defines CONST
CONST # resolves to Bar::CONST via ancestor lookup
end And then we create a follow up PR to make this and other invalidation more efficient.
Introduce `unresolve_name`, `unresolve_reference`, and `remove_name` as building blocks for incremental invalidation. Use `unresolve_reference` in `remove_definitions_for_document` to properly detach references from declarations when a file is updated.
4980e3b to
0ac1ae6
Compare
Extracted from #589
Add methods for unwinding name resolution during incremental updates:
unresolve_name: converts aResolvedname back toUnresolvedunresolve_reference: detaches a reference from its declaration and unresolves the underlying nameremove_name: removes a name and cleans up reverse indicesAdd
declaration_to_namesreverse index that tracks which names resolve to each declaration. Populated duringrecord_resolved_name, cleaned up by the unresolve/remove primitives.