diff --git a/Package.swift b/Package.swift index 7bad06be45..b12c0f8357 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.10 +// swift-tools-version:6.0 //===----------------------------------------------------------------------===// // // This source file is part of the SwiftNIO open source project @@ -23,23 +23,7 @@ let swiftSystem: PackageDescription.Target.Dependency = .product(name: "SystemPa // compatibility with previous NIO versions. let historicalNIOPosixDependencyRequired: [Platform] = [.macOS, .iOS, .tvOS, .watchOS, .linux, .android] -let strictConcurrencyDevelopment = false - -let strictConcurrencySettings: [SwiftSetting] = { - var initialSettings: [SwiftSetting] = [] - initialSettings.append(contentsOf: [ - .enableUpcomingFeature("StrictConcurrency"), - .enableUpcomingFeature("InferSendableFromCaptures"), - ]) - - if strictConcurrencyDevelopment { - // -warnings-as-errors here is a workaround so that IDE-based development can - // get tripped up on -require-explicit-sendable. - initialSettings.append(.unsafeFlags(["-require-explicit-sendable", "-warnings-as-errors"])) - } - - return initialSettings -}() +let swiftSettings: [SwiftSetting] = [] // This doesn't work when cross-compiling: the privacy manifest will be included in the Bundle and // Foundation will be linked. This is, however, strictly better than unconditionally adding the @@ -83,15 +67,15 @@ let package = Package( swiftCollections, swiftAtomics, ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .target( name: "_NIODataStructures", - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .target( name: "_NIOBase64", - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .target( name: "NIOEmbedded", @@ -102,7 +86,7 @@ let package = Package( swiftAtomics, swiftCollections, ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .target( name: "NIOPosix", @@ -118,7 +102,7 @@ let package = Package( ], exclude: includePrivacyManifest ? [] : ["PrivacyInfo.xcprivacy"], resources: includePrivacyManifest ? [.copy("PrivacyInfo.xcprivacy")] : [], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .target( name: "NIO", @@ -127,7 +111,7 @@ let package = Package( "NIOEmbedded", "NIOPosix", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .target( name: "_NIOConcurrency", @@ -135,7 +119,7 @@ let package = Package( .target(name: "NIO", condition: .when(platforms: historicalNIOPosixDependencyRequired)), "NIOCore", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .target( name: "NIOFoundationCompat", @@ -143,7 +127,7 @@ let package = Package( .target(name: "NIO", condition: .when(platforms: historicalNIOPosixDependencyRequired)), "NIOCore", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .target( name: "CNIOAtomics", @@ -190,7 +174,7 @@ let package = Package( dependencies: [ "CNIOAtomics" ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .target( name: "NIOHTTP1", @@ -201,7 +185,7 @@ let package = Package( "CNIOLLHTTP", swiftCollections, ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .target( name: "NIOWebSocket", @@ -212,7 +196,7 @@ let package = Package( "CNIOSHA1", "_NIOBase64", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .target( name: "CNIOLLHTTP", @@ -228,7 +212,7 @@ let package = Package( "NIOCore", swiftCollections, ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .target( name: "NIOTestUtils", @@ -239,7 +223,7 @@ let package = Package( "NIOHTTP1", swiftAtomics, ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .target( name: "NIOFS", @@ -255,7 +239,7 @@ let package = Package( path: "Sources/NIOFS", exclude: includePrivacyManifest ? [] : ["PrivacyInfo.xcprivacy"], resources: includePrivacyManifest ? [.copy("PrivacyInfo.xcprivacy")] : [], - swiftSettings: strictConcurrencySettings + [ + swiftSettings: swiftSettings + [ .define("ENABLE_MOCKING", .when(configuration: .debug)) ] ), @@ -266,7 +250,7 @@ let package = Package( "NIOFoundationCompat", ], path: "Sources/NIOFSFoundationCompat", - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .target( @@ -283,7 +267,7 @@ let package = Package( path: "Sources/_NIOFileSystem", exclude: includePrivacyManifest ? [] : ["PrivacyInfo.xcprivacy"], resources: includePrivacyManifest ? [.copy("PrivacyInfo.xcprivacy")] : [], - swiftSettings: strictConcurrencySettings + [ + swiftSettings: swiftSettings + [ .define("ENABLE_MOCKING", .when(configuration: .debug)) ] ), @@ -294,12 +278,12 @@ let package = Package( "NIOFoundationCompat", ], path: "Sources/_NIOFileSystemFoundationCompat", - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .target( name: "NIOFileSystem", dependencies: ["_NIOFileSystem"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), // MARK: - Examples @@ -311,7 +295,7 @@ let package = Package( "NIOCore", ], exclude: ["README.md"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .executableTarget( name: "NIOTCPEchoClient", @@ -320,7 +304,7 @@ let package = Package( "NIOCore", ], exclude: ["README.md"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .executableTarget( name: "NIOEchoServer", @@ -330,7 +314,7 @@ let package = Package( "NIOConcurrencyHelpers", ], exclude: ["README.md"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .executableTarget( name: "NIOEchoClient", @@ -340,7 +324,7 @@ let package = Package( "NIOConcurrencyHelpers", ], exclude: ["README.md"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .executableTarget( name: "NIOHTTP1Server", @@ -351,7 +335,7 @@ let package = Package( "NIOConcurrencyHelpers", ], exclude: ["README.md"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .executableTarget( name: "NIOHTTP1Client", @@ -362,7 +346,7 @@ let package = Package( "NIOConcurrencyHelpers", ], exclude: ["README.md"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .executableTarget( name: "NIOChatServer", @@ -372,7 +356,7 @@ let package = Package( "NIOConcurrencyHelpers", ], exclude: ["README.md"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .executableTarget( name: "NIOChatClient", @@ -382,7 +366,7 @@ let package = Package( "NIOConcurrencyHelpers", ], exclude: ["README.md"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .executableTarget( name: "NIOWebSocketServer", @@ -393,7 +377,7 @@ let package = Package( "NIOWebSocket", ], exclude: ["README.md"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .executableTarget( name: "NIOWebSocketClient", @@ -404,7 +388,7 @@ let package = Package( "NIOWebSocket", ], exclude: ["README.md"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .executableTarget( name: "NIOMulticastChat", @@ -412,7 +396,7 @@ let package = Package( "NIOPosix", "NIOCore", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .executableTarget( name: "NIOUDPEchoServer", @@ -421,7 +405,7 @@ let package = Package( "NIOCore", ], exclude: ["README.md"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .executableTarget( name: "NIOUDPEchoClient", @@ -430,7 +414,7 @@ let package = Package( "NIOCore", ], exclude: ["README.md"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .executableTarget( name: "NIOAsyncAwaitDemo", @@ -439,7 +423,7 @@ let package = Package( "NIOCore", "NIOHTTP1", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), // MARK: - Tests @@ -454,7 +438,7 @@ let package = Package( "NIOFoundationCompat", "NIOWebSocket", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .executableTarget( name: "NIOCrashTester", @@ -466,7 +450,7 @@ let package = Package( "NIOWebSocket", "NIOFoundationCompat", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .testTarget( name: "NIOCoreTests", @@ -478,7 +462,7 @@ let package = Package( "NIOTestUtils", swiftAtomics, ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .testTarget( name: "NIOEmbeddedTests", @@ -487,7 +471,7 @@ let package = Package( "NIOCore", "NIOEmbedded", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .testTarget( name: "NIOPosixTests", @@ -502,7 +486,7 @@ let package = Package( "CNIODarwin", "NIOTLS", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .testTarget( name: "NIOConcurrencyHelpersTests", @@ -510,17 +494,17 @@ let package = Package( "NIOConcurrencyHelpers", "NIOCore", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .testTarget( name: "NIODataStructuresTests", dependencies: ["_NIODataStructures"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .testTarget( name: "NIOBase64Tests", dependencies: ["_NIOBase64"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .testTarget( name: "NIOHTTP1Tests", @@ -532,7 +516,7 @@ let package = Package( "NIOFoundationCompat", "NIOTestUtils", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .testTarget( name: "NIOTLSTests", @@ -543,7 +527,7 @@ let package = Package( "NIOFoundationCompat", "NIOTestUtils", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .testTarget( name: "NIOWebSocketTests", @@ -552,7 +536,7 @@ let package = Package( "NIOEmbedded", "NIOWebSocket", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .testTarget( name: "NIOTestUtilsTests", @@ -562,7 +546,7 @@ let package = Package( "NIOEmbedded", "NIOPosix", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .testTarget( name: "NIOFoundationCompatTests", @@ -570,17 +554,17 @@ let package = Package( "NIOCore", "NIOFoundationCompat", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .testTarget( name: "NIOTests", dependencies: ["NIO"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .testTarget( name: "NIOSingletonsTests", dependencies: ["NIOCore", "NIOPosix"], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .testTarget( name: "NIOFSTests", @@ -591,7 +575,7 @@ let package = Package( swiftCollections, swiftSystem, ], - swiftSettings: strictConcurrencySettings + [ + swiftSettings: swiftSettings + [ .define("ENABLE_MOCKING", .when(configuration: .debug)) ] ), @@ -609,7 +593,7 @@ let package = Package( // the build. "Test Data" ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), .testTarget( name: "NIOFSFoundationCompatTests", @@ -617,7 +601,7 @@ let package = Package( "NIOFS", "NIOFSFoundationCompat", ], - swiftSettings: strictConcurrencySettings + swiftSettings: swiftSettings ), ] ) diff --git a/README.md b/README.md index 76083ea700..5e858fd9bb 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,8 @@ SwiftNIO | Minimum Swift Version `2.60.0 ..< 2.65.0` | 5.7 `2.65.0 ..< 2.76.0` | 5.8 `2.76.0 ..< 2.83.0` | 5.9 -`2.83.0 ...` | 5.10 +`2.83.0 ..< 2.87.0` | 5.10 +`2.87.0 ... ` | 6.0 ### SwiftNIO 1 SwiftNIO 1 is considered end of life - it is strongly recommended that you move to a newer version. The Core NIO team does not actively work on this version. No new features will be added to this version but PRs which fix bugs or security vulnerabilities will be accepted until the end of May 2022. diff --git a/Sources/NIOConcurrencyHelpers/NIOAtomic.swift b/Sources/NIOConcurrencyHelpers/NIOAtomic.swift index b67e6847d8..f2308ec929 100644 --- a/Sources/NIOConcurrencyHelpers/NIOAtomic.swift +++ b/Sources/NIOConcurrencyHelpers/NIOAtomic.swift @@ -19,7 +19,6 @@ import CNIOAtomics /// **Do not add conformance to this protocol for arbitrary types**. Only a small range /// of types have appropriate atomic operations supported by the CPU, and those types /// already have conformances implemented. -#if compiler(>=6.0) @preconcurrency public protocol NIOAtomicPrimitive { associatedtype AtomicWrapper @@ -35,18 +34,6 @@ public protocol NIOAtomicPrimitive { static var nio_atomic_load: @Sendable (UnsafeMutablePointer) -> Self { get } static var nio_atomic_store: @Sendable (UnsafeMutablePointer, Self) -> Void { get } } -#else -public protocol NIOAtomicPrimitive { - associatedtype AtomicWrapper - static var nio_atomic_create_with_existing_storage: (UnsafeMutablePointer, Self) -> Void { get } - static var nio_atomic_compare_and_exchange: (UnsafeMutablePointer, Self, Self) -> Bool { get } - static var nio_atomic_add: (UnsafeMutablePointer, Self) -> Self { get } - static var nio_atomic_sub: (UnsafeMutablePointer, Self) -> Self { get } - static var nio_atomic_exchange: (UnsafeMutablePointer, Self) -> Self { get } - static var nio_atomic_load: (UnsafeMutablePointer) -> Self { get } - static var nio_atomic_store: (UnsafeMutablePointer, Self) -> Void { get } -} -#endif extension Bool: NIOAtomicPrimitive { public typealias AtomicWrapper = catmc_nio_atomic__Bool diff --git a/Sources/NIOConcurrencyHelpers/atomics.swift b/Sources/NIOConcurrencyHelpers/atomics.swift index 75a2f90ee2..d472b083e8 100644 --- a/Sources/NIOConcurrencyHelpers/atomics.swift +++ b/Sources/NIOConcurrencyHelpers/atomics.swift @@ -297,7 +297,6 @@ extension Atomic: @unchecked Sendable where T: Sendable {} /// **Do not add conformance to this protocol for arbitrary types**. Only a small range /// of types have appropriate atomic operations supported by the CPU, and those types /// already have conformances implemented. -#if compiler(>=6.0) @preconcurrency public protocol AtomicPrimitive { static var atomic_create: @Sendable (Self) -> OpaquePointer { get } @@ -309,18 +308,6 @@ public protocol AtomicPrimitive { static var atomic_load: @Sendable (OpaquePointer) -> Self { get } static var atomic_store: @Sendable (OpaquePointer, Self) -> Void { get } } -#else -public protocol AtomicPrimitive { - static var atomic_create: (Self) -> OpaquePointer { get } - static var atomic_destroy: (OpaquePointer) -> Void { get } - static var atomic_compare_and_exchange: (OpaquePointer, Self, Self) -> Bool { get } - static var atomic_add: (OpaquePointer, Self) -> Self { get } - static var atomic_sub: (OpaquePointer, Self) -> Self { get } - static var atomic_exchange: (OpaquePointer, Self) -> Self { get } - static var atomic_load: (OpaquePointer) -> Self { get } - static var atomic_store: (OpaquePointer, Self) -> Void { get } -} -#endif extension Bool: AtomicPrimitive { public static let atomic_create = catmc_atomic__Bool_create diff --git a/Sources/NIOCore/AsyncChannel/AsyncChannel.swift b/Sources/NIOCore/AsyncChannel/AsyncChannel.swift index ee761680a6..050b72b7bf 100644 --- a/Sources/NIOCore/AsyncChannel/AsyncChannel.swift +++ b/Sources/NIOCore/AsyncChannel/AsyncChannel.swift @@ -323,11 +323,6 @@ public struct NIOAsyncChannel: Sendable { return result } - #if compiler(>=6.0) - // Note: Whitespace changes are used to workaround compiler bug - // Remove when compiler version 5.10 is no longer supported. - // https://github.com/swiftlang/swift/issues/79285 - // swift-format-ignore /// Provides scoped access to the inbound and outbound side of the underlying ``Channel``. /// /// - Important: After this method returned the underlying ``Channel`` will be closed. @@ -335,7 +330,11 @@ public struct NIOAsyncChannel: Sendable { /// - Parameters: /// - actor: actor where this function should be isolated to /// - body: A closure that gets scoped access to the inbound and outbound. - public func executeThenClose(isolation actor: isolated (any Actor)? = #isolation, _ body: (_ inbound: NIOAsyncChannelInboundStream, _ outbound: NIOAsyncChannelOutboundWriter) async throws -> sending Result) async throws -> sending Result { + public func executeThenClose( + isolation actor: isolated (any Actor)? = #isolation, + _ body: (_ inbound: NIOAsyncChannelInboundStream, _ outbound: NIOAsyncChannelOutboundWriter) + async throws -> sending Result + ) async throws -> sending Result { let result: Result do { result = try await body(self._inbound, self._outbound) @@ -370,7 +369,6 @@ public struct NIOAsyncChannel: Sendable { return result } - #endif } // swift-format-ignore: AmbiguousTrailingClosureOverload @@ -419,11 +417,6 @@ extension NIOAsyncChannel { return result } - #if compiler(>=6.0) - // Note: Whitespace changes are used to workaround compiler bug - // Remove when compiler version 5.10 is no longer supported. - // https://github.com/swiftlang/swift/issues/79285 - // swift-format-ignore /// Provides scoped access to the inbound side of the underlying ``Channel``. /// /// - Important: After this method returned the underlying ``Channel`` will be closed. @@ -431,7 +424,10 @@ extension NIOAsyncChannel { /// - Parameters: /// - actor: actor where this function should be isolated to /// - body: A closure that gets scoped access to the inbound. - public func executeThenClose(isolation actor: isolated (any Actor)? = #isolation, _ body: (_ inbound: NIOAsyncChannelInboundStream) async throws -> sending Result) async throws -> sending Result where Outbound == Never { + public func executeThenClose( + isolation actor: isolated (any Actor)? = #isolation, + _ body: (_ inbound: NIOAsyncChannelInboundStream) async throws -> sending Result + ) async throws -> sending Result where Outbound == Never { let result: Result do { result = try await body(self._inbound) @@ -466,7 +462,6 @@ extension NIOAsyncChannel { return result } - #endif } extension Channel { diff --git a/Sources/NIOCore/BSDSocketAPI.swift b/Sources/NIOCore/BSDSocketAPI.swift index 34a9db9983..4b0972c755 100644 --- a/Sources/NIOCore/BSDSocketAPI.swift +++ b/Sources/NIOCore/BSDSocketAPI.swift @@ -102,15 +102,9 @@ private let sysInet_pton: @convention(c) (CInt, UnsafePointer?, UnsafeMut #endif #if os(Android) -#if compiler(>=6.0) @usableFromInline let IFF_BROADCAST: CUnsignedInt = numericCast(Android.IFF_BROADCAST.rawValue) @usableFromInline let IFF_POINTOPOINT: CUnsignedInt = numericCast(Android.IFF_POINTOPOINT.rawValue) @usableFromInline let IFF_MULTICAST: CUnsignedInt = numericCast(Android.IFF_MULTICAST.rawValue) -#else -@usableFromInline let IFF_BROADCAST: CUnsignedInt = numericCast(SwiftGlibc.IFF_BROADCAST.rawValue) -@usableFromInline let IFF_POINTOPOINT: CUnsignedInt = numericCast(SwiftGlibc.IFF_POINTOPOINT.rawValue) -@usableFromInline let IFF_MULTICAST: CUnsignedInt = numericCast(SwiftGlibc.IFF_MULTICAST.rawValue) -#endif #if arch(arm) @usableFromInline let SO_RCVTIMEO = SO_RCVTIMEO_OLD @usableFromInline let SO_TIMESTAMP = SO_TIMESTAMP_OLD diff --git a/Sources/NIOCore/ByteBuffer-aux.swift b/Sources/NIOCore/ByteBuffer-aux.swift index 39db01bc4f..60e57dd300 100644 --- a/Sources/NIOCore/ByteBuffer-aux.swift +++ b/Sources/NIOCore/ByteBuffer-aux.swift @@ -1003,7 +1003,6 @@ extension Optional where Wrapped == ByteBuffer { } } -#if compiler(>=6) extension ByteBuffer { /// Get the string at `index` from this `ByteBuffer` decoding using the UTF-8 encoding. Does not move the reader index. /// The selected bytes must be readable or else `nil` will be returned. @@ -1077,4 +1076,3 @@ extension ByteBuffer { try self.getUTF8ValidatedString(at: self.readerIndex, length: length) } } -#endif // compiler(>=6) diff --git a/Sources/NIOCore/NIOLoopBound.swift b/Sources/NIOCore/NIOLoopBound.swift index ad216fd5c7..9f843b834b 100644 --- a/Sources/NIOCore/NIOLoopBound.swift +++ b/Sources/NIOCore/NIOLoopBound.swift @@ -139,17 +139,16 @@ public final class NIOLoopBoundBox: @unchecked Sendable { .init(_value: value, uncheckedEventLoop: eventLoop) } - #if compiler(>=6.0) - // Note: Whitespace changes are used to workaround compiler bug - // Remove when compiler version 5.10 is no longer supported. - // https://github.com/swiftlang/swift/issues/79285 - // swift-format-ignore /// Initialise a ``NIOLoopBoundBox`` by sending a value, validly callable off `eventLoop`. /// /// Contrary to ``init(_:eventLoop:)``, this method can be called off `eventLoop` because `value` is moved into the box and can no longer be accessed outside the box. /// So we don't need to protect `value` itself, we just need to protect the ``NIOLoopBoundBox`` against mutations which we do because the ``value`` /// accessors are checking that we're on `eventLoop`. - public static func makeBoxSendingValue(_ value: sending Value, as: Value.Type = Value.self, eventLoop: EventLoop) -> NIOLoopBoundBox { + public static func makeBoxSendingValue( + _ value: sending Value, + as: Value.Type = Value.self, + eventLoop: EventLoop + ) -> NIOLoopBoundBox { // Here, we -- possibly surprisingly -- do not precondition being on the EventLoop. This is okay for a few // reasons: // - This function takes its value as `sending` so we don't need to worry about somebody @@ -159,7 +158,6 @@ public final class NIOLoopBoundBox: @unchecked Sendable { // - The only way to ever write (or read indeed) `self._value` is by proving to be inside the `EventLoop`. .init(_value: value, uncheckedEventLoop: eventLoop) } - #endif /// Access the `value` with the precondition that the code is running on `eventLoop`. /// diff --git a/Sources/NIOCrashTester/CrashTests+EventLoop.swift b/Sources/NIOCrashTester/CrashTests+EventLoop.swift index bd6d55207d..3487fcff02 100644 --- a/Sources/NIOCrashTester/CrashTests+EventLoop.swift +++ b/Sources/NIOCrashTester/CrashTests+EventLoop.swift @@ -180,7 +180,7 @@ struct EventLoopCrashTests { NIOSingletons.groupLoopCountSuggestion = -1 } - #if compiler(>=5.9) && swift(<6.2) // We only support Concurrency executor take-over on those Swift versions, as versions greater than that have not been properly tested. + #if swift(<6.2) // We only support Concurrency executor take-over on those Swift versions, as versions greater than that have not been properly tested. let testInstallingSingletonMTELGAsConcurrencyExecutorWorksButOnlyOnce = CrashTest( regex: #"Fatal error: Must be called only once"# ) { @@ -207,6 +207,6 @@ struct EventLoopCrashTests { // This should crash _ = NIOSingletons.unsafeTryInstallSingletonPosixEventLoopGroupAsConcurrencyGlobalExecutor() } - #endif // compiler(>=5.9) && swift(<6.2) + #endif // swift(<6.2) } #endif // !canImport(Darwin) || os(macOS) diff --git a/Sources/NIOFS/Internal/System Calls/FileDescriptor+Syscalls.swift b/Sources/NIOFS/Internal/System Calls/FileDescriptor+Syscalls.swift index 2941243999..db13935c72 100644 --- a/Sources/NIOFS/Internal/System Calls/FileDescriptor+Syscalls.swift +++ b/Sources/NIOFS/Internal/System Calls/FileDescriptor+Syscalls.swift @@ -207,18 +207,20 @@ extension FileDescriptor { } // Read and decode. - var buffer = [CChar](repeating: 0, count: capacity) + var buffer = [UInt8](repeating: 0, count: capacity) return buffer.withUnsafeMutableBufferPointer { pointer in - self.listExtendedAttributes(pointer) + pointer.withMemoryRebound(to: CChar.self) { pointer in + self.listExtendedAttributes(pointer) + } }.map { size in // The buffer contains null terminated C-strings. var attributes = [String]() var slice = buffer.prefix(size) while let index = slice.firstIndex(of: 0) { // TODO: can we do this more cheaply? - let prefix = slice[...index] - attributes.append(String(cString: Array(prefix))) - slice = slice.dropFirst(prefix.count) + let prefix = slice[..) { - // Need to #if because CChar may be signed - self.init(validatingUTF8: platformString) - } - internal init( _errorCorrectingPlatformString platformString: UnsafePointer ) { diff --git a/Sources/NIOFS/Internal/System Calls/Syscall.swift b/Sources/NIOFS/Internal/System Calls/Syscall.swift index c3965c0f5d..7b672096bd 100644 --- a/Sources/NIOFS/Internal/System Calls/Syscall.swift +++ b/Sources/NIOFS/Internal/System Calls/Syscall.swift @@ -364,19 +364,22 @@ public enum Libc: Sendable { #if !os(Android) static func constr(_ name: CInt) -> Result { - var buffer = [CInterop.PlatformChar](repeating: 0, count: 128) + var buffer = [UInt8](repeating: 0, count: 128) repeat { let result = valueOrErrno(retryOnInterrupt: false) { buffer.withUnsafeMutableBufferPointer { pointer in - libc_confstr(name, pointer.baseAddress!, pointer.count) + pointer.withMemoryRebound(to: CInterop.PlatformChar.self) { buffer in + libc_confstr(name, buffer.baseAddress!, buffer.count) + } } } switch result { case let .success(length): if length <= buffer.count { - return .success(String(cString: buffer)) + let nullTerminationIndex = buffer.firstIndex(of: 0) ?? buffer.endIndex + return .success(String(decoding: buffer[..=6.0) static let SOCK_CLOEXEC = Android.SOCK_CLOEXEC static let SOCK_NONBLOCK = Android.SOCK_NONBLOCK - #else - static let SOCK_CLOEXEC = Glibc.SOCK_CLOEXEC - static let SOCK_NONBLOCK = Glibc.SOCK_NONBLOCK - #endif #elseif canImport(Musl) static let SOCK_CLOEXEC = Musl.SOCK_CLOEXEC static let SOCK_NONBLOCK = Musl.SOCK_NONBLOCK diff --git a/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift b/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift index d9dd2eab4b..63a0f55265 100644 --- a/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift +++ b/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift @@ -624,7 +624,6 @@ extension NIODeadline { } extension MultiThreadedEventLoopGroup { - #if compiler(>=6.0) /// Start & automatically shut down a new ``MultiThreadedEventLoopGroup``. /// /// This method allows to start & automatically dispose of a ``MultiThreadedEventLoopGroup`` following the principle of Structured Concurrency. @@ -660,5 +659,4 @@ extension MultiThreadedEventLoopGroup { } } } - #endif } diff --git a/Sources/NIOPosix/PosixSingletons+ConcurrencyTakeOver.swift b/Sources/NIOPosix/PosixSingletons+ConcurrencyTakeOver.swift index cc79c676d4..3ca4708e15 100644 --- a/Sources/NIOPosix/PosixSingletons+ConcurrencyTakeOver.swift +++ b/Sources/NIOPosix/PosixSingletons+ConcurrencyTakeOver.swift @@ -44,7 +44,7 @@ extension NIOSingletons { return false #else // Guard between the minimum and maximum supported version for the hook - #if compiler(>=5.9) && compiler(<6.3) + #if compiler(<6.3) guard #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) else { return false } diff --git a/Sources/NIOPosix/StructuredConcurrencyHelpers.swift b/Sources/NIOPosix/StructuredConcurrencyHelpers.swift index 07afda6f6a..012ef95647 100644 --- a/Sources/NIOPosix/StructuredConcurrencyHelpers.swift +++ b/Sources/NIOPosix/StructuredConcurrencyHelpers.swift @@ -25,18 +25,14 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -// swift-format-ignore -// Note: Whitespace changes are used to workaround compiler bug -// https://github.com/swiftlang/swift/issues/79285 -#if compiler(>=6.0) @inlinable @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) internal func asyncDo( isolation: isolated (any Actor)? = #isolation, - // DO NOT FIX THE WHITESPACE IN THE NEXT LINE UNTIL 5.10 IS UNSUPPORTED - // https://github.com/swiftlang/swift/issues/79285 - _ body: () async throws -> sending R, finally: sending @escaping ((any Error)?) async throws -> Void) async throws -> sending R { + _ body: () async throws -> sending R, + finally: sending @escaping ((any Error)?) async throws -> Void +) async throws -> sending R { let result: R do { result = try await body() @@ -62,36 +58,3 @@ internal func asyncDo( }.value return result } -#else -@inlinable -@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) -internal func asyncDo( - _ body: () async throws -> R, - finally: @escaping @Sendable ((any Error)?) async throws -> Void -) async throws -> R { - let result: R - do { - result = try await body() - } catch { - // `body` failed, we need to invoke `finally` with the `error`. - - // This _looks_ unstructured but isn't really because we unconditionally always await the return. - // We need to have an uncancelled task here to assure this is actually running in case we hit a - // cancellation error. - try await Task { - try await finally(error) - }.value - throw error - } - - // `body` succeeded, we need to invoke `finally` with `nil` (no error). - - // This _looks_ unstructured but isn't really because we unconditionally always await the return. - // We need to have an uncancelled task here to assure this is actually running in case we hit a - // cancellation error. - try await Task { - try await finally(nil) - }.value - return result -} -#endif diff --git a/Sources/NIOPosix/System.swift b/Sources/NIOPosix/System.swift index 7c5b972012..576f75c674 100644 --- a/Sources/NIOPosix/System.swift +++ b/Sources/NIOPosix/System.swift @@ -44,15 +44,9 @@ internal typealias MMsgHdr = CNIOWindows_mmsghdr #if os(Android) let INADDR_ANY = UInt32(0) // #define INADDR_ANY ((unsigned long int) 0x00000000) -#if compiler(>=6.0) let IFF_BROADCAST: CUnsignedInt = numericCast(Android.IFF_BROADCAST.rawValue) let IFF_POINTOPOINT: CUnsignedInt = numericCast(Android.IFF_POINTOPOINT.rawValue) let IFF_MULTICAST: CUnsignedInt = numericCast(Android.IFF_MULTICAST.rawValue) -#else -let IFF_BROADCAST: CUnsignedInt = numericCast(SwiftGlibc.IFF_BROADCAST.rawValue) -let IFF_POINTOPOINT: CUnsignedInt = numericCast(SwiftGlibc.IFF_POINTOPOINT.rawValue) -let IFF_MULTICAST: CUnsignedInt = numericCast(SwiftGlibc.IFF_MULTICAST.rawValue) -#endif internal typealias in_port_t = UInt16 extension ipv6_mreq { // http://lkml.iu.edu/hypermail/linux/kernel/0106.1/0080.html init(ipv6mr_multiaddr: in6_addr, ipv6mr_interface: UInt32) { @@ -63,21 +57,12 @@ extension ipv6_mreq { // http://lkml.iu.edu/hypermail/linux/kernel/0106.1/0080. } } #if arch(arm) -#if compiler(>=6.0) let S_IFSOCK = UInt32(Android.S_IFSOCK) let S_IFMT = UInt32(Android.S_IFMT) let S_IFREG = UInt32(Android.S_IFREG) let S_IFDIR = UInt32(Android.S_IFDIR) let S_IFLNK = UInt32(Android.S_IFLNK) let S_IFBLK = UInt32(Android.S_IFBLK) -#else -let S_IFSOCK = UInt32(SwiftGlibc.S_IFSOCK) -let S_IFMT = UInt32(SwiftGlibc.S_IFMT) -let S_IFREG = UInt32(SwiftGlibc.S_IFREG) -let S_IFDIR = UInt32(SwiftGlibc.S_IFDIR) -let S_IFLNK = UInt32(SwiftGlibc.S_IFLNK) -let S_IFBLK = UInt32(SwiftGlibc.S_IFBLK) -#endif #endif #endif diff --git a/Sources/NIOPosix/Thread.swift b/Sources/NIOPosix/Thread.swift index 9ed6165999..b730aba1b2 100644 --- a/Sources/NIOPosix/Thread.swift +++ b/Sources/NIOPosix/Thread.swift @@ -44,7 +44,6 @@ protocol ThreadOps { /// A Thread that executes some runnable block. /// /// All methods exposed are thread-safe. -// swift-format-ignore @usableFromInline final class NIOThread: Sendable { internal typealias ThreadBoxValue = (body: (NIOThread) -> Void, name: String?) diff --git a/Sources/NIOTestUtils/ManualTaskExecutor.swift b/Sources/NIOTestUtils/ManualTaskExecutor.swift index c87ff324fe..645c12cdff 100644 --- a/Sources/NIOTestUtils/ManualTaskExecutor.swift +++ b/Sources/NIOTestUtils/ManualTaskExecutor.swift @@ -12,8 +12,6 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6) - import DequeModule import Synchronization @@ -87,7 +85,7 @@ package func withManualTaskExecutor( /// - Returns: The value returned by `body`. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) @inlinable -package func withManualTaskExecutor( +package func withManualTaskExecutors( body: (ManualTaskExecutor, ManualTaskExecutor) async throws(Failure) -> T ) async throws(Failure) -> T { let taskExecutor1 = ManualTaskExecutor() @@ -162,5 +160,3 @@ package final class ManualTaskExecutor: TaskExecutor { } } } - -#endif // compiler(>=6) diff --git a/Sources/_NIOFileSystem/Internal/System Calls/FileDescriptor+Syscalls.swift b/Sources/_NIOFileSystem/Internal/System Calls/FileDescriptor+Syscalls.swift index 2941243999..0d824fca34 100644 --- a/Sources/_NIOFileSystem/Internal/System Calls/FileDescriptor+Syscalls.swift +++ b/Sources/_NIOFileSystem/Internal/System Calls/FileDescriptor+Syscalls.swift @@ -207,18 +207,20 @@ extension FileDescriptor { } // Read and decode. - var buffer = [CChar](repeating: 0, count: capacity) + var buffer = [UInt8](repeating: 0, count: capacity) return buffer.withUnsafeMutableBufferPointer { pointer in - self.listExtendedAttributes(pointer) + pointer.withMemoryRebound(to: CChar.self) { buffer in + self.listExtendedAttributes(buffer) + } }.map { size in // The buffer contains null terminated C-strings. var attributes = [String]() var slice = buffer.prefix(size) while let index = slice.firstIndex(of: 0) { // TODO: can we do this more cheaply? - let prefix = slice[...index] - attributes.append(String(cString: Array(prefix))) - slice = slice.dropFirst(prefix.count) + let prefix = slice[..) { // Need to #if because CChar may be signed - self.init(validatingUTF8: platformString) + self.init(validatingCString: platformString) } internal init( diff --git a/Sources/_NIOFileSystem/Internal/System Calls/Syscall.swift b/Sources/_NIOFileSystem/Internal/System Calls/Syscall.swift index c3965c0f5d..1520586458 100644 --- a/Sources/_NIOFileSystem/Internal/System Calls/Syscall.swift +++ b/Sources/_NIOFileSystem/Internal/System Calls/Syscall.swift @@ -364,19 +364,22 @@ public enum Libc: Sendable { #if !os(Android) static func constr(_ name: CInt) -> Result { - var buffer = [CInterop.PlatformChar](repeating: 0, count: 128) + var buffer = [UInt8](repeating: 0, count: 128) repeat { let result = valueOrErrno(retryOnInterrupt: false) { buffer.withUnsafeMutableBufferPointer { pointer in - libc_confstr(name, pointer.baseAddress!, pointer.count) + pointer.withMemoryRebound(to: CInterop.PlatformChar.self) { pointer in + libc_confstr(name, pointer.baseAddress!, pointer.count) + } } } switch result { case let .success(length): + let nullTerminationIndex = buffer.firstIndex(of: 0) ?? buffer.endIndex if length <= buffer.count { - return .success(String(cString: buffer)) + return .success(String(decoding: buffer[..=6.0) func testExecuteThenCloseFromActor() async throws { final actor TestActor { func test() async throws { @@ -547,7 +546,6 @@ final class AsyncChannelTests: XCTestCase { let r = try await actor.test() XCTAssertEqual(r.someMutableState, 5) } - #endif } // This is unchecked Sendable since we only call this in the testing eventloop diff --git a/Tests/NIOCoreTests/AsyncSequences/NIOAsyncWriterTests.swift b/Tests/NIOCoreTests/AsyncSequences/NIOAsyncWriterTests.swift index 97b601c73f..e5ede68615 100644 --- a/Tests/NIOCoreTests/AsyncSequences/NIOAsyncWriterTests.swift +++ b/Tests/NIOCoreTests/AsyncSequences/NIOAsyncWriterTests.swift @@ -607,11 +607,10 @@ final class NIOAsyncWriterTests: XCTestCase { self.assert(suspendCallCount: 1, yieldCallCount: 1, terminateCallCount: 1) } - #if compiler(>=6) @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) func testWriterFinish_AndSuspendBufferedYield() async throws { try await withThrowingTaskGroup(of: Void.self) { group in - try await withManualTaskExecutor { taskExecutor1, taskExecutor2 in + try await withManualTaskExecutors { taskExecutor1, taskExecutor2 in self.sink.setWritability(to: false) self.delegate.didYieldHandler = { _ in @@ -654,7 +653,6 @@ final class NIOAsyncWriterTests: XCTestCase { } } } - #endif // compiler(>=6) func testWriterFinish_whenFinished() { // This tests just checks that finishing again is a no-op diff --git a/Tests/NIOCoreTests/ByteBufferTest.swift b/Tests/NIOCoreTests/ByteBufferTest.swift index b869c4914c..780b2ffb9f 100644 --- a/Tests/NIOCoreTests/ByteBufferTest.swift +++ b/Tests/NIOCoreTests/ByteBufferTest.swift @@ -1316,7 +1316,6 @@ class ByteBufferTest: XCTestCase { } func testReadUTF8ValidatedString() throws { - #if compiler(>=6) guard #available(macOS 15, iOS 18, tvOS 18, watchOS 11, visionOS 2, *) else { throw XCTSkip("'readUTF8ValidatedString' is only available in Swift 6 and later") } @@ -1327,13 +1326,9 @@ class ByteBufferTest: XCTestCase { XCTAssertEqual(expected, actual) XCTAssertEqual("", try buf.readUTF8ValidatedString(length: 0)) XCTAssertNil(try buf.readUTF8ValidatedString(length: 1)) - #else - throw XCTSkip("'readUTF8ValidatedString' is only available in Swift 6 and later") - #endif // compiler(>=6) } func testGetUTF8ValidatedString() throws { - #if compiler(>=6) guard #available(macOS 15, iOS 18, tvOS 18, watchOS 11, visionOS 2, *) else { throw XCTSkip("'getUTF8ValidatedString' is only available in Swift 6 and later") } @@ -1342,13 +1337,9 @@ class ByteBufferTest: XCTestCase { buf.writeString(expected) let actual = try buf.getUTF8ValidatedString(at: 7, length: 7) XCTAssertEqual("goodbye", actual) - #else - throw XCTSkip("'getUTF8ValidatedString' is only available in Swift 6 and later") - #endif // compiler(>=6) } func testReadUTF8InvalidString() throws { - #if compiler(>=6) guard #available(macOS 15, iOS 18, tvOS 18, watchOS 11, visionOS 2, *) else { throw XCTSkip("'readUTF8ValidatedString' is only available in Swift 6 and later") } @@ -1363,9 +1354,6 @@ class ByteBufferTest: XCTestCase { } } XCTAssertEqual(buf.readableBytes, 16) - #else - throw XCTSkip("'readUTF8ValidatedString' is only available in Swift 6 and later") - #endif // compiler(>=6) } func testSetIntegerBeyondCapacity() throws { @@ -4227,7 +4215,6 @@ extension ByteBufferTest { // MARK: - peekUTF8ValidatedString Tests (available in Swift 6+) - #if compiler(>=6) func testPeekUTF8ValidatedString_Normal() throws { guard #available(macOS 15, iOS 18, tvOS 18, watchOS 11, visionOS 2, *) else { throw XCTSkip("'peekUTF8ValidatedString' is only available in Swift 6 and later") @@ -4267,7 +4254,6 @@ extension ByteBufferTest { ) XCTAssertEqual(buffer.readerIndex, 0, "peekUTF8ValidatedString() should not advance the reader index.") } - #endif // MARK: - peekDispatchData Tests (available when Dispatch is imported) diff --git a/Tests/NIOCoreTests/XCTest+AsyncAwait.swift b/Tests/NIOCoreTests/XCTest+AsyncAwait.swift index 9107a35518..0e7987d729 100644 --- a/Tests/NIOCoreTests/XCTest+AsyncAwait.swift +++ b/Tests/NIOCoreTests/XCTest+AsyncAwait.swift @@ -59,7 +59,7 @@ internal func XCTAssertThrowsError( @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) internal func XCTAssertNoThrow( _ expression: @autoclosure () async throws -> T, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) async { do { diff --git a/Tests/NIOFSIntegrationTests/XCTestExtensions.swift b/Tests/NIOFSIntegrationTests/XCTestExtensions.swift index 725eec0720..9ccf2c3bd2 100644 --- a/Tests/NIOFSIntegrationTests/XCTestExtensions.swift +++ b/Tests/NIOFSIntegrationTests/XCTestExtensions.swift @@ -17,7 +17,7 @@ import XCTest @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) func XCTAssertThrowsErrorAsync( - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line, expression: () async throws -> R, onError: (Error) -> Void = { _ in } @@ -32,7 +32,7 @@ func XCTAssertThrowsErrorAsync( func XCTAssertThrowsFileSystemError( _ expression: @autoclosure () throws -> R, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line, _ onError: (FileSystemError) -> Void = { _ in } ) { @@ -51,7 +51,7 @@ func XCTAssertThrowsFileSystemError( @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) func XCTAssertThrowsFileSystemErrorAsync( - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line, _ expression: () async throws -> R, onError: (FileSystemError) -> Void = { _ in } @@ -71,7 +71,7 @@ func XCTAssertThrowsFileSystemErrorAsync( func XCTAssertNoThrowAsync( _ expression: @autoclosure () async throws -> T, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) async { do { diff --git a/Tests/NIOFSTests/XCTestExtensions.swift b/Tests/NIOFSTests/XCTestExtensions.swift index 371c50b30f..3283e3d88d 100644 --- a/Tests/NIOFSTests/XCTestExtensions.swift +++ b/Tests/NIOFSTests/XCTestExtensions.swift @@ -17,7 +17,7 @@ import XCTest @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) func XCTAssertThrowsErrorAsync( - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line, expression: () async throws -> R, onError: (Error) -> Void = { _ in } @@ -32,7 +32,7 @@ func XCTAssertThrowsErrorAsync( func XCTAssertThrowsFileSystemError( _ expression: @autoclosure () throws -> R, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line, _ onError: (FileSystemError) -> Void = { _ in } ) { @@ -53,7 +53,7 @@ func XCTAssertSystemCallError( _ error: (any Error)?, name: String, errno: Errno, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { guard let systemCallError = error as? FileSystemError.SystemCallError else { diff --git a/Tests/NIOPosixTests/ChannelTests.swift b/Tests/NIOPosixTests/ChannelTests.swift index baf916f4ea..7473a56f68 100644 --- a/Tests/NIOPosixTests/ChannelTests.swift +++ b/Tests/NIOPosixTests/ChannelTests.swift @@ -3293,7 +3293,7 @@ final class ChannelTests: XCTestCase { func _testTCP_NODELAYDefaultValue( value: Bool, _ socketAddress: SocketAddress, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) throws { let singleThreadedELG = MultiThreadedEventLoopGroup(numberOfThreads: 1) diff --git a/Tests/NIOPosixTests/EventLoopTest.swift b/Tests/NIOPosixTests/EventLoopTest.swift index 93a5a70043..71e26646ef 100644 --- a/Tests/NIOPosixTests/EventLoopTest.swift +++ b/Tests/NIOPosixTests/EventLoopTest.swift @@ -2015,7 +2015,6 @@ final class EventLoopTest: XCTestCase { } } - #if compiler(>=6.0) func testStructuredConcurrencyMTELGStartStop() async throws { let loops = try await MultiThreadedEventLoopGroup.withEventLoopGroup( numberOfThreads: 3 @@ -2069,7 +2068,6 @@ final class EventLoopTest: XCTestCase { } XCTAssertEqual("cool", actual) } - #endif func testRegressionSelectableEventLoopDeadlock() throws { let iterations = 1_000 diff --git a/Tests/NIOPosixTests/NIOLoopBoundTests.swift b/Tests/NIOPosixTests/NIOLoopBoundTests.swift index e50ccf79c4..2e6b51e4fc 100644 --- a/Tests/NIOPosixTests/NIOLoopBoundTests.swift +++ b/Tests/NIOPosixTests/NIOLoopBoundTests.swift @@ -75,7 +75,6 @@ final class NIOLoopBoundTests: XCTestCase { ) } - #if compiler(>=6.0) func testLoopBoundBoxCanBeInitialisedWithTakingValueOffLoopAndLaterSetToValue() { let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { @@ -106,7 +105,6 @@ final class NIOLoopBoundTests: XCTestCase { }.wait() ) } - #endif func testInPlaceMutation() { var loopBound = NIOLoopBound(CoWValue(), eventLoop: loop) diff --git a/Tests/NIOPosixTests/NIOScheduledCallbackTests.swift b/Tests/NIOPosixTests/NIOScheduledCallbackTests.swift index 253aadcfdb..4caa11f622 100644 --- a/Tests/NIOPosixTests/NIOScheduledCallbackTests.swift +++ b/Tests/NIOPosixTests/NIOScheduledCallbackTests.swift @@ -390,7 +390,7 @@ private final class MockScheduledCallbackHandler: NIOScheduledCallbackHandler, S self.cancelCount.wrappingIncrement(by: 1, ordering: .sequentiallyConsistent) } - func assert(callbackCount: Int, cancelCount: Int, file: StaticString = #file, line: UInt = #line) { + func assert(callbackCount: Int, cancelCount: Int, file: StaticString = #filePath, line: UInt = #line) { XCTAssertEqual( self.callbackCount.load(ordering: .sequentiallyConsistent), callbackCount, @@ -407,7 +407,7 @@ private final class MockScheduledCallbackHandler: NIOScheduledCallbackHandler, S ) } - func waitForCallback(timeout: TimeAmount, file: StaticString = #file, line: UInt = #line) async throws { + func waitForCallback(timeout: TimeAmount, file: StaticString = #filePath, line: UInt = #line) async throws { try await XCTWithTimeout(timeout, file: file, line: line) { await self.callbackStream.first { _ in true } } } } @@ -424,7 +424,7 @@ private final class NonSendableMockScheduledCallbackHandler: NIOScheduledCallbac self.cancelCount += 1 } - func assert(callbackCount: Int, cancelCount: Int, file: StaticString = #file, line: UInt = #line) { + func assert(callbackCount: Int, cancelCount: Int, file: StaticString = #filePath, line: UInt = #line) { XCTAssertEqual( self.callbackCount, callbackCount, @@ -457,7 +457,7 @@ private final class NonSendableMockScheduledCallbackHandler: NIOScheduledCallbac /// This function is probably a good balance of pragmatism and clarity. func XCTWithTimeout( _ timeout: TimeAmount, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line, operation: @escaping @Sendable () async throws -> Result ) async throws -> Result where Result: Sendable { diff --git a/Tests/NIOPosixTests/SerialExecutorTests.swift b/Tests/NIOPosixTests/SerialExecutorTests.swift index 3c69698d0f..b95bf28523 100644 --- a/Tests/NIOPosixTests/SerialExecutorTests.swift +++ b/Tests/NIOPosixTests/SerialExecutorTests.swift @@ -36,13 +36,11 @@ actor EventLoopBoundActor { XCTAssertFalse(loop.inEventLoop) } - #if compiler(>=6.0) nonisolated func assumeInLoop() -> Int { self.assumeIsolated { actor in actor.counter } } - #endif } @available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) @@ -78,10 +76,6 @@ final class SerialExecutorTests: XCTestCase { } func testAssumeIsolation() async throws { - #if compiler(<6.0) - throw XCTSkip("Custom executors are only supported in 5.9") - #else - let el = self.group.next() let testActor = EventLoopBoundActor(loop: el) @@ -89,7 +83,6 @@ final class SerialExecutorTests: XCTestCase { testActor.assumeInLoop() }.get() XCTAssertEqual(result, 0) - #endif } override func setUp() { diff --git a/Tests/NIOPosixTests/TestUtils.swift b/Tests/NIOPosixTests/TestUtils.swift index 1d17d194ec..a70dcfb659 100644 --- a/Tests/NIOPosixTests/TestUtils.swift +++ b/Tests/NIOPosixTests/TestUtils.swift @@ -32,7 +32,9 @@ extension System { static var supportsVsockLoopback: Bool { #if os(Linux) || os(Android) - guard let modules = try? String(contentsOf: URL(fileURLWithPath: "/proc/modules")) else { return false } + guard let modules = try? String(contentsOf: URL(fileURLWithPath: "/proc/modules"), encoding: .utf8) else { + return false + } return modules.split(separator: "\n").compactMap({ $0.split(separator: " ").first }).contains("vsock_loopback") #else return false diff --git a/Tests/NIOPosixTests/ThreadTest.swift b/Tests/NIOPosixTests/ThreadTest.swift index 8f4fd72049..53333a3ce6 100644 --- a/Tests/NIOPosixTests/ThreadTest.swift +++ b/Tests/NIOPosixTests/ThreadTest.swift @@ -428,7 +428,8 @@ class ThreadTest: XCTestCase { } // MARK: - Helpers - static func joinThread(_ thread: NIOLockedValueBox, file: StaticString = #file, line: UInt = #line) { + static func joinThread(_ thread: NIOLockedValueBox, file: StaticString = #filePath, line: UInt = #line) + { if let thread = thread.withLockedValue({ $0 }) { thread.join() } else { diff --git a/Tests/NIOPosixTests/XCTest+AsyncAwait.swift b/Tests/NIOPosixTests/XCTest+AsyncAwait.swift index 3d58bffa3d..2c88cdb9bc 100644 --- a/Tests/NIOPosixTests/XCTest+AsyncAwait.swift +++ b/Tests/NIOPosixTests/XCTest+AsyncAwait.swift @@ -58,7 +58,7 @@ internal func XCTAssertThrowsError( @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) internal func XCTAssertNoThrow( _ expression: @autoclosure () async throws -> T, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) async { do { diff --git a/Tests/NIOTestUtilsTests/ManualTaskExecutorTest.swift b/Tests/NIOTestUtilsTests/ManualTaskExecutorTest.swift index 2b17234806..51a58b34dd 100644 --- a/Tests/NIOTestUtilsTests/ManualTaskExecutorTest.swift +++ b/Tests/NIOTestUtilsTests/ManualTaskExecutorTest.swift @@ -12,8 +12,6 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6) - import NIOTestUtils import Synchronization import XCTest @@ -40,7 +38,7 @@ class ManualTaskExecutorTest: XCTestCase { @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) func testTwoManualTaskExecutors() async { await withDiscardingTaskGroup { group in - await withManualTaskExecutor { taskExecutor1, taskExecutor2 in + await withManualTaskExecutors { taskExecutor1, taskExecutor2 in let task1DidRun = Mutex(false) let task2DidRun = Mutex(false) @@ -65,5 +63,3 @@ class ManualTaskExecutorTest: XCTestCase { } } } - -#endif // compiler(>=6)