Skip to content

Commit

Permalink
Add missing 'Sendable' conformance
Browse files Browse the repository at this point in the history
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
  • Loading branch information
glbrntt committed May 11, 2022
1 parent 65f7bee commit 235c68f
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 74 deletions.
4 changes: 2 additions & 2 deletions Sources/Examples/Echo/Model/echo.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ extension Echo_EchoAsyncClientProtocol {
public func collect<RequestStream>(
_ requests: RequestStream,
callOptions: CallOptions? = nil
) async throws -> Echo_EchoResponse where RequestStream: AsyncSequence, RequestStream.Element == Echo_EchoRequest {
) async throws -> Echo_EchoResponse where RequestStream: AsyncSequence & Sendable, RequestStream.Element == Echo_EchoRequest {
return try await self.performAsyncClientStreamingCall(
path: Echo_EchoClientMetadata.Methods.collect.path,
requests: requests,
Expand All @@ -340,7 +340,7 @@ extension Echo_EchoAsyncClientProtocol {
public func update<RequestStream>(
_ requests: RequestStream,
callOptions: CallOptions? = nil
) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: AsyncSequence, RequestStream.Element == Echo_EchoRequest {
) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: AsyncSequence & Sendable, RequestStream.Element == Echo_EchoRequest {
return self.performAsyncBidirectionalStreamingCall(
path: Echo_EchoClientMetadata.Methods.update.path,
requests: requests,
Expand Down
4 changes: 2 additions & 2 deletions Sources/Examples/RouteGuide/Model/route_guide.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ extension Routeguide_RouteGuideAsyncClientProtocol {
public func recordRoute<RequestStream>(
_ requests: RequestStream,
callOptions: CallOptions? = nil
) async throws -> Routeguide_RouteSummary where RequestStream: AsyncSequence, RequestStream.Element == Routeguide_Point {
) async throws -> Routeguide_RouteSummary where RequestStream: AsyncSequence & Sendable, RequestStream.Element == Routeguide_Point {
return try await self.performAsyncClientStreamingCall(
path: Routeguide_RouteGuideClientMetadata.Methods.recordRoute.path,
requests: requests,
Expand All @@ -359,7 +359,7 @@ extension Routeguide_RouteGuideAsyncClientProtocol {
public func routeChat<RequestStream>(
_ requests: RequestStream,
callOptions: CallOptions? = nil
) -> GRPCAsyncResponseStream<Routeguide_RouteNote> where RequestStream: AsyncSequence, RequestStream.Element == Routeguide_RouteNote {
) -> GRPCAsyncResponseStream<Routeguide_RouteNote> where RequestStream: AsyncSequence & Sendable, RequestStream.Element == Routeguide_RouteNote {
return self.performAsyncBidirectionalStreamingCall(
path: Routeguide_RouteGuideClientMetadata.Methods.routeChat.path,
requests: requests,
Expand Down
2 changes: 1 addition & 1 deletion Sources/GRPC/AsyncAwaitSupport/AsyncWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal final actor AsyncWriter<Delegate: AsyncWriterDelegate>: Sendable {
typealias PendingEnd = _Pending<End>

@usableFromInline
internal enum _CompletionState {
internal enum _CompletionState: Sendable {
/// Finish hasn't been called yet. May move to `pending` or `completed`.
case incomplete
/// Finish has been called but the writer is paused. May move to `completed`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import NIOHPACK

/// Async-await variant of BidirectionalStreamingCall.
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public struct GRPCAsyncBidirectionalStreamingCall<Request: Sendable, Response: Sendable> {
public struct GRPCAsyncBidirectionalStreamingCall<Request: Sendable, Response: Sendable>: Sendable {
private let call: Call<Request, Response>
private let responseParts: StreamingResponseParts<Response>
private let responseSource: PassthroughMessageSource<Response, Error>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import NIOHPACK

/// Async-await variant of `ClientStreamingCall`.
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public struct GRPCAsyncClientStreamingCall<Request: Sendable, Response: Sendable> {
public struct GRPCAsyncClientStreamingCall<Request: Sendable, Response: Sendable>: Sendable {
private let call: Call<Request, Response>
private let responseParts: UnaryResponseParts<Response>

Expand Down
5 changes: 5 additions & 0 deletions Sources/GRPC/AsyncAwaitSupport/GRPCAsyncRequestStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public struct GRPCAsyncRequestStream<Element: Sendable>: AsyncSequence {
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension GRPCAsyncRequestStream: Sendable where Element: Sendable {}
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension GRPCAsyncRequestStream.Iterator: Sendable where Element: Sendable {}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/// try await stream.finish()
/// ```
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public struct GRPCAsyncRequestStreamWriter<Request: Sendable> {
public struct GRPCAsyncRequestStreamWriter<Request: Sendable>: Sendable {
@usableFromInline
internal let asyncWriter: AsyncWriter<Delegate<Request>>

Expand Down
5 changes: 5 additions & 0 deletions Sources/GRPC/AsyncAwaitSupport/GRPCAsyncResponseStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ public struct GRPCAsyncResponseStream<Element>: AsyncSequence {
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension GRPCAsyncResponseStream: Sendable where Element: Sendable {}
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension GRPCAsyncResponseStream.Iterator: Sendable where Element: Sendable {}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

/// Writer for server-streaming RPC handlers to provide responses.
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public struct GRPCAsyncResponseStreamWriter<Response: Sendable> {
public struct GRPCAsyncResponseStreamWriter<Response: Sendable>: Sendable {
@usableFromInline
internal typealias Element = (Response, Compression)

Expand Down
2 changes: 1 addition & 1 deletion Sources/GRPC/AsyncAwaitSupport/GRPCAsyncUnaryCall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import NIOHPACK
/// Note: while this object is a `struct`, its implementation delegates to `Call`. It therefore
/// has reference semantics.
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public struct GRPCAsyncUnaryCall<Request: Sendable, Response: Sendable> {
public struct GRPCAsyncUnaryCall<Request: Sendable, Response: Sendable>: Sendable {
private let call: Call<Request, Response>
private let responseParts: UnaryResponseParts<Response>

Expand Down
Loading

0 comments on commit 235c68f

Please sign in to comment.