Skip to content

Commit cddf73e

Browse files
committed
[Gardening] Clean Up OS-Test Patterns Across The Codebase
Clean up a few general patterns that are now obviated by canImport This aligns more generally with the cleanup that the Swift Package Manager has already done in their automated XCTest-plumbing tool in swiftlang/swift-package-manager#1826.
1 parent 30ccb52 commit cddf73e

File tree

66 files changed

+161
-157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+161
-157
lines changed

benchmark/single-source/FloatingPointParsing.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public func run_ParseDoubleExp(_ N: Int) {
242242

243243
@inline(never)
244244
public func run_ParseFloat80Exp(_ N: Int) {
245-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(Linux)
245+
#if canImport(Darwin) || os(Linux)
246246
// On Darwin, long double is Float80 on x86, and Double otherwise.
247247
// On Linux, Float80 is at aleast available on x86.
248248
#if arch(x86_64) || arch(i386)
@@ -263,7 +263,7 @@ public func run_ParseDoubleUniform(_ N: Int) {
263263

264264
@inline(never)
265265
public func run_ParseFloat80Uniform(_ N: Int) {
266-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(Linux)
266+
#if canImport(Darwin) || os(Linux)
267267
// On Darwin, long double is Float80 on x86, and Double otherwise.
268268
// On Linux, Float80 is at aleast available on x86.
269269
#if arch(x86_64) || arch(i386)

benchmark/single-source/FloatingPointPrinting.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public func run_FloatingPointPrinting_Double_description_small(_ N: Int) {
106106

107107
@inline(never)
108108
public func run_FloatingPointPrinting_Float80_description_small(_ N: Int) {
109-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(Linux)
109+
#if canImport(Darwin) || os(Linux)
110110
// On Darwin, long double is Float80 on x86, and Double otherwise.
111111
// On Linux, Float80 is at aleast available on x86.
112112
#if arch(x86_64) || arch(i386)
@@ -152,7 +152,7 @@ public func run_FloatingPointPrinting_Double_description_uniform(_ N: Int) {
152152

153153
@inline(never)
154154
public func run_FloatingPointPrinting_Float80_description_uniform(_ N: Int) {
155-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(Linux)
155+
#if canImport(Darwin) || os(Linux)
156156
// On Darwin, long double is Float80 on x86, and Double otherwise.
157157
// On Linux, Float80 is at aleast available on x86.
158158
#if arch(x86_64) || arch(i386)
@@ -202,7 +202,7 @@ public func run_FloatingPointPrinting_Double_interpolated(_ N: Int) {
202202

203203
@inline(never)
204204
public func run_FloatingPointPrinting_Float80_interpolated(_ N: Int) {
205-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(Linux)
205+
#if canImport(Darwin) || os(Linux)
206206
// On Darwin, long double is Float80 on x86, and Double otherwise.
207207
// On Linux, Float80 is at aleast available on x86.
208208
#if arch(x86_64) || arch(i386)

benchmark/single-source/NSStringConversion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
// <rdar://problem/19003201>
14-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
14+
#if canImport(Darwin)
1515

1616
import TestsUtils
1717
import Foundation

benchmark/utils/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ import NibbleSort
103103
import NIOChannelPipeline
104104
import NSDictionaryCastToSwift
105105
import NSError
106-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
106+
#if canImport(Darwin)
107107
import NSStringConversion
108108
#endif
109109
import NopDeinit
110110
import ObjectAllocation
111-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
111+
#if canImport(Darwin)
112112
import ObjectiveCBridging
113113
import ObjectiveCBridgingStubs
114114
#if !(SWIFT_PACKAGE || Xcode)
@@ -287,14 +287,14 @@ registerBenchmark(MonteCarloE)
287287
registerBenchmark(MonteCarloPi)
288288
registerBenchmark(NSDictionaryCastToSwift)
289289
registerBenchmark(NSErrorTest)
290-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
290+
#if canImport(Darwin)
291291
registerBenchmark(NSStringConversion)
292292
#endif
293293
registerBenchmark(NibbleSort)
294294
registerBenchmark(NIOChannelPipeline)
295295
registerBenchmark(NopDeinit)
296296
registerBenchmark(ObjectAllocation)
297-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
297+
#if canImport(Darwin)
298298
registerBenchmark(ObjectiveCBridging)
299299
registerBenchmark(ObjectiveCBridgingStubs)
300300
#if !(SWIFT_PACKAGE || Xcode)

docs/DifferentiableProgramming.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ One concrete example is `sinf(_:)` from the C standard library. It can be made
19491949
differentiable by defining a derivative retroactively.
19501950

19511951
```swift
1952-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1952+
#if canImport(Darwin)
19531953
import func Darwin.sinf
19541954
#else
19551955
import func Glibc.sinf

stdlib/private/StdlibUnittest/RaceTest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
import SwiftPrivate
4040
import SwiftPrivateLibcExtras
4141
import SwiftPrivateThreadExtras
42-
#if os(macOS) || os(iOS)
42+
#if canImport(Darwin)
4343
import Darwin
44-
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
44+
#elseif canImport(Glibc)
4545
import Glibc
4646
#elseif os(Windows)
4747
import MSVCRT

stdlib/private/StdlibUnittest/StdlibCoreExtras.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
import SwiftPrivate
1414
import SwiftPrivateLibcExtras
15-
#if os(macOS) || os(iOS)
15+
#if canImport(Darwin)
1616
import Darwin
17-
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
17+
#elseif canImport(Glibc)
1818
import Glibc
1919
#elseif os(Windows)
2020
import MSVCRT

stdlib/private/StdlibUnittest/StdlibUnittest.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import SwiftPrivate
1515
import SwiftPrivateThreadExtras
1616
import SwiftPrivateLibcExtras
1717

18-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
18+
#if canImport(Darwin)
1919
import Foundation
2020
import Darwin
21-
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
21+
#elseif canImport(Glibc)
2222
import Glibc
2323
#elseif os(Windows)
2424
import MSVCRT
@@ -1728,7 +1728,7 @@ public final class TestSuite {
17281728
var _testNameToIndex: [String : Int] = [:]
17291729
}
17301730

1731-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1731+
#if canImport(Darwin)
17321732
func _getSystemVersionPlistProperty(_ propertyName: String) -> String? {
17331733
return NSDictionary(contentsOfFile: "/System/Library/CoreServices/SystemVersion.plist")?[propertyName] as? String
17341734
}

stdlib/private/StdlibUnittest/SymbolLookup.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
13+
#if canImport(Darwin)
1414
import Darwin
15-
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
15+
#elseif canImport(Glibc)
1616
import Glibc
1717
#elseif os(Windows)
1818
import MSVCRT
@@ -21,7 +21,7 @@
2121
#error("Unsupported platform")
2222
#endif
2323

24-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(OpenBSD)
24+
#if canImport(Darwin) || os(OpenBSD)
2525
let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: -2)
2626
#elseif os(Linux)
2727
let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: 0)

stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import SwiftPrivate
14-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
14+
#if canImport(Darwin)
1515
import Darwin
16-
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
16+
#elseif canImport(Glibc)
1717
import Glibc
1818
#elseif os(Windows)
1919
import MSVCRT

stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import SwiftPrivate
14-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
14+
#if canImport(Darwin)
1515
import Darwin
16-
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
16+
#elseif canImport(Glibc)
1717
import Glibc
1818
#elseif os(Windows)
1919
import MSVCRT

stdlib/private/SwiftPrivateThreadExtras/SwiftPrivateThreadExtras.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
//
1616
//===----------------------------------------------------------------------===//
1717

18-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
18+
#if canImport(Darwin)
1919
import Darwin
20-
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
20+
#elseif canImport(Glibc)
2121
import Glibc
2222
#elseif os(Windows)
2323
import MSVCRT

stdlib/private/SwiftPrivateThreadExtras/ThreadBarriers.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
13+
#if canImport(Darwin)
1414
import Darwin
15-
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
15+
#elseif canImport(Glibc)
1616
import Glibc
1717
#elseif os(Windows)
1818
import MSVCRT

stdlib/public/Differentiation/TgmathDerivatives.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
import Swift
1616

17-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
17+
#if canImport(Darwin)
1818
import Darwin.C.tgmath
19-
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
19+
#elseif canImport(Glibc)
2020
import Glibc
2121
#elseif os(Windows)
2222
import MSVCRT

stdlib/public/Platform/MachError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
13+
#if canImport(Darwin)
1414
/// Enumeration describing Mach error codes.
1515
@objc
1616
public enum MachErrorCode : Int32 {
@@ -202,4 +202,4 @@ public enum MachErrorCode : Int32 {
202202
/// The requested property cannot be changed at this time.
203203
case policyStatic = 51
204204
}
205-
#endif // os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
205+
#endif // canImport(Darwin)

stdlib/public/Platform/POSIXError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
13+
#if canImport(Darwin)
1414

1515
/// Enumeration describing POSIX error codes.
1616
@objc

stdlib/public/Platform/Platform.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import SwiftOverlayShims
1717
import ucrt
1818
#endif
1919

20-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
20+
#if canImport(Darwin)
2121
//===----------------------------------------------------------------------===//
2222
// MacTypes.h
2323
//===----------------------------------------------------------------------===//
@@ -103,7 +103,7 @@ public var errno : Int32 {
103103
// stdio.h
104104
//===----------------------------------------------------------------------===//
105105

106-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD) || os(PS4)
106+
#if canImport(Darwin) || os(FreeBSD) || os(PS4)
107107
public var stdin : UnsafeMutablePointer<FILE> {
108108
get {
109109
return __stdinp
@@ -248,7 +248,7 @@ public var S_IFBLK: mode_t { return mode_t(0o060000) }
248248
public var S_IFREG: mode_t { return mode_t(0o100000) }
249249
public var S_IFLNK: mode_t { return mode_t(0o120000) }
250250
public var S_IFSOCK: mode_t { return mode_t(0o140000) }
251-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
251+
#if canImport(Darwin)
252252
public var S_IFWHT: mode_t { return mode_t(0o160000) }
253253
#endif
254254

@@ -271,7 +271,7 @@ public var S_ISUID: mode_t { return mode_t(0o004000) }
271271
public var S_ISGID: mode_t { return mode_t(0o002000) }
272272
public var S_ISVTX: mode_t { return mode_t(0o001000) }
273273

274-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
274+
#if canImport(Darwin)
275275
public var S_ISTXT: mode_t { return S_ISVTX }
276276
public var S_IREAD: mode_t { return S_IRUSR }
277277
public var S_IWRITE: mode_t { return S_IWUSR }
@@ -315,7 +315,7 @@ public func ioctl(
315315
// unistd.h
316316
//===----------------------------------------------------------------------===//
317317

318-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
318+
#if canImport(Darwin)
319319
@available(*, unavailable, message: "Please use threads or posix_spawn*()")
320320
public func fork() -> Int32 {
321321
fatalError("unavailable function can't be called")
@@ -331,7 +331,7 @@ public func vfork() -> Int32 {
331331
// signal.h
332332
//===----------------------------------------------------------------------===//
333333

334-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
334+
#if canImport(Darwin)
335335
public var SIG_DFL: sig_t? { return nil }
336336
public var SIG_IGN: sig_t { return unsafeBitCast(1, to: sig_t.self) }
337337
public var SIG_ERR: sig_t { return unsafeBitCast(-1, to: sig_t.self) }
@@ -395,10 +395,10 @@ public typealias Semaphore = UnsafeMutablePointer<sem_t>
395395

396396
/// The value returned by `sem_open()` in the case of failure.
397397
public var SEM_FAILED: Semaphore? {
398-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
399-
// The value is ABI. Value verified to be correct for OS X, iOS, watchOS, tvOS.
398+
#if canImport(Darwin)
399+
// The value is ABI. Value verified to be correct for macOS, iOS, watchOS, tvOS.
400400
return Semaphore(bitPattern: -1)
401-
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
401+
#elseif canImport(Glibc)
402402
// The value is ABI. Value verified to be correct on Glibc.
403403
return Semaphore(bitPattern: 0)
404404
#else
@@ -429,7 +429,7 @@ public func sem_open(
429429
//===----------------------------------------------------------------------===//
430430

431431
// Some platforms don't have `extern char** environ` imported from C.
432-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD) || os(OpenBSD) || os(PS4)
432+
#if canImport(Darwin) || os(FreeBSD) || os(OpenBSD) || os(PS4)
433433
public var environ: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?> {
434434
return _swift_stdlib_getEnviron()
435435
}

stdlib/public/Platform/TiocConstants.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Tty ioctl request constants, needed only on Darwin and FreeBSD.
1414

1515
// Constants available on all platforms, also available on Linux.
16-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(FreeBSD) || os(Haiku)
16+
#if canImport(Darwin) || os(FreeBSD) || os(Haiku)
1717

1818
/// Set exclusive use of tty.
1919
public var TIOCEXCL: UInt { return 0x2000740d }
@@ -115,7 +115,7 @@ public var TIOCGLTC: UInt { return 0x40067474 }
115115

116116

117117
// Darwin only constants, also available on Linux.
118-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
118+
#if canImport(Darwin)
119119

120120
/// Get termios struct.
121121
public var TIOCGETA: UInt { return 0x40487413 }

stdlib/public/Platform/tgmath.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public func ${ufunc}(_ x: ${T}) -> ${T} {
234234

235235
% end
236236

237-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
237+
#if canImport(Darwin)
238238
// Unary intrinsic functions
239239
// Note these have a corresponding LLVM intrinsic
240240
% for T, ufunc in TypedUnaryIntrinsicFunctions():

stdlib/public/core/Availability.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public func _stdlib_isOSVersionAtLeast(
2424
_ minor: Builtin.Word,
2525
_ patch: Builtin.Word
2626
) -> Builtin.Int1 {
27-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
27+
#if canImport(Darwin)
2828
if Int(major) == 9999 {
2929
return true._value
3030
}

stdlib/public/core/CTypes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public typealias CFloat = Float
6767
public typealias CDouble = Double
6868

6969
/// The C 'long double' type.
70-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
70+
#if canImport(Darwin)
7171
// On Darwin, long double is Float80 on x86, and Double otherwise.
7272
#if arch(x86_64) || arch(i386)
7373
public typealias CLongDouble = Float80
@@ -231,7 +231,7 @@ extension UInt {
231231
}
232232

233233
/// A wrapper around a C `va_list` pointer.
234-
#if arch(arm64) && !(os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(Windows))
234+
#if arch(arm64) && !(canImport(Darwin) || os(Windows))
235235
@frozen
236236
public struct CVaListPointer {
237237
@usableFromInline // unsafe-performance

stdlib/public/core/UnicodeScalarProperties.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ extension Unicode.Scalar.Properties {
590590
return _hasBinaryProperty(__swift_stdlib_UCHAR_CHANGES_WHEN_NFKC_CASEFOLDED)
591591
}
592592

593-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
593+
#if canImport(Darwin)
594594
// FIXME: These properties were introduced in ICU 57, but Ubuntu 16.04 comes
595595
// with ICU 55 so the values won't be correct there. Exclude them on
596596
// non-Darwin platforms for now; bundling ICU with the toolchain would resolve

0 commit comments

Comments
 (0)