1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -DLIB_A %s -module-name A -emit-module-path %t/A.swiftmodule
// RUN: %target-swift-frontend -emit-module -DLIB_B %s -module-name B -emit-module-path %t/B.swiftmodule -I %t
// RUN: %target-swift-frontend -module-name C -emit-sil -O -DLIB_C %s -I %t | %FileCheck %s
// RUN: %target-swift-frontend -module-name C -emit-sil -O -DLIB_C_NO_SPI %s -I %t | %FileCheck %s --check-prefix=NOSPI
// Test using the public swiftinterface
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution -emit-module -DLIB_A %s -module-name A -emit-module-path %t/A.swiftmodule -emit-module-interface-path %t/A.swiftinterface
// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution -emit-module -DLIB_B %s -module-name B -emit-module-path %t/B.swiftmodule -I %t -emit-module-interface-path %t/B.swiftinterface
// RUN: rm %t/A.swiftmodule %t/B.swiftmodule
// RUN: %target-swift-frontend -module-name C -emit-sil -O -DLIB_C %s -I %t | %FileCheck %s --check-prefix=PUBLIC
// Test using the private swiftinterface
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution -emit-module -DLIB_A %s -module-name A -emit-module-path %t/A.swiftmodule -emit-module-interface-path %t/A.swiftinterface -emit-private-module-interface-path %t/A.private.swiftinterface
// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution -emit-module -DLIB_B %s -module-name B -emit-module-path %t/B.swiftmodule -I %t -emit-module-interface-path %t/B.swiftinterface -emit-private-module-interface-path %t/B.private.swiftinterface
// RUN: rm %t/A.swiftmodule %t/B.swiftmodule
// RUN: %target-swift-frontend -module-name C -emit-sil -O -DLIB_C %s -I %t | %FileCheck %s
#if LIB_A
@_specialize(exported: true, spi: A, where T == Int)
public func genericFuncLibA<T>(_ t: T) { print(t) }
public struct SomeStruct<T> {
var x : T
public init(_ t: T) { self.x = t }
@_specialize(exported: true, spi: A, where T == Int)
@inlinable
public func genericFuncInSomeStruct(_ t: T) { print(t) }
}
public struct SomeClass<T> {
var x : T
public init(_ t: T) { self.x = t }
@_specialize(exported: true, spi: A, where T == Int)
@inlinable
public func genericFuncInSomeClass(_ t: T) { print(t) }
}
public enum SomeEnum<T> {
case A
case B(T)
@_specialize(exported: true, spi: A, where T == Int)
@inlinable
public func genericFuncInSomeEnum(_ t: T) { print(SomeEnum.B(t)) }
}
@usableFromInline
struct SomeInternalStruct<T> {
var x : T
@usableFromInline
init(_ t: T) { self.x = t }
@_specialize(exported: true, spi: A, where T == Int)
@inlinable
func genericFuncInSomeStruct(_ t: T) { print(t) }
}
@inlinable
@inline(__always)
public func testSomeInternalStruct<T>(_ t: T) {
SomeInternalStruct(t).genericFuncInSomeStruct(t);
}
#elseif LIB_B
import A
@_specialize(exported: true, spi: A, where T == Int)
public func genericFuncLibB<T>(_ t: T) { print(t) }
@_specializeExtension
extension SomeStruct {
@_specialize(exported: true, spi: A, target: genericFuncInSomeStruct(_:), where T == Double)
public func genericFuncInSomeStruct_specialized(_ t: T) { fatalError("don't call") }
}
extension SomeClass {
@_specialize(exported: true, spi: A, target: genericFuncInSomeClass(_:), where T == Double)
public func genericFunc_specialized(_ t: T) { fatalError("don't call") }
}
extension SomeEnum {
@_specialize(exported: true, spi: A, target: genericFuncInSomeEnum(_:), where T == Double)
public func genericFunc_specialized(_ t: T) { fatalError("don't call") }
}
@_specializeExtension
extension SomeInternalStruct {
@_specialize(exported: true, spi: A, target: genericFuncInSomeStruct(_:), where T == Double)
public func genericFuncInSomeStruct_specialized(_ t: T) { fatalError("don't call") }
}
#elseif LIB_C
@_spi(A) import A
@_spi(A) import B
// CHECK-LABEL: sil @$s1C21testUseSpecializedSPIyyF : $@convention(thin) () -> () {
// CHECK: [[F1:%.*]] = function_ref @$s1A15genericFuncLibAyyxlFSi_Ts5
// CHECK: apply [[F1]]({{.*}}) : $@convention(thin) (Int) -> ()
// CHECK: [[F2:%.*]] = function_ref @$s1B15genericFuncLibByyxlFSi_Ts5
// CHECK: apply [[F2]]({{.*}}) : $@convention(thin) (Int) -> ()
// CHECK: function_ref @$s1A10SomeStructV013genericFuncInaB0yyxFSi_Ts5
// CHECK: function_ref @$s1A10SomeStructV013genericFuncInaB0yyxFSd_Ts5
// CHECK: function_ref @$s1A9SomeClassV013genericFuncInaB0yyxFSi_Ts5
// CHECK: function_ref @$s1A9SomeClassV013genericFuncInaB0yyxFSd_Ts5
// CHECK: function_ref @$s1A8SomeEnumO013genericFuncInaB0yyxFSi_Ts5
// CHECK: function_ref @$s1A8SomeEnumO013genericFuncInaB0yyxFSd_Ts5
// CHECK: } // end sil function '$s1C21testUseSpecializedSPIyyF'
// PUBLIC-LABEL: sil @$s1C21testUseSpecializedSPIyyF : $@convention(thin) () -> () {
// PUBLIC-NOT: function_ref @$s1A15genericFuncLibAyyxlFSi_Ts5
// PUBLIC-NOT: function_ref @$s1B15genericFuncLibByyxlFSi_Ts5
// PUBLIC-NOT: function_ref @$s1A10SomeStructV013genericFuncInaB0yyxFSi_Ts5
// PUBLIC-NOT: function_ref @$s1A10SomeStructV013genericFuncInaB0yyxFSd_Ts5
// PUBLIC-NOT: function_ref @$s1A9SomeClassV013genericFuncInaB0yyxFSi_Ts5
// PUBLIC-NOT: function_ref @$s1A9SomeClassV013genericFuncInaB0yyxFSd_Ts5
// PUBLIC-NOT: function_ref @$s1A8SomeEnumO013genericFuncInaB0yyxFSi_Ts5
// PUBLIC-NOT: function_ref @$s1A8SomeEnumO013genericFuncInaB0yyxFSd_Ts5
// PUBLIC: } // end sil function '$s1C21testUseSpecializedSPIyyF'
public func testUseSpecializedSPI() {
genericFuncLibA(1)
genericFuncLibB(2)
SomeStruct(1).genericFuncInSomeStruct(5)
SomeStruct(1.0).genericFuncInSomeStruct(5.0)
SomeClass(1).genericFuncInSomeClass(5)
SomeClass(1.0).genericFuncInSomeClass(5.0)
SomeEnum.B(1).genericFuncInSomeEnum(1)
SomeEnum.B(1.0).genericFuncInSomeEnum(1.0)
testSomeInternalStruct(1)
testSomeInternalStruct(1.0)
}
#elseif LIB_C_NO_SPI
import A
import B
// NOSPI-LABEL: sil @$s1C21testUseSpecializedSPIyyF : $@convention(thin) () -> () {
// NOSPI-NOT: function_ref @$s1A15genericFuncLibAyyxlFSi_Ts5
// NOSPI-NOT: function_ref @$s1B15genericFuncLibByyxlFSi_Ts5
// NOSPI-NOT: function_ref @$s1A10SomeStructV013genericFuncInaB0yyxFSi_Ts5
// NOSPI-NOT: function_ref @$s1A10SomeStructV013genericFuncInaB0yyxFSd_Ts5
// NOSPI-NOT: function_ref @$s1A9SomeClassV013genericFuncInaB0yyxFSi_Ts5
// NOSPI-NOT: function_ref @$s1A9SomeClassV013genericFuncInaB0yyxFSd_Ts5
// NOSPI-NOT: function_ref @$s1A8SomeEnumO013genericFuncInaB0yyxFSi_Ts5
// NOSPI-NOT: function_ref @$s1A8SomeEnumO013genericFuncInaB0yyxFSd_Ts5
// NOSPI: } // end sil function '$s1C21testUseSpecializedSPIyyF'
public func testUseSpecializedSPI() {
genericFuncLibA(1)
genericFuncLibB(2)
SomeStruct(1).genericFuncInSomeStruct(5)
SomeStruct(1.0).genericFuncInSomeStruct(5.0)
SomeClass(1).genericFuncInSomeClass(5)
SomeClass(1.0).genericFuncInSomeClass(5.0)
SomeEnum.B(1).genericFuncInSomeEnum(1)
SomeEnum.B(1.0).genericFuncInSomeEnum(1.0)
testSomeInternalStruct(1)
testSomeInternalStruct(1.0)
}
#endif
|