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
@@ -45,13 +45,6 @@ fn F() {
// CHECK:STDOUT: %W.type: type = facet_type <@W> [concrete]
// CHECK:STDOUT: %Self.7b5: %W.type = bind_symbolic_name Self, 0 [symbolic]
// CHECK:STDOUT: %DD: type = class_type @DD [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.31d: <witness> = impl_witness @DD.%Destroy.impl_witness_table [concrete]
// CHECK:STDOUT: %ptr.3d1: type = ptr_type %DD [concrete]
// CHECK:STDOUT: %pattern_type.3fc: type = pattern_type %ptr.3d1 [concrete]
// CHECK:STDOUT: %DD.as.Destroy.impl.Op.type: type = fn_type @DD.as.Destroy.impl.Op [concrete]
// CHECK:STDOUT: %DD.as.Destroy.impl.Op: %DD.as.Destroy.impl.Op.type = struct_value () [concrete]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
// CHECK:STDOUT: %Y.impl_witness: <witness> = impl_witness file.%Y.impl_witness_table [concrete]
@@ -63,11 +56,6 @@ fn F() {
// CHECK:STDOUT: %CC.type: type = generic_class_type @CC [concrete]
// CHECK:STDOUT: %CC.generic: %CC.type = struct_value () [concrete]
// CHECK:STDOUT: %CC.ef8: type = class_type @CC, @CC(%D) [symbolic]
// CHECK:STDOUT: %Destroy.impl_witness.520: <witness> = impl_witness @CC.%Destroy.impl_witness_table, @CC.as.Destroy.impl(%D) [symbolic]
// CHECK:STDOUT: %ptr.791: type = ptr_type %CC.ef8 [symbolic]
// CHECK:STDOUT: %pattern_type.931: type = pattern_type %ptr.791 [symbolic]
// CHECK:STDOUT: %CC.as.Destroy.impl.Op.type: type = fn_type @CC.as.Destroy.impl.Op, @CC.as.Destroy.impl(%D) [symbolic]
// CHECK:STDOUT: %CC.as.Destroy.impl.Op: %CC.as.Destroy.impl.Op.type = struct_value () [symbolic]
// CHECK:STDOUT: %Z.type: type = facet_type <@Z> [concrete]
// CHECK:STDOUT: %Self.1d7: %Z.type = bind_symbolic_name Self, 0 [symbolic]
// CHECK:STDOUT: %BitAndWith.type.f2e: type = generic_interface_type @BitAndWith [concrete]
@@ -99,12 +87,10 @@ fn F() {
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
// CHECK:STDOUT: .Destroy = %Core.Destroy
// CHECK:STDOUT: .BitAndWith = %Core.BitAndWith
// CHECK:STDOUT: import Core//prelude
// CHECK:STDOUT: import Core//prelude/...
// CHECK:STDOUT: }
// CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
// CHECK:STDOUT: %Core.BitAndWith: %BitAndWith.type.f2e = import_ref Core//prelude/parts/as, BitAndWith, loaded [concrete = constants.%BitAndWith.generic]
// CHECK:STDOUT: %Core.import_ref.636: %type.as.BitAndWith.impl.Op.type = import_ref Core//prelude/parts/as, loc25_42, loaded [concrete = constants.%type.as.BitAndWith.impl.Op]
// CHECK:STDOUT: %BitAndWith.impl_witness_table = impl_witness_table (%Core.import_ref.636), @type.as.BitAndWith.impl [concrete]
@@ -197,22 +183,6 @@ fn F() {
// CHECK:STDOUT: witness = ()
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: impl @DD.as.Destroy.impl: @DD.%Self.ref as constants.%Destroy.type {
// CHECK:STDOUT: %DD.as.Destroy.impl.Op.decl: %DD.as.Destroy.impl.Op.type = fn_decl @DD.as.Destroy.impl.Op [concrete = constants.%DD.as.Destroy.impl.Op] {
// CHECK:STDOUT: %self.patt: %pattern_type.3fc = binding_pattern self [concrete]
// CHECK:STDOUT: %self.param_patt: %pattern_type.3fc = 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.3d1 = value_param call_param0
// CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%DD [concrete = constants.%DD]
// CHECK:STDOUT: %self: %ptr.3d1 = bind_name self, %self.param
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Op = %DD.as.Destroy.impl.Op.decl
// CHECK:STDOUT: witness = @DD.%Destroy.impl_witness
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: impl @DD.as.Y.impl: %DD.ref as %Y.ref {
// CHECK:STDOUT: !members:
// CHECK:STDOUT: witness = file.%Y.impl_witness
@@ -223,35 +193,6 @@ fn F() {
// CHECK:STDOUT: witness = file.%W.impl_witness
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: generic impl @CC.as.Destroy.impl(@CC.%D.loc12_10.2: %Y.type) {
// CHECK:STDOUT: %D: %Y.type = bind_symbolic_name D, 0 [symbolic = %D (constants.%D)]
// CHECK:STDOUT: %CC: type = class_type @CC, @CC(%D) [symbolic = %CC (constants.%CC.ef8)]
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness @CC.%Destroy.impl_witness_table, @CC.as.Destroy.impl(%D) [symbolic = %Destroy.impl_witness (constants.%Destroy.impl_witness.520)]
// CHECK:STDOUT:
// CHECK:STDOUT: !definition:
// CHECK:STDOUT: %CC.as.Destroy.impl.Op.type: type = fn_type @CC.as.Destroy.impl.Op, @CC.as.Destroy.impl(%D) [symbolic = %CC.as.Destroy.impl.Op.type (constants.%CC.as.Destroy.impl.Op.type)]
// CHECK:STDOUT: %CC.as.Destroy.impl.Op: @CC.as.Destroy.impl.%CC.as.Destroy.impl.Op.type (%CC.as.Destroy.impl.Op.type) = struct_value () [symbolic = %CC.as.Destroy.impl.Op (constants.%CC.as.Destroy.impl.Op)]
// CHECK:STDOUT:
// CHECK:STDOUT: impl: @CC.%Self.ref as constants.%Destroy.type {
// CHECK:STDOUT: %CC.as.Destroy.impl.Op.decl: @CC.as.Destroy.impl.%CC.as.Destroy.impl.Op.type (%CC.as.Destroy.impl.Op.type) = fn_decl @CC.as.Destroy.impl.Op [symbolic = @CC.as.Destroy.impl.%CC.as.Destroy.impl.Op (constants.%CC.as.Destroy.impl.Op)] {
// CHECK:STDOUT: %self.patt: @CC.as.Destroy.impl.Op.%pattern_type (%pattern_type.931) = binding_pattern self [concrete]
// CHECK:STDOUT: %self.param_patt: @CC.as.Destroy.impl.Op.%pattern_type (%pattern_type.931) = value_param_pattern %self.patt, call_param0 [concrete]
// CHECK:STDOUT: %.loc12_17.1: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %self.param: @CC.as.Destroy.impl.Op.%ptr (%ptr.791) = value_param call_param0
// CHECK:STDOUT: %.loc12_17.2: type = splice_block %Self.ref [symbolic = %CC (constants.%CC.ef8)] {
// CHECK:STDOUT: %.loc12_17.3: type = specific_constant constants.%CC.ef8, @CC(constants.%D) [symbolic = %CC (constants.%CC.ef8)]
// CHECK:STDOUT: %Self.ref: type = name_ref Self, %.loc12_17.3 [symbolic = %CC (constants.%CC.ef8)]
// CHECK:STDOUT: }
// CHECK:STDOUT: %self: @CC.as.Destroy.impl.Op.%ptr (%ptr.791) = bind_name self, %self.param
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Op = %CC.as.Destroy.impl.Op.decl
// CHECK:STDOUT: witness = @CC.%Destroy.impl_witness
// CHECK:STDOUT: }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: generic impl @CC.as.Z.impl(%E.loc19_14.1: %facet_type) {
// CHECK:STDOUT: %E.loc19_14.2: %facet_type = bind_symbolic_name E, 0 [symbolic = %E.loc19_14.2 (constants.%E)]
// CHECK:STDOUT: %Y.lookup_impl_witness: <witness> = lookup_impl_witness %E.loc19_14.2, @Y [symbolic = %Y.lookup_impl_witness (constants.%Y.lookup_impl_witness)]
@@ -269,10 +210,6 @@ fn F() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @DD {
// CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%DD [concrete = constants.%DD]
// CHECK:STDOUT: impl_decl @DD.as.Destroy.impl [concrete] {} {}
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@DD.as.Destroy.impl.%DD.as.Destroy.impl.Op.decl), @DD.as.Destroy.impl [concrete]
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.31d]
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
// CHECK:STDOUT: complete_type_witness = %complete_type
// CHECK:STDOUT:
@@ -286,10 +223,6 @@ fn F() {
// CHECK:STDOUT: !definition:
// CHECK:STDOUT:
// CHECK:STDOUT: class {
// CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%CC.ef8 [symbolic = @CC.as.Destroy.impl.%CC (constants.%CC.ef8)]
// CHECK:STDOUT: impl_decl @CC.as.Destroy.impl [concrete] {} {}
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@CC.as.Destroy.impl.%CC.as.Destroy.impl.Op.decl), @CC.as.Destroy.impl [concrete]
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table, @CC.as.Destroy.impl(constants.%D) [symbolic = @CC.as.Destroy.impl.%Destroy.impl_witness (constants.%Destroy.impl_witness.520)]
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
// CHECK:STDOUT: complete_type_witness = %complete_type
// CHECK:STDOUT:
@@ -298,19 +231,6 @@ fn F() {
// CHECK:STDOUT: }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @DD.as.Destroy.impl.Op(%self.param: %ptr.3d1) = "no_op";
// CHECK:STDOUT:
// CHECK:STDOUT: generic fn @CC.as.Destroy.impl.Op(@CC.%D.loc12_10.2: %Y.type) {
// CHECK:STDOUT: %D: %Y.type = bind_symbolic_name D, 0 [symbolic = %D (constants.%D)]
// CHECK:STDOUT: %CC: type = class_type @CC, @CC(%D) [symbolic = %CC (constants.%CC.ef8)]
// CHECK:STDOUT: %ptr: type = ptr_type %CC [symbolic = %ptr (constants.%ptr.791)]
// CHECK:STDOUT: %pattern_type: type = pattern_type %ptr [symbolic = %pattern_type (constants.%pattern_type.931)]
// CHECK:STDOUT:
// CHECK:STDOUT: !definition:
// CHECK:STDOUT:
// CHECK:STDOUT: fn(%self.param: @CC.as.Destroy.impl.Op.%ptr (%ptr.791)) = "no_op";
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %CC.ref: %CC.type = name_ref CC, file.%CC.decl [concrete = constants.%CC.generic]
@@ -330,19 +250,6 @@ fn F() {
// CHECK:STDOUT: %D.loc12_10.1 => constants.%D
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @CC.as.Destroy.impl(constants.%D) {
// CHECK:STDOUT: %D => constants.%D
// CHECK:STDOUT: %CC => constants.%CC.ef8
// CHECK:STDOUT: %Destroy.impl_witness => constants.%Destroy.impl_witness.520
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @CC.as.Destroy.impl.Op(constants.%D) {
// CHECK:STDOUT: %D => constants.%D
// CHECK:STDOUT: %CC => constants.%CC.ef8
// CHECK:STDOUT: %ptr => constants.%ptr.791
// CHECK:STDOUT: %pattern_type => constants.%pattern_type.931
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @CC(constants.%Y.facet.682) {
// CHECK:STDOUT: %D.loc12_10.1 => constants.%Y.facet.682
// CHECK:STDOUT: }