Commit Graph

5 Commits

Author SHA1 Message Date
Doug Gregor
4bcccecfda [Concurrency] Implicitly strip optionals for return type of translated "async throws".
Review over a large number of APIs has found that most of the time, the
result type of an Objective-C completion handler method that becomes
"async throws" should be optional. Change the default behavior to
match this, and replace _Nullable_on_error with _Nullable_result to
capture the case where the result should be optional.
2020-10-30 00:01:20 -07:00
John McCall
a8464dcaf1 Implicitly import _Concurrency under -enable-experimental-concurrency 2020-10-22 00:53:15 -04:00
Doug Gregor
9b808c67fa [Concurrency] Import "did" delegate methods as @asyncHandler.
Infer @asyncHandler on a protocol methods that follow the delegate
convention of reporting that something happened via a "did" method, so
long as they also meet the constraints for an @asyncHandler method in
Swift. This enables inference of @asyncHandler for witnesses of these
methods.
2020-09-24 14:01:08 -07:00
Doug Gregor
6ad2757bef [Concurrency] Use completion/completionHandler parameter names for async import
Extend the check for completion handler parameters to also consider the
name of the parameter (not its argument label). If it's `completion` or
`completionHandler`, we have a completion handler. This extends our
API coverage for importing Objective-C methods with completion
handlers as 'async'.
2020-08-28 13:58:02 -07:00
Doug Gregor
1e5d30f5ca [Concurrency] Import Objective-C methods with completion handlers as async
When a given Objective-C method has a completion handler parameter
with an appropriate signature, import that Objective-C method as
async. For example, consider the following CloudKit API:

    - (void)fetchShareParticipantWithUserRecordID:(CKRecordID
*)userRecordID
            completionHandler:(void (^)(CKShareParticipant * _Nullable shareParticipant, NSError * _Nullable error))completionHandler;

With the experimental concurrency model, this would import as:

    func fetchShareParticipant(withUserRecordID userRecordID: CKRecord.ID) async throws -> CKShare.Participant?

The compiler will be responsible for turning the caller's continuation
into a block to pass along to the completion handler. When the error
parameter of the completion handler is non-null, the async call
will result in that error being thrown. Otherwise, the other arguments
passed to that completion handler will be returned as the result of
the async call.

async versions of methods are imported alongside their
completion-handler versions, to maintain source compatibility with
existing code that provides a completion handler.

Note that this only covers the Clang importer portion of this task.
2020-08-27 21:30:13 -07:00