-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,10 @@ | |
// NOTE: Types in this file should be self-contained and should not depend on any non-stdlib types. | ||
|
||
internal enum HostToPluginMessage: Codable { | ||
/// Get capability of this plugin. | ||
case getCapability | ||
/// Send capability of the host, and get capability of the plugin. | ||
case getCapability( | ||
capability: PluginMessage.HostCapability? | ||
) | ||
|
||
/// Expand a '@freestanding' macro. | ||
case expandFreestandingMacro( | ||
|
@@ -49,11 +51,19 @@ internal enum PluginToHostMessage: Codable { | |
capability: PluginMessage.PluginCapability | ||
) | ||
|
||
/// Unified response for freestanding/attached macro expansion. | ||
case expandMacroResult( | ||
expandedSource: String?, | ||
diagnostics: [PluginMessage.Diagnostic] | ||
) | ||
Comment on lines
+55
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another idea is, keep case expandAttachedMacroResult(
expandedSource: String?,
expandedSources: [String]?,
diagnostics: [PluginMessage.Diagnostic]
) then plugins fill either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer the new request |
||
|
||
// @available(*, deprecated: "use expandMacroResult() instead") | ||
case expandFreestandingMacroResult( | ||
expandedSource: String?, | ||
diagnostics: [PluginMessage.Diagnostic] | ||
) | ||
|
||
// @available(*, deprecated: "use expandMacroResult() instead") | ||
case expandAttachedMacroResult( | ||
expandedSources: [String]?, | ||
diagnostics: [PluginMessage.Diagnostic] | ||
|
@@ -66,7 +76,11 @@ internal enum PluginToHostMessage: Codable { | |
} | ||
|
||
/*namespace*/ internal enum PluginMessage { | ||
static var PROTOCOL_VERSION_NUMBER: Int { 4 } // Added 'loadPluginLibrary'. | ||
static var PROTOCOL_VERSION_NUMBER: Int { 5 } // Added 'expandMacroResult'. | ||
|
||
struct HostCapability: Codable { | ||
var protocolVersion: Int | ||
} | ||
|
||
struct PluginCapability: Codable { | ||
var protocolVersion: Int | ||
|
@@ -86,7 +100,7 @@ internal enum PluginToHostMessage: Codable { | |
|
||
enum MacroRole: String, Codable { | ||
case expression | ||
case freeStandingDeclaration | ||
case declaration | ||
case accessor | ||
case memberAttribute | ||
case member | ||
|
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 thatBridgedString
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.