Commit Graph

1184 Commits

Author SHA1 Message Date
Slava Pestov
d4cc35a938 AST: Remove VarDecl::hasNonPatternBindingInit() 2020-09-18 16:11:06 -04:00
Slava Pestov
d7f4b1a1bd AST: Capture list bindings now point back to their parent CaptureListExpr
We'll need this to get the right 'selfDC' when name lookup
finds a 'self' declaration in a capture list, eg

class C {
  func bar() {}
  func foo() {
    _ = { [self] in bar() }
  }
}
2020-09-18 02:59:15 -04:00
Nathan Hawes
bb773232a8 [Parse][CodeCompletion] Stop code completion within a closure causing parser recovery after the closure.
For example, the completion below would trigger error recovery within the
closure, which we recover from by skipping to the first inner closure's right
brace. The fact that we recovered though, was not recorded. The closure is
treated as still being an error, triggering another recovery after it that
skips over the 'Thing' token, giving a lone closure expression, rather than a
call.

CreateThings {
    Thing { point in
      print("hello")
      point.#^HERE^#
    }
    Thing { _ in }
}

This isn't an issue for code completion when the outer closure is a regular
closure, but when it's a function builder, invalid elements result in no types
being applied (no valid solutions) and we end up with no completion results.

The fix here is removing the error status from the parser result after the
initial parser recovery.
2020-09-10 21:59:09 -07:00
Nathan Hawes
a1ef6e4dac Merge pull request #33749 from nathawes/new-member-completion
[CodeCompletion] Update member completion to handle ambiguous and invalid base expressions
2020-09-09 18:51:22 -07:00
Nathan Hawes
b15c1fd349 [CodeCompletion] Deduplicate the two isMemberCompletion functions in ParseExpr.cpp and ParseDecl.cpp
Also:
- propagate the Solution -> Result rename to Solution parameter of deliverDotExprResults
- fixup header comment in CodeCompletionTypeChecking.h
2020-09-09 12:14:53 -07:00
Doug Gregor
6489e1aaac [Concurrency] Fix nested await/try parsing and effects checking.
Fix the parsing of await/try/try?/try! so that the two can be nested
(e.g., `await try f()` or `try await f()`).

Then, fix the effects checking logic to preserve all throws-related
information under an `await`, and preserve all async/await-related
information under `try`/`try?`/`try!`.

Add a number of tests, and fix 'await' handling for string
interpolations as well.
2020-09-04 13:36:58 -07:00
Nathan Hawes
491b691dbc [CodeCompletion][NFC] Add doc comments and rename symbols for clarity in the new member completion implementation. 2020-09-01 15:04:42 -07:00
Nathan Hawes
3d8561502b [CodeCompletion] Move CompletionCollector to ASTContext + bug fixes. 2020-08-28 22:24:23 -07:00
Nathan Hawes
cf60b2fe61 [CodeCompletion] Pass the CodeCompletionExpr rather than just the base expression to the DotExpr completion callback. 2020-08-28 22:24:22 -07:00
Nathan Hawes
3e8278ae71 Merge pull request #33676 from nathawes/parser-completion-fixes
[Parse][IDE] Various parser fixes for code completion
2020-08-28 22:11:31 -07:00
Nathan Hawes
00994f1147 [Parse] Stop early exiting when parsing catch statements and ObjCSelector expressions that contain code completions. 2020-08-28 17:09:37 -07:00
Frederick Kellison-Linn
352adc3b5d Remove Argument from UnresolvedMemberExpr
Instead, an expresison like `.foo()` is represented as an `UnresolvedMemberExpr` nested inside a `CallExpr`.
2020-08-26 22:42:30 -04:00
Doug Gregor
dd075c64c9 [Concurrency] Treat 'await' as a contextual keyword.
Replace the uglified '__await' keyword with a contextual keyword
'await'. This is more of what we would actually want for the
concurrency model.

When concurrency is enabled, this will be a source-breaking change,
because this is valid Swift code today:

```swift
  struct MyFuture<T> {
    func await() ->  }
    func doSomething() {
      let result = await()
    }
  }
```

but the call to `await()` will be parsed as an await expression when
concurrency is enabled. The source break is behind the experimental
concurrency flag, but this way we can see how much of an issue it is
in practice.
2020-08-13 10:34:51 -07:00
Tony Allevato
db2dd20ce6 Parse concurrency syntax when parsing for syntax-tree-only mode.
This allows the syntax parser library and SwiftSyntax to successfully
parse code using this experimental feature without requiring an API
to pass compiler flags into the parser.
2020-08-11 20:13:15 -07:00
Doug Gregor
5dd1bfea8d [Concurrency] Add support for 'async' closures.
Closurea can become 'async' in one of two ways:
* They can be explicitly marked 'async' prior to the 'in'
* They can be inferred as 'async' if they include 'await' in the body
2020-08-11 13:59:59 -07:00
Doug Gregor
d82c6cb718 [Syntax] Fix syntax tree creation for __await expressions. 2020-08-06 10:43:24 -07:00
Rintaro Ishizaki
5936ddb217 [CodeCompletion] Disable multi trailing closure completion at newline
let value = SomeThing {
    ...
  }
  <HERE>

Since Parser parses code-completion token as a part of the expression,
completion failed to suggest 'value'. Also, the type of 'value' is
often '<<error type>>' because of the code completion token.

For now, disable additional trailing closure completion (suggesting
'label: { <#code#> }') on newline positions. Users still get the
compltion on the same line as the closing brace.

rdar://problem/66456159
2020-08-03 11:58:22 -07:00
Chris Lattner
8bde04cc14 [Concurrency] Implement parsing and semantic analysis of await operator
Similar to `try`, await expressions have no specific semantics of their
own except to indicate that the subexpression contains calls to `async`
functions, which are suspension points. In this design, there can be
multiple such calls within the subexpression of a given `await`.

Note that we currently use the keyword `__await` because `await` in
this position introduces grammatical ambiguities. We'll wait until
later to sort out the specific grammar we want and evaluate
source-compatibility tradeoffs. It's possible that this kind of prefix
operator isn't what we want anyway.
2020-07-29 22:08:09 -07:00
Doug Gregor
06d322b211 [Concurrency] Rename -enable-experimental-async.
Use the more general name `-enable-experimental-concurrency` instead,
since async is one part of the model.
2020-07-28 09:38:54 -07:00
Doug Gregor
f6e9f352f0 [Concurrency] Add async to the Swift type system.
Add `async` to the type system. `async` can be written as part of a
function type or function declaration, following the parameter list, e.g.,

  func doSomeWork() async { ... }

`async` functions are distinct from non-`async` functions and there
are no conversions amongst them. At present, `async` functions do not
*do* anything, but this commit fully supports them as a distinct kind
of function throughout:

* Parsing of `async`
* AST representation of `async` in declarations and types
* Syntactic type representation of `async`
* (De-/re-)mangling of function types involving 'async'
* Runtime type representation and reconstruction of function types
involving `async`.
* Dynamic casting restrictions for `async` function types
* (De-)serialization of `async` function types
* Disabling overriding, witness matching, and conversions with
differing `async`
2020-07-27 18:18:03 -07:00
Brent Royal-Gordon
87d3d3ecb5 [NFC] Add comments with SR numbers for language version mode changes 2020-07-13 14:06:55 -07:00
Brent Royal-Gordon
9a838bb654 Differentiate between Swift 5 and “Swift 6” #file
In -swift-version 5 and earlier, #file will continue to be a synonym for #filePath; in a future -swift-version (“Swift 6 mode”), it will become a synonym for #fileID. #file in libraries will be interpreted according to the language mode the library was compiled in, not the language mode its client uses.

Implement this behavior, tied to a frontend flag instead of a language version. We do so by splitting the old `MagicIdentifierLiteralExprKind::File` into two separate cases, `FileIDSpelledAsFile` and `FilePathSpelledAsFile`, and propagating this distinction throughout the AST. This seems cleaner than looking up the setting for the module the declaration belongs to every time we see `File`.

This doesn’t handle module interfaces yet; we’ll take care of those in a separate commit.
2020-07-13 14:06:55 -07:00
Brent Royal-Gordon
acc01aea03 [NFC] Add MagicIdentifierKinds.def
Extracts the list of magic identifier literal kinds into a separate file and updates a lot of code to use macro metaprogramming instead of naming half a dozen cases manually. This is a complicated change, but it should be NFC.
2020-07-13 14:05:13 -07:00
Mishal Shah
bee7ba2fd5 [Apple Silicon] Update the comment in lib/Parse/ParseExpr.cpp
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2020-07-04 18:53:29 -07:00
Mishal Shah
60d996f060 [Apple Silicon] Add support for triple and availability canonicalization 2020-07-02 19:26:25 -07:00
Rintaro Ishizaki
f50b66689e [CodeCompletion] Fallback to nominal member completion after trailing closure
After trailing closure, we perform "Labeled trailing closure" completion
and fall back to other completion depending on the position.

If the completion happens at a newline position, it used to fallback to
global expression completion, but in type context, we should do override
completion instead.

Also, we didn't use to propagate 'hasCodeCompletion()' status properly.

rdar://problem/64650782
2020-06-24 01:04:33 -07:00
Rintaro Ishizaki
552134a06d Merge pull request #32276 from rintaro/ide-conformingmethods-disablelabeledtrailingclosure-rdar63781922
[SourceKit] Disable labeled trailing closure completion support except code completion
2020-06-11 08:59:37 -07:00
Rintaro Ishizaki
4205e46959 Merge pull request #32184 from rintaro/ide-completion-rdar63965160
[CodeCompletion] Wrap base expression with CodeCompletionExpr
2020-06-10 16:19:35 -07:00
Rintaro Ishizaki
67e88f4f26 [SourceKit] Disable labeled trailing closure support except code completion
Don't insert CodeCompletionExpr at the cursor position in
"conforming method list" or "typecontext" mode. This increase the chance
of successful type checking.

rdar://problem/63781922
2020-06-09 13:02:03 -07:00
Anthony Latsis
4b4634141f Sema: Remove TypeLoc from ExplicitCast 2020-06-09 15:20:25 +03:00
Rintaro Ishizaki
3ec250f701 [CodeCompletion] Wrap base expression with CodeCompletionExpr
For example for:

  funcName(base.<HERE>)

Wrap 'base' with 'CodeCompletionExpr' so that type checker can check
'base' independently without preventing the overload choice of 'funcName'.

This increases the chance of successful type checking.

rdar://problem/63965160
2020-06-05 15:51:07 -07:00
Owen Voorhees
45bc578ae5 [SourceManager] Rename line and column APIs for clarity 2020-05-21 12:54:07 -05:00
Rintaro Ishizaki
0355a87eea [Parse] Parse editor placeholder as a labeled trailng closure
So that SourceKit can expand them to closure literals.
2020-05-06 01:56:41 -04:00
John McCall
40836a0045 Resolve an ambiguity with the multiple-trailing-closure syntax in favor of parsing default: labels. 2020-05-06 01:56:41 -04:00
Rintaro Ishizaki
1cbb1e76d4 [CodeCompletion] Update for braceless multiple trailing closure 2020-05-06 01:56:41 -04:00
Rintaro Ishizaki
2e094a556d [Syntax] Update for braceless multiple trailing closure syntax 2020-05-06 01:56:41 -04:00
John McCall
8df09a0a1d Remove unnecessary check for a single closure.
At an earlier point, we were doing this check after parsing
the labeled closures, but that never made much sense, since
it's a good diagnostic regardless.
2020-05-06 01:56:40 -04:00
John McCall
a518e759d9 WIP for a different syntax for multiple trailing closures
that allows arbitrary `label: {}` suffixes after an initial
unlabeled closure.

Type-checking is not yet correct, as well as code-completion
and other kinds of tooling.
2020-05-06 01:56:40 -04:00
Rintaro Ishizaki
fd68f092f2 [CodeCompletion] Completion inside multiple trailing closure
rdar://problem/59688477
2020-05-06 01:56:40 -04:00
Pavel Yaskevich
6bd20ca768 [Parse] Allow multiple trailing closures to be delimited by _:
Syntax like `foo { _: { ... } }` is going to be parsed as a single
trailing closure.
2020-05-06 01:56:40 -04:00
Rintaro Ishizaki
d6dcd44e86 [Parse] Report "success" if '}' is found for multiple trailing closures 2020-05-06 01:56:40 -04:00
Nathan Hawes
4c4990ead4 Multiple trailing closure fixes
- Diagnose non-closure-literals after label + colon
- Form a TupleExpr, rather than a ParenExpr for a single labelled trailing closure.
2020-05-06 01:56:40 -04:00
Rintaro Ishizaki
150df80a75 [Syntax] Add declaration for multiple trailing closure 2020-05-06 01:56:40 -04:00
Pavel Yaskevich
c8a8b890f3 [Parser] Propagate status information from each closure in the trailing block 2020-05-06 01:56:40 -04:00
Pavel Yaskevich
08a29e8da6 [Parser] Check for first label in trailing closure block without backtracking 2020-05-06 01:56:40 -04:00
Pavel Yaskevich
ed5b6958f3 [Parse] Introduce tailored diagnostics for an invalid trailing closures block
If block is not just a list of labeled closures produce a tailored
diagnostic and skip over invalid code.
2020-05-06 01:56:40 -04:00
Pavel Yaskevich
d06126da3b [Parser] Add support for multiple trailing closures syntax
Accept trailing closures in following form:

```swift
foo {
  <label-1>: { ... }
  <label-2>: { ... }
  ...
  <label-N>: { ... }
}
```

Consider each labeled block to be a regular argument to a call or subscript,
so the result of parser looks like this:

```swift
foo(<label-1>: { ... }, ..., <label-N>: { ... })
```

Note that in this example parens surrounding parameter list are implicit
and for the cases when they are given by the user e.g.

```swift
foo(bar) {
  <label-1>: { ... }
  ...
}
```

location of `)` is changed to a location of `}` to make sure that call
"covers" all of the transformed arguments and parser result would look
like this:

```swift
foo(bar,
   <label-1>: { ... }
)
```

Resolves: rdar://problem/59203764
2020-05-06 01:56:40 -04:00
Pavel Yaskevich
07cb6b8ad2 [Parse] Account that there could be multiple trailing closures which parsing 2020-05-06 01:56:40 -04:00
Pavel Yaskevich
45ac1bcf17 [Parser] Adjust parseExprList to return multiple trailing closures
Also extend returned object from simplify being an expression to
`TrailingClosure` which has a label, label's source location and
associated closure expression.
2020-05-06 01:56:40 -04:00
Pavel Yaskevich
5cea9b9849 [AST] Add support for multiple trailing closures to the parser/expressions 2020-05-06 01:56:40 -04:00