-
Notifications
You must be signed in to change notification settings - Fork 441
Update CodeGeneration to use new convenience initializers #1019
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
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.
One minor comment, otherwise I'd say this looks good!
StructDecl( | ||
attributes: [CustomAttribute(trailingTrivia: .newline, attributeName: Type("resultBuilder"))], | ||
attributes: [.customAttribute(CustomAttribute(trailingTrivia: .newline, attributeName: Type("resultBuilder")))], | ||
modifiers: [DeclModifier(name: .public)], | ||
identifier: "\(type.syntaxKind)Builder") { |
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.
Any reason not to use the parsing initializer here too, i.e. something along the lines of
StructDecl("@resultBuilder public struct \(type.syntaxKind)Builder") {
...
}
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.
Thanks, I just missed that.
TBH I don't like where does it go with that new feature. Instead of clear calls structure it now just bunch of interpolated strings. Why bother with different statements if it could be just several strings for the whole file, like |
That’s very interesting because I very much prefer the new design because it’s IMO a lot easier to read. My idea for SwiftSyntaxBuilder currently was that you use the parser integration (aka string literals) for all the boilerplate that is mostly statically known while still being able to use result builder and the tree structure of the SwiftSyntax tree to
But that’s just my take. Going back to the example that @fwcd pointed out above, did you prefer StructDecl(
attributes: [.customAttribute(CustomAttribute(trailingTrivia: .newline, attributeName: Type("resultBuilder")))],
modifiers: [DeclModifier(name: .public)],
identifier: "\(type.syntaxKind)Builder") { over StructDecl("@resultBuilder public struct \(type.syntaxKind)Builder") { If yes, I would be very interested to hear the reasons. |
033cbdf
to
2c04f34
Compare
@swift-ci Please test |
I can kind of see the point of @evnik, we're basically trading compile-time type-safety (to a degree) for convenience/conciseness/readability. E.g. things like |
That is correct, we are trading some of the compile-time safety for generation-time safety (the parser will catch the same kind of issues that would previously have been caught while compiling the generation files but as @fwcd mentioned you very rarely compile the generation files without running them, so I think it doesn’t actually make a huge difference. IMO the real benefits of the new APIs are that
|
Since this is “just” the update of CodeGeneration for an API that already exists, I’m going to merge. I would still like to continue the discussion. |
Update CodeGeneration to take advantage of #1012