mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 19:20:13 +01:00
2 small simplifications in member access (#5055)
* `IsInstanceMethod` can look in the function's `self_param_id` instead of iterating through all of the implicit parameter patterns. * An associated entity is always associated with a single interface, so we don't need to handle the case when it isn't. Co-authored-by: Josh L <josh11b@users.noreply.github.com>
This commit is contained in:
@@ -45,15 +45,7 @@ static auto GetClassElementIndex(Context& context, SemIR::InstId element_id)
|
||||
static auto IsInstanceMethod(const SemIR::File& sem_ir,
|
||||
SemIR::FunctionId function_id) -> bool {
|
||||
const auto& function = sem_ir.functions().Get(function_id);
|
||||
for (auto param_id :
|
||||
sem_ir.inst_blocks().GetOrEmpty(function.implicit_param_patterns_id)) {
|
||||
if (SemIR::Function::GetNameFromPatternId(sem_ir, param_id) ==
|
||||
SemIR::NameId::SelfValue) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return function.self_param_id.has_value();
|
||||
}
|
||||
|
||||
// Returns the highest allowed access. For example, if this returns `Protected`
|
||||
@@ -187,13 +179,8 @@ static auto PerformImplLookup(
|
||||
MakeDiagnosticBuilderFn missing_impl_diagnoser = nullptr) -> SemIR::InstId {
|
||||
auto interface_type =
|
||||
GetInterfaceFromFacetType(context, assoc_type.interface_type_id);
|
||||
if (!interface_type) {
|
||||
context.TODO(loc_id,
|
||||
"Lookup of impl witness not yet supported except for a single "
|
||||
"interface");
|
||||
return SemIR::ErrorInst::SingletonInstId;
|
||||
}
|
||||
|
||||
// An associated entity is always associated with a single interface.
|
||||
CARBON_CHECK(interface_type);
|
||||
auto self_type_id = context.types().GetTypeIdForTypeConstantId(type_const_id);
|
||||
auto witness_id =
|
||||
LookupImplWitness(context, loc_id, type_const_id,
|
||||
|
||||
Reference in New Issue
Block a user