mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Special-case api/impl implicit imports and verify relevant redeclarations. (#3843)
Adds ImportIRId::ApiForImpl to reserve a specific slot for the `api` import, so that the code can trivially determine whether an import is from the same library. This is then used for merging function declarations, because the rules for redeclarations in the same library slightly differ as compared to other imports (note they're also not identical to same-file rules). The main thing this leaves from the recent #3762 is verifying that entities forward declared in the `impl` file are also defined, but that's not in-scope for merging; it's moreso post-checking validation. Note, a lot of our `invalid <entity> ID` comments in ids.h were incorrectly copy-pasted, so I've cut `<entity>`.
This commit is contained in:
@@ -169,14 +169,15 @@ static auto BuildFunctionDecl(Context& context,
|
||||
auto prev_id =
|
||||
context.decl_name_stack().LookupOrAddName(name_context, lookup_result_id);
|
||||
if (prev_id.is_valid()) {
|
||||
auto prev_inst = ResolvePrevInstForMerge(context, node_id, prev_id);
|
||||
auto prev_inst_for_merge =
|
||||
ResolvePrevInstForMerge(context, node_id, prev_id);
|
||||
|
||||
if (auto existing_function_decl =
|
||||
prev_inst.inst.TryAs<SemIR::FunctionDecl>()) {
|
||||
prev_inst_for_merge.inst.TryAs<SemIR::FunctionDecl>()) {
|
||||
if (MergeFunctionRedecl(context, node_id, function_info,
|
||||
/*new_is_import=*/false, is_definition,
|
||||
existing_function_decl->function_id,
|
||||
prev_inst.is_import)) {
|
||||
prev_inst_for_merge.import_ir_inst_id)) {
|
||||
// When merging, use the existing function rather than adding a new one.
|
||||
function_decl.function_id = existing_function_decl->function_id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user