Switch class to use a blanket impl for Destroy (#6125)

Right now, the class destroy impl is incorrectly generated (first
discussed [in
Discord](https://discord.com/channels/655572317891461132/941071822756143115/1418614787449032826)).
If we want it to be correct, deferred definition logic would need to be
added, and the declaration would need to be moved inside the `class`
scope (along with whatever generic logic that needs).

This instead switches to a blanket impl, to avoid creating latent bugs
with generating the `impl` and function body in the wrong scope. This
approach uses the same blanket impl as aggregate destruction that was
added by #6098.

The intent here is to allow progress on other parts of `Destroy`. For
example, under this model the implementation of the function body could
be done as part of lowering the specific.
This commit is contained in:
Jon Ross-Perkins
2025-09-29 16:05:06 +00:00
committed by GitHub
parent 5705b94da8
commit 49ba8cf3e1
230 changed files with 3632 additions and 21983 deletions
+2 -31
View File
@@ -492,18 +492,11 @@ fn MyF(bar: Cpp.Bar*);
// CHECK:STDOUT: %Bar: type = class_type @Bar [concrete]
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %Derived.elem: type = unbound_element_type %Derived, %Bar [concrete]
// CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
// CHECK:STDOUT: %pattern_type.f6d: type = pattern_type auto [concrete]
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness @Derived.%Destroy.impl_witness_table [concrete]
// CHECK:STDOUT: %ptr.404: type = ptr_type %Derived [concrete]
// CHECK:STDOUT: %pattern_type.605: type = pattern_type %ptr.404 [concrete]
// CHECK:STDOUT: %Derived.as.Destroy.impl.Op.type: type = fn_type @Derived.as.Destroy.impl.Op [concrete]
// CHECK:STDOUT: %Derived.as.Destroy.impl.Op: %Derived.as.Destroy.impl.Op.type = struct_value () [concrete]
// CHECK:STDOUT: %struct_type.base.36d: type = struct_type {.base: %Bar} [concrete]
// CHECK:STDOUT: %complete_type.fff: <witness> = complete_type_witness %struct_type.base.36d [concrete]
// CHECK:STDOUT: %MyF.type: type = fn_type @MyF [concrete]
// CHECK:STDOUT: %MyF: %MyF.type = struct_value () [concrete]
// CHECK:STDOUT: %.c07: type = cpp_overload_set_type @Derived.as.Destroy.impl.Op [concrete]
// CHECK:STDOUT: %.c07: type = cpp_overload_set_type @Bar.foo [concrete]
// CHECK:STDOUT: %empty_struct: %.c07 = struct_value () [concrete]
// CHECK:STDOUT: %Bar.foo.type: type = fn_type @Bar.foo [concrete]
// CHECK:STDOUT: %Bar.foo: %Bar.foo.type = struct_value () [concrete]
@@ -515,7 +508,7 @@ fn MyF(bar: Cpp.Bar*);
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %Bar.decl: type = class_decl @Bar [concrete = constants.%Bar] {} {}
// CHECK:STDOUT: %.617: %.c07 = cpp_overload_set_value @Derived.as.Destroy.impl.Op [concrete = constants.%empty_struct]
// CHECK:STDOUT: %.617: %.c07 = cpp_overload_set_value @Bar.foo [concrete = constants.%empty_struct]
// CHECK:STDOUT: %Bar.foo.decl: %Bar.foo.type = fn_decl @Bar.foo [concrete = constants.%Bar.foo] {} {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
@@ -524,30 +517,10 @@ fn MyF(bar: Cpp.Bar*);
// CHECK:STDOUT: %MyF.decl: %MyF.type = fn_decl @MyF [concrete = constants.%MyF] {} {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: impl @Derived.as.Destroy.impl: @Derived.%Self.ref as constants.%Destroy.type {
// CHECK:STDOUT: %Derived.as.Destroy.impl.Op.decl: %Derived.as.Destroy.impl.Op.type = fn_decl @Derived.as.Destroy.impl.Op [concrete = constants.%Derived.as.Destroy.impl.Op] {
// CHECK:STDOUT: %self.patt: %pattern_type.605 = binding_pattern self [concrete]
// CHECK:STDOUT: %self.param_patt: %pattern_type.605 = value_param_pattern %self.patt, call_param0 [concrete]
// CHECK:STDOUT: %.loc7: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %self.param: %ptr.404 = value_param call_param0
// CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Derived [concrete = constants.%Derived]
// CHECK:STDOUT: %self: %ptr.404 = bind_name self, %self.param
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Op = %Derived.as.Destroy.impl.Op.decl
// CHECK:STDOUT: witness = @Derived.%Destroy.impl_witness
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @Derived {
// CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
// CHECK:STDOUT: %Bar.ref: type = name_ref Bar, imports.%Bar.decl [concrete = constants.%Bar]
// CHECK:STDOUT: %.loc8: %Derived.elem = base_decl %Bar.ref, element0 [concrete]
// CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Derived [concrete = constants.%Derived]
// CHECK:STDOUT: impl_decl @Derived.as.Destroy.impl [concrete] {} {}
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@Derived.as.Destroy.impl.%Derived.as.Destroy.impl.Op.decl), @Derived.as.Destroy.impl [concrete]
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness]
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.base.36d [concrete = constants.%complete_type.fff]
// CHECK:STDOUT: complete_type_witness = %complete_type
// CHECK:STDOUT:
@@ -559,8 +532,6 @@ fn MyF(bar: Cpp.Bar*);
// CHECK:STDOUT: extend %Bar.ref
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Derived.as.Destroy.impl.Op(%self.param: %ptr.404) = "no_op";
// CHECK:STDOUT:
// CHECK:STDOUT: fn @MyF() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %Derived.ref: type = name_ref Derived, file.%Derived.decl [concrete = constants.%Derived]
+9 -5
View File
@@ -326,11 +326,13 @@ fn Call(e: Cpp.ExplicitObjectParam, n: i32, a: Cpp.Another) {
// CHECK:STDOUT: %pattern_type.fe8: type = pattern_type %ptr.235 [concrete]
// CHECK:STDOUT: %HasQualifiers.F.type.d208f0.2: type = fn_type @HasQualifiers.F.2 [concrete]
// CHECK:STDOUT: %HasQualifiers.F.efd4e4.2: %HasQualifiers.F.type.d208f0.2 = struct_value () [concrete]
// CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanAggregateDestroy>> [concrete]
// CHECK:STDOUT: %ptr.as.Destroy.impl.Op.type.142: type = fn_type @ptr.as.Destroy.impl.Op, @ptr.as.Destroy.impl(%i32) [concrete]
// CHECK:STDOUT: %ptr.as.Destroy.impl.Op.c04: %ptr.as.Destroy.impl.Op.type.142 = struct_value () [concrete]
// CHECK:STDOUT: %ptr.5d5: type = ptr_type %ptr.235 [concrete]
// CHECK:STDOUT: %Int.as.Destroy.impl.Op.type.4f9: type = fn_type @Int.as.Destroy.impl.Op, @Int.as.Destroy.impl(%int_32) [concrete]
// CHECK:STDOUT: %Int.as.Destroy.impl.Op.796: %Int.as.Destroy.impl.Op.type.4f9 = struct_value () [concrete]
// CHECK:STDOUT: %facet_value: %type_where = facet_value %i32, () [concrete]
// CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.type.cb3: type = fn_type @AggregateT.as_type.as.Destroy.impl.Op, @AggregateT.as_type.as.Destroy.impl(%facet_value) [concrete]
// CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.cad: %AggregateT.as_type.as.Destroy.impl.Op.type.cb3 = struct_value () [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
@@ -391,11 +393,13 @@ fn Call(e: Cpp.ExplicitObjectParam, n: i32, a: Cpp.Another) {
// CHECK:STDOUT: %bound_method.loc9_3: <bound method> = bound_method %b.var, %ptr.as.Destroy.impl.Op.specific_fn
// CHECK:STDOUT: %addr.loc9_3: %ptr.5d5 = addr_of %b.var
// CHECK:STDOUT: %ptr.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method.loc9_3(%addr.loc9_3)
// CHECK:STDOUT: %Int.as.Destroy.impl.Op.bound: <bound method> = bound_method %a.var, constants.%Int.as.Destroy.impl.Op.796
// CHECK:STDOUT: %facet_value: %type_where = facet_value constants.%i32, () [concrete = constants.%facet_value]
// CHECK:STDOUT: %.loc8_3: %type_where = converted constants.%i32, %facet_value [concrete = constants.%facet_value]
// CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %a.var, constants.%AggregateT.as_type.as.Destroy.impl.Op.cad
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: %bound_method.loc8_3: <bound method> = bound_method %a.var, %Int.as.Destroy.impl.Op.specific_fn
// CHECK:STDOUT: %bound_method.loc8_3: <bound method> = bound_method %a.var, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn
// CHECK:STDOUT: %addr.loc8_3: %ptr.235 = addr_of %a.var
// CHECK:STDOUT: %Int.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method.loc8_3(%addr.loc8_3)
// CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method.loc8_3(%addr.loc8_3)
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: }
// CHECK:STDOUT: