Replace AsyncIteratorProtocol.nextElement() with isolated next(_:)

Use an optional isolated parameter to this new `next(_:)` overload to
keep it on the same actor as the caller, and pass `#isolation` when
desugaring the async for..in loop. This keeps async iteration loops on
the same actor, allowing non-Sendable values to be used with many
async sequences.
This commit is contained in:
Doug Gregor
2024-01-16 16:44:55 -08:00
parent 35582370d4
commit 6ebb0ff560
29 changed files with 142 additions and 118 deletions

View File

@@ -10705,7 +10705,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
// Handle `next` reference.
if (getContextualTypePurpose(baseExpr) == CTP_ForEachSequence &&
(isRefTo(memberRef, ctx.Id_next, /*labels=*/{}) ||
isRefTo(memberRef, ctx.Id_nextElement, /*labels=*/{}))) {
isRefTo(memberRef, ctx.Id_next, /*labels=*/{StringRef()}))) {
auto *iteratorProto = cast<ProtocolDecl>(
getContextualType(baseExpr, /*forConstraint=*/false)
->getAnyNominal());
@@ -10931,8 +10931,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
if (auto *base = dyn_cast<DeclRefExpr>(UDE->getBase())) {
if (auto var = dyn_cast_or_null<VarDecl>(base->getDecl())) {
if (var->getNameStr().contains("$generator") &&
(UDE->getName().getBaseIdentifier() == Context.Id_next ||
UDE->getName().getBaseIdentifier() == Context.Id_nextElement))
(UDE->getName().getBaseIdentifier() == Context.Id_next))
return success();
}
}