Skip to content

[5.9][Macros] Attached macro expansions return single string #66935

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

rintaro
Copy link
Member

@rintaro rintaro commented Jun 26, 2023

Cherry-pick #66918 into release/5.9

(swift-syntax change: swiftlang/swift-syntax#1848)

  • Explanation: Previously the return value of expandAttachedMacro is [String]?. After the plugin returns it, the compiler joined them to make a "expanded source code". This is not good because the joining logic is in the compiler, but not in swift-syntax, which means some syntactic macro expansion logic can't use the same joining logic as the compiler. This change moves the logic to swift-syntax, and changes the IPC return value to String?.
  • Scope: Macro expansion
  • Risk: Low-Mid. This changes the plugin IPC message format. But it's versioned, this should backward compatible
  • Testing: Passed compiler test suite
  • Issue: rdar://111353623
  • Reviewer: Ben Barham (@bnbarham)

* Move collapse(expansions:for:attachedTo:) to SwiftSyntaxMacroExpansion
* SwiftSyntaxMacroExpansion.expandAttachedMacro() now perform collapsing
* SwiftSyntaxMacroExpansion.expandAttachedMacroWithoutCollapsing()
  to keep old behavior
* IPC request 'getCapability' now sends the host protocol version
* Unified IPC response 'macroExpansionResult' that returns single string
  for both 'expandFreestandingMacro' and 'expandAttachedMacro'
* Compiler accepts old 'expandFreestandingMacroResult' and
  'expandAttachedMacroResult' to keep compatibility
* Plugins check the compiler's protcol version to see if it suppports
  'macroExpansionResult', and fall back to old behavior if necessary

(cherry picked from commit eefe9dc)
@rintaro
Copy link
Member Author

rintaro commented Jun 26, 2023

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

@rintaro rintaro merged commit b13d8f6 into swiftlang:release/5.9 Jun 27, 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