Skip to content
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

Merged
merged 10 commits into from
Nov 18, 2022

Conversation

CyrusNajmabadi
Copy link
Member

No description provided.

@@ -8760,10 +8759,6 @@ private bool IsPossibleStatement(bool acceptAccessibilityMods)
case SyntaxKind.IdentifierToken:
return IsTrueIdentifier();

case SyntaxKind.CatchKeyword:
case SyntaxKind.FinallyKeyword:
return !_isInTry;
Copy link
Member Author

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, "}"),
Copy link
Member Author

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,
Copy link
Member Author

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
Copy link
Member Author

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.

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 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
Copy link
Member Author

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)
Copy link
Member Author

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.

Copy link
Member

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.

@jcouv jcouv self-assigned this Nov 17, 2022
@CyrusNajmabadi
Copy link
Member Author

Tagging @cston as well.

Copy link
Member

@jcouv jcouv left a 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;
Copy link
Member

@jcouv jcouv Nov 18, 2022

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

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member

@jcouv jcouv left a 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)

@CyrusNajmabadi
Copy link
Member Author

@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)
Copy link
Member

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.

@CyrusNajmabadi
Copy link
Member Author

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 :-)

@CyrusNajmabadi CyrusNajmabadi merged commit ccf9a90 into dotnet:main Nov 18, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the tryParsing branch November 18, 2022 22:19
@ghost ghost added this to the Next milestone Nov 18, 2022
@jcouv
Copy link
Member

jcouv commented Nov 18, 2022

Please remember to squash compiler PRs

@CyrusNajmabadi
Copy link
Member Author

Sorry! My bad. :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants