Skip to content

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

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 #1845 into release/5.9

(swift change: swiftlang/swift#66935)

  • 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)

rintaro added 2 commits June 26, 2023 13:24
* Move collapse(expansions:for:attachedTo:) to SwiftSyntaxMacroExpansion
* SwiftSyntaxMacroExpansion.expandAttachedMacro() now perform collapsing
* SwiftSyntaxMacroExpansion.expandAttachedMacroWithoutCollapsing() for
  to keep old behavior
* IPC message 'getCapability' now send 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 12bb25c)
Macro deifnition checking is only meant to be used by something that
expands macros (e.g. compiler). Not for macro implementation.

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

rintaro commented Jun 26, 2023

swiftlang/swift#66935
@swift-ci Please test

@rintaro rintaro merged commit 858aafd 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