Skip to content

Commit

Permalink
Optimization: avoid extending complete partial paths a @typeof symb…
Browse files Browse the repository at this point in the history
…ol is pushed next

This avoids a lot of extra work for the resolution when the identifier being
resolved is a variable that has a type. Since the definition is found but then
replace by the sequence `@typeof` and the type of the variable, which will never
resolve. This path *is* used when resolving for members of the type of the
variable.
  • Loading branch information
ggiraldez committed Jan 24, 2025
1 parent 0dad66e commit d3d75af
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/metaslang/bindings/src/graph/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ impl<'a, KT: KindTypes + 'static>
R: std::iter::Extend<ExtendedHandle>,
{
let node = path.end_node;
let is_complete = path.is_complete(&self.owner.stack_graph);

let mut db_candidates = Vec::new();
self.database.database.find_candidate_partial_paths(
Expand All @@ -269,6 +270,24 @@ impl<'a, KT: KindTypes + 'static>
result.extend(
db_candidates
.iter()
.filter(|candidate| {
if is_complete {
let candidate = &self.database.database[**candidate];
if let Some(last_symbol) = candidate
.symbol_stack_postcondition
.iter(self.partials)
.last()
{
// Special case: when the current partial path is
// already complete, don't extend through a @typeof
// symbol since that will not resolve to anything
if &self.owner.stack_graph[last_symbol.symbol] == "@typeof" {
return false;
}
}
}
true
})
.map(|candidate| ExtendedHandle::Handle(*candidate)),
);

Expand Down

0 comments on commit d3d75af

Please sign in to comment.