Skip to content

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

Merged
merged 5 commits into from
Sep 7, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Aug 31, 2023

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.

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.

@ahoppen ahoppen requested review from rintaro and bnbarham August 31, 2023 20:55
@ahoppen
Copy link
Member Author

ahoppen commented Aug 31, 2023

@swift-ci Please test

Copy link
Contributor

@natikgadzhi natikgadzhi left a 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.

return self.firstToken(viewMode: .sourceAccurate)
}

/// Returns the first token node that is part of this syntax node.
Copy link
Contributor

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 {
Copy link
Contributor

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).

@ahoppen
Copy link
Member Author

ahoppen commented Sep 1, 2023

@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.

@ahoppen ahoppen force-pushed the ahoppen/kill-syntaxdata branch from 4608340 to a2e4a3b Compare September 1, 2023 20:26
@ahoppen
Copy link
Member Author

ahoppen commented Sep 1, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Sep 1, 2023

@swift-ci Please test Windows

Copy link
Contributor

@kimdv kimdv left a 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`.
Copy link
Contributor

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?

Copy link
Member Author

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.
Copy link
Contributor

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

Copy link
Member Author

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
Copy link
Contributor

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?

Comment on lines 52 to 53
/// different. For example two different ``FunctionDeclSyntax`` nodes in the
/// might have the exact same contents but if they occur at a different
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed “in the”

Comment on lines 67 to 69
let rootId: UInt
/// Unique value for a node within its own tree.
Copy link
Contributor

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 ?

@ahoppen ahoppen force-pushed the ahoppen/kill-syntaxdata branch from 0ec0cf2 to 93f69c2 Compare September 5, 2023 19:09
@ahoppen
Copy link
Member Author

ahoppen commented Sep 5, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Sep 6, 2023

@swift-ci Please test macOS

@ahoppen
Copy link
Member Author

ahoppen commented Sep 6, 2023

@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`.
@ahoppen ahoppen force-pushed the ahoppen/kill-syntaxdata branch from 93f69c2 to e8e60fb Compare September 6, 2023 23:22
@ahoppen
Copy link
Member Author

ahoppen commented Sep 6, 2023

@swift-ci Please test

@ahoppen ahoppen enabled auto-merge September 6, 2023 23:33
@ahoppen
Copy link
Member Author

ahoppen commented Sep 6, 2023

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 361a140 into swiftlang:main Sep 7, 2023
@ahoppen ahoppen deleted the ahoppen/kill-syntaxdata branch September 7, 2023 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants