Commit Graph

803 Commits

Author SHA1 Message Date
Ben Barham
2562afa74e Merge pull request #63959 from bnbarham/more-workarounds
[CMake] Workaround stale object files causing rebuilds
2023-02-28 09:31:44 -08:00
Richard Wei
77c886c861 [Macros] Rename createUniqueName to makeUniqueName
As per Evolution comment: https://forums.swift.org/t/se-0382-second-review-expression-macros/63064/20

To be merged with https://github.com/apple/swift-syntax/pull/1367
2023-02-28 16:14:15 +08:00
Rintaro Ishizaki
b41a44d259 [Macros] Update PluginMessages for 'customAttrbuteSyntax' rename.
Rename 'customAttributeSyntax' -> 'attributeSyntax'
2023-02-27 23:54:30 -08:00
Ben Barham
50fb165d61 [CMake] Workaround stale object files causing rebuilds
Consider the case of A -> B. The previous workaround will add a
forced-B-dep.swift to A that is touched if B rebuilds. So if B is
rebuilt, A is also rebuilt. But A itself has no real changes, and so
none of its object files are built and none of the mtimes are updated.

Thus, A is then rebuilt again on the next run because its input
(forced-B-dep.swift) is newer than the corresponding object file. To
prevent this, update the mtime for the library and object files after the
build (which is actually a link step that both compiles and links).
2023-02-27 19:29:02 -08:00
Doug Gregor
0d6de9e4a1 [Diagnostics] Switch swift-syntax diagnostic style to grouped diagnostics
Use the new "grouped diagnostics" feature of the swift-syntax
diagnostic rendering to emit printed diagnostics under the
swift-syntax diagnostic style. This emits macro expansion buffers as
text to the terminal, inset in a box where the macro was expanded, so
that there is more context for understanding how the macro was
expanded and what went wrong inside it.
2023-02-27 08:56:21 -08:00
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
Evan Wilde
c67e22e6aa Merge pull request #63192 from etcwilde/ewilde/fix-backdeploy-compat56-crash
Fixes for the compat56 library
2023-02-07 10:22:50 -08:00
Evan Wilde
c1ef992d2d Disable ASTGen runtime-compat libs
The runtime compat 5.6 library is not available in current toolchains.
The stage-0 compiler builds fine since the builder compiler is not aware
of the 5.6 library, but the stage-1 compiler will not link since the
builder libraries don't have the compat 5.6 library, while the stage-0
compiler is aware of the library and attempts to link it into the built
products. The issue is that the bootstrap goes and uses the libraries
off of the builder instead of the things that actually match the
compiler.

This is currently safe because the 5.6 compat library only contains
concurrency runtime fixes and the compiler frontend does not use
concurrency yet. If this changes, we will need to re-enable this and
make the bootstrap use the libraries correctly.
2023-02-06 21:12:25 -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