Commit Graph

1224 Commits

Author SHA1 Message Date
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
Robert Widmann
0342855e50 [NFC] Debride Pattern.h of Implicit Tri-State
Remove all of this in favor of explicit constructors to preserve the one-liners, or distribute the setImplicit() calls to the callsites if necessary.
2020-04-30 22:03:55 -07:00
Robert Widmann
f9a506d799 [NFC] Strip EditorPlaceholderExpr of its TypeLoc 2020-04-28 20:10:10 -07:00
Robert Widmann
19ab68db98 [NFC] Strip UnresolvedSpecializeExpr of its TypeLoc
No caller needed the type
2020-04-28 20:10:10 -07:00
Robert Widmann
5b3060318e [NFC] Strip ClosureExpr of its TypeLoc 2020-04-28 20:10:10 -07:00
Robert Widmann
a6fc9b3679 Merge pull request #31253 from CodaFi/casting-call
Strip TypeExpr of its TypeLoc
2020-04-28 09:45:53 -07:00
Robert Widmann
7ed188216e Remodel the Interface for Implicit TypeExprs
Make it slightly easier to enforce the invariant that implicit TypeExpr
nodes have a contextual type set.
2020-04-23 17:04:38 -07:00
Robert Widmann
09db2902d2 Strip TypeExpr of its TypeLoc
Remove duplication in the modeling of TypeExpr. The type of a TypeExpr
node is always a metatype corresponding to the contextual
type of the type it's referencing. For some reason, the instance type
was also stored in this TypeLoc at random points in semantic analysis.

Under the assumption that this instance type is always going to be the
instance type of the contextual type of the expression, introduce
a number of simplifications:

1) Explicit TypeExpr nodes must be created with a TypeRepr node
2) Implicit TypeExpr nodes must be created with a contextual type
3) The typing rules for implicit TypeExpr simply opens this type
2020-04-23 17:04:38 -07:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Pavel Yaskevich
3accb65a5c [AST] Track whether key path expression has a leading dot
This is going to be useful to detect whether contextual root
is really expected during key path resolution in Sema.
2020-04-07 16:16:34 -07:00
Owen Voorhees
43e2d107e1 [SE-0276] Implement multi-pattern catch clauses
Like switch cases, a catch clause may now include a comma-
separated list of patterns. The body will be executed if any
one of those patterns is matched.

This patch replaces `CatchStmt` with `CaseStmt` as the children
of `DoCatchStmt` in the AST. This necessitates a number of changes
throughout the compiler, including:
- Parser & libsyntax support for the new syntax and AST structure
- Typechecking of multi-pattern catches, including those which
  contain bindings.
- SILGen support
- Code completion updates
- Profiler updates
- Name lookup changes
2020-04-04 09:28:26 -07:00