Skip to content

Commit 6ab50c8

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 db2a9a4 commit 6ab50c8

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

include/swift/AST/Expr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3658,6 +3658,8 @@ class ClosureActorIsolation {
36583658
bool preconcurrency() const {
36593659
return storage.getInt();
36603660
}
3661+
3662+
ActorIsolation getActorIsolation() const;
36613663
};
36623664

36633665
/// A base class for closure expressions.

lib/AST/Decl.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9220,27 +9220,7 @@ ActorIsolation swift::getActorIsolationOfContext(DeclContext *dc) {
92209220

92219221

92229222
if (auto *closure = dyn_cast<AbstractClosureExpr>(dc)) {
9223-
switch (auto isolation = closure->getActorIsolation()) {
9224-
case ClosureActorIsolation::Independent:
9225-
return ActorIsolation::forIndependent()
9226-
.withPreconcurrency(isolation.preconcurrency());
9227-
9228-
case ClosureActorIsolation::GlobalActor: {
9229-
return ActorIsolation::forGlobalActor(
9230-
isolation.getGlobalActor(), /*unsafe=*/false)
9231-
.withPreconcurrency(isolation.preconcurrency());
9232-
}
9233-
9234-
case ClosureActorIsolation::ActorInstance: {
9235-
auto selfDecl = isolation.getActorInstance();
9236-
auto actor = selfDecl->getType()->getReferenceStorageReferent()
9237-
->getAnyActor();
9238-
assert(actor && "Bad closure actor isolation?");
9239-
// FIXME: This could be a parameter... or a capture... hmmm.
9240-
return ActorIsolation::forActorInstanceSelf(actor)
9241-
.withPreconcurrency(isolation.preconcurrency());
9242-
}
9243-
}
9223+
return closure->getActorIsolation().getActorIsolation();
92449224
}
92459225

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

lib/AST/Expr.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,29 @@ RebindSelfInConstructorExpr::getCalledConstructor(bool &isChainToSuper) const {
17791779
return otherCtorRef;
17801780
}
17811781

1782+
ActorIsolation ClosureActorIsolation::getActorIsolation() const {
1783+
switch (getKind()) {
1784+
case ClosureActorIsolation::Independent:
1785+
return ActorIsolation::forIndependent().withPreconcurrency(
1786+
preconcurrency());
1787+
1788+
case ClosureActorIsolation::GlobalActor: {
1789+
return ActorIsolation::forGlobalActor(getGlobalActor(), /*unsafe=*/false)
1790+
.withPreconcurrency(preconcurrency());
1791+
}
1792+
1793+
case ClosureActorIsolation::ActorInstance: {
1794+
auto selfDecl = getActorInstance();
1795+
auto actor =
1796+
selfDecl->getType()->getReferenceStorageReferent()->getAnyActor();
1797+
assert(actor && "Bad closure actor isolation?");
1798+
// FIXME: This could be a parameter... or a capture... hmmm.
1799+
return ActorIsolation::forActorInstanceSelf(actor).withPreconcurrency(
1800+
preconcurrency());
1801+
}
1802+
}
1803+
}
1804+
17821805
void AbstractClosureExpr::setParameterList(ParameterList *P) {
17831806
parameterList = P;
17841807
// Change the DeclContext of any parameters to be this closure.

0 commit comments

Comments
 (0)