-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Use less stack space while parsing if-statements #41657
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
|
Tagging @RikkiGibson @jcouv @cston |
| this.EatToken(SyntaxKind.CloseParenToken), | ||
| this.ParseEmbeddedStatement(), | ||
| this.ParseElseClauseOpt()); | ||
| } |
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.
optimie the fast path of a normal if-statement, with no need for flow control or storage for flow control temps.
| this.ParseElseClauseOpt()); | ||
| } | ||
|
|
||
| private IfStatementSyntax ParseMisplacedElse() |
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.
MisplacedElse is a very rare case (usually just in the IDE as people are typing). it's fine for it to have it's own dedicated parsing method.
| return this.ParseIfStatement(); | ||
| case SyntaxKind.ElseKeyword: | ||
| // Including 'else' keyword to handle 'else without if' error cases | ||
| return this.ParseMisplacedElse(); |
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!
| return _syntaxFactory.IfStatement(@if, openParen, condition, closeParen, statement, elseClause); | ||
| return _syntaxFactory.IfStatement( | ||
| this.EatToken(SyntaxKind.IfKeyword, ErrorCode.ERR_ElseCannotStartStatement), | ||
| this.EatToken(SyntaxKind.OpenParenToken), |
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.
Should we call EatToken, ParseExpressionCore, etc in this way even though we know they will always fail? Basically everything before 'ParseElseClauseOpt'?
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.
Yes. That's the idea (and what the code did before). It effectively synthesizes the missing nodes/tokens we want here
ghost
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.
Auto-approval
|
Thanks! |
This gives us the ability to parse about 30 more frames during heavily recursive scenarios.