-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathmodule-alias-import-attrs.swift
183 lines (145 loc) · 6.78 KB
/
module-alias-import-attrs.swift
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
173
174
175
176
177
178
179
180
181
182
/// Test various import attributes with module aliasing.
///
/// Module 'Lib' imports module 'XLogging' via module aliasing and with various import attributes.
/// Module 'User' imports 'Lib'.
// RUN: %empty-directory(%t)
// RUN: %{python} %utils/split_file.py -o %t %s
/// Create AppleLogging.swiftmodule by aliasing XLogging
// RUN: %target-swift-frontend -module-name AppleLogging -module-alias XLogging=AppleLogging %t/FileLogging.swift -emit-module -emit-module-path %t/AppleLogging.swiftmodule
// RUN: test -f %t/AppleLogging.swiftmodule
/// Below, compile module Lib that imports XLogging with various import attributes via
/// -module-alias XLogging=AppleLogging
/// Test @_spi: Should fail
// RUN: not %target-swift-frontend -module-name Lib1 %t/FileLib1.swift -module-alias XLogging=AppleLogging -I %t -emit-module -emit-module-path %t/Lib1.swiftmodule 2> %t/result-Lib1.output
// RUN: %FileCheck %s -input-file %t/result-Lib1.output -check-prefix CHECK-SPI-ERROR
// CHECK-SPI-ERROR: error: 'spiFunc' is inaccessible due to '@_spi' protection level
/// Test @_spi: Should pass by adding @_spi
// RUN: %target-swift-frontend -module-name Lib2 %t/FileLib2.swift -module-alias XLogging=AppleLogging -I %t -emit-module -emit-module-path %t/Lib2.swiftmodule
// RUN: test -f %t/Lib2.swiftmodule
// RUN: llvm-bcanalyzer -dump %t/Lib2.swiftmodule > %t/Lib2.dump.txt
// RUN: %FileCheck -check-prefix=CHECK-REAL-NAME %s < %t/Lib2.dump.txt
// CHECK-REAL-NAME-NOT: XLogging
// CHECK-REAL-NAME: AppleLogging
/// Test @_implementationOnly: Should fail
// RUN: not %target-swift-frontend -module-name Lib3 %t/FileLib3.swift -module-alias XLogging=AppleLogging -I %t -emit-module -emit-module-path %t/Lib3.swiftmodule 2> %t/result-Lib3.output
// RUN: %FileCheck %s -input-file %t/result-Lib3.output -check-prefix CHECK-IMPL-ERROR
// CHECK-IMPL-ERROR: error: cannot use module 'XLogging' here; 'XLogging' has been imported as implementation-only
/// Test @_private: Should pass
/// Create AppleLoggingEnablePrivate.swiftmodule by aliasing XLogging
// RUN: %target-swift-frontend -module-name AppleLoggingEnablePrivate -module-alias XLogging=AppleLoggingEnablePrivate %S/Inputs/module-alias-src.swift -emit-module -emit-module-path %t/AppleLoggingEnablePrivate.swiftmodule -enable-private-imports -enable-implicit-dynamic
// RUN: test -f %t/AppleLoggingEnablePrivate.swiftmodule
// RUN: %target-swift-frontend -module-name Lib4 %t/FileLib4.swift -module-alias XLogging=AppleLoggingEnablePrivate -I %t -emit-module -emit-module-path %t/Lib4.swiftmodule
// RUN: llvm-bcanalyzer -dump %t/Lib4.swiftmodule > %t/Lib4.dump.txt
// RUN: %FileCheck -check-prefix=CHECK-REAL-NAME4 %s < %t/Lib4.dump.txt
// CHECK-REAL-NAME4-NOT: XLogging
// CHECK-REAL-NAME4: AppleLoggingEnablePrivate
/// Test @testable: Should pass
/// Create AppleLoggingEnableTesting.swiftmodule by aliasing XLogging
// RUN: %target-swift-frontend -module-name AppleLoggingEnableTesting -module-alias XLogging=AppleLoggingEnableTesting %t/FileLogging.swift -emit-module -emit-module-path %t/AppleLoggingEnableTesting.swiftmodule -enable-testing
// RUN: test -f %t/AppleLoggingEnableTesting.swiftmodule
// RUN: %target-swift-frontend -module-name Lib5 %t/FileLib5.swift -module-alias XLogging=AppleLoggingEnableTesting -I %t -emit-module -emit-module-path %t/Lib5.swiftmodule
// RUN: llvm-bcanalyzer -dump %t/Lib5.swiftmodule > %t/Lib5.dump.txt
// RUN: %FileCheck -check-prefix=CHECK-REAL-NAME5 %s < %t/Lib5.dump.txt
// CHECK-REAL-NAME5-NOT: XLogging
// CHECK-REAL-NAME5: AppleLoggingEnableTesting
/// Test import struct: Should pass with correct module name reference
// RUN: %target-swift-frontend -module-name Lib6 %t/FileLib6.swift -module-alias XLogging=AppleLogging -I %t -emit-module -emit-module-path %t/Lib6.swiftmodule -c -o %t/Lib6.o
// RUN: llvm-nm --defined-only %t/Lib6.o > %t/Lib6.dump.txt
// RUN: %FileCheck -check-prefix=CHECK-REAL-NAME6 %s < %t/Lib6.dump.txt
// CHECK-REAL-NAME6-NOT: XLogging
// CHECK-REAL-NAME6: s4Lib65start12AppleLogging6LoggerVyF
/// Test canImport
// RUN: %target-swift-frontend -module-name Lib7 %t/FileLib7.swift -module-alias XLogging=AppleLogging -I %t -emit-module -emit-module-path %t/Lib7.swiftmodule -Rmodule-loading 2> %t/Lib7.dump.txt
// RUN: %FileCheck -check-prefix=CHECK-LOAD %s < %t/Lib7.dump.txt
// CHECK-LOAD-NOT: XLogging.swiftmodule
// CHECK-LOAD: AppleLogging.swiftmodule
/// Test @_exported: Should pass with correct module name reference
// RUN: %target-swift-frontend -module-name Lib %t/FileLib.swift -module-alias XLogging=AppleLogging -I %t -emit-module -emit-module-path %t/Lib.swiftmodule
// RUN: test -f %t/Lib.swiftmodule
// RUN: %target-swift-frontend -module-name User %t/FileUser.swift -I %t -emit-module -emit-module-path %t/User.swiftmodule -c -o %t/User.o
// RUN: test -f %t/User.swiftmodule
// RUN: llvm-nm --defined-only %t/User.o > %t/User.dump.txt
// RUN: %FileCheck -check-prefix=CHECK-REAL-NAME-USER %s < %t/User.dump.txt
// CHECK-REAL-NAME-USER-NOT: XLogging
// CHECK-REAL-NAME-USER: s4User04MainA0V3use12AppleLogging6LoggerVyF
// BEGIN FileLogging.swift
public struct Logger {
public init() {}
@_spi(Usable) public func spiFunc() {}
public func regularFunc() {}
func internalFunc() {}
private func privateFunc() {}
}
struct InternalLogger {
init() {}
}
private struct PrivateLogger {
init() {}
}
public func setup() -> XLogging.Logger? {
return Logger()
}
// BEGIN FileLib1.swift
import XLogging
public func start() {
let it = Logger()
it.regularFunc()
it.spiFunc() // should fail
}
// BEGIN FileLib2.swift
@_spi(Usable) import XLogging
public func start() {
let it = Logger()
it.regularFunc()
it.spiFunc() // pass
}
// BEGIN FileLib3.swift
@_implementationOnly import XLogging
public func start() -> XLogging.Logger? { // should fail
return Logger()
}
// BEGIN FileLib4.swift
@_private(sourceFile: "module-alias-src.swift")
import XLogging
public func start() {
let x = InternalLogger() // should pass
let y = PrivateLogger() // should pass
Logger().internalFunc() // should pass
Logger().privateFunc() // should pass
print(x, y)
}
// BEGIN FileLib5.swift
@testable import XLogging
public func start() {
let x = InternalLogger() // should pass
print(x)
}
// BEGIN FileLib6.swift
import struct XLogging.Logger // should map to AppleLogging.Logger
public func start() -> XLogging.Logger {
let x = Logger()
x.regularFunc()
return x
}
// BEGIN FileLib7.swift
#if canImport(XLogging)
import XLogging // should map to AppleLogging.Logger
#endif
#if canImport(XLogging)
public func start() -> XLogging.Logger {
return Logger()
}
#endif
public func end() {}
// BEGIN FileLib.swift
@_exported import XLogging
public func start() -> XLogging.Logger? {
return Logger()
}
// BEGIN FileUser.swift
import Lib
public struct MainUser {
public func use() -> Logger {
return Logger() // should map to AppleLogging.Logger
}
}