mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Refactor name addition, particularly for associated entities. (#3924)
This is so that the constant associated with a function is used after the function declaration is complete, related to changing how function constants work.
This commit is contained in:
@@ -132,24 +132,8 @@ static auto BuildFunctionDecl(Context& context,
|
||||
function_info.definition_id = function_info.decl_id;
|
||||
}
|
||||
|
||||
// At interface scope, a function declaration introduces an associated
|
||||
// function.
|
||||
auto lookup_result_id = function_info.decl_id;
|
||||
if (name_context.enclosing_scope_id_for_new_inst().is_valid() &&
|
||||
!name_context.has_qualifiers) {
|
||||
auto scope_inst_id = context.name_scopes().GetInstIdIfValid(
|
||||
name_context.enclosing_scope_id_for_new_inst());
|
||||
if (auto interface_scope =
|
||||
context.insts().TryGetAsIfValid<SemIR::InterfaceDecl>(
|
||||
scope_inst_id)) {
|
||||
lookup_result_id = BuildAssociatedEntity(
|
||||
context, interface_scope->interface_id, function_info.decl_id);
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether this is a redeclaration.
|
||||
auto prev_id =
|
||||
context.decl_name_stack().LookupOrAddName(name_context, lookup_result_id);
|
||||
auto prev_id = name_context.prev_inst_id();
|
||||
if (prev_id.is_valid()) {
|
||||
auto prev_inst_for_merge =
|
||||
ResolvePrevInstForMerge(context, node_id, prev_id);
|
||||
@@ -179,6 +163,27 @@ static auto BuildFunctionDecl(Context& context,
|
||||
// Write the function ID into the FunctionDecl.
|
||||
context.ReplaceInstBeforeConstantUse(function_info.decl_id, function_decl);
|
||||
|
||||
// Check if we need to add this to name lookup, now that the function decl is
|
||||
// done.
|
||||
if (!prev_id.is_valid()) {
|
||||
// At interface scope, a function declaration introduces an associated
|
||||
// function.
|
||||
auto lookup_result_id = function_info.decl_id;
|
||||
if (name_context.enclosing_scope_id_for_new_inst().is_valid() &&
|
||||
!name_context.has_qualifiers) {
|
||||
auto scope_inst_id = context.name_scopes().GetInstIdIfValid(
|
||||
name_context.enclosing_scope_id_for_new_inst());
|
||||
if (auto interface_scope =
|
||||
context.insts().TryGetAsIfValid<SemIR::InterfaceDecl>(
|
||||
scope_inst_id)) {
|
||||
lookup_result_id = BuildAssociatedEntity(
|
||||
context, interface_scope->interface_id, function_info.decl_id);
|
||||
}
|
||||
}
|
||||
|
||||
context.decl_name_stack().AddName(name_context, lookup_result_id);
|
||||
}
|
||||
|
||||
if (SemIR::IsEntryPoint(context.sem_ir(), function_decl.function_id)) {
|
||||
// TODO: Update this once valid signatures for the entry point are decided.
|
||||
if (!context.inst_blocks().Get(implicit_param_refs_id).empty() ||
|
||||
|
||||
Reference in New Issue
Block a user