|
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 | +/// Ensure PkgKlass.second accessor symbols are present in the final binary. |
| 14 | +// RUN: nm -gU %t/%target-library-name(Utils) | grep "second" | %FileCheck %s --check-prefix=CHECK-NM |
| 15 | +// CHECK-NM: s5Utils8PkgKlassC6secondSo8NSObjectCvM |
| 16 | +// CHECK-NM: s5Utils8PkgKlassC6secondSo8NSObjectCvMTj |
| 17 | +// CHECK-NM: s5Utils8PkgKlassC6secondSo8NSObjectCvMTq |
| 18 | +// CHECK-NM: s5Utils8PkgKlassC6secondSo8NSObjectCvg |
| 19 | +// CHECK-NM: s5Utils8PkgKlassC6secondSo8NSObjectCvgTj |
| 20 | +// CHECK-NM: s5Utils8PkgKlassC6secondSo8NSObjectCvgTq |
| 21 | + |
| 22 | +/// Ensure accessing PkgKlass.second from a client does not cause a linker error. |
| 23 | +// RUN: %target-build-swift -I %t -L %t %t/Client.swift -package-name Pkg \ |
| 24 | +// RUN: %target-rpath(%t) -lUtils -o %t/a.out |
| 25 | + |
| 26 | + |
| 27 | +/// 2. Test `package import` and `@_spiOnly import`. |
4 | 28 | // RUN: %target-swift-frontend %t/CoreA.swift \
|
5 | 29 | // RUN: -module-name=CoreA -package-name Pkg \
|
6 | 30 | // RUN: -parse-as-library -emit-module \
|
|
13 | 37 | // RUN: -emit-module-path %t/CoreB.swiftmodule -I%t \
|
14 | 38 | // RUN: -O -wmo -enable-library-evolution
|
15 | 39 |
|
16 |
| -// RUN: %target-swift-frontend %t/Lib.swift \ |
17 |
| -// RUN: -module-name=Lib -package-name Pkg \ |
| 40 | +// RUN: %target-swift-frontend %t/UI.swift \ |
| 41 | +// RUN: -module-name=UI -package-name Pkg \ |
18 | 42 | // RUN: -parse-as-library -emit-module \
|
19 | 43 | // RUN: -experimental-spi-only-imports \
|
20 |
| -// RUN: -emit-module-path %t/Lib.swiftmodule -I %t \ |
| 44 | +// RUN: -emit-module-path %t/UI.swiftmodule -I %t \ |
21 | 45 | // 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 |
| 46 | +// RUN: -O -wmo -enable-library-evolution -Rmodule-loading 2> %t/UI-result.txt |
| 47 | +// RUN: %target-sil-opt %t/UI.swiftmodule -I %t -sil-verify-all -o %t/UI.sil |
| 48 | +// RUN: %FileCheck %s < %t/UI.sil |
25 | 49 |
|
26 | 50 | // REQUIRES: swift_in_compiler
|
27 | 51 |
|
| 52 | +//--- Client.swift |
| 53 | +public import Utils |
| 54 | + |
| 55 | +package func clientFunc(_ arg: PkgKlass) { |
| 56 | + print(arg.second as! AnyObject) |
| 57 | +} |
| 58 | + |
| 59 | +//--- UtilsA.swift |
| 60 | +public import Foundation |
| 61 | + |
| 62 | +package class PkgKlass { |
| 63 | + /// Serialized since it does not reference a type from module imported as @_implementationOnly. |
| 64 | + // PkgKlass.first.getter |
| 65 | + // CHECK-UTILS-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s5Utils8PkgKlassC5firstSSvg : $@convention(method) (@guaranteed PkgKlass) -> @owned String { |
| 66 | + package var first: String |
| 67 | + |
| 68 | + /// Not serialized since it references a type from module imported as @_implementationOnly. |
| 69 | + // PkgKlass.second.getter |
| 70 | + // CHECK-UTILS-DAG: sil package_external [canonical] @$s5Utils8PkgKlassC6secondSo8NSObjectCvg : $@convention(method) (@guaranteed PkgKlass) -> @owned NSObject |
| 71 | + package var second: NSObject |
| 72 | + |
| 73 | + package init(_ arg1: String, _ arg2: NSObject) { |
| 74 | + self.first = arg1 |
| 75 | + self.second = arg2 |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +//--- UtilsB.swift |
| 80 | +@_implementationOnly import Foundation |
| 81 | + |
| 82 | +public func utilsFunc() { |
| 83 | + let x: NSString = "utilsfunc" |
| 84 | + print(x) |
| 85 | +} |
28 | 86 |
|
29 |
| -//--- Lib.swift |
| 87 | +//--- UI.swift |
30 | 88 | package import CoreA
|
31 | 89 | @_spiOnly public import CoreB
|
32 | 90 |
|
33 | 91 | /// PkgStruct is imported with `package import` and should be serialized.
|
34 |
| -// CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib7libFuncyy5CoreA9PkgStructVF : $@convention(thin) (@in_guaranteed PkgStruct) -> () { |
35 |
| -package func libFunc(_ arg: PkgStruct) { |
| 92 | +// CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s2UI6uiFuncyy5CoreA9PkgStructVF : $@convention(thin) (@in_guaranteed PkgStruct) -> () { |
| 93 | +package func uiFunc(_ arg: PkgStruct) { |
36 | 94 | print(arg.pkgVar)
|
37 | 95 | }
|
38 | 96 |
|
39 | 97 | /// PubStruct is imported with `@_spiOnly public import` and should be serialized.
|
40 |
| -// CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib7spiFuncyy5CoreB15PubStructForSPIVF : $@convention(thin) (@in_guaranteed PubStructForSPI) -> () { |
| 98 | +// CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s2UI7spiFuncyy5CoreB15PubStructForSPIVF : $@convention(thin) (@in_guaranteed PubStructForSPI) -> () { |
41 | 99 | @_spi(InCoreB)
|
42 | 100 | public func spiFunc(_ arg: PubStructForSPI) {
|
43 | 101 | print(arg.pubVarForSPI)
|
|
0 commit comments