Commit Graph

721 Commits

Author SHA1 Message Date
Rintaro Ishizaki
d6cf55bf82 [ASTGen] Update PluginMessage for conformance macro 2023-02-24 15:16:38 -08:00
Holly Borla
02a53d070f [Macros] Correct the where clause syntax type in ConformanceMacro. 2023-02-23 20:58:22 -08:00
Holly Borla
a3caacd309 [Macros] Initial implementation of conformance macros. 2023-02-23 20:43:11 -08:00
Rintaro Ishizaki
4190cb7978 Merge pull request #63793 from rintaro/macro-plugin-executable
[Macros] Add executable plugin support
2023-02-23 14:02:33 -08:00
Rintaro Ishizaki
c6387a5450 [Macros] Small changes for review 2023-02-22 17:41:43 -08:00
Rintaro Ishizaki
e840409d03 [ASTGen] Remove unnecessary parameters from the expansion funcs 2023-02-22 15:32:25 -08:00
Michael Gottesman
8ee97e1eb3 [reference-bindings] Updates to ASTGen for swift-syntax changes 2023-02-22 13:57:51 -08:00
Rintaro Ishizaki
0e31393024 [Macros] Add executable plugin support
Executable compiler plugins are programs invoked by the host compiler
and communicate with the host with IPC via standard IO (stdin/stdout.)
Each message is serialized in JSON, prefixed with a header which is a
64bit little-endian integer indicating the size of the message.

* Basic/ExecuteWithPipe: External program invocation. Lik
  llvm::sys::ExecuteNoWait() but establishing pipes to the child's
  stdin/stdout
* Basic/Sandbox: Sandboxed execution helper. Create command line
  arguments to be executed in sandbox environment (similar to SwiftPM's
  pluging sandbox)
* AST/PluginRepository: ASTContext independent plugin manager
* ASTGen/PluginHost: Communication with the plugin. Messages are
  serialized by ASTGen/LLVMJSON

rdar://101508815
2023-02-22 10:22:14 -08:00
swift-ci
f68647ac39 Merge pull request #63693 from DougGregor/trim-attr-name
Trim the attribute name when grabbing it from a syntax tree
2023-02-15 18:01:41 -08:00
Doug Gregor
9950ea06ef Trim the attribute name when grabbing it from a syntax tree 2023-02-15 12:46:59 -08:00
Rintaro Ishizaki
66aba1bc67 [ASTGen] Add Encoder/Decoder implementation backed by llvm::json::Value
Preparation for a future use.
2023-02-15 11:55:16 -08:00
Holly Borla
46db62b5b5 [Macros] Pass the attached macro mangling to ASTGen to use as the discriminator
when creating the macro expansion context.
2023-02-14 16:24:27 -08:00
Holly Borla
3ddd25b4f1 [Macros] Fold the declaration node before expanding a peer macro. 2023-02-10 14:43:17 -08:00
Holly Borla
f04f512184 [Macros] Add a new macro role for attached peer macros. 2023-02-10 14:38:22 -08:00
Hamish Knight
c87b1b8bef Merge pull request #63022 from hamishknight/express-yourself 2023-02-03 16:40:09 +00:00
swift-ci
d67b65b8ee Merge pull request #63407 from DougGregor/macros-source-manager-expansion-context
[Macros] Create macro expansion contexts based on the SourceManager
2023-02-03 01:54:16 -08:00
Doug Gregor
8ad7601ade [Macros] Create macro expansion contexts based on the SourceManager
Rather than trying to patch up the "basic" macro expansion context
that comes from the swift-syntax package, implement our own based
on the new SourceManager. Fixes the `location(of:)` operation.
2023-02-02 23:24:56 -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
Doug Gregor
cbdb18097e [Macros] Fix emission of thrown errors.
Errors that were thrown out of a macro implementation were being
emitted and then lost. The result of this is a SILGen assertion later
on, if there were no other errors in the code.

Make sure we properly emit these diagnostics through the source
manager, which required fixing an issue in the offset computation used
for diagnostics.
2023-02-01 15:01:44 -08:00
Hamish Knight
a40f1abaff Introduce if/switch expressions
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.

For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.

The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
2023-02-01 15:30:18 +00:00
Doug Gregor
0af352314a Merge pull request #63322 from DougGregor/macro-expansion-unique-name-mangling 2023-01-31 20:17:41 -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
Doug Gregor
ac4aa41d0f [Macros] Use macro expansion mangling for unique names in macros
Use the name mangling scheme we've devised for macro expansions to
back the implementation of the macro expansion context's
`getUniqueName` operation. This way, we guarantee that the names
provided by macro expansions don't conflict, as well as making them
demangleable so we can determine what introduced the names.
2023-01-31 09:40:48 -08:00
Doug Gregor
32bd60acfa Make code compile for Swift 5.5 2023-01-29 11:25:21 -08:00
Doug Gregor
ba2b0f05fb Revert "Switch all ASTGen-produced diagnostics over to SourceManager"
This reverts commit 6bd72bb095.
2023-01-29 08:30:01 -08:00
Doug Gregor
28f0eadaf9 Revert "[ASTGen] Move source manager diagnostics code into its own file"
This reverts commit 83012a586a.
2023-01-29 08:29:58 -08:00
Doug Gregor
077bd71844 Attempt to get this compiling with Swift 5.5 2023-01-28 23:11:18 -08:00
Doug Gregor
83012a586a [ASTGen] Move source manager diagnostics code into its own file 2023-01-28 22:43:11 -08:00
Doug Gregor
6bd72bb095 Switch all ASTGen-produced diagnostics over to SourceManager 2023-01-28 22:26:39 -08:00
Doug Gregor
027ce8d21c [ASTGen/Macros] Introduce a Swift-side SourceManager into ASTGen.
Add SourceManager that can keep track of multiple source file syntax
nodes along with their external representations. The source manager can
emit diagnostics into any of those files, including tracking any
explicitly "detached" syntax nodes used for macro expansion.

Make sure we detach syntax nodes before passing them to macro
implementations, so they cannot see more of the source file than they
are permitted. We hadn't been doing this before (by accident), and
doing so motivated the introduction of the SourceManager.

Additionally, perform operator folding on macro arguments as part of
detaching them. Macro clients shouldn't have to do this, and moreover,
when clients do this, they lose the ability to easily emit diagnostics
on the now-folded nodes.
2023-01-28 22:23:52 -08:00
Doug Gregor
182950bacb Update to account for SwiftSyntaxMacros module rename and overhaul 2023-01-28 09:00:54 -08:00
Holly Borla
f6f57a8099 [Macros] Rename "synthesized member macros" to "member macros". 2023-01-26 21:52:36 -08:00
Doug Gregor
976060e29c Merge pull request #63220 from AtariDreams/deprecations
Fix DeclarationMacro deprecations
2023-01-26 17:04:08 -08:00
Anthony Latsis
56a1809f82 ASTGen: Handle member types with non-identifier qualifiers 2023-01-26 21:22:24 +03:00
Alex Hoppen
cbdaa25d89 Adjustment for removed with<childName> functions in SwiftSyntax 2023-01-26 17:09:55 +01:00
Richard Wei
dbbf6aa4f1 Merge branch 'main' into freestanding-macro-attr-cleanup 2023-01-26 18:09:45 +08:00
swift-ci
def44c55b7 Merge pull request #63223 from DougGregor/colorize-swift-syntax-diagnostics
Colorize swift syntax diagnostics
2023-01-26 01:16:31 -08:00
Alex Hoppen
641e5ef02c Merge pull request #63215 from ahoppen/ahoppen/effect-specifiers
Adjustments for re-structured effect specifiers
2023-01-26 08:16:56 +01:00
Doug Gregor
c7b7c4a8d4 Colorize swift-syntax diagnnostics when requested 2023-01-25 21:29:23 -08:00
Doug Gregor
d1716e69ec [ASTGen] Define asMacroExpansionExpr here to break link with swift-syntax PR 2023-01-25 21:22:28 -08:00
Doug Gregor
9b935762d6 Adjust to swift-syntax parsing freestanding macros as declarations more often 2023-01-25 17:07:38 -08:00
Rose
0a380cbba3 Fix DeclarationMacro deprecations
These deprecations are simple renames, but this PR should get rid of the warnings.
2023-01-25 13:50:02 -05:00
Alex Hoppen
112c778077 Adjustments for re-structured effect specifiers 2023-01-25 19:29:29 +01:00
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