Commit Graph

220 Commits

Author SHA1 Message Date
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
zoecarver
2e1893fe53 [astgen] Fix tuple locations. 2022-11-01 09:32:41 -07:00
zoecarver
42f4b750a9 [astgen] Add '.rawValue' to map operation. 2022-11-01 09:32:41 -07:00
Zoe Carver
60c8b4b178 Merge pull request #61834 from zoecarver/astgen-array-literal 2022-11-01 07:49:28 -07:00
swift-ci
90cc923acc Merge pull request #61829 from zoecarver/astgen-post-commit-review
[astgen] Address comments post-commit.
2022-10-31 16:33:42 -07:00
zoecarver
0801d478b8 [astgen] Add support for ArrayExpr. 2022-10-31 15:20:10 -07:00
Richard Wei
4ce1ebb120 [Macros] Support user-defined macros as compiler plugins (#61734)
Allow user-defined macros to be loaded from dynamic libraries and evaluated.

- Introduce a _CompilerPluginSupport module installed into the toolchain. Its `_CompilerPlugin` protocol acts as a stable interface between the compiler and user-defined macros.
- Introduce a `-load-plugin-library <path>` attribute which allows users to specify dynamic libraries to be loaded into the compiler.

A macro library must declare a public top-level computed property `public var allMacros: [Any.Type]` and be compiled to a dynamic library. The compiler will call the getter of this property to obtain and register all macros.

Known issues:
- We current do not have a way to strip out unnecessary symbols from the plugin dylib, i.e. produce a plugin library that does not contain SwiftSyntax symbols that will collide with the compiler itself.
- `MacroExpansionExpr`'s type is hard-coded as `(Int, String)`. It should instead be specified by the macro via protocol requirements such as `signature` and `genericSignature`. We need more protocol requirements in `_CompilerPlugin` to handle this.
- `dlopen` is not secure and is only for prototyping use here.

Friend PR: apple/swift-syntax#1022
2022-10-31 14:03:25 -07:00
zoecarver
88dfb83d76 Address a comments post-commit. 2022-10-31 13:51:14 -07:00
zoecarver
dd4a0ec405 [nfc] Format changes. 2022-10-30 12:01:31 -07:00
zoecarver
f85d687278 [astgen] Correctly thread initializer through VarDecl visitor. 2022-10-30 12:00:58 -07:00
zoecarver
37ef2d7834 [astgen] Correctly thread 'name' through VarDecl visitor. 2022-10-30 11:50:15 -07:00
zoecarver
799463b81e [astgen] Add ASTNodeKind; support decls in code-blocks. 2022-10-30 11:42:55 -07:00
zoecarver
3447dd7baa [astgen] Set TypeRepr when visiting ParamDecls. 2022-10-30 11:32:02 -07:00
zoecarver
6855ca76a0 [astgen] Add begin and end source locs to BraceStmt visitor. 2022-10-30 11:20:53 -07:00
zoecarver
61b160d288 [nfc] Run swift-format over Swift ASTGen sources. 2022-10-30 11:03:53 -07:00
zoecarver
371eb9143d [astgen] Add ReturnStmt visitor. 2022-10-30 10:55:17 -07:00
zoecarver
bec4ff77f3 [astgen] Use ASTNode to implement BraceStmt correctly. 2022-10-30 10:50:13 -07:00
zoecarver
6b7123e1e9 [astgen] Introduce ASTNode; update ResultType to be ASTNode. 2022-10-30 10:50:03 -07:00
Doug Gregor
8461427ef4 [ASTGen] Fix off-by-one error in allocation of UTF-8 string for buffer use
The semantics of llvm::MemoryBuffer and NULL termination are... subtle.
2022-10-27 17:05:20 -07:00
Robert Widmann
822fd47b8a Add Utilities to Retrieve the (Opened) Type of a Macro Reference 2022-10-27 11:11:11 -07:00
Robert Widmann
032e8d5e1d Start Lowering Generic ASTs
Lower generic argument lists and generic parameter lists, then expand the lowering for identifiers to take generic arguments into account.
2022-10-27 11:11:11 -07:00
Robert Widmann
f4f7f7f2ce Finish Off ASTGen Implementation for Types
Complete the lowering for the type ASTs present in SwiftSyntax to C++ TypeReprs
2022-10-27 11:11:11 -07:00
Doug Gregor
6cd0327655 Merge pull request #61691 from DougGregor/macros-expand-and-type-check 2022-10-24 05:47:57 -07:00
Doug Gregor
f04fd94465 [Macros] Separate out the expansion of macros into its own source file.
Once we've expanded a macro, create a new source buffer containing
the expanded macro contents.
2022-10-23 14:53:11 -07:00
Alex Hoppen
0738413fb7 [CMake] Link swiftParse and swiftAST against SwiftParserDiagnostics 2022-10-23 23:34:13 +02:00
Doug Gregor
e2993ea9bf [ASTGen] Support older host compilers 2022-10-21 06:41:06 -07:00
Doug Gregor
9979bb0e0a [Macros] Pass evaluated macro source back into the C++ part of the compiler.
Use this to print out the rewritten macro, for now.
2022-10-21 06:41:06 -07:00
Doug Gregor
636e6d1524 [Macros] "Expand" builtin macros for magic literals.
Introduce an experimental option `BuiltinMacros` that takes the magic
literals (`#file`, `#line`, `#function`, etc.) after type checking and
processes the original source for the expression using the build
syntactic macro system in the swift-syntax library. At present, the
result of expansion is printed to standard output, but it's enough to
verify that we're able to find the corresponding syntax node based on
the C++ AST.
2022-10-21 06:41:05 -07:00
Doug Gregor
9c528c6fe2 [ASTGen] Link in syntactic macros 2022-10-21 06:39:53 -07:00
Doug Gregor
2b741ad376 Move ASTGen source-file handling to its own (Swift) file 2022-10-21 06:39:53 -07:00
Doug Gregor
d33998538c Hold on to the SwiftSyntax source file parsed by ASTGen.
Rework the ASTGen interface to split apart parsing a source file,
turning the top-level declarations from that source file into C++ AST
nodes, and then deallocating that source file. Hold on to the source
file in the C++ SourceFile abstraction so we can query it later if we
need to.

And we will need to.
2022-10-21 06:39:53 -07:00
Doug Gregor
dec8813797 Merge pull request #61538 from DougGregor/astgen-spurious-whitespace
[ASTGen] Remove spurious whitespace
2022-10-12 15:42:59 -07:00
Doug Gregor
46703efe57 [ASTGen] Remove spurious whitespace 2022-10-10 16:42:13 -07:00
Doug Gregor
e35e82e7fd Add more missing dependencies 2022-10-10 14:33:38 -07:00