Support importing associated constant declarations (#4794)

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
This commit is contained in:
josh11b
2025-01-13 19:20:28 +00:00
committed by GitHub
co-authored by Josh L
parent 6f6e46ef57
commit 3a44b65b95
2 changed files with 1241 additions and 0 deletions
+25
View File
@@ -1336,6 +1336,28 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
.element_type_id = element_type_id});
}
static auto TryResolveTypedInst(ImportRefResolver& resolver,
SemIR::AssociatedConstantDecl inst,
SemIR::InstId import_inst_id) -> ResolveResult {
auto type_const_id = GetLocalConstantId(resolver, inst.type_id);
if (resolver.HasNewWork()) {
return ResolveResult::Retry();
}
auto type_id =
resolver.local_context().GetTypeIdForTypeConstant(type_const_id);
// Create a corresponding instruction to represent the declaration.
auto inst_id = resolver.local_context().AddInstInNoBlock(
resolver.local_context()
.MakeImportedLocAndInst<SemIR::AssociatedConstantDecl>(
AddImportIRInst(resolver, import_inst_id),
{.type_id = type_id,
.name_id = GetLocalNameId(resolver, inst.name_id)}));
return ResolveResult::Done(resolver.local_constant_values().Get(inst_id),
inst_id);
}
static auto TryResolveTypedInst(ImportRefResolver& resolver,
SemIR::AssociatedEntity inst) -> ResolveResult {
auto type_const_id = GetLocalConstantId(resolver, inst.type_id);
@@ -2574,6 +2596,9 @@ static auto TryResolveInstCanonical(ImportRefResolver& resolver,
case CARBON_KIND(SemIR::ArrayType inst): {
return TryResolveTypedInst(resolver, inst);
}
case CARBON_KIND(SemIR::AssociatedConstantDecl inst): {
return TryResolveTypedInst(resolver, inst, inst_id);
}
case CARBON_KIND(SemIR::AssociatedEntity inst): {
return TryResolveTypedInst(resolver, inst);
}
File diff suppressed because it is too large Load Diff