Skip to content

[Syntax] Don't rebuild Syntax with RawSyntax in SyntaxVisitor #14057

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
Jan 22, 2018

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Jan 22, 2018

We don't guarantee RawSyntax nodes as unique object in the tree, while we do that for SyntaxData. We shouldn't recreate SyntaxData once it's built.

RawSyntax

Although these are tree-like in nature, they maintain no parental relationships because they can be shared among many nodes.

SyntaxData

They represent a specific piece of source code, have an absolute location, line and column number, etc.


Also, Syntax nodes have the root node in it so getAbsolutePosition() doesn't need Root parameter.

CC: @nkcsgexi

We don't guarantee RawSyntax nodes as unique object in the tree, while
we do that for SyntaxData. We shouldn't recreate SyntaxData once it was
built.
@rintaro
Copy link
Member Author

rintaro commented Jan 22, 2018

@swift-ci Please smoke test

}
}
return NonTokenChildren;
return Data->getNumChildren();
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see any reason this skips token children.

Copy link
Contributor

Choose a reason for hiding this comment

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

I remember writing this and we had some tests that, for some reason, expected it to skip token children. Didn't want to mess with it at the time, because I was doing a behavior-preserving refactor. As far as I'm concerned, it should not skip tokens.

Copy link
Contributor

Choose a reason for hiding this comment

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

Originally, we defined children as something indicating recursive structure in the tree but I agree, this should not skip tokens. This may indicate the name children isn't quite right. FWIW, Roslyn likes to use the term slots, similar to how we also use the term layout. Whether you can descend into a node is irrelevant to the number of items in the syntax's layout.

}
}
return NonTokenChildren;
return Data->getNumChildren();
Copy link
Contributor

Choose a reason for hiding this comment

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

Originally, we defined children as something indicating recursive structure in the tree but I agree, this should not skip tokens. This may indicate the name children isn't quite right. FWIW, Roslyn likes to use the term slots, similar to how we also use the term layout. Whether you can descend into a node is irrelevant to the number of items in the syntax's layout.

@@ -181,7 +184,7 @@ class Syntax {

/// Get the absolute position of this raw syntax: its offset, line,
/// and column.
AbsolutePosition getAbsolutePosition(SourceFileSyntax Root) const;
AbsolutePosition getAbsolutePosition() const;
Copy link
Contributor

Choose a reason for hiding this comment

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

Good call.

@nkcsgexi nkcsgexi merged commit 98fc073 into swiftlang:master Jan 22, 2018
@rintaro
Copy link
Member Author

rintaro commented Jan 23, 2018

Thank you for clarifying Ashley and Harlan!

@rintaro rintaro deleted the syntax-visitor-no-raw branch January 23, 2018 16:25
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.

4 participants