mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The SIL parser used PolymorphicFunctionType in two places: - Internals of SILFunctionType parsing - Overload selection for class_method / super_method / dynamic_method instructions It is better to have Sema construct GenericFunctionType directly in SIL mode. In particular, the overload selection logic is simpler now, since it does not have to deal with the fact that PolymorphicFunctionTypes do not canonicalize. Mostly NFC, except the SIL printer output is a bit different; for a generic method on a generic type, the type parameters all come first, like ``<T><U> G<T> -> (U) -> ()'' -vs- ``<T> G<T> -> <U> (U) -> ()''. Also, generic constraints look different, instead of ``<`Self` : P>`` we now have ``<Self where Self : P>''. This patch has two consequences that will become important later: - While code that constructs PolymorphicFunctionType still exists in Sema, the SIL parser was the last major component that *consumed* PolymorphicFunctionType. - Everywhere we set SILFunction::ContextGenericParams, we now have a well-formed context GenericSignature available, allowing ContextGenericParams to be replaced by a GenericSignature eventually.
41 lines
1.8 KiB
Swift
41 lines
1.8 KiB
Swift
// RUN: %target-swift-frontend -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -emit-silgen | FileCheck %s
|
|
|
|
// REQUIRES: objc_interop
|
|
|
|
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 @_TFCSo7Genericd
|
|
// CHECK-NOT: sil hidden @_TFCSo8NSObjectd
|
|
|
|
class Generic<T>: NSObject {
|
|
var x: Int = 10
|
|
|
|
// CHECK-LABEL: sil hidden @_TFC18objc_generic_class7GenericD : $@convention(method) <T> (@owned Generic<T>) -> () {
|
|
// CHECK: bb0({{%.*}} : $Generic<T>):
|
|
// CHECK-LABEL: sil hidden [thunk] @_TToFC18objc_generic_class7GenericD : $@convention(objc_method) <T> (Generic<T>) -> () {
|
|
// CHECK: bb0([[SELF:%.*]] : $Generic<T>):
|
|
// CHECK: [[NATIVE:%.*]] = function_ref @_TFC18objc_generic_class7GenericD
|
|
// CHECK: apply [[NATIVE]]<T>([[SELF]])
|
|
deinit {
|
|
// Don't blow up when 'self' is referenced inside an @objc deinit method
|
|
// of a generic class. <rdar://problem/16325525>
|
|
self.x = 0
|
|
}
|
|
}
|
|
|
|
// CHECK-NOT: sil hidden @_TFC18objc_generic_class7Genericd
|
|
// CHECK-NOT: sil hidden @_TFCSo8NSObjectd
|
|
|
|
// CHECK-LABEL: sil hidden @_TFC18objc_generic_class11SubGeneric1D : $@convention(method) <U, V> (@owned SubGeneric1<U, V>) -> () {
|
|
// CHECK: bb0([[SELF:%.*]] : $SubGeneric1<U, V>):
|
|
// CHECK: [[SUPER_DEALLOC:%.*]] = super_method [[SELF]] : $SubGeneric1<U, V>, #Generic.deinit!deallocator.foreign : <T> Generic<T> -> () -> () , $@convention(objc_method) <τ_0_0> (Generic<τ_0_0>) -> ()
|
|
// CHECK: [[SUPER:%.*]] = upcast [[SELF:%.*]] : $SubGeneric1<U, V> to $Generic<Int>
|
|
// CHECK: apply [[SUPER_DEALLOC]]<Int>([[SUPER]])
|
|
class SubGeneric1<U, V>: Generic<Int> {
|
|
}
|
|
|