Skip to content

Commit 7d7d91a

Browse files
committed
Speculative fix for pre 6.1 compiler crashes by removing the sending keyword, and correct sendable metatype shim availability
1 parent a024ae0 commit 7d7d91a

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Sources/AsyncAlgorithms/AsyncShareSequence.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,22 @@ where Base.Element: Sendable, Base: AsyncSequenceSendableMetatype, Base.AsyncIte
338338
failure = error
339339
}
340340
}
341-
341+
#if compiler(>=6.1)
342342
let state: Mutex<State>
343+
#else
344+
let state: ManagedCriticalState<State>
345+
#endif
343346
let limit: Int?
344347

345348
init(
346349
_ iteratorFactory: @escaping @Sendable () -> sending Base.AsyncIterator,
347350
bufferingPolicy: AsyncBufferSequencePolicy
348351
) {
352+
#if compiler(>=6.1)
349353
state = Mutex(State(iteratorFactory, bufferingPolicy: bufferingPolicy))
354+
#else
355+
state = ManagedCriticalState(State(iteratorFactory, bufferingPolicy: bufferingPolicy))
356+
#endif
350357
switch bufferingPolicy.policy {
351358
case .bounded(let limit):
352359
self.limit = limit

Sources/AsyncAlgorithms/Locking.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ struct ManagedCriticalState<State> {
153153
return try critical(&header.pointee)
154154
}
155155
}
156+
157+
func withLock<R>(_ critical: (inout State) throws -> R) rethrows -> R {
158+
return try withCriticalRegion(critical)
159+
}
156160
}
157161

158162
extension ManagedCriticalState: @unchecked Sendable where State: Sendable {}

Sources/AsyncAlgorithms/SendableMetatypes.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
#if compiler(>=6.2)
13+
@available(AsyncAlgorithms 1.1, *)
1314
public typealias AsyncSequenceSendableMetatype = SendableMetatype & AsyncSequence
15+
@available(AsyncAlgorithms 1.1, *)
1416
public typealias AsyncIteratorSendableMetatype = SendableMetatype & AsyncIteratorProtocol
1517
#else
18+
@available(AsyncAlgorithms 1.1, *)
1619
public typealias AsyncSequenceSendableMetatype = AsyncSequence
20+
@available(AsyncAlgorithms 1.1, *)
1721
public typealias AsyncIteratorSendableMetatype = AsyncIteratorProtocol
1822
#endif

0 commit comments

Comments
 (0)