Commit Graph

1233 Commits

Author SHA1 Message Date
Hamish Knight
3e28bbbd2c Update for review feedback
- Remove OriginalArguments in favor of storing the
pre-rewritten argument list, which simplifies things
nicely
- Adopt llvm::indexed_accessor_iterator
2021-09-01 18:40:29 +01:00
Hamish Knight
a5775482ee [Parser] Adopt ArgumentList
Split up the expr list parsing members such that
there are separate entry points for tuple and
argument list parsing, and start using the argument
list parsing member for call and subscripts.
2021-09-01 18:40:24 +01:00
jiaren wang
d8780d33e9 [Parse] give more useful errors for forget 'do' keyword. 2021-09-01 21:18:56 +08:00
Ehud Adler
a7a826a0e2 Removes dynamicType diagnostic. Fixes SR-14667 2021-08-30 10:59:16 -04:00
Hamish Knight
72d4d9f1e9 [AST] Add some 'create' factory methods
This provides consistency with other AST nodes,
and will be useful for implementing ArgumentList
construction in the future.
2021-07-28 23:14:44 +01:00
Alex Hoppen
27bec7ae7d [CodeCompletion] Fix crasher and missing completion for generic arguments to nested type
Completing a generic parameter to a nested type `Outer.Nested<#^COMPLETE^#>` crashed when used to initialize a local variable and returned no results when initializing a global variable.

This is because the generic argument parsing logic for nested types inside `parseExprPostfixSuffix` didn’t match that of global types in `parseExprIdentifier`. Make sure they do the same thing semantically.

Fixes rdar://77909679 [SR-14627]
2021-07-22 18:37:32 +02:00
Bruno Rocha
1fe3857735 [SE-0290] Add #unavailable 2021-07-02 13:35:11 +02:00
Alex Hoppen
39e92db1b1 Merge pull request #38049 from ahoppen/pr/keypath-completion
[CodeCompletion] Migrate key path completion to be solver based
2021-06-30 22:03:44 +02:00
Alex Hoppen
d64b8ecea6 [CodeCompletion] Migrate key path completion to be solver based
This commit essentially consistes of the following steps:
- Add a new code completion key path component that represents the code completion token inside a key path. Previously, the key path would have an invalid component at the end if it contained a code completion token.
- When type checking the key path, model the code completion token’s result type by a new type variable that is unrelated to the previous components (because the code completion token might resolve to anything).
- Since the code completion token is now properly modelled in the constraint system, we can use the solver based code completion implementation and inspect any solution determined by the constraint solver. The base type for code completion is now the result type of the key path component that preceeds the code completion component.

This resolves bugs where code completion was not working correctly if the key path’s type had a generic base or result type. It’s also nice to have moved another completion type over to the solver-based implementation.

Resolves rdar://78779234 [SR-14685] and rdar://78779335 [SR-14703]
2021-06-25 23:19:35 +02:00
Alex Hoppen
94a9876d39 [IDE] Show completion results if member is followed by trailing closure
When completing `items.#^COMPLETE^# { $0.content }`, we are stopping parsing of the expression after the code completion token and are thus left with `{ $0.content }` in `parseDeclVar`, which interprets the `{` as the start of an accessor clause, wrapping the entire variable in an accessor decl and thus causing code completion to not show any results.

To avoid this issue, consume any postfix expressions after the code completion token and discard them. This assures that the trailing closure gets consumed before it can be interpreted as an accessor decl.

Fixes rdar://77259087 [SR-14544]
2021-06-23 13:48:59 +02:00
Rintaro Ishizaki
fbc6da73b7 Merge pull request #37871 from rintaro/ide-completion-rdar78798718
[CodeCompletion] Don't offer completion names for closure argument names
2021-06-10 20:37:12 -07:00
Rintaro Ishizaki
4e8d98de49 [CodeCompletion] Completion inside closure capture list 2021-06-10 14:44:39 -07:00
Rintaro Ishizaki
5cf87d30f5 [CodeCompletion] Don't offer completion names for closure argument names
Parse a completion token as an empty parameter name (just like `_`) to
prevent the parser to parse it as an expression and offer completions
for it.

rdar://78798718
2021-06-10 13:45:09 -07:00
Hamish Knight
c1b1feb8e7 [AST] Clean up CaptureListEntry
Don't store a VarDecl separately, expose a `getVar`
accessor that forwards onto `getSingleVar`, and
rename `Init` to `PBD`.
2021-06-08 22:56:06 +01:00
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