Commit Graph

501 Commits

Author SHA1 Message Date
Alex Hoppen
14d0f41ca7 [libSyntax] Model parameter modifiers as a ModifierList
This fixes a libSyntax misparse where the first parameter name was parsed as the `isolated` token.
2022-09-30 14:05:15 +02:00
Suyash Srijan
fd8d7afc5b [Parse] Fix variable identifier parsing including code on newline as part of the identifier (#61036) 2022-09-12 23:05:20 +01:00
Slava Pestov
79ed990728 AST: Replace TupleTypeRepr's ellipsis with PackExpansionTypeRepr 2022-09-07 12:35:54 -04:00
Doug Gregor
d7ea96badb Parse a general function-signature for an initializer.
This helps unify the parse trees with function declarations.
2022-07-13 21:49:23 -07:00
Ben Barham
862f3fc420 [Parse] Set missing contextual keyword token kind for async
Resolves rdar://93080331.
2022-05-13 18:42:09 -07:00
Josh Soref
4721852fcb Spelling parse (#42469)
* spelling: appear

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: availability

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: available

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: coerce

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: collection

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: condition

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conditional

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: delimiter

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: derived

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: diagnostics

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: disambiguation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: dropped

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: escaped

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: existence

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: expression

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: expressions

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: extended

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: furthermore

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: identifier

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: indentation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: inspect

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: miscellaneous

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: multiline

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: offset

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: passthrough

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: precede

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: prefix

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: receiver

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: reference

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: registered

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: representing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: returned

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: sequence

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: should

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: successfully

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: that

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: trivia

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unsupported

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: whitespace

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 09:31:40 -07:00
Luciano Almeida
90c5dfa9ed [Parse] Track whether an let _: pattern is an async let pattern 2022-04-17 14:06:39 -03:00
Evan Wilde
69cb29e758 Fix await in effect with async
Typing `func foo() await {` is something that folks do from time-to-time.
The old error message was unintuitive and suggested adding a semicolon
between the parenthesis and the await, then proceeded to complain about
the opening brace. This wasn't very clear about what the error actually
was.

Pulling this in line with `try`, `throw`, and `throws`, this patch
suggests replacing `await` with `async` when in the function effect
position, and provides a nice fix-it.
2022-03-05 15:53:17 -08:00
Holly Borla
9e3c0e6370 [Parse] Parse 'any' as a contextual keyword. 2021-12-09 23:15:02 -08:00
Xi Ge
06e63896cd ModuleInterface: consume _const keyword at var and parameter decls and keep them in textual/binary modules
This is to ensure users can start adding these annotations. Type checker supports will come in later commits.

Related to pitch: https://forums.swift.org/t/pitch-compile-time-constant-values/53606

rdar://85268028
2021-11-19 22:13:23 -08:00
Alex Hoppen
b888dc0e40 [Parser] Don't modify the current token kind when cutting off parsing
Previously, when we reached the maximum nesting level, we changed the current token’s kind to an EOF token. A lot of places in the parser are not set up to expect this token change. The intended workaround was to check whether pushing a structure marker failed (which would change the token kind) and bail out parsing if this happened. This was fragile and caused assertion failures in assert builds.

Instead of changing the current token’s kind, and failing to push the structure marker, let the lexer know that it should cut off lexing, essentially making the input buffer stop at the current position. The parser will continue to consume its current token (`Parser.Tok`) and the next token that’s already lexed in the lexer (`Lexer.NextToken`) before reaching the emulated EOF token. Thus two more tokens are parsed than before, but that shouldn’t make much of a difference.
2021-11-09 12:28:10 +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
Frederick Kellison-Linn
c305cb01a8 [Sema] Re-enable placeholder type parsing and folding 2021-08-19 14:53:21 -04:00
willtunnels
319b3e64aa Add support for opaque result types in structural positions (#38392)
* [TypeResolver][TypeChecker] Add support for structural opaque result types

* [TypeResolver][TypeChecker] Clean up changes that add structural opaque result types
2021-08-03 23:45:02 -04:00
Alex Hoppen
fec7f6c3c0 [CodeCompletion] Fix issue causing the completion status to not be set correctly for pattern completion
We weren’t setting the code completion token status correctly when parsing patterns with code completion tokens.

Because of this, in the added test case, the `searchSubject` gets added as a member of `Foo` twice - once in the first pass and once in the second pass, causing an assertion failure.

Fixes rdar://80575116 [SR-14687]
2021-07-26 20:50:10 +02:00
Kavon Farvardin
5ffe8e0878 fix parsing of isolated as an argument label
With the introduction of `isolated` as
a type modifier for actor types, the
parsing of a parameter regressed such
that `isolated` was no longer accepted
as an ordinary argument label. This patch
fixes that and adds a little lookahead
utility to clean-up the code that
disambiguates the uses of `isolated`
as either a label or a type modifier.

Resolves rdar://80300022
2021-07-15 17:49:33 -07:00
willtunnels
214f480024 Merge pull request #38041 from willtunnels/general-opaque-return-types
[Frontend][Parse] Parse new named opaque return type syntax
2021-06-24 23:01:45 -04:00
Benjamin Driscoll
deb0457032 [Parse] Allow named opaque types in more places
- Allow named opaque types in typed patterns and subscripts
- Fix inheritance clause printing for `GenericParamList`
- clang-format changes from previous commit on this branch
2021-06-24 11:08:15 -04:00
Benjamin Driscoll
dddf0eceb0 [IDE][Parse] Address CR for new named opaque return type syntax 2021-06-23 21:36:05 -04:00
Benjamin Driscoll
d2de21a084 [Frontend][Parse] Parse new named opaque return type syntax
In order to put constraints on opaque types in function returns, we want to
support naming them like 'func f() -> <T> T { }'. This commit parses that
syntax into the new `OpaqueReturnParameteriedTypeRepr`. This is hidden behind
the new flag --enable-experimental-opaque-return-types.
2021-06-22 20:04:55 -04:00
Doug Gregor
c73732769d [Parser] Allow closures with custom attributes and capture lists.
The parsing of Swift 1.0 beta-1 array syntax (e.g., `Int [something]`)
was preventing closures with both a custom attribute (e.g.,
`@MainActor) and a capture list from parsing correctly. Don't parse
that syntax within custom attributes.

Fixes rdar://77303587.
2021-06-18 22:15:40 -07:00
Doug Gregor
4afa371094 Introduce subtyping rule for functions with "isolated" parameters.
With isolated parameters being part of a function's type, check to
ensure that isolated and non-isolated parameters aren't incorrectly
matched. Specifically, it is okay to add `isolated` to a parameter
when there is a subtyping relationship, but not remove it:

```swift
actor A { }
func f(_: isolated A) { }
func g(_: A) { }

func test() {
  let _: (isolated A) -> Void = g    // okay to add 'isolated'
  let _: (A) -> Void = f             // error when removing 'isolated'
}
```
2021-06-07 23:59:39 -07:00
Doug Gregor
5004a5447b [Concurrency] Make "self" parameter of actor-isolated functions 'isolated'.
The notion of "actor-isolated" currently exists at the declaration level.
For functions, it is going to be captured in the function type itself,
where 'self' is declared to be 'isolated'. Model isolation both
ways: the 'self' of a method that is isolated to an actor instance
will be 'isolated' as well.

We are still using declaration-based checking of actor isolation.
However, by mirroring this information we can move more incrementally
over to doing checking based on 'isolated' parameters.
2021-06-07 23:59:38 -07:00
Doug Gregor
bd8626fa1b [Concurrency] Parse and add 'isolated' parameters to the type system. 2021-06-07 23:59:38 -07:00
Slava Pestov
c9f550c60f Parse: Parse an explicit 'nil' default argument as DefaultArgumentKind::NilLiteral
We support a special DefaultArgumentKind::NilLiteral, but it was only
used for synthesized and imported default arguments as well.

Let's also use it for parsed default arguments that are exactly 'nil',
so that rethrows checking can special-case them.
2021-04-02 23:56:59 -04:00
Alex Hoppen
695c725f1e [CodeComplete] Return true from canParseType if type contains code completion token
From my point of view, a type that contains a code completion token can still be parsed as a type and as such, `canParseType` should return `true` for e.g. `#^COMPLETE^#` or `SomeType.#^COMPLETE^#`.

Changing this fixes an issue that caused no type completions to be shown inside a enum case decl.

Fixes rdar://71984715
2021-03-23 15:02:26 +01: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
Alex Hoppen
efb91f70a1 [libSyntax] Handle deferred node data in SyntaxParseActions
By now ParsedRawSyntaxNode does not have any knowledge about deferred
node data anymore, which frees up SyntaxParseActions (and, in
particular its sublass SyntaxTreeCreator) to perform optimisations to
more efficiently create and record deferred nodes.
2021-03-09 14:26:08 +01:00
Slava Pestov
ddc975bf5f Parse: Only parse 'reasync' if -enable-experimental-concurrency is on 2021-03-02 00:49:34 -05:00
Holly Borla
140cbaa744 [Parser] Allow $ prefixes on argument labels and closure parameter
declarations.
2021-02-25 18:35:14 -08:00
Slava Pestov
6c69d17e0c Parse: Implement parsing for 'reasync' attribute
Part of <rdar://problem/71098795>.
2021-02-15 22:18:54 -05: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
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
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