Skip to content

Commit b93997a

Browse files
committed
[AST] Move conversion of ClosureActorIsolation to ActorIsolation to its own function
Just a little bit of cleanup because this logic is really quite general and doesn't need to live in `getActorIsolationOfContext`.
1 parent 497ae4e commit b93997a

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

include/swift/AST/Expr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3670,6 +3670,8 @@ class ClosureActorIsolation {
36703670
bool preconcurrency() const {
36713671
return storage.getInt();
36723672
}
3673+
3674+
ActorIsolation getActorIsolation() const;
36733675
};
36743676

36753677
/// A base class for closure expressions.

lib/AST/Decl.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9215,26 +9215,7 @@ ActorIsolation swift::getActorIsolationOfContext(DeclContext *dc) {
92159215

92169216

92179217
if (auto *closure = dyn_cast<AbstractClosureExpr>(dc)) {
9218-
switch (auto isolation = closure->getActorIsolation()) {
9219-
case ClosureActorIsolation::Independent:
9220-
return ActorIsolation::forIndependent()
9221-
.withPreconcurrency(isolation.preconcurrency());
9222-
9223-
case ClosureActorIsolation::GlobalActor: {
9224-
return ActorIsolation::forGlobalActor(
9225-
isolation.getGlobalActor(), /*unsafe=*/false)
9226-
.withPreconcurrency(isolation.preconcurrency());
9227-
}
9228-
9229-
case ClosureActorIsolation::ActorInstance: {
9230-
auto selfDecl = isolation.getActorInstance();
9231-
auto actor = selfDecl->getType()->getReferenceStorageReferent()
9232-
->getAnyActor();
9233-
assert(actor && "Bad closure actor isolation?");
9234-
return ActorIsolation::forActorInstance(actor)
9235-
.withPreconcurrency(isolation.preconcurrency());
9236-
}
9237-
}
9218+
return closure->getActorIsolation().getActorIsolation();
92389219
}
92399220

92409221
if (auto *tld = dyn_cast<TopLevelCodeDecl>(dc)) {

lib/AST/Expr.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,28 @@ RebindSelfInConstructorExpr::getCalledConstructor(bool &isChainToSuper) const {
17371737
return otherCtorRef;
17381738
}
17391739

1740+
ActorIsolation ClosureActorIsolation::getActorIsolation() const {
1741+
switch (getKind()) {
1742+
case ClosureActorIsolation::Independent:
1743+
return ActorIsolation::forIndependent().withPreconcurrency(
1744+
preconcurrency());
1745+
1746+
case ClosureActorIsolation::GlobalActor: {
1747+
return ActorIsolation::forGlobalActor(getGlobalActor(), /*unsafe=*/false)
1748+
.withPreconcurrency(preconcurrency());
1749+
}
1750+
1751+
case ClosureActorIsolation::ActorInstance: {
1752+
auto selfDecl = getActorInstance();
1753+
auto actor =
1754+
selfDecl->getType()->getReferenceStorageReferent()->getAnyActor();
1755+
assert(actor && "Bad closure actor isolation?");
1756+
return ActorIsolation::forActorInstance(actor).withPreconcurrency(
1757+
preconcurrency());
1758+
}
1759+
}
1760+
}
1761+
17401762
void AbstractClosureExpr::setParameterList(ParameterList *P) {
17411763
parameterList = P;
17421764
// Change the DeclContext of any parameters to be this closure.

0 commit comments

Comments
 (0)