Browse Source

Enable ExistentialAny for v2 (#1967)

Motivation:

The use of existentials can be made more obvious by enabling
the upcoming 'ExistentialAny' feature.

Modifications:

Enable 'ExistentialAny' and fix warnings.

Result:

Use of existentials is more obvious
George Barnett 1 year ago
parent
commit
ddcd2fe2a6

+ 4 - 4
Sources/GRPCHTTP2Core/Client/Connection/ClientConnectionHandler.swift

@@ -30,7 +30,7 @@ public enum ClientConnectionEvent: Sendable {
     /// The local peer initiated the close.
     case initiatedLocally
     /// The connection was closed unexpectedly
-    case unexpected(Error?, isIdle: Bool)
+    case unexpected((any Error)?, isIdle: Bool)
   }
 
   /// The connection is now ready.
@@ -62,7 +62,7 @@ final class ClientConnectionHandler: ChannelInboundHandler, ChannelOutboundHandl
   }
 
   /// The `EventLoop` of the `Channel` this handler exists in.
-  private let eventLoop: EventLoop
+  private let eventLoop: any EventLoop
 
   /// The maximum amount of time the connection may be idle for. If the connection remains idle
   /// (i.e. has no open streams) for this period of time then the connection will be gracefully
@@ -104,7 +104,7 @@ final class ClientConnectionHandler: ChannelInboundHandler, ChannelOutboundHandl
   ///   - keepaliveWithoutCalls: Whether the client sends keep-alive pings when there are no calls
   ///       in progress.
   init(
-    eventLoop: EventLoop,
+    eventLoop: any EventLoop,
     maxIdleTime: TimeAmount?,
     keepaliveTime: TimeAmount?,
     keepaliveTimeout: TimeAmount?,
@@ -612,7 +612,7 @@ extension ClientConnectionHandler {
 
     enum OnClosed {
       case succeed(EventLoopPromise<Void>)
-      case unexpectedClose(Error?, isIdle: Bool)
+      case unexpectedClose((any Error)?, isIdle: Bool)
       case none
     }
 

+ 1 - 1
Sources/GRPCHTTP2Core/Client/Connection/Connection.swift

@@ -69,7 +69,7 @@ struct Connection: Sendable {
     /// Closed because the remote peer initiate shutdown (i.e. sent a GOAWAY frame).
     case remote
     /// Closed because the connection encountered an unexpected error.
-    case error(Error, wasIdle: Bool)
+    case error(any Error, wasIdle: Bool)
   }
 
   /// Inputs to the 'run' method.

+ 6 - 6
Sources/GRPCHTTP2Core/Client/Connection/GRPCChannel.swift

@@ -264,9 +264,9 @@ extension GRPCChannel {
     /// A stream was created, use it.
     case created(Connection.Stream)
     /// An error occurred while trying to create a stream, try again if possible.
-    case tryAgain(Error)
+    case tryAgain(any Error)
     /// An unrecoverable error occurred (e.g. the channel is closed), fail the RPC and don't retry.
-    case stopTrying(Error)
+    case stopTrying(any Error)
   }
 
   private func makeStream(
@@ -734,8 +734,8 @@ extension GRPCChannel.StateMachine {
     var finish: Bool = false
 
     struct ResumableContinuations {
-      var continuations: [CheckedContinuation<LoadBalancer, Error>]
-      var result: Result<LoadBalancer, Error>
+      var continuations: [CheckedContinuation<LoadBalancer, any Error>]
+      var result: Result<LoadBalancer, any Error>
     }
   }
 
@@ -878,7 +878,7 @@ extension GRPCChannel.StateMachine {
   }
 
   mutating func enqueue(
-    continuation: CheckedContinuation<LoadBalancer, Error>,
+    continuation: CheckedContinuation<LoadBalancer, any Error>,
     waitForReady: Bool,
     id: QueueEntryID
   ) -> Bool {
@@ -902,7 +902,7 @@ extension GRPCChannel.StateMachine {
 
   mutating func dequeueContinuation(
     id: QueueEntryID
-  ) -> CheckedContinuation<LoadBalancer, Error>? {
+  ) -> CheckedContinuation<LoadBalancer, any Error>? {
     switch self.state {
     case .notRunning(var state):
       self.state = ._modifying

+ 1 - 1
Sources/GRPCHTTP2Core/Client/Connection/RequestQueue.swift

@@ -18,7 +18,7 @@ import DequeModule
 
 @available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
 struct RequestQueue {
-  typealias Continuation = CheckedContinuation<LoadBalancer, Error>
+  typealias Continuation = CheckedContinuation<LoadBalancer, any Error>
 
   private struct QueueEntry {
     var continuation: Continuation

+ 1 - 1
Sources/GRPCHTTP2Core/Internal/NIOChannelPipeline+GRPC.swift

@@ -107,7 +107,7 @@ extension ChannelPipeline.SynchronousOperations {
   @_spi(Package)
   @available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
   public func configureGRPCClientPipeline(
-    channel: Channel,
+    channel: any Channel,
     config: GRPCChannel.Config
   ) throws -> (
     NIOAsyncChannel<ClientConnectionEvent, Void>,

+ 1 - 1
Sources/GRPCHTTP2Core/Internal/Timer.swift

@@ -45,7 +45,7 @@ struct Timer {
   }
 
   /// Schedule a task on the given `EventLoop`.
-  mutating func schedule(on eventLoop: EventLoop, work: @escaping @Sendable () throws -> Void) {
+  mutating func schedule(on eventLoop: any EventLoop, work: @escaping @Sendable () throws -> Void) {
     self.task?.cancel()
 
     if self.repeat {

+ 2 - 2
Sources/GRPCHTTP2Core/Server/Connection/ServerConnectionManagementHandler.swift

@@ -44,7 +44,7 @@ final class ServerConnectionManagementHandler: ChannelDuplexHandler {
   typealias OutboundOut = HTTP2Frame
 
   /// The `EventLoop` of the `Channel` this handler exists in.
-  private let eventLoop: EventLoop
+  private let eventLoop: any EventLoop
 
   /// The maximum amount of time a connection may be idle for. If the connection remains idle
   /// (i.e. has no open streams) for this period of time then the connection will be gracefully
@@ -201,7 +201,7 @@ final class ServerConnectionManagementHandler: ChannelDuplexHandler {
   ///       connection is closed if there are too many strikes.
   ///   - clock: A clock providing the current time.
   init(
-    eventLoop: EventLoop,
+    eventLoop: any EventLoop,
     maxIdleTime: TimeAmount?,
     maxAge: TimeAmount?,
     maxGraceTime: TimeAmount?,

+ 1 - 1
Sources/GRPCHTTP2TransportNIOPosix/HTTP2ServerTransport+Posix.swift

@@ -341,7 +341,7 @@ extension ServerBootstrap {
   @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
   fileprivate func bind<Output: Sendable>(
     to address: GRPCHTTP2Core.SocketAddress,
-    childChannelInitializer: @escaping @Sendable (Channel) -> EventLoopFuture<Output>
+    childChannelInitializer: @escaping @Sendable (any Channel) -> EventLoopFuture<Output>
   ) async throws -> NIOAsyncChannel<Output, Never> {
     if let virtualSocket = address.virtualSocket {
       return try await self.bind(

+ 1 - 1
Sources/GRPCHTTP2TransportNIOPosix/NIOClientBootstrap+SocketAddress.swift

@@ -23,7 +23,7 @@ extension ClientBootstrap {
   @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
   func connect<Result: Sendable>(
     to address: GRPCHTTP2Core.SocketAddress,
-    _ configure: @Sendable @escaping (Channel) -> EventLoopFuture<Result>
+    _ configure: @Sendable @escaping (any Channel) -> EventLoopFuture<Result>
   ) async throws -> Result {
     if let ipv4 = address.ipv4 {
       return try await self.connect(to: NIOCore.SocketAddress(ipv4), channelInitializer: configure)

+ 1 - 1
Sources/GRPCHTTP2TransportNIOTransportServices/HTTP2ServerTransport+TransportServices.swift

@@ -332,7 +332,7 @@ extension NIOCore.SocketAddress {
 extension NIOTSListenerBootstrap {
   fileprivate func bind<Output: Sendable>(
     to address: GRPCHTTP2Core.SocketAddress,
-    childChannelInitializer: @escaping @Sendable (Channel) -> EventLoopFuture<Output>
+    childChannelInitializer: @escaping @Sendable (any Channel) -> EventLoopFuture<Output>
   ) async throws -> NIOAsyncChannel<Output, Never> {
     if address.virtualSocket != nil {
       throw RuntimeError(