@@ -8,6 +8,8 @@ import Builtin
8
8
import Swift
9
9
import SwiftShims
10
10
11
+ import Foundation
12
+
11
13
@objc(XX) protocol X {
12
14
}
13
15
@@ -115,3 +117,48 @@ bb0(%0 : $T):
115
117
strong_release %0 : $T
116
118
return %3 : $@thick T.Type
117
119
}
120
+
121
+ // CHECK-LABEL: sil @$test_peephole_objc_to_thick_to_objc :
122
+ // CHECK: [[T:%.*]] = apply
123
+ // CHECK-NOT: objc_to_thick_metatype
124
+ // CHECK-NOT: thick_to_objc_metatype
125
+ // CHECK: enum $Optional<@objc_metatype AnyObject.Type>, #Optional.some!enumelt, [[T]] : $@objc_metatype AnyObject.Type
126
+ // CHECK: } // end sil function '$test_peephole_objc_to_thick_to_objc'
127
+
128
+ sil @$test_peephole_objc_to_thick_to_objc : $@convention(thin) (@guaranteed NSObject) -> Optional<UnsafeMutablePointer<OpaquePointer>> {
129
+ // %0 "obj" // users: %3, %2, %1
130
+ bb0(%0 : $NSObject):
131
+ debug_value %0 : $NSObject, let, name "obj", argno 1 // id: %1
132
+ %2 = objc_method %0 : $NSObject, #NSObject.classForCoder!getter.foreign : (NSObject) -> () -> AnyObject.Type, $@convention(objc_method) (NSObject) -> @objc_metatype AnyObject.Type // user: %3
133
+ %3 = apply %2(%0) : $@convention(objc_method) (NSObject) -> @objc_metatype AnyObject.Type // user: %4
134
+ %4 = objc_to_thick_metatype %3 : $@objc_metatype AnyObject.Type to $@thick AnyObject.Type // users: %6, %5
135
+ debug_value %4 : $@thick AnyObject.Type, let, name "c" // id: %5
136
+ %6 = thick_to_objc_metatype %4 : $@thick AnyObject.Type to $@objc_metatype AnyObject.Type // user: %7
137
+ %7 = enum $Optional<@objc_metatype AnyObject.Type>, #Optional.some!enumelt, %6 : $@objc_metatype AnyObject.Type // user: %10
138
+ %8 = enum $Optional<UnsafeMutablePointer<UInt32>>, #Optional.none!enumelt // user: %10
139
+ // function_ref class_copyMethodList
140
+ %9 = function_ref @class_copyMethodList : $@convention(c) (Optional<@objc_metatype AnyObject.Type>, Optional<UnsafeMutablePointer<UInt32>>) -> Optional<UnsafeMutablePointer<OpaquePointer>> // user: %10
141
+ %10 = apply %9(%7, %8) : $@convention(c) (Optional<@objc_metatype AnyObject.Type>, Optional<UnsafeMutablePointer<UInt32>>) -> Optional<UnsafeMutablePointer<OpaquePointer>> // users: %12, %11
142
+ debug_value %10 : $Optional<UnsafeMutablePointer<OpaquePointer>>, let, name "l" // id: %11
143
+ return %10 : $Optional<UnsafeMutablePointer<OpaquePointer>> // id: %12
144
+ }
145
+
146
+ // CHECK-LABEL: sil @$test_peephole_thick_to_objc_to_thick :
147
+ // CHECK: [[T:%.*]] = apply
148
+ // CHECK-NOT: thick_to_objc_metatype
149
+ // CHECK-NOT: objc_to_thick_metatype
150
+ // CHECK: return [[T]]
151
+ // CHECK: } // end sil function '$test_peephole_thick_to_objc_to_thick'
152
+
153
+ sil @$test_peephole_thick_to_objc_to_thick : $@convention(thin) (@guaranteed AnyObject) -> @thick AnyObject.Type {
154
+ bb0(%0 : $AnyObject):
155
+ %func = function_ref @foo : $@convention(thin) (@guaranteed AnyObject) -> @thick AnyObject.Type
156
+ %res = apply %func(%0) : $@convention(thin) (@guaranteed AnyObject) -> @thick AnyObject.Type
157
+ %objctype = thick_to_objc_metatype %res : $@thick AnyObject.Type to $@objc_metatype AnyObject.Type
158
+ %thicktype = objc_to_thick_metatype %objctype : $@objc_metatype AnyObject.Type to $@thick AnyObject.Type
159
+ return %thicktype : $@thick AnyObject.Type
160
+ }
161
+
162
+ // class_copyMethodList
163
+ sil [serializable] [clang class_copyMethodList] @class_copyMethodList : $@convention(c) (Optional<@objc_metatype AnyObject.Type>, Optional<UnsafeMutablePointer<UInt32>>) -> Optional<UnsafeMutablePointer<OpaquePointer>>
164
+ sil [serializable] @foo : $@convention(thin) (@guaranteed AnyObject) -> @thick AnyObject.Type
0 commit comments