diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
index 43ddbfecf006fa..edbaabbf7de363 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
@@ -224,6 +224,7 @@ public static object GetUninitializedObject(
/// true if given type is reference type or value type that contains references
[Intrinsic]
public static bool IsReferenceOrContainsReferences()
+ // where T : allows ref struct // TODO https://github.com/dotnet/runtime/issues/102847
{
// The body of this function will be replaced by the EE with unsafe code!!!
// See getILIntrinsicImplementationForRuntimeHelpers for how this happens.
diff --git a/src/libraries/System.Collections.Concurrent/ref/System.Collections.Concurrent.cs b/src/libraries/System.Collections.Concurrent/ref/System.Collections.Concurrent.cs
index 6c2b09321b7f96..84c5c0212de2b2 100644
--- a/src/libraries/System.Collections.Concurrent/ref/System.Collections.Concurrent.cs
+++ b/src/libraries/System.Collections.Concurrent/ref/System.Collections.Concurrent.cs
@@ -101,13 +101,13 @@ public ConcurrentDictionary(int concurrencyLevel, int capacity, System.Collectio
public System.Collections.Generic.ICollection Values { get { throw null; } }
public TValue AddOrUpdate(TKey key, System.Func addValueFactory, System.Func updateValueFactory) { throw null; }
public TValue AddOrUpdate(TKey key, TValue addValue, System.Func updateValueFactory) { throw null; }
- public TValue AddOrUpdate(TKey key, System.Func addValueFactory, System.Func updateValueFactory, TArg factoryArgument) { throw null; }
+ public TValue AddOrUpdate(TKey key, System.Func addValueFactory, System.Func updateValueFactory, TArg factoryArgument) where TArg : allows ref struct { throw null; }
public void Clear() { }
public bool ContainsKey(TKey key) { throw null; }
public System.Collections.Generic.IEnumerator> GetEnumerator() { throw null; }
public TValue GetOrAdd(TKey key, System.Func valueFactory) { throw null; }
public TValue GetOrAdd(TKey key, TValue value) { throw null; }
- public TValue GetOrAdd(TKey key, System.Func valueFactory, TArg factoryArgument) { throw null; }
+ public TValue GetOrAdd(TKey key, System.Func valueFactory, TArg factoryArgument) where TArg : allows ref struct { throw null; }
void System.Collections.Generic.ICollection>.Add(System.Collections.Generic.KeyValuePair keyValuePair) { }
bool System.Collections.Generic.ICollection>.Contains(System.Collections.Generic.KeyValuePair keyValuePair) { throw null; }
void System.Collections.Generic.ICollection>.CopyTo(System.Collections.Generic.KeyValuePair[] array, int index) { }
diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs
index e6ae682a9c8536..bf48ef7f5a18ce 100644
--- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs
+++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs
@@ -1201,6 +1201,7 @@ public TValue GetOrAdd(TKey key, Func valueFactory)
/// key is already in the dictionary, or the new value for the key as returned by valueFactory
/// if the key was not in the dictionary.
public TValue GetOrAdd(TKey key, Func valueFactory, TArg factoryArgument)
+ where TArg : allows ref struct
{
if (key is null)
{
@@ -1279,6 +1280,7 @@ public TValue GetOrAdd(TKey key, TValue value)
/// absent) or the result of updateValueFactory (if the key was present).
public TValue AddOrUpdate(
TKey key, Func addValueFactory, Func updateValueFactory, TArg factoryArgument)
+ where TArg : allows ref struct
{
if (key is null)
{
diff --git a/src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.cs b/src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.cs
index bf180cfb33dbc0..8e452d7e1d1e3f 100644
--- a/src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.cs
+++ b/src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.cs
@@ -200,8 +200,16 @@ public static partial class ImmutableArray
public static System.Collections.Immutable.ImmutableArray CreateRange(System.Collections.Generic.IEnumerable items) { throw null; }
public static System.Collections.Immutable.ImmutableArray CreateRange(System.Collections.Immutable.ImmutableArray items, System.Func selector) { throw null; }
public static System.Collections.Immutable.ImmutableArray CreateRange(System.Collections.Immutable.ImmutableArray items, int start, int length, System.Func selector) { throw null; }
- public static System.Collections.Immutable.ImmutableArray CreateRange(System.Collections.Immutable.ImmutableArray items, System.Func selector, TArg arg) { throw null; }
- public static System.Collections.Immutable.ImmutableArray CreateRange(System.Collections.Immutable.ImmutableArray items, int start, int length, System.Func selector, TArg arg) { throw null; }
+ public static System.Collections.Immutable.ImmutableArray CreateRange(System.Collections.Immutable.ImmutableArray items, System.Func selector, TArg arg)
+#if NET9_0_OR_GREATER
+ where TArg : allows ref struct
+#endif
+ { throw null; }
+ public static System.Collections.Immutable.ImmutableArray CreateRange(System.Collections.Immutable.ImmutableArray items, int start, int length, System.Func selector, TArg arg)
+#if NET9_0_OR_GREATER
+ where TArg : allows ref struct
+#endif
+ { throw null; }
public static System.Collections.Immutable.ImmutableArray Create() { throw null; }
public static System.Collections.Immutable.ImmutableArray Create(System.Collections.Immutable.ImmutableArray items, int start, int length) { throw null; }
public static System.Collections.Immutable.ImmutableArray Create(T item) { throw null; }
@@ -672,7 +680,11 @@ public static partial class ImmutableInterlocked
public static void Enqueue(ref System.Collections.Immutable.ImmutableQueue location, T value) { }
public static TValue GetOrAdd(ref System.Collections.Immutable.ImmutableDictionary location, TKey key, System.Func valueFactory) where TKey : notnull { throw null; }
public static TValue GetOrAdd(ref System.Collections.Immutable.ImmutableDictionary location, TKey key, TValue value) where TKey : notnull { throw null; }
- public static TValue GetOrAdd(ref System.Collections.Immutable.ImmutableDictionary location, TKey key, System.Func valueFactory, TArg factoryArgument) where TKey : notnull { throw null; }
+ public static TValue GetOrAdd(ref System.Collections.Immutable.ImmutableDictionary location, TKey key, System.Func valueFactory, TArg factoryArgument) where TKey : notnull
+#if NET9_0_OR_GREATER
+ where TArg : allows ref struct
+#endif
+ { throw null; }
public static System.Collections.Immutable.ImmutableArray InterlockedCompareExchange(ref System.Collections.Immutable.ImmutableArray location, System.Collections.Immutable.ImmutableArray value, System.Collections.Immutable.ImmutableArray comparand) { throw null; }
public static System.Collections.Immutable.ImmutableArray InterlockedExchange(ref System.Collections.Immutable.ImmutableArray location, System.Collections.Immutable.ImmutableArray value) { throw null; }
public static bool InterlockedInitialize(ref System.Collections.Immutable.ImmutableArray location, System.Collections.Immutable.ImmutableArray value) { throw null; }
@@ -683,9 +695,17 @@ public static void Push(ref System.Collections.Immutable.ImmutableStack lo
public static bool TryRemove(ref System.Collections.Immutable.ImmutableDictionary location, TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value) where TKey : notnull { throw null; }
public static bool TryUpdate(ref System.Collections.Immutable.ImmutableDictionary location, TKey key, TValue newValue, TValue comparisonValue) where TKey : notnull { throw null; }
public static bool Update(ref T location, System.Func transformer) where T : class? { throw null; }
- public static bool Update(ref T location, System.Func transformer, TArg transformerArgument) where T : class? { throw null; }
+ public static bool Update(ref T location, System.Func transformer, TArg transformerArgument) where T : class?
+#if NET9_0_OR_GREATER
+ where TArg : allows ref struct
+#endif
+ { throw null; }
public static bool Update(ref System.Collections.Immutable.ImmutableArray location, Func, System.Collections.Immutable.ImmutableArray> transformer) { throw null; }
- public static bool Update(ref System.Collections.Immutable.ImmutableArray location, Func, TArg, System.Collections.Immutable.ImmutableArray> transformer, TArg transformerArgument) { throw null; }
+ public static bool Update(ref System.Collections.Immutable.ImmutableArray location, Func, TArg, System.Collections.Immutable.ImmutableArray> transformer, TArg transformerArgument)
+#if NET9_0_OR_GREATER
+ where TArg : allows ref struct
+#endif
+ { throw null; }
}
public static partial class ImmutableList
{
diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray.cs
index 8f244bc8305bd5..15de249335b8f3 100644
--- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray.cs
+++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray.cs
@@ -337,6 +337,9 @@ public static ImmutableArray CreateRange(ImmutableArr
/// the source array.
///
public static ImmutableArray CreateRange(ImmutableArray items, Func selector, TArg arg)
+#if NET9_0_OR_GREATER
+ where TArg : allows ref struct
+#endif
{
Requires.NotNull(selector, nameof(selector));
@@ -370,6 +373,9 @@ public static ImmutableArray CreateRange(Immuta
/// included in the resulting array.
///
public static ImmutableArray CreateRange(ImmutableArray items, int start, int length, Func selector, TArg arg)
+#if NET9_0_OR_GREATER
+ where TArg : allows ref struct
+#endif
{
int itemsLength = items.Length;
diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableInterlocked.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableInterlocked.cs
index 397ae8338b9b57..573d2764266f35 100644
--- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableInterlocked.cs
+++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableInterlocked.cs
@@ -76,6 +76,9 @@ public static bool Update(ref T location, Func transformer) where T : c
/// invocation of returned the existing value.
///
public static bool Update(ref T location, Func transformer, TArg transformerArgument) where T : class?
+#if NET9_0_OR_GREATER
+ where TArg : allows ref struct
+#endif
{
Requires.NotNull(transformer, nameof(transformer));
@@ -162,6 +165,9 @@ public static bool Update(ref ImmutableArray location, Func returned the existing value.
///
public static bool Update(ref ImmutableArray location, Func, TArg, ImmutableArray> transformer, TArg transformerArgument)
+#if NET9_0_OR_GREATER
+ where TArg : allows ref struct
+#endif
{
Requires.NotNull(transformer, nameof(transformer));
@@ -241,7 +247,11 @@ public static bool InterlockedInitialize(ref ImmutableArray location, Immu
/// The function to execute to obtain the value to insert into the dictionary if the key is not found.
/// The argument to pass to the value factory.
/// The value obtained from the dictionary or if it was not present.
- public static TValue GetOrAdd(ref ImmutableDictionary location, TKey key, Func valueFactory, TArg factoryArgument) where TKey : notnull
+ public static TValue GetOrAdd(ref ImmutableDictionary location, TKey key, Func valueFactory, TArg factoryArgument)
+ where TKey : notnull
+#if NET9_0_OR_GREATER
+ where TArg : allows ref struct
+#endif
{
Requires.NotNull(valueFactory, nameof(valueFactory));
diff --git a/src/libraries/System.Linq/src/System/Linq/Sum.cs b/src/libraries/System.Linq/src/System/Linq/Sum.cs
index 7eb2dc855dc67b..481997b8f82633 100644
--- a/src/libraries/System.Linq/src/System/Linq/Sum.cs
+++ b/src/libraries/System.Linq/src/System/Linq/Sum.cs
@@ -60,11 +60,11 @@ private static TResult Sum(ReadOnlySpan span)
if (typeof(T) == typeof(long))
{
- return (TResult)(object)SumSignedIntegersVectorized(MemoryMarshal.Cast(span));
+ return (TResult)(object)SumSignedIntegersVectorized(Unsafe.BitCast, ReadOnlySpan>(span));
}
if (typeof(T) == typeof(int))
{
- return (TResult)(object)SumSignedIntegersVectorized(MemoryMarshal.Cast(span));
+ return (TResult)(object)SumSignedIntegersVectorized(Unsafe.BitCast, ReadOnlySpan>(span));
}
}
diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.Helpers.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.Helpers.cs
index 1ddabb93dd0ea4..5e4e89b61742d0 100644
--- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.Helpers.cs
+++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.Helpers.cs
@@ -36,7 +36,11 @@ private static void ValidateInputOutputSpanNonOverlapping(ReadOnlySpan inp
private static unsafe Span Rename(Span span)
{
Debug.Assert(sizeof(TFrom) == sizeof(TTo));
+#if NET9_0_OR_GREATER
+ return Unsafe.BitCast, Span>(span);
+#else
return *(Span*)(&span);
+#endif
}
/// Creates a span of from a when they're the same type.
@@ -48,7 +52,11 @@ private static unsafe Span Rename(Span span)
private static unsafe ReadOnlySpan Rename(ReadOnlySpan span)
{
Debug.Assert(sizeof(TFrom) == sizeof(TTo));
+#if NET9_0_OR_GREATER
+ return Unsafe.BitCast, ReadOnlySpan>(span);
+#else
return *(ReadOnlySpan*)(&span);
+#endif
}
/// Mask used to handle alignment elements before vectorized handling of the input.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Action.cs b/src/libraries/System.Private.CoreLib/src/System/Action.cs
index dacc4fa7cc5b7b..9c78bed630e036 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Action.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Action.cs
@@ -6,37 +6,196 @@
namespace System
{
public delegate void Action();
- public delegate void Action(T obj);
- public delegate void Action(T1 arg1, T2 arg2);
- public delegate void Action(T1 arg1, T2 arg2, T3 arg3);
- public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4);
- public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
- public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);
- public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7);
- public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);
- public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9);
- public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10);
- public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11);
- public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12);
- public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13);
- public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14);
- public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15);
- public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16);
+
+ public delegate void Action(T obj)
+ where T : allows ref struct;
+
+ public delegate void Action(T1 arg1, T2 arg2)
+ where T1 : allows ref struct
+ where T2 : allows ref struct;
+
+ public delegate void Action(T1 arg1, T2 arg2, T3 arg3)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct;
+
+ public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct;
+
+ public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct;
+
+ public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct;
+
+ public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct;
+
+ public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where T8 : allows ref struct;
+
+ public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where T8 : allows ref struct
+ where T9 : allows ref struct;
+
+ public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where T8 : allows ref struct
+ where T9 : allows ref struct
+ where T10 : allows ref struct;
+
+ public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where T8 : allows ref struct
+ where T9 : allows ref struct
+ where T10 : allows ref struct
+ where T11 : allows ref struct;
+
+ public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where T8 : allows ref struct
+ where T9 : allows ref struct
+ where T10 : allows ref struct
+ where T11 : allows ref struct
+ where T12 : allows ref struct;
+
+ public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where T8 : allows ref struct
+ where T9 : allows ref struct
+ where T10 : allows ref struct
+ where T11 : allows ref struct
+ where T12 : allows ref struct
+ where T13 : allows ref struct;
+
+ public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where T8 : allows ref struct
+ where T9 : allows ref struct
+ where T10 : allows ref struct
+ where T11 : allows ref struct
+ where T12 : allows ref struct
+ where T13 : allows ref struct
+ where T14 : allows ref struct;
+
+ public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where T8 : allows ref struct
+ where T9 : allows ref struct
+ where T10 : allows ref struct
+ where T11 : allows ref struct
+ where T12 : allows ref struct
+ where T13 : allows ref struct
+ where T14 : allows ref struct
+ where T15 : allows ref struct;
+
+ public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where T8 : allows ref struct
+ where T9 : allows ref struct
+ where T10 : allows ref struct
+ where T11 : allows ref struct
+ where T12 : allows ref struct
+ where T13 : allows ref struct
+ where T14 : allows ref struct
+ where T15 : allows ref struct
+ where T16 : allows ref struct;
// This should probably technically be T? rather than T to match `IComparer`. However, the use cases are generally different,
// with Comparison typically being used via a lambda, with the T inferred from the type of the collection being sorted,
// and forcing nullable warnings onto all such usage leads to many spurious warnings.
- public delegate int Comparison(T x, T y);
+ public delegate int Comparison(T x, T y)
+ where T : allows ref struct;
- public delegate TOutput Converter(TInput input);
+ public delegate TOutput Converter(TInput input)
+ where TInput : allows ref struct
+ where TOutput : allows ref struct;
- public delegate bool Predicate(T obj);
+ public delegate bool Predicate(T obj)
+ where T : allows ref struct;
}
namespace System.Buffers
{
- public delegate void SpanAction(Span span, TArg arg);
- public delegate void ReadOnlySpanAction(ReadOnlySpan span, TArg arg);
+ public delegate void SpanAction(Span span, TArg arg)
+ where TArg : allows ref struct;
+
+ public delegate void ReadOnlySpanAction(ReadOnlySpan span, TArg arg)
+ where TArg : allows ref struct;
internal delegate TResult SpanFunc(Span span, T1 arg1, T2 arg2, T3 arg3);
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IAsyncEnumerable.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IAsyncEnumerable.cs
index 097c31d12679da..bf7dcf51416c06 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IAsyncEnumerable.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IAsyncEnumerable.cs
@@ -8,6 +8,9 @@ namespace System.Collections.Generic
/// Exposes an enumerator that provides asynchronous iteration over values of a specified type.
/// The type of values to enumerate.
public interface IAsyncEnumerable
+#if NET9_0_OR_GREATER
+ where T : allows ref struct
+#endif
{
/// Returns an enumerator that iterates asynchronously through the collection.
/// A that may be used to cancel the asynchronous iteration.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IAsyncEnumerator.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IAsyncEnumerator.cs
index fc1a9d5e1d93b2..f5249067de14ca 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IAsyncEnumerator.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IAsyncEnumerator.cs
@@ -8,6 +8,9 @@ namespace System.Collections.Generic
/// Supports a simple asynchronous iteration over a generic collection.
/// The type of objects to enumerate.
public interface IAsyncEnumerator : IAsyncDisposable
+#if NET9_0_OR_GREATER
+ where T : allows ref struct
+#endif
{
/// Advances the enumerator asynchronously to the next element of the collection.
///
diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IEnumerable.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IEnumerable.cs
index 096f0d9dfff401..1cdfaeb34a0f85 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IEnumerable.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IEnumerable.cs
@@ -9,6 +9,7 @@ namespace System.Collections.Generic
{
// Implement this interface if you need to support foreach semantics.
public interface IEnumerable : IEnumerable
+ where T : allows ref struct
{
// Returns an IEnumerator for this enumerable Object. The enumerator provides
// a simple way to access all the contents of a collection.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IEnumerator.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IEnumerator.cs
index 45693471642276..8d32647af98a5e 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IEnumerator.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IEnumerator.cs
@@ -6,6 +6,7 @@ namespace System.Collections.Generic
// Base interface for all generic enumerators, providing a simple approach
// to iterating over a collection.
public interface IEnumerator : IDisposable, IEnumerator
+ where T : allows ref struct
{
// Returns the current element of the enumeration. The returned value is
// undefined before the first call to MoveNext and following a
@@ -16,5 +17,10 @@ public interface IEnumerator : IDisposable, IEnumerator
{
get;
}
+
+ // NOTE: An implementation of an enumerator using a ref struct T will
+ // not be able to implement IEnumerator.Current to return that T (as
+ // doing so would require boxing). It should throw a NotSupportedException
+ // from that property implementation.
}
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Function.cs b/src/libraries/System.Private.CoreLib/src/System/Function.cs
index 519d1cd82e4b06..a8554896437dfb 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Function.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Function.cs
@@ -3,21 +3,190 @@
namespace System
{
- public delegate TResult Func();
- public delegate TResult Func(T arg);
- public delegate TResult Func(T1 arg1, T2 arg2);
- public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3);
- public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4);
- public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
- public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);
- public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7);
- public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);
- public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9);
- public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10);
- public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11);
- public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12);
- public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13);
- public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14);
- public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15);
- public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16);
+ public delegate TResult Func()
+ where TResult : allows ref struct;
+
+ public delegate TResult Func(T arg)
+ where T : allows ref struct
+ where TResult : allows ref struct;
+
+ public delegate TResult Func(T1 arg1, T2 arg2)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where TResult : allows ref struct;
+
+ public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where TResult : allows ref struct;
+
+ public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where TResult : allows ref struct;
+
+ public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where TResult : allows ref struct;
+
+ public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where TResult : allows ref struct;
+
+ public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where TResult : allows ref struct;
+
+ public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where T8 : allows ref struct
+ where TResult : allows ref struct;
+
+ public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where T8 : allows ref struct
+ where T9 : allows ref struct
+ where TResult : allows ref struct;
+
+ public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where T8 : allows ref struct
+ where T9 : allows ref struct
+ where T10 : allows ref struct
+ where TResult : allows ref struct;
+
+ public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where T8 : allows ref struct
+ where T9 : allows ref struct
+ where T10 : allows ref struct
+ where T11 : allows ref struct
+ where TResult : allows ref struct;
+
+ public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where T8 : allows ref struct
+ where T9 : allows ref struct
+ where T10 : allows ref struct
+ where T11 : allows ref struct
+ where T12 : allows ref struct
+ where TResult : allows ref struct;
+
+ public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13)
+ where T1 : allows ref struct
+ where T2 : allows ref struct
+ where T3 : allows ref struct
+ where T4 : allows ref struct
+ where T5 : allows ref struct
+ where T6 : allows ref struct
+ where T7 : allows ref struct
+ where T8 : allows ref struct
+ where T9 : allows ref struct
+ where T10 : allows ref struct
+ where T11 : allows ref struct
+ where T12 : allows ref struct
+ where T13 : allows ref struct
+ where TResult : allows ref struct;
+
+ public delegate TResult Func