Find the builtin TypeCanAggregateDestroy in the FacetType for facet values (#6119)

When doing impl lookup with a constraint facet type including the
builtin `TypeCanAggregateDestroy`, we look at the type to see if it
satisfies it. However if the type is a facet value, we need to look at
the FacetType to see if the eventual concrete type is going to satisfy
it.

Note that we can do this check up front in the `LookupImplWitness()`
function without creating a symbolic instruction to be modified by
future specifics with a more precise type for the facet value, because
the result of `TypeCanAggregateDestroy` does not actually provide a
witness, so we don't need the final specific type.

This was noticed by removing the "shortcut" in convert for converting a
`FacetAccessType(<symbolic binding>)` to `typeof(<symbolic binding>)`.
By removing the shortcut, we go into impl lookup when checking `impl`
decls containing `TypeCanAggregateDestroy` via deduce.
This commit is contained in:
Dana Jansens
2025-10-02 18:57:37 +00:00
committed by GitHub
parent 57c0fde145
commit 0c761a9a78
4 changed files with 34 additions and 13 deletions
+13 -2
View File
@@ -545,8 +545,19 @@ static auto GetOrAddLookupImplWitness(Context& context, SemIR::LocId loc_id,
// Returns true if the `Self` should impl `Destroy`.
static auto TypeCanDestroy(Context& context,
SemIR::ConstantId query_self_const_id) -> bool {
auto inst = context.insts().Get(
context.constant_values().GetInstId(query_self_const_id));
auto inst = context.insts().Get(context.constant_values().GetInstId(
GetCanonicalizedFacetOrTypeValue(context, query_self_const_id)));
// For facet values, look if the FacetType provides the same.
if (auto facet_type =
context.types().TryGetAs<SemIR::FacetType>(inst.type_id())) {
const auto& info = context.facet_types().Get(facet_type->facet_type_id);
if (info.builtin_constraint_mask.HasAnyOf(
SemIR::BuiltinConstraintMask::TypeCanDestroy)) {
return true;
}
}
CARBON_KIND_SWITCH(inst) {
case CARBON_KIND(SemIR::ClassType class_type): {
auto class_info = context.classes().Get(class_type.class_id);