Skip to content

Fix !! incremental parsing#59977

Merged
RikkiGibson merged 4 commits intodotnet:mainfrom
Youssef1313:59580-exclamation-exclamation
Mar 8, 2022
Merged

Fix !! incremental parsing#59977
RikkiGibson merged 4 commits intodotnet:mainfrom
Youssef1313:59580-exclamation-exclamation

Conversation

@Youssef1313
Copy link
Copy Markdown
Member

@Youssef1313 Youssef1313 commented Mar 6, 2022

Fixes #59580

cc @RikkiGibson @tmat

Relates to test plan #36024

@Youssef1313 Youssef1313 requested a review from a team as a code owner March 6, 2022 09:40
@ghost ghost added Community The pull request was submitted by a contributor who is not a Microsoft employee. Area-Compilers labels Mar 6, 2022
Comment thread src/Compilers/CSharp/Portable/Parser/LanguageParser.cs Outdated
Comment thread src/Compilers/CSharp/Portable/Parser/LanguageParser.cs Outdated
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

Look for a method that has 'Fabricated' in its name. That should be what we are updating.

@Youssef1313
Copy link
Copy Markdown
Member Author

There is IsFabricatedToken. I'll see if updating it fixes the issue.

Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

Needs a tweak. If you can't find the relevant method, LMK and i can hunt it down on monday. THanks!

Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

LGTM!

@Youssef1313
Copy link
Copy Markdown
Member Author

@CyrusNajmabadi Thanks for the hint!

{
case SyntaxKind.GreaterThanGreaterThanToken:
case SyntaxKind.GreaterThanGreaterThanEqualsToken:
case SyntaxKind.ExclamationExclamationToken:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

my bad on forgetting about this @Youssef1313 @RikkiGibson . The merging tokens bit totally should have triggered things for me!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider adding a note to MergeAdjacent to mention this method should be updated when used.

Copy link
Copy Markdown
Contributor

@cston cston Mar 7, 2022

Choose a reason for hiding this comment

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

Consider adding a note to MergeAdjacent to mention this method should be updated when used.

It looks LanguageParser.ParseLambdaExpression() also uses MergeAdjacent() for SyntaxKind.EqualsGreaterThanToken. If there's a potential incremental parsing bug there, we should open an issue.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

good catch!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider adding an assert to MergeAdjacent(): Debug.Assert(IsFabricatedToken(kind));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Logged #60002.

@RikkiGibson RikkiGibson self-assigned this Mar 6, 2022
Copy link
Copy Markdown
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 3)

@jcouv
Copy link
Copy Markdown
Member

jcouv commented Mar 7, 2022

@RikkiGibson @cston for second review. Thanks

@jcouv jcouv self-assigned this Mar 7, 2022
@@ -432,7 +463,6 @@ public void TestStatementToGlobalStatementChange()
SyntaxKind.IdentifierName,
SyntaxKind.SemicolonToken);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

}

Consider adding back the blank line.

Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

changing my vote. we're jsut asking to eb be bitten by the other merged token. we should just fix the code now and not have some random tree corruption issue someone has to figure out months down the line :)

@RikkiGibson
Copy link
Copy Markdown
Member

changing my vote. we're jsut asking to eb be bitten by the other merged token. we should just fix the code now and not have some random tree corruption issue someone has to figure out months down the line :)

making sure I understand your concern here. Are you asking that #60002 be addressed now and not afterwards? Since we do have #60005 open currently which should address it.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

#60005 open currently which should address it.

That adds the assert (which is good). But i see no code change that adds the merged token taht the parser is creating to the blnder-reader to make sure we don't try to reuse that. or is the theory there that that's ok because => is a token that the lexer would produce? if so, i could be offbase and maybe this change is totally fine, just very subtle.

Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

retracting my objection.

@CyrusNajmabadi CyrusNajmabadi dismissed their stale review March 7, 2022 22:29

not clear enough if that is hte actual fix.

@RikkiGibson
Copy link
Copy Markdown
Member

@Youssef1313 do you think it's reasonable to do #59977 (comment) as part of this PR, just to ensure it's all out of the way?

@RikkiGibson RikkiGibson merged commit 15bf05a into dotnet:main Mar 8, 2022
@ghost ghost added this to the Next milestone Mar 8, 2022
@Youssef1313 Youssef1313 deleted the 59580-exclamation-exclamation branch March 8, 2022 04:29
@Youssef1313
Copy link
Copy Markdown
Member Author

Youssef1313 commented Mar 8, 2022

@RikkiGibson This one is now already merged. I'm not sure it will be easy to reproduce the problem with lambdas parsing.

The else part of this condition will eat the fabricated token.

if (equalsToken != null)
{
// we only get an equals token if we had !!=> or !=> (enforced by IsPossibleLambdaExpression).
// So we must have a greater than token following. If not, some invariant is badly broken.
var greaterThan = this.EatToken();
Debug.Assert(greaterThan.Kind == SyntaxKind.GreaterThanToken);
arrow = MergeAdjacent(equalsToken, greaterThan, SyntaxKind.EqualsGreaterThanToken);
}
else
{
// Case x=>, x =>
arrow = this.EatToken(SyntaxKind.EqualsGreaterThanToken);
}

Per @CyrusNajmabadi explanation, this is in general not correct because the merged token can be moved to a place where it contextually have a different meaning and hence a different SyntaxKind. But for this specific case:

  • The else is needed because lexer can pass us EqualsGreaterThanToken. The = and > gets separated only when there is a !!=> with no space between !! and =>. The !!=> thing is handed to parser as !, !=, and >. Then parameter null checking will merge the !! and leave the = and > as individual tokens.

Since => cannot have a different SyntaxKind when moved from one place in the tree to the other, I think there is no bug (currently) here. A bug will occur if => started to have different meanings.

The question is:

Should we add it to IsFabricatedToken anyway just in case => had a different meaning in future. Or probably leave everything as is now until an issue is reported?

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

Labels

Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issues with formatting and whitespace around !! annotation

6 participants