From 6b7936c9b30720f57b1123d06916273aa5ed2f49 Mon Sep 17 00:00:00 2001 From: Simon Whitty Date: Mon, 16 Nov 2026 09:17:10 +1100 Subject: [PATCH 1/2] Fix Swift 6.4 compiler warnings in FlyingSocks - With Swift 6.4, call withChecked(Throwing)Continuation without an isolation argument so it picks the nonisolated(nonsending) overload. Older compilers keep passing isolation explicitly: without it, Swift 6.0 runs the body off the actor and crashes. - Require SendableMetatype on AsyncBufferedIteratorProtocol (Swift 6.2+), as EventQueue does. Iterators are taken out of an actor and advanced with the nonisolated nextBuffer, so an isolated conformance is unsafe. - Avoid capturing the Buffer metatype in nextElements. - Discard unused throwing Tasks explicitly in sources and tests, and use the HTTPHeaders WebSocket response initialiser in the test mock. --- FlyingFox/Tests/HTTPResponse+Mock.swift | 2 +- FlyingFox/Tests/HTTPServerTests.swift | 4 ++-- .../Sources/AsyncBufferedSequence.swift | 17 +++++++++++++- FlyingSocks/Sources/AsyncSocket.swift | 2 +- .../Sources/IdentifiableContinuation.swift | 22 +++++++++++++++---- FlyingSocks/Tests/AsyncSocketTests.swift | 2 +- 6 files changed, 39 insertions(+), 10 deletions(-) diff --git a/FlyingFox/Tests/HTTPResponse+Mock.swift b/FlyingFox/Tests/HTTPResponse+Mock.swift index 8839400e..f7f529f7 100644 --- a/FlyingFox/Tests/HTTPResponse+Mock.swift +++ b/FlyingFox/Tests/HTTPResponse+Mock.swift @@ -71,7 +71,7 @@ extension HTTPResponse { static func make(headers: [HTTPHeader: String] = [:], webSocket handler: some WSHandler) -> Self { - HTTPResponse(headers: headers, + HTTPResponse(headers: HTTPHeaders(headers), webSocket: handler) } diff --git a/FlyingFox/Tests/HTTPServerTests.swift b/FlyingFox/Tests/HTTPServerTests.swift index f4c50eed..3c9ddce4 100644 --- a/FlyingFox/Tests/HTTPServerTests.swift +++ b/FlyingFox/Tests/HTTPServerTests.swift @@ -43,7 +43,7 @@ actor HTTPServerTests { func startServerWithPort(_ server: HTTPServer, preferConnectionsDiscarding: Bool = true) async throws -> UInt16 { self.stopServer = server - Task { + _ = Task { try await HTTPServer.$preferConnectionsDiscarding.withValue(preferConnectionsDiscarding) { try await server.run() } @@ -663,7 +663,7 @@ actor HTTPServerTests { return true } - Task { try await server.run() } + _ = Task { try await server.run() } self.stopServer = server #expect(try await waiting.value == true) diff --git a/FlyingSocks/Sources/AsyncBufferedSequence.swift b/FlyingSocks/Sources/AsyncBufferedSequence.swift index 6a8f74a5..c2b942c5 100644 --- a/FlyingSocks/Sources/AsyncBufferedSequence.swift +++ b/FlyingSocks/Sources/AsyncBufferedSequence.swift @@ -34,6 +34,19 @@ public protocol AsyncBufferedSequence: AsyncSequence, Sendable where As } +// Iterators are taken out of an actor and advanced with the nonisolated `nextBuffer`, +// so their conformance must not be isolated to a global actor (SendableMetatype). +#if compiler(>=6.2) +public protocol AsyncBufferedIteratorProtocol: AsyncIteratorProtocol, SendableMetatype { + // Buffered elements are returned in this collection type + associatedtype Buffer: Collection where Buffer.Element == Element + + /// Retrieves available elements from the buffer. Suspends if 0 elements are available. + /// - Parameter count: The suggested number of elements to return + /// - Returns: Collection with between 1 and the number elements that was requested. Nil is returned if the sequence has ended. + mutating func nextBuffer(suggested count: Int) async throws -> Buffer? +} +#else public protocol AsyncBufferedIteratorProtocol: AsyncIteratorProtocol { // Buffered elements are returned in this collection type associatedtype Buffer: Collection where Buffer.Element == Element @@ -43,6 +56,7 @@ public protocol AsyncBufferedIteratorProtocol: AsyncIteratorProtocol { /// - Returns: Collection with between 1 and the number elements that was requested. Nil is returned if the sequence has ended. mutating func nextBuffer(suggested count: Int) async throws -> Buffer? } +#endif extension AsyncBufferedIteratorProtocol where Element: Sendable { @@ -51,7 +65,8 @@ extension AsyncBufferedIteratorProtocol where Element: Sendable { /// non-Sendable `Buffer` crossing into an actor, and it can't be wrapped in /// `Disconnected` because it shares the iterator's region. mutating func nextElements(suggested count: Int) async throws -> [Element]? { - try await nextBuffer(suggested: count).map(Array.init) + guard let buffer = try await nextBuffer(suggested: count) else { return nil } + return Array(buffer) } } diff --git a/FlyingSocks/Sources/AsyncSocket.swift b/FlyingSocks/Sources/AsyncSocket.swift index 15354dcf..78d1d752 100644 --- a/FlyingSocks/Sources/AsyncSocket.swift +++ b/FlyingSocks/Sources/AsyncSocket.swift @@ -429,7 +429,7 @@ private actor ClientPoolLoader { } try await pool.prepare() isStarted = true - Task { try await pool.run() } + _ = Task { try await pool.run() } return pool } } diff --git a/FlyingSocks/Sources/IdentifiableContinuation.swift b/FlyingSocks/Sources/IdentifiableContinuation.swift index 06130596..bc741fe7 100644 --- a/FlyingSocks/Sources/IdentifiableContinuation.swift +++ b/FlyingSocks/Sources/IdentifiableContinuation.swift @@ -58,8 +58,8 @@ package func withIdentifiableContinuation( let state = Mutex((isStarted: false, isCancelled: false)) nonisolated(unsafe) let body = body return await withTaskCancellationHandler { - await withCheckedContinuation(isolation: isolation, function: function) { - let continuation = IdentifiableContinuation(id: id, continuation: $0) + let operation = { (checked: CheckedContinuation) in + let continuation = IdentifiableContinuation(id: id, continuation: checked) body(continuation) let sendCancel = state.withLock { $0.isStarted = true @@ -69,6 +69,13 @@ package func withIdentifiableContinuation( handler(id) } } + // Swift 6.4 deprecates the `isolation:` overload for a nonisolated(nonsending) one, + // which inherits the isolation. Older compilers need it passed explicitly. +#if compiler(>=6.4) + return await withCheckedContinuation(function: function, operation) +#else + return await withCheckedContinuation(isolation: isolation, function: function, operation) +#endif } onCancel: { let sendCancel = state.withLock { $0.isCancelled = true @@ -105,8 +112,8 @@ package func withIdentifiableThrowingContinuation( let state = Mutex((isStarted: false, isCancelled: false)) nonisolated(unsafe) let body = body return try await withTaskCancellationHandler { - try await withCheckedThrowingContinuation(isolation: isolation, function: function) { - let continuation = IdentifiableContinuation(id: id, continuation: $0) + let operation = { (checked: CheckedContinuation) in + let continuation = IdentifiableContinuation(id: id, continuation: checked) body(continuation) let sendCancel = state.withLock { $0.isStarted = true @@ -116,6 +123,13 @@ package func withIdentifiableThrowingContinuation( handler(id) } } + // Swift 6.4 deprecates the `isolation:` overload for a nonisolated(nonsending) one, + // which inherits the isolation. Older compilers need it passed explicitly. +#if compiler(>=6.4) + return try await withCheckedThrowingContinuation(function: function, operation) +#else + return try await withCheckedThrowingContinuation(isolation: isolation, function: function, operation) +#endif } onCancel: { let sendCancel = state.withLock { $0.isCancelled = true diff --git a/FlyingSocks/Tests/AsyncSocketTests.swift b/FlyingSocks/Tests/AsyncSocketTests.swift index eef7db31..198cc8cb 100644 --- a/FlyingSocks/Tests/AsyncSocketTests.swift +++ b/FlyingSocks/Tests/AsyncSocketTests.swift @@ -53,7 +53,7 @@ struct AsyncSocketTests { let (s1, s2) = try await AsyncSocket.makePair() async let d2 = s2.readString(length: 12) - Task { + _ = Task { try await s1.writeString("Fish & Chips") } From 26e119dcaafdf6b97e0038a2c86300333d02ae25 Mon Sep 17 00:00:00 2001 From: Simon Whitty Date: Mon, 16 Nov 2026 09:21:54 +1100 Subject: [PATCH 2/2] Make the deprecated HTTPRoute.method unavailable Mark it unavailable, renamed to methods, and remove its test. --- FlyingFox/Sources/HTTPRoute.swift | 12 ++---------- FlyingFox/Tests/HTTPRouteTests.swift | 8 -------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/FlyingFox/Sources/HTTPRoute.swift b/FlyingFox/Sources/HTTPRoute.swift index 97f73210..b30a9529 100644 --- a/FlyingFox/Sources/HTTPRoute.swift +++ b/FlyingFox/Sources/HTTPRoute.swift @@ -150,17 +150,9 @@ public struct HTTPRoute: Sendable { } } - @available(*, deprecated, renamed: "methods", message: "Use ``methods`` instead") + @available(*, unavailable, renamed: "methods", message: "Use ``methods`` instead") public var method: Component { - if methods == HTTPMethod.allMethods { - return .wildcard - } else { - let firstMethod = HTTPMethod.sortedMethods - .filter { methods.contains($0) } - .first! - .rawValue - return .caseInsensitive(firstMethod) - } + fatalError("Use methods instead") } } diff --git a/FlyingFox/Tests/HTTPRouteTests.swift b/FlyingFox/Tests/HTTPRouteTests.swift index ac0a45ad..b0abe43f 100644 --- a/FlyingFox/Tests/HTTPRouteTests.swift +++ b/FlyingFox/Tests/HTTPRouteTests.swift @@ -470,14 +470,6 @@ struct HTTPRouteTests { } #endif - @Test - func deprecated_Method() { - #expect(HTTPRoute("/fish/*").method == .wildcard) - #expect(HTTPRoute("GET /fish/*").method == .caseInsensitive("GET")) - #expect(HTTPRoute("PUT /fish/*").method == .caseInsensitive("PUT")) - #expect(HTTPRoute("GET,PUT /fish/*").method == .caseInsensitive("GET")) - } - @Test func routeParameters() { let route = HTTPRoute("GET /mock/:id")