Skip to content

Commit 14649c5

Browse files
authored
Merge pull request #71524 from DougGregor/async-iterator-next-rename
Rename `AsyncIteratorProtocol.next(_:)` to `next(isolation:)`
2 parents 5cb418a + a4f0709 commit 14649c5

22 files changed

+107
-100
lines changed

include/swift/AST/KnownIdentifiers.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ IDENTIFIER(makeIterator)
118118
IDENTIFIER(makeAsyncIterator)
119119
IDENTIFIER(nestedContainer)
120120
IDENTIFIER(isEmpty)
121+
IDENTIFIER(isolation)
121122
IDENTIFIER(Iterator)
122123
IDENTIFIER(AsyncIterator)
123124
IDENTIFIER(load)

lib/Sema/CSGen.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4604,12 +4604,15 @@ generateForEachStmtConstraints(ConstraintSystem &cs, DeclContext *dc,
46044604
TypeChecker::getForEachIteratorNextFunction(dc, stmt->getForLoc(), isAsync);
46054605
Identifier nextId = nextFn ? nextFn->getName().getBaseIdentifier()
46064606
: ctx.Id_next;
4607+
TinyPtrVector<Identifier> labels;
4608+
if (nextFn && nextFn->getParameters()->size() == 1)
4609+
labels.push_back(ctx.Id_isolation);
46074610
auto *nextRef = UnresolvedDotExpr::createImplicit(
46084611
ctx,
46094612
new (ctx) DeclRefExpr(makeIteratorVar, DeclNameLoc(stmt->getForLoc()),
46104613
/*Implicit=*/true),
4611-
nextId, /*labels=*/ArrayRef<Identifier>());
4612-
nextRef->setFunctionRefKind(FunctionRefKind::SingleApply);
4614+
nextId, labels);
4615+
nextRef->setFunctionRefKind(FunctionRefKind::Compound);
46134616

46144617
ArgumentList *nextArgs;
46154618
if (nextFn && nextFn->getParameters()->size() == 1) {

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10804,7 +10804,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
1080410804
// Handle `next` reference.
1080510805
if (getContextualTypePurpose(baseExpr) == CTP_ForEachSequence &&
1080610806
(isRefTo(memberRef, ctx.Id_next, /*labels=*/{}) ||
10807-
isRefTo(memberRef, ctx.Id_next, /*labels=*/{StringRef()}))) {
10807+
isRefTo(memberRef, ctx.Id_next, /*labels=*/{ "isolation" }))) {
1080810808
auto *iteratorProto = cast<ProtocolDecl>(
1080910809
getContextualType(baseExpr, /*forConstraint=*/false)
1081010810
->getAnyNominal());

stdlib/public/Concurrency/AsyncCompactMapSequence.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ extension AsyncCompactMapSequence: AsyncSequence {
140140
/// that transforms to a non-`nil` value.
141141
@available(SwiftStdlib 5.11, *)
142142
@inlinable
143-
public mutating func next(_ actor: isolated (any Actor)?) async throws(Failure) -> ElementOfResult? {
143+
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> ElementOfResult? {
144144
while true {
145-
guard let element = try await baseIterator.next(actor) else {
145+
guard let element = try await baseIterator.next(isolation: actor) else {
146146
return nil
147147
}
148148

stdlib/public/Concurrency/AsyncDropFirstSequence.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,24 @@ extension AsyncDropFirstSequence: AsyncSequence {
118118
/// Produces the next element in the drop-first sequence.
119119
///
120120
/// Until reaching the number of elements to drop, this iterator calls
121-
/// `next(_:)` on its base iterator and discards the result. If the
121+
/// `next(isolation:)` on its base iterator and discards the result. If the
122122
/// base iterator returns `nil`, indicating the end of the sequence, this
123123
/// iterator returns `nil`. After reaching the number of elements to drop,
124-
/// this iterator passes along the result of calling `next(_:)` on the
125-
/// base iterator.
124+
/// this iterator passes along the result of calling `next(isolation:)` on
125+
/// the base iterator.
126126
@available(SwiftStdlib 5.11, *)
127127
@inlinable
128-
public mutating func next(_ actor: isolated (any Actor)?) async throws(Failure) -> Base.Element? {
128+
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> Base.Element? {
129129
var remainingToDrop = count
130130
while remainingToDrop > 0 {
131-
guard try await baseIterator.next(actor) != nil else {
131+
guard try await baseIterator.next(isolation: actor) != nil else {
132132
count = 0
133133
return nil
134134
}
135135
remainingToDrop -= 1
136136
}
137137
count = 0
138-
return try await baseIterator.next(actor)
138+
return try await baseIterator.next(isolation: actor)
139139
}
140140
}
141141

stdlib/public/Concurrency/AsyncDropWhileSequence.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,26 +129,26 @@ extension AsyncDropWhileSequence: AsyncSequence {
129129

130130
/// Produces the next element in the drop-while sequence.
131131
///
132-
/// This iterator calls `next(_:)` on its base iterator and evaluates
133-
/// the result with the `predicate` closure. As long as the predicate
134-
/// returns `true`, this method returns `nil`. After the predicate returns
135-
/// `false`, for a value received from the base iterator, this method
136-
/// returns that value. After that, the iterator returns values received
137-
/// from its base iterator as-is, and never executes the predicate closure
138-
/// again.
132+
/// This iterator calls `next(isolation:)` on its base iterator and
133+
/// evaluates the result with the `predicate` closure. As long as the
134+
/// predicate returns `true`, this method returns `nil`. After the predicate
135+
/// returns `false`, for a value received from the base iterator, this
136+
/// method returns that value. After that, the iterator returns values
137+
/// received from its base iterator as-is, and never executes the predicate
138+
/// closure again.
139139
@available(SwiftStdlib 5.11, *)
140140
@inlinable
141-
public mutating func next(_ actor: isolated (any Actor)?) async throws(Failure) -> Base.Element? {
141+
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> Base.Element? {
142142
while let predicate = self.predicate {
143-
guard let element = try await baseIterator.next(actor) else {
143+
guard let element = try await baseIterator.next(isolation: actor) else {
144144
return nil
145145
}
146146
if await predicate(element) == false {
147147
self.predicate = nil
148148
return element
149149
}
150150
}
151-
return try await baseIterator.next(actor)
151+
return try await baseIterator.next(isolation: actor)
152152
}
153153
}
154154

stdlib/public/Concurrency/AsyncFilterSequence.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,16 @@ extension AsyncFilterSequence: AsyncSequence {
116116

117117
/// Produces the next element in the filter sequence.
118118
///
119-
/// This iterator calls `next()` on its base iterator; if this call
120-
/// returns `nil`, `next()` returns nil. Otherwise, `next()`
121-
/// evaluates the result with the `predicate` closure. If the closure
122-
/// returns `true`, `next()` returns the received element; otherwise
123-
/// it awaits the next element from the base iterator.
119+
/// This iterator calls `next(isolation:)` on its base iterator; if this
120+
/// call returns `nil`, `next(isolation:)` returns nil. Otherwise,
121+
/// `next(isolation:)` evaluates the result with the `predicate` closure. If
122+
/// the closure returns `true`, `next(isolation:)` returns the received
123+
/// element; otherwise it awaits the next element from the base iterator.
124124
@available(SwiftStdlib 5.11, *)
125125
@inlinable
126-
public mutating func next(_ actor: isolated (any Actor)?) async throws(Failure) -> Base.Element? {
126+
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> Base.Element? {
127127
while true {
128-
guard let element = try await baseIterator.next(actor) else {
128+
guard let element = try await baseIterator.next(isolation: actor) else {
129129
return nil
130130
}
131131
if await isIncluded(element) {

stdlib/public/Concurrency/AsyncFlatMapSequence.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -267,20 +267,21 @@ extension AsyncFlatMapSequence: AsyncSequence {
267267

268268
/// Produces the next element in the flat map sequence.
269269
///
270-
/// This iterator calls `next()` on its base iterator; if this call
271-
/// returns `nil`, `next()` returns `nil`. Otherwise, `next()`
272-
/// calls the transforming closure on the received element, takes the
273-
/// resulting asynchronous sequence, and creates an asynchronous iterator
274-
/// from it. `next()` then consumes values from this iterator until
275-
/// it terminates. At this point, `next()` is ready to receive the
276-
/// next value from the base sequence.
270+
/// This iterator calls `next(isolation:)` on its base iterator; if this
271+
/// call returns `nil`, `next(isolation:)` returns `nil`. Otherwise,
272+
/// `next(isolation:)` calls the transforming closure on the received
273+
/// element, takes the resulting asynchronous sequence, and creates an
274+
/// asynchronous iterator from it. `next(isolation:)` then consumes values
275+
/// from this iterator until it terminates. At this point,
276+
/// `next(isolation:)` is ready to receive the next value from the base
277+
/// sequence.
277278
@available(SwiftStdlib 5.11, *)
278279
@inlinable
279-
public mutating func next(_ actor: isolated (any Actor)?) async throws(Failure) -> SegmentOfResult.Element? {
280+
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> SegmentOfResult.Element? {
280281
while !finished {
281282
if var iterator = currentIterator {
282283
do {
283-
let optElement = try await iterator.next(actor)
284+
let optElement = try await iterator.next(isolation: actor)
284285
guard let element = optElement else {
285286
currentIterator = nil
286287
continue
@@ -293,15 +294,15 @@ extension AsyncFlatMapSequence: AsyncSequence {
293294
throw error as! Failure
294295
}
295296
} else {
296-
let optItem = try await baseIterator.next(actor)
297+
let optItem = try await baseIterator.next(isolation: actor)
297298
guard let item = optItem else {
298299
finished = true
299300
return nil
300301
}
301302
do {
302303
let segment = await transform(item)
303304
var iterator = segment.makeAsyncIterator()
304-
let optElement = try await iterator.next(actor)
305+
let optElement = try await iterator.next(isolation: actor)
305306
guard let element = optElement else {
306307
currentIterator = nil
307308
continue

stdlib/public/Concurrency/AsyncIteratorProtocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public protocol AsyncIteratorProtocol<Element, Failure> {
106106
/// - Returns: The next element, if it exists, or `nil` to signal the end of
107107
/// the sequence.
108108
@available(SwiftStdlib 5.11, *)
109-
mutating func next(_ actor: isolated (any Actor)?) async throws(Failure) -> Element?
109+
mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> Element?
110110
}
111111

112112
@available(SwiftStdlib 5.1, *)
@@ -115,7 +115,7 @@ extension AsyncIteratorProtocol {
115115
/// required to maintain backward compatibility with existing async iterators.
116116
@available(SwiftStdlib 5.11, *)
117117
@inlinable
118-
public mutating func next(_ actor: isolated (any Actor)?) async throws(Failure) -> Element? {
118+
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> Element? {
119119
do {
120120
return try await next()
121121
} catch {

stdlib/public/Concurrency/AsyncMapSequence.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,14 @@ extension AsyncMapSequence: AsyncSequence {
120120

121121
/// Produces the next element in the map sequence.
122122
///
123-
/// This iterator calls `next()` on its base iterator; if this call returns
124-
/// `nil`, `next()` returns `nil`. Otherwise, `next()` returns the result of
125-
/// calling the transforming closure on the received element.
123+
/// This iterator calls `next(isolation:)` on its base iterator; if this
124+
/// call returns `nil`, `next(isolation:)` returns `nil`. Otherwise,
125+
/// `next(isolation:)` returns the result of calling the transforming
126+
/// closure on the received element.
126127
@available(SwiftStdlib 5.11, *)
127128
@inlinable
128-
public mutating func next(_ actor: isolated (any Actor)?) async throws(Failure) -> Transformed? {
129-
guard let element = try await baseIterator.next(actor) else {
129+
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> Transformed? {
130+
guard let element = try await baseIterator.next(isolation: actor) else {
130131
return nil
131132
}
132133
return await transform(element)

stdlib/public/Concurrency/AsyncPrefixSequence.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ extension AsyncPrefixSequence: AsyncSequence {
112112
/// Produces the next element in the prefix sequence.
113113
///
114114
/// Until reaching the number of elements to include, this iterator calls
115-
/// `next()` on its base iterator and passes through the
115+
/// `next(isolation:)` on its base iterator and passes through the
116116
/// result. After reaching the maximum number of elements, subsequent calls
117-
/// to `next()` return `nil`.
117+
/// to `next(isolation:)` return `nil`.
118118
@available(SwiftStdlib 5.11, *)
119119
@inlinable
120-
public mutating func next(_ actor: isolated (any Actor)?) async throws(Failure) -> Base.Element? {
120+
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> Base.Element? {
121121
if remaining != 0 {
122122
remaining &-= 1
123-
return try await baseIterator.next(actor)
123+
return try await baseIterator.next(isolation: actor)
124124
} else {
125125
return nil
126126
}

stdlib/public/Concurrency/AsyncPrefixWhileSequence.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ extension AsyncPrefixWhileSequence: AsyncSequence {
129129
/// `nil`, ending the sequence.
130130
@available(SwiftStdlib 5.11, *)
131131
@inlinable
132-
public mutating func next(_ actor: isolated (any Actor)?) async throws(Failure) -> Base.Element? {
133-
if !predicateHasFailed, let nextElement = try await baseIterator.next(actor) {
132+
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> Base.Element? {
133+
if !predicateHasFailed, let nextElement = try await baseIterator.next(isolation: actor) {
134134
if await predicate(nextElement) {
135135
return nextElement
136136
} else {

stdlib/public/Concurrency/AsyncStream.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ extension AsyncStream: AsyncSequence {
392392
/// `next()` might return `nil` immediately, or return `nil` on
393393
/// subsequent calls.
394394
@available(SwiftStdlib 5.11, *)
395-
public mutating func next(_ actor: isolated (any Actor)?) async -> Element? {
395+
public mutating func next(isolation actor: isolated (any Actor)?) async -> Element? {
396396
await context.produce()
397397
}
398398
}
@@ -551,7 +551,7 @@ extension AsyncStream {
551551

552552
@available(SwiftStdlib 5.11, *)
553553
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
554-
public mutating func next(_ actor: isolated (any Actor)?) async -> Element? {
554+
public mutating func next(isolation actor: isolated (any Actor)?) async -> Element? {
555555
fatalError("Unavailable in task-to-thread concurrency model")
556556
}
557557
}

stdlib/public/Concurrency/AsyncThrowingCompactMapSequence.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ extension AsyncThrowingCompactMapSequence: AsyncSequence {
162162
/// error, the sequence ends and `next()` rethrows the error.
163163
@available(SwiftStdlib 5.11, *)
164164
@inlinable
165-
public mutating func next(_ actor: isolated (any Actor)?) async throws(Failure) -> ElementOfResult? {
165+
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> ElementOfResult? {
166166
while !finished {
167-
guard let element = try await baseIterator.next(actor) else {
167+
guard let element = try await baseIterator.next(isolation: actor) else {
168168
finished = true
169169
return nil
170170
}

stdlib/public/Concurrency/AsyncThrowingDropWhileSequence.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,19 @@ extension AsyncThrowingDropWhileSequence: AsyncSequence {
156156

157157
/// Produces the next element in the drop-while sequence.
158158
///
159-
/// This iterator calls `next()` on its base iterator and evaluates
160-
/// the result with the `predicate` closure. As long as the predicate
161-
/// returns `true`, this method returns `nil`. After the predicate returns
162-
/// `false`, for a value received from the base iterator, this method
163-
/// returns that value. After that, the iterator returns values received
164-
/// from its base iterator as-is, and never executes the predicate closure
165-
/// again. If calling the closure throws an error, the sequence ends and
166-
/// `next()` rethrows the error.
159+
/// This iterator calls `next(isolation:)` on its base iterator and
160+
/// evaluates the result with the `predicate` closure. As long as the
161+
/// predicate returns `true`, this method returns `nil`. After the predicate
162+
/// returns `false`, for a value received from the base iterator, this
163+
/// method returns that value. After that, the iterator returns values
164+
/// received from its base iterator as-is, and never executes the predicate
165+
/// closure again. If calling the closure throws an error, the sequence
166+
/// ends and `next(isolation:)` rethrows the error.
167167
@available(SwiftStdlib 5.11, *)
168168
@inlinable
169-
public mutating func next(_ actor: isolated (any Actor)?) async throws(Failure) -> Base.Element? {
169+
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> Base.Element? {
170170
while !finished && !doneDropping {
171-
guard let element = try await baseIterator.next(actor) else {
171+
guard let element = try await baseIterator.next(isolation: actor) else {
172172
return nil
173173
}
174174
do {
@@ -184,7 +184,7 @@ extension AsyncThrowingDropWhileSequence: AsyncSequence {
184184
guard !finished else {
185185
return nil
186186
}
187-
return try await baseIterator.next(actor)
187+
return try await baseIterator.next(isolation: actor)
188188
}
189189
}
190190

stdlib/public/Concurrency/AsyncThrowingFilterSequence.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,18 @@ extension AsyncThrowingFilterSequence: AsyncSequence {
138138

139139
/// Produces the next element in the filter sequence.
140140
///
141-
/// This iterator calls `next()` on its base iterator; if this call
142-
/// returns `nil`, `next()` returns nil. Otherwise, `next()`
141+
/// This iterator calls `next(isolation:)` on its base iterator; if this
142+
/// call returns `nil`, `next(isolation:)` returns nil. Otherwise, `next()`
143143
/// evaluates the result with the `predicate` closure. If the closure
144-
/// returns `true`, `next()` returns the received element; otherwise
145-
/// it awaits the next element from the base iterator. If calling the
146-
/// closure throws an error, the sequence ends and `next()` rethrows
147-
/// the error.
144+
/// returns `true`, `next(isolation:)` returns the received element;
145+
/// otherwise it awaits the next element from the base iterator. If calling
146+
/// the closure throws an error, the sequence ends and `next(isolation:)`
147+
/// rethrows the error.
148148
@available(SwiftStdlib 5.11, *)
149149
@inlinable
150-
public mutating func next(_ actor: isolated (any Actor)?) async throws(Failure) -> Base.Element? {
150+
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> Base.Element? {
151151
while !finished {
152-
guard let element = try await baseIterator.next(actor) else {
152+
guard let element = try await baseIterator.next(isolation: actor) else {
153153
return nil
154154
}
155155
do {

0 commit comments

Comments
 (0)