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)

0 commit comments

Comments
 (0)