Give the BindSymbolicName for .Self in a binding pattern a FacetType type (#6036)

If it's just `TypeType` then the `BindSymbolicName` appears directly in
type positions, but if it is replaced with another facet value, then we
would need to insert a `FacetAccessType` around it. By giving it a
`FacetType` type, like other `BindSymbolicName`s we make it consistent
and avoid having to introduce extra instructions.
This commit is contained in:
Dana Jansens
2025-09-10 17:57:08 +00:00
committed by GitHub
parent d6fbe3c663
commit ed43fd2c1c
132 changed files with 1564 additions and 1248 deletions
+14 -3
View File
@@ -227,13 +227,24 @@ auto HandleParseNode(Context& context, Parse::VarBindingPatternId node_id)
}
auto HandleParseNode(Context& context,
Parse::CompileTimeBindingPatternStartId /*node_id*/)
-> bool {
Parse::CompileTimeBindingPatternStartId node_id) -> bool {
// Make a scope to contain the `.Self` facet value for use in the type of the
// compile time binding. This is popped when handling the
// CompileTimeBindingPatternId.
context.scope_stack().PushForSameRegion();
MakePeriodSelfFacetValue(context, SemIR::TypeType::TypeId);
// The `.Self` must have a type of `FacetType`, so that it gets wrapped in
// `FacetAccessType` when used in a type position, such as in `U:! I(.Self)`.
// This allows substitution with other facet values without requiring an
// additional `FacetAccessType` to be inserted.
SemIR::FacetTypeId facet_type_id =
context.facet_types().Add(SemIR::FacetTypeInfo{});
auto const_id = EvalOrAddInst<SemIR::FacetType>(
context, node_id,
{.type_id = SemIR::TypeType::TypeId, .facet_type_id = facet_type_id});
auto type_id = context.types().GetTypeIdForTypeConstantId(const_id);
MakePeriodSelfFacetValue(context, type_id);
return true;
}