Make FacetAccessType evaluate to SymbolicBindingType for type-of a BindSymbolicName (#6115)

The SymbolicBindingType refers to the type value that will be
substituted in for the BindSymbolicName, but holds onto the EntityNameId
from the BindSymbolicName instead of (or in addition to, for now) the
instruction.

The EntityNameId will be used to look in the ScopeStack to find the
witnesses either from the BindSymbolicName instruction, or other
instructions that specify `impls` constraints against the EntityName.

This will allow us to have the `T` in `I(T)` resolve to a `.Self`
reference in the type so that we get type equality with the binding's
type: `T:! I(.Self)`.
This commit is contained in:
Dana Jansens
2025-10-06 18:56:43 +00:00
committed by GitHub
parent bd4d5805dd
commit fe020ee08b
237 changed files with 7827 additions and 7586 deletions
+41 -6
View File
@@ -752,6 +752,8 @@ static auto GetLocalConstantId(ImportRefResolver& resolver,
}
// Translates a NameId from the import IR to a local NameId.
//
// No new work is generated by calling this function.
static auto GetLocalNameId(ImportContext& context, SemIR::NameId import_name_id)
-> SemIR::NameId {
if (auto ident_id = import_name_id.AsIdentifierId(); ident_id.has_value()) {
@@ -761,6 +763,23 @@ static auto GetLocalNameId(ImportContext& context, SemIR::NameId import_name_id)
return import_name_id;
}
// Returns the id for a local symbolic EntityName from an imported one,
// preserving only the `NameId`, the `CompileTimeBindIndex`, and whether it is a
// template. Other parts of the EntityName are not kept and are not considered
// part of the canonical EntityName (even if they are present there).
//
// No new work is generated by calling this function.
static auto GetLocalSymbolicEntityNameId(
ImportContext& context, SemIR::EntityNameId import_entity_name_id)
-> SemIR::EntityNameId {
const auto& import_entity_name =
context.import_entity_names().Get(import_entity_name_id);
auto name_id = GetLocalNameId(context, import_entity_name.name_id);
return context.local_entity_names().AddSymbolicBindingName(
name_id, SemIR::NameScopeId::None, import_entity_name.bind_index(),
import_entity_name.is_template);
}
// Gets the local constant values corresponding to an imported inst block.
static auto GetLocalInstBlockContents(ImportRefResolver& resolver,
SemIR::InstBlockId import_block_id)
@@ -1501,12 +1520,8 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
return ResolveResult::Retry();
}
const auto& import_entity_name =
resolver.import_entity_names().Get(inst.entity_name_id);
auto name_id = GetLocalNameId(resolver, import_entity_name.name_id);
auto entity_name_id = resolver.local_entity_names().AddSymbolicBindingName(
name_id, SemIR::NameScopeId::None, import_entity_name.bind_index(),
import_entity_name.is_template);
auto entity_name_id =
GetLocalSymbolicEntityNameId(resolver, inst.entity_name_id);
return ResolveAsDeduplicated<SemIR::BindSymbolicName>(
resolver,
{.type_id =
@@ -2960,6 +2975,23 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
GetLocalCanonicalInstBlockId(resolver, inst.elements_id, elems)});
}
static auto TryResolveTypedInst(ImportRefResolver& resolver,
SemIR::SymbolicBindingType inst)
-> ResolveResult {
auto facet_value_inst_id =
GetLocalConstantInstId(resolver, inst.facet_value_inst_id);
if (resolver.HasNewWork()) {
return ResolveResult::Retry();
}
auto entity_name_id =
GetLocalSymbolicEntityNameId(resolver, inst.entity_name_id);
return ResolveAsDeduplicated<SemIR::SymbolicBindingType>(
resolver, {.type_id = SemIR::TypeType::TypeId,
.entity_name_id = entity_name_id,
.facet_value_inst_id = facet_value_inst_id});
}
static auto TryResolveTypedInst(ImportRefResolver& resolver,
SemIR::TupleAccess inst) -> ResolveResult {
auto type_id = GetLocalConstantId(resolver, inst.type_id);
@@ -3311,6 +3343,9 @@ static auto TryResolveInstCanonical(ImportRefResolver& resolver,
case CARBON_KIND(SemIR::SymbolicBindingPattern inst): {
return TryResolveTypedInst(resolver, inst, constant_inst_id);
}
case CARBON_KIND(SemIR::SymbolicBindingType inst): {
return TryResolveTypedInst(resolver, inst);
}
case CARBON_KIND(SemIR::TupleAccess inst): {
return TryResolveTypedInst(resolver, inst);
}