|
1 | 1 | // RUN: %empty-directory(%t)
|
2 | 2 | // RUN: split-file %s %t
|
3 | 3 |
|
| 4 | +/// 1. Test `@_implementationOnly import`. |
| 5 | +// RUN: %target-build-swift-dylib(%t/%target-library-name(Utils)) \ |
| 6 | +// RUN: %t/UtilsA.swift %t/UtilsB.swift \ |
| 7 | +// RUN: -module-name Utils -emit-module -package-name Pkg \ |
| 8 | +// RUN: -Xfrontend -experimental-package-cmo -Xfrontend -experimental-allow-non-resilient-access \ |
| 9 | +// RUN: -enable-library-evolution -O -wmo |
| 10 | +// RUN: %target-sil-opt %t/Utils.swiftmodule -I %t -sil-verify-all -o %t/Utils.sil |
| 11 | +// RUN: %FileCheck %s --check-prefix=CHECK-UTILS < %t/Utils.sil |
| 12 | + |
| 13 | +/// Verify accessing PkgKlass.second from a client in a dynamic context does not cause a linker error. |
| 14 | +// RUN: %target-build-swift -I %t -L %t %t/Client.swift -package-name Pkg \ |
| 15 | +// RUN: -O -wmo -enable-library-evolution \ |
| 16 | +// RUN: %target-rpath(%t) -lUtils -o %t/a.out |
| 17 | + |
| 18 | +// RUN: %target-swift-frontend -emit-sil -I %t -L %t %t/Client.swift \ |
| 19 | +// RUN: -package-name Pkg -O -wmo -enable-library-evolution \ |
| 20 | +// RUN: -lUtils -o %t/Client.sil |
| 21 | +// RUN: %FileCheck %s --check-prefix=CHECK-CLIENT < %t/Client.sil |
| 22 | + |
| 23 | +/// 2. Test `package import` and `@_spiOnly import`. |
4 | 24 | // RUN: %target-swift-frontend %t/CoreA.swift \
|
5 | 25 | // RUN: -module-name=CoreA -package-name Pkg \
|
6 | 26 | // RUN: -parse-as-library -emit-module \
|
|
13 | 33 | // RUN: -emit-module-path %t/CoreB.swiftmodule -I%t \
|
14 | 34 | // RUN: -O -wmo -enable-library-evolution
|
15 | 35 |
|
16 |
| -// RUN: %target-swift-frontend %t/Lib.swift \ |
17 |
| -// RUN: -module-name=Lib -package-name Pkg \ |
| 36 | +// RUN: %target-swift-frontend %t/UI.swift \ |
| 37 | +// RUN: -module-name=UI -package-name Pkg \ |
18 | 38 | // RUN: -parse-as-library -emit-module \
|
19 | 39 | // RUN: -experimental-spi-only-imports \
|
20 |
| -// RUN: -emit-module-path %t/Lib.swiftmodule -I %t \ |
| 40 | +// RUN: -emit-module-path %t/UI.swiftmodule -I %t \ |
21 | 41 | // RUN: -experimental-package-cmo -experimental-allow-non-resilient-access \
|
22 |
| -// RUN: -O -wmo -enable-library-evolution -Rmodule-loading 2> %t/Lib-result.txt |
23 |
| -// RUN: %target-sil-opt %t/Lib.swiftmodule -I %t -sil-verify-all -o %t/Lib.sil |
24 |
| -// RUN: %FileCheck %s < %t/Lib.sil |
| 42 | +// RUN: -O -wmo -enable-library-evolution -Rmodule-loading 2> %t/UI-result.txt |
| 43 | +// RUN: %target-sil-opt %t/UI.swiftmodule -I %t -sil-verify-all -o %t/UI.sil |
| 44 | +// RUN: %FileCheck %s < %t/UI.sil |
25 | 45 |
|
26 | 46 | // REQUIRES: swift_in_compiler
|
| 47 | +// REQUIRES: OS=macosx || OS=ios || OS=tvos || OS=watchos || OS=maccatalyst |
| 48 | + |
| 49 | +//--- Client.swift |
| 50 | +package import Utils |
| 51 | + |
| 52 | +package func clientFunc<T: PkgKlass>(_ list: [T]) { |
| 53 | + // closure #1 in clientFunc<A>(_:) |
| 54 | + // CHECK-CLIENT: sil private @$s6Client10clientFuncyySayxG5Utils8PkgKlassCRbzlFSo8NSObjectCxXEfU_ : $@convention(thin) <T where T : PkgKlass> (@in_guaranteed T) -> (@out NSObject, @error_indirect Never) { |
| 55 | + // CHECK-CLIENT: class_method {{.*}} #PkgKlass.second!getter : (PkgKlass) -> () -> NSObject, $@convention(method) (@guaranteed PkgKlass) -> @owned NSObject |
| 56 | + // CHECK-CLIENT: } // end sil function '$s6Client10clientFuncyySayxG5Utils8PkgKlassCRbzlFSo8NSObjectCxXEfU_' |
| 57 | + let result = list.map { $0.second } |
| 58 | + print(result) |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +//--- UtilsA.swift |
| 63 | +public import Foundation // public import to allow `NSObject` in API. |
27 | 64 |
|
| 65 | +package class PkgKlass: NSObject { |
| 66 | + /// Serialized since it does _not_ reference a type from module imported as @_implementationOnly. |
| 67 | + // PkgKlass.first.getter |
| 68 | + // CHECK-UTILS-DAG: sil package [serialized_for_package] [canonical] @$s5Utils8PkgKlassC5firstSSvg : $@convention(method) (@guaranteed PkgKlass) -> @owned String { |
| 69 | + package var first: String |
| 70 | + |
| 71 | + /// NOT serialized since it does reference a type from module imported as @_implementationOnly. |
| 72 | + // PkgKlass.second.getter |
| 73 | + // CHECK-UTILS-DAG: sil package_external [canonical] @$s5Utils8PkgKlassC6secondSo8NSObjectCvg : $@convention(method) (@guaranteed PkgKlass) -> @owned NSObject |
| 74 | + @objc package var second: NSObject |
| 75 | + |
| 76 | + init(first: String, second: NSObject) { |
| 77 | + self.first = first |
| 78 | + self.second = second |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +//--- UtilsB.swift |
| 83 | +@_implementationOnly import Foundation |
| 84 | + |
| 85 | +public func utilsFunc() { |
| 86 | + let x: NSString = "utilsfunc" |
| 87 | + print(x) |
| 88 | +} |
28 | 89 |
|
29 |
| -//--- Lib.swift |
| 90 | +//--- UI.swift |
30 | 91 | package import CoreA
|
31 | 92 | @_spiOnly public import CoreB
|
32 | 93 |
|
33 | 94 | /// PkgStruct is imported with `package import` and should be serialized.
|
34 |
| -// CHECK-DAG: sil package [serialized_for_package] [canonical] @$s3Lib7libFuncyy5CoreA9PkgStructVF : $@convention(thin) (@in_guaranteed PkgStruct) -> () { |
| 95 | +// CHECK-DAG: sil package [serialized_for_package] [canonical] @$s2UI7libFuncyy5CoreA9PkgStructVF : $@convention(thin) (@in_guaranteed PkgStruct) -> () { |
35 | 96 | package func libFunc(_ arg: PkgStruct) {
|
36 | 97 | print(arg.pkgVar)
|
37 | 98 | }
|
38 | 99 |
|
39 | 100 | /// PubStruct is imported with `@_spiOnly public import` and should be serialized.
|
40 |
| -// CHECK-DAG: sil [serialized_for_package] [canonical] @$s3Lib7spiFuncyy5CoreB15PubStructForSPIVF : $@convention(thin) (@in_guaranteed PubStructForSPI) -> () { |
41 |
| -@_spi(InCoreB) |
| 101 | +// CHECK-DAG: sil [serialized_for_package] [canonical] @$s2UI7spiFuncyy5CoreB15PubStructForSPIVF : $@convention(thin) (@in_guaranteed PubStructForSPI) -> () { |
| 102 | +@_spi(GroupB) |
42 | 103 | public func spiFunc(_ arg: PubStructForSPI) {
|
43 | 104 | print(arg.pubVarForSPI)
|
44 | 105 | }
|
|
0 commit comments