-
Notifications
You must be signed in to change notification settings - Fork 440
[Macros] Cache parsed syntax tree in compiler plugins #2682
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] Cache parsed syntax tree in compiler plugins #2682
Conversation
@swift-ci Please test |
/// Syntax added by `add(_:)` method. Keyed by the `id` of the node. | ||
private var knownSourceSyntax: [Syntax.ID: KnownSourceSyntax] = [:] | ||
|
||
init(syntaxrRegistry: ParsedSyntaxRegistry) { |
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.
init(syntaxrRegistry: ParsedSyntaxRegistry) { | |
init(syntaxRegistry: ParsedSyntaxRegistry) { |
The compiler may send the same syntax to the plugins multiple times. For example, 'memberAttribute' macro request contains parent nominal decl syntax, and the compiler sends a request for each members. Parsing it multiple times is a waste. rdar://129624305
d0eb2f7
to
3c23a0e
Compare
@swift-ci Please test |
3c23a0e
to
baff373
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
1 similar comment
@swift-ci Please test Windows |
@swift-ci Please test Windows |
[6.0][Macros] Cache parsed syntax tree in compiler plugins #2682
@@ -24,6 +24,49 @@ import SwiftSyntax | |||
import SwiftSyntaxMacros | |||
#endif | |||
|
|||
/// Caching parser for PluginMessage.Syntax | |||
class ParsedSyntaxRegistry { |
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.
Naming nitpick: A registry for me is something that stores long-lived values (possibly even eternal), which is quite the opposite of a cache. Would ParsedSyntaxCache
be a better name?
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.
Heh, in fairness it was originally the first. The LRU was added after 😅. But yeah, Cache is probably the better name now.
The compiler may send the same syntax to the plugins multiple times.
For example,
memberAttribute
macro request contains parent nominal decl syntax, and the compiler sends a request for each members. Parsing it multiple times is a waste.rdar://129624305