Commit Graph

1105 Commits

Author SHA1 Message Date
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
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
Doug Gregor
18f70dd25e Merge pull request #61386 from DougGregor/key-path-parsing-new-parser
Switch to the "old" key path expression syntax nodes.
2022-09-30 16:14:51 -07:00
Doug Gregor
fbb9822913 Switch to the "old" key path expression syntax nodes.
The new Swift parser uses a revamped set of syntax nodes for key paths
that better match the language. However, the C++ parser does not
produce anything like these syntax nodes, so switch to an "old"
keypath node style for now.
2022-09-30 11:53:48 -07:00
Anthony Latsis
18156d1177 Merge pull request #61347 from AnthonyLatsis/migrate-compiler-to-gh-issues
Gardening: Migrate compiler sources to GitHub issues
2022-09-30 10:48:52 +03:00
Anthony Latsis
2843e0c871 Gardening: Migrate compiler sources to GitHub issues 2022-09-29 23:58:55 +03:00
Hamish Knight
bca941b152 [AST] NFC: Rename IfExpr -> TernaryExpr
This matches what we call it in SwiftSyntax, and
is just generally clearer.
2022-09-28 10:33:31 +01:00
Joe Groff
d4b690cfd3 Merge pull request #61302 from jckarter/single-closure-for-all-static-partial-applications
Sema: Form all static member partial applications with one closure
2022-09-26 19:52:20 -07:00
Luciano Almeida
52e2b3dc24 [Parse] Suggest platform correction based on known platforms edit distance 2022-09-26 19:44:04 -03:00
Joe Groff
6463d96df0 Sema: Use AutoClosureExpr again in KeyPathExpr-as-function expansion
Remove the preallocated closure discriminator from KeyPathExpr and go back
to expanding them using an AutoClosureExpr inside of a CaptureListExpr now
that that's supported. This allows the discriminator to be assigned during
type checking without disturbing the indexing of explicit closure literals.
2022-09-23 10:26:18 -07:00
Joe Groff
a6a486c60b Merge pull request #61253 from jckarter/key-path-literal-as-function-ast-optimization-2
Sema: Simplify AST representation of key path literals as functions. [take 2]
2022-09-22 15:59:41 -07:00
Joe Groff
c6b6787f74 Sema: Simplify AST representation of key path literals as functions.
Previously, we would turn a key path literal like `\.foo` in function type
context into a double-wrapped closure like this:

```
  foo(\.x) // before type checking
  foo({ $kp$ in { $0[$kp$] } }(\.x)) // after type checking
```

in order to preserve the evaluation semantics of the key path literal. This
works but leads to some awkward raw SIL generated out of SILGen which misses
out on various SILGen peepholes and requires a fair number of passes to clean
up. The semantics can still be preserved with a single layer of closure, by
using a capture list:

```
  foo({[$kp$ = \.x] in $0[$kp$] }) // after type checking
```

which generates better natural code out of SILGen, and is also (IMO) easier
to understand on human inspection.

Changing the AST representation did lead to a change in code generation that
interfered with the efficacy of CapturePropagation of key path literals; for
key path literals used as nonescaping closures, a mark_dependence of the
nonescaping function value on the key path was left behind, leaving the key
path object alive. The dependence is severed by the specialization done in
the pass, so update the pass to eliminate the dependence.

Compared to the previous patch, this version removes the attempt to have
the type-checked function expression carry the noescape-ness of its context,
and allows for coerceToType to introduce a function conversion instead, since
that FunctionConversionExpr is apparently load-bearing for default argument
generators.
2022-09-22 12:00:22 -07:00
Artem Chikin
b8c1b4b3d0 Revert "Sema: Simplify AST representation of key path literals as functions." 2022-09-22 09:54:22 -07:00
Allan Shortlidge
f1ecb4c215 Parse: Offer a fix-it when platform is specified with the wrong case in availability attributes and queries.
Resolves rdar://100195680
2022-09-21 16:21:36 -07:00
Joe Groff
57553878f8 Sema: Simplify AST representation of key path literals as functions.
Previously, we would turn a key path literal like `\.foo` in function type
context into a double-wrapped closure like this:

  foo(\.x) // before type checking
  foo({ $kp$ in { $0[$kp$] } }(\.x)) // after type checking

in order to preserve the evaluation semantics of the key path literal. This
works but leads to some awkward raw SIL generated out of SILGen which misses
out on various SILGen peepholes and requires a fair number of passes to clean
up. The semantics can still be preserved with a single layer of closure, by
using a capture list:

  foo({[$kp$ = \.x] in $0[$kp$] }) // after type checking

which generates better natural code out of SILGen, and is also (IMO) easier
to understand on human inspection.

Changing the AST representation did lead to a change in code generation that
interfered with the efficacy of CapturePropagation of key path literals; for
key path literals used as nonescaping closures, a mark_dependence of the
nonescaping function value on the key path was left behind, leaving the key
path object alive. The dependence is severed by the specialization done in
the pass, so update the pass to eliminate the dependence.
2022-09-21 09:40:30 -07:00
Allan Shortlidge
06595f6597 Merge pull request #60852 from tshortli/parse-has-symbol
AST: Parse `#_hasSymbol`
2022-09-12 09:32:52 -07:00
Slava Pestov
da76e1ee71 Sema: Allow one-element tuples when -enable-experimental-variadic-generics is on 2022-09-10 00:26:43 -04:00
Allan Shortlidge
f5f1d3c028 AST: Parse #_hasSymbol
Introduce the compiler directive `#_hasSymbol` which will be used to detect whether weakly linked symbols are present at runtime. It is intended for use in combination with `@_weakLinked import` or `-weak-link-at-target`.

```
if #_hasSymbol(foo(_:)) {
  foo(42)
}
```

Parsing only; SILGen is coming in a later commit.

Resolves rdar://99342017
2022-09-08 17:15:29 -07:00
Luciano Almeida
5170a2e494 [Parse] Handle underscored integer in #sourceLocation line directive 2022-08-29 22:53:40 -03:00
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
Rintaro Ishizaki
1eed8675f7 [Parse] Parser update for UnresolvedTernaryExprSyntax 2022-08-18 10:37:18 -07:00