Commit Graph

1224 Commits

Author SHA1 Message Date
swift-ci
3be14e0a4a Merge pull request #64622 from kavon/bifurcate-moveonly-featureflag
Fix minimal stdlib builds with noncopyable types
2023-03-28 14:44:24 -07:00
Kavon Farvardin
6f98e9a2c6 trifurcate the MoveOnly feature
I want to reserve Feature::MoveOnly only for move-only types and other
things that are part of SE-390. Other prototyped features like
noimplicitcopy and some older names for consume were left behind
as guarded by this Feature. That's really not the right way to do it,
as people will expect that the feature is enabled all the time, which
would put those unofficial features into on-by-default. So this change
introduces two new Features to guard those unofficial features.
2023-03-24 15:43:35 -07:00
Alex Hoppen
d5a90174f0 [Macros] Disallow self and Self as macro names
We were allowing `self` and `Self` as freestanding macro names, which we don’t want.
2023-03-24 09:32:51 -07:00
Alex Hoppen
35871c2af7 [CodeCompletion] Fix assertion failure if completing in a macro call argument
rdar://106966610
2023-03-21 13:41:45 -07:00
Saleem Abdulrasool
b52fdb9d4b Apply suggestions from MSVC workaround 2023-03-18 14:11:31 -07:00
Saleem Abdulrasool
9acb1e1310 Apply suggestions for VS2019 workaround
The MSVC 2019 14.29 toolset seems to not properly handle the member variable reference in this case.  Workaround this by explicitly using the `this` identifier to indicate that we would like to access the member variable.  This is repaired in newer toolsets, however, the CI is currently using the older toolset.
2023-03-18 08:09:43 -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
Richard Wei
833338f9ce [Macros] Top-level freestanding macros (#63553)
Allow freestanding macros to be used at top-level.
- Parse top-level `#…` as `MacroExpansionDecl` when we are not in scripting mode.
- Add macro expansion decls to the source lookup cache with name-driven lazy expansion. Not supporting arbitrary name yet.
- Experimental support for script mode and brace-level declaration macro expansions: When type-checking a `MacroExpansionExpr`, assign it a substitute `MacroExpansionDecl` if the macro reference resolves to a declaration macro. This doesn’t work quite fully yet and will be enabled in a future fix.
2023-03-06 07:15:20 -08:00
Michael Gottesman
25d5fff50b [reference-bindings] Put inout parsing behind a flag harder.
In my earlier commit that attempted to do this I wasn't aggressive enough. In
this commit, I was more aggressive in putting it behind a flag and as a result
we reject all of the patterns in the tests I added into tree.
2023-03-05 13:22:18 -08:00
Michael Gottesman
7c58752a6f Merge pull request #64012 from gottesmm/reference-bindings-part-1
[reference-binding] Parser support for inout bindings
2023-03-02 15:16:25 -08:00
Michael Gottesman
c97121d3ee [reference-binding] Add support for inout binding parsing/serialization. 2023-03-01 20:48:54 -08:00
Michael Gottesman
4b354f6132 [reference-binding] Make InBindingState into a true type called PatternBindingState.
This cleans up the parser code a little bit around here and will make it easier
for me to add inout.
2023-03-01 20:48:33 -08:00
Joe Groff
ecceb02e2a Implement consume x operator with the accepted SE-0366 syntax.
Implement it as a contextual operator that only parses as an operator when
followed by an identifier.
2023-03-01 17:37:54 -08:00
Alex Hoppen
8bdf68d483 [IDE] Check whether an AST node contains the IDE inspection point based on CharSourceRange
This fixes an issue if the range ends with a string literal that contains the IDE inspection target. In that case the end of the range will point to the start of the string literal but the IDE inspection target is inside the string literal and thus after the range’s end.
2023-02-20 15:37:38 +01:00
Alex Hoppen
754e9d7d54 [CodeCompletion] Fix issue when completing inside a switch in a closure 2023-02-14 09:40:56 +01:00
Hamish Knight
c87b1b8bef Merge pull request #63022 from hamishknight/express-yourself 2023-02-03 16:40:09 +00:00
Martin Svensson
9f6dc70d58 [Parser] Handle REPL raw multi-line string literal input
Extend handling of incomplete multi-line string literals during input in
REPL to also cover raw multi-line strings.

Fixes #52840 and apple/llvm-project#4628
2023-02-02 13:23:28 +09:00
Holly Borla
e41cdfbdd4 Merge pull request #63341 from hborla/generalize-macro-expansion-expr
[Macros] Generalize `MacroExpansionExpr` and use it for both freestanding and attached macros.
2023-02-01 11:04:39 -08:00
Hamish Knight
a40f1abaff Introduce if/switch expressions
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.

For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.

The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
2023-02-01 15:30:18 +00:00
Anthony Latsis
3302b27df8 Merge pull request #62775 from AnthonyLatsis/sugar-type-members-2
Parser: Support member types with non-identifier qualifiers
2023-02-01 02:07:12 +03:00
Holly Borla
7c50f95e1b [Macros] Use MacroExpansionExpr when resolving attached and freestanding macros. 2023-01-31 09:27:06 -08:00
Anthony Latsis
c46b7c1bd0 Parser: Parse member types with non-identifier qualifiers in type context 2023-01-26 20:49:33 +03:00
Doug Gregor
6e3289d4d5 [Macros] Compute discriminators for freestanding macro expansions.
Introduce discriminators into freestanding macro expansion expressions
and declarations. Compute these discriminators alongside closure and
local-declaration discriminators, checking them in the AST verifier.
2023-01-25 22:03:38 -08:00
Holly Borla
287b54fbd0 [Parser] Gate 'repeat' parsing for variadic generics behind the experimental
feature flag to preserve existing parser diagnostics until the feature is
official.
2023-01-07 09:50:14 -08:00
Holly Borla
74bf2f3e7a [AST] Introduce a syntactic distinction betweek vararg type reprs and
pack expansion type reprs.

Classic variadic parameters still use the postfix ellipsis syntax, and
pack expansion types now use a prefix 'repeat' keyword.
2023-01-07 09:50:11 -08: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
Michael Gottesman
b95fe48a90 Merge pull request #62742 from gottesmm/pr-947919228bebf49e02eae5aedb1efee8038c2b4b
[borrow-expr] Add simple support for borrow-expr and wire it up to SILGenApply
2023-01-03 08:04:33 -08:00
Doug Gregor
6bb9cb8b5d [Macros] Always parse macro expansions, diagnose later
Always parse macro expansions, regardless of language mode, and
eliminate the fallback path for very, very, very old object literals
like `#Color`. Instead, check for the feature flag for macro
declaration and at macro expansion time, since this is a semantic
restriction.

While here, refactor things so the vast majority of the macro-handling
logic still applies even if the Swift Swift parser is disabled. Only
attempts to expand the macro will fail. This allows us to enable the
macro-diagnostics test everywhere.
2023-01-02 21:22:04 -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
Doug Gregor
b9aee05676 (Mostly) get rid of Parser::setLocalDiscriminator.
The parser no longer sets local discriminators, and this function is
currently only responsible for adding local type declarations to the
source file. Rename it and remove most of the former callers so it
does just that.
2022-12-21 15:01:08 -08:00
Michael Gottesman
947919228b [borrow-expr] Add simple support for borrow-expr but don't wire it up to anything. 2022-12-21 14:36:43 -08:00
Doug Gregor
402ba1492f Set closure descriminators via a request.
Rather than set closure discriminators in both the parser (for explicit
closures) and then later as part of contextualizing closures (for
autoclosures), do so via a request that sets all of the discriminators
for a given context.
2022-12-19 15:23:45 -08:00
Holly Borla
c4461778b3 [Parser] Parse contextual 'each' in expressions as PackElementExpr. 2022-12-14 20:45:52 -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
Alex Hoppen
d9382b1bdb Merge pull request #62362 from ahoppen/ahoppen/completion-like-cursor-info
[IDE] Implement completion-like cursor info for ValueDecls
2022-12-12 12:40:40 +01:00
Doug Gregor
41e012542c Remove __FILE__ et al as keywords.
These were keywords prior to Swift 2, and have only been kept around as
keywords to provide a custom error message to rewrite to `#file` et
al. It's incorrect to keep them as keywords, and that error should be
implemented differently if we care about it.
2022-12-11 08:30:05 -08:00
Doug Gregor
9d24f447b7 Remove special handling of __FILE__, __LINE__, etc.
These were replaced by `#file`, `#line`, etc. with SE-0028, prior to
Swift 3. We don't need this custom error message any more, and they
shouldn't be keywords. Stop treating them as keywords in the lexer.
2022-12-10 15:38:09 -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
Slava Pestov
f7cb4e1a24 Parse: Allow empty generic argument lists and generic argument lists containing ... in expression context 2022-12-06 14:15:07 -05:00
Doug Gregor
af6b30a195 [Code completion] Add code completion support for macro expansions. 2022-11-28 18:33:10 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Doug Gregor
787af41765 [Macros] Parse generic arguments in macro expansions. 2022-11-17 16:46:43 -08:00
Robert Widmann
4c162b2aeb Delete libSyntax 2022-11-16 14:52:28 -08:00
Robert Widmann
530d937879 Remove SyntaxContext and Parser Affordances 2022-11-16 13:24:21 -08:00
Doug Gregor
d6d2318dc9 [Macros] Handle macro expansion for function-like macros. 2022-10-27 17:15:30 -07:00
Richard Wei
56e7cce809 [Macros] Parse MacroExpansionExpr and MacroExpansionDecl
Introduce `MacroExpansionExpr` and `MacroExpansionDecl` and plumb it through. Parse them in roughly the same way we parse `ObjectLiteralExpr`.

The syntax is gated under `-enable-experimental-feature Macros`.
2022-10-21 01:50:35 -07:00
swift-ci
754c0ceab1 Merge pull request #61480 from atrick/fix-move-keyword
Disable '_move' contextual keyword absent -enable-experimental-move-only
2022-10-07 11:18:07 -07:00
Alex Hoppen
e006c24e82 [libSyntax] Adjustments because nodes can have unexpected nodes at the end 2022-10-07 14:22:16 +02:00
Andrew Trick
19175926da Disable '_move' contextual keyword absent -enable-experimental-move-only
Fixes rdar://100872195 ( error: 'move' can only be applied to lvalues
  error: Can not use feature when experimental move only is disabled!)

Identifiers with a single underscore are not reserved for use by the
language implementation. It is perfectly valid for a library to define
its own '_move'.

The contextual _move keyword should only be parse when it is followed by an lvalue, so should *not* conflict with user-defined '_move' functions.
https://github.com/apple/swift-evolution/blob/main/proposals/0366-move-function.md#source-compatibility
2022-10-06 16:33:26 -07:00