9 Commits

Author SHA1 Message Date
Anthony Latsis
7f6d3bcd41 ASTPrinter: Turn on explicit any printing for everything and remove the option to disable it 2023-05-13 02:55:49 +03:00
Ben Barham
fabb02100f [Test] Add @escaping to async refactoring tests
The async refactorings ignore whether a completion handler had
`@escaping` or not. In preparation of fixing this, fix up all functions
to have `@escaping` for their completion handler parameter.

Also some small miscellaneous fixes in order to reduce the number of
warnings output on test failures and also the addition of `REQUIRES:
concurrency` on all tests.
2021-07-24 09:53:17 +10:00
Hamish Knight
1ebb1fd2f5 [Async Refactoring] Add parens around custom error cast
When passing a forwarded error to a CustomError?
completion handler parameter, wrap the cast in a
set of parentheses to silence a warning in the
refactored code.

rdar://80409905
2021-07-22 23:20:24 +01:00
Ben Barham
8569c8a51b [Refactoring] Avoid redeclarations or shadowing in async refactored code
When converting a call or function, rename declarations such that
redeclaration errors and shadowing are avoided. In some cases this will
be overly conservative, but since any renamed variable can be fixed with
edit all in scope, this is preferred over causing redeclaration errors
or possible shadowing.

Resolves rdar://73973517
2021-05-13 17:48:41 +10:00
Alex Hoppen
f1455c29bf [Refactoring] Check that code compiles after refatorings in variable_as_callback.swift 2021-05-12 09:26:42 +02:00
Alex Hoppen
effae5f2a9 [Refactoring] Remove the VARIABLE-COMPLETION-HANDLER suffix from checks in variable_as_callback.swift
These were a legacy from when the tests lived in `basic.swift`. They are no longer needed.
2021-05-12 09:26:42 +02:00
Alex Hoppen
32ceb24b6c [Refactoring] Promote call to refactored completion handlers to return
When a function’s completion handler is being passed to another function and the function that the completion handler is being declared in is converted to async, replace the call to the completion handler by a `return` statement.

For example:
```swift
func foo(completion: (String) -> Void) {
  bar(completion)
}
```

becomes
```swift
func foo() async -> String {
  return await bar()
}
```

Previously, we were calling the completion handler, which no longer exists in the newly created `async` function.
2021-05-12 09:26:25 +02:00
Alex Hoppen
921443e8ab [Refactoring] Support creation of async legacy bodies even if a parameter is not optional
If the parameter is not an `Optional`, add a placeholder instead that the user can fill with a sensible default value.
2021-05-11 15:49:55 +02:00
Alex Hoppen
dd978cca0b [Refactoring] Support refactoring calls to async if a variable or function is used as completion handler
Previously, we only supported  refactoring a function to call the async alternative if a closure was used for the callback parameter. With this change, we also support calling a arbitrary function (or variable with function type) that is passed to the completion handler argument.

The implementation basically re-uses the code we already have to create the legacy function’s body (which calls the newly created async version and then forwards the arguments to the legacy completion handler).

To describe the completion handler that the result is being forwarded to, I’m also using `AsyncHandlerDesc`, but since the completion handler may be a variable, it doesn’t necessarily have an `Index` within a function decl that declares it. Because of this, I split the `AsyncHandlerDesc` up into a context-free `AsyncHandlerDesc` (without an `Index`) and `AsyncHandlerParamDesc` (which includes the `Index`). It turns out that `AsyncHandlerDesc` is sufficient in most places.

Resolves rdar://77460524
2021-05-11 15:48:24 +02:00