Import contained RequireImpls when importing an Interface or NamedConstraint (#6344)

When importing an Interface or NamedConstraint, walk the block of
`RequireImplsId`s, and for each one:
- Import the RequireImplsDecl from it, which also imports the
`RequireImpls` structure and its id.
- Collect those decls and build a block of `RequireImplsId`s for the
local SemIR to reference from the Interface or NamedConstraint.

The import of RequireImplsDecl is done in a single phase instead of
three, unlike other decls. This is possible since require declarations
have no name, so they can't be referenced by instructions inside them,
thus there's no cycles to concern ourselves with.
This commit is contained in:
Dana Jansens
2025-11-14 14:31:11 +00:00
committed by GitHub
parent b300f36e6f
commit 0177dc5677
16 changed files with 430 additions and 153 deletions
+16 -3
View File
@@ -4,7 +4,10 @@
#include "toolchain/sem_ir/impl.h"
#include "toolchain/base/kind_switch.h"
#include "toolchain/sem_ir/file.h"
#include "toolchain/sem_ir/specific_interface.h"
#include "toolchain/sem_ir/specific_named_constraint.h"
namespace Carbon::SemIR {
@@ -20,9 +23,19 @@ auto ImplStore::GetOrAddLookupBucket(const Impl& impl) -> LookupBucketRef {
if (auto facet_type = sem_ir_.types().TryGetAs<FacetType>(facet_type_id)) {
const FacetTypeInfo& facet_type_info =
sem_ir_.facet_types().Get(facet_type->facet_type_id);
if (auto interface_type = facet_type_info.TryAsSingleInterface()) {
interface_id = interface_type->interface_id;
specific_id = interface_type->specific_id;
if (auto single = facet_type_info.TryAsSingleExtend()) {
CARBON_KIND_SWITCH(*single) {
case CARBON_KIND(SemIR::SpecificInterface interface): {
interface_id = interface.interface_id;
specific_id = interface.specific_id;
break;
}
case CARBON_KIND(SemIR::SpecificNamedConstraint _): {
// TODO: Handle named constraints which resolve to a single interface
// in the IdentifiedFacetType.
break;
}
}
}
}
return LookupBucketRef(