Commit Graph

7 Commits

Author SHA1 Message Date
Ben Barham
3de83aca66 [ClangImporter] Add @completionHandlerAsync for imported decls
Implicitly add the @completionHandlerAsync attribute for ObjCMethodDecl
that have a completion handler. Adds a link from the non-async to the
async function for use in diagnostics and refactorings.

Resolves rdar://74665226
2021-03-31 08:39:12 +10:00
Evan Wilde
a4a427e816 Adding additional test cases
This patch adds four new test cases

1. Calling the comp-handler function on an instance of this class
2. Calling the comp-handler function on a nested struct instance
3. Calling the comp-handler function on a different struct instance
4. Storing a comp-handler function is just fine
2021-03-24 23:10:01 -07:00
Evan Wilde
8516c0c5aa Fix crash with failed typecheck
The walker was crashing if something failed to typecheck since the type
wasn't available. I've added a little test to ensure that not only do we
not crash, but continue checking within the closure.
2021-03-24 22:54:15 -07:00
Evan Wilde
5e17dc4aab Only traverse closures once
So closures are in a PatternBindingDecl. Since we have an entry-point
into PatternBindingDecl that gets hit for every one of them, we used to
traverse the PBD's that are declared inside of the FunctionDecls twice.

This patch stops us from actually traversing into the PBD from the
checker, and instead pulling out the initializers of interest and
walking each expression separately.
2021-03-24 17:48:49 -07:00
Evan Wilde
f03df6dc2f Check global closures
This patch adds checking for usage of completion handler functions with
async alternatives in closures at either the global scope (for
-parse-as-library) or as top-level-decls.

The top-level and global scope are typechecked in the order that they
are declared. This means that if the closure calls a completion
handler function that is declared later, the attribute won't have been
typechecked yet and thus won't have a resolved async function. This
patch updates the warning emitter to typecheck and resolve the attribute
if it needs to. If the thing doesn't typecheck, we don't need emit the
warning at all because the attribute is bad and we tell them to fix it.
2021-03-23 23:43:16 -07:00
Evan Wilde
dfee59e3d1 Emit warning suggesting async function
This patch adds a diagnostic to recommend using the async function
instead of using the completion handler version. The diagnostic is only
emitted when the call is made in an async context and the
completion-handler version of the function is attributed with the
@completionHandleyAsync attribute.
2021-03-23 23:43:16 -07:00
Evan Wilde
5b17c7c3c4 Updating tests for @completionHandlerAsync
This patch updates the tests for the @completionHandlerAsync attribute.

The main test is broken into three chunks; parsing, typechecking, and
the decl assginment phases.

For parsing, we verify both happy cases, with an explicitly provided
completion handler index and one where it is omitted. We also verify the
various ways that parsing can fail, with ill-formed names, missing
parens etc....

The typechecking phase verifies that the function the attribute is
attached to is not async, that it takes a completion handler, that the
completion handler is a function type, is a function that returns Void,
is @escaping, and is not @autoclosure.

The decl assignment complains about the name not referencing an existing
function, and the ambiguous naming of async functions.
2021-03-13 13:38:15 -08:00