Skip to content

[5.9][Macro] Attributes for freestanding macro expansion #65990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented May 18, 2023

Cherry-pick #65815, #65882, #65932, #65959, and #65967 into release/5.9

  • Explanation: Enable attributes and modifiers on macro expansion syntax. Attributes and modifiers on the expansion syntax are syntactically copied to the expanded declarations. Also, @available attributes are respected in the arguments of the expansion syntax e.g. @available(macOS 99, *) #someMacro(someAPIfromMacOS_99()).
  • Scope: Freestanding macro expansion parsing and expansion. And availability check inside freestanding macro expansion and expanded declarations.
  • Risk: Mid. The changes are relatively straightforward, but this touches broad area of the compiler and swift-syntax
  • Testing: Added regression test cases
  • Issue: rdar://107386648
  • Reviewers: Alex Hoppen (@ahoppen), Ben Barham (@bnbarham), Doug Gregor (@DougGregor)

rintaro added 5 commits May 17, 2023 15:11
* Parse `#<identifier>` attribute list as a `MacroExpansionDecl`
  regardless of the position
* Diagnose whitespaces between `#` and the macro name.
* Correctly attach attributes to `MacroExpansionDecl`
* Fix `OrigDeclAttributes` to handle modifiers (use `getLocation()`
  instead of `AtLoc`.)

Type checking is a TODO

rdar://107386648
(cherry picked from commit 9fc1521)
Share the same expansion logic between ASTGen and
SwiftCompilerMessageHandling

(cherry picked from commit 5fe2ead)
* Unify macro expansion parsing logic between MacroExpansionExpr and
  MacroExpansionDecl
* Diagnose whitespace between '#' and the macro name
* Diagnose keyword as a macro name

(cherry picked from commit e3a0f24)
@rintaro rintaro requested a review from a team as a code owner May 18, 2023 01:04
@rintaro
Copy link
Member Author

rintaro commented May 18, 2023

swiftlang/swift-syntax#1675
@swift-ci Please test

@DougGregor DougGregor merged commit 2498203 into swiftlang:release/5.9 May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants