adds a field to SemIR::Interface to indicate whether it is a core interface (#7091)

The existing `GetCoreInterface` has linear-time complexity and adds more
than the search criteria to the `CoreInterfaceCache`. Adding a new field
to `Interface` changes this operation when building packages other than
`Core`, as this should only be set for the core library.
This commit is contained in:
Christopher Di Bella
2026-04-24 17:33:23 +00:00
committed by GitHub
parent 9532effeae
commit f0c4b37c63
14 changed files with 1002 additions and 48 deletions
+12
View File
@@ -87,6 +87,18 @@ static auto BuildInterfaceDecl(Context& context,
} else {
// Create a new interface if this isn't a valid redeclaration.
interface_info.generic_id = BuildGenericDecl(context, decl_inst_id);
if (context.sem_ir().package_id() == PackageNameId::Core) {
auto name = context.names().GetIRBaseName(interface_info.name_id);
interface_info.core_interface =
llvm::StringSwitch<SemIR::CoreInterface>(name)
.Case("Copy", SemIR::CoreInterface::Copy)
.Case("CppUnsafeDeref", SemIR::CoreInterface::CppUnsafeDeref)
.Case("Default", SemIR::CoreInterface::Default)
.Case("Destroy", SemIR::CoreInterface::Destroy)
.Case("IntFitsIn", SemIR::CoreInterface::IntFitsIn)
.Default(SemIR::CoreInterface::Unknown);
}
interface_decl.interface_id = context.interfaces().Add(interface_info);
if (interface_info.has_parameters()) {
interface_decl.type_id =