Skip to content

[libSyntax] Store Range of ParsedRawSyntaxNode in dedicated field #36274

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
Mar 8, 2021

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Mar 4, 2021

Essentially all ParsedRawSyntaxNode types have a range associated with them, so let's just store it in a dedicated field with a common getter.

Additionally, this cleans up the recorded storage to just contain an OpaqueSyntaxNode. When deferred nodes are being handled by SyntaxParseActions, we can use this OpaqueNode storage to store either recorded or deferred node data, which is left to be interpreted by the SyntaxParseAction.

We could also rewrite TokLoc and TokLength in DeferredTokenNode in terms of the new Range property for now. But since I’ll move DeferredTokenNode down to SyntaxParseActions in the next PR which also needs the range information, it’s easier to keep the information duplicated for now.

@ahoppen ahoppen requested a review from rintaro March 4, 2021 07:51
@ahoppen
Copy link
Member Author

ahoppen commented Mar 4, 2021

@swift-ci Please smoke test

@ahoppen
Copy link
Member Author

ahoppen commented Mar 4, 2021

@swift-ci Please smoke test Windows

llvm_unreachable("node not deferred");
}
}
CharSourceRange getRange() const { return Range; }
Copy link
Member

Choose a reason for hiding this comment

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

While you are here, please add a comment that this includes trivia ranges.

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’ll do.

unsigned len = leadTriviaLen + DeferredToken.TokLength + trailTriviaLen;

return CharSourceRange{begin, len};
}
CharSourceRange getDeferredTokenRange() const {
Copy link
Member

Choose a reason for hiding this comment

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

As far as I can see, this getDeferredTokenRange()(doesn't include trivia) is used only in ParsedRawSyntaxRecorder and it's just for calculating the range with trivia after all. Can we abolish this method? If you prefer not to remove this, please add a comment to clarify this does not include trivia ranges.

Copy link
Member Author

Choose a reason for hiding this comment

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

It’ll be gone in the next PR (here). I know that this splitting between PRs sometimes feels a little bit random. Sorry about that.

Essentially all ParsedRawSyntaxNode types have a range associated with
them, so let's just store it in a dedicated field with a common getter.

Additionally, this cleans up the recorded storage to just contain an
OpaqueSyntaxNode. When deferred nodes are being handled by
SyntaxParseActions, we can use this OpaqueNode storage to store either
recorded or deferred node data, which is left to be interpreted by the
SyntaxParseAction.
@ahoppen ahoppen force-pushed the pr/range-in-parsedrawsyntaxnode branch from 69c4f88 to 7be748d Compare March 5, 2021 13:43
@ahoppen
Copy link
Member Author

ahoppen commented Mar 5, 2021

@swift-ci Please smoke test

@ahoppen ahoppen merged commit 26dc01b into swiftlang:main Mar 8, 2021
@ahoppen ahoppen deleted the pr/range-in-parsedrawsyntaxnode branch March 8, 2021 09:21
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