150 Commits

Author SHA1 Message Date
Arnold Schwaighofer
13ff5abdb8 Introduce @specialized attribute
Implements SE-0460 -- the non-underscored version of @specialized.

It allows to specify "internal" (not abi affecting) specializations.

rdar://150033316
2025-05-23 13:12:47 -07:00
Becca Royal-Gordon
c9f539e146 [NFC] Extract autodiff parsing code to Decl.cpp
The `@differentiable` and `@derivative` attributes need a parent pointer. Move the code to populate it from Parser to AST so it can be more easily shared between the parsers.

Done in preparation for similar code to be added for `@abi`.
2024-12-19 15:47:07 -08:00
Alejandro Alonso
90ce2cd361 Restrict parsing integer types in certain contexts 2024-11-06 13:55:01 -08:00
Alejandro Alonso
71fee06c9a Requestify GTPD::getValueType 2024-09-04 15:13:46 -07:00
Alejandro Alonso
f4f60f4344 Remove Value requirement Add GenericTypeParamKind 2024-09-04 15:13:43 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Mateus Rodrigues
b1ba769754 Minor changes for better clarity 2024-07-25 15:30:37 -03:00
Mateus Rodrigues
e0d416cdab Ungate accepted parts of SE439 2024-07-22 09:55:16 -03:00
Xiaodi Wu
e1f537107f Merge branch 'main' into trailing-comma 2024-06-29 16:36:06 -04:00
Mateus Rodrigues
013997dae7 Implement trailing comma for comma-separated lists 2024-06-18 14:01:38 -03:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Alex Hoppen
1650052150 [CodeCompletion] Fix missing completions in type member access of right-hand side in generic where clause
Fixes the issue in https://github.com/apple/swift/pull/61064#discussion_r1493108941
2024-02-20 14:39:48 -08:00
Kavon Farvardin
b55c4f1fc9 [nfc] allow ErrorTypeRepr to store a ZeroArgDiagnostic
There are sometimes parsing stuations where we don't want to
emit a parsing error, because of feature guarding. For
example, if a Feature involves new syntax for a type, we
must be able to parse both the true and false sides of an
ifdef guarding that new syntax based on a Feature flag.
2023-11-13 15:49:46 -08:00
Kavon Farvardin
2cbe4380e5 handle parsing ~ before a type in more places
It's still an error in most places, but now we don't
give as bizzare of an error message.

rdar://110421020
2023-06-26 16:23:57 -07:00
Holly Borla
0ed4b3325f [SE-0393] Enable parameter packs for generic functions.
The VariadicGenerics flag still exists and is required for generic types
with parameter packs
2023-04-15 15:40:05 -07:00
Holly Borla
234b5dc660 [SE-0393] Require the repeat keyword for generic requirement expansions. 2023-04-12 22:04:01 -07:00
Alex Hoppen
024e2c93af [Parse] Add curly braces
Maybe this makes VSCode happy and resolves a Windows-only compilation failure `error C2059: syntax error: ')'`
2023-03-17 13:40:56 -07:00
Alex Hoppen
8a2cd86deb Split IDEInspectionCallbacks into CodeCompletionCallbacks and DoneParsingCallback
Cursor info only cares about the `doneParsing` callback and not about all the `complete` functions that are now defined in `CodeCompletionCallbacks`. To make the design clearer, split `IDEInspectionCallbacks`.

rdar://105120332
2023-03-17 10:31:13 -07:00
Sophia Poirier
cdde853663 [Variadic Generics] fix diagnostics dangling reference and fixits for parameter pack syntax change: T... -> each T 2023-03-04 10:01:16 -08:00
Sophia Poirier
70cffb06f3 [Variadic Generics] type parameter pack syntax change: T... -> each T 2023-03-02 14:42:28 -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
Robert Widmann
530d937879 Remove SyntaxContext and Parser Affordances 2022-11-16 13:24:21 -08:00
Hamish Knight
6aa44a1754 [AST] Remove @_typeSequence attribute
This is no longer needed now that we have the
ellipsis spelling.
2022-10-14 15:40:13 +01:00
Hamish Knight
48ea933804 Parse an ellipsis T... for type parameter packs
In a generic parameter list, parse an ellipsis
to produce a type parameter pack. This replaces
the previous `@_typeSequence` attribute.
2022-10-14 15:40:12 +01:00
Hamish Knight
b645e63ce5 [AST] NFC: Refactor GenericTypeParamDecl construction
Add distinct overloads for the parser,
deserialization and code synthesis.
2022-10-14 15:40:12 +01:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Robert Widmann
8fbe69f698 Add Layout Requirements To AST
Layout Requirements aren't a fully-exposed part of the language, but
we do need some representation for them.
2022-08-01 17:11:07 -07:00
Alex Hoppen
a35f1856c0 [CodeCompletion] Offer suggestions if a nested type is followed by an equal type requirement
If the first type has a code completion token, don't record a same type constraint because otherwise if we have
```swift
  K.#^COMPLETE^# == Foo
```
we parse this as
```
  K == Foo
```
and thus simplify `K` to `Foo`. But we didn't want to state that `K` is `Foo` but that `K` has a member of type `Foo`.

rdar://77458518
2022-05-03 09:36:51 +02:00
Slava Pestov
2b766c278a Parse: Remove unnecessary blank lines 2022-04-01 13:54:42 -04:00
Doug Gregor
0416ec708b Augment GenericTypeParamDecl with bits indicating they came from opaque types 2022-01-26 14:47:11 -08:00
Alex Hoppen
60c78afb13 Merge pull request #40065 from ahoppen/pr/lexing-cutoff
[Parser] Don't modify the current token kind when cutting off parsing
2021-11-09 18:33:19 +01: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
Robert Widmann
22405cefea Plumb the "Is Type Sequence" Bit Through the Surface AST 2021-11-08 13:48:30 -08:00
Doug Gregor
06bbc70b3e Module printing and serialization support for @unchecked Sendable 2021-07-11 12:29:54 -07:00
Anthony Latsis
47ce1529f0 Parse: Only diagnose dollar-prefixed identifiers that are Swift declarations 2020-11-19 20:30:53 +03:00
Slava Pestov
5808d9beb9 Parse: Remove parse-time name lookup 2020-11-16 22:39:44 -05:00
Slava Pestov
0a9a6405ab Parse: Create a trailing where clause even if it was incomplete
Also, store the end location of the where clause explicitly, so that
we can recover it even if there are no requirements.

This fixes one of the failing tests when parser lookup is disabled in
swift-ide-test by ensuring that the source range of the function
extends to the end of the 'where' clause, even though the 'where'
clause has a code completion token in it.
2020-11-16 16:52:50 -05:00
Slava Pestov
445d747622 AST: Move GenericParamList and friends to GenericParamList.{h,cpp} 2020-09-29 19:51:03 -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
Slava Pestov
c46eb22fcd AST: Don't attach trailing where clause requirements to the GenericParamList
Previously we had two representations for the 'where' clause of a
parsed declaration; if the declaration had generic parameters of
its own, we would store them in the GenericParamList, otherwise
we would store them separately in a TrailingWhereClause instance.

Since the latter is more general and also used for protocols and
extensions, let's just use it for everything and simplify
GenericParamList in the process.
2020-07-28 02:07:16 -04: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
Anthony Latsis
d688710fb3 [Diag] Move invalid where clause on top-level decl diagnostic to Sema 2020-03-15 13:38:49 +03:00
fischertony
6f08216936 Sema: Support where clauses on contextually generic decls 2020-03-05 04:37:12 +03:00
fischertony
eb539e62f8 Parse: Diagnose where clauses early on non-generic top-level declarations 2020-03-04 15:04:28 +03:00
Rintaro Ishizaki
ea6886114a [CodeCompletion] Generalize generic requirement completion
Align completion logics for all 'where' clauses.
2020-02-26 09:57:18 -08:00
ninjiacoder
06424ee6e5 [Diagnostics] Resolve SR-11677: Offer a better diagnostic when && is used in trailing where clause declaration 2019-11-03 23:50:09 +08:00
Rintaro Ishizaki
60341baf62 [SyntaxParse] Refactor generic requirement syntax structure
Re-apply a part of 0569cbfb28 after
reverting ASTGen changes. This is still an improvement.
2019-10-21 15:16:56 -07:00
Rintaro Ishizaki
8768832f24 Revert "Merge pull request #27281 from rintaro/reapply-syntaxparse-genericparam"
This reverts commit 5d3e8d6c83, reversing
changes made to 27e881d97e.
2019-10-14 12:46:31 -07:00
Rintaro Ishizaki
402e791422 Revert "Merge pull request #27377 from rintaro/syntaxparse-rdar55711699"
This reverts commit 6a0bc459fc, reversing
changes made to 6aadbc3d52.
2019-10-14 12:20:21 -07:00
Rintaro Ishizaki
fbc7c6c1c5 Revert "Merge pull request #27416 from rintaro/syntaxparse-declassociatedtype"
This reverts commit 5726179da9, reversing
changes made to d5adbe2c55.
2019-10-14 12:19:53 -07:00