mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 13:31:06 +01:00
Wrap lookup result in a new ScopeLookupResult (#4831)
Benefits: * Provide a proper API for accessing lookup information. * Make assumptions on whether the result is poisoned or not and how we can use `InstId` explicit. * Allow safely reusing the `InstId` value for pointing to the poisoning entity for poisoned results (in a future PR). * Consolidate `LookupNameInExactScopeResult`, `std::pair<SemIR::InstId, bool>` and part of `LookupResult`. Part of #4622.
This commit is contained in:
@@ -160,8 +160,8 @@ auto DeclNameStack::AddName(NameContext name_context, SemIR::InstId target_id,
|
||||
}
|
||||
|
||||
name_scope.AddRequired({.name_id = name_context.unresolved_name_id,
|
||||
.inst_id = target_id,
|
||||
.access_kind = access_kind});
|
||||
.result = SemIR::ScopeLookupResult::MakeFound(
|
||||
target_id, access_kind)});
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -262,20 +262,20 @@ auto DeclNameStack::ApplyAndLookupName(NameContext& name_context,
|
||||
}
|
||||
|
||||
// For identifier nodes, we need to perform a lookup on the identifier.
|
||||
auto [resolved_inst_id, is_poisoned] = context_->LookupNameInDecl(
|
||||
auto lookup_result = context_->LookupNameInDecl(
|
||||
name_context.loc_id, name_id, name_context.parent_scope_id,
|
||||
name_context.initial_scope_index);
|
||||
if (is_poisoned) {
|
||||
if (lookup_result.is_poisoned()) {
|
||||
name_context.unresolved_name_id = name_id;
|
||||
name_context.state = NameContext::State::Poisoned;
|
||||
} else if (!resolved_inst_id.has_value()) {
|
||||
} else if (!lookup_result.is_found()) {
|
||||
// Invalid indicates an unresolved name. Store it and return.
|
||||
name_context.unresolved_name_id = name_id;
|
||||
name_context.state = NameContext::State::Unresolved;
|
||||
} else {
|
||||
// Store the resolved instruction and continue for the target scope
|
||||
// update.
|
||||
name_context.resolved_inst_id = resolved_inst_id;
|
||||
name_context.resolved_inst_id = lookup_result.target_inst_id();
|
||||
name_context.state = NameContext::State::Resolved;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user