Skip to content

[5.9] [Macros] Tighten declaration semantics and improve expansion of freestanding macros #66527

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

…lt type

Fixes rdar://108871352.

(cherry picked from commit 759f520)
The compiler knows (from a macro declaration) what freestanding macro
role a macro implementation is expected to implement. Pass that through
to the macro expansion code itself, rather than guessing based on the
protocol conformances of the implementation type. We already use this
approach with attached macros, so this is more of the same.

Eliminates a crash and improves diagnostics when the freestanding macro
role and its implementation are out of sync, fixing rdar://110418969.

(cherry picked from commit 3c04cff)
Per SE-0397, a macro may only have a single freestanding macro role,
otherwise we would have an ambiguity in how a particular freestanding
macro would be expanded. Produce an error on such macro declarations.

Fixes rdar://110178899.

(cherry picked from commit c5ec389)
@DougGregor DougGregor requested a review from a team as a code owner June 10, 2023 05:01
@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#1763

@swift-ci please test

…rn types

There is no reason to special-case `Void` to permit it. Rather, make
this a syntactic rule. Thanks to Alex Hoppen for the suggestion.
…terfaces

This allows us to continue to accept Swift interface files created with
older versions of the Swift 5.9 compiler that emitted a spurious
`-> ()` on non-expression macro declarations.
@DougGregor DougGregor force-pushed the freestanding-macro-cleanups-5.9 branch from 6ab34fb to c72f379 Compare June 10, 2023 06:27
@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#1763

@swift-ci please test

@DougGregor DougGregor merged commit 2d53ae0 into swiftlang:release/5.9 Jun 10, 2023
@DougGregor DougGregor deleted the freestanding-macro-cleanups-5.9 branch June 10, 2023 17:45
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