Skip to content

Commit ca266d3

Browse files
authored
Merge pull request swiftlang#74560 from hborla/isolated-parameter-checking
[Concurrency] Calls that pass an isolated parameter matching the isolation of the context do not exit to nonisolated.
2 parents 6a52dc1 + 4ff4cfd commit ca266d3

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
@@ -3463,21 +3463,18 @@ namespace {
34633463

34643464
argForIsolatedParam = arg;
34653465
unsatisfiedIsolation = std::nullopt;
3466+
3467+
// Assume that a callee with an isolated parameter does not
3468+
// cross an isolation boundary. We'll set this again below if
3469+
// the given isolated argument doesn't match the isolation of the
3470+
// caller.
3471+
mayExitToNonisolated = false;
3472+
3473+
// If the argument is an isolated parameter from the enclosing context,
3474+
// or #isolation, then the call does not cross an isolation boundary.
34663475
if (getIsolatedActor(arg) || isa<CurrentContextIsolationExpr>(arg))
34673476
continue;
34683477

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

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)