Skip to content

Commit 39c9ff1

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 3cf948b commit 39c9ff1

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
@@ -9218,26 +9218,7 @@ ActorIsolation swift::getActorIsolationOfContext(DeclContext *dc) {
92189218

92199219

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

92439224
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
@@ -1732,6 +1732,28 @@ RebindSelfInConstructorExpr::getCalledConstructor(bool &isChainToSuper) const {
17321732
return otherCtorRef;
17331733
}
17341734

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

0 commit comments

Comments
 (0)