-
Notifications
You must be signed in to change notification settings - Fork 439
protocol ListBuilder #2451
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
protocol ListBuilder #2451
Conversation
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.
Removing >3000 LOC. I love it 😍
f296439
to
9f5d39b
Compare
Updated ✅
Note: The |
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.
Thank you. Let’s keep the ordering in ConvenienceInitializers.swift alphabetical, though. Or at least not break it any more than it’s already broken.
9f5d39b
to
bac1a1d
Compare
Done ✅ |
@swift-ci Please test |
Head branch was pushed to by a user without write access
bac1a1d
to
c1dc8b3
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
Introducing the
ListBuilder
protocol with a default function implementation can significantly reduce the amount of generated code in theSources/SwiftSyntaxBuilder/generated/ResultBuilders.swift
file. Additionally, it makes the codebase more comprehensible by emphasizing similarities among all the result builders and highlighting differences between them.Apart from this, the PR addresses another issue that requires detailed explanation. Two generated result builders (
ExprListBuilder
andUnexpectedNodesBuilder
) stood out from the others. They were "special" because theirExpression
was not a concrete type; instead, it was a protocol (ExprSyntaxProtocol
andSyntaxProtocol
respectively). So we were dealing with existentials here, which are not very good. Furthermore, we had to create additional extensions dedicated to these two result builders, located at the bottom of theSources/SwiftSyntaxBuilder/ResultBuilderExtensions.swift
file, accompanied by a lengthy comment.The key point is that these two result builders don't need to be treated as special cases, and they don't have to involve existentials. They can conform to the
ListBuilder
protocol, just like all the other builders do. Despite this, we can still make them work with protocols just as before, maintaining the same approach used for some other result builders in the same file (Sources/SwiftSyntaxBuilder/ResultBuilderExtensions.swift
). This eliminates the need for special treatment and enhances codebase consistency.In summary, this PR represents a refactoring. All the functionality remains unchanged. However, the refactoring is significant, making the code more structured, consistent, and efficient.