-
Notifications
You must be signed in to change notification settings - Fork 439
[SwiftParser] Improve ergonomics for initializers of RawXXXSyntax
#2805
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
[SwiftParser] Improve ergonomics for initializers of RawXXXSyntax
#2805
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.
Thank you. That does simplify the construction of raw syntax nodes.
I am not personally a huge fan of using .init
to create objects. It’s easy to write but I think it hurts readability along the way because you don’t know which object is being constructed. Could you change those to the actual type names or stick with the enum case name if we don’t actually need to go through the initializer?
CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxNodesFile.swift
Show resolved
Hide resolved
CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/RawSyntaxNodesFile.swift
Outdated
Show resolved
Hide resolved
39015d3
to
9e630fd
Compare
I've reverted most changes back to their original states, however for the convenience initializers I've implemented another idea, e.g. /// convenience init for `decl`
public init(decl: some RawDeclSyntaxNodeProtocol) {
self = .decl(RawDeclSyntax(decl))
} The call sites should be more readable now? item: .init(expr: RawMissingExprSyntax(arena: self.arena)), |
9e630fd
to
e95eff3
Compare
added convenience initializers for choice enum changed parameter types in RawNode's initializers from concrete types to generic whenever possible
e95eff3
to
ec9a775
Compare
@swift-ci Please test |
1 similar comment
@swift-ci Please test |
@swift-ci Please test Windows |
This PR aims to improve developer ergonomics when using the designated initializers of raw syntax nodes. Simply put, it's through achieving feature parity with the non-raw side.
Prefer generic types over type erasure types
Currently the designated initializer of
RawXXXSyntax
always uses type-erased types instead of generic types as parameter types, leading to much clunkiness, e.g.The initializer body, however, only invokes
pattern.raw
, therefore we could just replacepattern: RawPatternSyntax
withpattern: some RawPatternSyntaxNodeProtocol
transparently,Actually it's what
PatternExprSyntax.init
has been doing,Generate convenience generic initializers for choices enum
e.g.
So call sites might get rid of type erasure as follows,
Remove type erasure in call sites
This PR has removed unnecessary uses of type-erased types in many call sites thanks to the new initializers.