Commit Graph

2173 Commits

Author SHA1 Message Date
Doug Gregor
bf61578f81 [Macros] Don't assert when a macro parameter has a default argument 2023-02-08 14:34:11 -08:00
Richard Wei
01e4c8df26 [Macros] Use name lookup for lazy declaration macro expansion (#63411)
- Use the name lookup table instead of adding members from a macro expansion to the parent decl context.
- Require declaration macros to specify introduced names and used the declared names to guide macro expansions lazily.
2023-02-07 11:24:42 +08:00
Ellie Shin
258b13b05d Merge pull request #63355 from apple/es-export-pr
Add access level and scope checks to package types
2023-02-03 15:20:29 -08:00
Ellie Shin
be20333a87 Add access level and scope checks to package types
Resolves rdar://104617227
2023-02-02 16:51:17 -08:00
Allan Shortlidge
8fde58f6ca Merge pull request #63357 from tshortli/se0376-rename-backdeploy
[SE-0376] Rename `@_backDeploy(before:)` to `@backDeployed(before:)`
2023-02-02 12:36:53 -08:00
Alex Hoppen
d54af66b50 [Parser] When performing parser validation, suppress warnings from SwiftParser
We can get into a situation where the C++ parser has emitted a warning but no error and thus `hadAnyError()` is still `false`. Suppress warnings from SwiftParser to avoid emitting the same warning that we already emitted from the C++ parser from SwiftParser.
2023-02-02 16:50:04 +01:00
Allan Shortlidge
d2524a6de8 AST: Implement parsing support for the accepted spelling of @backDeployed for SE-0376.
For source compatibility `@_backDeploy` continues to be accepted as a spelling.

rdar://102792909
2023-02-01 22:04:33 -08:00
John McCall
ea107ae025 Merge pull request #63324 from rjmccall/element-archetype-printing
Fix printing and implement parsing of opened element archetypes in SIL
2023-02-01 18:59:54 -05:00
John McCall
c491d25d06 Fix printing and implement parsing of opened element archetypes in SIL
Also, fix a couple places that were checking for opened existentials
to check for any local archetype.
2023-01-31 19:54:31 -05: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
e6d7ea53ed [Parser] Use proper ParseDeclOptions when parsing the result of a member macro
expansion.
2023-01-27 22:37:22 -08:00
Holly Borla
32a0705e90 [Macros] Use the singular 'memberAttribute' spelling for attached member
attribute macros.
2023-01-26 21:52:39 -08:00
Holly Borla
f6f57a8099 [Macros] Rename "synthesized member macros" to "member macros". 2023-01-26 21:52:36 -08:00
Anthony Latsis
fe047b98fb Parser: Tweak parseTypeIdentifier to better suit its only remaining client 2023-01-26 21:22:18 +03:00
Doug Gregor
af7ce9e945 [Macros] Remove the @declaration attribute.
We have @freestanding working appropriately now.
2023-01-25 17:07:38 -08:00
Doug Gregor
c188ab4f91 Remove the "@expression" attribute now that it has a better spelling 2023-01-25 17:07:38 -08:00
Doug Gregor
d74f235eb9 Generalize @attached parsing and representation to also include @freestanding.
The attached and freestanding macro attributes use the same parsing
logic and representation, so generalize the "attached" attribute into
a more general "macro role" attribute.
2023-01-25 17:07:38 -08:00
Holly Borla
8b9be30783 [Macros] Add a new macro role for synthesized member macros. 2023-01-22 21:19:21 -08:00
Jonathan Grynspan
95af9e3963 [SR-15231] #sourceLocation doesn't recognize CRLF line endings #57553 (#63071) 2023-01-19 10:22:25 -05:00
Holly Borla
a475ecdbd1 [Parser] Extract parsing a source file via ASTGen into a helper function, and
call it from parseExpandedAttributeList.

In the future, it would be much better to requestify computing exportedSourceFile,
so the new Swift parser is invoked on-demand rather than making sure it's
invoked in all of the appropriate parser entry points.
2023-01-15 10:11:00 -08:00
Holly Borla
ffa47556f5 [Parser] Parse top-level attribute lists for member attribute macro
expansion.
2023-01-15 10:11:00 -08:00
Holly Borla
5d7b280889 [Macros] Use @attached for member attribute macros.
Add MemberAttributes to MacroRole that corresponds to a `memberAttributes`
argument to the `@attached` attribute.
2023-01-15 10:11:00 -08:00
Doug Gregor
43cadcad3a [Macros] Serialization and printing for @attached. 2023-01-14 21:48:43 -08:00
Doug Gregor
de16b47875 [Macros] Introduce the @attached attribute for declaring attached macros.
Describe attached macros with the `@attached` attribute, providing the
macro role and affected names as arguments to the macro. The form of
this macro will remain the same as it gains other kinds of attached
macro roles beyond "accessor".

Remove the "accessors" role from `@declaration`, which will be going
away.
2023-01-13 22:47:59 -08:00
Doug Gregor
8c3bd021c5 [Macros] Parse accessors produced my an accessor macro.
Once an accessor macro has produced accessors, parse them and wire them
into the AST so the rest of the compiler will see them. First
end-to-end test case!
2023-01-13 13:17:17 -08:00
Doug Gregor
0988e54e5b [Parser] Factor parsing of accessors into its own function 2023-01-13 09:10:05 -08:00
Andrew Trick
559ae7f567 Merge pull request #62981 from atrick/fix-warnings
Fix compiler warnings.
2023-01-12 18:18:15 -08:00
Andrew Trick
567103eef4 Fix compiler warnings.
main branch shouldn't have any warnings. It messes up my workflow.
2023-01-11 15:21:07 -08:00
John McCall
188b28b2e5 [NFC] Extract a utility routine to parse a UUID string literal. 2023-01-11 03:11:30 -05:00
Richard Wei
f17b7c48bf [Macros] Freestanding declaration macros
Add support for freestanding declaration macros.

- Parse `@declaration` attribute.
- Type check and expand `MacroExpansionDecl`.

Known issues:
- Generic macros are not yet handled.
- Expansion does not work when the parent decl context is `BraceStmt`. Need to parse freestanding declaration macro expansions in `BraceStmt` as `MacroExpansionDecl`, and add expanded decls to name lookup.
2023-01-10 19:09:11 -08:00
Anthony Latsis
ad5d55c36e [NFC] AST: Rename IdentTypeReprDeclRefTypeRepr 2023-01-07 07:14:44 +03:00
Anthony Latsis
ea7662768e Parse: Use TypeRepr * instead of DeclNameRef in a note that points to an extension 2023-01-07 07:11:29 +03:00
Doug Gregor
7000969f14 Introduce and use #externalMacro for externally-defined macros.
Align the grammar of macro declarations with SE-0382, so that macro
definitions are parsed as an expression. External macro definitions
are referenced via a referenced to the macro `#externalMacro`. Define
that macro in the standard library, and recognize uses of it as the
definition of other macros to use externally-defined macros. For
example, this means that the "stringify" macro used in a lot of
examples is now defined as something like this:

    @expression macro stringify<T>(_ value: T) -> (T, String) =
        #externalMacro(module: "MyMacros", type: "StringifyMacro")

We still parse the old "A.B" syntax for two reasons. First, it's
helpful to anyone who has existing code using the prior syntax, so they
get a warning + Fix-It to rewrite to the new syntax. Second, we use it
to define builtin macros like `externalMacro` itself, which looks like this:

    @expression
    public macro externalMacro<T>(module: String, type: String) -> T =
        Builtin.ExternalMacro

This uses the same virtual `Builtin` module as other library builtins,
and we can expand it to handle other builtin macro implementations
(such as #line) over time.
2023-01-02 21:22:05 -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
Doug Gregor
9e61b01ec1 Rework computation of local discriminators for named entities.
Local discriminators for named entities are currently being set by the
parser, so entities not created by the parser (e.g., that come from
synthesized code) don't get local discriminators. Moreover, there is
no checking to ensure that every named local entity gets a local
discriminator, so some entities would incorrectly get a local
discriminator of 0.

Assign local discriminators as part of setting closure discriminators,
in response to a request asking for the local discriminator, so the
parser does not need to track this information, and all local
declarations---including synthesized ones---get local discriminators.
And add checking to make sure that every entity that needs a local
discriminator gets assigned one.

There are a few interesting cases in here:
* There was a potential mangling collision with local property
wrappers because their generated variables weren't getting local
discriminators
* $interpolation variables introduced for string interpolation weren't
getting local discriminators, they were just wrong.
* "Local rename" when dealing with captures like `[x]` was dependent on
the new delcaration of `x` *not* getting a local discriminator. There
are funny cases involving nesting where it would do the wrong thing.
2022-12-21 15:01:07 -08:00
Doug Gregor
8b1051eb86 We can do round-trip and validation testing even with deep nesting 2022-12-16 09:55:11 -08:00
Doug Gregor
33589de62f Experimentally emit diagnostics from the new Swift parser
Introduce the experimental feature `ParserDiagnostics`, which emits
diagnostics from the new Swift parser *first* for a source file. If
that produces any errors, we suppress any diagnostics emitted from the
C++ parser.
2022-12-15 21:24:44 -08:00
Doug Gregor
1a3c6d721f [ASTGen] Handle new parser validation in ASTGen.
Replace the use of the "consistency check" vended by swift-syntax with
an ASTGen-implemented operation that emits diagnostics from the new parser
via the normal diagnostic engine. This eliminates our last dependency
on SwiftCompilerSupport, so stop linking it.
2022-12-15 21:24:44 -08:00
Doug Gregor
7dd6af759d [New parser] Move round-trip checking logic into ASTGen
This removes one bit of code dependency on SwiftCompilerSupport, which
we want to eliminate.
2022-12-15 07:13:38 -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
Doug Gregor
4ce0834c51 [Macros] Serialization support for macro declarations. 2022-11-28 18:33:09 -08:00
Doug Gregor
b29fcb4e58 [Macros] Parse macro declarations fully, and treat them as normal declarations 2022-11-28 18:32:43 -08:00
Doug Gregor
7157510e00 [Macros] Parse macro declarations. 2022-11-28 18:32:43 -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
Holly Borla
2213a02aaa Revert "[Sema] Record opaque type decls for type reconstruction after creation instead of in the parser." 2022-11-15 08:44:01 -08:00