Skip to content

Simplify representation of AttributeLists/Modifiers on all MemberDecls.#32999

Merged
jcouv merged 42 commits intodotnet:masterfrom
CyrusNajmabadi:namespaceMods
Jun 8, 2019
Merged

Simplify representation of AttributeLists/Modifiers on all MemberDecls.#32999
jcouv merged 42 commits intodotnet:masterfrom
CyrusNajmabadi:namespaceMods

Conversation

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi commented Jan 31, 2019

The current (i.e. prior to this PR) way of representing attributes/modifiers is to specify which nodes they can go on in an adhoc manner. Some member decls specify they take attributes+modifiers, some only attributes, and some take none at all. While this is accurate as per the grammar, it makes for some ungainly APIs and complex use cases.

For example, our parser detects if you write attributes/modifiers for a namespace, but then has no place to put it. Similarly, lots of code in later layers has to write specialized code to get at modifiers/attributelists.

--

This PR attempts to simplify things (taking a page from TypeScript). After this PR, we simply define all member decls as being able to have attributes/modifiers. This means that if we run into attributes/modifiers that aren't grammatically legal, we still have a place to put them. And, later layers can more easily get/change/add these properties easily.

--

This also ties into the goal of pulling errors out of hte parser, since they affect incremental parsing, as well as making it more difficult for later phases to understand what is going on.

--

Todo:

  • tests.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner January 31, 2019 06:20
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

Tagging @jcouv @gafter

if (node.Modifiers.Count > 0)
{
diagnostics.Add(ErrorCode.ERR_BadModifiersOnNamespace, node.Modifiers[0].GetLocation());
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this moved from LanguageParser to here. This is how we've dealt with other Namespace errors that were previously syntax errors, that we wanted to move out of hte parser.

if (attributes.Count > 0)
{
namespaceDecl = AddLeadingSkippedSyntax(namespaceDecl, attributes.ToListNode());
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no need for skipped syntax (which sucks). We can totally represent this expected sort of case simply in the syntax model.

abstract Microsoft.CodeAnalysis.CSharp.Syntax.AnonymousFunctionExpressionSyntax.Body.get -> Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode
abstract Microsoft.CodeAnalysis.CSharp.Syntax.BaseArgumentListSyntax.Arguments.get -> Microsoft.CodeAnalysis.SeparatedSyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax>
abstract Microsoft.CodeAnalysis.CSharp.Syntax.BaseCrefParameterListSyntax.Parameters.get -> Microsoft.CodeAnalysis.SeparatedSyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.CrefParameterSyntax>
abstract Microsoft.CodeAnalysis.CSharp.Syntax.BaseFieldDeclarationSyntax.AttributeLists.get -> Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jcouv I'm not sure if htis is the right way to deal with publicapi.shipped.

Here's what happened. types like BaseFieldDeclarationSyntax had 'AttributeLists'. But this abstract method moved down into MemberDeclaration. To ensure that this member still exists in BaseFieldDeclarationSyntax i added an abstract-override. So you'll see that abstract-override added below. This should be source/binary compatible. But it does require updating these files accordingly.

override Microsoft.CodeAnalysis.CSharp.Syntax.NullableDirectiveTriviaSyntax.IsActive.get -> bool
override Microsoft.CodeAnalysis.CSharp.Syntax.RangeExpressionSyntax.Accept(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor visitor) -> void
override Microsoft.CodeAnalysis.CSharp.Syntax.RangeExpressionSyntax.Accept<TResult>(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<TResult> visitor) -> TResult
override abstract Microsoft.CodeAnalysis.CSharp.Syntax.BaseFieldDeclarationSyntax.AttributeLists.get -> Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

here are the abstract overrides corresponding to the members that were removed.

@@ -1,4 +1,18 @@
*REMOVED*static Microsoft.CodeAnalysis.CSharp.LanguageVersionFacts.TryParse(this string version, out Microsoft.CodeAnalysis.CSharp.LanguageVersion result) -> bool
*REMOVED*abstract Microsoft.CodeAnalysis.CSharp.Syntax.BaseFieldDeclarationSyntax.AttributeLists.get -> Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jcouv I'm not sure if htis is the right way to deal with publicapi.shipped.

Here's what happened. types like BaseFieldDeclarationSyntax had 'AttributeLists'. But this abstract method moved down into MemberDeclaration. To ensure that this member still exists in BaseFieldDeclarationSyntax i added an abstract-override. So you'll see that abstract-override added below. This should be source/binary compatible. But it does require updating these files accordingly.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner January 31, 2019 07:51
@jinujoseph jinujoseph added Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Jan 31, 2019
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@jcouv @gafter Can you ptal? Thanks!

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@jcouv @gafter Can you ptal? Thanks!

@jcouv jcouv self-assigned this Feb 19, 2019
@jcouv jcouv added this to the 16.1.P1 milestone Feb 19, 2019
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.

Change LGTM modulo some test suggestions (iteration 34). Pinged Neal to confirm the desire to make this change.

Copy link
Copy Markdown
Member

@gafter gafter left a comment

Choose a reason for hiding this comment

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

:shipit:

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

Thanks for the reviews. Now that i know this works for you guys, i'll beef up the tests :)

// [$$
// namespace Goo {
return skippedTokensTriviaSyntax is SkippedTokensTriviaSyntax;
return false;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added bonus. IDE doesn't have to try to infer what's happening from error recovery.

@jcouv
Copy link
Copy Markdown
Member

jcouv commented May 31, 2019

I'm marking as "personal" for now, to make room in our query. Ping when tests are added and ready for another look. Thanks! #Closed

@jcouv jcouv added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label May 31, 2019
@jcouv
Copy link
Copy Markdown
Member

jcouv commented Jun 3, 2019

@CyrusNajmabadi This PR looks good and is just missing a couple of tests when you get a chance. Thanks! #Closed

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@jcouv Yup! I've been a little under the weather. I'll try to get to this in hte next week. Thanks!

@jcouv jcouv removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Jun 7, 2019
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@jcouv added a few tiny tests to just hit the new scenarios.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@jcouv ? :)

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@jcouv I'm champing at the bit for this to go in :D

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

@jcouv jcouv merged commit 685348a into dotnet:master Jun 8, 2019
@CyrusNajmabadi CyrusNajmabadi deleted the namespaceMods branch June 8, 2019 22:40
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

Awesome, thanks!

agocke added a commit to agocke/roslyn that referenced this pull request Aug 6, 2019
There was a previous parsing change (dotnet#32999) which modified namespace
parsing to allow modifiers and attributes on namespaces, to improve
error recovery.

This PR contained a bug because it didn't move the incremental parsing
check to before parsing attributes and modifiers, which should now
be included in incremental parsing to prevent changes from being dropped

Fixes dotnet#37665, dotnet#37664, dotnet#37663
agocke added a commit that referenced this pull request Aug 7, 2019
There was a previous parsing change (#32999) which modified namespace
parsing to allow modifiers and attributes on namespaces, to improve
error recovery.

This PR contained a bug because it didn't move the incremental parsing
check to before parsing attributes and modifiers, which should now
be included in incremental parsing to prevent changes from being dropped

Fixes #37665, #37664, #37663
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.

5 participants