-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
Conversation
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.
@swift-ci Please smoke test |
} | ||
} | ||
return NonTokenChildren; | ||
return Data->getNumChildren(); |
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 don't see any reason this skips token children.
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 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.
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.
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(); |
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.
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; |
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 call.
Thank you for clarifying Ashley and Harlan! |
We don't guarantee
RawSyntax
nodes as unique object in the tree, while we do that forSyntaxData
. We shouldn't recreateSyntaxData
once it's built.RawSyntax
SyntaxData
Also,
Syntax
nodes have the root node in it sogetAbsolutePosition()
doesn't needRoot
parameter.CC: @nkcsgexi