Skip to content

Commit a3ed8e1

Browse files
fabianfettLukasa
andauthored
Drop Swift 5.10 (#3393)
This PR drops Swift 5.10 and enables Swift 6 language mode. --------- Co-authored-by: Cory Benfield <lukasa@apple.com>
1 parent 2143eb9 commit a3ed8e1

37 files changed

+123
-268
lines changed

Package.swift

Lines changed: 52 additions & 68 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ SwiftNIO | Minimum Swift Version
8686
`2.60.0 ..< 2.65.0` | 5.7
8787
`2.65.0 ..< 2.76.0` | 5.8
8888
`2.76.0 ..< 2.83.0` | 5.9
89-
`2.83.0 ...` | 5.10
89+
`2.83.0 ..< 2.87.0` | 5.10
90+
`2.87.0 ... ` | 6.0
9091

9192
### SwiftNIO 1
9293
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.

Sources/NIOConcurrencyHelpers/NIOAtomic.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import CNIOAtomics
1919
/// **Do not add conformance to this protocol for arbitrary types**. Only a small range
2020
/// of types have appropriate atomic operations supported by the CPU, and those types
2121
/// already have conformances implemented.
22-
#if compiler(>=6.0)
2322
@preconcurrency
2423
public protocol NIOAtomicPrimitive {
2524
associatedtype AtomicWrapper
@@ -35,18 +34,6 @@ public protocol NIOAtomicPrimitive {
3534
static var nio_atomic_load: @Sendable (UnsafeMutablePointer<AtomicWrapper>) -> Self { get }
3635
static var nio_atomic_store: @Sendable (UnsafeMutablePointer<AtomicWrapper>, Self) -> Void { get }
3736
}
38-
#else
39-
public protocol NIOAtomicPrimitive {
40-
associatedtype AtomicWrapper
41-
static var nio_atomic_create_with_existing_storage: (UnsafeMutablePointer<AtomicWrapper>, Self) -> Void { get }
42-
static var nio_atomic_compare_and_exchange: (UnsafeMutablePointer<AtomicWrapper>, Self, Self) -> Bool { get }
43-
static var nio_atomic_add: (UnsafeMutablePointer<AtomicWrapper>, Self) -> Self { get }
44-
static var nio_atomic_sub: (UnsafeMutablePointer<AtomicWrapper>, Self) -> Self { get }
45-
static var nio_atomic_exchange: (UnsafeMutablePointer<AtomicWrapper>, Self) -> Self { get }
46-
static var nio_atomic_load: (UnsafeMutablePointer<AtomicWrapper>) -> Self { get }
47-
static var nio_atomic_store: (UnsafeMutablePointer<AtomicWrapper>, Self) -> Void { get }
48-
}
49-
#endif
5037

5138
extension Bool: NIOAtomicPrimitive {
5239
public typealias AtomicWrapper = catmc_nio_atomic__Bool

Sources/NIOConcurrencyHelpers/atomics.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ extension Atomic: @unchecked Sendable where T: Sendable {}
297297
/// **Do not add conformance to this protocol for arbitrary types**. Only a small range
298298
/// of types have appropriate atomic operations supported by the CPU, and those types
299299
/// already have conformances implemented.
300-
#if compiler(>=6.0)
301300
@preconcurrency
302301
public protocol AtomicPrimitive {
303302
static var atomic_create: @Sendable (Self) -> OpaquePointer { get }
@@ -309,18 +308,6 @@ public protocol AtomicPrimitive {
309308
static var atomic_load: @Sendable (OpaquePointer) -> Self { get }
310309
static var atomic_store: @Sendable (OpaquePointer, Self) -> Void { get }
311310
}
312-
#else
313-
public protocol AtomicPrimitive {
314-
static var atomic_create: (Self) -> OpaquePointer { get }
315-
static var atomic_destroy: (OpaquePointer) -> Void { get }
316-
static var atomic_compare_and_exchange: (OpaquePointer, Self, Self) -> Bool { get }
317-
static var atomic_add: (OpaquePointer, Self) -> Self { get }
318-
static var atomic_sub: (OpaquePointer, Self) -> Self { get }
319-
static var atomic_exchange: (OpaquePointer, Self) -> Self { get }
320-
static var atomic_load: (OpaquePointer) -> Self { get }
321-
static var atomic_store: (OpaquePointer, Self) -> Void { get }
322-
}
323-
#endif
324311

325312
extension Bool: AtomicPrimitive {
326313
public static let atomic_create = catmc_atomic__Bool_create

Sources/NIOCore/AsyncChannel/AsyncChannel.swift

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -323,19 +323,18 @@ public struct NIOAsyncChannel<Inbound: Sendable, Outbound: Sendable>: Sendable {
323323
return result
324324
}
325325

326-
#if compiler(>=6.0)
327-
// Note: Whitespace changes are used to workaround compiler bug
328-
// Remove when compiler version 5.10 is no longer supported.
329-
// https://github.com/swiftlang/swift/issues/79285
330-
// swift-format-ignore
331326
/// Provides scoped access to the inbound and outbound side of the underlying ``Channel``.
332327
///
333328
/// - Important: After this method returned the underlying ``Channel`` will be closed.
334329
///
335330
/// - Parameters:
336331
/// - actor: actor where this function should be isolated to
337332
/// - body: A closure that gets scoped access to the inbound and outbound.
338-
public func executeThenClose<Result>(isolation actor: isolated (any Actor)? = #isolation, _ body: (_ inbound: NIOAsyncChannelInboundStream<Inbound>, _ outbound: NIOAsyncChannelOutboundWriter<Outbound>) async throws -> sending Result) async throws -> sending Result {
333+
public func executeThenClose<Result>(
334+
isolation actor: isolated (any Actor)? = #isolation,
335+
_ body: (_ inbound: NIOAsyncChannelInboundStream<Inbound>, _ outbound: NIOAsyncChannelOutboundWriter<Outbound>)
336+
async throws -> sending Result
337+
) async throws -> sending Result {
339338
let result: Result
340339
do {
341340
result = try await body(self._inbound, self._outbound)
@@ -370,7 +369,6 @@ public struct NIOAsyncChannel<Inbound: Sendable, Outbound: Sendable>: Sendable {
370369

371370
return result
372371
}
373-
#endif
374372
}
375373

376374
// swift-format-ignore: AmbiguousTrailingClosureOverload
@@ -419,19 +417,17 @@ extension NIOAsyncChannel {
419417
return result
420418
}
421419

422-
#if compiler(>=6.0)
423-
// Note: Whitespace changes are used to workaround compiler bug
424-
// Remove when compiler version 5.10 is no longer supported.
425-
// https://github.com/swiftlang/swift/issues/79285
426-
// swift-format-ignore
427420
/// Provides scoped access to the inbound side of the underlying ``Channel``.
428421
///
429422
/// - Important: After this method returned the underlying ``Channel`` will be closed.
430423
///
431424
/// - Parameters:
432425
/// - actor: actor where this function should be isolated to
433426
/// - body: A closure that gets scoped access to the inbound.
434-
public func executeThenClose<Result>(isolation actor: isolated (any Actor)? = #isolation, _ body: (_ inbound: NIOAsyncChannelInboundStream<Inbound>) async throws -> sending Result) async throws -> sending Result where Outbound == Never {
427+
public func executeThenClose<Result>(
428+
isolation actor: isolated (any Actor)? = #isolation,
429+
_ body: (_ inbound: NIOAsyncChannelInboundStream<Inbound>) async throws -> sending Result
430+
) async throws -> sending Result where Outbound == Never {
435431
let result: Result
436432
do {
437433
result = try await body(self._inbound)
@@ -466,7 +462,6 @@ extension NIOAsyncChannel {
466462

467463
return result
468464
}
469-
#endif
470465
}
471466

472467
extension Channel {

Sources/NIOCore/BSDSocketAPI.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,9 @@ private let sysInet_pton: @convention(c) (CInt, UnsafePointer<CChar>?, UnsafeMut
102102
#endif
103103

104104
#if os(Android)
105-
#if compiler(>=6.0)
106105
@usableFromInline let IFF_BROADCAST: CUnsignedInt = numericCast(Android.IFF_BROADCAST.rawValue)
107106
@usableFromInline let IFF_POINTOPOINT: CUnsignedInt = numericCast(Android.IFF_POINTOPOINT.rawValue)
108107
@usableFromInline let IFF_MULTICAST: CUnsignedInt = numericCast(Android.IFF_MULTICAST.rawValue)
109-
#else
110-
@usableFromInline let IFF_BROADCAST: CUnsignedInt = numericCast(SwiftGlibc.IFF_BROADCAST.rawValue)
111-
@usableFromInline let IFF_POINTOPOINT: CUnsignedInt = numericCast(SwiftGlibc.IFF_POINTOPOINT.rawValue)
112-
@usableFromInline let IFF_MULTICAST: CUnsignedInt = numericCast(SwiftGlibc.IFF_MULTICAST.rawValue)
113-
#endif
114108
#if arch(arm)
115109
@usableFromInline let SO_RCVTIMEO = SO_RCVTIMEO_OLD
116110
@usableFromInline let SO_TIMESTAMP = SO_TIMESTAMP_OLD

Sources/NIOCore/ByteBuffer-aux.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,6 @@ extension Optional where Wrapped == ByteBuffer {
10031003
}
10041004
}
10051005

1006-
#if compiler(>=6)
10071006
extension ByteBuffer {
10081007
/// Get the string at `index` from this `ByteBuffer` decoding using the UTF-8 encoding. Does not move the reader index.
10091008
/// The selected bytes must be readable or else `nil` will be returned.
@@ -1077,4 +1076,3 @@ extension ByteBuffer {
10771076
try self.getUTF8ValidatedString(at: self.readerIndex, length: length)
10781077
}
10791078
}
1080-
#endif // compiler(>=6)

Sources/NIOCore/NIOLoopBound.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,16 @@ public final class NIOLoopBoundBox<Value>: @unchecked Sendable {
139139
.init(_value: value, uncheckedEventLoop: eventLoop)
140140
}
141141

142-
#if compiler(>=6.0)
143-
// Note: Whitespace changes are used to workaround compiler bug
144-
// Remove when compiler version 5.10 is no longer supported.
145-
// https://github.com/swiftlang/swift/issues/79285
146-
// swift-format-ignore
147142
/// Initialise a ``NIOLoopBoundBox`` by sending a value, validly callable off `eventLoop`.
148143
///
149144
/// 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.
150145
/// So we don't need to protect `value` itself, we just need to protect the ``NIOLoopBoundBox`` against mutations which we do because the ``value``
151146
/// accessors are checking that we're on `eventLoop`.
152-
public static func makeBoxSendingValue(_ value: sending Value, as: Value.Type = Value.self, eventLoop: EventLoop) -> NIOLoopBoundBox<Value> {
147+
public static func makeBoxSendingValue(
148+
_ value: sending Value,
149+
as: Value.Type = Value.self,
150+
eventLoop: EventLoop
151+
) -> NIOLoopBoundBox<Value> {
153152
// Here, we -- possibly surprisingly -- do not precondition being on the EventLoop. This is okay for a few
154153
// reasons:
155154
// - This function takes its value as `sending` so we don't need to worry about somebody
@@ -159,7 +158,6 @@ public final class NIOLoopBoundBox<Value>: @unchecked Sendable {
159158
// - The only way to ever write (or read indeed) `self._value` is by proving to be inside the `EventLoop`.
160159
.init(_value: value, uncheckedEventLoop: eventLoop)
161160
}
162-
#endif
163161

164162
/// Access the `value` with the precondition that the code is running on `eventLoop`.
165163
///

Sources/NIOCrashTester/CrashTests+EventLoop.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ struct EventLoopCrashTests {
180180
NIOSingletons.groupLoopCountSuggestion = -1
181181
}
182182

183-
#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.
183+
#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.
184184
let testInstallingSingletonMTELGAsConcurrencyExecutorWorksButOnlyOnce = CrashTest(
185185
regex: #"Fatal error: Must be called only once"#
186186
) {
@@ -207,6 +207,6 @@ struct EventLoopCrashTests {
207207
// This should crash
208208
_ = NIOSingletons.unsafeTryInstallSingletonPosixEventLoopGroupAsConcurrencyGlobalExecutor()
209209
}
210-
#endif // compiler(>=5.9) && swift(<6.2)
210+
#endif // swift(<6.2)
211211
}
212212
#endif // !canImport(Darwin) || os(macOS)

Sources/NIOFS/Internal/System Calls/FileDescriptor+Syscalls.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,20 @@ extension FileDescriptor {
207207
}
208208

209209
// Read and decode.
210-
var buffer = [CChar](repeating: 0, count: capacity)
210+
var buffer = [UInt8](repeating: 0, count: capacity)
211211
return buffer.withUnsafeMutableBufferPointer { pointer in
212-
self.listExtendedAttributes(pointer)
212+
pointer.withMemoryRebound(to: CChar.self) { pointer in
213+
self.listExtendedAttributes(pointer)
214+
}
213215
}.map { size in
214216
// The buffer contains null terminated C-strings.
215217
var attributes = [String]()
216218
var slice = buffer.prefix(size)
217219
while let index = slice.firstIndex(of: 0) {
218220
// TODO: can we do this more cheaply?
219-
let prefix = slice[...index]
220-
attributes.append(String(cString: Array(prefix)))
221-
slice = slice.dropFirst(prefix.count)
221+
let prefix = slice[..<index]
222+
attributes.append(String(decoding: Array(prefix), as: Unicode.UTF8.self))
223+
slice = slice.dropFirst(prefix.count + 1)
222224
}
223225

224226
return attributes

0 commit comments

Comments
 (0)