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

Use 7.2 language features in Roslyn #26010

Merged
merged 9 commits into from
Apr 13, 2018
Merged

Conversation

VSadov
Copy link
Member

@VSadov VSadov commented Apr 6, 2018

Trying to use the new language features in the Roslyn codebase.

@VSadov VSadov requested review from a team as code owners April 6, 2018 23:57
@VSadov VSadov changed the title [WIP] Use new features [WIP] Use new language features in Roslyn Apr 7, 2018
@VSadov
Copy link
Member Author

VSadov commented Apr 7, 2018

@dotnet/roslyn-compiler - FYI. Trying to use new language features in Roslyn.

@VSadov
Copy link
Member Author

VSadov commented Apr 7, 2018

Ref reassignments work very nicely in the AVL tree implementation of SmallDictionary. 👍

@VSadov
Copy link
Member Author

VSadov commented Apr 7, 2018

readonly structs and in parameters work fine too.

Another nice part is that the changes are not disrupting existing code and can be done incrementally.
That was one of the design goals.


currentNodeParent = currentNode;
currentNode = currentNode.Right;
currentNode = new AvlNode(hashCode, key, value);
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this... this is how I usually implement things in C++, it simplifies the code a lot and also removes a special case for inserting the root node.

Copy link
Contributor

Choose a reason for hiding this comment

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

also removes a special case for inserting the root node

would that be possible here by restructuring the loop and moving the null check?

{
_triviaStack.PushLeadingTrivia(ref token);
_triviaStack.PushLeadingTrivia(in token);
Copy link
Member

@sharwell sharwell Apr 7, 2018

Choose a reason for hiding this comment

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

❓ Why explicit? At this point it behaves like passing by value which seems to be less noisy. #WontFix

Copy link
Member Author

@VSadov VSadov Apr 10, 2018

Choose a reason for hiding this comment

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

It was explicit ref originally. I assumed that ref was used for performance which makes it important that we continue passing the token by direct reference. That is where you use in at the call site - to make sure there is no copying.

Basically - I used the "ref for performance reasons" pattern as an indication of perf-sensitive codepaths and used explicit in there.
I think it makes sense to prevent unexpected perf regressions or at least as a self-documenting way to say that avoiding copies is very important. #WontFix

@@ -6,7 +6,7 @@

namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax
{
internal struct BlendedNode
internal readonly struct BlendedNode
Copy link
Member

@sharwell sharwell Apr 7, 2018

Choose a reason for hiding this comment

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

❓ What prevents this in C# 7.2? If it's allowed, it would be helpful in the review if the C# 7.2 features could be brought in separately from the C# 7.3 features. #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not realize that 7.2 is no longer barred. I will separate 7.3 into a separate PR, so that this could actually get merged.


In reply to: 179906078 [](ancestors = 179906078)

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that I still need to update the toolset compiler packages to 2.7.0 which matches Visual Studio 2017 version 15.6
There was a number of important fixes and it seems the changed code is relying on some of them.


In reply to: 180535550 [](ancestors = 180535550,179906078)

@jcouv jcouv added Area-Compilers PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. labels Apr 7, 2018
Copy link
Member

@jaredpar jaredpar left a comment

Choose a reason for hiding this comment

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

:shipit:

@VSadov VSadov removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Apr 10, 2018
@VSadov VSadov changed the title [WIP] Use new language features in Roslyn Use 7.2 language features in Roslyn Apr 11, 2018
@VSadov
Copy link
Member Author

VSadov commented Apr 11, 2018

@dotnet/roslyn-compiler - ok, since we want to merge this, I need one more review. Thanks.

@VSadov
Copy link
Member Author

VSadov commented Apr 11, 2018

The 7.3 part is now a separate PR - #26092

That is not going to be merged. Not until after 7.3 is officially released.

@@ -395,7 +395,7 @@ private TNode[] Nodes
/// </summary>
public Enumerator GetEnumerator()
{
return new Enumerator(this);
return new Enumerator(in this);
Copy link
Member

@sharwell sharwell Apr 11, 2018

Choose a reason for hiding this comment

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

❓ Why make this change? The current structure appears to only have one field, which is SyntaxNode (a reference type) and therefore be cheapest to copy by value. #Resolved

Copy link
Member Author

@VSadov VSadov Apr 11, 2018

Choose a reason for hiding this comment

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

Will take a look. I may have mixed it up with other cases. There would not be much point to pass a single reference by in. #Resolved

@@ -2210,7 +2210,6 @@ Microsoft.CodeAnalysis.SyntaxTokenList.Reverse() -> Microsoft.CodeAnalysis.Synta
Microsoft.CodeAnalysis.SyntaxTokenList.Reversed
Microsoft.CodeAnalysis.SyntaxTokenList.Reversed.Enumerator
Microsoft.CodeAnalysis.SyntaxTokenList.Reversed.Enumerator.Current.get -> Microsoft.CodeAnalysis.SyntaxToken
Microsoft.CodeAnalysis.SyntaxTokenList.Reversed.Enumerator.Enumerator(ref Microsoft.CodeAnalysis.SyntaxTokenList list) -> void
Copy link
Member

@jasonmalinowski jasonmalinowski Apr 11, 2018

Choose a reason for hiding this comment

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

Breaking change? #ByDesign

Copy link
Member

@tannergooding tannergooding Apr 11, 2018

Choose a reason for hiding this comment

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

Yes, but only with specific compiler versions (or newer): dotnet/csharplang#1308 #ByDesign

Copy link
Member

@tannergooding tannergooding Apr 11, 2018

Choose a reason for hiding this comment

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

(which might be even worse than a normal breaking change 😄) #WontFix

Copy link
Member Author

Choose a reason for hiding this comment

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

Technically yes. But I am certain that it was public by mistake. Noone should be instantiating these enumerators except via GetEnumerator call. No other struct enumerator have a public constructor. Especially those that take byre parameters.

We can discuss this further but while most compat breaks are bad, not all are. I think this public exposure should be undone ASAP. - not just because it stands in the way of changing from ref -> in, I could leave it as ref. I left ref in other public places, for compat reasons.

Here a public ctor just makes no sense.


In reply to: 180876819 [](ancestors = 180876819)

Copy link
Member Author

Choose a reason for hiding this comment

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

I am simply removing the ctors. It is not related to in vs. ref


In reply to: 180885818 [](ancestors = 180885818)

Copy link
Member Author

Choose a reason for hiding this comment

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

I have sent a note to Compat Council to decide on this, but I think we should remove these from the public API.

I can keep the ref ctors public (for what use?) and add in ctor with a dummy parameter for the use in GetEnumerator - to avoid defensive copying, but it would be a very counterproductive "fix"


In reply to: 180900004 [](ancestors = 180900004,180876819)

Copy link
Member Author

Choose a reason for hiding this comment

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

Compat Council is ok with removing the following from the public surface:

  1. Microsoft.CodeAnalysis.SyntaxTokenList.Reversed.Enumerator.Enumerator(ref Microsoft.CodeAnalysis.SyntaxTokenList list)

  2. Microsoft.CodeAnalysis.SyntaxTriviaList.Reversed.Enumerator.Enumerator(ref Microsoft.CodeAnalysis.SyntaxTriviaList list)


In reply to: 180905813 [](ancestors = 180905813,180900004,180876819)

@VSadov
Copy link
Member Author

VSadov commented Apr 12, 2018

@dotnet/roslyn-compiler - PING

Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

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

LGTM

@VSadov VSadov closed this Apr 12, 2018
@VSadov VSadov reopened this Apr 12, 2018
@VSadov
Copy link
Member Author

VSadov commented Apr 12, 2018

Why tests are getting stuck and not starting?

@VSadov VSadov closed this Apr 12, 2018
@VSadov VSadov reopened this Apr 12, 2018
@jaredpar
Copy link
Member

@VSadov I sent an email about this in the AM. 😄

@VSadov
Copy link
Member Author

VSadov commented Apr 12, 2018

@jaredpar I thought the issue was resolved and I may need just cycle through Close/Reopen that typically resolves "stuck" tests issue.

@VSadov
Copy link
Member Author

VSadov commented Apr 12, 2018

Oh well..

Copy link
Contributor

@OmarTawfik OmarTawfik left a comment

Choose a reason for hiding this comment

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

Awesome! 👍

@jaredpar
Copy link
Member

@VSadov looks like the required tests have all passed now.

@VSadov
Copy link
Member Author

VSadov commented Apr 13, 2018

Thanks!!

@VSadov VSadov merged commit d2d03c8 into dotnet:master Apr 13, 2018
@VSadov VSadov deleted the useNewFeatures branch April 13, 2018 16:07
@jcouv
Copy link
Member

jcouv commented Apr 16, 2018

@VSadov FYI, it looks like we had missed "readonly" completion during IDE testing. See #19216
Did you notice anything strange while dogfooding the feature?

garuma added a commit to KirillOsenkov/XmlParser that referenced this pull request Apr 22, 2018
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.

None yet

9 participants