Skip to content

Commit d6ba1ea

Browse files
committed
Fixed GRPCCore issues when enabling explicit-sendable rule.
1 parent 0e52abf commit d6ba1ea

10 files changed

+52
-15
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ let defaultSwiftSettings: [SwiftSetting] =
6565
.enableUpcomingFeature("ExistentialAny"),
6666
.enableUpcomingFeature("InternalImportsByDefault"),
6767
.enableUpcomingFeature("MemberImportVisibility"),
68+
.unsafeFlags(["-Xfrontend", "-require-explicit-sendable"]),
6869
]
6970

7071
// -------------------------------------------------------------------------------------------------

Sources/GRPCCore/Call/Client/Internal/ClientRPCExecutor+HedgingExecutor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ extension ClientRPCExecutor.HedgingExecutor {
501501
}
502502

503503
@usableFromInline
504-
struct ScheduledState {
504+
struct ScheduledState: Sendable {
505505
@usableFromInline
506506
var _handle: CancellableTaskHandle?
507507
@usableFromInline

Sources/GRPCCore/Call/Client/Internal/ClientRPCExecutor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
@available(gRPCSwift 2.0, *)
1818
@usableFromInline
19-
enum ClientRPCExecutor {
19+
enum ClientRPCExecutor: Sendable {
2020
/// Execute the request and handle its response.
2121
///
2222
/// - Parameters:

Sources/GRPCCore/Call/Client/Internal/ClientStreamExecutor.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
@available(gRPCSwift 2.0, *)
1818
@usableFromInline
19-
internal enum ClientStreamExecutor {
19+
internal enum ClientStreamExecutor: Sendable {
2020
/// Execute a request on the stream executor.
2121
///
2222
/// - Parameters:
@@ -250,3 +250,6 @@ internal enum ClientStreamExecutor {
250250
}
251251
}
252252
}
253+
254+
@available(*, unavailable)
255+
extension ClientStreamExecutor.RawBodyPartToMessageSequence.AsyncIterator: Sendable {}

Sources/GRPCCore/Call/Client/Internal/RetryDelaySequence.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public import Musl // should be @usableFromInline
2727

2828
@available(gRPCSwift 2.0, *)
2929
@usableFromInline
30-
struct RetryDelaySequence: Sequence {
30+
struct RetryDelaySequence: Sequence, Sendable {
3131
@usableFromInline
3232
typealias Element = Duration
3333

@@ -45,7 +45,7 @@ struct RetryDelaySequence: Sequence {
4545
}
4646

4747
@usableFromInline
48-
struct Iterator: IteratorProtocol {
48+
struct Iterator: IteratorProtocol, Sendable {
4949
@usableFromInline
5050
let policy: RetryPolicy
5151
@usableFromInline

Sources/GRPCCore/Call/Server/Internal/ServerRPCExecutor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
@available(gRPCSwift 2.0, *)
1818
@usableFromInline
19-
struct ServerRPCExecutor {
19+
struct ServerRPCExecutor: Sendable {
2020
/// Executes an RPC using the provided handler.
2121
///
2222
/// - Parameters:
@@ -272,7 +272,7 @@ struct ServerRPCExecutor {
272272
}
273273

274274
@usableFromInline
275-
enum OnFirstRequestPart<Bytes: GRPCContiguousBytes> {
275+
enum OnFirstRequestPart<Bytes: GRPCContiguousBytes>: Sendable {
276276
case process(
277277
Metadata,
278278
UnsafeTransfer<RPCAsyncSequence<RPCRequestPart<Bytes>, any Error>.AsyncIterator>

Sources/GRPCCore/Coding/CompressionAlgorithm.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ extension CompressionAlgorithmSet {
9494
}
9595

9696
/// A sequence of ``CompressionAlgorithm`` values present in a ``CompressionAlgorithmSet``.
97-
public struct Elements: Sequence {
97+
public struct Elements: Sequence, Sendable {
9898
public typealias Element = CompressionAlgorithm
9999

100100
private let algorithmSet: CompressionAlgorithmSet
@@ -107,7 +107,7 @@ extension CompressionAlgorithmSet {
107107
return Iterator(algorithmSet: self.algorithmSet)
108108
}
109109

110-
public struct Iterator: IteratorProtocol {
110+
public struct Iterator: IteratorProtocol, Sendable {
111111
private let algorithmSet: CompressionAlgorithmSet
112112
private var iterator: IndexingIterator<[CompressionAlgorithm.Value]>
113113

Sources/GRPCCore/Streaming/Internal/AsyncSequenceOfOne.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct AsyncSequenceOfOne<Element: Sendable, Failure: Error>: AsyncSequence, Sen
4949
}
5050

5151
@usableFromInline
52-
struct AsyncIterator: AsyncIteratorProtocol {
52+
struct AsyncIterator: AsyncIteratorProtocol, Sendable {
5353
@usableFromInline
5454
private(set) var result: Result<Element, Failure>?
5555

Sources/GRPCCore/Streaming/Internal/BroadcastAsyncSequence.swift

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct BroadcastAsyncSequence<Element: Sendable>: Sendable, AsyncSequence {
8989
@available(gRPCSwift 2.0, *)
9090
extension BroadcastAsyncSequence {
9191
@usableFromInline
92-
struct AsyncIterator: AsyncIteratorProtocol {
92+
struct AsyncIterator: AsyncIteratorProtocol, Sendable {
9393
@usableFromInline
9494
let _storage: _BroadcastSequenceStorage<Element>
9595
@usableFromInline
@@ -1204,7 +1204,7 @@ struct _BroadcastSequenceStateMachine<Element: Sendable>: Sendable {
12041204
}
12051205

12061206
@usableFromInline
1207-
enum OnCancelSubscription {
1207+
enum OnCancelSubscription: Sendable {
12081208
case none
12091209
case resume(ConsumerContinuation, Result<Element?, any Error>)
12101210
}
@@ -1244,7 +1244,7 @@ struct _BroadcastSequenceStateMachine<Element: Sendable>: Sendable {
12441244
}
12451245

12461246
@usableFromInline
1247-
enum OnSubscribe {
1247+
enum OnSubscribe: Sendable {
12481248
case subscribed(_BroadcastSequenceStateMachine<Element>.Subscriptions.ID)
12491249
}
12501250

@@ -1282,7 +1282,7 @@ struct _BroadcastSequenceStateMachine<Element: Sendable>: Sendable {
12821282
}
12831283

12841284
@usableFromInline
1285-
enum OnWaitToProduceMore {
1285+
enum OnWaitToProduceMore: Sendable {
12861286
case none
12871287
case resume(ProducerContinuation, Result<Void, any Error>)
12881288
}
@@ -1498,7 +1498,7 @@ extension _BroadcastSequenceStateMachine {
14981498
}
14991499

15001500
@usableFromInline
1501-
enum ElementLookup {
1501+
enum ElementLookup: Sendable {
15021502
/// The element was found in the collection.
15031503
case found(Element)
15041504
/// The element isn't in the collection, but it could be in the future.
@@ -1810,3 +1810,33 @@ extension _BroadcastSequenceStateMachine {
18101810
case many([Value])
18111811
}
18121812
}
1813+
1814+
@available(*, unavailable)
1815+
extension _BroadcastSequenceStateMachine.ConsumerContinuations: Sendable {}
1816+
1817+
@available(*, unavailable)
1818+
extension _BroadcastSequenceStateMachine.ProducerContinuations: Sendable {}
1819+
1820+
@available(*, unavailable)
1821+
extension _BroadcastSequenceStateMachine.OnInvalidateAllSubscriptions: Sendable {}
1822+
1823+
@available(*, unavailable)
1824+
extension _BroadcastSequenceStateMachine.OnYield: Sendable {}
1825+
1826+
@available(*, unavailable)
1827+
extension _BroadcastSequenceStateMachine.OnFinish: Sendable {}
1828+
1829+
@available(*, unavailable)
1830+
extension _BroadcastSequenceStateMachine.OnNext: Sendable {}
1831+
1832+
@available(*, unavailable)
1833+
extension _BroadcastSequenceStateMachine.OnNext.ReturnAndResumeProducers: Sendable {}
1834+
1835+
@available(*, unavailable)
1836+
extension _BroadcastSequenceStateMachine.OnSetContinuation: Sendable {}
1837+
1838+
@available(*, unavailable)
1839+
extension _BroadcastSequenceStateMachine.OnDropResources: Sendable {}
1840+
1841+
@available(*, unavailable)
1842+
extension _BroadcastSequenceStateMachine._OneOrMany: Sendable {}

Sources/GRPCCore/Streaming/Internal/UncheckedAsyncIteratorSequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,6 @@ final class UncheckedAsyncIteratorSequence<
8080
return AsyncIterator(base: self.base)
8181
}
8282
}
83+
84+
@available(*, unavailable)
85+
extension UncheckedAsyncIteratorSequence.AsyncIterator: Sendable {}

0 commit comments

Comments
 (0)