Skip to content

Rework MacroExpansionContext and macro protocols #1288

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 Jan 27, 2023

This pull request collects together a number of changes to the API of the SwiftSyntaxMacros package to bring it into line with the proposals. It includes:

  • MacroExpansionContext is now a protocol
  • BasicMacroExpansionContext is an implementation of MacroExpansionContext that is suitable for testing and similar clients
  • MacroExpansionContext adds a location(of:) operation to get a source location for a given syntax node. #column is back to being expressible as a macro ;)
  • The *Macro protocols have been reworked and genericized
  • The module has been renamed to SwiftSyntaxMacros.

The macros design has moved to having `MacroExpansionContext` be a
class-bound protocol. Adjust the implementation accordingly, and add a
`TestingMacroExpansionContext` for a concrete implementation to use in
test cases.

And since I didn't want to break the `#fileID` macro that used to work,
implement a general scheme for getting the location of a syntax node :).
@DougGregor DougGregor changed the title Rework MacroExpansionContext as a protocol Rework MacroExpansionContext and macro protocols Jan 27, 2023
Make the signature generic over all freestanding macro expansion syntax
nodes (to account for places where we parse as a declaration), and
generic over the macro expansion context (lest we cause an existential
crisis).
The bounds aren't quite what I was hoping for, because we don't have a
way to abstract over "nodes that have accessors".
This is intended to be it's final name.
@DougGregor DougGregor requested a review from ahoppen as a code owner January 28, 2023 07:37
@DougGregor
Copy link
Member Author

swiftlang/swift#63284

@swift-ci please test

1 similar comment
@DougGregor
Copy link
Member Author

swiftlang/swift#63284

@swift-ci please test

@DougGregor
Copy link
Member Author

swiftlang/swift#63284

@swift-ci please test

1 similar comment
@DougGregor
Copy link
Member Author

swiftlang/swift#63284

@swift-ci please test

@DougGregor
Copy link
Member Author

swiftlang/swift#63284

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test Linux

@DougGregor
Copy link
Member Author

swiftlang/swift#63284

@swift-ci please test

1 similar comment
@DougGregor
Copy link
Member Author

swiftlang/swift#63284

@swift-ci please test

@DougGregor DougGregor merged commit f7667e1 into swiftlang:main Jan 29, 2023
@DougGregor DougGregor deleted the macro-expansion-context-as-protocol branch January 29, 2023 23:38
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.

1 participant