mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Concurrency] Apply nonisolated(unsafe) to iterator variables for
async for-in loops. Async iterators are not `Sendable`; they're only meant to be used from the isolation domain that creates them. But the `next()` method runs on the generic executor, so calling it from an actor-isolated context passes non-`Sendable` state across the isolation boundary. `next()` should inherit the isolation of the caller, but for now, use the opt out.
This commit is contained in:
@@ -4516,6 +4516,19 @@ generateForEachStmtConstraints(ConstraintSystem &cs, DeclContext *dc,
|
||||
sequenceExpr->getStartLoc(), ctx.getIdentifier(name), dc);
|
||||
makeIteratorVar->setImplicit();
|
||||
|
||||
// FIXME: Apply `nonisolated(unsafe)` to async iterators.
|
||||
//
|
||||
// Async iterators are not `Sendable`; they're only meant to be used from
|
||||
// the isolation domain that creates them. But the `next()` method runs on
|
||||
// the generic executor, so calling it from an actor-isolated context passes
|
||||
// non-`Sendable` state across the isolation boundary. `next()` should
|
||||
// inherit the isolation of the caller, but for now, use the opt out.
|
||||
if (isAsync) {
|
||||
auto *nonisolated = new (ctx)
|
||||
NonisolatedAttr(/*unsafe=*/true, /*implicit=*/true);
|
||||
makeIteratorVar->getAttrs().add(nonisolated);
|
||||
}
|
||||
|
||||
// First, let's form a call from sequence to `.makeIterator()` and save
|
||||
// that in a special variable which is going to be used by SILGen.
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user