浏览代码

Add missing 'Sendable' conformance (#1404)

Motivation:

Sendable conformance was missing in a handful of places which generates
warnings in newer toolchains.

Modifications:

- Make client calls Sendable
- Client call wrappers should require Sendable types (this was
  implicitly enfored by calls requiring request and response types to be
  Sendable). This also requires the async sequence of requests to be
  Sendable for calls where requests are streamed which required a
  codegen change.
- Make the various gRPC async sequence types conditionally Sendable

Result:

Fewer warnings
George Barnett 3 年之前
父节点
当前提交
1f55d8029d
共有 1 个文件被更改,包括 11 次插入3 次删除
  1. 11 3
      Sources/protoc-gen-grpc-swift/Generator-Client+AsyncAwait.swift

+ 11 - 3
Sources/protoc-gen-grpc-swift/Generator-Client+AsyncAwait.swift

@@ -155,7 +155,10 @@ extension Generator {
         let streamsResponses = [.serverStreaming, .bidirectionalStreaming].contains(rpcType)
         let streamsRequests = [.clientStreaming, .bidirectionalStreaming].contains(rpcType)
 
-        let sequenceProtocols = streamsRequests ? ["Sequence", "AsyncSequence"] : [nil]
+        // (protocol, requires sendable)
+        let sequenceProtocols: [(String, Bool)?] = streamsRequests
+          ? [("Sequence", false), ("AsyncSequence", true)]
+          : [nil]
 
         for (j, sequenceProtocol) in sequenceProtocols.enumerated() {
           // Print a new line if this is not the first function in the extension.
@@ -170,8 +173,13 @@ extension Generator {
           let returnType = streamsResponses
             ? Types.responseStream(of: self.methodOutputName)
             : self.methodOutputName
-          let maybeWhereClause = sequenceProtocol.map {
-            "where RequestStream: \($0), RequestStream.Element == \(self.methodInputName)"
+          let maybeWhereClause = sequenceProtocol.map { protocolName, mustBeSendable -> String in
+            let constraints = [
+              "RequestStream: \(protocolName)" + (mustBeSendable ? " & Sendable" : ""),
+              "RequestStream.Element == \(self.methodInputName)",
+            ]
+
+            return "where " + constraints.joined(separator: ", ")
           }
           self.printFunction(
             name: functionName,