Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Adding ValueTuple and ITuple to corlib in CoreCLR #8695

Merged
merged 6 commits into from
Dec 22, 2016

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Dec 20, 2016

ValueTuple types are supporting the C#7.0 tuples feature. They have been implemented as a standalone CoreFx package, but should be moved down into the various corlibs (mscorlib/desktop and mscorlib/mono are already done) to be consistent with System.Tuple and can be used by other APIs.

This PR does not contain ITuple yet, but I will push it shortly into this same PR.
It is an interface in CompilerServices namespace used for dynamic pattern matching (in a future version of C#). It applies to System.Tuple and System.ValueTuple types. It was implemented in mscorlib/desktop, and I'm in the process of implementing it in other corlibs.

The main purpose for opening this PR at this point is to raise two questions:

  1. where should test code for ValueTuple go?
  2. where is the existing test code for System.Tuple? I could not find it.

FYI @tarekgh @VSadov

@tarekgh
Copy link
Member

tarekgh commented Dec 20, 2016

do you want to add the new exposed types to the file https://github.com/dotnet/coreclr/blob/master/src/mscorlib/model.xml to ensure the rewriter will include it?

@tarekgh
Copy link
Member

tarekgh commented Dec 20, 2016

CC @jkotas

@tarekgh
Copy link
Member

tarekgh commented Dec 20, 2016

LGTM.

@jamesqo
Copy link

jamesqo commented Dec 20, 2016

Nice. Do you want to consider cherry-picking the changes from dotnet/corefx#14187 here as well? They were rejected since the corefx ValueTuple is used on older runtimes that box for enum.GetHashCode(), but CoreCLR optimizes that away now-- see #7895 so there's no reason to use EqualityComparer anymore.

Besides that, LGTM.

@@ -8,12 +8,14 @@ namespace System.Numerics.Hashing

internal static class HashHelpers
{
public static readonly int RandomSeed = Guid.NewGuid().GetHashCode();
Copy link
Member

Choose a reason for hiding this comment

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

This does not seem to be actually used.

Also, could you please change this to be initialized with new Random().Next(Int32.MinValue, Int32.MaxValue) instead? CoreCLR and CoreRT are initializing the random seed via NewGuid() already - it would be nice to do it just once per process.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for catching that. I accidentally copied over the code that used the random seed. Fixed.


if (!(other is ValueTuple))
{
throw new ArgumentException(Environment.GetResourceString("ArgumentException_ValueTupleIncorrectType", this.GetType().ToString()), nameof(other));
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add the getter for the resource to src\mscorlib\corefx\SR.cs to so that this file can be exactly same as the copy in CoreRT?

@jkotas
Copy link
Member

jkotas commented Dec 21, 2016

(Once this goes through and propagates to corefx, you will also need to update the packaging in corefx to use the forwarders to corelib where applicable.)

@jcouv
Copy link
Member Author

jcouv commented Dec 21, 2016

@jkotas Yes, updating type forwarders (and also adding tests for ITuple) in corefx will be the next steps. I may need some pointers on how to do that.

@jcouv jcouv force-pushed the tuple-coreclr branch 2 times, most recently from eb12c23 to a8c3e5d Compare December 21, 2016 05:21
@jcouv
Copy link
Member Author

jcouv commented Dec 21, 2016

@jamesqo If you wouldn't mind taking another look. I added your change from dotnet/corefx#14187. Thanks

@@ -8608,6 +8608,14 @@
<Member Name="GetHashCode" />
<Member Name="ToString" />
<Member MemberType="Property" Name="Item1" />
<Member Status="ImplRoot" Name="System.Collections.IStructuralComparable.CompareTo(System.Object,System.Collections.IComparer)" />
Copy link
Member Author

Choose a reason for hiding this comment

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

@tarekgh Thanks for the modelgen tool. I copied the bits that I think are useful here, but I don't really know how to validate.
In particular, I'm surprised that these pre-existing Tuple APIs weren't in the model.xml. Is adding them correct?

Copy link
Member

Choose a reason for hiding this comment

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

The corelib pruning tool automatically keeps interface implementations around. It is not necessary to mention them explicitly.

Copy link
Member

Choose a reason for hiding this comment

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

to validate it, after compiling S.P.Corelib.dll look inside and make sure all new exposed APIs are already there and not get removed by the IL re-writer.

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've spot checked the S.P.Corelib.dll and the new APIs appear there.
I've left the interface implementations in the model.xml. Let me know if they need to be removed, or ok to leave. Thanks

@jkotas
Copy link
Member

jkotas commented Dec 21, 2016

BTW: I am moving the EditorBrowsableAttribute to CoreLib in #8703

@jkotas
Copy link
Member

jkotas commented Dec 21, 2016

@jcouv I have moved the EditorBrowsableAttribute to CoreLib. You can uncomment it.

@jamesqo
Copy link

jamesqo commented Dec 22, 2016

@jcouv LGTM

@jcouv
Copy link
Member Author

jcouv commented Dec 22, 2016

Thanks. Rebased and removed the commit that was removing EditorBrowsable (so the attribute is back in TupleExtensions.cs).

@jkotas jkotas merged commit 2d49c2c into dotnet:master Dec 22, 2016
@jcouv jcouv deleted the tuple-coreclr branch December 22, 2016 07:03
@karelz karelz added this to the 2.1.0 milestone Aug 28, 2017
@karelz karelz modified the milestones: 2.1.0, 2.0.0 Aug 28, 2017
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Adding ValueTuple
* Adding ITuple
* Porting equality comparer optimization from corefx PR dotnet/coreclr#14187

Commit migrated from dotnet/coreclr@2d49c2c
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants