Commit Graph

2740 Commits

Author SHA1 Message Date
Rintaro Ishizaki
8ef504acf3 Merge pull request #35050 from rintaro/ide-completion-rdar72198530
[CodeCompletion] Annotate 'async' functions/initializers in results
2020-12-18 09:29:07 -08:00
Nathan Hawes
246e0d304c Merge pull request #35113 from nathawes/missing-completion-in-multistatment-closure-arg-of-overloaded-call
[CodeCompletion][Sema] Don't guess whether a solution will be applied to the AST based on solutions formed for code completion.
2020-12-17 11:07:56 +10:00
Nathan Hawes
5ac5cabe4f [CodeCompletion][Sema] Don't guess whether a solution will be applied to the AST based on solutions formed for code completion.
When solving for code completion, we ignore missing arguments after the one
containing the code completion location, don't favor overloads with a number of
params matching the number of arguments in a call and so on. Because of this,
we can't assume multiple solutions being formed when solving for code completion
means there won't be a single best solution formed when solving for regular
type-checking.

Resolves rdar://problem/72362275
2020-12-16 13:44:59 +10:00
Rintaro Ishizaki
4c38ec5a4a Merge pull request #35069 from rintaro/ide-completion-rdar72199413
[Parse/CodeCompletion] Implement effects specifier completion
2020-12-15 13:11:18 -08:00
Rintaro Ishizaki
ed82d1828e [CodeCompletion] Complete effects specifiers in closure signature position 2020-12-14 12:43:50 -08:00
Rintaro Ishizaki
4284a51589 [Parse/CodeCompletion] Implement effects specifier completion
Rewrote and rename 'parseAsyncThrows' to 'parseEffectsSpecifiers'.
Implemented 'CodeCompletionCallbacks::completeEffectsSpecifier()'
2020-12-14 12:38:15 -08:00
Rintaro Ishizaki
be7466eb3f [CodeCompletion] Annotate 'async' functions/initializers in results
Similar to how it shows "throws" today.

Introduced CodeCompletionStringChunk::ChunkKind::AsyncKeyword

rdar://problem/72198530
2020-12-14 11:03:24 -08:00
Rintaro Ishizaki
82eca57e13 [CodeCompletion] Complete 'await' in expression position
rdar://problem/72199267
2020-12-11 11:53:32 -08:00
Doug Gregor
d7367997d2 Merge pull request #34985 from DougGregor/import-swift-async-attr
[Concurrency] Implement support for swift_async attribute.
2020-12-10 10:09:28 -08:00
Doug Gregor
82b44fc6dd [Concurrency] Fix async throws import nullability in the presence of typedefs. 2020-12-08 14:51:03 -08:00
Doug Gregor
915afc3aa5 [Clang importer] Implement support for importing _Nullable_result.
`_Nullable_result` indicates that a parameter of a completion handler
should be imported as optional when the completion handler can fail by
throwing an error.

Implements rdar://70108088.
2020-12-08 14:49:54 -08:00
Doug Gregor
b837675910 [Concurrency] Introduce more completion-handler names to the import heuristics.
Extend the set of completion-handler names we look for to infer an
`async` import of an Objective-C method, which includes:

* (with)CompletionBlock
* (with)reply
* (with)replyTo

both as parameter names and as base name suffixes.
2020-12-07 16:47:31 -08:00
Doug Gregor
3cd115e283 [Concurrency] Implement support for swift_async attribute.
The `swift_async` attribute helps control how a method is imported as
`async` into Swift.

Implements rdar://70111787.
2020-12-06 23:21:18 -08:00
Rintaro Ishizaki
e066d4351b Merge pull request #34586 from rintaro/ide-completion-rdar71005827
[DerivedConformance] Correctly set access of derived 'hash(into:)'
2020-11-20 09:30:32 +09:00
Nathan Hawes
1eb05b7760 Merge pull request #34733 from nathawes/migrate-unresolved-completion
[CodeCompletion][Sema][Parse] Migrate unresolved member completion to the solver-based completion implementation
2020-11-19 01:26:43 -08:00
Rintaro Ishizaki
5aab24be17 Merge pull request #34800 from bnbarham/fixup-batch-test
[Gardening] Fix up order-dependent batch code complete tests
2020-11-19 08:12:42 +09:00
Doug Gregor
d249b5cce5 [Clang importer] Make sure we mirror protocol decls for all names.
When mirroring declarations from protocols, make sure to mirror for
all potential imported names. Otherwise, we might miss out on one or
the other of an async import or a completion-handler import of the
same method.

Fixes rdar://71429577.
2020-11-17 22:26:41 -08:00
Ben Barham
54bc17ee34 [Gardening] Fix up order-dependent batch code complete tests
swift-ide-test -batch-code-completion has no particular order for the
output completion list. Update the order dependent tests to use DAG
instead.
2020-11-18 14:34:17 +10:00
Nathan Hawes
c777b2578a [test] Re-enable now-passing IDE/complete_unresolved_members.swift run line 2020-11-16 11:02:08 -08:00
Nathan Hawes
ca7fb37aba [CodeCompletion][Sema][Parse] Migrate unresolved member completion to the solver-based completion implementation
Following on from updating regular member completion, this hooks up unresolved
member completion (i.e. .<complete here>) to the typeCheckForCodeCompletion API
to generate completions from all solutions the constraint solver produces (even
those requiring fixes), rather than relying on a single solution being applied
to the AST (if any). This lets us produce unresolved member completions even
when the contextual type is ambiguous or involves errors.

Whenever typeCheckExpression is called on an expression containing a code
completion expression and a CompletionCallback has been set, each solution
formed is passed to the callback so the type of the completion expression can
be extracted and used to lookup up the members to return.
2020-11-13 15:37:14 -08:00
Nathan Hawes
1105531b7b Merge pull request #34521 from nathawes/handle-dicts-parsed-as-arrays-for-completion
[CodeCompletion][Sema] Add fix to treat empty or single-element array literals as dictionaries when used as such
2020-11-11 15:54:55 -08:00
Nathan Hawes
edbbefce91 [CodeCompletion][Sema] Add fix to treat empty or single-element array literals as dictionaries when used as such
In the single-element case, it is treated as the dictionary key.

func takesDict(_ x: [Int: String]) {}
takesDict([]) // diagnose with fixit to add missing ':'
takesDict([1]) // diagnose with fixit to add missing ': <#value#>'
takesDict([foo.<complete>]) // prioritise Int members in completion results -
                            // the user just hasn't written the value yet.

The above previously failed with a generic mismatch error in normal type
checking (due to the literal being parsed as an array literal) and code
completion could not pick up the expected type from the context.
2020-11-11 11:48:39 -08:00
Saleem Abdulrasool
7c968c6ccf AST: support availability on Windows
Enable Windows specific availability annotations in Swift.
2020-11-09 20:03:52 -08:00
Rintaro Ishizaki
b63dd8b4d6 Merge pull request #34596 from rintaro/ide-completion-rdar71063455
[CodeCompletion] Deduplicate results in ExprContextInfo
2020-11-05 14:00:28 -08:00
Rintaro Ishizaki
d221f14215 [CodeCompletion] Deduplicate results in ExprContextInfo
Using canonical types. Otherwise 'Optional<T>' and 'T?' aren't
considered the same.

Also, for example, the expected context types are 'T?' and 'T', don't
get results from 'T' twice.

rdar://problem/71063455
2020-11-05 11:32:16 -08:00
Rintaro Ishizaki
fa7b67192a [DerivedConformance] Correctly set access of derived 'hash(into:)'
If access of the target type is 'private', derived hash(into:) used to
be created with 'private' access. But it should be 'fileprivate'.

rdar://problem/71005827
2020-11-04 19:50:16 -08:00
Ben Barham
b4572c4e59 [Gardening] Migrate complete_expr_postfix_begin test to use new batching 2020-11-05 13:27:04 +10:00
Rintaro Ishizaki
096edf1629 Merge pull request #34579 from rintaro/ide-test-batchcompletion-xfail
[CodeCompletion] Add XFAIL to swift-ide-test
2020-11-04 18:51:48 -08:00
Rintaro Ishizaki
65f3133ba9 [CodeCompletion] Add XFAIL to swift-ide-test
In -batch-code-completion mode, add a token parameter 'xfail={reason}'.
When 'FileCheck' succeeds on the token, it is considered "unexpected
pass", and the test fails.

rdar://problem/71021285
2020-11-04 15:20:06 -08:00
Rintaro Ishizaki
b57aa8fe26 Merge pull request #34564 from rintaro/ide-completion-rdar71008072
[LookupVisibleDecls] Include protocol members when finding 'subscript(dynamicMember:)'
2020-11-03 16:37:28 -08:00
Ben Barham
9532169279 Merge pull request #34548 from bnbarham/completion-string-interp-init-70833348
[CodeCompletion] Do not include decl in own initializer/default argument
2020-11-04 10:31:59 +10:00
Rintaro Ishizaki
78973173e9 [LookupVisibleDecls] Include protocol members when finding subscript(dynamicMember:)
struct Point { var x, y: Int }
  protocol P {}
  extension P {
    subscript<T>(dynamicMember key: KeyPath<Point, T>) -> T
  }
  @dynamicMemberLookup struct S: P {}

  S().<HERE>

Previously, completion couldn't suggest 'x' and 'y'. Include
'NL_ProtocolMembers' when finding 'subscript(dynamicMember:)'.

rdar://problem/71008072
2020-11-03 14:19:03 -08:00
Rintaro Ishizaki
5938ef8b05 [CodeCompletion] Add tests for fixed cases
Just adding a test case since it's already fixed.

Until d78bf22413, if there are multiple
brace statements in an ASTNode, only the first brace statement is
considered to be type checked.

rdar://problem/71001317
2020-11-03 13:01:36 -08:00
Ben Barham
c3d1e34b0c [CodeCompletion] Do not include decl in own default argument
Similar to 4cf7426698 but for the case
when the completion is in a default argument expression rather than
initializer. Fixed to grab either the initializer or default argument if
there is one.
2020-11-03 16:42:28 +10:00
Ben Barham
95ae19255e [CodeCompletion] Do not include decl in own (string interp) initializer
Strings are a single token, so the previous check would treat
completions inside string interpolations as being outside of the
initializer.

Grab the end of the token from the Lexer, but wrap in a context check to
avoid performing that for every declaration found in the lookup.

Resolves rdar://70833348
2020-11-03 16:42:28 +10:00
Ben Barham
4da190dde1 [NameLookup] Retain invalid decls when filtering via access path
Fixes missing declarations in the completions list due to their type
being invalid.

Resolves rdar://70704835
2020-11-02 08:49:05 +10:00
Ben Barham
4cf7426698 [CodeCompletion] Do not include decl completion in its own initializer
`::lookupVisibleDecls` had an inline consumer in order to remove
"unusable" results. Refactor this method, moving the consumer (now
`UsableFilteringDeclConsumer`) to allow its use when looking up top
level module declarations.

Also use the `AccessFilteringDeclConsumer` in preference to a condition
in `addVarDecl`.

Resolves rdar://56755598
2020-11-02 08:49:05 +10:00
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
Alejandro Alonso
424802fb34 Revert SE-0283 (#34492)
Reverted despite build failures.
2020-10-29 17:32:06 -07:00
Nathan Hawes
a07dda60ef Merge pull request #34448 from nathawes/completion-dedupe-ambiguous
[CodeCompletion] Dedupe completion results if multiple lookups were made
2020-10-27 10:33:32 -07:00
Anthony Latsis
4ce7a2d060 CodeCompletion: Annotate archetypes, generic parameters and dependent members 2020-10-27 14:39:52 +03:00
Nathan Hawes
62a5fb1698 [CodeCompletion] Dedupe completion results if multiple lookups were made.
Solver-based member completion performs a lookup per solution, but if the base
types in each solution are variations of the same generic (e.g. Array<Int>,
Array<String>), we can end up with the same result appearing twice (e.g. count)
2020-10-26 15:41:24 -07:00
Azoy
fd950ebbf3 Implement Tuple Comparable Conformance
Add protocol witnesses for all Comparable requirements
2020-10-22 18:27:07 -04:00
Azoy
e60ef84bd2 Implement Tuple Equatable Conformance 2020-10-22 18:24:28 -04:00
John McCall
a8464dcaf1 Implicitly import _Concurrency under -enable-experimental-concurrency 2020-10-22 00:53:15 -04:00
Doug Gregor
6d41524fe6 [SE-0289] Finish renaming source code, tests to "result builders" 2020-10-20 22:18:51 -07:00
Doug Gregor
0d568a93d4 [SE-0289] Update diagnostics & many other strings to "result builders" 2020-10-20 21:44:09 -07:00
Doug Gregor
6a40a3a8aa [SE-0289] Add support for @resultBuilder.
"Function builders" are being renamed to "result builders". Add the
corresponding `@resultBuilder` attribute, with `@_functionBuilder` as
an alias for it, Update test cases to use @resultBuilder.
2020-10-20 13:24:51 -07:00
Nathan Hawes
15f5222bbd [CodeCompletion][Sema] Allow missing args when solving if the completion location indicates the user may intend to write them later.
func foo(a: Int, b: Int) {}
func foo(a: String) {}

// Int and String should both be valid, despite the missing argument for the
// first overload since the second arg may just have not been written yet.
foo(a: <complete here>

func bar(a: (Int) -> ()) {}
func bar(a: (String, Int) -> ()) {}

// $0 being of type String should be valid, rather than just Int, since $1 may
// just have not been written yet.
bar { $0.<complete here> }
2020-10-19 12:16:19 -07:00
Nathan Hawes
90418612f4 [CodeCompletion] Reuse CompletionContextFinder for fallback completion when no typeCheckExpression call is made
...and adjust the fallback context it choses now that ErrorExprs no longer
cause constraint generation to fail.

Also fix some issues with the fallback logic in typeCheckForCodeCompletion:

1) For completion expressions in multi-statement closures, we were assuming a
separate typeCheckExpression call would be made when the outer expression
produced a single solution that had a resolved type for the closure. If the
solution contained other fixes unrelated to the closure however, it wasn't
applied and a separate call for the body was never made.

2) typeCheckForCodeComplation sometimes falls back to regular expression type
checking but didn't update the passed-in target's expression after santizing
and prechecking it, which may have modified it and its sub-expressions. This
triggered assertion failures in certain cases due to the mix of the stale
top-level expression pointer being used with updated subexpressions.
2020-10-12 18:17:35 -07:00