Commit Graph

567 Commits

Author SHA1 Message Date
Joe Groff
833c25c7d0 Parser: Generalize : lookahead to disambiguate all parameter specifiers as argument labels 2023-02-28 09:16:45 -08:00
Joe Groff
704a4363d7 C++ parser: support borrowing and consuming modifiers.
And adjust contextual parameter modifier parsing in general to be more
properly contextual, so we don't have to reserve `__shared` or `__owned`,
or their successor spellings, as argument labels anymore.
2023-02-28 09:16:45 -08:00
Joe Groff
655e9e681d Add ParamSpecifier cases for Borrowing and Consuming.
And do a first pass of auditing existing uses of the parameter specifiers to
make sure that we look at the ValueOwnership mapping in most cases instead of
individual modifiers.
2023-02-28 09:16:44 -08:00
Joe Groff
1311df6544 AST: Combine various ownership TypeReprs into one OwnershipTypeRepr.
This lets us consolidate code paths that mostly run in parallel over the
existing InOutTypeRepr/SharedTypeRepr/OwnedTypeRepr family of types. This
patch by itself is NFC but makes it easier to introduce new spellings,
particularly the newly-official `borrowing` and `consuming` modifiers
that were approved in SE-0377.
2023-02-28 09:15:43 -08:00
Kavon Farvardin
197a97621f require an ownership specifier for noncopyable parameters
Per the current proposal, these are to be specified
explicitly, as they form an important part of the API.

Bonus: This commit includes a fix to make
`CompileTimeConstTypeRepr` a proper `isa<>` subtype of
`SpecifierTypeRepr`, since we forgot to add it to
that type's `classof` function.

resolves rdar://105480354
2023-02-16 22:08:13 -08:00
Alex Hoppen
754e9d7d54 [CodeCompletion] Fix issue when completing inside a switch in a closure 2023-02-14 09:40:56 +01:00
Holly Borla
89fa17d74c [Parser] Replace postfix ellipsis with a prefix 'repeat' keyword for pack
expansion expressions, and create them in the parser instead of during
pre-checking in the constraint system.
2023-01-07 09:49:14 -08:00
Doug Gregor
b399b92566 [Parser] Remove the notion of a "local context".
The "local context" was only used to prevent parsing of closures in a
non-local context, and also string interpolations because they are
similar-ish to closures. However, this isn't something a parser should
decide, so remove this special-case semantic check from the parser and
eliminate the notion of "local context" entirely.
2022-12-21 15:01:08 -08:00
Holly Borla
05443c442e Merge pull request #62509 from hborla/explicit-pack-reference-keyword
[Parser] Add a contextual `each` keyword for pack references.
2022-12-13 16:44:11 -08:00
Alex Hoppen
fe2ae72ad2 [IDE] Rename CodeCompletion to IDEInspection in cases where the code path no longer exclusively applies to code completion
The code completio infrastructure is also being used for cursor info now, so it should no longer be called code completion.

rdar://103251187
2022-12-13 11:41:05 +01:00
Holly Borla
29f6c0d9a9 [Parser] Parse 'each' as a contextual keyword applied to pack references. 2022-12-10 22:17:59 -08:00
Alex Hoppen
9a0a7722f9 [IDE] Disable a few code completion specific paths for solver-based CursorInfo
The lexer will be responsible for knowing whether we have a code completion token, everything else will also work for other IDE inspection features.

The changes start to really make sense once I rename CodeCompletion -> IDEInspection in a lot of places.
2022-12-10 12:12:21 +01:00
Doug Gregor
7157510e00 [Macros] Parse macro declarations. 2022-11-28 18:32:43 -08:00
Robert Widmann
530d937879 Remove SyntaxContext and Parser Affordances 2022-11-16 13:24:21 -08:00
Alex Hoppen
b50e795484 Merge pull request #61353 from ahoppen/ahoppen/fix-func-parameter-parsing
[libSyntax] Model parameter modifiers as a `ModifierList`
2022-10-03 21:40:16 +02:00
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
Anthony Latsis
2843e0c871 Gardening: Migrate compiler sources to GitHub issues 2022-09-29 23:58:55 +03: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