Commit Graph

6300 Commits

Author SHA1 Message Date
Alex Hoppen
38278e5148 [SwiftSyntax] Fix issue in generation of ParsedSyntaxBuilders
`child_elt_name` was inferred from the last iteration of the loop above, which was incorrect.
2022-07-23 09:28:03 +02:00
Doug Gregor
3e53290187 Merge pull request #60052 from DougGregor/syntax-decl-cleanup
[Syntax] Clean up syntax grammar for declaration nodes
2022-07-20 16:09:28 -07:00
Doug Gregor
2da25612ba Short-circuit validation of #if conditions after a versioned check.
When we encounter a check like `#if compiler(>=6.0) && something` or
`#if swift(<6.0) || something`, and the left-hand term is a versioning
check that determines the result of the whole condition, then we will
not attempt to validate the right-hand term. This allows us to use
versioned checks along with new discovery features (say, if we add an
`#if attribute(x)`) without having to next conditions.
2022-07-19 21:27:54 -07:00
Doug Gregor
569859ab60 Add hasFeature(X) to check for future features 2022-07-19 21:27:39 -07:00
Doug Gregor
a317fad88d Add -enable-upcoming-feature X command-line argument.
Introduce the `-enable-upcoming-feature X` command-line argument to
allow one to opt into features that will be enabled in an upcoming language
mode. Stage in several features this way (`ConciseMagicFile`,
`ForwardTrailingClosures`, `BareSlashRegexLiterals`).
2022-07-19 21:20:12 -07:00
Egor Zhdan
e9dedf3c27 [cxx-interop][SwiftCompilerSources] Use swift::DiagnosticEngine instead of BridgedDiagnosticEngine
This also removes `BridgedOptionalDiagnosticEngine`.

rdar://83361087
2022-07-14 11:06:31 +01:00
Doug Gregor
73debb48f3 [Syntax] Factor out the detail for a declaration modifier. 2022-07-13 21:49:23 -07: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
Doug Gregor
188cf5c59a [Parser] Produce the appropriate syntax node kind for actors. 2022-07-13 21:49:23 -07:00
Robert Widmann
003b362a65 Differentiate Shebang from Garbage
Add #! as an explicit kind of trivia.
2022-07-08 18:28:57 -07:00
Konrad `ktoso` Malawski
728c007fb9 [Distributed] Implement witnesses for sync or non-throw dist reqs
[Distributed] generic and inner test; without one edge case

[Distributed] fix distributed_thunk test; unsure about those extra hops, could remove later

[Distributed] Remove type pretending in getSILFunctionType; it is not needed

It seems our constant replacement in the earlier phases is enough, and
we don't need this trick at all.

[Distributed] Use thunk when calling cross-actor on DA protocols
2022-07-04 19:02:11 +09:00
Hamish Knight
8d59eb08df [Parse] Ban trailing space for /.../ regex literals
Ban space and tab as the last character of a
`/.../` regex literal, unless escaped with a
backslash. This matches the banning of space and
tab as the first character, and helps avoid breaking
source in even more cases.
2022-06-23 20:38:28 +01:00
Hamish Knight
53994d1faa [Parse] Fix code completion crash when avoiding skipping
Fix a crash that could occur when performing
completion at the start of an accessor body.
Previously we assumed `CodeCompletion` would never
be null due to function body skipping in the first
pass of code completion. However with the
introduction of the ability to avoid skipping in
certain cases, it might be now be null if we need
to avoid skipping. Found by the stress tester.

rdar://95772803
2022-06-23 15:57:05 +01:00
Hamish Knight
e610a69dac Merge pull request #59641 from hamishknight/no-skip-slash 2022-06-23 15:09:26 +01:00
Hamish Knight
515945fc6d [Parse] Avoid skipping bodies with /.../ regex literals
While skipping, if we encounter a token that looks
like it could be the start of a `/.../` regex
literal, fall back to parsing the function or type
body normally, as such a token could become a
regex literal. As such, it could treat `{` and
`}` as literal, or otherwise have contents that
would be lexically invalid Swift.

To avoid falling back in too many cases, we apply
the existing regex literal heuristics. Cases that
pass the heuristic fall back to regular parsing.
Cases that fail the heuristic are further checked
to make sure they wouldn't contain an unbalanced
`{` or `}`, but otherwise are allowed to be
skipped. This allows us to continue skipping for
most occurrences of infix and prefix `/`.

This is meant as a lower risk workaround to fix the
the issue, we ought to go back to handling regex
literals in the lexer.

Resolves rdar://95354010
2022-06-22 20:05:21 +01:00
Hamish Knight
325ba43396 [Parse] NFC: Split off tryScanRegexLiteral
This is a `const` version of `tryLexRegexLiteral`
that does not advance `CurPtr`, but attempts to
scan ahead to the end of a regex literal.
2022-06-22 20:05:21 +01:00
Hamish Knight
4f5bf99e07 [Parse] NFC: Allow sub-lexers to disable diagnostics
And `const` qualify a couple of params/methods.
2022-06-22 20:05:19 +01:00
Egor Zhdan
038a4f0b80 [cxx-interop][SwiftCompilerSources] Use swift::SourceLoc instead of BridgedSourceLoc
C++ interop is now enabled in SwiftCompilerSources, so we can remove some of the C bridging layer and use C++ classes directly from Swift.

rdar://83361087
2022-06-11 00:13:39 +01:00
Rintaro Ishizaki
e1412a0978 Merge pull request #59209 from rintaro/syntaxparser-libswift
[SwiftCompilerModules] Link lib_InternalSwiftSyntaxParser to libswift
2022-06-08 15:36:21 -07:00
Serena
e05f68c822 Change diagnostic error thrown for when string interpolations aren't closed by a parenthesis (#58882)
[Parse] Diagnose unclosed string interpolations
2022-06-04 19:32:41 +03:00
Rintaro Ishizaki
8826ef64d5 [Syntax] Remove fallback regex parsing logic
Now that libSwiftSyntaxParser links to libswift. We don't need this
anymore.
2022-06-02 12:23:03 -07:00
Doug Gregor
3cf576da23 Refactor bare slash regex literals as a future feature 2022-05-30 08:33:46 -07:00
Doug Gregor
2fbe202146 Introduce FUTURE_FEATURE definitions for features staged in Swift 6.
Using the same feature set logic as experimental features, provide
feature names for "future" features, which are changes that will
become available with Swift 6. Use the feature check when determining
whether to implementation the feature instead of a language version
check, and map existing flags for these features (when available) over
to the feature set.

As an internal implementation detail, this makes it easier to reason
about when specific features are enabled (or not). If we decide to go
with piecemeal adoption support for features, it can provide an
alternative path to enabling features that feeds this mechanism.
2022-05-30 08:32:56 -07:00
Doug Gregor
0de5d7818d Make named opaque types an experimental feature 2022-05-26 13:44:08 -07:00
Doug Gregor
a523473315 Make static assertions an experimental feature 2022-05-26 13:43:36 -07:00
Doug Gregor
6d82448dc8 Add -enable-experimental-feature X for experimental features.
Experimental features can only be enabled in non-production (+Asserts)
builds. They can be detected with `hasFeature` in the same manner as
"future" features.

The `-enable-experimental-feature X` flag will also look for future
features by that name, so that when an experimental feature becomes an
accepted future feature, it will still be enabled in the same manner.

Switch variadic generics over to this approach, eliminating the
specific LangOption for it.
2022-05-26 11:50:39 -07:00
Luciano Almeida
0eafd08603 Merge pull request #58742 from moritzdietsche/fix-it-for-repeated-any-or-some-in-composition
[lib/Parse] #58741 Do not suggest moving `any` or `some` to the beginning of a compositi…
2022-05-25 22:38:39 -03:00
Alex Hoppen
e75c56b666 [SwiftSyntax] Fix assertion failure if regex literal was not terminated at the end of the file
Fixes a SwiftSyntax parsing assertion failure if there is a regex literal at the end of the file. I.e. either a single line regex literal in a file without a trailing newline or a multi-line regex literal.

This does not crash in non-assert builds.
2022-05-25 15:36:23 +02:00
swift-ci
645d73f27e Merge pull request #58480 from beccadax/so-i-put-versions-in-your-version-numbers
Update SWIFT_COMPILER_VERSION language features
2022-05-24 17:47:43 -07:00
Moritz Dietsche
29ec7d4e33 Merge branch 'apple:main' into fix-it-for-repeated-any-or-some-in-composition 2022-05-22 07:39:33 +02:00
Alex Hoppen
1d750f965c [SwiftSyntax] Parse regex literals using a fallback lexer implemented in C++
`libInternalSwiftSyntaxParser.dylib` currently doesn’t link against `SwiftExperimentalStringProcessing`, so it can’t use the regex lexing functions defined within. This caused SwiftSyntax to fail if the source code contained regex literals.

Implement a fallback regex lexing function in C++ and use it for SwiftSyntax parsing.

rdar://93580240

Co-authored-by: Rintaro Ishizaki <rishizaki@apple.com>
2022-05-20 19:47:11 +02:00
Holly Borla
896dddc702 Merge pull request #58950 from hborla/parse-any-associated-value
[Parser] Allow parsing `any` in structural position within enum associated value types.
2022-05-17 20:49:47 -07:00
Holly Borla
7a65b6bbb4 [Parser] Allow parsing 'any' in structural position within enum associated
value types.

This change simply calls into Parser::startsParameterName, which already
supports parsing 'any' and 'some', instead of repeating the code without
checking for contextual keywords.
2022-05-17 14:42:25 -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
Alex Hoppen
795be6c2bb Merge pull request #58734 from ahoppen/pr/fix-completion-in-property-attribute
[CodeCompletion] Support type checking attributes even if they are not part of the AST
2022-05-13 09:39:00 +02:00
Hamish Knight
4ee6a84383 Merge pull request #58835 from hamishknight/allow-prefix-slash 2022-05-12 17:56:32 +01:00
Hamish Knight
350a01aeb0 [Parse] Expand unbalanced ) regex literal heuristic
Previously we would only check for a starting
character of `)` when performing a tentative
lex of a regex literal. Expand this to cover the
entire range of the regex literal, ensuring to
take escapes and custom character classes into
account.
2022-05-12 11:49:11 +01:00
Hamish Knight
9c62319be1 [Parse] Lenient prefix / parsing
Treat a prefix operator containing `/` the same as
the unapplied infix operator case, where we
tentatively lex. This means that we bail if there
is no closing `/` or the starting character is
invalid. This leaves binary operator containing
`/` in expression position as the last place where
we know that we definitely have a regex literal.
2022-05-12 11:49:10 +01:00
Hamish Knight
105ab3149a [Parse] Re-allow prefix operators containing / 2022-05-12 11:49:09 +01:00
Hamish Knight
22548aad9d Merge pull request #58823 from hamishknight/irregular-grammar 2022-05-11 19:05:02 +01:00
Anton Korobeynikov
a1e138b2af [AutoDiff] Implement cross-file lookup of derivatives (#58644)
Look-up for functions with @derivative attributes defined in non-primary source files

Fixes #55170
2022-05-11 08:18:51 -07:00
Hamish Knight
e234f80f14 Track regex literal source locations in SourceManager
This is unfortunately needed to ensure we correctly
re-lex regex literal tokens correctly, which is
needed for diagnostic logic to correctly compute
source ranges.

rdar://92469692
2022-05-11 10:45:39 +01:00
mdietsche@icloud.com
8ce878f7e3 Do not suggest moving any or some to the beginning of a composition if the first type is already an existential or opaque type. 2022-05-08 01:53:37 +02:00
Alex Hoppen
9dbd5829de [CodeCompletion] Support type checking attributes even if they are not part of the AST
The code completion might occur inside an attriubte that isn’t part of the AST because it’s missing a `VarDecl` that it could be attached to. In these cases, record the `CustomAttr` and type check it standalone, pretending it was part of a `DeclContext`.

This also fixes a few issues where code completion previously wouldn’t find the attribute constructor call and thus wasn’t providing code completion inside the property wrapper.

rdar://92842803
2022-05-07 08:58:52 +02:00
Hamish Knight
fb0ba6ab00 Merge pull request #58505 from hamishknight/regulation-grammar 2022-05-05 15:34:53 +01:00
Alex Hoppen
33ee653d7e Merge pull request #58614 from ahoppen/pr/complete-type-with-same-type-requirement
[CodeCompletion] Offer suggestions if a nested type is followed by a same type requirement
2022-05-04 08:51:11 +02: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
Alex Hoppen
17fc634bf6 [Syntax] Classify contextual keywords used as decl attribute as contextual keyword
Previously, we classified e.g. final as an identifier, but it should be qualified as a contextual keyword.

rdar://92463926 [apple/swift-syntax#387]
2022-05-02 17:36:55 +02:00
Hamish Knight
ba28b6a19b [Parse] Split prefix operators from regex in the lexer
Teach the lexer not to consider `/` an operator
character when attempting to re-lex a regex
literal. This allows us to split off a prefix
operator.

Previously this was done after-the-fact in the
parser, but that didn't cover the unapplied infix
operator case, and didn't form a `tok::amp_prefix`
for `foo(&/.../)`, which led to a suboptimal
diagnostic.

This also now means we'll split an operator for
cases such as `foo(!/^/)` rather than treating it
as an unapplied infix operator.

rdar://92469917
2022-04-29 10:53:56 +01:00
Hamish Knight
1a86c1e0e3 [Parse] Remove redundant check
We already check this in `Parser::tryLexRegexLiteral`,
and the failure case doesn't make sense here as
we call `discardToken` afterwards.
2022-04-29 10:53:56 +01:00