Commit Graph

567 Commits

Author SHA1 Message Date
Rintaro Ishizaki
1c791d345d [Parse] Factor out 'isEffectsSpecifier()' 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
Anthony Latsis
413352b77c Merge pull request #34620 from AnthonyLatsis/parse-misc
Parse: Only diagnose dollar-prefixed identifiers that are Swift declarations
2020-12-04 09:09:45 +03:00
Anthony Latsis
47ce1529f0 Parse: Only diagnose dollar-prefixed identifiers that are Swift declarations 2020-11-19 20:30:53 +03:00
Kk Shinkai
a0f0747283 Fix misspellings 2020-11-18 11:47:16 +08: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
Owen Voorhees
c6a266ef62 Merge pull request #29735 from owenv/multiple-varargs
[SE-0284] Allow Multiple Variadic Parameters in Functions, Subscripts, and Initializers
2020-09-05 11:27:21 -05:00
Nathan Hawes
3e0500d73c [Parse][IDE] Don't drop default argument init exprs containing code completion exprs and type check them for code completion.
Fixes up some tests marked as non-ideal to give the ideal result now too.
2020-08-28 17:09:37 -07:00
Owen Voorhees
9708247065 [SE-0284] Lift the 1-vararg-per-function restriction
[SE-0284] Add round_trip_parse_gen tests

[SE-0284] Add missing test cases
2020-08-23 21:37:07 -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
b1802fa2eb [Concurrency] Minor fixes for parsing and syntax of 'async' 2020-07-28 22:06:18 -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
Rintaro Ishizaki
bf379f2321 [CodeCompletion] Don't throw away parsed return type for function decls
Parsed type should be in the result AST to maintain the source range of
the decl.

rdar://problem/65906026
2020-07-21 15:49:11 -07:00
Michael Gottesman
d2f986739c Merge pull request #32940 from gottesmm/pr-8414ddbc369ed5bb8c0622162de920b962426cf1
[ast] Rename VarPattern -> BindingPattern.
2020-07-18 20:47:21 -07:00
Michael Gottesman
092edd6621 [ast] Rename VarPattern -> BindingPattern.
VarPattern is today used to implement both 'let' and 'var' pattern bindings, so
today is already misleading. The reason why the name Var was chosen was done b/c
it is meant to represent a pattern that performs 'variable binding'. Given that
I am going to add a new 'inout' pattern binding to this, it makes sense to
give it now a better fitting name before I make things more confusing.
2020-07-16 18:56:01 -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
Robert Widmann
fc9070c072 Strip TypeLoc from IsPattern 2020-06-10 13:29:39 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Robert Widmann
31242bc3da Remove The Parser Hack For If-Let
The parser used to rewrite

if let x: T

into

if let x: T?

This transformation is correct at face value, but relied on being able
to construct TypeReprs with bogus source locations. Instead of having
the parser kick semantic analysis into shape, let's perform this
reinterpretation when we resolve if-let patterns in statement
conditions.
2020-05-13 12:34:24 -07:00
Argyrios Kyrtzidis
b4baf420b4 [ASTPrinter] Fix issue where printing if-let variables shows their type as optional
Fixes
https://bugs.swift.org/browse/SR-12631
rdar://62894516
2020-05-12 16:39:09 -07: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
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
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
7161ed01f8 Work Around IDE Structure Markers
Structure analysis trusts what should be implicit pattern nodes have the
right source location information in them. Preserve that behavior for
now.
2020-05-01 16:30:45 -07: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
Rintaro Ishizaki
62d8eed570 [Parse] Don't drop parsed error types in where clause from AST
Code completion requires the source range of the 'where' clause to
correctly lookup member of types in where clause.

rdar://problem/61911134
2020-04-23 08:54:38 -07:00
Alexis Laferrière
c1618c13f1 [Parser] Fix suggested fix-its on enum case with empty parens
rdar://problem/58546221
2020-01-15 10:54:56 -08:00
Tapan Thaker
fce55a6fb2 [Parse] Provide a diagnostic when a closure parameter is declared with type sugar (#28315)
* diagnostic when a closure parameter is declared with type sugar

* Use a test that was already commmited for SR-11724
i

* Use isa<T> instead of asking for the kind directly

* Fix nit: Remove a whitespace
2019-12-11 17:17:37 -08:00
Brent Royal-Gordon
63ec1cf5af Introduce a separate #filePath, remove -pound-file
This makes the path behavior more first-class. The feature is now hidden behind an experimental flag, -enable-experimental-concise-pound-file.
2019-12-04 16:35:13 -08:00
Hamish Knight
01d5c00f9b [Sema] Requestify default arg type checking
This commit introduces a request to type-check a
default argument expression and splits
`getDefaultValue` into 2 accessors:

- `getStructuralDefaultExpr` which retrieves the
potentially un-type-checked default argument
expression.

- `getTypeCheckedDefaultExpr` which retrieves a
fully type-checked default argument expression.

In addition, this commit adds `hasDefaultExpr`,
which allows checking for a default expr without
kicking off a request.
2019-11-11 13:49:06 -08:00
Robert Widmann
dd1b15775d Partially Revert #27862
When SE-110 was being implemented, we accidentally began to accept
closure parameter declarations that had no associated parameter names,
e.g.

foo { ([Int]) in /**/ }

This syntax has never been sanctioned by any version of Swift and should
be banned.  However, the change was made long enough ago and there are
enough clients relying on this, that we cannot accept the source break
at the moment.  For now, add a bit to ParamDecl that marks a parameter
as destructured, and back out setting the invalid bit on the type repr
for these kinds of declarations.

To prevent further spread of this syntax, stub in a warning that offers
to insert an anonymous parameter.

Resolves part of rdar://56673657 and improves QoI for errors like
rdar://56911630
2019-11-10 22:10:53 -08:00
Robert Widmann
6dc3f4aad9 Fixup the destructuring diagnostics
Use the isInvalid() bit on the TypeRepr to signal that a closure
parameter is potentially a tuple destructure.  This has two benefits
1) Parse is no longer using the isInvalid() bit on Decl
2) Invalidating the type repr itself means that we no longer spuriously
diagnose variable patterns in destructures as missing types.
2019-10-24 16:03:41 -07:00
Robert Widmann
5beb6f0f6e Restructure invalid parameter diagnostic
Diagnose the fact that we're missing a colon, not the fact that we're missing a type since that's actually what has gone wrong.
2019-10-24 09:56:02 -07:00
Nathan Hawes
05ef088859 Revert "Remove The Last Vestiges of isInvalid from Parse" 2019-10-22 11:31:07 -07:00
Robert Widmann
dc63923a30 Restructure invalid parameter diagnostic
Diagnose the fact that we're missing a colon, not the fact that we're missing a type since that's actually what has gone wrong.
2019-10-21 15:18:20 -07:00
Robert Widmann
961a1cf0a4 Clean up invalidation in Parse
Clean up uses of setInvalid() and remove uses of isInvalid() in preparation for that being a semantic accessor.
2019-10-21 15:17:07 -07:00
Victor Guerra
459181178e [Diagnostics] Add a fix-it for try instead of throws in function decl… (#27647)
* [Diagnostics] Add a fix-it for try instead of throws in function decls and types.

Sometimes one would misstype `throws` for `try` so we provide a fix-it for that.
It might happen in two cases:

In function declarations:
```swift
func foo() try {}
```

In function types:
```swift
let f = () try -> Int
```

Resolves SR-11574.
2019-10-17 01:19:28 +02:00
Rintaro Ishizaki
8a03e08966 Revert "Merge pull request #26403 from rintaro/gsoc-2019-part1"
This reverts commit 1a211e6e5f, reversing
changes made to 482d0621a6.
2019-10-14 15:18:05 -07:00
Rintaro Ishizaki
00613db8db Revert "Merge pull request #27230 from rintaro/syntaxparsse-rdar55421369"
This reverts commit b09f87594a, reversing
changes made to d0b7ecab00.
2019-10-14 12:47:23 -07:00
Rintaro Ishizaki
0e8010d8b9 Revert "Merge pull request #27592 from rintaro/syntaxparse-exprtuple"
This reverts commit cdfd1ab2cf, reversing
changes made to eb02f20f99.
2019-10-14 12:15:48 -07:00
Robert Widmann
2516089cb6 Clean up the pseudo-clone-constructor for ParamDecl 2019-10-11 11:51:50 -07:00
Robert Widmann
060cbb293f [NFC] Downgrade The TypeLoc in VarDecl to a TypeRepr
TypeCheckPattern used to splat the interface type into this, and
different parts of the compiler would check one or the other.   There is
now one source of truth: The interface type.  The type repr is now just
a signal that the user has written an explicit type annotation on
a parameter.  For variables, we will eventually be able to just grab
this information from the parent pattern.
2019-10-11 11:15:51 -07:00
Slava Pestov
12231d2df3 Merge pull request #27571 from slavapestov/circular-validation-cleanups-5
Circular validation cleanups, part 5
2019-10-10 19:52:56 -04:00
Slava Pestov
d8b61ff24b Sema: Peel off typeCheckParameterList()'s specifier computation into a request
Since getSpecifier() now kicks off a request instead of always
returning what was previously set, we can't pass a ParamSpecifier
to the ParamDecl constructor anymore. Instead, callers either
call setSpecifier() if the ParamDecl is synthesized, or they
rely on the request, which can compute the specifier in three
specific cases:

- Ordinary parsed parameters get their specifier from the TypeRepr.

- The 'self' parameter's specifier is based on the self access kind.

- Accessor parameters are either the 'newValue' parameter of a
  setter, or a cloned subscript parameter.

For closure parameters with inferred types, we still end up
calling setSpecifier() twice, once to set the initial defalut
value and a second time when applying the solution in the
case that we inferred an 'inout' specifier. In practice this
should not be a big problem because expression type checking
walks the AST in a pre-determined order anyway.
2019-10-10 15:00:07 -04:00
Rintaro Ishizaki
bb08667bf5 [SyntaxParse] Parse tuple/paren expression syntax 2019-10-09 14:48:47 -07:00
Jordan Rose
8ff1dac381 [AST] Break some header dependencies for faster rebuilds (#27374)
DiagnosticEngine.h no longer depends on Attr.h.
Expr.h no longer depends on TypeRepr.h.

No functionality change.
2019-09-26 09:17:10 -07:00
Rintaro Ishizaki
b09f87594a Merge pull request #27230 from rintaro/syntaxparsse-rdar55421369
[SyntaxParse] Re-apply move-only ParsedRawSyntaxNode
2019-09-19 07:36:14 +02:00