Skip to content

Commit 01d349c

Browse files
authored
Merge pull request swiftlang#38009 from DougGregor/local-functions-isolated-self-5.5
2 parents 2be52a7 + 82014d7 commit 01d349c

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,10 +1468,10 @@ namespace {
14681468
}
14691469
}
14701470

1471-
// "Defer" blocks are treated as if they are in their enclosing context.
1472-
if (auto func = dyn_cast<FuncDecl>(dc)) {
1473-
if (func->isDeferBody())
1474-
continue;
1471+
if (auto func = dyn_cast<AbstractFunctionDecl>(dc)) {
1472+
// @Sendable functions are nonisolated.
1473+
if (func->isSendable())
1474+
return ReferencedActor(var, ReferencedActor::SendableFunction);
14751475
}
14761476

14771477
// Check isolation of the context itself. We do this separately
@@ -1480,9 +1480,14 @@ namespace {
14801480
switch (auto isolation = getActorIsolationOfContext(dc)) {
14811481
case ActorIsolation::Independent:
14821482
case ActorIsolation::Unspecified:
1483-
if (auto func = dyn_cast<AbstractFunctionDecl>(dc)) {
1484-
if (func->isSendable())
1485-
return ReferencedActor(var, ReferencedActor::SendableFunction);
1483+
// Local functions can capture an isolated parameter.
1484+
// FIXME: This really should be modeled by getActorIsolationOfContext.
1485+
if (isa<FuncDecl>(dc) && cast<FuncDecl>(dc)->isLocalCapture()) {
1486+
// FIXME: Local functions could presumably capture an isolated
1487+
// parameter that isn't 'self'.
1488+
if (isPotentiallyIsolated &&
1489+
(var->isSelfParameter() || var->isSelfParamCapture()))
1490+
continue;
14861491
}
14871492

14881493
return ReferencedActor(var, ReferencedActor::NonIsolatedContext);
@@ -1493,12 +1498,6 @@ namespace {
14931498
var, isolation.getGlobalActor());
14941499

14951500
case ActorIsolation::ActorInstance:
1496-
// FIXME: Local functions could presumably capture an isolated
1497-
// parameter that isn't'self'.
1498-
if (isPotentiallyIsolated &&
1499-
(var->isSelfParameter() || var->isSelfParamCapture()))
1500-
return ReferencedActor(var, ReferencedActor::Isolated);
1501-
15021501
break;
15031502
}
15041503
}

test/Concurrency/actor_isolation.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,4 +857,13 @@ actor Counter {
857857

858858
return counter
859859
}
860+
861+
func localNext() -> Int {
862+
func doIt() {
863+
counter = counter + 1
864+
}
865+
doIt()
866+
867+
return counter
868+
}
860869
}

0 commit comments

Comments
 (0)