Skip to content

Commit cf62abc

Browse files
authored
Drop support for Swift 5.5 (#336)
1 parent cf09800 commit cf62abc

File tree

14 files changed

+22
-86
lines changed

14 files changed

+22
-86
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.5
1+
// swift-tools-version:5.6
22
import PackageDescription
33

44
let package = Package(

Sources/PostgresNIO/Connection/PostgresConnection.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import Logging
88
import NIOPosix
99

1010
/// A Postgres connection. Use it to run queries against a Postgres server.
11-
public final class PostgresConnection {
11+
///
12+
/// Thread safety is achieved by dispatching all access to shared state onto the underlying EventLoop.
13+
public final class PostgresConnection: @unchecked Sendable {
1214
/// A Postgres connection ID
1315
public typealias ID = Int
1416

@@ -449,7 +451,6 @@ extension PostgresConnection {
449451

450452
// MARK: Async/Await Interface
451453

452-
#if canImport(_Concurrency)
453454
extension PostgresConnection {
454455

455456
/// Creates a new connection to a Postgres server.
@@ -513,7 +514,6 @@ extension PostgresConnection {
513514
return try await promise.futureResult.map({ $0.asyncSequence() }).get()
514515
}
515516
}
516-
#endif
517517

518518
// MARK: EventLoopFuture interface
519519

@@ -785,7 +785,3 @@ extension PostgresConnection.InternalConfiguration {
785785
self.requireBackendKeyData = config.connection.requireBackendKeyData
786786
}
787787
}
788-
789-
#if swift(>=5.6)
790-
extension PostgresConnection: @unchecked Sendable {}
791-
#endif

Sources/PostgresNIO/Data/PostgresData.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import NIOCore
22
import struct Foundation.UUID
33

4-
public struct PostgresData: CustomStringConvertible, CustomDebugStringConvertible {
4+
public struct PostgresData: Sendable, CustomStringConvertible, CustomDebugStringConvertible {
55
public static var null: PostgresData {
66
return .init(type: .null)
77
}
@@ -112,7 +112,3 @@ extension PostgresData: PostgresDataConvertible {
112112
return self
113113
}
114114
}
115-
116-
#if swift(>=5.6)
117-
extension PostgresData: Sendable {}
118-
#endif

Sources/PostgresNIO/Data/PostgresDataType.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// Currently there a two wire formats supported:
44
/// - text
55
/// - binary
6-
public enum PostgresFormat: Int16 {
6+
public enum PostgresFormat: Int16, Sendable {
77
case text = 0
88
case binary = 1
99
}
@@ -17,11 +17,6 @@ extension PostgresFormat: CustomStringConvertible {
1717
}
1818
}
1919

20-
#if swift(>=5.6)
21-
extension PostgresFormat: Sendable {}
22-
#endif
23-
24-
2520
// TODO: The Codable conformance does not make any sense. Let's remove this with next major break.
2621
extension PostgresFormat: Codable {}
2722

@@ -31,7 +26,7 @@ public typealias PostgresFormatCode = PostgresFormat
3126

3227
/// The data type's raw object ID.
3328
/// Use `select * from pg_type where oid = <idhere>;` to lookup more information.
34-
public struct PostgresDataType: RawRepresentable, Hashable, CustomStringConvertible {
29+
public struct PostgresDataType: RawRepresentable, Sendable, Hashable, CustomStringConvertible {
3530
/// `0`
3631
public static let null = PostgresDataType(0)
3732
/// `16`
@@ -238,10 +233,6 @@ public struct PostgresDataType: RawRepresentable, Hashable, CustomStringConverti
238233
}
239234
}
240235

241-
#if swift(>=5.6)
242-
extension PostgresDataType: Sendable {}
243-
#endif
244-
245236
// TODO: The Codable conformance does not make any sense. Let's remove this with next major break.
246237
extension PostgresDataType: Codable {}
247238

Sources/PostgresNIO/Data/PostgresRow.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import class Foundation.JSONDecoder
77
/// - Warning: Please note that random access to cells in a ``PostgresRow`` have O(n) time complexity. If you require
88
/// random access to cells in O(1) create a new ``PostgresRandomAccessRow`` with the given row and
99
/// access it instead.
10-
public struct PostgresRow {
10+
public struct PostgresRow: Sendable {
1111
@usableFromInline
1212
let lookupTable: [String: Int]
1313
@usableFromInline
@@ -138,7 +138,7 @@ public struct PostgresRandomAccessRow {
138138
}
139139
}
140140

141-
extension PostgresRandomAccessRow: RandomAccessCollection {
141+
extension PostgresRandomAccessRow: Sendable, RandomAccessCollection {
142142
public typealias Element = PostgresCell
143143
public typealias Index = Int
144144

@@ -320,9 +320,3 @@ extension PostgresRow: CustomStringConvertible {
320320
return row.description
321321
}
322322
}
323-
324-
#if swift(>=5.6)
325-
extension PostgresRow: Sendable {}
326-
327-
extension PostgresRandomAccessRow: Sendable {}
328-
#endif

Sources/PostgresNIO/New/Messages/DataRow.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import NIOCore
99
/// Not putting `DataRow` in ``PSQLBackendMessage`` is our way to trick
1010
/// the Swift compiler
1111
@usableFromInline
12-
struct DataRow: PostgresBackendMessage.PayloadDecodable, Equatable {
12+
struct DataRow: Sendable, PostgresBackendMessage.PayloadDecodable, Equatable {
1313
@usableFromInline
1414
var columnCount: Int16
1515
@usableFromInline
@@ -116,7 +116,3 @@ extension DataRow {
116116
return self[byteIndex]
117117
}
118118
}
119-
120-
#if swift(>=5.5)
121-
extension DataRow: Sendable {}
122-
#endif

Sources/PostgresNIO/New/Messages/RowDescription.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import NIOCore
99
/// Not putting `DataRow` in ``PSQLBackendMessage`` is our way to trick
1010
/// the Swift compiler.
1111
@usableFromInline
12-
struct RowDescription: PostgresBackendMessage.PayloadDecodable, Equatable {
12+
struct RowDescription: PostgresBackendMessage.PayloadDecodable, Sendable, Equatable {
1313
/// Specifies the object ID of the parameter data type.
1414
@usableFromInline
1515
var columns: [Column]
@@ -86,7 +86,3 @@ struct RowDescription: PostgresBackendMessage.PayloadDecodable, Equatable {
8686
return RowDescription(columns: result)
8787
}
8888
}
89-
90-
#if swift(>=5.6)
91-
extension RowDescription.Column: Sendable {}
92-
#endif

Sources/PostgresNIO/New/PSQLRowStream.swift

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import NIOCore
22
import Logging
33

4-
final class PSQLRowStream {
4+
// Thread safety is guaranteed in the RowStream through dispatching onto the NIO EventLoop.
5+
final class PSQLRowStream: @unchecked Sendable {
56
private typealias AsyncSequenceSource = NIOThrowingAsyncSequenceProducer<DataRow, Error, AdaptiveRowBuffer, PSQLRowStream>.Source
67

78
enum RowSource {
@@ -23,10 +24,7 @@ final class PSQLRowStream {
2324
case iteratingRows(onRow: (PostgresRow) throws -> (), EventLoopPromise<Void>, PSQLRowsDataSource)
2425
case waitingForAll([PostgresRow], EventLoopPromise<[PostgresRow]>, PSQLRowsDataSource)
2526
case consumed(Result<String, Error>)
26-
27-
#if canImport(_Concurrency)
2827
case asyncSequence(AsyncSequenceSource, PSQLRowsDataSource)
29-
#endif
3028
}
3129

3230
internal let rowDescription: [RowDescription.Column]
@@ -64,8 +62,7 @@ final class PSQLRowStream {
6462
}
6563

6664
// MARK: Async Sequence
67-
68-
#if canImport(_Concurrency)
65+
6966
func asyncSequence() -> PostgresRowSequence {
7067
self.eventLoop.preconditionInEventLoop()
7168

@@ -150,7 +147,6 @@ final class PSQLRowStream {
150147
preconditionFailure("Invalid state: \(self.downstreamState)")
151148
}
152149
}
153-
#endif
154150

155151
// MARK: Consume in array
156152

@@ -312,12 +308,10 @@ final class PSQLRowStream {
312308
self.downstreamState = .waitingForAll(rows, promise, dataSource)
313309
// immediately request more
314310
dataSource.request(for: self)
315-
316-
#if canImport(_Concurrency)
311+
317312
case .asyncSequence(let consumer, let source):
318313
let yieldResult = consumer.yield(contentsOf: newRows)
319314
self.executeActionBasedOnYieldResult(yieldResult, source: source)
320-
#endif
321315

322316
case .consumed(.success):
323317
preconditionFailure("How can we receive further rows, if we are supposed to be done")
@@ -353,12 +347,10 @@ final class PSQLRowStream {
353347
case .waitingForAll(let rows, let promise, _):
354348
self.downstreamState = .consumed(.success(commandTag))
355349
promise.succeed(rows)
356-
357-
#if canImport(_Concurrency)
350+
358351
case .asyncSequence(let source, _):
359352
source.finish()
360353
self.downstreamState = .consumed(.success(commandTag))
361-
#endif
362354

363355
case .consumed:
364356
break
@@ -380,13 +372,11 @@ final class PSQLRowStream {
380372
case .waitingForAll(_, let promise, _):
381373
self.downstreamState = .consumed(.failure(error))
382374
promise.fail(error)
383-
384-
#if canImport(_Concurrency)
375+
385376
case .asyncSequence(let consumer, _):
386377
consumer.finish(error)
387378
self.downstreamState = .consumed(.failure(error))
388-
#endif
389-
379+
390380
case .consumed:
391381
break
392382
}
@@ -432,8 +422,3 @@ protocol PSQLRowsDataSource {
432422
func cancel(for stream: PSQLRowStream)
433423

434424
}
435-
436-
#if swift(>=5.5)
437-
// Thread safety is guaranteed in the RowStream through dispatching onto the NIO EventLoop.
438-
extension PSQLRowStream: @unchecked Sendable {}
439-
#endif

Sources/PostgresNIO/New/PostgresCell.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import NIOCore
22

33
/// A representation of a cell value within a ``PostgresRow`` and ``PostgresRandomAccessRow``.
4-
public struct PostgresCell: Equatable {
4+
public struct PostgresCell: Sendable, Equatable {
55
/// The cell's value as raw bytes.
66
public var bytes: ByteBuffer?
77
/// The cell's data type. This is important metadata when decoding the cell.
@@ -86,7 +86,3 @@ extension PostgresCell {
8686
try self.decode(T.self, context: .default, file: file, line: line)
8787
}
8888
}
89-
90-
#if swift(>=5.6)
91-
extension PostgresCell: Sendable {}
92-
#endif

Sources/PostgresNIO/New/PostgresQuery.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import NIOCore
22

33
/// A Postgres SQL query, that can be executed on a Postgres server. Contains the raw sql string and bindings.
4-
public struct PostgresQuery: Hashable {
4+
public struct PostgresQuery: Sendable, Hashable {
55
/// The query string
66
public var sql: String
77
/// The query binds
@@ -104,9 +104,9 @@ struct PSQLExecuteStatement {
104104
var rowDescription: RowDescription?
105105
}
106106

107-
public struct PostgresBindings: Hashable {
107+
public struct PostgresBindings: Sendable, Hashable {
108108
@usableFromInline
109-
struct Metadata: Hashable {
109+
struct Metadata: Sendable, Hashable {
110110
@usableFromInline
111111
var dataType: PostgresDataType
112112
@usableFromInline
@@ -179,9 +179,3 @@ public struct PostgresBindings: Hashable {
179179
self.metadata.append(.init(dataType: postgresData.type, format: .binary))
180180
}
181181
}
182-
183-
#if swift(>=5.6)
184-
extension PostgresQuery: Sendable {}
185-
extension PostgresBindings: Sendable {}
186-
extension PostgresBindings.Metadata: Sendable {}
187-
#endif

0 commit comments

Comments
 (0)