Skip to content

Commit

Permalink
Remove support for Swift 5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
swhitty committed Jul 14, 2024
1 parent fe8b3ca commit afdd366
Show file tree
Hide file tree
Showing 13 changed files with 4 additions and 61 deletions.
21 changes: 0 additions & 21 deletions FlyingFox/Sources/HTTPBodySequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ public struct HTTPBodySequence: Sendable, AsyncSequence {
}

public init(data: Data, suggestedBufferSize: Int = 4096) {
#if compiler(>=5.9)
self.storage = .sequence(.init(data: data, bufferSize: suggestedBufferSize))
#else
self.storage = .complete(data)
#endif
}

public init(from bytes: some AsyncBufferedSequence<UInt8>, count: Int, suggestedBufferSize: Int = 4096) {
Expand All @@ -57,11 +53,9 @@ public struct HTTPBodySequence: Sendable, AsyncSequence {
)
}

#if compiler(>=5.9)
public init(from bytes: some AsyncBufferedSequence<UInt8>, suggestedBufferSize: Int = 4096) {
self.storage = .sequence(.init(bytes: bytes, bufferSize: suggestedBufferSize))
}
#endif

public init(file url: URL, suggestedBufferSize: Int = 4096) throws {
try self.init(file: url, maxSizeForComplete: 10_485_760, suggestedBufferSize: suggestedBufferSize)
Expand All @@ -87,8 +81,6 @@ public struct HTTPBodySequence: Sendable, AsyncSequence {
enum Storage: @unchecked Sendable {
case complete(Data)
case dataSequence(AsyncDataSequence)

#if compiler(>=5.9)
case sequence(Sequence)

struct Sequence {
Expand All @@ -110,7 +102,6 @@ public struct HTTPBodySequence: Sendable, AsyncSequence {
self.canReplay = false
}
}
#endif
}

public var count: Int? {
Expand All @@ -119,10 +110,8 @@ public struct HTTPBodySequence: Sendable, AsyncSequence {
return data.count
case .dataSequence(let sequence):
return sequence.count
#if compiler(>=5.9)
case .sequence(let sequence):
return sequence.count
#endif
}
}

Expand All @@ -134,12 +123,10 @@ public struct HTTPBodySequence: Sendable, AsyncSequence {
return try await sequence.reduce(into: Data()) {
$0.append($1)
}
#if compiler(>=5.9)
case .sequence(let sequence):
return try await sequence.sequence.reduce(into: Data()) {
$0.append($1)
}
#endif
}
}

Expand All @@ -152,10 +139,8 @@ public struct HTTPBodySequence: Sendable, AsyncSequence {
switch storage {
case .complete: return true
case .dataSequence: return false
#if compiler(>=5.9)
case .sequence(let sequence):
return sequence.canReplay
#endif
}
}
}
Expand All @@ -177,11 +162,9 @@ public extension HTTPBodySequence {
case .dataSequence(let sequence):
self.storage = .dataIterator(sequence.makeAsyncIterator())
self.bufferSize = 0
#if compiler(>=5.9)
case .sequence(let sequence):
self.storage = .iterator(sequence.sequence.makeAsyncIterator())
self.bufferSize = sequence.bufferSize
#endif
}
}

Expand All @@ -198,15 +181,13 @@ public extension HTTPBodySequence {
}
storage = .dataIterator(iterator)
return result
#if compiler(>=5.9)
case var .iterator(iterator):
guard let result = try await getNextBuffer(&iterator) else {
isComplete = true
return nil
}
storage = .iterator(iterator)
return result
#endif
}
}

Expand All @@ -220,9 +201,7 @@ public extension HTTPBodySequence {
enum Internal: @unchecked Sendable {
case complete(Data)
case dataIterator(AsyncDataSequence.AsyncIterator)
#if compiler(>=5.9)
case iterator(any AsyncBufferedIteratorProtocol<UInt8>)
#endif
}
}
}
2 changes: 0 additions & 2 deletions FlyingFox/Sources/HTTPRouteParameterValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ public extension HTTPRoute {
}
}

#if compiler(>=5.9)
extension HTTPRoute {

func extractParameterValues<each P: HTTPRouteParameterValue>(
Expand All @@ -164,4 +163,3 @@ extension HTTPRoute {
return try P(parameter: parameters[index])
}
}
#endif
9 changes: 0 additions & 9 deletions FlyingFox/Sources/HTTPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public final actor HTTPServer {
handlers.appendRoute(route, handler: handler)
}

#if compiler(>=5.9)

public func appendRoute<each P: HTTPRouteParameterValue>(
_ route: HTTPRoute,
handler: @Sendable @escaping (HTTPRequest, repeat each P) async throws -> HTTPResponse
Expand All @@ -83,7 +81,6 @@ public final actor HTTPServer {
) {
handlers.appendRoute(route, handler: handler)
}
#endif

public func start() async throws {
guard state == nil else {
Expand Down Expand Up @@ -161,18 +158,13 @@ public final actor HTTPServer {
@TaskLocal static var preferConnectionsDiscarding = true

private func listenForConnections(on socket: AsyncSocket) async throws {
#if compiler(>=5.9)
if #available(macOS 14.0, iOS 17.0, tvOS 17.0, *), Self.preferConnectionsDiscarding {
try await listenForConnectionsDiscarding(on: socket)
} else {
try await listenForConnectionsFallback(on: socket)
}
#else
try await listenForConnectionsFallback(on: socket)
#endif
}

#if compiler(>=5.9)
@available(macOS 14.0, iOS 17.0, tvOS 17.0, *)
private func listenForConnectionsDiscarding(on socket: AsyncSocket) async throws {
try await withThrowingDiscardingTaskGroup { [logger] group in
Expand All @@ -184,7 +176,6 @@ public final actor HTTPServer {
}
throw SocketError.disconnected
}
#endif

@available(macOS, deprecated: 17.0, renamed: "listenForConnectionsDiscarding(on:)")
@available(iOS, deprecated: 17.0, renamed: "listenForConnectionsDiscarding(on:)")
Expand Down
3 changes: 0 additions & 3 deletions FlyingFox/Sources/Handlers/RoutedHTTPHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public struct RoutedHTTPHandler: HTTPHandler, Sendable {
append((route, ClosureHTTPHandler(handler)))
}

#if compiler(>=5.9)

public mutating func appendRoute<each P: HTTPRouteParameterValue>(
_ route: HTTPRoute,
handler: @Sendable @escaping (HTTPRequest, repeat each P) async throws -> HTTPResponse
Expand All @@ -67,7 +65,6 @@ public struct RoutedHTTPHandler: HTTPHandler, Sendable {
}
append((route, closure))
}
#endif

public mutating func insertRoute(_ route: HTTPRoute,
at index: Index,
Expand Down
9 changes: 0 additions & 9 deletions FlyingFox/Tests/HTTPBodySequenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ final class HTTPBodySequenceTests: XCTestCase {
)

// when then
#if compiler(>=5.9)
await AsyncAssertEqual(
try await body.collectAll(),
[
Expand All @@ -206,14 +205,6 @@ final class HTTPBodySequenceTests: XCTestCase {
Data([0x9])
]
)
#else
await AsyncAssertEqual(
try await body.collectAll(),
[
Data([0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9])
]
)
#endif
}

func testSequencePayload_IsFlushed() async {
Expand Down
2 changes: 0 additions & 2 deletions FlyingFox/Tests/HTTPEncoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ final class HTTPEncoderTests: XCTestCase {
)
}

#if compiler(>=5.9)
func testEncodesChunkedResponse() async throws {
let data = try await HTTPEncoder.encodeResponse(
.makeChunked(
Expand Down Expand Up @@ -150,7 +149,6 @@ final class HTTPEncoderTests: XCTestCase {
""".data(using: .utf8)
)
}
#endif

func testEncodesRequest() async throws {
await AsyncAssertEqual(
Expand Down
2 changes: 0 additions & 2 deletions FlyingFox/Tests/HTTPResponse+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ extension HTTPResponse {
body: body)
}

#if compiler(>=5.9)
static func makeChunked(version: HTTPVersion = .http11,
statusCode: HTTPStatusCode = .ok,
headers: [HTTPHeader: String] = [:],
Expand All @@ -58,7 +57,6 @@ extension HTTPResponse {
body: HTTPBodySequence(from: consuming, suggestedBufferSize: chunkSize)
)
}
#endif

static func make(version: HTTPVersion = .http11,
statusCode: HTTPStatusCode = .ok,
Expand Down
2 changes: 0 additions & 2 deletions FlyingFox/Tests/HTTPRouteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@ final class HTTPRouteTests: XCTestCase {
)
}

#if compiler(>=5.9)
func testPathParameters() {
// given
let route = HTTPRoute("GET /mock/:id/hello/:zonk")
Expand All @@ -542,7 +541,6 @@ final class HTTPRouteTests: XCTestCase {
try route.extractParameterValues(of: (Int, String, String).self, from: request)
)
}
#endif

func testDescription() {
XCTAssertEqual(
Expand Down
5 changes: 0 additions & 5 deletions FlyingFox/Tests/HTTPServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ final class HTTPServerTests: XCTestCase {
)
}

#if canImport(Darwin) || compiler(>=5.8)
func testConnections_AreHandled_DiscardingTaskGroup() async throws {
let server = HTTPServer.make()
let port = try await startServerWithPort(server, preferConnectionsDiscarding: true)
Expand All @@ -184,7 +183,6 @@ final class HTTPServerTests: XCTestCase {
404
)
}
#endif

func testHandlerErrors_Return500() async throws {
let server = HTTPServer.make() { _ in
Expand Down Expand Up @@ -436,8 +434,6 @@ final class HTTPServerTests: XCTestCase {
await AsyncAssertThrowsError(try await waiting.value, of: (any Error).self)
}

#if compiler(>=5.9)

func testRoutes_To_ParamaterPackWithRequest() async throws {
let server = HTTPServer.make()
await server.appendRoute("/fish/:id") { (request: HTTPRequest, id: String) in
Expand Down Expand Up @@ -465,7 +461,6 @@ final class HTTPServerTests: XCTestCase {
"Hello 🍟"
)
}
#endif
}

extension HTTPServer {
Expand Down
2 changes: 0 additions & 2 deletions FlyingFox/Tests/Handlers/RoutedHTTPHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ final class RoutedHTTPHandlerTests: XCTestCase {
)
}

#if compiler(>=5.9)
func testParameterPackRoute() async throws {
// given
var handler = RoutedHTTPHandler()
Expand All @@ -128,7 +127,6 @@ final class RoutedHTTPHandlerTests: XCTestCase {
"900 shrimp 🍤"
)
}
#endif
}

private struct MockHandler: HTTPHandler {
Expand Down
4 changes: 2 additions & 2 deletions FlyingSocks/Sources/SwiftSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
// SOFTWARE.
//

#if compiler(<5.9)
#warning("FlyingFox will soon remove support for Swift 5.8")
#if compiler(<5.10)
#warning("FlyingFox will soon remove support for Swift 5.9")
#endif
2 changes: 1 addition & 1 deletion FlyingSocks/Tests/IdentifiableContinuationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private actor Waiter<T, E: Error> {
private func safeAssertIsolated() {
#if compiler(>=5.10)
assertIsolated()
#elseif compiler(>=5.9)
#else
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
assertIsolated()
}
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.8
// swift-tools-version:5.9

import PackageDescription

Expand Down

0 comments on commit afdd366

Please sign in to comment.