Browse Source

Propagate generics from AsyncSequence to RPCAsyncSequence (#1980)

Motivation:

`RPCAsyncSequence` was added before we raised the minimum 
swift version to 6.0. As a result it used a fully erased sequence where
the iterator had to upcast from `Any` to the expected type. This 
causes an allocation per message.

Modification:

- Make `RPCAsyncSequence` generic over its `Element` and its `Failure` type
- This required bumping its availability to the latest SDKs which is 
  rather viral.
- Modify the code generator to allow visionOS to be specified
- Modify the code gen translator to bump the availability of generated code
- Regenerate

Result:

Fewer allocations
George Barnett 1 year ago
parent
commit
066b63059d
1 changed files with 24 additions and 24 deletions
  1. 24 24
      Tests/GRPCProtobufCodeGenTests/ProtobufCodeGeneratorTests.swift

+ 24 - 24
Tests/GRPCProtobufCodeGenTests/ProtobufCodeGeneratorTests.swift

@@ -73,14 +73,14 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
                     SayHello.descriptor
                 ]
             }
-            @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+            @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
             internal typealias ClientProtocol = Hello_World_GreeterClientProtocol
-            @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+            @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
             internal typealias Client = Hello_World_GreeterClient
         }
 
         /// The greeting service definition.
-        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+        @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
         internal protocol Hello_World_GreeterClientProtocol: Sendable {
             /// Sends a greeting.
             func sayHello<R>(
@@ -92,7 +92,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
             ) async throws -> R where R: Sendable
         }
 
-        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+        @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
         extension Hello_World_Greeter.ClientProtocol {
             internal func sayHello<R>(
                 request: ClientRequest.Single<Hello_World_HelloRequest>,
@@ -110,7 +110,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
         }
 
         /// The greeting service definition.
-        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+        @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
         internal struct Hello_World_GreeterClient: Hello_World_Greeter.ClientProtocol {
             private let client: GRPCCore.GRPCClient
             
@@ -188,23 +188,23 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
               SayHello.descriptor
             ]
           }
-          @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+          @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
           public typealias StreamingServiceProtocol = Helloworld_GreeterStreamingServiceProtocol
-          @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+          @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
           public typealias ServiceProtocol = Helloworld_GreeterServiceProtocol
         }
 
         /// The greeting service definition.
-        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+        @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
         public protocol Helloworld_GreeterStreamingServiceProtocol: GRPCCore.RegistrableRPCService {
           /// Sends a greeting.
           func sayHello(request: ServerRequest.Stream<Helloworld_HelloRequest>) async throws -> ServerResponse.Stream<Helloworld_HelloReply>
         }
 
         /// Conformance to `GRPCCore.RegistrableRPCService`.
-        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+        @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
         extension Helloworld_Greeter.StreamingServiceProtocol {
-          @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+          @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
           public func registerMethods(with router: inout GRPCCore.RPCRouter) {
             router.registerHandler(
               forMethod: Helloworld_Greeter.Method.SayHello.descriptor,
@@ -218,14 +218,14 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
         }
 
         /// The greeting service definition.
-        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+        @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
         public protocol Helloworld_GreeterServiceProtocol: Helloworld_Greeter.StreamingServiceProtocol {
           /// Sends a greeting.
           func sayHello(request: ServerRequest.Single<Helloworld_HelloRequest>) async throws -> ServerResponse.Single<Helloworld_HelloReply>
         }
 
         /// Partial conformance to `Helloworld_GreeterStreamingServiceProtocol`.
-        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+        @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
         extension Helloworld_Greeter.ServiceProtocol {
           public func sayHello(request: ServerRequest.Stream<Helloworld_HelloRequest>) async throws -> ServerResponse.Stream<Helloworld_HelloReply> {
             let response = try await self.sayHello(request: ServerRequest.Single(stream: request))
@@ -283,27 +283,27 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
               SayHello.descriptor
             ]
           }
-          @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+          @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
           package typealias StreamingServiceProtocol = GreeterStreamingServiceProtocol
-          @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+          @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
           package typealias ServiceProtocol = GreeterServiceProtocol
-          @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+          @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
           package typealias ClientProtocol = GreeterClientProtocol
-          @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+          @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
           package typealias Client = GreeterClient
         }
 
         /// The greeting service definition.
-        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+        @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
         package protocol GreeterStreamingServiceProtocol: GRPCCore.RegistrableRPCService {
           /// Sends a greeting.
           func sayHello(request: ServerRequest.Stream<HelloRequest>) async throws -> ServerResponse.Stream<HelloReply>
         }
 
         /// Conformance to `GRPCCore.RegistrableRPCService`.
-        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+        @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
         extension Greeter.StreamingServiceProtocol {
-          @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+          @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
           package func registerMethods(with router: inout GRPCCore.RPCRouter) {
             router.registerHandler(
               forMethod: Greeter.Method.SayHello.descriptor,
@@ -317,14 +317,14 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
         }
 
         /// The greeting service definition.
-        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+        @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
         package protocol GreeterServiceProtocol: Greeter.StreamingServiceProtocol {
           /// Sends a greeting.
           func sayHello(request: ServerRequest.Single<HelloRequest>) async throws -> ServerResponse.Single<HelloReply>
         }
 
         /// Partial conformance to `GreeterStreamingServiceProtocol`.
-        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+        @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
         extension Greeter.ServiceProtocol {
           package func sayHello(request: ServerRequest.Stream<HelloRequest>) async throws -> ServerResponse.Stream<HelloReply> {
             let response = try await self.sayHello(request: ServerRequest.Single(stream: request))
@@ -333,7 +333,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
         }
 
         /// The greeting service definition.
-        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+        @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
         package protocol GreeterClientProtocol: Sendable {
           /// Sends a greeting.
           func sayHello<R>(
@@ -345,7 +345,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
           ) async throws -> R where R: Sendable
         }
 
-        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+        @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
         extension Greeter.ClientProtocol {
           package func sayHello<R>(
             request: ClientRequest.Single<HelloRequest>,
@@ -363,7 +363,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
         }
 
         /// The greeting service definition.
-        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+        @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
         package struct GreeterClient: Greeter.ClientProtocol {
           private let client: GRPCCore.GRPCClient