mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 09:01:04 +01:00
Make identifying a facet type an operation on a (self+facet type) pair (#6592)
Identifying a facet type takes both a self and facet type as a pair, and then encode the self into the IdentifiedFacetType. This makes a constraint that requires some _other_ type implements an interface visible in the IdentifiedFacetType. And it will help to enable facet types with `where T impls Z` for `T` that is not `.Self` in the future. IdentifiedFacetTypes are now stored in a CanonicalValueStore instead of a RelationalValueStore as they key is the combination of self and (declared) facet type together now. When the self-type is a facet value (has type FacetType) this is most straightforward. But when it's a type we need to construct a FacetValue to construct a specific for a require decl, to replace the generic binding of the symbolic `Self`, which has type FacetType. To do so, we make a FacetValue with an empty FacetType (equivalent to TypeType). This prevents any looking for witnesses through the FacetType, which matches what you can get from a type directly, requiring witnesses to come from finding an `impl` decl. Add additional InstNamer logic for such empty facet types so they print as `<typename>.type.facet` if possible instead of as just `facet_value`.
This commit is contained in:
@@ -302,7 +302,8 @@ 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.
|
||||
@@ -312,12 +313,7 @@ auto HandleParseNode(Context& context,
|
||||
// `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);
|
||||
auto type_id = GetEmptyFacetType(context);
|
||||
|
||||
MakePeriodSelfFacetValue(context, type_id);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user