Skip to content

Commit

Permalink
Apply OverloadResolutionPriority to Span-based delegating to ROS coun…
Browse files Browse the repository at this point in the history
…terparts (#109602)
  • Loading branch information
stephentoub authored Nov 13, 2024
1 parent d3d0fce commit f40ef93
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,12 @@ public static System.Collections.Immutable.ImmutableArray<TResult> CreateRange<T
public static System.Collections.Immutable.ImmutableArray<T> Create<T>(params T[]? items) { throw null; }
public static System.Collections.Immutable.ImmutableArray<T> Create<T>(T[] items, int start, int length) { throw null; }
public static System.Collections.Immutable.ImmutableArray<T> Create<T>(params System.ReadOnlySpan<T> items) { throw null; }
[System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute(-1)]
public static System.Collections.Immutable.ImmutableArray<T> Create<T>(System.Span<T> items) { throw null; }
public static System.Collections.Immutable.ImmutableArray<TSource> ToImmutableArray<TSource>(this System.Collections.Generic.IEnumerable<TSource> items) { throw null; }
public static System.Collections.Immutable.ImmutableArray<TSource> ToImmutableArray<TSource>(this System.Collections.Immutable.ImmutableArray<TSource>.Builder builder) { throw null; }
public static System.Collections.Immutable.ImmutableArray<T> ToImmutableArray<T>(this System.ReadOnlySpan<T> items) { throw null; }
[System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute(-1)]
public static System.Collections.Immutable.ImmutableArray<T> ToImmutableArray<T>(this System.Span<T> items) { throw null; }
}
[System.Runtime.CompilerServices.CollectionBuilderAttribute(typeof(System.Collections.Immutable.ImmutableArray), "Create")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<Compile Include="System.Collections.Immutable.net9.cs" />
</ItemGroup>

<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))">
<Compile Include="$(CoreLibSharedDir)System\Runtime\CompilerServices\OverloadResolutionPriorityAttribute.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections\ref\System.Collections.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime\ref\System.Runtime.csproj" />
Expand All @@ -28,4 +32,4 @@
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ The System.Collections.Immutable library is built-in as part of the shared frame
<Compile Include="System\Collections\Frozen\String\OrdinalStringFrozenSet.AlternateLookup.cs" />
</ItemGroup>

<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))">
<Compile Include="$(CoreLibSharedDir)System\Runtime\CompilerServices\OverloadResolutionPriorityAttribute.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<Compile Include="$(CoreLibSharedDir)System\Runtime\CompilerServices\CollectionBuilderAttribute.cs" Link="System\Runtime\CompilerServices\CollectionBuilderAttribute.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;

namespace System.Collections.Immutable
{
Expand Down Expand Up @@ -104,6 +105,7 @@ public static ImmutableArray<T> Create<T>(params ReadOnlySpan<T> items)
/// <typeparam name="T">The type of element stored in the array.</typeparam>
/// <param name="items">The elements to store in the array.</param>
/// <returns>An immutable array containing the specified items.</returns>
[OverloadResolutionPriority(-1)]
public static ImmutableArray<T> Create<T>(Span<T> items)
{
return Create((ReadOnlySpan<T>)items);
Expand All @@ -126,6 +128,7 @@ public static ImmutableArray<T> ToImmutableArray<T>(this ReadOnlySpan<T> items)
/// <typeparam name="T">The type of element in the list.</typeparam>
/// <param name="items">The elements to store in the array.</param>
/// <returns>An immutable array containing the specified items.</returns>
[OverloadResolutionPriority(-1)]
public static ImmutableArray<T> ToImmutableArray<T>(this Span<T> items)
{
return Create((ReadOnlySpan<T>)items);
Expand Down
56 changes: 56 additions & 0 deletions src/libraries/System.Memory/ref/System.Memory.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ public readonly void CopyTo(System.Span<float> destination) { }
private readonly int _dummyPrimitive;
public Vector(System.ReadOnlySpan<byte> values) { throw null; }
public Vector(System.ReadOnlySpan<T> values) { throw null; }
[System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute(-1)]
public Vector(System.Span<T> values) { throw null; }
public Vector(T value) { throw null; }
public Vector(T[] values) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ public static SpanRuneEnumerator EnumerateRunes(this ReadOnlySpan<char> span)
/// <remarks>
/// Invalid sequences will be represented in the enumeration by <see cref="Rune.ReplacementChar"/>.
/// </remarks>
[OverloadResolutionPriority(-1)]
public static SpanRuneEnumerator EnumerateRunes(this Span<char> span)
{
return new SpanRuneEnumerator(span);
Expand All @@ -404,6 +405,7 @@ public static SpanLineEnumerator EnumerateLines(this ReadOnlySpan<char> span)
/// for <see cref="string.ReplaceLineEndings"/> for more information on how newline
/// sequences are detected.
/// </remarks>
[OverloadResolutionPriority(-1)]
public static SpanLineEnumerator EnumerateLines(this Span<char> span)
{
return new SpanLineEnumerator(span);
Expand Down
Loading

0 comments on commit f40ef93

Please sign in to comment.