Commit Graph

783 Commits

Author SHA1 Message Date
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
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