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:
Jon Ross-Perkins
2024-04-04 16:03:41 +00:00
committed by GitHub
parent 45c071f2af
commit 2361830592
64 changed files with 1031 additions and 551 deletions
+4 -3
View File
@@ -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;
}