mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 15:51:07 +01:00
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:
+31
-73
@@ -105,24 +105,15 @@ fn CallFAndGIncomplete() {
|
||||
// CHECK:STDOUT: %ReturnDUsed: %ReturnDUsed.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %Call.type: type = fn_type @Call [concrete]
|
||||
// CHECK:STDOUT: %Call: %Call.type = struct_value () [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 @D.%Destroy.impl_witness_table [concrete]
|
||||
// CHECK:STDOUT: %ptr.19c: type = ptr_type %D [concrete]
|
||||
// CHECK:STDOUT: %pattern_type.a94: type = pattern_type %ptr.19c [concrete]
|
||||
// CHECK:STDOUT: %D.as.Destroy.impl.Op.type: type = fn_type @D.as.Destroy.impl.Op [concrete]
|
||||
// CHECK:STDOUT: %D.as.Destroy.impl.Op: %D.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: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
|
||||
// CHECK:STDOUT: .Destroy = %Core.Destroy
|
||||
// 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: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
@@ -175,29 +166,9 @@ fn CallFAndGIncomplete() {
|
||||
// CHECK:STDOUT: %D.decl.loc37: type = class_decl @D [concrete = constants.%D] {} {}
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: impl @D.as.Destroy.impl: @D.%Self.ref as constants.%Destroy.type {
|
||||
// CHECK:STDOUT: %D.as.Destroy.impl.Op.decl: %D.as.Destroy.impl.Op.type = fn_decl @D.as.Destroy.impl.Op [concrete = constants.%D.as.Destroy.impl.Op] {
|
||||
// CHECK:STDOUT: %self.patt: %pattern_type.a94 = binding_pattern self [concrete]
|
||||
// CHECK:STDOUT: %self.param_patt: %pattern_type.a94 = value_param_pattern %self.patt, call_param0 [concrete]
|
||||
// CHECK:STDOUT: %.loc37: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
|
||||
// CHECK:STDOUT: } {
|
||||
// CHECK:STDOUT: %self.param: %ptr.19c = value_param call_param0
|
||||
// CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%D [concrete = constants.%D]
|
||||
// CHECK:STDOUT: %self: %ptr.19c = bind_name self, %self.param
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !members:
|
||||
// CHECK:STDOUT: .Op = %D.as.Destroy.impl.Op.decl
|
||||
// CHECK:STDOUT: witness = @D.%Destroy.impl_witness
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: class @C;
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: class @D {
|
||||
// CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%D [concrete = constants.%D]
|
||||
// CHECK:STDOUT: impl_decl @D.as.Destroy.impl [concrete] {} {}
|
||||
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@D.as.Destroy.impl.%D.as.Destroy.impl.Op.decl), @D.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.%empty_struct_type [concrete = constants.%complete_type]
|
||||
// CHECK:STDOUT: complete_type_witness = %complete_type
|
||||
// CHECK:STDOUT:
|
||||
@@ -222,8 +193,6 @@ fn CallFAndGIncomplete() {
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @D.as.Destroy.impl.Op(%self.param: %ptr.19c) = "no_op";
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- fail_use_imported.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
@@ -236,16 +205,18 @@ fn CallFAndGIncomplete() {
|
||||
// CHECK:STDOUT: %ReturnCUsed: %ReturnCUsed.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %ReturnDUnused.type: type = fn_type @ReturnDUnused [concrete]
|
||||
// CHECK:STDOUT: %ReturnDUnused: %ReturnDUnused.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %D.b3dde2.1: type = class_type @D.1 [concrete]
|
||||
// CHECK:STDOUT: %D: type = class_type @D [concrete]
|
||||
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
|
||||
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
|
||||
// CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
|
||||
// CHECK:STDOUT: %ReturnDUsed.type: type = fn_type @ReturnDUsed [concrete]
|
||||
// CHECK:STDOUT: %ReturnDUsed: %ReturnDUsed.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
|
||||
// CHECK:STDOUT: %Destroy.impl_witness.57e: <witness> = impl_witness imports.%Destroy.impl_witness_table.15e [concrete]
|
||||
// CHECK:STDOUT: %D.as.Destroy.impl.Op.type: type = fn_type @D.as.Destroy.impl.Op [concrete]
|
||||
// CHECK:STDOUT: %D.as.Destroy.impl.Op: %D.as.Destroy.impl.Op.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %ptr.19c: type = ptr_type %D.b3dde2.1 [concrete]
|
||||
// CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanAggregateDestroy>> [concrete]
|
||||
// CHECK:STDOUT: %facet_value: %type_where = facet_value %D, () [concrete]
|
||||
// CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.type.707: 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.34d: %AggregateT.as_type.as.Destroy.impl.Op.type.707 = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %ptr.19c: type = ptr_type %D [concrete]
|
||||
// CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.specific_fn: <specific function> = specific_function %AggregateT.as_type.as.Destroy.impl.Op.34d, @AggregateT.as_type.as.Destroy.impl.Op(%facet_value) [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
@@ -261,16 +232,9 @@ fn CallFAndGIncomplete() {
|
||||
// CHECK:STDOUT: import Core//prelude
|
||||
// CHECK:STDOUT: import Core//prelude/...
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %Main.import_ref.8f24d3.1: <witness> = import_ref Main//incomplete_return, loc37_10, loaded [concrete = constants.%complete_type]
|
||||
// CHECK:STDOUT: %Main.import_ref.cabe25.1 = import_ref Main//incomplete_return, inst20 [no loc], unloaded
|
||||
// CHECK:STDOUT: %Main.import_ref.8f2: <witness> = import_ref Main//incomplete_return, loc37_10, loaded [concrete = constants.%complete_type.357]
|
||||
// CHECK:STDOUT: %Main.import_ref.cab = import_ref Main//incomplete_return, inst20 [no loc], unloaded
|
||||
// CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
|
||||
// CHECK:STDOUT: %Main.import_ref.a28: <witness> = import_ref Main//incomplete_return, loc37_9, loaded [concrete = constants.%Destroy.impl_witness.57e]
|
||||
// CHECK:STDOUT: %Main.import_ref.8f24d3.2: <witness> = import_ref Main//incomplete_return, loc37_10, loaded [concrete = constants.%complete_type]
|
||||
// CHECK:STDOUT: %Main.import_ref.cabe25.2 = import_ref Main//incomplete_return, inst20 [no loc], unloaded
|
||||
// CHECK:STDOUT: %Main.import_ref.130: type = import_ref Main//incomplete_return, loc37_9, loaded [concrete = constants.%D.b3dde2.1]
|
||||
// CHECK:STDOUT: %Main.import_ref.e45: type = import_ref Main//incomplete_return, inst67 [no loc], loaded [concrete = constants.%Destroy.type]
|
||||
// CHECK:STDOUT: %Main.import_ref.ed1: %D.as.Destroy.impl.Op.type = import_ref Main//incomplete_return, loc37_9, loaded [concrete = constants.%D.as.Destroy.impl.Op]
|
||||
// CHECK:STDOUT: %Destroy.impl_witness_table.15e = impl_witness_table (%Main.import_ref.ed1), @D.as.Destroy.impl [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
@@ -290,25 +254,13 @@ fn CallFAndGIncomplete() {
|
||||
// CHECK:STDOUT: %CallFAndGIncomplete.decl: %CallFAndGIncomplete.type = fn_decl @CallFAndGIncomplete [concrete = constants.%CallFAndGIncomplete] {} {}
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: impl @D.as.Destroy.impl: imports.%Main.import_ref.130 as imports.%Main.import_ref.e45 [from "fail_incomplete_return.carbon"] {
|
||||
// CHECK:STDOUT: !members:
|
||||
// CHECK:STDOUT: witness = imports.%Main.import_ref.a28
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: class @C [from "fail_incomplete_return.carbon"];
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: class @D.1 [from "fail_incomplete_return.carbon"] {
|
||||
// CHECK:STDOUT: complete_type_witness = imports.%Main.import_ref.8f24d3.1
|
||||
// CHECK:STDOUT: class @D [from "fail_incomplete_return.carbon"] {
|
||||
// CHECK:STDOUT: complete_type_witness = imports.%Main.import_ref.8f2
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !members:
|
||||
// CHECK:STDOUT: .Self = imports.%Main.import_ref.cabe25.1
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: class @D.2 [from "fail_incomplete_return.carbon"] {
|
||||
// CHECK:STDOUT: complete_type_witness = imports.%Main.import_ref.8f24d3.2
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !members:
|
||||
// CHECK:STDOUT: .Self = imports.%Main.import_ref.cabe25.2
|
||||
// CHECK:STDOUT: .Self = imports.%Main.import_ref.cab
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @CallFAndGIncomplete() {
|
||||
@@ -318,19 +270,27 @@ fn CallFAndGIncomplete() {
|
||||
// CHECK:STDOUT: %ReturnCUsed.ref: %ReturnCUsed.type = name_ref ReturnCUsed, imports.%Main.ReturnCUsed [concrete = constants.%ReturnCUsed]
|
||||
// CHECK:STDOUT: %ReturnCUsed.call: init <error> = call %ReturnCUsed.ref()
|
||||
// CHECK:STDOUT: %ReturnDUnused.ref: %ReturnDUnused.type = name_ref ReturnDUnused, imports.%Main.ReturnDUnused [concrete = constants.%ReturnDUnused]
|
||||
// CHECK:STDOUT: %.loc33_17.1: ref %D.b3dde2.1 = temporary_storage
|
||||
// CHECK:STDOUT: %ReturnDUnused.call: init %D.b3dde2.1 = call %ReturnDUnused.ref() to %.loc33_17.1
|
||||
// CHECK:STDOUT: %.loc33_17.2: ref %D.b3dde2.1 = temporary %.loc33_17.1, %ReturnDUnused.call
|
||||
// CHECK:STDOUT: %.loc33_17.1: ref %D = temporary_storage
|
||||
// CHECK:STDOUT: %ReturnDUnused.call: init %D = call %ReturnDUnused.ref() to %.loc33_17.1
|
||||
// CHECK:STDOUT: %.loc33_17.2: ref %D = temporary %.loc33_17.1, %ReturnDUnused.call
|
||||
// CHECK:STDOUT: %ReturnDUsed.ref: %ReturnDUsed.type = name_ref ReturnDUsed, imports.%Main.ReturnDUsed [concrete = constants.%ReturnDUsed]
|
||||
// CHECK:STDOUT: %.loc34_15.1: ref %D.b3dde2.1 = temporary_storage
|
||||
// CHECK:STDOUT: %ReturnDUsed.call: init %D.b3dde2.1 = call %ReturnDUsed.ref() to %.loc34_15.1
|
||||
// CHECK:STDOUT: %.loc34_15.2: ref %D.b3dde2.1 = temporary %.loc34_15.1, %ReturnDUsed.call
|
||||
// CHECK:STDOUT: %D.as.Destroy.impl.Op.bound.loc34: <bound method> = bound_method %.loc34_15.2, constants.%D.as.Destroy.impl.Op
|
||||
// CHECK:STDOUT: %.loc34_15.1: ref %D = temporary_storage
|
||||
// CHECK:STDOUT: %ReturnDUsed.call: init %D = call %ReturnDUsed.ref() to %.loc34_15.1
|
||||
// CHECK:STDOUT: %.loc34_15.2: ref %D = temporary %.loc34_15.1, %ReturnDUsed.call
|
||||
// CHECK:STDOUT: %facet_value.loc34: %type_where = facet_value constants.%D, () [concrete = constants.%facet_value]
|
||||
// CHECK:STDOUT: %.loc34_15.3: %type_where = converted constants.%D, %facet_value.loc34 [concrete = constants.%facet_value]
|
||||
// CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound.loc34: <bound method> = bound_method %.loc34_15.2, constants.%AggregateT.as_type.as.Destroy.impl.Op.34d
|
||||
// CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.1: <specific function> = specific_function constants.%AggregateT.as_type.as.Destroy.impl.Op.34d, @AggregateT.as_type.as.Destroy.impl.Op(constants.%facet_value) [concrete = constants.%AggregateT.as_type.as.Destroy.impl.Op.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc34: <bound method> = bound_method %.loc34_15.2, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.1
|
||||
// CHECK:STDOUT: %addr.loc34: %ptr.19c = addr_of %.loc34_15.2
|
||||
// CHECK:STDOUT: %D.as.Destroy.impl.Op.call.loc34: init %empty_tuple.type = call %D.as.Destroy.impl.Op.bound.loc34(%addr.loc34)
|
||||
// CHECK:STDOUT: %D.as.Destroy.impl.Op.bound.loc33: <bound method> = bound_method %.loc33_17.2, constants.%D.as.Destroy.impl.Op
|
||||
// CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call.loc34: init %empty_tuple.type = call %bound_method.loc34(%addr.loc34)
|
||||
// CHECK:STDOUT: %facet_value.loc33: %type_where = facet_value constants.%D, () [concrete = constants.%facet_value]
|
||||
// CHECK:STDOUT: %.loc33_17.3: %type_where = converted constants.%D, %facet_value.loc33 [concrete = constants.%facet_value]
|
||||
// CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound.loc33: <bound method> = bound_method %.loc33_17.2, constants.%AggregateT.as_type.as.Destroy.impl.Op.34d
|
||||
// CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.2: <specific function> = specific_function constants.%AggregateT.as_type.as.Destroy.impl.Op.34d, @AggregateT.as_type.as.Destroy.impl.Op(constants.%facet_value) [concrete = constants.%AggregateT.as_type.as.Destroy.impl.Op.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc33: <bound method> = bound_method %.loc33_17.2, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.2
|
||||
// CHECK:STDOUT: %addr.loc33: %ptr.19c = addr_of %.loc33_17.2
|
||||
// CHECK:STDOUT: %D.as.Destroy.impl.Op.call.loc33: init %empty_tuple.type = call %D.as.Destroy.impl.Op.bound.loc33(%addr.loc33)
|
||||
// CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call.loc33: init %empty_tuple.type = call %bound_method.loc33(%addr.loc33)
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
@@ -342,5 +302,3 @@ fn CallFAndGIncomplete() {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @ReturnDUsed [from "fail_incomplete_return.carbon"];
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @D.as.Destroy.impl.Op = "no_op" [from "fail_incomplete_return.carbon"];
|
||||
// CHECK:STDOUT:
|
||||
|
||||
Reference in New Issue
Block a user