Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6317,14 +6317,9 @@ computeDefaultInferredActorIsolation(ValueDecl *value) {

// Asynchronous variants for functions imported from ObjC are
// `nonisolated(nonsending)` by default.
if (value->hasClangNode()) {
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(value)) {
if (!isa<ProtocolDecl>(AFD->getDeclContext()) &&
AFD->getForeignAsyncConvention()) {
return {
{ActorIsolation::forCallerIsolationInheriting(), {}}, nullptr, {}};
}
}
if (value->hasClangNode() && value->isAsync() &&
!isa<ProtocolDecl>(value->getDeclContext())) {
return {{ActorIsolation::forCallerIsolationInheriting(), {}}, nullptr, {}};
}

// We did not find anything special, return unspecified.
Expand Down
6 changes: 6 additions & 0 deletions test/ClangImporter/objc_async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,9 @@ extension CoffeeDelegate {
return await self.icedMochaServiceGenerateMocha!(NSObject())
}
}

@MainActor
func testGetSendableClasses() async {
let x = ImportObjCAsyncGetter()
_ = await x.sendableClasses
}
11 changes: 11 additions & 0 deletions test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
#define NONSENDABLE __attribute__((__swift_attr__("@_nonSendable")))
#define ASSUME_NONSENDABLE_BEGIN _Pragma("clang attribute ASSUME_NONSENDABLE.push (__attribute__((swift_attr(\"@_nonSendable(_assumed)\"))), apply_to = any(objc_interface, record, enum))")
#define ASSUME_NONSENDABLE_END _Pragma("clang attribute ASSUME_NONSENDABLE.pop")
#define ASYNC_NAME(NAME) __attribute__((swift_async_name(#NAME)))
#else
// If we take this #else, we should see minor failures of some subtests,
// but not systematic failures of everything that uses this header.
#define SENDABLE
#define NONSENDABLE
#define ASSUME_NONSENDABLE_BEGIN
#define ASSUME_NONSENDABLE_END
#define ASYNC_NAME(NAME)
#endif

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

NONSENDABLE
@interface ImportObjCAsyncGetter : NSObject

- (void)getSendableClassesWithCompletionHandler:
(void (^SENDABLE)(NSArray<SendableClass *> *myClasses))handler
ASYNC_NAME(getter:sendableClasses());

@end

#pragma clang assume_nonnull end