// RUN: %target-swift-frontend -emit-silgen -emit-verbose-sil %s | %FileCheck %s // CHECK-LABEL: @_specialize(exported: false, kind: full, where T == Int, U == Float) // CHECK-NEXT: func specializeThis(_ t: T, u: U) @_specialize(where T == Int, U == Float) func specializeThis(_ t: T, u: U) {} public protocol PP { associatedtype PElt } public protocol QQ { associatedtype QElt } public struct RR : PP { public typealias PElt = Float } public struct SS : QQ { public typealias QElt = Int } public struct GG {} // CHECK-LABEL: public class CC where T : PP { // CHECK-NEXT: @_specialize(exported: false, kind: full, where T == RR, U == SS) // CHECK-NEXT: @inline(never) public func foo(_ u: U, g: GG) -> (U, GG) where U : QQ public class CC { @inline(never) @_specialize(where T == RR, U == SS) public func foo(_ u: U, g: GG) -> (U, GG) { return (u, g) } } // CHECK-LABEL: sil hidden [_specialize exported: false, kind: full, where T == Int, U == Float] @_T015specialize_attr0A4Thisyx_q_1utr0_lF : $@convention(thin) (@in T, @in U) -> () { // CHECK-LABEL: sil [noinline] [_specialize exported: false, kind: full, where T == RR, U == SS] @_T015specialize_attr2CCC3fooqd___AA2GGVyxGtqd___AG1gtAA2QQRd__lF : $@convention(method) (@in U, GG, @guaranteed CC) -> (@out U, GG) { // ----------------------------------------------------------------------------- // Test user-specialized subscript accessors. public protocol TestSubscriptable { associatedtype Element subscript(i: Int) -> Element { get set } } public class ASubscriptable : TestSubscriptable { var storage: UnsafeMutablePointer init(capacity: Int) { storage = UnsafeMutablePointer.allocate(capacity: capacity) } public subscript(i: Int) -> Element { @_specialize(where Element == Int) get { return storage[i] } @_specialize(where Element == Int) set(rhs) { storage[i] = rhs } } } // ASubscriptable.subscript.getter with _specialize // CHECK-LABEL: sil [_specialize exported: false, kind: full, where Element == Int] @_T015specialize_attr14ASubscriptableC9subscriptxSicfg : $@convention(method) (Int, @guaranteed ASubscriptable) -> @out Element { // ASubscriptable.subscript.setter with _specialize // CHECK-LABEL: sil [_specialize exported: false, kind: full, where Element == Int] @_T015specialize_attr14ASubscriptableC9subscriptxSicfs : $@convention(method) (@in Element, Int, @guaranteed ASubscriptable) -> () { // ASubscriptable.subscript.materializeForSet with no attribute // CHECK-LABEL: sil [transparent] [serialized] @_T015specialize_attr14ASubscriptableC9subscriptxSicfm : $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, Int, @guaranteed ASubscriptable) -> (Builtin.RawPointer, Optional) { public class Addressable : TestSubscriptable { var storage: UnsafeMutablePointer init(capacity: Int) { storage = UnsafeMutablePointer.allocate(capacity: capacity) } public subscript(i: Int) -> Element { @_specialize(where Element == Int) unsafeAddress { return UnsafePointer(storage + i) } @_specialize(where Element == Int) unsafeMutableAddress { return UnsafeMutablePointer(storage + i) } } } // Addressable.subscript.getter with no attribute // CHECK-LABEL: sil [transparent] [serialized] @_T015specialize_attr11AddressableC9subscriptxSicfg : $@convention(method) (Int, @guaranteed Addressable) -> @out Element { // Addressable.subscript.unsafeAddressor with _specialize // CHECK-LABEL: sil [_specialize exported: false, kind: full, where Element == Int] @_T015specialize_attr11AddressableC9subscriptxSicflu : $@convention(method) (Int, @guaranteed Addressable) -> UnsafePointer { // Addressable.subscript.setter with no attribute // CHECK-LABEL: sil [transparent] [serialized] @_T015specialize_attr11AddressableC9subscriptxSicfs : $@convention(method) (@in Element, Int, @guaranteed Addressable) -> () { // Addressable.subscript.unsafeMutableAddressor with _specialize // CHECK-LABEL: sil [_specialize exported: false, kind: full, where Element == Int] @_T015specialize_attr11AddressableC9subscriptxSicfau : $@convention(method) (Int, @guaranteed Addressable) -> UnsafeMutablePointer { // Addressable.subscript.materializeForSet with no attribute // CHECK-LABEL: sil [transparent] [serialized] @_T015specialize_attr11AddressableC9subscriptxSicfm : $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, Int, @guaranteed Addressable) -> (Builtin.RawPointer, Optional) {