Skip to content

Commit 3fdc52d

Browse files
authored
Marked objects as Sendable or explicitly not Sendable (#8)
* Fixed GRPCCore issues when enabling explicit-sendable rule. * Changed the code to enable -require-explicit-sendable compiler flag. * Removed -require-explicit-sendable flag from Package manifest. * Fixed formatting issue. * Marked AsyncIterators as not Sendable * Added Sendable conformance back to Iterators.
1 parent 0e52abf commit 3fdc52d

10 files changed

+67
-22
lines changed

Sources/GRPCCodeGen/CodeGenerationRequest.swift

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public struct CodeGenerationRequest {
8282
}
8383
}
8484

85+
@available(*, unavailable)
86+
extension CodeGenerationRequest: Sendable {}
87+
8588
@available(gRPCSwift 2.0, *)
8689
extension CodeGenerationRequest {
8790
@available(*, deprecated, renamed: "makeSerializerSnippet")
@@ -123,7 +126,7 @@ extension CodeGenerationRequest {
123126

124127
/// Represents an import: a module or a specific item from a module.
125128
@available(gRPCSwift 2.0, *)
126-
public struct Dependency: Equatable {
129+
public struct Dependency: Equatable, Sendable {
127130
/// If the dependency is an item, the property's value is the item representation.
128131
/// If the dependency is a module, this property is nil.
129132
public var item: Item?
@@ -158,7 +161,7 @@ public struct Dependency: Equatable {
158161
}
159162

160163
/// Represents an item imported from a module.
161-
public struct Item: Equatable {
164+
public struct Item: Equatable, Sendable {
162165
/// The keyword that specifies the item's kind (e.g. `func`, `struct`).
163166
public var kind: Kind
164167

@@ -171,7 +174,7 @@ public struct Dependency: Equatable {
171174
}
172175

173176
/// Represents the imported item's kind.
174-
public struct Kind: Equatable {
177+
public struct Kind: Equatable, Sendable {
175178
/// Describes the keyword associated with the imported item.
176179
internal enum Value: String {
177180
case `typealias`
@@ -233,7 +236,7 @@ public struct Dependency: Equatable {
233236
}
234237

235238
/// Describes any requirement for the `@preconcurrency` attribute.
236-
public struct PreconcurrencyRequirement: Equatable {
239+
public struct PreconcurrencyRequirement: Equatable, Sendable {
237240
internal enum Value: Equatable {
238241
case required
239242
case notRequired
@@ -265,7 +268,7 @@ public struct Dependency: Equatable {
265268

266269
/// Represents a service described in an IDL file.
267270
@available(gRPCSwift 2.0, *)
268-
public struct ServiceDescriptor: Hashable {
271+
public struct ServiceDescriptor: Hashable, Sendable {
269272
/// Documentation from comments above the IDL service description.
270273
/// It is already formatted, meaning it contains "///" and new lines.
271274
public var documentation: String
@@ -323,7 +326,7 @@ extension ServiceDescriptor {
323326

324327
/// Represents a method described in an IDL file.
325328
@available(gRPCSwift 2.0, *)
326-
public struct MethodDescriptor: Hashable {
329+
public struct MethodDescriptor: Hashable, Sendable {
327330
/// Documentation from comments above the IDL method description.
328331
/// It is already formatted, meaning it contains "///" and new lines.
329332
public var documentation: String
@@ -388,7 +391,7 @@ extension MethodDescriptor {
388391
}
389392

390393
@available(gRPCSwift 2.0, *)
391-
public struct ServiceName: Hashable {
394+
public struct ServiceName: Hashable, Sendable {
392395
/// The identifying name as used in the service/method descriptors including any namespace.
393396
///
394397
/// This value is also used to identify the service to the remote peer, usually as part of the
@@ -423,7 +426,7 @@ public struct ServiceName: Hashable {
423426
}
424427

425428
@available(gRPCSwift 2.0, *)
426-
public struct MethodName: Hashable {
429+
public struct MethodName: Hashable, Sendable {
427430
/// The identifying name as used in the service/method descriptors.
428431
///
429432
/// This value is also used to identify the method to the remote peer, usually as part of the
@@ -455,7 +458,7 @@ public struct MethodName: Hashable {
455458
/// Represents the name associated with a namespace, service or a method, in three different formats.
456459
@available(*, deprecated, message: "Use ServiceName/MethodName instead.")
457460
@available(gRPCSwift 2.0, *)
458-
public struct Name: Hashable {
461+
public struct Name: Hashable, Sendable {
459462
/// The base name is the name used for the namespace/service/method in the IDL file, so it should follow
460463
/// the specific casing of the IDL.
461464
///

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,6 @@ struct AsyncSequenceOfOne<Element: Sendable, Failure: Error>: AsyncSequence, Sen
7474
}
7575
}
7676
}
77+
78+
@available(*, unavailable)
79+
extension AsyncSequenceOfOne.AsyncIterator: Sendable {}

Sources/GRPCCore/Streaming/Internal/BroadcastAsyncSequence.swift

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ extension BroadcastAsyncSequence {
111111
}
112112
}
113113

114+
@available(*, unavailable)
115+
extension BroadcastAsyncSequence.AsyncIterator: Sendable {}
116+
114117
// MARK: - Continuation
115118

116119
@available(gRPCSwift 2.0, *)
@@ -1204,7 +1207,7 @@ struct _BroadcastSequenceStateMachine<Element: Sendable>: Sendable {
12041207
}
12051208

12061209
@usableFromInline
1207-
enum OnCancelSubscription {
1210+
enum OnCancelSubscription: Sendable {
12081211
case none
12091212
case resume(ConsumerContinuation, Result<Element?, any Error>)
12101213
}
@@ -1244,7 +1247,7 @@ struct _BroadcastSequenceStateMachine<Element: Sendable>: Sendable {
12441247
}
12451248

12461249
@usableFromInline
1247-
enum OnSubscribe {
1250+
enum OnSubscribe: Sendable {
12481251
case subscribed(_BroadcastSequenceStateMachine<Element>.Subscriptions.ID)
12491252
}
12501253

@@ -1282,7 +1285,7 @@ struct _BroadcastSequenceStateMachine<Element: Sendable>: Sendable {
12821285
}
12831286

12841287
@usableFromInline
1285-
enum OnWaitToProduceMore {
1288+
enum OnWaitToProduceMore: Sendable {
12861289
case none
12871290
case resume(ProducerContinuation, Result<Void, any Error>)
12881291
}
@@ -1498,7 +1501,7 @@ extension _BroadcastSequenceStateMachine {
14981501
}
14991502

15001503
@usableFromInline
1501-
enum ElementLookup {
1504+
enum ElementLookup: Sendable {
15021505
/// The element was found in the collection.
15031506
case found(Element)
15041507
/// The element isn't in the collection, but it could be in the future.
@@ -1810,3 +1813,33 @@ extension _BroadcastSequenceStateMachine {
18101813
case many([Value])
18111814
}
18121815
}
1816+
1817+
@available(*, unavailable)
1818+
extension _BroadcastSequenceStateMachine.ConsumerContinuations: Sendable {}
1819+
1820+
@available(*, unavailable)
1821+
extension _BroadcastSequenceStateMachine.ProducerContinuations: Sendable {}
1822+
1823+
@available(*, unavailable)
1824+
extension _BroadcastSequenceStateMachine.OnInvalidateAllSubscriptions: Sendable {}
1825+
1826+
@available(*, unavailable)
1827+
extension _BroadcastSequenceStateMachine.OnYield: Sendable {}
1828+
1829+
@available(*, unavailable)
1830+
extension _BroadcastSequenceStateMachine.OnFinish: Sendable {}
1831+
1832+
@available(*, unavailable)
1833+
extension _BroadcastSequenceStateMachine.OnNext: Sendable {}
1834+
1835+
@available(*, unavailable)
1836+
extension _BroadcastSequenceStateMachine.OnNext.ReturnAndResumeProducers: Sendable {}
1837+
1838+
@available(*, unavailable)
1839+
extension _BroadcastSequenceStateMachine.OnSetContinuation: Sendable {}
1840+
1841+
@available(*, unavailable)
1842+
extension _BroadcastSequenceStateMachine.OnDropResources: Sendable {}
1843+
1844+
@available(*, unavailable)
1845+
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)