// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -target %target-swift-5.1-abi-triple | %FileCheck %s // REQUIRES: objc_interop // REQUIRES: concurrency import gizmo // Although we don't ever expose initializers and methods of generic classes // to ObjC yet, a generic subclass of an ObjC class must still use ObjC // deallocation. // CHECK-NOT: sil hidden [ossa] @$sSo7GenericCfd // CHECK-NOT: sil hidden [ossa] @$sSo8NSObjectCfd class Generic: NSObject, ObjCProtocol { var x: Int = 10 // CHECK-LABEL: sil private [thunk] [ossa] @$s18objc_generic_class7GenericC5evokeyyFTo : $@convention(objc_method) (Generic) -> () { // CHECK: [[FN:%.*]] = function_ref @$s18objc_generic_class7GenericC5evokeyyF // CHECK-NEXT: apply [[FN]] func evoke() {} // CHECK-LABEL: sil private [thunk] [ossa] @$s18objc_generic_class7GenericC10evokeAsyncyyYaFTo : $@convention(objc_method) (@convention(block) () -> (), Generic) -> () { // CHECK: [[FN:%.*]] = function_ref @$s18objc_generic_class7GenericC10evokeAsyncyyYaFyyYacfU_To // CHECK-NEXT: partial_apply [callee_guaranteed] [[FN]] // CHECK-LABEL: sil shared [thunk] [ossa] @$s18objc_generic_class7GenericC10evokeAsyncyyYaFyyYacfU_To : $@convention(thin) @Sendable @async (@convention(block) () -> (), Generic) -> () // CHECK: [[FN:%.*]] = function_ref @$s18objc_generic_class7GenericC10evokeAsyncyyYaF : $@convention(method) @async <τ_0_0> (@guaranteed Generic<τ_0_0>) -> () // CHECK-NEXT: apply [[FN]] func evokeAsync() async {} // CHECK-LABEL: sil hidden [ossa] @$s18objc_generic_class7GenericCfD : $@convention(method) (@owned Generic) -> () { // CHECK: bb0({{%.*}} : @owned $Generic): // CHECK: } // end sil function '$s18objc_generic_class7GenericCfD' // CHECK-LABEL: sil private [thunk] [ossa] @$s18objc_generic_class7GenericCfDTo : $@convention(objc_method) (Generic) -> () { // CHECK: bb0([[SELF:%.*]] : @unowned $Generic): // CHECK: [[SELF_COPY:%.*]] = copy_value [[SELF]] // CHECK: [[NATIVE:%.*]] = function_ref @$s18objc_generic_class7GenericCfD // CHECK: apply [[NATIVE]]([[SELF_COPY]]) // CHECK: } // end sil function '$s18objc_generic_class7GenericCfDTo' deinit { // Don't blow up when 'self' is referenced inside an @objc deinit method // of a generic class. self.x = 0 } } // CHECK-NOT: sil hidden [ossa] @$s18objc_generic_class7GenericCfd // CHECK-NOT: sil hidden [ossa] @$sSo8NSObjectCfd @objc protocol ObjCProtocol { func evoke() func evokeAsync() async } // CHECK-LABEL: sil hidden [ossa] @$s18objc_generic_class11SubGeneric1CfD : $@convention(method) (@owned SubGeneric1) -> () { // CHECK: bb0([[SELF:%.*]] : @owned $SubGeneric1): // CHECK: [[SUPER_DEALLOC:%.*]] = objc_super_method [[SELF]] : $SubGeneric1, #Generic.deinit!deallocator.foreign : (Generic) -> () -> (), $@convention(objc_method) <τ_0_0> (Generic<τ_0_0>) -> () // CHECK: [[SUPER:%.*]] = upcast [[SELF:%.*]] : $SubGeneric1 to $Generic // CHECK: apply [[SUPER_DEALLOC]]([[SUPER]]) class SubGeneric1: Generic { } // Ensure that the verifier doesn't reject @objc functions where all of the // generic parameters have been same-typed to concrete types. public struct GenericStruct { } public extension GenericStruct where T == String { public class Y { @objc public func f() -> String { "hello" } } } // rdar://129187133 - handle generic @objc thunks properly actor GenericActor : SendableObjCProtocol { // CHECK-LABEL: sil private [thunk] [ossa] @$s18objc_generic_class12GenericActorC10evokeAsyncyyYaFTo : $@convention(objc_method) (@convention(block) () -> (), @sil_isolated GenericActor) -> () // CHECK: [[FN:%.*]] = function_ref @$s18objc_generic_class12GenericActorC10evokeAsyncyyYaFyyYacfU_To : $@convention(thin) @Sendable @async <τ_0_0> (@convention(block) () -> (), @sil_isolated GenericActor<τ_0_0>) -> () // CHECK-NEXT: partial_apply [callee_guaranteed] [[FN]] func evokeAsync() async {} // CHECK-LABEL: sil shared [thunk] [ossa] @$s18objc_generic_class12GenericActorC10evokeAsyncyyYaFyyYacfU_To : $@convention(thin) @Sendable @async (@convention(block) () -> (), @sil_isolated GenericActor) -> () // CHECK: [[FN:%.*]] = function_ref @$s18objc_generic_class12GenericActorC10evokeAsyncyyYaF : $@convention(method) @async <τ_0_0> (@sil_isolated @guaranteed GenericActor<τ_0_0>) -> () // CHECK-NEXT: apply [[FN]] } @objc protocol SendableObjCProtocol : Sendable { func evokeAsync() async }