Skip to content

Commit d3de4a6

Browse files
authored
Merge pull request #81363 from gottesmm/release/6.2-rdar150209093
[6.2][concurrency] Ensure that we treat closures that are nonisolated(nonsending) via their ActorIsolation as nonisolated(nonsending).
2 parents e7607e1 + 03d8c0a commit d3de4a6

File tree

5 files changed

+420
-79
lines changed

5 files changed

+420
-79
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,6 +2638,9 @@ static CanSILFunctionType getSILFunctionType(
26382638
} else if (decl->getAttrs().hasAttribute<ConcurrentAttr>()) {
26392639
actorIsolation = ActorIsolation::forNonisolated(false /*unsafe*/);
26402640
}
2641+
} else if (auto *closure = constant->getAbstractClosureExpr()) {
2642+
if (auto isolation = closure->getActorIsolation())
2643+
actorIsolation = isolation;
26412644
}
26422645

26432646
if (!actorIsolation) {

lib/SILGen/SILGen.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,13 @@ static ActorIsolation getActorIsolationForFunction(SILFunction &fn) {
765765
return ActorIsolation::forNonisolated(false);
766766
}
767767

768+
// If we have a closure expr, check if our type is
769+
// nonisolated(nonsending). In that case, we use that instead.
770+
if (auto *closureExpr = constant.getAbstractClosureExpr()) {
771+
if (auto actorIsolation = closureExpr->getActorIsolation())
772+
return actorIsolation;
773+
}
774+
768775
// If we have actor isolation for our constant, put the isolation onto the
769776
// function. If the isolation is unspecified, we do not return it.
770777
if (auto isolation =

lib/Sema/CSApply.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,8 +1345,32 @@ namespace {
13451345
new (ctx) AutoClosureExpr(/*set body later*/ nullptr, thunkTy, dc);
13461346
thunk->setParameterList(thunkParamList);
13471347
thunk->setThunkKind(AutoClosureExpr::Kind::SingleCurryThunk);
1348+
1349+
// TODO: We should do this in the ActorIsolation checker but for now it is
1350+
// too risky. This is a narrow fix for 6.2.
1351+
//
1352+
// The problem that this is working around is given an autoclosure that
1353+
// returns an autoclosure that partially applies over an instance method,
1354+
// we do not visit the inner autoclosure in the ActorIsolation checker
1355+
// meaning that we do not properly call setActorIsolation on the
1356+
// AbstractClosureExpr that we produce here.
1357+
switch (thunkTy->getIsolation().getKind()) {
1358+
case FunctionTypeIsolation::Kind::NonIsolated:
1359+
case FunctionTypeIsolation::Kind::Parameter:
1360+
case FunctionTypeIsolation::Kind::Erased:
1361+
break;
1362+
case FunctionTypeIsolation::Kind::GlobalActor:
1363+
thunk->setActorIsolation(ActorIsolation::forGlobalActor(
1364+
thunkTy->getIsolation().getGlobalActorType()));
1365+
break;
1366+
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
1367+
thunk->setActorIsolation(
1368+
ActorIsolation::forCallerIsolationInheriting());
1369+
break;
1370+
}
1371+
13481372
cs.cacheType(thunk);
1349-
1373+
13501374
// If the `self` type is existential, it must be opened.
13511375
OpaqueValueExpr *baseOpened = nullptr;
13521376
Expr *origBaseExpr = baseExpr;

test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ typedef void (^NonsendableCompletionHandler)(NSString * _Nullable, NSString * _N
123123
__attribute__((swift_async_error(zero_argument, 3)));
124124
- (void)getIceCreamFlavorWithCompletionHandler:
125125
(void (^)(Flavor flavor, NSError *__nullable error))completionHandler;
126+
127+
@property(class, strong, readonly) SlowServer *standardServer;
128+
- (void)getValueWithKey:(NSString *)valueIdentifier
129+
completion:(void (^)(NSString *__nullable value,
130+
NSError *__nullable error))completionHandler;
131+
- (void)getMainActorValueWithKey:(NSString *)valueIdentifier
132+
completion:
133+
(void (^)(NSString *__nullable value,
134+
NSError *__nullable error))completionHandler
135+
MAIN_ACTOR;
126136
@end
127137

128138
@protocol RefrigeratorDelegate<NSObject>

0 commit comments

Comments
 (0)