mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
163 lines
6.4 KiB
Plaintext
163 lines
6.4 KiB
Plaintext
// RUN: %target-sil-opt -enable-objc-interop -enable-sil-verify-all %s -devirtualizer | %FileCheck %s
|
|
|
|
sil_stage canonical
|
|
|
|
import Builtin
|
|
import Swift
|
|
import SwiftShims
|
|
|
|
class K {
|
|
func ping() -> Int
|
|
private func pong() -> Int
|
|
@objc deinit
|
|
init()
|
|
}
|
|
|
|
//CHECK-LABEL: _TFC4test1K4pingfS0_FT_Si
|
|
//CHECK: function_ref @_TFC4test1K4pongfS0_FT_Si
|
|
//CHECK-NEXT: apply
|
|
//CHECK-NEXT: return
|
|
sil [ossa] @_TFC4test1K4pingfS0_FT_Si : $@convention(method) (@guaranteed K) -> Int {
|
|
bb0(%0 : @guaranteed $K):
|
|
%1 = class_method %0 : $K, #K.pong : (K) -> () -> Int, $@convention(method) (@guaranteed K) -> Int // user: %2
|
|
%2 = apply %1(%0) : $@convention(method) (@guaranteed K) -> Int // user: %3
|
|
return %2 : $Int // id: %3
|
|
}
|
|
|
|
sil @_TFC5test21K4pongfS0_FT_Si : $@convention(method) (@guaranteed K) -> Int
|
|
sil @_TFC4test1K4pongfS0_FT_Si : $@convention(method) (@guaranteed K) -> Int
|
|
sil @_TFC4test1Kd : $@convention(method) (@guaranteed K) -> @owned Builtin.NativeObject
|
|
sil @_TFC4test1KD : $@convention(method) (@guaranteed K) -> ()
|
|
sil @_TFC4test1KcfMS0_FT_S0_ : $@convention(method) (@owned K) -> @owned K
|
|
sil @_TFC4test1KCfMS0_FT_S0_ : $@convention(thin) (@thick K.Type) -> @owned K
|
|
|
|
sil_vtable K {
|
|
#K.ping: @_TFC4test1K4pingfS0_FT_Si // test.K.ping (test.K)() -> Swift.Int
|
|
#K.pong: @_TFC4test1K4pongfS0_FT_Si // test.K.pong (test.K)() -> Swift.Int
|
|
#K.init!initializer: @_TFC4test1KcfMS0_FT_S0_ // test.K.init (test.K.Type)() -> test.K
|
|
}
|
|
|
|
|
|
class X
|
|
{
|
|
private func ping() -> Int
|
|
@objc deinit
|
|
init()
|
|
}
|
|
|
|
class Y : X
|
|
{
|
|
@objc deinit
|
|
override init()
|
|
}
|
|
|
|
class A
|
|
{
|
|
private func ping() -> Int
|
|
@objc deinit
|
|
init()
|
|
}
|
|
|
|
class B : A
|
|
{
|
|
override func ping() -> Int
|
|
@objc deinit
|
|
override init()
|
|
}
|
|
|
|
sil @_TFC14devirt_access21X4pingfS0_FT_Si : $@convention(method) (@guaranteed X) -> Int
|
|
sil public_external [transparent] @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBI_Si : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int
|
|
sil @_TFC14devirt_access21Xd : $@convention(method) (@guaranteed X) -> @owned Builtin.NativeObject
|
|
sil @_TFC14devirt_access21XD : $@convention(method) (@guaranteed X) -> ()
|
|
sil @_TFC14devirt_access21XcfMS0_FT_S0_ : $@convention(method) (@owned X) -> @owned X
|
|
sil @_TFC14devirt_access21XCfMS0_FT_S0_ : $@convention(thin) (@thick X.Type) -> @owned X
|
|
sil @_TFC14devirt_access21Yd : $@convention(method) (@guaranteed Y) -> @owned Builtin.NativeObject
|
|
sil @_TFC14devirt_access21YD : $@convention(method) (@guaranteed Y) -> ()
|
|
sil @_TFC14devirt_access21YcfMS0_FT_S0_ : $@convention(method) (@owned Y) -> @owned Y
|
|
sil @_TFC14devirt_access21YCfMS0_FT_S0_ : $@convention(thin) (@thick Y.Type) -> @owned Y
|
|
sil @_TFC14devirt_access21A4pingfS0_FT_Si : $@convention(method) (@guaranteed A) -> Int
|
|
sil @_TFC14devirt_access21Ad : $@convention(method) (@guaranteed A) -> @owned Builtin.NativeObject
|
|
sil @_TFC14devirt_access21AD : $@convention(method) (@guaranteed A) -> ()
|
|
sil @_TFC14devirt_access21AcfMS0_FT_S0_ : $@convention(method) (@owned A) -> @owned A
|
|
sil @_TFC14devirt_access21ACfMS0_FT_S0_ : $@convention(thin) (@thick A.Type) -> @owned A
|
|
sil @_TFC14devirt_access21B4pingfS0_FT_Si : $@convention(method) (@guaranteed B) -> Int
|
|
sil @_TFC14devirt_access21Bd : $@convention(method) (@guaranteed B) -> @owned Builtin.NativeObject
|
|
sil @_TFC14devirt_access21BD : $@convention(method) (@guaranteed B) -> ()
|
|
sil @_TFC14devirt_access21BcfMS0_FT_S0_ : $@convention(method) (@owned B) -> @owned B
|
|
sil @_TFC14devirt_access21BCfMS0_FT_S0_ : $@convention(thin) (@thick B.Type) -> @owned B
|
|
|
|
// CHECK-LABEL: sil [ossa] @Case1 :
|
|
// CHECK: [[FUNC:%.*]] = function_ref @_TFC14devirt_access21X4pingfS0_FT_Si :
|
|
// CHECK: apply [[FUNC]](
|
|
// CHECK: } // end sil function 'Case1'
|
|
sil [ossa] @Case1 : $@convention(thin) (@owned X) -> Int {
|
|
bb0(%0 : @owned $X):
|
|
%1 = copy_value %0 : $X
|
|
%3 = class_method %1 : $X, #X.ping : (X) -> () -> Int, $@convention(method) (@guaranteed X) -> Int
|
|
%4 = apply %3(%1) : $@convention(method) (@guaranteed X) -> Int // user: %6
|
|
destroy_value %1 : $X
|
|
destroy_value %0 : $X
|
|
return %4 : $Int
|
|
}
|
|
|
|
//CHECK-LABEL: sil [ossa] @Case2
|
|
//CHECK: function_ref @_TFC14devirt_access21X4pingfS0_FT_Si
|
|
// Y is an internal class, it has no subclasses and it is a wmo compilation,
|
|
// therefore ping method invocation can be devirtualized.
|
|
//CHECK-NOT: class_method
|
|
//CHECK: apply
|
|
//CHECK-NOT: class_method
|
|
//CHECK: return
|
|
sil [ossa] @Case2 : $@convention(thin) (@owned Y) -> Int {
|
|
bb0(%0 : @owned $Y):
|
|
%1 = copy_value %0 : $Y
|
|
%3 = upcast %1 : $Y to $X
|
|
%4 = class_method %3 : $X, #X.ping : (X) -> () -> Int, $@convention(method) (@guaranteed X) -> Int
|
|
%5 = apply %4(%3) : $@convention(method) (@guaranteed X) -> Int
|
|
destroy_value %3 : $X
|
|
destroy_value %0 : $Y
|
|
return %5 : $Int
|
|
}
|
|
|
|
//CHECK-LABEL: sil [ossa] @Case3
|
|
//CHECK: class_method
|
|
//CHECK: return
|
|
sil [ossa] @Case3 : $@convention(thin) (@owned A) -> Int {
|
|
bb0(%0 : @owned $A):
|
|
%3 = class_method %0 : $A, #A.ping : (A) -> () -> Int, $@convention(method) (@guaranteed A) -> Int
|
|
%4 = apply %3(%0) : $@convention(method) (@guaranteed A) -> Int
|
|
destroy_value %0 : $A
|
|
return %4 : $Int
|
|
}
|
|
|
|
//CHECK-LABEL: sil [ossa] @Case4
|
|
//CHECK: class_method
|
|
//CHECK: return
|
|
sil [ossa] @Case4 : $@convention(thin) (@owned B) -> Int {
|
|
bb0(%0 : @owned $B):
|
|
%3 = class_method %0 : $B, #B.ping : (B) -> () -> Int, $@convention(method) (@guaranteed B) -> Int
|
|
%4 = apply %3(%0) : $@convention(method) (@guaranteed B) -> Int
|
|
destroy_value %0 : $B
|
|
return %4 : $Int
|
|
}
|
|
|
|
sil_vtable X {
|
|
#X.ping: @_TFC14devirt_access21X4pingfS0_FT_Si // devirt_access2.X.ping (devirt_access2.X)() -> Swift.Int
|
|
#X.init!initializer: @_TFC14devirt_access21XcfMS0_FT_S0_ // devirt_access2.X.init (devirt_access2.X.Type)() -> devirt_access2.X
|
|
}
|
|
|
|
sil_vtable Y {
|
|
#X.ping: @_TFC14devirt_access21X4pingfS0_FT_Si // devirt_access2.X.ping (devirt_access2.X)() -> Swift.Int
|
|
#X.init!initializer: @_TFC14devirt_access21YcfMS0_FT_S0_ // devirt_access2.Y.init (devirt_access2.Y.Type)() -> devirt_access2.Y
|
|
}
|
|
|
|
sil_vtable A {
|
|
#A.ping: @_TFC14devirt_access21A4pingfS0_FT_Si // devirt_access2.A.ping (devirt_access2.A)() -> Swift.Int
|
|
#A.init!initializer: @_TFC14devirt_access21AcfMS0_FT_S0_ // devirt_access2.A.init (devirt_access2.A.Type)() -> devirt_access2.A
|
|
}
|
|
|
|
sil_vtable B {
|
|
#A.ping: @_TFC14devirt_access21B4pingfS0_FT_Si // devirt_access2.B.ping (devirt_access2.B)() -> Swift.Int
|
|
#A.init!initializer: @_TFC14devirt_access21BcfMS0_FT_S0_ // devirt_access2.B.init (devirt_access2.B.Type)() -> devirt_access2.B
|
|
}
|