@@ -44,6 +44,29 @@ void PostfixCompletionCallback::fallbackTypeCheck(DeclContext *DC) {
44
44
[&](const Solution &S) { sawSolution (S); });
45
45
}
46
46
47
+ static ClosureActorIsolation
48
+ getClosureActorIsolation (const Solution &S, AbstractClosureExpr *ACE) {
49
+ auto getType = [&S](Expr *E) -> Type {
50
+ // Prefer the contextual type of the closure because it might be 'weaker'
51
+ // than the type determined for the closure by the constraints system. E.g.
52
+ // the contextual type might have a global actor attribute but because no
53
+ // methods from that global actor are called in the closure, the closure has
54
+ // a non-actor type.
55
+ auto target = S.solutionApplicationTargets .find (dyn_cast<ClosureExpr>(E));
56
+ if (target != S.solutionApplicationTargets .end ()) {
57
+ if (auto Ty = target->second .getClosureContextualType ()) {
58
+ return Ty;
59
+ }
60
+ }
61
+ return getTypeForCompletion (S, E);
62
+ };
63
+ auto getClosureActorIsolationThunk = [&S](AbstractClosureExpr *ACE) {
64
+ return getClosureActorIsolation (S, ACE);
65
+ };
66
+ return determineClosureActorIsolation (ACE, getType,
67
+ getClosureActorIsolationThunk);
68
+ }
69
+
47
70
void PostfixCompletionCallback::sawSolutionImpl (
48
71
const constraints::Solution &S) {
49
72
auto &CS = S.getConstraintSystem ();
@@ -68,7 +91,14 @@ void PostfixCompletionCallback::sawSolutionImpl(
68
91
if (auto SelectedOverload = S.getOverloadChoiceIfAvailable (CalleeLocator))
69
92
ReferencedDecl = SelectedOverload->choice .getDeclOrNull ();
70
93
94
+ llvm::DenseMap<AbstractClosureExpr *, ClosureActorIsolation>
95
+ ClosureActorIsolations;
71
96
bool IsAsync = isContextAsync (S, DC);
97
+ for (auto SAT : S.solutionApplicationTargets ) {
98
+ if (auto ACE = getAsExpr<AbstractClosureExpr>(SAT.second .getAsASTNode ())) {
99
+ ClosureActorIsolations[ACE] = getClosureActorIsolation (S, ACE);
100
+ }
101
+ }
72
102
73
103
auto Key = std::make_pair (BaseTy, ReferencedDecl);
74
104
auto Ret = BaseToSolutionIdx.insert ({Key, Results.size ()});
@@ -91,7 +121,7 @@ void PostfixCompletionCallback::sawSolutionImpl(
91
121
92
122
Results.push_back ({BaseTy, ReferencedDecl,
93
123
/* ExpectedTypes=*/ {}, DisallowVoid, ISDMT,
94
- ImplicitReturn, IsAsync});
124
+ ImplicitReturn, IsAsync, ClosureActorIsolations });
95
125
if (ExpectedTy) {
96
126
Results.back ().ExpectedTypes .push_back (ExpectedTy);
97
127
}
@@ -131,6 +161,7 @@ void PostfixCompletionCallback::deliverResults(
131
161
Lookup.shouldCheckForDuplicates (Results.size () > 1 );
132
162
for (auto &Result : Results) {
133
163
Lookup.setCanCurrDeclContextHandleAsync (Result.IsInAsyncContext );
164
+ Lookup.setClosureActorIsolations (Result.ClosureActorIsolations );
134
165
Lookup.setIsStaticMetatype (Result.BaseIsStaticMetaType );
135
166
Lookup.getPostfixKeywordCompletions (Result.BaseTy , BaseExpr);
136
167
Lookup.setExpectedTypes (Result.ExpectedTypes ,
0 commit comments