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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/mscorlib/System.Private.CoreLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@
<!-- We want the sources to show up nicely in VS-->
<Compile Include="@(MscorlibSources)">
</Compile>
<Compile Include="src\System\Runtime\CompilerServices\ITuple.cs" />
<Compile Include="src\System\Runtime\CompilerServices\TupleElementNamesAttribute.cs" />
<Compile Include="src\System\TupleExtensions.cs" />
<Compile Include="src\System\ValueTuple.cs" />
</ItemGroup>

<!-- Resources -->
Expand Down
10 changes: 10 additions & 0 deletions src/mscorlib/corefx/SR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,14 @@ public static string Format(string formatString, params object[] args)
{
return string.Format(CultureInfo.CurrentCulture, formatString, args);
}

internal static string ArgumentException_ValueTupleIncorrectType
{
get { return Environment.GetResourceString("ArgumentException_ValueTupleIncorrectType"); }
}

internal static string ArgumentException_ValueTupleLastArgumentNotATuple
{
get { return Environment.GetResourceString("ArgumentException_ValueTupleLastArgumentNotATuple"); }
}
}
331 changes: 330 additions & 1 deletion src/mscorlib/model.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/mscorlib/src/System.Private.CoreLib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2282,3 +2282,6 @@ Globalization.cp_57011 = ISCII Punjabi

;------------------

; ValueTuple
ArgumentException_ValueTupleIncorrectType=Argument must be of type {0}.
ArgumentException_ValueTupleLastArgumentNotAValueTuple=The last element of an eight element ValueTuple must be a ValueTuple.
8 changes: 5 additions & 3 deletions src/mscorlib/src/System/Numerics/Hashing/HashHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ namespace System.Numerics.Hashing

internal static class HashHelpers
{
public static readonly int RandomSeed = new Random().Next(Int32.MinValue, Int32.MaxValue);

public static int Combine(int h1, int h2)
{
// The jit optimizes this to use the ROL instruction on x86
// RyuJIT optimizes this to use the ROL instruction
// Related GitHub pull request: dotnet/coreclr#1830
uint shift5 = ((uint)h1 << 5) | ((uint)h1 >> 27);
return ((int)shift5 + h1) ^ h2;
uint rol5 = ((uint)h1 << 5) | ((uint)h1 >> 27);
return ((int)rol5 + h1) ^ h2;
}
}
}
22 changes: 22 additions & 0 deletions src/mscorlib/src/System/Runtime/CompilerServices/ITuple.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System.Runtime.CompilerServices
{
/// <summary>
/// This interface is required for types that want to be indexed into by dynamic patterns.
/// </summary>
public interface ITuple
{
/// <summary>
/// The number of positions in this data structure.
/// </summary>
int Length { get; }

/// <summary>
/// Get the element at position <param name="index"/>.
/// </summary>
object this[int index] { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;

namespace System.Runtime.CompilerServices
{
/// <summary>
/// Indicates that the use of <see cref="System.ValueTuple"/> on a member is meant to be treated as a tuple with element names.
/// </summary>
[CLSCompliant(false)]
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Event)]
public sealed class TupleElementNamesAttribute : Attribute
{
private readonly string[] _transformNames;

/// <summary>
/// Initializes a new instance of the <see
/// cref="TupleElementNamesAttribute"/> class.
/// </summary>
/// <param name="transformNames">
/// Specifies, in a pre-order depth-first traversal of a type's
/// construction, which <see cref="System.ValueType"/> occurrences are
/// meant to carry element names.
/// </param>
/// <remarks>
/// This constructor is meant to be used on types that contain an
/// instantiation of <see cref="System.ValueType"/> that contains
/// element names. For instance, if <c>C</c> is a generic type with
/// two type parameters, then a use of the constructed type <c>C{<see
/// cref="System.ValueTuple{T1, T2}"/>, <see
/// cref="System.ValueTuple{T1, T2, T3}"/></c> might be intended to
/// treat the first type argument as a tuple with element names and the
/// second as a tuple without element names. In which case, the
/// appropriate attribute specification should use a
/// <c>transformNames</c> value of <c>{ "name1", "name2", null, null,
/// null }</c>.
/// </remarks>
public TupleElementNamesAttribute(string[] transformNames)
{
if (transformNames == null)
{
throw new ArgumentNullException(nameof(transformNames));
}

_transformNames = transformNames;
}

/// <summary>
/// Specifies, in a pre-order depth-first traversal of a type's
/// construction, which <see cref="System.ValueTuple"/> elements are
/// meant to carry element names.
/// </summary>
public IList<string> TransformNames => _transformNames;
}
}
Loading