-
Notifications
You must be signed in to change notification settings - Fork 440
Model SyntaxVisitor as a class #158
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
9ee9449
to
11a32cf
Compare
@swift-ci Please test |
Build failed |
Avoid the overhead of existentials by modelling the entire syntax node hierarchy using structs with custom casting functions. This results in a major performance gain for SyntaxRewriter.
Improve the performance of SyntaxRewriter by avoiding unnecessary casts, reusing the SyntaxBox and eliminating .enumerated()
Refactor the implementation to match SyntaxRewriter, thereby gaining the same performance benefits.
Otherwise it requires a lot of boilerplate to return the Syntax node's type in the lit-test-helper.
Since all the methods on the SyntaxVisitor were mutating, it makes more sense to model the SyntaxVisitor as a class. This also increases visitation performance.
11a32cf
to
bc5fef3
Compare
@swift-ci Please test |
Build failed |
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.
The original change that turned SyntaxVisitor
into a protocol caused an unfortunate (and large) amount of churn on swift-format's rule pipeline due to some tricky interactions between generics, protocols, and mutability. Even though it's a little sad to see all the work to fix that having to be reverted (we never migrated again to SyntaxVisitorBase
), it's absolutely the right thing in the long run. 👍
…ignores_discretionary Restore some discretionary newlines from PR swiftlang#143
Since all the methods on the SyntaxVisitor were mutating, it makes more sense to model the SyntaxVisitor as a class. This also increases visitation performance.
API Change
SyntaxVisitor
SyntaxVisitor
need to become classesSyntaxAnyVisitor
SyntaxAnyVisitor
need to become classesPerformance improvements
Performance measurements were done by running an empty
SyntaxRewriter
/SyntaxVisitor
on a Swift file with ~5000 lines of code. The baseline is the current performance of SwiftSyntax before #155 is merged.Empty
SyntaxVisitor
Empty
SyntaxAnyVisitor