Skip to content

Commit f565569

Browse files
authored
Remove majority of @unchecked Sendable usages (apple#295)
# Motivation `@unchecked Sendable` is a great way to make a type `Sendable` while it is not really `Sendable` this is rarely useful and we should rather use conditional `@unchecked Sendable` annotations such as the one on `ManagedCriticalState` # Modification This PR removes all `@unchecked Sendable` in the main algorithm target except the one on `Merge` since we are doing manual locking there. # Result No more `@unchecked Sendable` usage.
1 parent 220f86f commit f565569

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

Sources/AsyncAlgorithms/Channels/AsyncChannel.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/// on the `Iterator` is made, or when `finish()` is called from another Task.
2020
/// As `finish()` induces a terminal state, there is no more need for a back pressure management.
2121
/// This function does not suspend and will finish all the pending iterations.
22-
public final class AsyncChannel<Element: Sendable>: AsyncSequence, @unchecked Sendable {
22+
public final class AsyncChannel<Element: Sendable>: AsyncSequence, Sendable {
2323
public typealias Element = Element
2424
public typealias AsyncIterator = Iterator
2525

Sources/AsyncAlgorithms/Channels/AsyncThrowingChannel.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/// and is resumed when the next call to `next()` on the `Iterator` is made, or when `finish()`/`fail(_:)` is called
1919
/// from another Task. As `finish()` and `fail(_:)` induce a terminal state, there is no more need for a back pressure management.
2020
/// Those functions do not suspend and will finish all the pending iterations.
21-
public final class AsyncThrowingChannel<Element: Sendable, Failure: Error>: AsyncSequence, @unchecked Sendable {
21+
public final class AsyncThrowingChannel<Element: Sendable, Failure: Error>: AsyncSequence, Sendable {
2222
public typealias Element = Element
2323
public typealias AsyncIterator = Iterator
2424

Sources/AsyncAlgorithms/Debounce/AsyncDebounceSequence.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ extension AsyncSequence {
1313
/// Creates an asynchronous sequence that emits the latest element after a given quiescence period
1414
/// has elapsed by using a specified Clock.
1515
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
16-
public func debounce<C: Clock>(for interval: C.Instant.Duration, tolerance: C.Instant.Duration? = nil, clock: C) -> AsyncDebounceSequence<Self, C> where Self: Sendable {
16+
public func debounce<C: Clock>(for interval: C.Instant.Duration, tolerance: C.Instant.Duration? = nil, clock: C) -> AsyncDebounceSequence<Self, C> where Self: Sendable, Self.Element: Sendable {
1717
AsyncDebounceSequence(self, interval: interval, tolerance: tolerance, clock: clock)
1818
}
1919

2020
/// Creates an asynchronous sequence that emits the latest element after a given quiescence period
2121
/// has elapsed.
2222
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
23-
public func debounce(for interval: Duration, tolerance: Duration? = nil) -> AsyncDebounceSequence<Self, ContinuousClock> where Self: Sendable {
23+
public func debounce(for interval: Duration, tolerance: Duration? = nil) -> AsyncDebounceSequence<Self, ContinuousClock> where Self: Sendable, Self.Element: Sendable {
2424
self.debounce(for: interval, tolerance: tolerance, clock: .continuous)
2525
}
2626
}
2727

2828
/// An `AsyncSequence` that emits the latest element after a given quiescence period
2929
/// has elapsed.
3030
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
31-
public struct AsyncDebounceSequence<Base: AsyncSequence, C: Clock>: Sendable where Base: Sendable {
31+
public struct AsyncDebounceSequence<Base: AsyncSequence & Sendable, C: Clock>: Sendable where Base.Element: Sendable {
3232
private let base: Base
3333
private let clock: C
3434
private let interval: C.Instant.Duration

Sources/AsyncAlgorithms/Debounce/DebounceStateMachine.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
13-
struct DebounceStateMachine<Base: AsyncSequence, C: Clock> {
13+
struct DebounceStateMachine<Base: AsyncSequence & Sendable, C: Clock>: Sendable where Base.Element: Sendable {
1414
typealias Element = Base.Element
1515

16-
private enum State {
16+
private enum State: Sendable {
1717
/// The initial state before a call to `next` happened.
1818
case initial(base: Base)
1919

Sources/AsyncAlgorithms/Debounce/DebounceStorage.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
13-
final class DebounceStorage<Base: AsyncSequence, C: Clock>: @unchecked Sendable where Base: Sendable {
13+
final class DebounceStorage<Base: AsyncSequence & Sendable, C: Clock>: Sendable where Base.Element: Sendable {
1414
typealias Element = Base.Element
1515

1616
/// The state machine protected with a lock.

0 commit comments

Comments
 (0)