Replace @completionHandlerAsync with @available(*, renamed:)

Instead of a new attribute `@completionHandlerAsync`, allow the use of
the existing `renamed` parameter of `@available` to specify the
asynchronous alternative of a synchronous function.

No errors will be output from invalid names as `@completionHandlerAsync`
had, but if a function is correctly matched then it will be used to
output warnings when using the synchronous function in an asynchronous
context (as before).

Resolves rdar://80612731
This commit is contained in:
Ben Barham
2021-07-14 15:45:02 +10:00
parent ebd820c5ee
commit e7e9b57051
31 changed files with 649 additions and 816 deletions

View File

@@ -5,12 +5,9 @@
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -enable-experimental-concurrency | %FileCheck -check-prefix=SIMPLE %s
func simple(completion: @escaping (String) -> Void) { }
// SIMPLE: async_attribute_added.swift [[# @LINE-1]]:1 -> [[# @LINE-1]]:1
// SIMPLE-NEXT: @available(*, deprecated, message: "Prefer async alternative instead")
// SIMPLE-NEXT: @available(*, renamed: "simple()")
// SIMPLE-EMPTY:
// SIMPLE-NEXT: async_attribute_added.swift [[# @LINE-4]]:1 -> [[# @LINE-4]]:1
// SIMPLE-NEXT: @completionHandlerAsync("simple()", completionHandlerIndex: 0)
// SIMPLE-EMPTY:
// SIMPLE-NEXT: async_attribute_added.swift [[# @LINE-7]]:53 -> [[# @LINE-7]]:56
// SIMPLE-NEXT: async_attribute_added.swift [[# @LINE-4]]:53 -> [[# @LINE-4]]:56
// SIMPLE-NEXT: {
// SIMPLE-NEXT: Task {
// SIMPLE-NEXT: let result = await simple()
@@ -18,24 +15,24 @@ func simple(completion: @escaping (String) -> Void) { }
// SIMPLE-NEXT: }
// SIMPLE-NEXT: }
// SIMPLE-EMPTY:
// SIMPLE-NEXT: async_attribute_added.swift [[# @LINE-15]]:56 -> [[# @LINE-15]]:56
// SIMPLE-NEXT: async_attribute_added.swift [[# @LINE-12]]:56 -> [[# @LINE-12]]:56
// SIMPLE-EMPTY:
// SIMPLE-EMPTY:
// SIMPLE-EMPTY:
// SIMPLE-NEXT: async_attribute_added.swift [[# @LINE-19]]:56 -> [[# @LINE-19]]:56
// SIMPLE-NEXT: async_attribute_added.swift [[# @LINE-16]]:56 -> [[# @LINE-16]]:56
// SIMPLE-NEXT: func simple() async -> String { }
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):5 -enable-experimental-concurrency | %FileCheck -check-prefix=OTHER-ARGS %s
func otherArgs(first: Int, second: String, completion: @escaping (String) -> Void) { }
// OTHER-ARGS: @completionHandlerAsync("otherArgs(first:second:)", completionHandlerIndex: 2)
// OTHER-ARGS: @available(*, renamed: "otherArgs(first:second:)")
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):5 -enable-experimental-concurrency | %FileCheck -check-prefix=EMPTY-NAMES %s
func emptyNames(first: Int, _ second: String, completion: @escaping (String) -> Void) { }
// EMPTY-NAMES: @completionHandlerAsync("emptyNames(first:_:)", completionHandlerIndex: 2)
// EMPTY-NAMES: @available(*, renamed: "emptyNames(first:_:)")
// Not a completion handler named parameter, but should still be converted
// during function conversion since it has been attributed
@completionHandlerAsync("otherName()", completionHandlerIndex: 0)
@available(*, renamed: "otherName()")
func otherName(notHandlerName: @escaping (String) -> (Void)) {}
func otherName() async -> String {}