mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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.
This commit is contained in:
@@ -102,6 +102,8 @@ def create_parser():
|
||||
parser.add_argument('--enable-infer-import-as-member', action='store_true',
|
||||
help='Infer when a global could be imported as a ' +
|
||||
'member.')
|
||||
parser.add_argument('--enable-experimental-concurrency', action='store_true',
|
||||
help='Enable experimental concurrency model.')
|
||||
parser.add_argument('-swift-version', metavar='N',
|
||||
help='the Swift version to use')
|
||||
parser.add_argument('-show-overlay', action='store_true',
|
||||
@@ -328,6 +330,8 @@ def main():
|
||||
extra_args = ['-skip-imports']
|
||||
if args.enable_infer_import_as_member:
|
||||
extra_args = extra_args + ['-enable-infer-import-as-member']
|
||||
if args.enable_experimental_concurrency:
|
||||
extra_args = extra_args + ['-enable-experimental-concurrency']
|
||||
if args.swift_version:
|
||||
extra_args = extra_args + ['-swift-version', '%s' % args.swift_version]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user