Commit Graph

803 Commits

Author SHA1 Message Date
Holly Borla
e5ba38925a [Macros] Allow one attached macro declaration to fulfill multiple roles. 2023-01-23 17:56:48 -08:00
Holly Borla
f1742fd721 [Macros] Initial implementation for synthesized member macro expansion. 2023-01-23 17:56:48 -08:00
Doug Gregor
bdf1183757 [Diagnostics] Add a swift-syntax diagnostic style
The SwiftDiagnostics module within swift-syntax has a diagnostic
pretty-printer that does a nice rendering of the source code with
diagnostics placed inside gaps between the code lines.
Introduce another `-diagnostic-style` argument, `swift-syntax`,
to bridge from the pretty-printed C++ diagnostics over to the
swift-syntax diagnostics engine.
2023-01-21 23:09:56 -08:00
Holly Borla
0d7109710f [Macros] Pass the parent declaration of the member-to-expand to member
attribute macro expansions.
2023-01-15 11:36:47 -08:00
Holly Borla
4f8e1daa26 [Macros] Implement the skeleton of attribute macro expansion.
Attribute macros are expanded during AttachedSemanticAttrsRequest. This
change invokves the expansion, but it does nothing with the result yet.
The next step is to parse back in the attribute list, type check it, and
return the resulting attributes back to the request to add to the semantic
attribute list.
2023-01-15 10:11:00 -08:00
Doug Gregor
91ee109c2f [Macros] Start expanding accessor macros attached to a storage declaration.
Accessor macros are attached macros (written with attribute syntax)
that can generate accessors for a property or subscript. Recognize
custom attributes that are accessor macros when written on a storage
declaration, and expand those macros.

This is very much a work in progress, and the result of the expansion
isn't yet parsed or wired into the AST.
2023-01-13 10:12:25 -08:00
Alex Hoppen
597150fea8 Adjustments for merging of contextual and lexical keywords 2023-01-11 15:18:05 +01:00
swift-ci
a82e17bffa Merge pull request #62934 from rxwei/freestanding-declaration-macros
[Macros] Freestanding declaration macros
2023-01-10 21:55:16 -08: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
Ben Barham
f8d03a235f Merge pull request #62736 from bnbarham/remove-superfluous-metatype-handling
[ASTGen] Remove superfluous metatype handling
2023-01-09 15:14:25 -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
Anthony Latsis
ad5d55c36e [NFC] AST: Rename IdentTypeReprDeclRefTypeRepr 2023-01-07 07:14:44 +03:00
Ben Barham
7a12d6f0a3 [ASTGen] Remove superfluous metatype handling
Metatypes are now parsed properly in the Swift parser. Remove the
now-superfluous metatype handling in the `MemberTypeIdentifierSyntax`
visit.
2022-12-21 11:38:24 -08:00
Doug Gregor
4ef35c5f14 Embrace the swift-syntax notion of Fix-Its as separate notes.
The swift-syntax diagnostic system always treats Fix-Its as separate
notes, which are never attached to the primary diagnostic. Embrace this
module in the mapping over to the existing C++ diagnostic engine.
2022-12-15 21:24:44 -08:00
Doug Gregor
f8e98ca454 [ASTGen] Make sure we handle Fix-Its without a matching note.
Any Fix-Its not associated with a note are automatically associated
with the main diagnostic.
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
Doug Gregor
cb3a24edda [Macros] Note when diagnostics came from the implementation of a macro 2022-12-14 16:18:58 -08:00
Doug Gregor
387a79c47b [Macro test] Handle source locations in macro diagnostics better.
"Relink" the folded syntax node back into the primary syntax node. When
we do this, we get consistent source locations that do not require any
adjustment.

Test this by adding a Fix-It to the silly AddBlocker macro, replacing
the `+` with a `-`.
2022-12-14 16:13:49 -08:00
Doug Gregor
fa54d7090d [Macros] Handle throwing in macro expansions 2022-12-13 23:18:51 -08:00
Doug Gregor
f0fc1c51bb Remove compiler plugin support library
The functionality of the compiler plugin support library has been
subsumed into parts of the compiler. Remove the functionality and its
last test.
2022-12-05 12:54:36 -08:00
Doug Gregor
14aebcab1b Bridge swift-syntax diagnostics to the C++ diagnostic engine's diagnostics.
Implement an ASTGen operation to bridge swift-syntax diagnostics, as
produced by the parser, operator folding, and macros, over to the C++
diagnostic engine infrastructure. Use this to wire up macro expansion
diagnostics.
2022-12-05 11:49:42 -08:00
Doug Gregor
728ba4eada [Macros] Adapt to rename of ExpressionMacro.expansion(of:in:). 2022-12-05 09:34:54 -08:00
Doug Gregor
b6df4118fb Drop unnecessary SPI import 2022-12-02 22:46:09 -08:00
Doug Gregor
5bd94d680e [Macros] Adapt to macro API changes and switch more testing to use it.
The API provided by macro evaluation has changed a bit. Adapt ASTGen to
the new API, and use this as an opportunity to start moving more tests
to using the shared libraries built into the toolchain.
2022-12-02 16:35:14 -08:00
Doug Gregor
d59b50f268 [ASTGen] We don't need SPI from _SwiftSyntaxMacros. 2022-12-02 08:54:07 -08:00
Doug Gregor
811595394f [Macros] Build and test a macro plugin based on SwiftSyntax 2022-12-01 23:20:56 -08:00
Doug Gregor
1c00e1cafe Copy all of the swift-syntax Swift modules.
Make the build directory for lib/swift/host look like the eventually
toolchain directory by copying in all of the Swift module files. This
makes it easier to correctly build anything requiring these libraries
against either the build or the install directories.
2022-11-30 15:57:10 -08:00
Doug Gregor
52d513af6b Build swift-syntax as shared libraries instead of static libraries.
This allows the various binaries (swift-frontend, SourceKit, etc.) to
share the same code, as well as allowing plugins to link against these
shared libraries.
2022-11-30 15:31:57 -08:00
Doug Gregor
20013181e1 [CMake] Link to swift-syntax libriares from lib/swift/host. 2022-11-30 13:54:03 -08:00
Doug Gregor
e67c546a77 [Macros] Resolve in-process macros via external type name.
This approach works for both macros built into the compiler (e.g., the
builtin macros) as well as those that are loaded via plugin but don't
conform to the _CompilerPluginSupport protocol.

This eliminates all uses of the `MacroSystem` itself in ASTGen, and
pushes more of the implementation through ASTGen.
2022-11-28 18:32:43 -08:00
Doug Gregor
cc142d4843 [Macros] Use the resolved macro for evaluation.
Don't look up the macro name again when doing expansion; that's already
been done when we found the macro definition.
2022-11-28 18:32:43 -08:00
Doug Gregor
813dc12ad3 [Macros] Use the external module/type name in lieu of macro registration.
A macro declaration contains the external module and type name of the
macro's implementation. Use that information to find the macro type
(via its type metadata accessor) in a loaded plugin, so we no longer
require the "allMacros" array. Instead, each macro implementation type
must be a public struct.

Since we are now fully dependent on the macro declaration for
everything about a macro except its kind, remove most of the query
infrastructure for compiler plugins.

Replace the macro registration scheme based on the allMacros array with
2022-11-28 18:32:43 -08:00
Ben Barham
6f716a5fe2 Merge pull request #62129 from bnbarham/fix-syntax-dependencies
[CMake] Temporarily workaround CMake dependencies bug
2022-11-17 14:25:46 -08:00
Richard Wei
1930f86a1a [Macros] Emit diagnostics from plugins
Make `_rewrite` return an buffer containing diagnostics and emit them.
2022-11-17 03:17:57 -08:00
Ben Barham
fa43760766 [CMake] Temporarily workaround CMake dependencies bug
Workaround a CMake bug in order to make sure that ASTGen is rebuilt when
the swift-syntax dependencies change.
2022-11-16 16:16:44 -08:00
Doug Gregor
c0d53c4a47 [CMake] Fixup build for compiler plugin support library 2022-11-15 19:32:20 -08:00
Doug Gregor
97ced3057b [ASTGen] Handle metatypes and simple generic types. 2022-11-13 22:45:47 -08:00
Doug Gregor
4b87cb7b14 [Macros] Plumb the owning module and supplemental modules through to Macro.
Plumb the information about the owning module and supplemental
signature modules through to the Macro data structure, for both
built-in and plugin macros.

We're resolving the given module names into module declarations, but
otherwise performing no checking and not emitting any diagnostics.
This information is not yet used.
2022-11-11 15:24:37 -08:00
Doug Gregor
36613dc3ea [Macros] Simplify the macro signature context with a generic typealias.
The macro signature context was a (possibly generic) struct declaration
containing a typealias. We don't need the struct itself, because the
typealias can be generic as well. This eliminates an extra, annoying
hop through name lookup.
2022-11-11 15:24:37 -08:00
Doug Gregor
f98842bace [Macros] Unify the creation of the macro evaluation context.
We had two implementations of the code that forms the macro evaluation
context buffer, one in ASTGen and one in Sema. Unify them into a single
place, and unify the creation of macros so we localize this arcane
knowledge.
2022-11-11 15:24:37 -08:00
Doug Gregor
16f81fbad5 Introduce a Macro AST type and use it to describe the macros we find 2022-11-11 15:24:37 -08:00
Zoe Carver
beac60303a Merge pull request #61899 from zoecarver/astgen-fixes
A few more ASTGen fixes.
2022-11-04 09:49:41 -07:00
zoecarver
673ccd15a9 [astgen] Fix argument/param labels/names. 2022-11-03 16:36:13 -07:00
zoecarver
cae1a2b7d1 [astgen] Support labeled tuples. 2022-11-03 13:54:34 -07:00
zoecarver
738b89e270 [astgen] Use element location instead of source file location to prevent crash. 2022-11-02 17:42:47 -07:00
Doug Gregor
85e42435f6 [ASTGen] Disable implicit import of _StringProcessing in ASTGen.
Reduce dependencies for rdar://101819413 .
2022-11-02 15:25:01 -07:00
zoecarver
1e08317d3a Format sources. 2022-11-01 10:59:26 -07:00
zoecarver
b6b7224d50 [astgen] Correctly represent FuncDecl as a DeclContect. 2022-11-01 09:33:44 -07:00
zoecarver
4892800685 [astgen] Fix the locations of a few visitors. 2022-11-01 09:33:44 -07:00