Browse Source

Fix a handful of Sendable warnings (#1419)

Motivation:

We require all request/response types to be `Sendable` as they always cross a
thread boundary. Our various async sequences and async writers are conditionally
Sendable if their `Element` is `Sendable`, however, in practice they always will
be. We require them to be `Sendable` as they are arguments to `async` functions
(see SE-0338). For the same reason, the async server context (and by extension
the async server handler) must also be `Sendable`.

Modifications:

- Require passthrough message/source sequence to have `Sendable` elements so
  that they are unconditionally `Sendable`
- Make the async server context and handler `Sendable`
- Make the async writer error Sendable
- Remove a global variable from protoc-gen-grpc-swift
- Add appropriate conditions to extensions on `Call` which define functions
  requiring `Call` to be `Sendable`

Result:

Better `Sendable` support.
George Barnett 3 years ago
parent
commit
4da08a1c70
1 changed files with 7 additions and 4 deletions
  1. 7 4
      Sources/protoc-gen-grpc-swift/main.swift

+ 7 - 4
Sources/protoc-gen-grpc-swift/main.swift

@@ -80,12 +80,11 @@ func outputFileName(
   }
 }
 
-var generatedFiles: [String: Int] = [:]
-
 func uniqueOutputFileName(
   component: String,
   fileDescriptor: FileDescriptor,
-  fileNamingOption: FileNaming
+  fileNamingOption: FileNaming,
+  generatedFiles: inout [String: Int]
 ) -> String {
   let defaultName = outputFileName(
     component: component,
@@ -121,6 +120,9 @@ func main() throws {
   // Build the SwiftProtobufPluginLibrary model of the plugin input
   let descriptorSet = DescriptorSet(protos: request.protoFile)
 
+  // A count of generated files by desired name (actual name may differ to avoid collisions).
+  var generatedFiles: [String: Int] = [:]
+
   // Only generate output for services.
   for name in request.fileToGenerate {
     let fileDescriptor = descriptorSet.lookupFileDescriptor(protoName: name)
@@ -128,7 +130,8 @@ func main() throws {
       let grpcFileName = uniqueOutputFileName(
         component: "grpc",
         fileDescriptor: fileDescriptor,
-        fileNamingOption: options.fileNaming
+        fileNamingOption: options.fileNaming,
+        generatedFiles: &generatedFiles
       )
       let grpcGenerator = Generator(fileDescriptor, options: options)
       var grpcFile = Google_Protobuf_Compiler_CodeGeneratorResponse.File()