Skip to content

Commit 97f1e61

Browse files
committed
[Concurrency] Replace ClosureActorIsolation with ActorIsolation throughout
the isolation query APIs.
1 parent 54f5fef commit 97f1e61

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
@@ -3970,7 +3970,7 @@ class AbstractClosureExpr : public DeclContext, public Expr {
39703970

39713971
case ActorIsolation::ActorInstance:
39723972
return ClosureActorIsolation::forActorInstance(
3973-
actorIsolation.getCapturedActor(), preconcurrency);
3973+
actorIsolation.getActorInstance(), preconcurrency);
39743974

39753975
case ActorIsolation::GlobalActor:
39763976
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
@@ -10333,7 +10333,7 @@ ActorIsolation swift::getActorIsolation(ValueDecl *value) {
1033310333

1033410334
ActorIsolation swift::getActorIsolationOfContext(
1033510335
DeclContext *dc,
10336-
llvm::function_ref<ClosureActorIsolation(AbstractClosureExpr *)>
10336+
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
1033710337
getClosureActorIsolation) {
1033810338
auto dcToUse = dc;
1033910339
// Defer bodies share actor isolation of their enclosing context.
@@ -10349,7 +10349,7 @@ ActorIsolation swift::getActorIsolationOfContext(
1034910349
return getActorIsolation(var);
1035010350

1035110351
if (auto *closure = dyn_cast<AbstractClosureExpr>(dcToUse)) {
10352-
return getClosureActorIsolation(closure).getActorIsolation();
10352+
return getClosureActorIsolation(closure);
1035310353
}
1035410354

1035510355
if (auto *tld = dyn_cast<TopLevelCodeDecl>(dcToUse)) {
@@ -10619,7 +10619,7 @@ NominalTypeDecl *ActorIsolation::getActor() const {
1061910619
return actorInstance.get<NominalTypeDecl *>();
1062010620
}
1062110621

10622-
VarDecl *ActorIsolation::getCapturedActor() const {
10622+
VarDecl *ActorIsolation::getActorInstance() const {
1062310623
assert(getKind() == ActorInstance);
1062410624
return actorInstance.dyn_cast<VarDecl *>();
1062510625
}

lib/AST/Expr.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,14 +2017,9 @@ Expr *AbstractClosureExpr::getSingleExpressionBody() const {
20172017
return nullptr;
20182018
}
20192019

2020-
ClosureActorIsolation
2020+
ActorIsolation
20212021
swift::__AbstractClosureExpr_getActorIsolation(AbstractClosureExpr *CE) {
2022-
return CE->getClosureActorIsolation();
2023-
}
2024-
2025-
llvm::function_ref<ClosureActorIsolation(AbstractClosureExpr *)>
2026-
swift::_getRef__AbstractClosureExpr_getActorIsolation() {
2027-
return __AbstractClosureExpr_getActorIsolation;
2022+
return CE->getActorIsolation();
20282023
}
20292024

20302025
#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) {

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,16 +2960,16 @@ static bool isPreconcurrency(ConstraintSystem &cs, DeclContext *dc) {
29602960
static bool okToRemoveGlobalActor(ConstraintSystem &cs,
29612961
DeclContext *dc,
29622962
Type globalActor, Type ty) {
2963-
auto findGlobalActorForClosure = [&](AbstractClosureExpr *ace) -> ClosureActorIsolation {
2963+
auto findGlobalActorForClosure = [&](AbstractClosureExpr *ace) -> ActorIsolation {
29642964
// FIXME: Because the actor isolation checking happens after constraint
29652965
// solving, the closure expression does not yet have its actor isolation
29662966
// set, i.e., the code that would call
29672967
// `AbstractClosureExpr::setActorIsolation` hasn't run yet.
29682968
// So, I expect the existing isolation to always be set to the default.
29692969
// If the assertion below starts tripping, then this ad-hoc inference
29702970
// is no longer needed!
2971-
auto existingIso = ace->getClosureActorIsolation();
2972-
if (existingIso != ClosureActorIsolation()) {
2971+
auto existingIso = ace->getActorIsolation();
2972+
if (existingIso != ActorIsolation::forUnspecified()) {
29732973
assert(false && "somebody set the closure's isolation already?");
29742974
return existingIso;
29752975
}
@@ -2980,17 +2980,17 @@ static bool okToRemoveGlobalActor(ConstraintSystem &cs,
29802980
if (auto closType = GetClosureType{cs}(ace)) {
29812981
if (auto fnTy = closType->getAs<AnyFunctionType>()) {
29822982
if (auto globActor = fnTy->getGlobalActor()) {
2983-
return ClosureActorIsolation::forGlobalActor(globActor,
2984-
isPreconcurrency(cs, ace));
2983+
return ActorIsolation::forGlobalActor(globActor, /*unsafe=*/false)
2984+
.withPreconcurrency(isPreconcurrency(cs, ace));
29852985
}
29862986
}
29872987
}
29882988

29892989
// otherwise, check for an explicit annotation
29902990
if (auto *ce = dyn_cast<ClosureExpr>(ace)) {
29912991
if (auto globActor = getExplicitGlobalActor(ce)) {
2992-
return ClosureActorIsolation::forGlobalActor(globActor,
2993-
isPreconcurrency(cs, ce));
2992+
return ActorIsolation::forGlobalActor(globActor, /*unsafe=*/false)
2993+
.withPreconcurrency(isPreconcurrency(cs, ace));
29942994
}
29952995
}
29962996

0 commit comments

Comments
 (0)