Skip to content

Commit fb529ff

Browse files
committed
[cxx-interop] Mark all CxxStdlib APIs as @_alwaysEmitIntoClient
The change in 269fc94 turned out not to be enough to solve linker errors when using the CxxStdlib overlay with a non-default C++ stdlib. In addition to `@inlinable`, the Swift functions in the overlay need to be `@_alwaysEmitIntoClient` to prevent Swift from trying to link a program that uses libc++ on Linux against the CxxStdlib binary shipped in the toolchain. rdar://138838506
1 parent ad70dc8 commit fb529ff

File tree

2 files changed

+45
-45
lines changed

2 files changed

+45
-45
lines changed

stdlib/public/Cxx/std/Chrono.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import CxxStdlibShim
1414

1515
extension std.chrono.seconds {
1616
@available(SwiftStdlib 5.7, *)
17-
@inlinable
17+
@_alwaysEmitIntoClient
1818
public init(_ duration: Duration) {
1919
let (seconds, _) = duration.components
2020
self = __swift_interopMakeChronoSeconds(seconds)
@@ -23,7 +23,7 @@ extension std.chrono.seconds {
2323

2424
extension std.chrono.milliseconds {
2525
@available(SwiftStdlib 5.7, *)
26-
@inlinable
26+
@_alwaysEmitIntoClient
2727
public init(_ duration: Duration) {
2828
let (seconds, attoseconds) = duration.components
2929
self = __swift_interopMakeChronoMilliseconds(
@@ -34,7 +34,7 @@ extension std.chrono.milliseconds {
3434

3535
extension std.chrono.microseconds {
3636
@available(SwiftStdlib 5.7, *)
37-
@inlinable
37+
@_alwaysEmitIntoClient
3838
public init(_ duration: Duration) {
3939
let (seconds, attoseconds) = duration.components
4040
self = __swift_interopMakeChronoMicroseconds(
@@ -45,7 +45,7 @@ extension std.chrono.microseconds {
4545

4646
extension std.chrono.nanoseconds {
4747
@available(SwiftStdlib 5.7, *)
48-
@inlinable
48+
@_alwaysEmitIntoClient
4949
public init(_ duration: Duration) {
5050
let (seconds, attoseconds) = duration.components
5151
self = __swift_interopMakeChronoNanoseconds(
@@ -56,22 +56,22 @@ extension std.chrono.nanoseconds {
5656

5757
@available(SwiftStdlib 5.7, *)
5858
extension Duration {
59-
@inlinable
59+
@_alwaysEmitIntoClient
6060
public init(_ seconds: std.chrono.seconds) {
6161
self = Duration.seconds(seconds.count())
6262
}
6363

64-
@inlinable
64+
@_alwaysEmitIntoClient
6565
public init(_ milliseconds: std.chrono.milliseconds) {
6666
self = Duration.milliseconds(milliseconds.count())
6767
}
6868

69-
@inlinable
69+
@_alwaysEmitIntoClient
7070
public init(_ microseconds: std.chrono.microseconds) {
7171
self = Duration.microseconds(microseconds.count())
7272
}
7373

74-
@inlinable
74+
@_alwaysEmitIntoClient
7575
public init(_ nanoseconds: std.chrono.nanoseconds) {
7676
self = Duration.nanoseconds(nanoseconds.count())
7777
}

stdlib/public/Cxx/std/String.swift

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension std.string {
1919
///
2020
/// - Complexity: O(*n*), where *n* is the number of UTF-8 code units in the
2121
/// Swift string.
22-
@inlinable
22+
@_alwaysEmitIntoClient
2323
public init(_ string: String) {
2424
self = string.withCString(encodedAs: UTF8.self) { buffer in
2525
#if os(Windows)
@@ -33,7 +33,7 @@ extension std.string {
3333
}
3434
}
3535

36-
@inlinable
36+
@_alwaysEmitIntoClient
3737
public init(_ string: UnsafePointer<CChar>?) {
3838
if let str = string {
3939
#if os(Windows)
@@ -56,7 +56,7 @@ extension std.u16string {
5656
///
5757
/// - Complexity: O(*n*), where *n* is the number of UTF-16 code units in the
5858
/// Swift string.
59-
@inlinable
59+
@_alwaysEmitIntoClient
6060
public init(_ string: String) {
6161
self.init()
6262
for char in string.utf16 {
@@ -71,7 +71,7 @@ extension std.u32string {
7171
///
7272
/// - Complexity: O(*n*), where *n* is the number of UTF-32 code units in the
7373
/// Swift string.
74-
@inlinable
74+
@_alwaysEmitIntoClient
7575
public init(_ string: String) {
7676
self.init()
7777
for char in string.unicodeScalars {
@@ -83,21 +83,21 @@ extension std.u32string {
8383
// MARK: Initializing C++ string from a Swift String literal
8484

8585
extension std.string: ExpressibleByStringLiteral {
86-
@inlinable
86+
@_alwaysEmitIntoClient
8787
public init(stringLiteral value: String) {
8888
self.init(value)
8989
}
9090
}
9191

9292
extension std.u16string: ExpressibleByStringLiteral {
93-
@inlinable
93+
@_alwaysEmitIntoClient
9494
public init(stringLiteral value: String) {
9595
self.init(value)
9696
}
9797
}
9898

9999
extension std.u32string: ExpressibleByStringLiteral {
100-
@inlinable
100+
@_alwaysEmitIntoClient
101101
public init(stringLiteral value: String) {
102102
self.init(value)
103103
}
@@ -106,27 +106,27 @@ extension std.u32string: ExpressibleByStringLiteral {
106106
// MARK: Concatenating and comparing C++ strings
107107

108108
extension std.string: Equatable, Comparable {
109-
@inlinable
109+
@_alwaysEmitIntoClient
110110
public static func ==(lhs: std.string, rhs: std.string) -> Bool {
111111
return lhs.compare(rhs) == 0
112112
}
113113

114-
@inlinable
114+
@_alwaysEmitIntoClient
115115
public static func <(lhs: std.string, rhs: std.string) -> Bool {
116116
return lhs.compare(rhs) < 0
117117
}
118118

119-
@inlinable
119+
@_alwaysEmitIntoClient
120120
public static func +=(lhs: inout std.string, rhs: std.string) {
121121
lhs.append(rhs)
122122
}
123123

124-
@inlinable
124+
@_alwaysEmitIntoClient
125125
public mutating func append(_ other: std.string) {
126126
__appendUnsafe(other) // ignore the returned pointer
127127
}
128128

129-
@inlinable
129+
@_alwaysEmitIntoClient
130130
public static func +(lhs: std.string, rhs: std.string) -> std.string {
131131
var copy = lhs
132132
copy += rhs
@@ -135,27 +135,27 @@ extension std.string: Equatable, Comparable {
135135
}
136136

137137
extension std.u16string: Equatable, Comparable {
138-
@inlinable
138+
@_alwaysEmitIntoClient
139139
public static func ==(lhs: std.u16string, rhs: std.u16string) -> Bool {
140140
return lhs.compare(rhs) == 0
141141
}
142142

143-
@inlinable
143+
@_alwaysEmitIntoClient
144144
public static func <(lhs: std.u16string, rhs: std.u16string) -> Bool {
145145
return lhs.compare(rhs) < 0
146146
}
147147

148-
@inlinable
148+
@_alwaysEmitIntoClient
149149
public static func +=(lhs: inout std.u16string, rhs: std.u16string) {
150150
lhs.append(rhs)
151151
}
152152

153-
@inlinable
153+
@_alwaysEmitIntoClient
154154
public mutating func append(_ other: std.u16string) {
155155
__appendUnsafe(other) // ignore the returned pointer
156156
}
157157

158-
@inlinable
158+
@_alwaysEmitIntoClient
159159
public static func +(lhs: std.u16string, rhs: std.u16string) -> std.u16string {
160160
var copy = lhs
161161
copy += rhs
@@ -164,27 +164,27 @@ extension std.u16string: Equatable, Comparable {
164164
}
165165

166166
extension std.u32string: Equatable, Comparable {
167-
@inlinable
167+
@_alwaysEmitIntoClient
168168
public static func ==(lhs: std.u32string, rhs: std.u32string) -> Bool {
169169
return lhs.compare(rhs) == 0
170170
}
171171

172-
@inlinable
172+
@_alwaysEmitIntoClient
173173
public static func <(lhs: std.u32string, rhs: std.u32string) -> Bool {
174174
return lhs.compare(rhs) < 0
175175
}
176176

177-
@inlinable
177+
@_alwaysEmitIntoClient
178178
public static func +=(lhs: inout std.u32string, rhs: std.u32string) {
179179
lhs.append(rhs)
180180
}
181181

182-
@inlinable
182+
@_alwaysEmitIntoClient
183183
public mutating func append(_ other: std.u32string) {
184184
__appendUnsafe(other) // ignore the returned pointer
185185
}
186186

187-
@inlinable
187+
@_alwaysEmitIntoClient
188188
public static func +(lhs: std.u32string, rhs: std.u32string) -> std.u32string {
189189
var copy = lhs
190190
copy += rhs
@@ -195,7 +195,7 @@ extension std.u32string: Equatable, Comparable {
195195
// MARK: Hashing C++ strings
196196

197197
extension std.string: Hashable {
198-
@inlinable
198+
@_alwaysEmitIntoClient
199199
public func hash(into hasher: inout Hasher) {
200200
// Call std::hash<std::string>::operator()
201201
let cxxHash = __swift_interopHashOfString().callAsFunction(self)
@@ -204,7 +204,7 @@ extension std.string: Hashable {
204204
}
205205

206206
extension std.u16string: Hashable {
207-
@inlinable
207+
@_alwaysEmitIntoClient
208208
public func hash(into hasher: inout Hasher) {
209209
// Call std::hash<std::u16string>::operator()
210210
let cxxHash = __swift_interopHashOfU16String().callAsFunction(self)
@@ -213,7 +213,7 @@ extension std.u16string: Hashable {
213213
}
214214

215215
extension std.u32string: Hashable {
216-
@inlinable
216+
@_alwaysEmitIntoClient
217217
public func hash(into hasher: inout Hasher) {
218218
// Call std::hash<std::u32string>::operator()
219219
let cxxHash = __swift_interopHashOfU32String().callAsFunction(self)
@@ -224,42 +224,42 @@ extension std.u32string: Hashable {
224224
// MARK: Getting a Swift description of a C++ string
225225

226226
extension std.string: CustomDebugStringConvertible {
227-
@inlinable
227+
@_alwaysEmitIntoClient
228228
public var debugDescription: String {
229229
return "std.string(\(String(self)))"
230230
}
231231
}
232232

233233
extension std.u16string: CustomDebugStringConvertible {
234-
@inlinable
234+
@_alwaysEmitIntoClient
235235
public var debugDescription: String {
236236
return "std.u16string(\(String(self)))"
237237
}
238238
}
239239

240240
extension std.u32string: CustomDebugStringConvertible {
241-
@inlinable
241+
@_alwaysEmitIntoClient
242242
public var debugDescription: String {
243243
return "std.u32string(\(String(self)))"
244244
}
245245
}
246246

247247
extension std.string: CustomStringConvertible {
248-
@inlinable
248+
@_alwaysEmitIntoClient
249249
public var description: String {
250250
return String(self)
251251
}
252252
}
253253

254254
extension std.u16string: CustomStringConvertible {
255-
@inlinable
255+
@_alwaysEmitIntoClient
256256
public var description: String {
257257
return String(self)
258258
}
259259
}
260260

261261
extension std.u32string: CustomStringConvertible {
262-
@inlinable
262+
@_alwaysEmitIntoClient
263263
public var description: String {
264264
return String(self)
265265
}
@@ -275,7 +275,7 @@ extension String {
275275
/// (`"\u{FFFD}"`).
276276
///
277277
/// - Complexity: O(*n*), where *n* is the number of bytes in the C++ string.
278-
@inlinable
278+
@_alwaysEmitIntoClient
279279
public init(_ cxxString: std.string) {
280280
let buffer = UnsafeBufferPointer<CChar>(
281281
start: cxxString.__c_strUnsafe(),
@@ -294,7 +294,7 @@ extension String {
294294
///
295295
/// - Complexity: O(*n*), where *n* is the number of bytes in the C++ UTF-16
296296
/// string.
297-
@inlinable
297+
@_alwaysEmitIntoClient
298298
public init(_ cxxU16String: std.u16string) {
299299
let buffer = UnsafeBufferPointer<UInt16>(
300300
start: cxxU16String.__dataUnsafe(),
@@ -311,7 +311,7 @@ extension String {
311311
///
312312
/// - Complexity: O(*n*), where *n* is the number of bytes in the C++ UTF-32
313313
/// string.
314-
@inlinable
314+
@_alwaysEmitIntoClient
315315
public init(_ cxxU32String: std.u32string) {
316316
let buffer = UnsafeBufferPointer<Unicode.Scalar>(
317317
start: cxxU32String.__dataUnsafe(),
@@ -334,7 +334,7 @@ extension String {
334334
///
335335
/// - Complexity: O(*n*), where *n* is the number of bytes in the C++ string
336336
/// view.
337-
@inlinable
337+
@_alwaysEmitIntoClient
338338
public init(_ cxxStringView: std.string_view) {
339339
let buffer = UnsafeBufferPointer<CChar>(
340340
start: cxxStringView.__dataUnsafe(),
@@ -354,7 +354,7 @@ extension String {
354354
///
355355
/// - Complexity: O(*n*), where *n* is the number of bytes in the C++ UTF-16
356356
/// string view.
357-
@inlinable
357+
@_alwaysEmitIntoClient
358358
public init(_ cxxU16StringView: std.u16string_view) {
359359
let buffer = UnsafeBufferPointer<UInt16>(
360360
start: cxxU16StringView.__dataUnsafe(),
@@ -372,7 +372,7 @@ extension String {
372372
///
373373
/// - Complexity: O(*n*), where *n* is the number of bytes in the C++ UTF-32
374374
/// string view.
375-
@inlinable
375+
@_alwaysEmitIntoClient
376376
public init(_ cxxU32StringView: std.u32string_view) {
377377
let buffer = UnsafeBufferPointer<Unicode.Scalar>(
378378
start: cxxU32StringView.__dataUnsafe(),

0 commit comments

Comments
 (0)