Skip to content

Commit 9b793df

Browse files
committed
[transferring] Change CheckedContinuation.resume and Async{Throwing,}Stream.yield to use transferring parameters.
Importantly, I used silgen_name to preserve the name since I have not yet removed the mangling for transferring for named entities. This ensures that this is an ABI neutral change until I make that other change. rdar://120420024
1 parent 61dadcf commit 9b793df

File tree

4 files changed

+45
-17
lines changed

4 files changed

+45
-17
lines changed

stdlib/public/Concurrency/AsyncStream.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ public struct AsyncStream<Element> {
191191
///
192192
/// This can be called more than once and returns to the caller immediately
193193
/// without blocking for any awaiting consumption from the iteration.
194+
@_silgen_name("$sScS12ContinuationV5yieldyAB11YieldResultOyx__GxnF")
194195
@discardableResult
195-
public func yield(_ value: __owned Element) -> YieldResult {
196+
public func yield(_ value: transferring Element) -> YieldResult {
196197
storage.yield(value)
197198
}
198199

@@ -421,12 +422,15 @@ extension AsyncStream.Continuation {
421422
/// If you call this method repeatedly, each call returns immediately, without
422423
/// blocking for any awaiting consumption from the iteration.
423424
@discardableResult
425+
@_silgen_name("$sScS12ContinuationV5yield4withAB11YieldResultOyx__Gs0E0Oyxs5NeverOG_tF")
424426
public func yield(
425-
with result: Result<Element, Never>
427+
with result: transferring borrowing Result<Element, Never>
426428
) -> YieldResult {
427-
switch result {
428-
case .success(let val):
429-
return storage.yield(val)
429+
// TODO: Once borrowing values can have borrowing switches, remove this
430+
// copy. For now it is necessary though.
431+
switch copy result {
432+
case .success(let val):
433+
return storage.yield(val)
430434
}
431435
}
432436

@@ -501,7 +505,8 @@ public struct AsyncStream<Element> {
501505
@discardableResult
502506
@available(SwiftStdlib 5.1, *)
503507
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
504-
public func yield(_ value: __owned Element) -> YieldResult {
508+
@_silgen_name("$sScS12ContinuationV5yieldyAB11YieldResultOyx__GxnF")
509+
public func yield(_ value: transferring Element) -> YieldResult {
505510
fatalError("Unavailable in task-to-thread concurrency model")
506511
}
507512
@available(SwiftStdlib 5.1, *)
@@ -570,8 +575,9 @@ extension AsyncStream.Continuation {
570575
@discardableResult
571576
@available(SwiftStdlib 5.1, *)
572577
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
578+
@_silgen_name("$sScS12ContinuationV5yield4withAB11YieldResultOyx__Gs0E0Oyxs5NeverOG_tF")
573579
public func yield(
574-
with result: Result<Element, Never>
580+
with result: transferring borrowing Result<Element, Never>
575581
) -> YieldResult {
576582
fatalError("Unavailable in task-to-thread concurrency model")
577583
}

stdlib/public/Concurrency/AsyncThrowingStream.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ public struct AsyncThrowingStream<Element, Failure: Error> {
214214
/// This can be called more than once and returns to the caller immediately
215215
/// without blocking for any awaiting consumption from the iteration.
216216
@discardableResult
217-
public func yield(_ value: __owned Element) -> YieldResult {
217+
@_silgen_name("$sScs12ContinuationV5yieldyAB11YieldResultOyxq___GxnF")
218+
public func yield(_ value: transferring Element) -> YieldResult {
218219
storage.yield(value)
219220
}
220221

@@ -462,10 +463,13 @@ extension AsyncThrowingStream.Continuation {
462463
/// If you call this method repeatedly, each call returns immediately, without
463464
/// blocking for any awaiting consumption from the iteration.
464465
@discardableResult
466+
@_silgen_name("$sScs12ContinuationV5yield4withAB11YieldResultOyxs5Error_p__Gs0E0OyxsAG_pG_tsAG_pRs_rlF")
465467
public func yield(
466-
with result: Result<Element, Failure>
468+
with result: transferring borrowing Result<Element, Failure>
467469
) -> YieldResult where Failure == Error {
468-
switch result {
470+
// TODO: Once borrowing values can have borrowing switches, remove this
471+
// copy. For now it is necessary though.
472+
switch copy result {
469473
case .success(let val):
470474
return storage.yield(val)
471475
case .failure(let err):
@@ -547,7 +551,8 @@ public struct AsyncThrowingStream<Element, Failure: Error> {
547551
@discardableResult
548552
@available(SwiftStdlib 5.1, *)
549553
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
550-
public func yield(_ value: __owned Element) -> YieldResult {
554+
@_silgen_name("$sScs12ContinuationV5yieldyAB11YieldResultOyxq___GxnF")
555+
public func yield(_ value: transferring Element) -> YieldResult {
551556
fatalError("Unavailable in task-to-thread concurrency model")
552557
}
553558
@available(SwiftStdlib 5.1, *)
@@ -609,8 +614,9 @@ extension AsyncThrowingStream.Continuation {
609614
@discardableResult
610615
@available(SwiftStdlib 5.1, *)
611616
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
617+
@_silgen_name("$sScs12ContinuationV5yield4withAB11YieldResultOyxs5Error_p__Gs0E0OyxsAG_pG_tsAG_pRs_rlF")
612618
public func yield(
613-
with result: Result<Element, Failure>
619+
with result: transferring borrowing Result<Element, Failure>
614620
) -> YieldResult where Failure == Error {
615621
fatalError("Unavailable in task-to-thread concurrency model")
616622
}

stdlib/public/Concurrency/CheckedContinuation.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ public struct CheckedContinuation<T, E: Error>: Sendable {
159159
/// After `resume` enqueues the task, control immediately returns to
160160
/// the caller. The task continues executing when its executor is
161161
/// able to reschedule it.
162-
public func resume(returning value: __owned T) {
162+
@_silgen_name("$sScC6resume9returningyxn_tF")
163+
public func resume(returning value: transferring T) {
163164
if let c: UnsafeContinuation<T, E> = canary.takeContinuation() {
164165
c.resume(returning: value)
165166
} else {
@@ -206,8 +207,10 @@ extension CheckedContinuation {
206207
/// the caller. The task continues executing when its executor is
207208
/// able to reschedule it.
208209
@_alwaysEmitIntoClient
209-
public func resume<Er: Error>(with result: Result<T, Er>) where E == Error {
210-
switch result {
210+
public func resume<Er: Error>(with result: transferring borrowing Result<T, Er>) where E == Error {
211+
// TODO: Once borrowing values can have borrowing switches, remove this
212+
// copy. For now it is necessary though.
213+
switch copy result {
211214
case .success(let val):
212215
self.resume(returning: val)
213216
case .failure(let err):
@@ -230,8 +233,10 @@ extension CheckedContinuation {
230233
/// the caller. The task continues executing when its executor is
231234
/// able to reschedule it.
232235
@_alwaysEmitIntoClient
233-
public func resume(with result: Result<T, E>) {
234-
switch result {
236+
public func resume(with result: transferring borrowing Result<T, E>) {
237+
// TODO: Once borrowing values can have borrowing switches, remove this
238+
// copy. For now it is necessary though.
239+
switch copy result {
235240
case .success(let val):
236241
self.resume(returning: val)
237242
case .failure(let err):

test/api-digester/stability-concurrency-abi.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ Constructor AsyncStream.init(unfolding:onCancel:) has mangled name changing from
9797
// SerialExecutor gained `enqueue(_: __owned Job)`, protocol requirements got default implementations
9898
Func SerialExecutor.enqueue(_:) has been added as a protocol requirement
9999

100+
// .yield and .resume here use silgen_name to preserve mangling after adding transferring.
101+
//
102+
// Once transferring's mangling has been relazed a little bit, this will go away.
103+
Func AsyncStream.Continuation.yield(_:) has mangled name changing from 'Swift.AsyncStream.Continuation.yield(__owned A) -> Swift.AsyncStream<A>.Continuation.YieldResult' to 'Swift.AsyncStream.Continuation.yield(transferring __owned A) -> Swift.AsyncStream<A>.Continuation.YieldResult'
104+
Func AsyncStream.Continuation.yield(with:) has mangled name changing from 'Swift.AsyncStream.Continuation.yield(with: Swift.Result<A, Swift.Never>) -> Swift.AsyncStream<A>.Continuation.YieldResult' to 'Swift.AsyncStream.Continuation.yield(with: transferring Swift.Result<A, Swift.Never>) -> Swift.AsyncStream<A>.Continuation.YieldResult'
105+
Func AsyncStream.Continuation.yield(with:) has parameter 0 changing from Default to Shared
106+
Func AsyncThrowingStream.Continuation.yield(_:) has mangled name changing from 'Swift.AsyncThrowingStream.Continuation.yield(__owned A) -> Swift.AsyncThrowingStream<A, B>.Continuation.YieldResult' to 'Swift.AsyncThrowingStream.Continuation.yield(transferring __owned A) -> Swift.AsyncThrowingStream<A, B>.Continuation.YieldResult'
107+
Func AsyncThrowingStream.Continuation.yield(with:) has mangled name changing from 'Swift.AsyncThrowingStream.Continuation.yield< where B == Swift.Error>(with: Swift.Result<A, Swift.Error>) -> Swift.AsyncThrowingStream<A, Swift.Error>.Continuation.YieldResult' to 'Swift.AsyncThrowingStream.Continuation.yield< where B == Swift.Error>(with: transferring Swift.Result<A, Swift.Error>) -> Swift.AsyncThrowingStream<A, Swift.Error>.Continuation.YieldResult'
108+
Func AsyncThrowingStream.Continuation.yield(with:) has parameter 0 changing from Default to Shared
109+
Func CheckedContinuation.resume(returning:) has mangled name changing from 'Swift.CheckedContinuation.resume(returning: __owned A) -> ()' to 'Swift.CheckedContinuation.resume(returning: transferring __owned A) -> ()'
110+
100111
// We deprecated `enqueue(_: UnownedJob)` and annotate it as such for all platforms,
101112
// while adding a new overload that accepts `Job` with new availability.
102113
// The ABI checker seems to be confused by this case.

0 commit comments

Comments
 (0)