Skip to content

[Concurrency] Emit async methods in ObjC protocols once. #36822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
13 changes: 12 additions & 1 deletion lib/IRGen/GenClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,8 +1153,19 @@ namespace {
Protocols.push_back(proto);
}

for (Decl *member : theProtocol->getMembers())
for (Decl *member : theProtocol->getMembers()) {
// Async methods coming from ObjC protocols shouldn't be recorded twice.
// At the moment, the language doesn't allow suppressing the
// completionHandler-based variant, so this is sufficient.
if (theProtocol->hasClangNode() && theProtocol->isObjC()) {
if (auto funcOrAccessor = dyn_cast<AbstractFunctionDecl>(member)) {
if (funcOrAccessor->isAsyncContext()) {
continue;
}
}
}
visit(member);
}
}

/// Gather protocol records for all of the explicitly-specified Objective-C
Expand Down
3 changes: 3 additions & 0 deletions test/Concurrency/Inputs/Delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@

@end

@protocol MyAsyncProtocol
-(void)myAsyncMethod:(void (^ _Nullable)(NSError * _Nullable, NSString * _Nullable))completionHandler;
@end

#endif
15 changes: 15 additions & 0 deletions test/Concurrency/objc_async_protocol_irgen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-concurrency -import-objc-header %S/Inputs/Delegate.h %s -emit-ir -o - | %FileCheck %s
// REQUIRES: concurrency
// REQUIRES: objc_interop


let anyObject: AnyObject = (MyAsyncProtocol.self as AnyObject) // or something like this

// rdar://76192003
// Make sure we don't emit 2 copies of methods, due to a completion-handler
// version and another due to an async based version.

// CHECK-LABEL: @_PROTOCOL_INSTANCE_METHODS_MyAsyncProtocol = internal constant
// CHECK-SAME: selector_data(myAsyncMethod:)
// CHECK-NOT: selector_data(myAsyncMethod:)
// CHECK-SAME: align 8