Skip to content

[5.9] [Macros] Pass macro role for freestanding macro expansion #1763

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

Conversation

DougGregor
Copy link
Member

  • Explanation: Extend the protocol used by the macro server to include a freestanding macro role in the freestanding macro expansion request, and provide improved diagnostics when the role requested is not implemented by the macro implementation type. This is, on the whole, more informative than crashing the compiler, which is what happened before.
  • Scope: Narrow; only affects validation of freestanding macro expansions.
  • Risk: Low; narrow change to perform better validation when expanding freestanding macros.
  • Reviewed by: @rintaro
  • Issue: rdar://110418969
  • Original pull request: [Macros] Pass macro role for freestanding macro expansion  #1757, Eliminate redundant precondition checking #1762

Macros can only have a single freestanding macro role, so that their
expansion is unambiguous. However, that restriction is at the level of a
macro declaration, and is not reflected in a similar restriction on the
set of macro protocols to which a macro implementation can conform.
Therefore, have the compiler pass a freestanding macro role through to
macro expansion in the same way that we do for attached macros, and
use that to determine which macro protocol to use.

Part of fixing rdar://110418969.

(cherry picked from commit fe05c66)
(cherry picked from commit 4a8b665)
Thanks to Rintaro for pointing this out.
@DougGregor DougGregor requested a review from ahoppen as a code owner June 10, 2023 04:44
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor merged commit c40fd0d into swiftlang:release/5.9 Jun 10, 2023
@DougGregor DougGregor deleted the freestanding-macro-role-message-5.9 branch June 10, 2023 14:49
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