Implement 'extern library' support for functions. (#4220)

Support for types (particularly classes) is left as a TODO.

There's also an issue I'm observing with a "define in impl" test, but
this is probably an issue with resolving the prior declaration which is
imported indirectly. The PR was already feeling big, so I'm choosing to
cut here.

Note, this does not implement the rule "The owning library's API file
must import the `extern` declaration, and must also contain a
declaration."
This commit is contained in:
Jon Ross-Perkins
2024-08-19 22:12:21 +00:00
committed by GitHub
parent 0a4b0f33e3
commit 2d3842fc06
34 changed files with 1729 additions and 937 deletions
+8 -10
View File
@@ -54,7 +54,8 @@ static auto BuildInterfaceDecl(Context& context,
context.AddPlaceholderInst(SemIR::LocIdAndInst(node_id, interface_decl));
SemIR::Interface interface_info = {name_context.MakeEntityWithParamsBase(
name, interface_decl_id, /*is_extern=*/false)};
name, interface_decl_id, /*is_extern=*/false,
SemIR::LibraryNameId::Invalid)};
RequireGenericParams(context, interface_info.implicit_param_refs_id);
RequireGenericParams(context, interface_info.param_refs_id);
@@ -75,15 +76,12 @@ static auto BuildInterfaceDecl(Context& context,
// TODO: This should be refactored a little, particularly for
// prev_import_ir_id. See similar logic for classes and functions, which
// might also be refactored to merge.
CheckIsAllowedRedecl(context, Lex::TokenKind::Interface,
existing_interface.name_id,
{.loc = node_id,
.is_definition = is_definition,
.is_extern = false},
{.loc = existing_interface.latest_decl_id(),
.is_definition = existing_interface.is_defined(),
.is_extern = false},
/*prev_import_ir_id=*/SemIR::ImportIRId::Invalid);
CheckIsAllowedRedecl(
context, Lex::TokenKind::Interface, existing_interface.name_id,
RedeclInfo(interface_info, node_id, is_definition),
RedeclInfo(existing_interface, existing_interface.latest_decl_id(),
existing_interface.is_defined()),
/*prev_import_ir_id=*/SemIR::ImportIRId::Invalid);
// Can't merge interface definitions due to the generic requirements.
// TODO: Should this also be mirrored to classes/functions for generics?