mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 21:41:27 +01:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user