-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Macros] Attached macro expansions return single string #66918
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
[Macros] Attached macro expansions return single string #66918
Conversation
swiftlang/swift-syntax#1845 |
case expandMacroResult( | ||
expandedSource: String?, | ||
diagnostics: [PluginMessage.Diagnostic] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another idea is, keep expandFreestandingMacroResult
as-is, and make expandAttachedMacroResult
be
case expandAttachedMacroResult(
expandedSource: String?,
expandedSources: [String]?,
diagnostics: [PluginMessage.Diagnostic]
)
then plugins fill either expandedSource
or expandedSources
depending on host's protocol version.
@bnbarham wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the new request
8fd9ccc
to
e122087
Compare
swiftlang/swift-syntax#1845 |
case expandMacroResult( | ||
expandedSource: String?, | ||
diagnostics: [PluginMessage.Diagnostic] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the new request
@@ -407,6 +407,29 @@ func checkMacroDefinition( | |||
} | |||
} | |||
|
|||
// Make an expansion result for '@_cdecl' function caller. | |||
func makeExpansionOutputResult( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't have to be this PR, but could this use BridgedString
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withBridgedString
can't escape the closure argument. Since we need to send the result back to C++ somehow, and currently (afaik) we don't have a way to call C++ lambda from Swift, I don't think it's super simple to use it.
Of course we can create BridgedString
using the allocated buffer instead, but I'm not sure we should do it. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, I meant the latter + having swift_ASTGen_expand*
return it instead of taking it as an output parameter. Is the concern that BridgedString
is currently only ever used in the other direction at the moment? IMO having it as the return value + a comment mentioning the caller owns the underlying buffer is enough to me. But like I said, it shouldn't block this PR so we can talk about it later.
/// Deinitialize and unset athe plugin capability stored in C++ | ||
/// 'LoadexExeucutablePlugin'. This should be called inside lock. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Deinitialize and unset athe plugin capability stored in C++ | |
/// 'LoadexExeucutablePlugin'. This should be called inside lock. | |
/// Deinitialize and unset the plugin capability stored in C++ | |
/// 'LoadedExecutablePlugin'. This should be called inside lock. |
* 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
e122087
to
eefe9dc
Compare
swiftlang/swift-syntax#1845 |
This is an effort of de-duplicating macro expansion codes between dylib plugins, executable plugins, and macro testing i.e.
MacroSystem
.swift-syntax change: swiftlang/swift-syntax#1845
collapse(expansions:for:attachedTo:)
toSwiftSyntaxMacroExpansion
SwiftSyntaxMacroExpansion.expandAttachedMacro()
now perform collapsingSwiftSyntaxMacroExpansion.expandAttachedMacroWithoutCollapsing()
to keep old behaviorgetCapability
now sends the host protocol versionmacroExpansionResult
that returns single string for bothexpandFreestandingMacro
andexpandAttachedMacro
expandFreestandingMacroResult
andexpandAttachedMacroResult
to keep compatibilitymacroExpansionResult
, and fall back to old behavior if necessaryAlso:
PluginMessage.MacroRole
definition mismatchfreeStandingDeclaration
->declaration