mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 16:21: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:
@@ -5,8 +5,10 @@
|
||||
#include "toolchain/check/require_impls.h"
|
||||
|
||||
#include "toolchain/check/generic.h"
|
||||
#include "toolchain/check/inst.h"
|
||||
#include "toolchain/check/interface.h"
|
||||
#include "toolchain/sem_ir/ids.h"
|
||||
#include "toolchain/sem_ir/typed_insts.h"
|
||||
|
||||
namespace Carbon::Check {
|
||||
|
||||
@@ -68,28 +70,19 @@ auto GetRequireImplsSpecificFromEnclosingSpecific(
|
||||
return {.specific_id = specific_id};
|
||||
}
|
||||
|
||||
auto GetRequireImplsSpecificFromEnclosingSpecificWithSelfType(
|
||||
auto GetRequireImplsSpecificFromEnclosingSpecificWithSelfFacetValue(
|
||||
Context& context, const SemIR::RequireImpls& require,
|
||||
SemIR::SpecificId enclosing_specific_id, SemIR::TypeInstId self_id,
|
||||
SemIR::InstId witness_id) -> RequireImplsSpecific {
|
||||
if (enclosing_specific_id.has_value()) {
|
||||
auto enclosing_generic_decl =
|
||||
GetEnclosingDeclFromEnclosingSpecificId(context, enclosing_specific_id);
|
||||
CARBON_CHECK(enclosing_generic_decl.Is<SemIR::InterfaceDecl>(),
|
||||
"Incorrect enclosing specific for RequireImpls with explicit "
|
||||
"self type. Expected an interface. Found {0}.",
|
||||
enclosing_generic_decl);
|
||||
}
|
||||
|
||||
// Construct a facet value around the `self_id` type of the correct facet
|
||||
// type for the `Self` in the require's self-specific.
|
||||
auto self_facet_value = GetSelfFacetValueForInterfaceMemberSpecific(
|
||||
context, enclosing_specific_id, require.generic_id,
|
||||
context.types().GetTypeIdForTypeInstId(self_id), witness_id);
|
||||
SemIR::SpecificId enclosing_specific_id,
|
||||
SemIR::ConstantId self_facet_value_id) -> RequireImplsSpecific {
|
||||
auto self_facet_value_inst_id =
|
||||
context.constant_values().GetInstId(self_facet_value_id);
|
||||
auto self_facet_value = context.insts().Get(self_facet_value_inst_id);
|
||||
CARBON_CHECK(context.types().Is<SemIR::FacetType>(self_facet_value.type_id()),
|
||||
"{0}", self_facet_value);
|
||||
|
||||
auto arg_ids =
|
||||
GetSpecificArgsFromEnclosingSpecific(context, enclosing_specific_id);
|
||||
arg_ids.push_back(self_facet_value);
|
||||
arg_ids.push_back(self_facet_value_inst_id);
|
||||
|
||||
auto specific_id = MakeSpecific(context, SemIR::LocId(require.decl_id),
|
||||
require.generic_id, arg_ids);
|
||||
|
||||
Reference in New Issue
Block a user