-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Move context-sensitive parsing to context-free parsing. #65480
Conversation
@@ -8760,10 +8759,6 @@ private bool IsPossibleStatement(bool acceptAccessibilityMods) | |||
case SyntaxKind.IdentifierToken: | |||
return IsTrueIdentifier(); | |||
|
|||
case SyntaxKind.CatchKeyword: | |||
case SyntaxKind.FinallyKeyword: | |||
return !_isInTry; |
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.
this was actually highly undesirable in the parser. it effectively made the handling of blocks, and 'catch/finally' tokens context-sensitive. While unlikely to cause bad issues, it means you could end up in some sort of wonky incremental scenario where something like a block might move inside/outside of a try, and get reused, despite the context not being the same (and thus meaning that non-incremental parsing would produce a different tree).
@@ -4114,24 +4114,39 @@ public static int Main() | |||
"; | |||
// Extra Errors | |||
ParseAndValidate(test, | |||
// (12,13): error CS1524: Expected catch or finally | |||
// } | |||
Diagnostic(ErrorCode.ERR_ExpectedEndTry, "}"), |
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.
this went away because the catch already has syntax errors, so the later error is suppressed now.
@@ -14038,15 +14025,13 @@ private new ResetPoint GetResetPoint() | |||
return new ResetPoint( | |||
base.GetResetPoint(), | |||
_termState, | |||
_isInTry, |
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.
removing context we used to have save/restore (but didn't store within nodes (like we do with our other contextual flags)).
@@ -32,7 +32,6 @@ internal partial class LanguageParser : SyntaxParser | |||
|
|||
private int _recursionDepth; | |||
private TerminatorState _termState; // Resettable | |||
private bool _isInTry; // Resettable | |||
private bool _checkedTopLevelStatementsFeatureAvailability; // Resettable |
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.
this flag is likely bad as well.
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.
(it is, and it is removed in my sibling pr)
@@ -32,7 +32,6 @@ internal partial class LanguageParser : SyntaxParser | |||
|
|||
private int _recursionDepth; | |||
private TerminatorState _termState; // Resettable | |||
private bool _isInTry; // Resettable |
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.
less contextual state (explained below why thisi s bad).
@@ -14096,5 +14086,44 @@ private new struct ResetPoint | |||
node = this.AddTrailingSkippedSyntax(node, trailingTrash.Node); | |||
return node; | |||
} | |||
|
|||
private static bool ContainsErrorDiagnostic(GreenNode node) |
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.
copied out from the other PR. if this goes in first, i'll unify that one on his.
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 current diff shows this being deleted from above and added here.
Tagging @cston as well. |
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.
Done with review pass (iteration 5). Much like the simplification! Minor comment only.
@@ -8840,10 +8800,6 @@ private bool IsPossibleStatement(bool acceptAccessibilityMods) | |||
case SyntaxKind.IdentifierToken: | |||
return IsTrueIdentifier(); | |||
|
|||
case SyntaxKind.CatchKeyword: | |||
case SyntaxKind.FinallyKeyword: | |||
return !_isInTry; |
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.
nit: If this is still called on those keywords, consider handling catch and finally explicitly and returning true for clarity
Otherwise, consider asserting/throwing #Closed
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.
on the fence... this def can be called on those (this is IsPossibleStatement). but explicitly hitting them and stating that they are not statements (which is what we want so that higher up try-statements actually will consume error catches/finallys into them), seems inverted from how this method generally works. specifically that it says the cases that def are statements, not hte cases that are not.
I would be ok with having these there commented otu saying why we explicitly do not consider them the start of statements.
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.
Let's leave as-is then
fcd80b6
to
dc8e601
Compare
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.
LGTM Thanks (iteration 10)
@cston ptal if available. Thanks! |
@@ -14096,5 +14086,44 @@ private new struct ResetPoint | |||
node = this.AddTrailingSkippedSyntax(node, trailingTrash.Node); | |||
return node; | |||
} | |||
|
|||
private static bool ContainsErrorDiagnostic(GreenNode node) |
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 current diff shows this being deleted from above and added here.
It was added in multiple different PRs. This just removes the dupe when they merged together :-) |
Please remember to squash compiler PRs |
Sorry! My bad. :-( |
No description provided.