Skip to content

[SE-0382] Implement macros defined as expansions of other macros #64802

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

DougGregor
Copy link
Member

@DougGregor DougGregor commented Mar 31, 2023

  • Explanation: Implement support for defining a macro in terms of the expansion of another macro, one of the last few pieces needed for a complete implementation of SE-0382 "Expression macros".
  • Scope: Affects macro definitions, allowing definitions other than #externalMacro.
  • Issue: rdar://104044325
  • Risk: Low; only affects macro declaration and expansion.
  • Testing: Additional tests added.
  • Original pull request: [Macros] [SE-0382] Implement macros defined as expansions of other macros #64641

In preparation for supporting macros that are defined in terms of other
macros, adopt macro definition checking provided by the
`MacroDeclSyntax.checkDefinition` operation (implemented in
swift-syntax). Use this in lieu of the checking on the C++ side.

This required me to finally fix an issue with the source ranges for
Fix-Its, where we were replacing the leading/trailing trivia of nodes
along with the node itself, even though that's incorrect: we should
only replce the node itself, and there are other Fix-It kinds for
replacing leading or trailing trivia.

(cherry picked from commit 49277f7)
We were enabling the `$Macros` feature unconditionally, even when the
compiler itself doesn't support macros (because it's missing
swift-syntax). Change this to only enable the feature when the
compiler supports it.

(cherry picked from commit 73a2041)
Handle a trivial macro defined in terms of another macro.

(cherry picked from commit 9292231)
This enables macros to be defined in terms of other macros.

(cherry picked from commit 40b3321)
These expressions are a little tricky, because we don't always
type-check them in the way that clients would expect. We might want to
change the representation here, but until then... don't walk the
untypechecked ones.

(cherry picked from commit aac0406)
This should complete the implementation of expanded macro
definitions, rdar://104044325.

(cherry picked from commit cfbdae5)
(cherry picked from commit 68b367b)
@DougGregor DougGregor requested a review from a team as a code owner March 31, 2023 04:15
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor merged commit 45c26cd into swiftlang:release/5.9 Mar 31, 2023
@DougGregor DougGregor deleted the macro-replacement-expansion-5.9 branch March 31, 2023 13:44
@AnthonyLatsis AnthonyLatsis added the 🍒 release cherry pick Flag: Release branch cherry picks label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants