Skip to content

Commit 6684f15

Browse files
authored
Drop Swift 5.10 (#586)
1 parent 7a3d19d commit 6684f15

File tree

6 files changed

+30
-104
lines changed

6 files changed

+30
-104
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
swift-image:
21-
- swift:5.10-jammy
22-
- swift:6.0-noble
21+
- swift:6.0-jammy
2322
- swift:6.1-noble
24-
- swiftlang/swift:nightly-6.2-noble
23+
- swift:6.2-noble
2524
- swiftlang/swift:nightly-main-noble
2625
container: ${{ matrix.swift-image }}
2726
runs-on: ubuntu-latest
@@ -64,7 +63,7 @@ jobs:
6463
- postgres-image: postgres:13
6564
postgres-auth: trust
6665
container:
67-
image: swift:6.1-noble
66+
image: swift:6.2-noble
6867
volumes: [ 'pgrunshare:/var/run/postgresql' ]
6968
runs-on: ubuntu-latest
7069
env:

Package.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
// swift-tools-version:5.10
1+
// swift-tools-version:6.0
22
import PackageDescription
33

4+
#if compiler(>=6.1)
5+
let swiftSettings: [SwiftSetting] = []
6+
#else
47
let swiftSettings: [SwiftSetting] = [
5-
.enableUpcomingFeature("StrictConcurrency"),
8+
// Sadly the 6.0 compiler concurrency checker finds false positives.
9+
// To be able to compile, lets reduce the language version down to 5 for 6.0 only.
10+
.swiftLanguageMode(.v5)
611
]
12+
#endif
713

814
let package = Package(
915
name: "postgres-nio",

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<img src="https://img.shields.io/github/actions/workflow/status/vapor/postgres-nio/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration">
1313
</a>
1414
<a href="https://swift.org">
15-
<img src="https://design.vapor.codes/images/swift510up.svg" alt="Swift 5.10+">
15+
<img src="https://design.vapor.codes/images/swift60up.svg" alt="Swift 6.0+">
1616
</a>
1717
<a href="https://www.swift.org/sswg/incubation-process.html">
1818
<img src="https://design.vapor.codes/images/sswg-graduated.svg" alt="SSWG Incubation Level: Graduated">
@@ -163,7 +163,7 @@ Please see [SECURITY.md] for details on the security process.
163163
[Team Chat]: https://discord.gg/vapor
164164
[MIT License]: LICENSE
165165
[Continuous Integration]: https://github.com/vapor/postgres-nio/actions
166-
[Swift 5.10]: https://swift.org
166+
[Swift 6.0]: https://swift.org
167167
[Security.md]: https://github.com/vapor/.github/blob/main/SECURITY.md
168168

169169
[`PostgresConnection`]: https://api.vapor.codes/postgresnio/documentation/postgresnio/postgresconnection

Sources/PostgresNIO/Connection/PostgresConnection.swift

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,6 @@ extension PostgresConnection {
531531
}
532532
}
533533

534-
#if compiler(>=6.0)
535534
/// Puts the connection into an open transaction state, for the provided `closure`'s lifetime.
536535
///
537536
/// The function starts a transaction by running a `BEGIN` query on the connection against the database. It then
@@ -552,9 +551,8 @@ extension PostgresConnection {
552551
file: String = #file,
553552
line: Int = #line,
554553
isolation: isolated (any Actor)? = #isolation,
555-
// DO NOT FIX THE WHITESPACE IN THE NEXT LINE UNTIL 5.10 IS UNSUPPORTED
556-
// https://github.com/swiftlang/swift/issues/79285
557-
_ process: (PostgresConnection) async throws -> sending Result) async throws -> sending Result {
554+
_ process: (PostgresConnection) async throws -> sending Result
555+
) async throws -> sending Result {
558556
do {
559557
try await self.query("BEGIN;", logger: logger)
560558
} catch {
@@ -583,57 +581,6 @@ extension PostgresConnection {
583581
throw transactionError
584582
}
585583
}
586-
#else
587-
/// Puts the connection into an open transaction state, for the provided `closure`'s lifetime.
588-
///
589-
/// The function starts a transaction by running a `BEGIN` query on the connection against the database. It then
590-
/// lends the connection to the user provided closure. The user can then modify the database as they wish. If the user
591-
/// provided closure returns successfully, the function will attempt to commit the changes by running a `COMMIT`
592-
/// query against the database. If the user provided closure throws an error, the function will attempt to rollback the
593-
/// changes made within the closure.
594-
///
595-
/// - Parameters:
596-
/// - logger: The `Logger` to log into for the transaction.
597-
/// - file: The file, the transaction was started in. Used for better error reporting.
598-
/// - line: The line, the transaction was started in. Used for better error reporting.
599-
/// - closure: The user provided code to modify the database. Use the provided connection to run queries.
600-
/// The connection must stay in the transaction mode. Otherwise this method will throw!
601-
/// - Returns: The closure's return value.
602-
public func withTransaction<Result>(
603-
logger: Logger,
604-
file: String = #file,
605-
line: Int = #line,
606-
_ process: (PostgresConnection) async throws -> Result
607-
) async throws -> Result {
608-
do {
609-
try await self.query("BEGIN;", logger: logger)
610-
} catch {
611-
throw PostgresTransactionError(file: file, line: line, beginError: error)
612-
}
613-
614-
var closureHasFinished: Bool = false
615-
do {
616-
let value = try await process(self)
617-
closureHasFinished = true
618-
try await self.query("COMMIT;", logger: logger)
619-
return value
620-
} catch {
621-
var transactionError = PostgresTransactionError(file: file, line: line)
622-
if !closureHasFinished {
623-
transactionError.closureError = error
624-
do {
625-
try await self.query("ROLLBACK;", logger: logger)
626-
} catch {
627-
transactionError.rollbackError = error
628-
}
629-
} else {
630-
transactionError.commitError = error
631-
}
632-
633-
throw transactionError
634-
}
635-
}
636-
#endif
637584
}
638585

639586
// MARK: EventLoopFuture interface

Sources/PostgresNIO/New/VariadicGenerics.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ extension PostgresRow {
116116
extension AsyncSequence where Element == PostgresRow {
117117
// --- snip TODO: Remove once bug is fixed, that disallows tuples of one
118118
@inlinable
119-
public func decode<Column: PostgresDecodable>(
119+
@preconcurrency
120+
public func decode<Column: PostgresDecodable & Sendable>(
120121
_: Column.Type,
121122
context: PostgresDecodingContext<some PostgresJSONDecoder>,
122123
file: String = #fileID,
@@ -128,7 +129,8 @@ extension AsyncSequence where Element == PostgresRow {
128129
}
129130

130131
@inlinable
131-
public func decode<Column: PostgresDecodable>(
132+
@preconcurrency
133+
public func decode<Column: PostgresDecodable & Sendable>(
132134
_: Column.Type,
133135
file: String = #fileID,
134136
line: Int = #line
@@ -137,7 +139,8 @@ extension AsyncSequence where Element == PostgresRow {
137139
}
138140
// --- snap TODO: Remove once bug is fixed, that disallows tuples of one
139141

140-
public func decode<each Column: PostgresDecodable>(
142+
@preconcurrency
143+
public func decode<each Column: PostgresDecodable & Sendable>(
141144
_ columnType: (repeat each Column).Type,
142145
context: PostgresDecodingContext<some PostgresJSONDecoder>,
143146
file: String = #fileID,
@@ -148,7 +151,8 @@ extension AsyncSequence where Element == PostgresRow {
148151
}
149152
}
150153

151-
public func decode<each Column: PostgresDecodable>(
154+
@preconcurrency
155+
public func decode<each Column: PostgresDecodable & Sendable>(
152156
_ columnType: (repeat each Column).Type,
153157
file: String = #fileID,
154158
line: Int = #line

Sources/PostgresNIO/Pool/PostgresClient.swift

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,15 @@ public final class PostgresClient: Sendable, ServiceLifecycle.Service {
308308
return try await closure(lease.connection)
309309
}
310310

311-
#if compiler(>=6.0)
312311
/// Lease a connection for the provided `closure`'s lifetime.
313312
///
314313
/// - Parameter closure: A closure that uses the passed `PostgresConnection`. The closure **must not** capture
315314
/// the provided `PostgresConnection`.
316315
/// - Returns: The closure's return value.
317316
public func withConnection<Result>(
318317
isolation: isolated (any Actor)? = #isolation,
319-
// DO NOT FIX THE WHITESPACE IN THE NEXT LINE UNTIL 5.10 IS UNSUPPORTED
320-
// https://github.com/swiftlang/swift/issues/79285
321-
_ closure: (PostgresConnection) async throws -> sending Result) async throws -> sending Result {
318+
_ closure: (PostgresConnection) async throws -> sending Result
319+
) async throws -> sending Result {
322320
let lease = try await self.leaseConnection()
323321

324322
defer { lease.release() }
@@ -346,41 +344,13 @@ public final class PostgresClient: Sendable, ServiceLifecycle.Service {
346344
file: String = #file,
347345
line: Int = #line,
348346
isolation: isolated (any Actor)? = #isolation,
349-
// DO NOT FIX THE WHITESPACE IN THE NEXT LINE UNTIL 5.10 IS UNSUPPORTED
350-
// https://github.com/swiftlang/swift/issues/79285
351-
_ closure: (PostgresConnection) async throws -> sending Result) async throws -> sending Result {
352-
try await self.withConnection { connection in
353-
try await connection.withTransaction(logger: logger, file: file, line: line, closure)
347+
_ closure: (PostgresConnection) async throws -> sending Result
348+
) async throws -> sending Result {
349+
// for 6.0 to compile we need to explicitly forward the isolation.
350+
try await self.withConnection(isolation: isolation) { connection in
351+
try await connection.withTransaction(logger: logger, file: file, line: line, isolation: isolation, closure)
354352
}
355353
}
356-
#else
357-
358-
/// Lease a connection, which is in an open transaction state, for the provided `closure`'s lifetime.
359-
///
360-
/// The function leases a connection from the underlying connection pool and starts a transaction by running a `BEGIN`
361-
/// query on the leased connection against the database. It then lends the connection to the user provided closure.
362-
/// The user can then modify the database as they wish. If the user provided closure returns successfully, the function
363-
/// will attempt to commit the changes by running a `COMMIT` query against the database. If the user provided closure
364-
/// throws an error, the function will attempt to rollback the changes made within the closure.
365-
///
366-
/// - Parameters:
367-
/// - logger: The `Logger` to log into for the transaction.
368-
/// - file: The file, the transaction was started in. Used for better error reporting.
369-
/// - line: The line, the transaction was started in. Used for better error reporting.
370-
/// - closure: The user provided code to modify the database. Use the provided connection to run queries.
371-
/// The connection must stay in the transaction mode. Otherwise this method will throw!
372-
/// - Returns: The closure's return value.
373-
public func withTransaction<Result>(
374-
logger: Logger,
375-
file: String = #file,
376-
line: Int = #line,
377-
_ closure: (PostgresConnection) async throws -> Result
378-
) async throws -> Result {
379-
try await self.withConnection { connection in
380-
try await connection.withTransaction(logger: logger, file: file, line: line, closure)
381-
}
382-
}
383-
#endif
384354

385355
/// Run a query on the Postgres server the client is connected to.
386356
///

0 commit comments

Comments
 (0)