Skip to content

Move AbsoluteSyntaxInfo to "edge" SyntaxData information #659

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 1 commit into from
Sep 2, 2022

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Aug 30, 2022

The root node doesn't need to hold its AbsoluteSyntaxInfo because it's always zero. Move this information to "edge" data so only non-root nodes hold the "absolute info". Introduce an "edge" info struct, and use it with indirect enum case instead of SyntaxBox.

Previously the structure of SyntaxData was:

  • AbsoluteRawSyntax
    • RawSyntax
    • AbsoluteSyntaxInfo
  • Tagged union of
    • SyntaxArena
    • SyntaxBox
      • Parent SyntaxData

Now:

  • RawSyntax node
  • Tagged union of:
    • SyntaxData.Info.Root
      • SyntaxArena
    • SyntaxData.Info.Edge (indirect case)
      • Parent SyntaxData
      • AbsoluteSyntaxInfo

This reduces the size of SyntaxData to 2 words.

Also SyntaxData.parent now returns SyntaxData instead of Syntax. SyntaxData should not rely on Syntax API at all.

As for the performance, compared to pre #635, this improves testEmptyAnyVistorPerformance/testEmptyRewriterPerformance/testEmptyVisitorPerformance by 5-10%.

@rintaro rintaro requested a review from ahoppen as a code owner August 30, 2022 17:01
@rintaro
Copy link
Member Author

rintaro commented Aug 30, 2022

@swift-ci Please test

@rintaro rintaro force-pushed the syntaxdata-indirect-edge branch from 3255377 to 96d70de Compare August 30, 2022 23:38
@rintaro
Copy link
Member Author

rintaro commented Aug 30, 2022

@swift-ci Please test

@rintaro rintaro mentioned this pull request Sep 1, 2022
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

I’m not really comfortable with the name edge. Otherwise LGTM.

init(_ value: Syntax) {
self.value = value
// For non-root nodes.
struct Edge {
Copy link
Member

Choose a reason for hiding this comment

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

I don’t like the term edge here. To me the edge would be information that’s related to the parent-child relationship between two nodes. But absoluteInfo is information about this node in the entire tree.

It’s not a great name but NonRoot would make me stumble a lot less.

@ahoppen
Copy link
Member

ahoppen commented Sep 2, 2022

rdar://99492992

The root node doesn't need to hold its `AbsoluteSyntaxInfo` because
it's always zero. Move this information to "edge" data so only non-root
nodes hold the "absolute info". Introduce an "edge" info struct, and use
it with `indirect` enum case instead of `SyntaxBox`.

Previously the structure of `SyntaxData` was:
 * AbsoluteRawSyntax
   * RawSyntax
   * AbsoluteSyntaxInfo
 * Tagged union of
   * SyntaxArena
   * SyntaxBox
     * Parent SyntaxData

Now:
 * RawSyntax node
 * Tagged union of:
   * SyntaxData.Info.Root
     * SyntaxArena
   * SyntaxData.Info.Edge (indirect case)
     * Parent SyntaxData
     * AbsoluteSyntaxInfo

This reduces the size of `SyntaxData` to 2 words.

Also `SyntaxData.parent` now returns `SyntaxData` instead of `Syntax`.
`SyntaxData` should not rely on `Syntax` API at all.
@rintaro rintaro force-pushed the syntaxdata-indirect-edge branch from 96d70de to 53d91e8 Compare September 2, 2022 17:23
@rintaro
Copy link
Member Author

rintaro commented Sep 2, 2022

@swift-ci Please test

1 similar comment
@rintaro
Copy link
Member Author

rintaro commented Sep 2, 2022

@swift-ci Please test

@rintaro rintaro merged commit fe12b6a into swiftlang:main Sep 2, 2022
@rintaro rintaro deleted the syntaxdata-indirect-edge branch September 2, 2022 21:03
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.

2 participants