Commit Graph

1219 Commits

Author SHA1 Message Date
Rintaro Ishizaki
ce87bf7537 [Parse] Postfix '#if' expression
Implement postfix ifconfig expression which expands '#if' functionality
to postfix member reference expressions.

rdar://problem/51690082
2021-04-29 09:12:23 -07:00
Alex Hoppen
4603b6753b [CodeComplete] Fix issue completing type in generic signature
Due to https://github.com/apple/swift/pull/36552, parsing the code completion token as a type inside a generic parameter list no longer fails. Instead, it consumes the code completion token as a type identifier. However, since `parseExprIdentifer` does not return a `ParserStatus`, the information whether a code completion token was consumed gets lost, causing `setCodeCompletionDelayedDeclState` to not be called and thus no code completion results show up.

To resolve this, make `parseExprIdentifier` return its `ParserStatus` through a `ParserResult`.

Fixes rdar://76335452 [SR-14432]
2021-04-12 18:45:00 +02:00
Nathan Hawes
b8f5bf3434 [CodeCompletion][Parse] Don't drop the contained expression when completing within an InOutExpr
When completing within an InOutExpr like `&foo.<complete>`, we were forming a
CodeCompletionExpr with a base when parsing the content of the InOutExpr and
storing it in CodeCompletionCallbacksImpl::CodeCompleteTokenExpr. When the
result of that parse contained a code completion though, we were dropping the
sub-expression completely and forming an empty code completion result in place
of the inout expression, which resulted in later code inserting a code
completion expression with no base into the AST. The solver based completion
was later asking for the type of the code completion and its base using the
expression stored in CodeCompletionCallbacksImpl::CodeCompleteTokenExpr, but
that never ended up in the AST so we hit an assertion about the expression not
have a type in the formed solutions.

Resolves rdar://75366814
2021-04-03 13:39:23 +10:00
Alex Hoppen
bfbd812a21 [Parser] Distinguish between backtracking scopes that can be cancelled or not
For backtracking scopes that are never cancelled, we can completely disable the SyntaxParsingContext, avoiding the creation of deferred nodes which will never get recorded.
2021-03-10 17:29:33 +01:00
Holly Borla
140cbaa744 [Parser] Allow $ prefixes on argument labels and closure parameter
declarations.
2021-02-25 18:35:14 -08:00
Doug Gregor
8448e61b3a Add support for attributes on closures. 2021-02-16 22:19:43 -08:00
Slava Pestov
6c69d17e0c Parse: Implement parsing for 'reasync' attribute
Part of <rdar://problem/71098795>.
2021-02-15 22:18:54 -05:00
Alex Hoppen
d0e27bb037 Merge pull request #35649 from ahoppen/trivia-parsing
[libSyntax] Avoid lexing of trivia into pieces if possible
2021-02-08 09:37:23 +01:00
Doug Gregor
089151cede [Parser] Narrow the Fix-It correcting "async" -> "await" in expressions.
The way in which we detected an "async" in expression context broke
some well-formed code that used "async" as a variable. Narrow the
check to only cases where the code will be ill-formed with "async" as
an identifier.
2021-02-05 13:05:32 -08:00
Doug Gregor
238290cdc4 [SE-0296] Enable async/await by default.
Always parse `async` and `await`, allowing the definition and use of
asynchronous functions without the "experimental concurrency" flag.

Note that, at present, use of asynchronous functions requires one to
explicitly import or link against the `_Concurrency` library. We'll
sort this out in a follow-up change.

Tracked by rdar://73455330.
2021-02-05 09:51:46 -08:00
Alex Hoppen
a8c01365b8 [Lexer] Eliminate unnecessary calls to TriviaLexer::lexTrivia
If the lexer itself keeps track of where the first comment of a token
starts, we can avoid parsing trivia into pieces.
2021-02-05 08:15:55 +01:00
Alex Hoppen
08ad703553 [Lexer] Push trivia piece lexing down to SyntaxParsingContext
This is again a transitional state before SyntaxParsingContext hands
the responsibility over to SyntaxTreeCreator and from there to
SyntaxParseActions.
2021-02-05 08:15:54 +01:00
Alex Hoppen
6911553067 [Lexer] Push trivia lexing down to the parser
This is an intermediate state in which the lexer delegates the
responsibility for trivia lexing to the parser. Later, the parser will
delegate this responsibility to SyntaxParsingContext which will hand it
over to SyntaxParseAction, which will only lex the pieces if it is
really necessary to do so.
2021-02-05 08:15:54 +01:00
Evan Wilde
49bfcd223e Replace improper 'async' in parser
By replacing the 'async' with 'await' in the parser, we avoid the issue
of cascading errors as the compiler gets more and more confused by what
it's reading. Instead, everything mostly passes and we just emit the one
error message.

One caveat that I hadn't taken into account before was that we could
have a function called "async", in which case we don't want to replace
the "async" keyword with "await".
2021-01-26 18:20:39 -08:00
Doug Gregor
3c38ffe0ea [Concurrency] await try -> try await
The `try await` ordering is both easier to read and indicates the order
of operations better, because the suspension point occurs first and
then one can observe a thrown error.
2020-12-23 13:21:59 -08:00
Kavon Farvardin
463003194e add warning that 'await' will become contextual keyword 2020-12-22 15:46:24 -08:00
Rintaro Ishizaki
31595e3b2b [Parse] Adjust diagnostics message for duplicated effects specifiers 2020-12-14 14:58:30 -08:00
Rintaro Ishizaki
c72f9e5c92 [Parse] Adjust diagnostics for effects specifiers in closure signature 2020-12-14 12:43:50 -08:00
Rintaro Ishizaki
1c791d345d [Parse] Factor out 'isEffectsSpecifier()' 2020-12-14 12:43:50 -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
Doug Gregor
18ef1869f3 [Concurrency] Diagnose "try await" with a Fix-It 2020-12-04 00:57:18 -08:00
Anthony Latsis
47ce1529f0 Parse: Only diagnose dollar-prefixed identifiers that are Swift declarations 2020-11-19 20:30:53 +03: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
Slava Pestov
5808d9beb9 Parse: Remove parse-time name lookup 2020-11-16 22:39:44 -05: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
maustinstar
037edf3a8c [SR-11711] Refactor shared parser code for single-expression returns 2020-11-03 22:03:11 -05:00
maustinstar
3913c31688 [SR-11711] Single-expression returns for #if declarations within closures 2020-11-03 12:48:05 -05:00
Rintaro Ishizaki
1de9668e90 Merge pull request #34257 from rintaro/syntax-typeexpr-rdar70101520
[Syntax] Parse attributed types in expr position as TypeExprSyntax
2020-10-10 16:22:08 -07:00
Rintaro Ishizaki
411751218c [Syntax] Parse attributed types in expr position as TypeExprSyntax
rdar://problem/70101520
https://bugs.swift.org/browse/SR-13711
2020-10-09 17:19:36 -07:00
Nathan Hawes
a91cede79b [Parse][CodeCompletion] Don't special case code completion when forming single-expression closures/function bodies (NFC)
Code completion used to avoid forming single expression closures/function
bodies when the single expression contained the code completion expression
because a contextual type mismatch could result in types not being applied
to the AST, giving no completions.

Completions that have been migrated to the new solver-based completion
mechanism don't need this behavior, however. Rather than trying to guess
whether the type of completion we're going to end up performing is one of
the ones that haven't been migrated to the solver yet when parsing, instead
just always form single-expression closures/function bodies (like we do for
regular compilation) and undo the transformation if and when we know we're
going to perform a completion kind we haven't migrated yet.

Once all completion kinds are migrated, the undo-ing code can be removed.
2020-10-09 16:02:13 -07:00
Slava Pestov
04c21c18c9 Parse: Disable circular definition check when parser lookup is off 2020-10-02 22:12:39 -04:00
Holly Borla
355fbb3a8b Merge pull request #34109 from hborla/local-property-wrappers
[Property Wrappers] Support local property wrappers
2020-10-01 22:45:41 -07:00
Slava Pestov
025921c927 Parse: Move the lookup of 'self' for a SuperRefExpr to preCheckExpression() 2020-09-28 17:50:52 -04:00
Holly Borla
3a47087cc1 [Parser] Don't resolve decl references in the parser if the declaration
has a custom attribute.
2020-09-26 18:58:42 -07:00
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