Skip to content

Commit 764d324

Browse files
authored
Merge pull request #74563 from hborla/6.0-isolated-parameter-checking
[6.0][Concurrency] Calls that pass an isolated parameter matching the isolation of the context do not exit to nonisolated.
2 parents c6475c3 + e0cdbec commit 764d324

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3457,21 +3457,18 @@ namespace {
34573457

34583458
argForIsolatedParam = arg;
34593459
unsatisfiedIsolation = std::nullopt;
3460+
3461+
// Assume that a callee with an isolated parameter does not
3462+
// cross an isolation boundary. We'll set this again below if
3463+
// the given isolated argument doesn't match the isolation of the
3464+
// caller.
3465+
mayExitToNonisolated = false;
3466+
3467+
// If the argument is an isolated parameter from the enclosing context,
3468+
// or #isolation, then the call does not cross an isolation boundary.
34603469
if (getIsolatedActor(arg) || isa<CurrentContextIsolationExpr>(arg))
34613470
continue;
34623471

3463-
// An isolated parameter was provided with a non-isolated argument.
3464-
// FIXME: The modeling of unsatisfiedIsolation is not great here.
3465-
// We'd be better off using something more like closure isolation
3466-
// that can talk about specific parameters.
3467-
auto nominal = getType(arg)->getAnyNominal();
3468-
if (!nominal) {
3469-
// FIXME: This is wrong for distributed actors.
3470-
nominal = getType(arg)->getASTContext().getProtocol(
3471-
KnownProtocolKind::Actor);
3472-
}
3473-
3474-
mayExitToNonisolated = false;
34753472
auto calleeIsolation = ActorIsolation::forActorInstanceParameter(
34763473
const_cast<Expr *>(arg->findOriginalValue()), paramIdx);
34773474

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-frontend -disable-availability-checking -swift-version 6 %s -emit-sil -o /dev/null -verify
2+
3+
public func doNotCross(
4+
isolation: isolated (any Actor)? = #isolation,
5+
_ block: () async -> Void
6+
) async {
7+
await block()
8+
}
9+
10+
actor MyActor {
11+
func doStuff() {}
12+
13+
func test() async {
14+
await doNotCross {
15+
doStuff()
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)