Skip to content

Commit 8bac434

Browse files
committed
[Concurrency] Replace ClosureActorIsolation with ActorIsolation throughout
the isolation query APIs. (cherry picked from commit 97f1e61)
1 parent 8d0fc1d commit 8bac434

13 files changed

+67
-69
lines changed

include/swift/AST/ActorIsolation.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,6 @@ class NominalTypeDecl;
3131
class SubstitutionMap;
3232
class AbstractFunctionDecl;
3333
class AbstractClosureExpr;
34-
class ClosureActorIsolation;
35-
36-
/// Trampoline for AbstractClosureExpr::getActorIsolation.
37-
ClosureActorIsolation
38-
__AbstractClosureExpr_getActorIsolation(AbstractClosureExpr *CE);
39-
40-
/// Returns a function reference to \c __AbstractClosureExpr_getActorIsolation.
41-
/// This is needed so we can use it as a default argument for
42-
/// \c getActorIsolationOfContext without knowing the layout of
43-
/// \c ClosureActorIsolation.
44-
llvm::function_ref<ClosureActorIsolation(AbstractClosureExpr *)>
45-
_getRef__AbstractClosureExpr_getActorIsolation();
4634

4735
/// Determine whether the given types are (canonically) equal, declared here
4836
/// to avoid having to include Types.h.
@@ -100,6 +88,11 @@ class ActorIsolation {
10088
parameterIndex(0) { }
10189

10290
public:
91+
// No-argument constructor needed for DenseMap use in PostfixCompletion.cpp
92+
explicit ActorIsolation(Kind kind = Unspecified)
93+
: pointer(nullptr), kind(kind), isolatedByPreconcurrency(false),
94+
parameterIndex(0) { }
95+
10396
static ActorIsolation forUnspecified() {
10497
return ActorIsolation(Unspecified, nullptr);
10598
}
@@ -157,7 +150,7 @@ class ActorIsolation {
157150

158151
NominalTypeDecl *getActor() const;
159152

160-
VarDecl *getCapturedActor() const;
153+
VarDecl *getActorInstance() const;
161154

162155
bool isGlobalActor() const {
163156
return getKind() == GlobalActor || getKind() == GlobalActorUnsafe;
@@ -227,16 +220,19 @@ class ActorIsolation {
227220
/// Determine how the given value declaration is isolated.
228221
ActorIsolation getActorIsolation(ValueDecl *value);
229222

223+
/// Trampoline for AbstractClosureExpr::getActorIsolation.
224+
ActorIsolation
225+
__AbstractClosureExpr_getActorIsolation(AbstractClosureExpr *CE);
226+
230227
/// Determine how the given declaration context is isolated.
231228
/// \p getClosureActorIsolation allows the specification of actor isolation for
232229
/// closures that haven't been saved been saved to the AST yet. This is useful
233230
/// for solver-based code completion which doesn't modify the AST but stores the
234231
/// actor isolation of closures in the constraint system solution.
235232
ActorIsolation getActorIsolationOfContext(
236233
DeclContext *dc,
237-
llvm::function_ref<ClosureActorIsolation(AbstractClosureExpr *)>
238-
getClosureActorIsolation =
239-
_getRef__AbstractClosureExpr_getActorIsolation());
234+
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
235+
getClosureActorIsolation = __AbstractClosureExpr_getActorIsolation);
240236

241237
/// Check if both the value, and context are isolated to the same actor.
242238
bool isSameActorIsolated(ValueDecl *value, DeclContext *dc);
@@ -260,9 +256,9 @@ bool usesFlowSensitiveIsolation(AbstractFunctionDecl const *fn);
260256
/// \return true if it is safe to drop the global-actor qualifier.
261257
bool safeToDropGlobalActor(
262258
DeclContext *dc, Type globalActor, Type ty,
263-
llvm::function_ref<ClosureActorIsolation(AbstractClosureExpr *)>
259+
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
264260
getClosureActorIsolation =
265-
_getRef__AbstractClosureExpr_getActorIsolation());
261+
__AbstractClosureExpr_getActorIsolation);
266262

267263
void simple_display(llvm::raw_ostream &out, const ActorIsolation &state);
268264

include/swift/AST/Expr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3967,7 +3967,7 @@ class AbstractClosureExpr : public DeclContext, public Expr {
39673967

39683968
case ActorIsolation::ActorInstance:
39693969
return ClosureActorIsolation::forActorInstance(
3970-
actorIsolation.getCapturedActor(), preconcurrency);
3970+
actorIsolation.getActorInstance(), preconcurrency);
39713971

39723972
case ActorIsolation::GlobalActor:
39733973
case ActorIsolation::GlobalActorUnsafe:

include/swift/IDE/CompletionLookup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
131131
bool CanCurrDeclContextHandleAsync = false;
132132
/// Actor isolations that were determined during constraint solving but that
133133
/// haven't been saved to the AST.
134-
llvm::DenseMap<AbstractClosureExpr *, ClosureActorIsolation>
134+
llvm::DenseMap<AbstractClosureExpr *, ActorIsolation>
135135
ClosureActorIsolations;
136136
bool HaveDot = false;
137137
bool IsUnwrappedOptional = false;
@@ -253,7 +253,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
253253
}
254254

255255
void setClosureActorIsolations(
256-
llvm::DenseMap<AbstractClosureExpr *, ClosureActorIsolation>
256+
llvm::DenseMap<AbstractClosureExpr *, ActorIsolation>
257257
ClosureActorIsolations) {
258258
this->ClosureActorIsolations = ClosureActorIsolations;
259259
}

include/swift/IDE/PostfixCompletion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class PostfixCompletionCallback : public TypeCheckCompletionCallback {
6363

6464
/// Actor isolations that were determined during constraint solving but that
6565
/// haven't been saved to the AST.
66-
llvm::DenseMap<AbstractClosureExpr *, ClosureActorIsolation>
66+
llvm::DenseMap<AbstractClosureExpr *, ActorIsolation>
6767
ClosureActorIsolations;
6868

6969
/// Checks whether this result has the same \c BaseTy and \c BaseDecl as

include/swift/Sema/IDETypeChecking.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ namespace swift {
318318
bool completionContextUsesConcurrencyFeatures(const DeclContext *dc);
319319

320320
/// Determine the isolation of a particular closure.
321-
ClosureActorIsolation determineClosureActorIsolation(
321+
ActorIsolation determineClosureActorIsolation(
322322
AbstractClosureExpr *closure, llvm::function_ref<Type(Expr *)> getType,
323-
llvm::function_ref<ClosureActorIsolation(AbstractClosureExpr *)>
323+
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
324324
getClosureActorIsolation);
325325

326326
/// If the capture list shadows any declarations using shorthand syntax, i.e.

lib/AST/Decl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10237,7 +10237,7 @@ ActorIsolation swift::getActorIsolation(ValueDecl *value) {
1023710237

1023810238
ActorIsolation swift::getActorIsolationOfContext(
1023910239
DeclContext *dc,
10240-
llvm::function_ref<ClosureActorIsolation(AbstractClosureExpr *)>
10240+
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
1024110241
getClosureActorIsolation) {
1024210242
auto dcToUse = dc;
1024310243
// Defer bodies share actor isolation of their enclosing context.
@@ -10253,7 +10253,7 @@ ActorIsolation swift::getActorIsolationOfContext(
1025310253
return getActorIsolation(var);
1025410254

1025510255
if (auto *closure = dyn_cast<AbstractClosureExpr>(dcToUse)) {
10256-
return getClosureActorIsolation(closure).getActorIsolation();
10256+
return getClosureActorIsolation(closure);
1025710257
}
1025810258

1025910259
if (auto *tld = dyn_cast<TopLevelCodeDecl>(dcToUse)) {
@@ -10523,7 +10523,7 @@ NominalTypeDecl *ActorIsolation::getActor() const {
1052310523
return actorInstance.get<NominalTypeDecl *>();
1052410524
}
1052510525

10526-
VarDecl *ActorIsolation::getCapturedActor() const {
10526+
VarDecl *ActorIsolation::getActorInstance() const {
1052710527
assert(getKind() == ActorInstance);
1052810528
return actorInstance.dyn_cast<VarDecl *>();
1052910529
}

lib/AST/Expr.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,14 +2012,9 @@ Expr *AbstractClosureExpr::getSingleExpressionBody() const {
20122012
return nullptr;
20132013
}
20142014

2015-
ClosureActorIsolation
2015+
ActorIsolation
20162016
swift::__AbstractClosureExpr_getActorIsolation(AbstractClosureExpr *CE) {
2017-
return CE->getClosureActorIsolation();
2018-
}
2019-
2020-
llvm::function_ref<ClosureActorIsolation(AbstractClosureExpr *)>
2021-
swift::_getRef__AbstractClosureExpr_getActorIsolation() {
2022-
return __AbstractClosureExpr_getActorIsolation;
2017+
return CE->getActorIsolation();
20232018
}
20242019

20252020
#define FORWARD_SOURCE_LOCS_TO(CLASS, NODE) \

lib/IDE/CompletionLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ void CompletionLookup::analyzeActorIsolation(
777777
if (isolation != ClosureActorIsolations.end()) {
778778
return isolation->second;
779779
} else {
780-
return CE->getClosureActorIsolation();
780+
return CE->getActorIsolation();
781781
}
782782
};
783783
auto contextIsolation = getActorIsolationOfContext(

lib/IDE/PostfixCompletion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void PostfixCompletionCallback::fallbackTypeCheck(DeclContext *DC) {
111111
[&](const Solution &S) { sawSolution(S); });
112112
}
113113

114-
static ClosureActorIsolation
114+
static ActorIsolation
115115
getClosureActorIsolation(const Solution &S, AbstractClosureExpr *ACE) {
116116
auto getType = [&S](Expr *E) -> Type {
117117
// Prefer the contextual type of the closure because it might be 'weaker'
@@ -213,7 +213,7 @@ void PostfixCompletionCallback::sawSolutionImpl(
213213
isImplicitSingleExpressionReturn(CS, CompletionExpr);
214214

215215
bool IsInAsyncContext = isContextAsync(S, DC);
216-
llvm::DenseMap<AbstractClosureExpr *, ClosureActorIsolation>
216+
llvm::DenseMap<AbstractClosureExpr *, ActorIsolation>
217217
ClosureActorIsolations;
218218
for (auto SAT : S.targets) {
219219
if (auto ACE = getAsExpr<AbstractClosureExpr>(SAT.second.getAsASTNode())) {

lib/SILGen/SILGenProlog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,7 @@ void SILGenFunction::emitHopToActorValue(SILLocation loc, ManagedValue actor) {
15931593
}
15941594
auto isolation =
15951595
getActorIsolationOfContext(FunctionDC, [](AbstractClosureExpr *CE) {
1596-
return CE->getClosureActorIsolation();
1596+
return CE->getActorIsolation();
15971597
});
15981598
if (isolation != ActorIsolation::Nonisolated
15991599
&& isolation != ActorIsolation::Unspecified) {

0 commit comments

Comments
 (0)