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

Remove dedicated tuple type symbol #39370

Merged
merged 22 commits into from
Dec 17, 2019
Merged

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Oct 17, 2019

Fixes #20648

Makes tuples be generic types and removes the TupleTypeSymbol wrapping.
Instead, we're adding tuple element names and virtual fields directly onto NamedTypeSymbol (storing them in an optional TupleUncommonData) with AddOrWrapTupleMembers.

Diagnostics now always prefer tuple syntax, while IL verification always uses System.ValueTuple<...>.

Impacted APIs are Arity, TypeArguments and OriginalDefinition.

VB will be handled separately, but following the same model.

The IDE code was updated:

  • ValueTupleRef was added to the tests, which caused some refactorings to generate better GetHashCode methods
  • some special handling was added so that we find the definition of tuple fields on the user syntax, not on the System.ValueTuple definition
  • some tweaks to QuickInfo displaying tuples

Status: a couple of IDE tests are still failing.

@jcouv jcouv added this to the 16.5 milestone Oct 17, 2019
@jcouv jcouv self-assigned this Oct 17, 2019
@jcouv jcouv force-pushed the tuple-symbols branch 4 times, most recently from 15cb3e3 to c517383 Compare October 22, 2019 00:26
@CyrusNajmabadi
Copy link
Member

CyrusNajmabadi commented Oct 30, 2019

Any implication on hte public roslyn surface area here? would this be observable to clients of the API? i.e. would someone now see Generate TypeArguments on a tuple symbol where they didn't before? #Resolved

@jcouv
Copy link
Member Author

jcouv commented Oct 30, 2019

@CyrusNajmabadi Yes, there is some impact. It is detailed here. For example, Arity and TypeArguments. #Resolved

@CyrusNajmabadi
Copy link
Member

CyrusNajmabadi commented Oct 31, 2019

@CyrusNajmabadi Yes, there is some impact. It is detailed here. For example, Arity and TypeArguments.

interesting! when you make the change LMK if there is any ide fallout. i'd be curious to see what sort of impact this has on consumptive code.

Note: IDE has special serialization/deserializtion logic here for Tuples: https://github.com/dotnet/roslyn/blob/master/src/Workspaces/Core/Portable/SymbolKey/SymbolKey.TupleTypeSymbolKey.cs

My hope is that you will be able to get rid of this almost entirely and just use the named-type-symbolkey serialization logic. Though... perhaps taht won't be possible since there still needs to be some way to funnel the element-names around. But perhaps we can unify this in some cleaner way versus what we have right now.

Thanks! #Resolved

@jcouv jcouv closed this Nov 4, 2019
@jcouv jcouv reopened this Nov 4, 2019
@jcouv jcouv force-pushed the tuple-symbols branch 3 times, most recently from ebe37eb to 28692cc Compare November 5, 2019 01:36
@jaredpar jaredpar closed this Nov 5, 2019
@jaredpar jaredpar reopened this Nov 5, 2019
@jcouv jcouv force-pushed the tuple-symbols branch 6 times, most recently from bd53057 to 49f3922 Compare November 8, 2019 21:58
@jcouv jcouv force-pushed the tuple-symbols branch 2 times, most recently from 8b5d7ff to a485e8a Compare December 3, 2019 00:04
@jcouv jcouv force-pushed the tuple-symbols branch 2 times, most recently from 88a8e27 to 16197a2 Compare December 4, 2019 00:25
@gafter
Copy link
Member

gafter commented Dec 12, 2019

            default:

What about GetType and ReferenceEquals? #Resolved


Refers to: src/Compilers/CSharp/Portable/Symbols/Tuples/TupleTypeSymbol.cs:547 in e8059fb. [](commit_id = e8059fb, deletion_comment = False)

@@ -123,6 +124,10 @@ public override ImmutableArray<Location> Locations
{
get
{
if (IsTupleType)
{
return TupleData.Locations;
Copy link
Member

@gafter gafter Dec 12, 2019

Choose a reason for hiding this comment

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

Locations [](start = 37, length = 9)

I assume this is an improvement in the user experience. Nit: add an empty line after the }, and in the next method too. #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.

Yes, we need to keep locations pointing to where various tuples and tuple element names are defined in source.
Without this, GoToDefinition and FindAllReferences works badly.


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

@gafter
Copy link
Member

gafter commented Dec 13, 2019

        // Note: we emitted the missing fields

This is confusing. We didn't even give an error about it, we just emitted them? What if source had contained a private Item1? Would we then have emitted a synthesized one also? #WontFix


Refers to: src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs:5878 in e8059fb. [](commit_id = e8059fb, deletion_comment = False)

@jcouv
Copy link
Member Author

jcouv commented Dec 16, 2019

    /// For instance, ValueTuple&lt;..., ValueTuple&lt; int >> (the underlying type for an 8-tuple)

No can do. This results in bad XML:

image


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


Refers to: src/Compilers/CSharp/Portable/Symbols/Tuples/TupleTypeSymbol.cs:229 in e8059fb. [](commit_id = e8059fb, deletion_comment = False)

@jcouv
Copy link
Member Author

jcouv commented Dec 16, 2019

            default:

Unsure (they are currently allowed, but I'm not sure if that's dangerous). I'd rather separate this question from this PR, as it is existing behavior. File an issue?


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


Refers to: src/Compilers/CSharp/Portable/Symbols/Tuples/TupleTypeSymbol.cs:547 in e8059fb. [](commit_id = e8059fb, deletion_comment = False)

@jcouv
Copy link
Member Author

jcouv commented Dec 16, 2019

        // Note: we emitted the missing fields

I'm open to making this scenario an error, but I'm not sure how much I care.
The scenario where Item1 is defined but is private is covered in BadValueTupleByItself.


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


Refers to: src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs:5878 in e8059fb. [](commit_id = e8059fb, deletion_comment = False)

@jcouv
Copy link
Member Author

jcouv commented Dec 16, 2019

            if (currentType.IsTupleType)

I'll remove this unreferenced method :)


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


Refers to: src/Compilers/CSharp/Portable/Symbols/Tuples/TupleTypeSymbol.cs:260 in e8059fb. [](commit_id = e8059fb, deletion_comment = False)

@jcouv
Copy link
Member Author

jcouv commented Dec 16, 2019

            default:

Filed #40417 for "GetType"

I think "ReferenceEquals" is okay, but we can discuss that in that issue. Thanks


In reply to: 566164166 [](ancestors = 566164166,565187780)


Refers to: src/Compilers/CSharp/Portable/Symbols/Tuples/TupleTypeSymbol.cs:547 in e8059fb. [](commit_id = e8059fb, deletion_comment = False)

@gafter
Copy link
Member

gafter commented Dec 16, 2019

Done reviewing (Iteration 18). Only two remaining substantive comments: one in NamedTypeSymbol.cs and one in UnsupportedMetadataTypeSymbol.cs. #Resolved

Copy link
Contributor

@mavasani mavasani left a comment

Choose a reason for hiding this comment

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

IDE changes LGTM.

Dim actualNames = rootCodeModel.CodeElements.OfType(Of EnvDTE.CodeElement).Select(Function(e) e.Name).ToArray()
Assert.Equal(names.Length, rootCodeModel.CodeElements.Count)
Copy link
Contributor

@mavasani mavasani Dec 17, 2019

Choose a reason for hiding this comment

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

unintentional change? #Resolved

Copy link
Member Author

@jcouv jcouv Dec 17, 2019

Choose a reason for hiding this comment

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

This made debugging failures easier (you get to access the actualNames local) #Resolved

@@ -421,7 +421,7 @@ public override object VisitNamedType(INamedTypeSymbol namedTypeSymbol)
WriteType(SymbolKeyType.ErrorType);
ErrorTypeSymbolKey.Create(namedTypeSymbol, this);
}
else if (namedTypeSymbol.IsTupleType)
else if (namedTypeSymbol.IsTupleType && namedTypeSymbol.TupleUnderlyingType != namedTypeSymbol)
Copy link
Contributor

@mavasani mavasani Dec 17, 2019

Choose a reason for hiding this comment

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

Should we be using the symbol comparer for comparing symbols? #Resolved

Copy link
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.

image

@JoeRobich
Copy link
Member

All CI checks are passing. Overriding to merge.

@JoeRobich JoeRobich merged commit cc30674 into dotnet:master Dec 17, 2019
@jcouv jcouv deleted the tuple-symbols branch December 17, 2019 21:58
@jcouv
Copy link
Member Author

jcouv commented Dec 17, 2019

Yay, thanks!

davidjohnoliver added a commit to davidjohnoliver/CodeConnections that referenced this pull request Sep 14, 2020
This lowers the minimum required VS version.

Note: 3.4 introduces test failures related to tuple underlying type resolution - probably related to this change: dotnet/roslyn#39370
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.

INamedTypeSymbol.Arity incorrectly reports zero for ValueTuple<int, int> in VB
7 participants