Skip to content

Commit cd1ca40

Browse files
committed
stdlib: Adopt @_disallowFeatureSuppression(NoncopyableGenerics2).
This prevents some re-declaration errors when building the standard library from its `.swiftinterface` with older compilers.
1 parent 47129e3 commit cd1ca40

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

stdlib/public/core/Optional.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,20 +213,22 @@ extension Optional where Wrapped: ~Copyable {
213213
}
214214
}
215215

216-
#if hasFeature(BorrowingSwitch)
217216
// FIXME(NCG): Make this public.
218217
@_alwaysEmitIntoClient
219218
public borrowing func _borrowingMap<U: ~Copyable, E: Error>(
220219
_ transform: (borrowing Wrapped) throws(E) -> U
221220
) throws(E) -> U? {
221+
#if $NoncopyableGenerics2
222222
switch self {
223223
case .some(_borrowing y):
224224
return .some(try transform(y))
225225
case .none:
226226
return .none
227227
}
228+
#else
229+
fatalError("unsupported compiler")
230+
#endif
228231
}
229-
#endif
230232
}
231233

232234
extension Optional {
@@ -263,6 +265,7 @@ extension Optional {
263265
}
264266
}
265267

268+
@_disallowFeatureSuppression(NoncopyableGenerics2)
266269
extension Optional where Wrapped: ~Copyable {
267270
// FIXME(NCG): Make this public.
268271
@_alwaysEmitIntoClient
@@ -277,7 +280,6 @@ extension Optional where Wrapped: ~Copyable {
277280
}
278281
}
279282

280-
#if hasFeature(BorrowingSwitch)
281283
// FIXME(NCG): Make this public.
282284
@_alwaysEmitIntoClient
283285
public func _borrowingFlatMap<U: ~Copyable, E: Error>(
@@ -290,7 +292,6 @@ extension Optional where Wrapped: ~Copyable {
290292
return .none
291293
}
292294
}
293-
#endif
294295
}
295296

296297
extension Optional {
@@ -546,7 +547,6 @@ public struct _OptionalNilComparisonType: ExpressibleByNilLiteral {
546547
}
547548
}
548549

549-
#if hasFeature(BorrowingSwitch)
550550
extension Optional where Wrapped: ~Copyable {
551551
/// Returns a Boolean value indicating whether an argument matches `nil`.
552552
///
@@ -735,9 +735,6 @@ extension Optional where Wrapped: ~Copyable {
735735
}
736736
}
737737
}
738-
#else
739-
#error("FIXME(NCG): Fill this out.")
740-
#endif
741738

742739
/// Performs a nil-coalescing operation, returning the wrapped value of an
743740
/// `Optional` instance or a default value.

stdlib/public/core/Result.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ extension Result {
6161
}
6262
}
6363

64+
@_disallowFeatureSuppression(NoncopyableGenerics2)
6465
extension Result where Success: ~Copyable {
6566
// FIXME(NCG): Make this public.
6667
@_alwaysEmitIntoClient
@@ -75,7 +76,6 @@ extension Result where Success: ~Copyable {
7576
}
7677
}
7778

78-
#if $BorrowingSwitch
7979
// FIXME(NCG): Make this public.
8080
@_alwaysEmitIntoClient
8181
public borrowing func _borrowingMap<NewSuccess: ~Copyable>(
@@ -88,7 +88,6 @@ extension Result where Success: ~Copyable {
8888
return .failure(failure)
8989
}
9090
}
91-
#endif
9291
}
9392

9493
extension Result where Success: ~Copyable {
@@ -131,6 +130,7 @@ extension Result where Success: ~Copyable {
131130
}
132131
}
133132

133+
@_disallowFeatureSuppression(NoncopyableGenerics2)
134134
extension Result {
135135
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
136136
@usableFromInline
@@ -186,6 +186,7 @@ extension Result {
186186
}
187187
}
188188

189+
@_disallowFeatureSuppression(NoncopyableGenerics2)
189190
extension Result where Success: ~Copyable {
190191
// FIXME(NCG): Make this public.
191192
@_alwaysEmitIntoClient
@@ -200,7 +201,6 @@ extension Result where Success: ~Copyable {
200201
}
201202
}
202203

203-
#if $BorrowingSwitch
204204
// FIXME(NCG): Make this public.
205205
@_alwaysEmitIntoClient
206206
public borrowing func _borrowingFlatMap<NewSuccess: ~Copyable>(
@@ -213,7 +213,6 @@ extension Result where Success: ~Copyable {
213213
return .failure(failure)
214214
}
215215
}
216-
#endif
217216
}
218217

219218
extension Result {

stdlib/public/core/UnsafeBufferPointer.swift.gyb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ extension Unsafe${Mutable}BufferPointer where Element: ~Copyable {
456456

457457
}
458458

459+
@_disallowFeatureSuppression(NoncopyableGenerics2)
459460
extension Unsafe${Mutable}BufferPointer {
460461
/// Accesses the element at the specified position.
461462
///

stdlib/public/core/UnsafePointer.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ extension UnsafePointer where Pointee: ~Copyable {
286286
}
287287
}
288288

289+
@_disallowFeatureSuppression(NoncopyableGenerics2)
289290
extension UnsafePointer {
290291
// This preserves the ABI of the original (pre-6.0) `pointee` property that
291292
// used to export a getter. The current one above would export a read
@@ -315,6 +316,7 @@ extension UnsafePointer where Pointee: ~Copyable {
315316
}
316317
}
317318

319+
@_disallowFeatureSuppression(NoncopyableGenerics2)
318320
extension UnsafePointer {
319321
// This preserves the ABI of the original (pre-6.0) subscript that used to
320322
// export a getter. The current one above would export a read accessor, if it
@@ -843,6 +845,7 @@ extension UnsafeMutablePointer where Pointee: ~Copyable {
843845
}
844846
}
845847

848+
@_disallowFeatureSuppression(NoncopyableGenerics2)
846849
extension UnsafeMutablePointer {
847850
// This preserves the ABI of the original (pre-6.0) `pointee` property that
848851
// used to export a getter. The current one above would export a read
@@ -1300,6 +1303,7 @@ extension UnsafeMutablePointer where Pointee: ~Copyable {
13001303
}
13011304
}
13021305

1306+
@_disallowFeatureSuppression(NoncopyableGenerics2)
13031307
extension UnsafeMutablePointer {
13041308
// This preserves the ABI of the original (pre-6.0) subscript that used to
13051309
// export a getter. The current one above would export a read accessor, if it

test/ModuleInterface/Inputs/NoncopyableGenerics_Misc.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,6 @@ public func old_swap<T: ~Copyable>(_ a: inout T, _ b: inout T) {}
109109

110110
@_preInverseGenerics
111111
public func borrowsNoncopyable<T: ~Copyable>(_ t: borrowing T) {}
112+
113+
@_disallowFeatureSuppression(NoncopyableGenerics2)
114+
public func suppressesNoncopyableGenerics<T: ~Copyable>(_ t: borrowing T) {}

test/ModuleInterface/noncopyable_generics.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ import NoncopyableGenerics_Misc
156156
// CHECK-MISC-NEXT: public func borrowsNoncopyable<T>(_ t: T)
157157
// CHECK-MISC-NEXT: #endif
158158

159+
// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics2
160+
// CHECK-MISC-NEXT: public func suppressesNoncopyableGenerics<T>(_ t: borrowing T) where T : ~Copyable
161+
// CHECK-MISC-NEXT: #endif
162+
163+
159164
import Swiftskell
160165

161166
// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics2

0 commit comments

Comments
 (0)