Skip to content

Commit 1df363c

Browse files
authored
Enable "ExistentialAny" upcoming feature (#622)
1 parent 7fa45c5 commit 1df363c

29 files changed

Lines changed: 113 additions & 111 deletions

Package.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import PackageDescription
33

44
#if compiler(>=6.1)
55
let swiftSettings: [SwiftSetting] = [
6-
.enableUpcomingFeature("NonisolatedNonsendingByDefault")
6+
.enableUpcomingFeature("ExistentialAny"),
7+
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
78
]
89
#else
910
let swiftSettings: [SwiftSetting] = [
11+
.enableUpcomingFeature("ExistentialAny"),
1012
// Sadly the 6.0 compiler concurrency checker finds false positives.
1113
// To be able to compile, lets reduce the language version down to 5 for 6.0 only.
12-
.swiftLanguageMode(.v5)
14+
.swiftLanguageMode(.v5),
1315
]
1416
#endif
1517

Sources/ConnectionPoolModule/ConnectionPool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ public final class ConnectionPool<
484484
}
485485

486486
@inlinable
487-
/*private*/ func connectionEstablishFailed(_ error: Error, for request: StateMachine.ConnectionRequest) {
487+
/*private*/ func connectionEstablishFailed(_ error: any Error, for request: StateMachine.ConnectionRequest) {
488488
self.observabilityDelegate.connectFailed(id: request.connectionID, error: error)
489489

490490
self.modifyStateAndRunActions { state in

Sources/ConnectionPoolModule/ConnectionPoolObservabilityDelegate.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public protocol ConnectionPoolObservabilityDelegate: Sendable {
99

1010
/// A connection attempt failed with the given error. After some period of
1111
/// time ``startedConnecting(id:)`` may be called again.
12-
func connectFailed(id: ConnectionID, error: Error)
12+
func connectFailed(id: ConnectionID, error: any Error)
1313

1414
/// A connection was established on the connection with the given ID. `streamCapacity` streams are
1515
/// available to use on the connection. The maximum number of available streams may change over
@@ -24,15 +24,15 @@ public protocol ConnectionPoolObservabilityDelegate: Sendable {
2424

2525
func keepAliveSucceeded(id: ConnectionID)
2626

27-
func keepAliveFailed(id: ConnectionID, error: Error)
27+
func keepAliveFailed(id: ConnectionID, error: any Error)
2828

2929
/// The remote peer is quiescing the connection: no new streams will be created on it. The
3030
/// connection will eventually be closed and removed from the pool.
3131
func connectionClosing(id: ConnectionID)
3232

3333
/// The connection was closed. The connection may be established again in the future (notified
3434
/// via ``startedConnecting(id:)``).
35-
func connectionClosed(id: ConnectionID, error: Error?)
35+
func connectionClosed(id: ConnectionID, error: (any Error)?)
3636

3737
func requestQueueDepthChanged(_ newDepth: Int)
3838
}
@@ -42,7 +42,7 @@ public struct NoOpConnectionPoolMetrics<ConnectionID: Hashable & Sendable>: Conn
4242

4343
public func startedConnecting(id: ConnectionID) {}
4444

45-
public func connectFailed(id: ConnectionID, error: Error) {}
45+
public func connectFailed(id: ConnectionID, error: any Error) {}
4646

4747
public func connectSucceeded(id: ConnectionID, streamCapacity: UInt16) {}
4848

@@ -52,11 +52,11 @@ public struct NoOpConnectionPoolMetrics<ConnectionID: Hashable & Sendable>: Conn
5252

5353
public func keepAliveSucceeded(id: ConnectionID) {}
5454

55-
public func keepAliveFailed(id: ConnectionID, error: Error) {}
55+
public func keepAliveFailed(id: ConnectionID, error: any Error) {}
5656

5757
public func connectionClosing(id: ConnectionID) {}
5858

59-
public func connectionClosed(id: ConnectionID, error: Error?) {}
59+
public func connectionClosed(id: ConnectionID, error: (any Error)?) {}
6060

6161
public func requestQueueDepthChanged(_ newDepth: Int) {}
6262
}

Sources/ConnectionPoolModule/PoolStateMachine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ struct PoolStateMachine<
432432
}
433433

434434
@inlinable
435-
mutating func connectionEstablishFailed(_ error: Error, for request: ConnectionRequest) -> Action {
435+
mutating func connectionEstablishFailed(_ error: any Error, for request: ConnectionRequest) -> Action {
436436
switch self.poolState {
437437
case .running:
438438
self.poolState = .connectionCreationFailing(

Sources/PostgresNIO/Connection/PostgresConnection+Configuration.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ extension PostgresConnection {
130130
/// The `Channel` to use in existing-channel configurations.
131131
///
132132
/// Always `nil` for other configurations.
133-
public var establishedChannel: Channel? {
133+
public var establishedChannel: (any Channel)? {
134134
if case let .configureChannel(channel) = self.endpointInfo { return channel }
135135
else { return nil }
136136
}
@@ -193,7 +193,7 @@ extension PostgresConnection {
193193
/// - channel: The `NIOCore/Channel` to use. The channel must already be active and connected to an
194194
/// endpoint (i.e. `NIOCore/Channel/isActive` must be `true`).
195195
/// - tls: The TLS mode to use.
196-
public init(establishedChannel channel: Channel, tls: PostgresConnection.Configuration.TLS, username: String, password: String?, database: String?) {
196+
public init(establishedChannel channel: any Channel, tls: PostgresConnection.Configuration.TLS, username: String, password: String?, database: String?) {
197197
self.init(endpointInfo: .configureChannel(channel), tls: tls, username: username, password: password, database: database)
198198
}
199199

@@ -206,14 +206,14 @@ extension PostgresConnection {
206206
/// - Parameters:
207207
/// - channel: The `NIOCore/Channel` to use. The channel must already be active and connected to an
208208
/// endpoint (i.e. `NIOCore/Channel/isActive` must be `true`).
209-
public init(establishedChannel channel: Channel, username: String, password: String?, database: String?) {
209+
public init(establishedChannel channel: any Channel, username: String, password: String?, database: String?) {
210210
self.init(establishedChannel: channel, tls: .disable, username: username, password: password, database: database)
211211
}
212212

213213
// MARK: - Implementation details
214214

215215
enum EndpointInfo {
216-
case configureChannel(Channel)
216+
case configureChannel(any Channel)
217217
case bindUnixDomainSocket(path: String)
218218
case connectTCP(host: String, port: Int)
219219
}
@@ -242,7 +242,7 @@ extension PostgresConnection {
242242
case unresolvedTCP(host: String, port: Int)
243243
case unresolvedUDS(path: String)
244244
case resolved(address: SocketAddress)
245-
case bootstrapped(channel: Channel)
245+
case bootstrapped(channel: any Channel)
246246
}
247247

248248
let connection: InternalConfiguration.Connection

Sources/PostgresNIO/Connection/PostgresConnection.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public final class PostgresConnection: @unchecked Sendable {
1717
/// The connection's underlying channel
1818
///
1919
/// This should be private, but it is needed for `PostgresConnection` compatibility.
20-
internal let channel: Channel
20+
internal let channel: any Channel
2121

2222
/// The underlying `EventLoop` of both the connection and its channel.
23-
public var eventLoop: EventLoop {
23+
public var eventLoop: any EventLoop {
2424
return self.channel.eventLoop
2525
}
2626

@@ -48,7 +48,7 @@ public final class PostgresConnection: @unchecked Sendable {
4848

4949
private var _logger: Logger
5050

51-
init(channel: Channel, connectionID: ID, logger: Logger) {
51+
init(channel: any Channel, connectionID: ID, logger: Logger) {
5252
self.channel = channel
5353
self.id = connectionID
5454
self._logger = logger
@@ -60,7 +60,7 @@ public final class PostgresConnection: @unchecked Sendable {
6060
func start(configuration: InternalConfiguration) -> EventLoopFuture<Void> {
6161
// 1. configure handlers
6262

63-
let configureSSLCallback: ((Channel, PostgresChannelHandler) throws -> ())?
63+
let configureSSLCallback: ((any Channel, PostgresChannelHandler) throws -> ())?
6464

6565
switch configuration.tls.base {
6666
case .prefer(let context), .require(let context):
@@ -124,7 +124,7 @@ public final class PostgresConnection: @unchecked Sendable {
124124
/// - Returns: A SwiftNIO `EventLoopFuture` that will provide a ``PostgresConnection``
125125
/// at a later point in time.
126126
public static func connect(
127-
on eventLoop: EventLoop,
127+
on eventLoop: any EventLoop,
128128
configuration: PostgresConnection.Configuration,
129129
id connectionID: ID,
130130
logger: Logger
@@ -141,7 +141,7 @@ public final class PostgresConnection: @unchecked Sendable {
141141
connectionID: ID,
142142
configuration: PostgresConnection.InternalConfiguration,
143143
logger: Logger,
144-
on eventLoop: EventLoop
144+
on eventLoop: any EventLoop
145145
) -> EventLoopFuture<PostgresConnection> {
146146

147147
var mlogger = logger
@@ -156,7 +156,7 @@ public final class PostgresConnection: @unchecked Sendable {
156156
// on and the EventLoop. In addition, it eliminates all potential races between the creating
157157
// thread and the EventLoop.
158158
return eventLoop.flatSubmit { () -> EventLoopFuture<PostgresConnection> in
159-
let connectFuture: EventLoopFuture<Channel>
159+
let connectFuture: EventLoopFuture<any Channel>
160160

161161
switch configuration.connection {
162162
case .resolved(let address):
@@ -190,9 +190,9 @@ public final class PostgresConnection: @unchecked Sendable {
190190
}
191191

192192
static func makeBootstrap(
193-
on eventLoop: EventLoop,
193+
on eventLoop: any EventLoop,
194194
configuration: PostgresConnection.InternalConfiguration
195-
) -> NIOClientTCPBootstrapProtocol {
195+
) -> any NIOClientTCPBootstrapProtocol {
196196
#if canImport(Network)
197197
if let tsBootstrap = NIOTSConnectionBootstrap(validatingGroup: eventLoop) {
198198
return tsBootstrap.connectTimeout(configuration.options.connectTimeout)
@@ -295,7 +295,7 @@ extension PostgresConnection {
295295
tlsConfiguration: TLSConfiguration? = nil,
296296
serverHostname: String? = nil,
297297
logger: Logger = .init(label: "codes.vapor.postgres"),
298-
on eventLoop: EventLoop
298+
on eventLoop: any EventLoop
299299
) -> EventLoopFuture<PostgresConnection> {
300300
var tlsFuture: EventLoopFuture<PostgresConnection.Configuration.TLS>
301301

@@ -368,7 +368,7 @@ extension PostgresConnection {
368368
/// - logger: A logger to log background events into
369369
/// - Returns: An established ``PostgresConnection`` asynchronously that can be used to run queries.
370370
public static func connect(
371-
on eventLoop: EventLoop = PostgresConnection.defaultEventLoopGroup.any(),
371+
on eventLoop: any EventLoop = PostgresConnection.defaultEventLoopGroup.any(),
372372
configuration: PostgresConnection.Configuration,
373373
id connectionID: ID,
374374
logger: Logger
@@ -677,7 +677,7 @@ extension PostgresConnection {
677677

678678
extension PostgresConnection: PostgresDatabase {
679679
public func send(
680-
_ request: PostgresRequest,
680+
_ request: any PostgresRequest,
681681
logger: Logger
682682
) -> EventLoopFuture<Void> {
683683
guard let command = request as? PostgresCommands else {
@@ -832,7 +832,7 @@ extension PostgresConnection {
832832
/// Returns the default `EventLoopGroup` singleton, automatically selecting the best for the platform.
833833
///
834834
/// This will select the concrete `EventLoopGroup` depending which platform this is running on.
835-
public static var defaultEventLoopGroup: EventLoopGroup {
835+
public static var defaultEventLoopGroup: any EventLoopGroup {
836836
#if canImport(Network)
837837
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) {
838838
return NIOTSEventLoopGroup.singleton

Sources/PostgresNIO/Connection/PostgresDatabase+PreparedQuery.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ extension PostgresDatabase {
3030

3131
public struct PreparedQuery: Sendable {
3232
let underlying: PSQLPreparedStatement
33-
let database: PostgresDatabase
33+
let database: any PostgresDatabase
3434

35-
init(underlying: PSQLPreparedStatement, database: PostgresDatabase) {
35+
init(underlying: PSQLPreparedStatement, database: any PostgresDatabase) {
3636
self.underlying = underlying
3737
self.database = database
3838
}

Sources/PostgresNIO/New/Connection State Machine/ListenStateMachine.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct ListenStateMachine {
2626
return self.channels[channel]!.startListeningSucceeded()
2727
}
2828

29-
mutating func startListeningFailed(channel: String, error: Error) -> Dictionary<Int, NotificationListener>.Values {
29+
mutating func startListeningFailed(channel: String, error: any Error) -> Dictionary<Int, NotificationListener>.Values {
3030
return self.channels[channel]!.startListeningFailed(error)
3131
}
3232

@@ -56,7 +56,7 @@ struct ListenStateMachine {
5656
return self.channels[channel]?.cancelListening(id: id) ?? .none
5757
}
5858

59-
mutating func fail(_ error: Error) -> [NotificationListener] {
59+
mutating func fail(_ error: any Error) -> [NotificationListener] {
6060
var result = [NotificationListener]()
6161
while var (_, channel) = self.channels.popFirst() {
6262
switch channel.fail(error) {
@@ -89,7 +89,7 @@ extension ListenStateMachine {
8989
case starting([Int: NotificationListener])
9090
case listening([Int: NotificationListener])
9191
case stopping([Int: NotificationListener])
92-
case failed(Error)
92+
case failed(any Error)
9393
}
9494

9595
private var state: State
@@ -143,7 +143,7 @@ extension ListenStateMachine {
143143
}
144144
}
145145

146-
mutating func startListeningFailed(_ error: Error) -> Dictionary<Int, NotificationListener>.Values {
146+
mutating func startListeningFailed(_ error: any Error) -> Dictionary<Int, NotificationListener>.Values {
147147
switch self.state {
148148
case .initialized, .listening, .stopping:
149149
fatalError("Invalid state: \(self.state)")
@@ -221,7 +221,7 @@ extension ListenStateMachine {
221221
case none
222222
}
223223

224-
mutating func fail(_ error: Error) -> FailAction {
224+
mutating func fail(_ error: any Error) -> FailAction {
225225
switch self.state {
226226
case .initialized:
227227
return .none

Sources/PostgresNIO/New/NotificationListener.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import NIOCore
22

33
// This object is @unchecked Sendable, since we syncronize state on the EL
44
final class NotificationListener: @unchecked Sendable {
5-
let eventLoop: EventLoop
5+
let eventLoop: any EventLoop
66

77
let channel: String
88
let id: Int
99

1010
private var state: State
1111

1212
enum State {
13-
case streamInitialized(CheckedContinuation<PostgresNotificationSequence, Error>)
14-
case streamListening(AsyncThrowingStream<PostgresNotification, Error>.Continuation)
13+
case streamInitialized(CheckedContinuation<PostgresNotificationSequence, any Error>)
14+
case streamListening(AsyncThrowingStream<PostgresNotification, any Error>.Continuation)
1515

1616
case closure(PostgresListenContext, (PostgresListenContext, PostgresMessage.NotificationResponse) -> Void)
1717
case done
@@ -31,8 +31,8 @@ final class NotificationListener: @unchecked Sendable {
3131
init(
3232
channel: String,
3333
id: Int,
34-
eventLoop: EventLoop,
35-
checkedContinuation: CheckedContinuation<PostgresNotificationSequence, Error>
34+
eventLoop: any EventLoop,
35+
checkedContinuation: CheckedContinuation<PostgresNotificationSequence, any Error>
3636
) {
3737
self.channel = channel
3838
self.id = id
@@ -43,7 +43,7 @@ final class NotificationListener: @unchecked Sendable {
4343
init(
4444
channel: String,
4545
id: Int,
46-
eventLoop: EventLoop,
46+
eventLoop: any EventLoop,
4747
context: PostgresListenContext,
4848
closure: @Sendable @escaping (PostgresListenContext, PostgresMessage.NotificationResponse) -> Void
4949
) {
@@ -109,7 +109,7 @@ final class NotificationListener: @unchecked Sendable {
109109
}
110110
}
111111

112-
func failed(_ error: Error) {
112+
func failed(_ error: any Error) {
113113
self.eventLoop.preconditionInEventLoop()
114114

115115
switch self.state {

0 commit comments

Comments
 (0)