-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Parser] Don't modify the current token kind when cutting off parsing #40065
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
|
@swift-ci Please smoke test |
bnbarham
left a comment
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.
Nice!
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 assume this was from me, obviously doesn't matter but could remove if you wanted it to be a little neater :P
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.
Whatever. The file hit the issue before and now doesn’t hit it any longer so I don’t want to change it anymore.
37cc359 to
55f1bf9
Compare
|
@swift-ci Please smoke test |
55f1bf9 to
21aa2d3
Compare
|
@swift-ci Please smoke test |
21aa2d3 to
d725c51
Compare
|
@swift-ci Please smoke test |
bnbarham
left a comment
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.
Nice, much cleaner!
lib/Parse/Parser.cpp
Outdated
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.
Can this ever be a nullptr? BufferID is set from BaseLexer->getBufferID() which would suggest not, in which case maybe &BaseLexer makes more sense?
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 idea. Changed it to a reference.
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.
The crash here was the assertion failure right? Would it be worth adding // REQUIRES: asserts or a comment to that effect in here? The test does work either way so maybe doesn't matter, but IMO it'd be nice to differentiate it from the existing structure_overflow*.swift ones.
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.
Added a comment.
Previously, when we reached the maximum nesting level, we changed the current token’s kind to an EOF token. A lot of places in the parser are not set up to expect this token change. The intended workaround was to check whether pushing a structure marker failed (which would change the token kind) and bail out parsing if this happened. This was fragile and caused assertion failures in assert builds. Instead of changing the current token’s kind, and failing to push the structure marker, let the lexer know that it should cut off lexing, essentially making the input buffer stop at the current position. The parser will continue to consume its current token (`Parser.Tok`) and the next token that’s already lexed in the lexer (`Lexer.NextToken`) before reaching the emulated EOF token. Thus two more tokens are parsed than before, but that shouldn’t make much of a difference.
d725c51 to
b888dc0
Compare
|
@swift-ci Please smoke test |
Instead, let the lexer know that it should interpret the next token to be lexed as an EOF token. This makes parsing cutoff a lot more stable because the parser is not expecting the current token kind to change in a lot of places.
Technically, this causes two more tokens to be parsed than in the previous implementation (namely
Parser.TokandLexer.NextToken) but since we bail out at a fairly low nesting level, this shouldn't make a big difference.