Commit Graph

6321 Commits

Author SHA1 Message Date
Rintaro Ishizaki
ed34dfc637 [Syntax] Introduce UnresolvedIsExpr/UnresolvedAsExpr
SequenceExprSyntax should have odd number elements. Previously 'a as b'
was parsed like:
```
(sequence_expr
  (identifier_expr "a"),
  (as_expr
    'as'
    (typeidentifier "b")))
```
So it had even number elements. Now it's parsed
```
(sequence_expr
  (identifier_expr "a"),
  (unresolved_as_expr 'as')
  (type_expr
    (typeidentifier "b")))
```
2022-08-23 13:03:18 -07:00
Slava Pestov
7a335d6c66 AST: Introduce @tuple (T) syntax for one-element tuples in SIL mode 2022-08-23 11:12:00 -04:00
Doug Gregor
bde58e7d58 Merge pull request #60208 from DougGregor/has-attribute 2022-08-18 17:55:16 -07:00
Rintaro Ishizaki
1eed8675f7 [Parse] Parser update for UnresolvedTernaryExprSyntax 2022-08-18 10:37:18 -07:00
Rintaro Ishizaki
a673043737 Terminology change: 'garbage' -> 'unexpected'
There are no "garbage" characters in Swift code. They are just
"unexpected."
2022-08-15 14:32:28 -07:00
Michael Gottesman
c10c0f6285 [move-function] Add a new context sensitive move expr.
It doesn't do anything yet.
2022-08-08 12:50:41 -07:00
Slava Pestov
d222ac5f6e Sema: New syntax for @opened archetypes in textual SIL
The old syntax was

    @opened("UUID") constraintType

Where constraintType was the right hand side of a conformance requirement.

This would always create an archetype where the interface type was `Self`,
so it couldn't cope with member types of opened existential types.

Member types of opened existential types is now a thing with SE-0309, so
this lack of support prevented writing SIL test cases using this feature.

The new syntax is

    @opened("UUID", constraintType) interfaceType

The interfaceType is a type parameter rooted in an implicit `Self`
generic parameter, which is understood to be the underlying type of the
existential.

Fixes rdar://problem/93771238.
2022-08-07 19:03:46 -04:00
Robert Widmann
845a4e4541 Formalize Labeled Syntax
This represents labeled statements as an explicit kind of statement and removes the Labeled trait. Any kind of statement is allowed to be labeled in the tree, but we specifically diagnose the syntax elements that aren't allowed to have labels. This homogenizes the way clients deal with statement labels and also makes parser recovery quite a bit easier in the case where we have a label but no actual statement following it.
2022-08-05 15:01:02 -07:00
Alex Hoppen
c2695f0ffc [libSyntax] Allow adding garbage nodes in between any two children of a syntax node
When the source code is invalid, this allows us to represent tokens that could not be used to form a valid syntax tree with more fidelity.

This commit does not start using GarbageNodes yet, it just sets everything up for them.
2022-08-04 09:20:31 +02:00
Allan Shortlidge
f8581f2612 Merge pull request #60366 from tshortli/can-import-version-more-than-two-components
Parse: Fix parsing of `canImport()` version arguments with more than two components
2022-08-03 12:17:17 -07:00
Allan Shortlidge
3a5fe80b48 Parse: Fix parsing of canImport() version arguments with more than two components.
Resolves: rdar://97990159
2022-08-02 15:54:40 -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
Doug Gregor
3f8d80aaf6 Fix infinite recursion at the end of a file 2022-07-26 10:13:59 -04:00
Alex Hoppen
5dfa894ea7 Merge pull request #60191 from ahoppen/pr/await-contextual-keyword
[SourceKit] Register await as a contextual keyword
2022-07-26 15:54:06 +02:00
Doug Gregor
b3c5fde118 Parse declaration attributes within #if...#endif blocks.
Introduce support for parsing declaration attributes that occur within
example:

    #if hasAttribute(frozen)
    @frozen
    #endif
    public struct X { ... }

will apply to "frozen" attribute to the struct `X`, but only when the
compiler supports the "frozen" attribute.

Correctly determining whether a particular `#if` block contains
attributes to be associated with the following declaration vs.
starting a new declaration requires arbitrary lookahead. The parser
will ensure that at least one of the branches of the `#if` contains an
attribute, and that none of the branches contains something that does
not fit the attribute grammar, before committing to parsing the `#if`
clause as part of the declaration attributes. This lookahead does
occur at the top level (e.g., in the parsing of top-level declarations
and code), but should only need to scan past the first `#if` line to
the following token in the common case.

Unlike other `#if` when used to wrap statements or declarations, we
make no attempt to record the `#if` not taken anywhere in the AST.
This reflects a change in attitude in the design of the AST, because
we have found that trying to represent this information there (e.g.,
via `IfConfigDecl`) complicates clients while providing little value.
This information is best kept in the syntax tree, only.
2022-07-25 21:31:17 -04:00
Doug Gregor
7a75ddafe1 Add "#if hasAttribute(X)" support query attributes. 2022-07-25 21:31:16 -04:00
Alex Hoppen
83380f2682 [SourceKit] Register await as a contextual keyword
`await` in an expresssion should be marked as a contextual keyword, not as an identifier

Resolves apple/sourcekit-lsp#591
2022-07-25 10:26:44 +02:00
Alex Hoppen
837ce1738c Merge pull request #60207 from simanerush/code-completion-foreach 2022-07-25 06:46:37 +02:00
Sima Nerush
90984b7137 Cleanup; add comments 2022-07-24 15:33:55 -06:00
Sima Nerush
5e28b06baf Add in keyword completion and a test 2022-07-24 15:10:01 -06:00
Alex Hoppen
5494161ddd Merge pull request #60196 from ahoppen/pr/misc-libsyntax-improvements
[libSyntax] Small improvements
2022-07-24 17:14:20 +02:00
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