-
Notifications
You must be signed in to change notification settings - Fork 440
Remove the SyntaxData abstraction layer #2129
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
@swift-ci Please test |
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.
Ah, thank you! I've learned a lot reading through the changes, and I think this change simplifies things.
A few nitpicks and traces of SyntaxData
, but it looks like the code should work fine to me.
CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxBaseNodesFile.swift
Show resolved
Hide resolved
CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxBaseNodesFile.swift
Show resolved
Hide resolved
return self.firstToken(viewMode: .sourceAccurate) | ||
} | ||
|
||
/// Returns the first token node that is part of this syntax node. |
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.
Nit: unrelated to this PR, would be good to document parameters and what viewMode
does.
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
struct AbsoluteRawSyntax { |
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.
Nit: unrelated to this PR. It would be good to add more docs on what AbsoluteRawSyntax
does. (Also may just be because I'm a beginner and didn't have enough exposure yet, but that's probably who the documentation is for).
@natikgadzhi You are right about the documentation. I’d prefer to keep these changes out of this PR though because it’s already quite big. |
4608340
to
a2e4a3b
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
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.
Added some inline comments up for discussion
// MARK: Type information | ||
|
||
extension SyntaxProtocol { | ||
/// The kind of the syntax node, e.g. if it is a `functionDecl`. |
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.
Would it make sense to refer to the SyntaxKind.functionDecl
?
Just so the developer can navigate to the actual type?
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.
Good idea. I just copied that comment but might as well improve it.
// MARK: Children / parent | ||
|
||
public extension SyntaxProtocol { | ||
/// A sequence over the `present` children of this node. |
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.
I'm not sure I understand this doc comment.
Does that mean, not matter the view mode you provide, then it's only the present children of the node, that will be returned
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.
Oh, that comment still pre-dated the introduction of SyntaxTreeViewMode
. I removed the present
part of the comment.
} | ||
} | ||
|
||
/// AbsoluteSyntaxInfo represents the information that relates a RawSyntax to a |
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.
Is there missing some ticks around RawSyntax
?
/// different. For example two different ``FunctionDeclSyntax`` nodes in the | ||
/// might have the exact same contents but if they occur at a different |
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.
"... nodes in the might have" it sounds a bit strange to me?
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.
Removed “in the”
let rootId: UInt | ||
/// Unique value for a node within its own tree. |
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.
Some places do we have a newline after declarations. Personally I think it's easier to read.
What do you think of adding new lines after a declaration ?
0ec0cf2
to
93f69c2
Compare
@swift-ci Please test |
@swift-ci Please test macOS |
@swift-ci Please test Windows |
`SyntaxData` just held the data of the `Syntax` node and didn’t provide any additional functionality. Instead, it required unecessary casts between `Syntax` and `SyntaxData` and we were inconsistent about where we took `Syntax` or `SyntaxData`. Store the members of `SyntaxData` directly in `Syntax`.
93f69c2
to
e8e60fb
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
SyntaxData
just held the data of theSyntax
node and didn’t provide any additional functionality. Instead, it required unecessary casts betweenSyntax
andSyntaxData
and we were inconsistent about where we tookSyntax
orSyntaxData
. Store the members ofSyntaxData
directly inSyntax
.I saw slight (0.5% - 2%) performance improvements in instruction count when running swift-format with this change.
The best way to review this is commit-by-commit. The first two commits just split up files, the last commit is the actual removal of
SyntaxData
.