Skip to content

Commit 08f108c

Browse files
committed
[concurrency] Import getters with completion handlers as nonisolated(nonsending).
Specifically, this means importing getters defined via swift_async_name. This just ensures that they are treated just like any other imported objc async function with completion handler. rdar://156985950
1 parent 94de642 commit 08f108c

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6317,14 +6317,9 @@ computeDefaultInferredActorIsolation(ValueDecl *value) {
63176317

63186318
// Asynchronous variants for functions imported from ObjC are
63196319
// `nonisolated(nonsending)` by default.
6320-
if (value->hasClangNode()) {
6321-
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(value)) {
6322-
if (!isa<ProtocolDecl>(AFD->getDeclContext()) &&
6323-
AFD->getForeignAsyncConvention()) {
6324-
return {
6325-
{ActorIsolation::forCallerIsolationInheriting(), {}}, nullptr, {}};
6326-
}
6327-
}
6320+
if (value->hasClangNode() && value->isAsync() &&
6321+
!isa<ProtocolDecl>(value->getDeclContext())) {
6322+
return {{ActorIsolation::forCallerIsolationInheriting(), {}}, nullptr, {}};
63286323
}
63296324

63306325
// We did not find anything special, return unspecified.

test/ClangImporter/objc_async.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,3 +404,9 @@ extension CoffeeDelegate {
404404
return await self.icedMochaServiceGenerateMocha!(NSObject())
405405
}
406406
}
407+
408+
@MainActor
409+
func testGetSendableClasses() async {
410+
let x = ImportObjCAsyncGetter()
411+
_ = await x.sendableClasses
412+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
#define NONSENDABLE __attribute__((__swift_attr__("@_nonSendable")))
1212
#define ASSUME_NONSENDABLE_BEGIN _Pragma("clang attribute ASSUME_NONSENDABLE.push (__attribute__((swift_attr(\"@_nonSendable(_assumed)\"))), apply_to = any(objc_interface, record, enum))")
1313
#define ASSUME_NONSENDABLE_END _Pragma("clang attribute ASSUME_NONSENDABLE.pop")
14+
#define ASYNC_NAME(NAME) __attribute__((swift_async_name(#NAME)))
1415
#else
1516
// If we take this #else, we should see minor failures of some subtests,
1617
// but not systematic failures of everything that uses this header.
1718
#define SENDABLE
1819
#define NONSENDABLE
1920
#define ASSUME_NONSENDABLE_BEGIN
2021
#define ASSUME_NONSENDABLE_END
22+
#define ASYNC_NAME(NAME)
2123
#endif
2224

2325
#define NS_ENUM(_type, _name) enum _name : _type _name; \
@@ -381,4 +383,13 @@ MAIN_ACTOR
381383
- (void)loadFloatOrThrowWithCompletionHandler:(void (^)(float, NSError* __nullable)) completionHandler;
382384
@end
383385

386+
NONSENDABLE
387+
@interface ImportObjCAsyncGetter : NSObject
388+
389+
- (void)getSendableClassesWithCompletionHandler:
390+
(void (^SENDABLE)(NSArray<SendableClass *> *myClasses))handler
391+
ASYNC_NAME(getter:sendableClasses());
392+
393+
@end
394+
384395
#pragma clang assume_nonnull end

0 commit comments

Comments
 (0)