diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Array.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Array.CoreCLR.cs index 55ed9f70b082be..75f6aa40ce4d14 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Array.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Array.CoreCLR.cs @@ -9,13 +9,6 @@ using System.Reflection; using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System { // Note that we make a T[] (single-dimensional w/ zero as the lower bound) implement both diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Buffer.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Buffer.CoreCLR.cs index 8c7bc784ad8961..5e1d8249e3ddda 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Buffer.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Buffer.CoreCLR.cs @@ -7,15 +7,6 @@ using System.Runtime.InteropServices; using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -using nint = System.UInt64; -#else -using nuint = System.UInt32; -using nint = System.UInt32; -#endif - namespace System { public partial class Buffer diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Object.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Object.CoreCLR.cs index 3c7cb5c23982a2..a65358449ee8ca 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Object.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Object.CoreCLR.cs @@ -4,13 +4,6 @@ using System.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System { public partial class Object diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs index a5db6f21277f4c..15cad526595576 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs @@ -9,13 +9,6 @@ using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System.Runtime.CompilerServices { internal static unsafe class CastHelpers diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs index a0e841070d15ea..49e8a4e08c8c0c 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs @@ -7,13 +7,6 @@ using System.Runtime.InteropServices; using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System.Runtime.CompilerServices { public static partial class RuntimeHelpers @@ -348,31 +341,31 @@ internal unsafe struct MethodTable | 0x40000000 // enum_flag_ComObject | 0x00400000;// enum_flag_ICastable; - private const int ParentMethodTableOffset = 0x10 + private const int DebugClassNamePtr = // adjust for debug_m_szClassName #if DEBUG - + sizeof(nuint) // adjust for debug_m_szClassName -#endif - ; - #if TARGET_64BIT - private const int ElementTypeOffset = 0x30 + 8 #else - private const int ElementTypeOffset = 0x20 + 4 #endif -#if DEBUG - + sizeof(nuint) // adjust for debug_m_szClassName +#else + 0 #endif - ; + ; + + private const int ParentMethodTableOffset = 0x10 + DebugClassNamePtr; #if TARGET_64BIT - private const int InterfaceMapOffset = 0x38 + private const int ElementTypeOffset = 0x30 + DebugClassNamePtr; #else - private const int InterfaceMapOffset = 0x24 + private const int ElementTypeOffset = 0x20 + DebugClassNamePtr; #endif -#if DEBUG - + sizeof(nuint) // adjust for debug_m_szClassName + +#if TARGET_64BIT + private const int InterfaceMapOffset = 0x38 + DebugClassNamePtr; +#else + private const int InterfaceMapOffset = 0x24 + DebugClassNamePtr; #endif - ; public bool HasComponentSize { diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/Unsafe.cs b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/Unsafe.cs index 62649b4c224636..ca63162736745b 100644 --- a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/Unsafe.cs +++ b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/Unsafe.cs @@ -8,15 +8,6 @@ using System.Runtime.CompilerServices; using System.Runtime.Versioning; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -using nint = System.Int64; -#else -using nuint = System.UInt32; -using nint = System.Int32; -#endif - // // The implementations of most the methods in this file are provided as intrinsics. // In CoreCLR, the body of the functions are replaced by the EE with unsafe code. See see getILIntrinsicImplementationForUnsafe for details. @@ -145,19 +136,6 @@ public static ref T Add(ref T source, IntPtr elementOffset) #endif } -#if TARGET_64BIT - /// - /// Adds an element offset to the given reference. - /// - [Intrinsic] - [NonVersionable] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ref T Add(ref T source, nint elementOffset) - { - return ref Unsafe.Add(ref source, (IntPtr)(void*)elementOffset); - } -#endif - /// /// Adds an byte offset to the given reference. /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffer.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Buffer.Unix.cs index 6c6a823a521e06..18f55d3bb39812 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffer.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffer.Unix.cs @@ -2,26 +2,19 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System { public static partial class Buffer { #if TARGET_ARM64 - // Managed code is currently faster than glibc unoptimized memmove - // TODO-ARM64-UNIX-OPT revisit when glibc optimized memmove is in Linux distros - // https://github.com/dotnet/runtime/issues/8897 - private const nuint MemmoveNativeThreshold = ulong.MaxValue; + // Managed code is currently faster than glibc unoptimized memmove + // TODO-ARM64-UNIX-OPT revisit when glibc optimized memmove is in Linux distros + // https://github.com/dotnet/runtime/issues/8897 + private static nuint MemmoveNativeThreshold => nuint.MaxValue; #elif TARGET_ARM - private const nuint MemmoveNativeThreshold = 512; + private const nuint MemmoveNativeThreshold = 512; #else - private const nuint MemmoveNativeThreshold = 2048; + private const nuint MemmoveNativeThreshold = 2048; #endif } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffer.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Buffer.Windows.cs index 226a0cd7e1d1b0..d5607de9134784 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffer.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffer.Windows.cs @@ -2,13 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System { public static partial class Buffer @@ -16,7 +9,7 @@ public static partial class Buffer #if TARGET_ARM64 // Determine optimal value for Windows. // https://github.com/dotnet/runtime/issues/8896 - private const nuint MemmoveNativeThreshold = ulong.MaxValue; + private static nuint MemmoveNativeThreshold => nuint.MaxValue; #else private const nuint MemmoveNativeThreshold = 2048; #endif diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffer.cs b/src/libraries/System.Private.CoreLib/src/System/Buffer.cs index e8d9b778282216..3880d590ca4ce0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffer.cs @@ -12,15 +12,6 @@ using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nint = System.Int64; -using nuint = System.UInt64; -#else -using nint = System.Int32; -using nuint = System.UInt32; -#endif - namespace System { public static partial class Buffer @@ -341,7 +332,7 @@ ref Unsafe.As(ref source), private static void Memmove(ref byte dest, ref byte src, nuint len) { // P/Invoke into the native version when the buffers are overlapping. - if (((nuint)Unsafe.ByteOffset(ref src, ref dest) < len) || ((nuint)Unsafe.ByteOffset(ref dest, ref src) < len)) + if (((nuint)(nint)Unsafe.ByteOffset(ref src, ref dest) < len) || ((nuint)(nint)Unsafe.ByteOffset(ref dest, ref src) < len)) { goto BuffersOverlap; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs index b1253aa3ff290f..321c2119cfe567 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs @@ -8,13 +8,6 @@ using System.Runtime.InteropServices; using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nint = System.Int64; -#else -using nint = System.Int32; -#endif - namespace System.Collections.Generic { #region ArraySortHelper for single arrays diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CharUnicodeInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CharUnicodeInfo.cs index 9a1c24607e71f7..51d0ae46b3ae10 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CharUnicodeInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CharUnicodeInfo.cs @@ -9,13 +9,6 @@ using System.Text.Unicode; using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System.Globalization { /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs index eaa2042fd9e558..0481c684cd8a98 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs @@ -10,13 +10,6 @@ using System.Text.Unicode; using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else // TARGET_64BIT -using nuint = System.UInt32; -#endif // TARGET_64BIT - namespace System.Globalization { /// diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs b/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs index ecdb454203bf4e..6c17ca92ac85a0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs @@ -8,13 +8,6 @@ using System.Threading; using System.Threading.Tasks; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System.IO { /* diff --git a/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs b/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs index d82c18f1fa78ea..720da614f236e2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs @@ -11,9 +11,9 @@ #pragma warning disable SA1121 // explicitly using type aliases instead of built-in types #if TARGET_64BIT -using nint = System.Int64; +using nint_t = System.Int64; #else -using nint = System.Int32; +using nint_t = System.Int32; #endif namespace System @@ -162,7 +162,7 @@ public static IntPtr Subtract(IntPtr pointer, int offset) => public static int Size { [NonVersionable] - get => sizeof(nint); + get => sizeof(nint_t); } [CLSCompliant(false)] @@ -172,25 +172,24 @@ public static int Size public static IntPtr MaxValue { [NonVersionable] - get => (IntPtr)nint.MaxValue; + get => (IntPtr)nint_t.MaxValue; } public static IntPtr MinValue { [NonVersionable] - get => (IntPtr)nint.MinValue; + get => (IntPtr)nint_t.MinValue; } - // Don't just delegate to nint.CompareTo as it needs to throw when not IntPtr + // Don't just delegate to nint_t.CompareTo as it needs to throw when not IntPtr public unsafe int CompareTo(object? value) { if (value is null) { return 1; } - if (value is IntPtr o) + if (value is nint i) { - nint i = (nint)o; if ((nint)_value < i) return -1; if ((nint)_value > i) return 1; return 0; @@ -199,31 +198,31 @@ public unsafe int CompareTo(object? value) throw new ArgumentException(SR.Arg_MustBeIntPtr); } - public unsafe int CompareTo(IntPtr value) => ((nint)_value).CompareTo((nint)value); + public unsafe int CompareTo(IntPtr value) => ((nint_t)_value).CompareTo((nint_t)value); [NonVersionable] - public unsafe bool Equals(IntPtr other) => (nint)_value == (nint)other; + public unsafe bool Equals(IntPtr other) => (nint_t)_value == (nint_t)other; - public unsafe override string ToString() => ((nint)_value).ToString(); - public unsafe string ToString(string? format) => ((nint)_value).ToString(format); - public unsafe string ToString(IFormatProvider? provider) => ((nint)_value).ToString(provider); - public unsafe string ToString(string? format, IFormatProvider? provider) => ((nint)_value).ToString(format, provider); + public unsafe override string ToString() => ((nint_t)_value).ToString(); + public unsafe string ToString(string? format) => ((nint_t)_value).ToString(format); + public unsafe string ToString(IFormatProvider? provider) => ((nint_t)_value).ToString(provider); + public unsafe string ToString(string? format, IFormatProvider? provider) => ((nint_t)_value).ToString(format, provider); - public static IntPtr Parse(string s) => (IntPtr)nint.Parse(s); - public static IntPtr Parse(string s, NumberStyles style) => (IntPtr)nint.Parse(s, style); - public static IntPtr Parse(string s, IFormatProvider? provider) => (IntPtr)nint.Parse(s, provider); - public static IntPtr Parse(string s, NumberStyles style, IFormatProvider? provider) => (IntPtr)nint.Parse(s, style, provider); + public static IntPtr Parse(string s) => (IntPtr)nint_t.Parse(s); + public static IntPtr Parse(string s, NumberStyles style) => (IntPtr)nint_t.Parse(s, style); + public static IntPtr Parse(string s, IFormatProvider? provider) => (IntPtr)nint_t.Parse(s, provider); + public static IntPtr Parse(string s, NumberStyles style, IFormatProvider? provider) => (IntPtr)nint_t.Parse(s, style, provider); public static bool TryParse(string? s, out IntPtr result) { Unsafe.SkipInit(out result); - return nint.TryParse(s, out Unsafe.As(ref result)); + return nint_t.TryParse(s, out Unsafe.As(ref result)); } public static bool TryParse(string? s, NumberStyles style, IFormatProvider? provider, out IntPtr result) { Unsafe.SkipInit(out result); - return nint.TryParse(s, style, provider, out Unsafe.As(ref result)); + return nint_t.TryParse(s, style, provider, out Unsafe.As(ref result)); } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Marvin.OrdinalIgnoreCase.cs b/src/libraries/System.Private.CoreLib/src/System/Marvin.OrdinalIgnoreCase.cs index c8ff3fb7eaefef..9867caac97dbd4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Marvin.OrdinalIgnoreCase.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Marvin.OrdinalIgnoreCase.cs @@ -8,13 +8,6 @@ using System.Text.Unicode; using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System { internal static partial class Marvin diff --git a/src/libraries/System.Private.CoreLib/src/System/Marvin.cs b/src/libraries/System.Private.CoreLib/src/System/Marvin.cs index 4e5b9d5a035b67..f397c230b5019b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Marvin.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Marvin.cs @@ -8,13 +8,6 @@ using System.Runtime.InteropServices; using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System { internal static partial class Marvin diff --git a/src/libraries/System.Private.CoreLib/src/System/Memory.cs b/src/libraries/System.Private.CoreLib/src/System/Memory.cs index cb8f631c5d44c6..bed73caea13571 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Memory.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Memory.cs @@ -12,13 +12,6 @@ using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else // TARGET_64BIT -using nuint = System.UInt32; -#endif // TARGET_64BIT - namespace System { /// @@ -364,7 +357,7 @@ public unsafe Span Span ThrowHelper.ThrowArgumentOutOfRangeException(); } #else - if ((uint)desiredStartIndex > (uint)lengthOfUnderlyingSpan || (uint)desiredLength > (uint)(lengthOfUnderlyingSpan - desiredStartIndex)) + if ((uint)desiredStartIndex > (uint)lengthOfUnderlyingSpan || (uint)desiredLength > (uint)lengthOfUnderlyingSpan - (uint)desiredStartIndex) { ThrowHelper.ThrowArgumentOutOfRangeException(); } diff --git a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs index 2a66efac7709c6..33bc6f9e1fffc3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs +++ b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs @@ -8,13 +8,6 @@ using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif // TARGET_64BIT - namespace System { /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector.cs index f20b762afbf13f..e27b5bf883d1cd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector.cs @@ -10,13 +10,6 @@ using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nint = System.Int64; -#else -using nint = System.Int32; -#endif - namespace System.Numerics { /* Note: The following patterns are used throughout the code here and are described here diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector.tt b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector.tt index 3c02ba2bebac02..86bd98984a9471 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector.tt +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector.tt @@ -15,13 +15,6 @@ using System.Text; using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nint = System.Int64; -#else -using nint = System.Int32; -#endif - namespace System.Numerics { /* Note: The following patterns are used throughout the code here and are described here diff --git a/src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs b/src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs index 77552dea34750a..c66cd3b699a564 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs @@ -12,13 +12,6 @@ using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else // TARGET_64BIT -using nuint = System.UInt32; -#endif // TARGET_64BIT - namespace System { /// @@ -286,7 +279,7 @@ public unsafe ReadOnlySpan Span ThrowHelper.ThrowArgumentOutOfRangeException(); } #else - if ((uint)desiredStartIndex > (uint)lengthOfUnderlyingSpan || (uint)desiredLength > (uint)(lengthOfUnderlyingSpan - desiredStartIndex)) + if ((uint)desiredStartIndex > (uint)lengthOfUnderlyingSpan || (uint)desiredLength > (uint)lengthOfUnderlyingSpan - (uint)desiredStartIndex) { ThrowHelper.ThrowArgumentOutOfRangeException(); } diff --git a/src/libraries/System.Private.CoreLib/src/System/ReadOnlySpan.cs b/src/libraries/System.Private.CoreLib/src/System/ReadOnlySpan.cs index a765967f5f87a8..7ce5284ad2d33f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ReadOnlySpan.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ReadOnlySpan.cs @@ -13,13 +13,6 @@ #pragma warning disable 0809 //warning CS0809: Obsolete member 'Span.Equals(object)' overrides non-obsolete member 'object.Equals(object)' -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System { /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs index 2413cacd01d02b..736259d2334f8a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs @@ -4,13 +4,6 @@ using System.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System.Runtime.InteropServices { public struct ArrayWithOffset diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.cs index b7bd0361d53cca..c163c364771d4b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.cs @@ -7,13 +7,6 @@ using System.Threading; using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nint = System.Int64; -#else -using nint = System.Int32; -#endif - namespace System.Runtime.InteropServices { /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs index 227e84e71c2fac..76aab4ab2c4b18 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs @@ -10,13 +10,6 @@ using Internal.Runtime.CompilerServices; using System.Diagnostics.CodeAnalysis; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System.Runtime.InteropServices { /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Span.cs b/src/libraries/System.Private.CoreLib/src/System/Span.cs index 25bab98c889918..6016674dcdfdfd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Span.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Span.cs @@ -13,13 +13,6 @@ #pragma warning disable 0809 //warning CS0809: Obsolete member 'Span.Equals(object)' overrides non-obsolete member 'object.Equals(object)' -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System { /// @@ -273,7 +266,7 @@ public ref T GetPinnableReference() /// Clears the contents of this span. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Clear() + public unsafe void Clear() { if (RuntimeHelpers.IsReferenceOrContainsReferences()) { diff --git a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.Byte.cs b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.Byte.cs index f965f98ac7f5ed..c396bb06fe653c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.Byte.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.Byte.cs @@ -10,15 +10,6 @@ using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -using nint = System.Int64; -#else -using nuint = System.UInt32; -using nint = System.Int32; -#endif // TARGET_64BIT - namespace System { internal static partial class SpanHelpers // .Byte @@ -1311,11 +1302,11 @@ public static int LastIndexOfAny(ref byte searchSpace, byte value0, byte value1, // Optimized byte-based SequenceEquals. The "length" parameter for this one is declared a nuint rather than int as we also use it for types other than byte // where the length can exceed 2Gb once scaled by sizeof(T). - public static bool SequenceEqual(ref byte first, ref byte second, nuint length) + public static unsafe bool SequenceEqual(ref byte first, ref byte second, nuint length) { bool result; // Use nint for arithmetic to avoid unnecessary 64->32->64 truncations - if (length >= sizeof(nuint)) + if (length >= (nuint)sizeof(nuint)) { // Conditional jmp foward to favor shorter lengths. (See comment at "Equal:" label) // The longer lengths can make back the time due to branch misprediction @@ -1473,9 +1464,9 @@ public static bool SequenceEqual(ref byte first, ref byte second, nuint length) #if TARGET_64BIT if (Sse2.IsSupported) { - Debug.Assert(length <= sizeof(nuint) * 2); + Debug.Assert(length <= (nuint)sizeof(nuint) * 2); - nuint offset = length - sizeof(nuint); + nuint offset = length - (nuint)sizeof(nuint); nuint differentBits = LoadNUInt(ref first) - LoadNUInt(ref second); differentBits |= LoadNUInt(ref first, offset) - LoadNUInt(ref second, offset); result = (differentBits == 0); @@ -1484,10 +1475,10 @@ public static bool SequenceEqual(ref byte first, ref byte second, nuint length) else #endif { - Debug.Assert(length >= sizeof(nuint)); + Debug.Assert(length >= (nuint)sizeof(nuint)); { nuint offset = 0; - nuint lengthToExamine = length - sizeof(nuint); + nuint lengthToExamine = length - (nuint)sizeof(nuint); // Unsigned, so it shouldn't have overflowed larger than length (rather than negative) Debug.Assert(lengthToExamine < length); if (lengthToExamine > 0) @@ -1499,7 +1490,7 @@ public static bool SequenceEqual(ref byte first, ref byte second, nuint length) { goto NotEqual; } - offset += sizeof(nuint); + offset += (nuint)sizeof(nuint); } while (lengthToExamine > offset); } @@ -1540,7 +1531,7 @@ private static int LocateFirstFoundByte(Vector match) } [MethodImpl(MethodImplOptions.AggressiveOptimization)] - public static int SequenceCompareTo(ref byte first, int firstLength, ref byte second, int secondLength) + public static unsafe int SequenceCompareTo(ref byte first, int firstLength, ref byte second, int secondLength) { Debug.Assert(firstLength >= 0); Debug.Assert(secondLength >= 0); @@ -1693,16 +1684,16 @@ public static int SequenceCompareTo(ref byte first, int firstLength, ref byte se } } - if (lengthToExamine > sizeof(nuint)) + if (lengthToExamine > (nuint)sizeof(nuint)) { - lengthToExamine -= sizeof(nuint); + lengthToExamine -= (nuint)sizeof(nuint); while (lengthToExamine > offset) { if (LoadNUInt(ref first, offset) != LoadNUInt(ref second, offset)) { goto BytewiseCheck; } - offset += sizeof(nuint); + offset += (nuint)sizeof(nuint); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.Char.cs b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.Char.cs index 0f21d07c107c08..b3234e4aa77a13 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.Char.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.Char.cs @@ -10,15 +10,6 @@ using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -using nint = System.Int64; -#else -using nuint = System.UInt32; -using nint = System.Int32; -#endif - namespace System { internal static partial class SpanHelpers // .Char @@ -66,7 +57,7 @@ ref Unsafe.As(ref valueTail), } [MethodImpl(MethodImplOptions.AggressiveOptimization)] - public static int SequenceCompareTo(ref char first, int firstLength, ref char second, int secondLength) + public static unsafe int SequenceCompareTo(ref char first, int firstLength, ref char second, int secondLength) { Debug.Assert(firstLength >= 0); Debug.Assert(secondLength >= 0); @@ -79,7 +70,7 @@ public static int SequenceCompareTo(ref char first, int firstLength, ref char se nuint minLength = (nuint)(((uint)firstLength < (uint)secondLength) ? (uint)firstLength : (uint)secondLength); nuint i = 0; // Use nuint for arithmetic to avoid unnecessary 64->32->64 truncations - if (minLength >= (sizeof(nuint) / sizeof(char))) + if (minLength >= (nuint)(sizeof(nuint) / sizeof(char))) { if (Vector.IsHardwareAccelerated && minLength >= (nuint)Vector.Count) { @@ -96,14 +87,14 @@ public static int SequenceCompareTo(ref char first, int firstLength, ref char se while (nLength >= i); } - while (minLength >= (i + sizeof(nuint) / sizeof(char))) + while (minLength >= (i + (nuint)(sizeof(nuint) / sizeof(char)))) { if (Unsafe.ReadUnaligned (ref Unsafe.As(ref Unsafe.Add(ref first, (nint)i))) != Unsafe.ReadUnaligned(ref Unsafe.As(ref Unsafe.Add(ref second, (nint)i)))) { break; } - i += sizeof(nuint) / sizeof(char); + i += (nuint)(sizeof(nuint) / sizeof(char)); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.cs b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.cs index ddd2416eceaea0..24e82c21a8267e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.cs @@ -6,13 +6,6 @@ using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System { internal static partial class SpanHelpers @@ -348,14 +341,14 @@ public static unsafe void ClearWithReferences(ref IntPtr ip, nuint pointerSizeLe for (; pointerSizeLength >= 8; pointerSizeLength -= 8) { - Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -1) = default; - Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -2) = default; - Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -3) = default; - Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -4) = default; - Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -5) = default; - Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -6) = default; - Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -7) = default; - Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -8) = default; + Unsafe.Add(ref Unsafe.Add(ref ip, (nint)pointerSizeLength), -1) = default; + Unsafe.Add(ref Unsafe.Add(ref ip, (nint)pointerSizeLength), -2) = default; + Unsafe.Add(ref Unsafe.Add(ref ip, (nint)pointerSizeLength), -3) = default; + Unsafe.Add(ref Unsafe.Add(ref ip, (nint)pointerSizeLength), -4) = default; + Unsafe.Add(ref Unsafe.Add(ref ip, (nint)pointerSizeLength), -5) = default; + Unsafe.Add(ref Unsafe.Add(ref ip, (nint)pointerSizeLength), -6) = default; + Unsafe.Add(ref Unsafe.Add(ref ip, (nint)pointerSizeLength), -7) = default; + Unsafe.Add(ref Unsafe.Add(ref ip, (nint)pointerSizeLength), -8) = default; } Debug.Assert(pointerSizeLength <= 7); @@ -396,15 +389,15 @@ public static unsafe void ClearWithReferences(ref IntPtr ip, nuint pointerSizeLe // Write first four and last three. Unsafe.Add(ref ip, 2) = default; Unsafe.Add(ref ip, 3) = default; - Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -3) = default; - Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -2) = default; + Unsafe.Add(ref Unsafe.Add(ref ip, (nint)pointerSizeLength), -3) = default; + Unsafe.Add(ref Unsafe.Add(ref ip, (nint)pointerSizeLength), -2) = default; Write2To3: Debug.Assert(pointerSizeLength >= 2); // Write first two and last one. Unsafe.Add(ref ip, 1) = default; - Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -1) = default; + Unsafe.Add(ref Unsafe.Add(ref ip, (nint)pointerSizeLength), -1) = default; Write1: Debug.Assert(pointerSizeLength >= 1); diff --git a/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs b/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs index 5ceed67a563a94..1708b2cb1e3289 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs @@ -10,13 +10,6 @@ using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System { public partial class String diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs b/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs index c0bdbf03f70599..31de76bfd0c9ad 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs @@ -12,32 +12,10 @@ using Internal.Runtime.CompilerServices; #endif -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if SYSTEM_PRIVATE_CORELIB -#if TARGET_64BIT -using nint = System.Int64; -using nuint = System.UInt64; -#else // TARGET_64BIT -using nint = System.Int32; -using nuint = System.UInt32; -#endif // TARGET_64BIT -#else -using nint = System.Int64; // https://github.com/dotnet/runtime/issues/33575 - use long/ulong outside of corelib until the compiler supports it -using nuint = System.UInt64; -#endif - namespace System.Text { internal static partial class ASCIIUtility { -#if DEBUG && SYSTEM_PRIVATE_CORELIB - static ASCIIUtility() - { - Debug.Assert(sizeof(nint) == IntPtr.Size && nint.MinValue < 0, "nint is defined incorrectly."); - Debug.Assert(sizeof(nuint) == IntPtr.Size && nuint.MinValue == 0, "nuint is defined incorrectly."); - } -#endif // DEBUG && SYSTEM_PRIVATE_CORELIB - [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool AllBytesInUInt64AreAscii(ulong value) { @@ -524,7 +502,9 @@ private static unsafe nuint GetIndexOfFirstNonAsciiChar_Default(char* pBuffer, n char* pOriginalBuffer = pBuffer; +#if SYSTEM_PRIVATE_CORELIB Debug.Assert(bufferLength <= nuint.MaxValue / sizeof(char)); +#endif // Before we drain off char-by-char, try a generic vectorized loop. // Only run the loop if we have at least two vectors we can pull out. @@ -687,7 +667,9 @@ private static unsafe nuint GetIndexOfFirstNonAsciiChar_Sse2(char* pBuffer, nuin Vector128 asciiMaskForPADDUSW = Vector128.Create((ushort)0x7F80); // used for PADDUSW const uint NonAsciiDataSeenMask = 0b_1010_1010_1010_1010; // used for determining whether 'currentMask' contains non-ASCII data +#if SYSTEM_PRIVATE_CORELIB Debug.Assert(bufferLength <= nuint.MaxValue / sizeof(char)); +#endif // Read the first vector unaligned. diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf16Utility.Validation.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf16Utility.Validation.cs index 73bfa603f92528..c2b38f159d6aab 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf16Utility.Validation.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf16Utility.Validation.cs @@ -15,15 +15,12 @@ #pragma warning disable SA1121 // explicitly using type aliases instead of built-in types #if SYSTEM_PRIVATE_CORELIB #if TARGET_64BIT -using nint = System.Int64; -using nuint = System.UInt64; +using nuint_t = System.UInt64; #else // TARGET_64BIT -using nint = System.Int32; -using nuint = System.UInt32; +using nuint_t = System.UInt32; #endif // TARGET_64BIT #else -using nint = System.Int64; // https://github.com/dotnet/runtime/issues/33575 - use long/ulong outside of corelib until the compiler supports it -using nuint = System.UInt64; +using nuint_t = System.UInt64; #endif namespace System.Text.Unicode @@ -33,8 +30,7 @@ internal static unsafe partial class Utf16Utility #if DEBUG && SYSTEM_PRIVATE_CORELIB static Utf16Utility() { - Debug.Assert(sizeof(nint) == IntPtr.Size && nint.MinValue < 0, "nint is defined incorrectly."); - Debug.Assert(sizeof(nuint) == IntPtr.Size && nuint.MinValue == 0, "nuint is defined incorrectly."); + Debug.Assert(sizeof(nuint_t) == IntPtr.Size && nuint.MinValue == 0, "nuint_t is defined incorrectly."); } #endif // DEBUG && SYSTEM_PRIVATE_CORELIB @@ -291,15 +287,15 @@ static Utf16Utility() Vector utf16Data = Unsafe.ReadUnaligned>(pInputBuffer); Vector twoOrMoreUtf8Bytes = Vector.GreaterThanOrEqual(utf16Data, vector0080); Vector threeOrMoreUtf8Bytes = Vector.GreaterThanOrEqual(utf16Data, vector0800); - Vector sumVector = (Vector)(Vector.Zero - twoOrMoreUtf8Bytes - threeOrMoreUtf8Bytes); + Vector sumVector = (Vector)(Vector.Zero - twoOrMoreUtf8Bytes - threeOrMoreUtf8Bytes); // We'll try summing by a natural word (rather than a 16-bit word) at a time, // which should halve the number of operations we must perform. nuint popcnt = 0; - for (int i = 0; i < Vector.Count; i++) + for (int i = 0; i < Vector.Count; i++) { - popcnt += sumVector[i]; + popcnt += (nuint)sumVector[i]; } uint popcnt32 = (uint)popcnt; diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Transcoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Transcoding.cs index 64f76fec691474..201626fd6b876e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Transcoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Transcoding.cs @@ -13,34 +13,10 @@ using Internal.Runtime.CompilerServices; #endif -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if SYSTEM_PRIVATE_CORELIB -#if TARGET_64BIT -using nint = System.Int64; -using nuint = System.UInt64; -#else // TARGET_64BIT -using nint = System.Int32; -using nuint = System.UInt32; -#endif // TARGET_64BIT -#else -using nint = System.Int64; // https://github.com/dotnet/runtime/issues/33575 - use long/ulong outside of corelib until the compiler supports it -using nuint = System.UInt64; -#endif - namespace System.Text.Unicode { internal static unsafe partial class Utf8Utility { -#if DEBUG && SYSTEM_PRIVATE_CORELIB - static Utf8Utility() - { - Debug.Assert(sizeof(nint) == IntPtr.Size && nint.MinValue < 0, "nint is defined incorrectly."); - Debug.Assert(sizeof(nuint) == IntPtr.Size && nuint.MinValue == 0, "nuint is defined incorrectly."); - - _ValidateAdditionalNIntDefinitions(); - } -#endif // DEBUG && SYSTEM_PRIVATE_CORELIB - // On method return, pInputBufferRemaining and pOutputBufferRemaining will both point to where // the next byte would have been consumed from / the next char would have been written to. // inputLength in bytes, outputCharsRemaining in chars. diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Validation.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Validation.cs index 8284828d530436..636829e289c268 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Validation.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Validation.cs @@ -11,32 +11,10 @@ using Internal.Runtime.CompilerServices; #endif -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if SYSTEM_PRIVATE_CORELIB -#if TARGET_64BIT -using nint = System.Int64; -using nuint = System.UInt64; -#else // TARGET_64BIT -using nint = System.Int32; -using nuint = System.UInt32; -#endif // TARGET_64BIT -#else -using nint = System.Int64; // https://github.com/dotnet/runtime/issues/33575 - use long/ulong outside of corelib until the compiler supports it -using nuint = System.UInt64; -#endif - namespace System.Text.Unicode { internal static unsafe partial class Utf8Utility { -#if DEBUG && SYSTEM_PRIVATE_CORELIB - private static void _ValidateAdditionalNIntDefinitions() - { - Debug.Assert(sizeof(nint) == IntPtr.Size && nint.MinValue < 0, "nint is defined incorrectly."); - Debug.Assert(sizeof(nuint) == IntPtr.Size && nuint.MinValue == 0, "nuint is defined incorrectly."); - } -#endif // DEBUG && SYSTEM_PRIVATE_CORELIB - // Returns &inputBuffer[inputLength] if the input buffer is valid. /// /// Given an input buffer of byte length , diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.WhiteSpace.CoreLib.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.WhiteSpace.CoreLib.cs index cf656bc1dc2d1c..6c34b06728dd93 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.WhiteSpace.CoreLib.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.WhiteSpace.CoreLib.cs @@ -5,14 +5,6 @@ using System.Runtime.InteropServices; using Internal.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nint = System.Int32; -using nuint = System.UInt32; -#endif - namespace System.Text.Unicode { internal static partial class Utf8Utility diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Utf8Span.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Utf8Span.cs index eb6cdb6527d416..3a90590bb6da76 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Utf8Span.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Utf8Span.cs @@ -15,20 +15,6 @@ #pragma warning disable 0809 //warning CS0809: Obsolete member 'Utf8Span.Equals(object)' overrides non-obsolete member 'object.Equals(object)' -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if SYSTEM_PRIVATE_CORELIB -#if TARGET_64BIT -using nint = System.Int64; -using nuint = System.UInt64; -#else -using nint = System.Int32; -using nuint = System.UInt32; -#endif -#else -using nint = System.Int64; // https://github.com/dotnet/runtime/issues/33575 - use long/ulong outside of corelib until the compiler supports it -using nuint = System.UInt64; -#endif - namespace System.Text { [StructLayout(LayoutKind.Auto)] @@ -132,7 +118,7 @@ internal ref byte DangerousGetMutableReference(nuint index) #if SYSTEM_PRIVATE_CORELIB return ref Unsafe.AddByteOffset(ref DangerousGetMutableReference(), index); #else - return ref Unsafe.AddByteOffset(ref DangerousGetMutableReference(), (IntPtr)index); + return ref Unsafe.AddByteOffset(ref DangerousGetMutableReference(), (nint)index); #endif } diff --git a/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs b/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs index 99eb0cf759087f..d28bd83c90a312 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs @@ -11,9 +11,9 @@ #pragma warning disable SA1121 // explicitly using type aliases instead of built-in types #if TARGET_64BIT -using nuint = System.UInt64; +using nuint_t = System.UInt64; #else -using nuint = System.UInt32; +using nuint_t = System.UInt32; #endif namespace System @@ -156,7 +156,7 @@ public static UIntPtr Subtract(UIntPtr pointer, int offset) => public static int Size { [NonVersionable] - get => sizeof(nuint); + get => sizeof(nuint_t); } [NonVersionable] @@ -165,13 +165,13 @@ public static int Size public static UIntPtr MaxValue { [NonVersionable] - get => (UIntPtr)nuint.MaxValue; + get => (UIntPtr)nuint_t.MaxValue; } public static UIntPtr MinValue { [NonVersionable] - get => (UIntPtr)nuint.MinValue; + get => (UIntPtr)nuint_t.MinValue; } public unsafe int CompareTo(object? value) @@ -180,9 +180,8 @@ public unsafe int CompareTo(object? value) { return 1; } - if (value is UIntPtr o) + if (value is nuint i) { - nuint i = (nuint)o; if ((nuint)_value < i) return -1; if ((nuint)_value > i) return 1; return 0; @@ -191,31 +190,31 @@ public unsafe int CompareTo(object? value) throw new ArgumentException(SR.Arg_MustBeUIntPtr); } - public unsafe int CompareTo(UIntPtr value) => ((nuint)_value).CompareTo((nuint)value); + public unsafe int CompareTo(UIntPtr value) => ((nuint_t)_value).CompareTo((nuint_t)value); [NonVersionable] public unsafe bool Equals(UIntPtr other) => (nuint)_value == (nuint)other; - public unsafe override string ToString() => ((nuint)_value).ToString(); - public unsafe string ToString(string? format) => ((nuint)_value).ToString(format); - public unsafe string ToString(IFormatProvider? provider) => ((nuint)_value).ToString(provider); - public unsafe string ToString(string? format, IFormatProvider? provider) => ((nuint)_value).ToString(format, provider); + public unsafe override string ToString() => ((nuint_t)_value).ToString(); + public unsafe string ToString(string? format) => ((nuint_t)_value).ToString(format); + public unsafe string ToString(IFormatProvider? provider) => ((nuint_t)_value).ToString(provider); + public unsafe string ToString(string? format, IFormatProvider? provider) => ((nuint_t)_value).ToString(format, provider); - public static UIntPtr Parse(string s) => (UIntPtr)nuint.Parse(s); - public static UIntPtr Parse(string s, NumberStyles style) => (UIntPtr)nuint.Parse(s, style); - public static UIntPtr Parse(string s, IFormatProvider? provider) => (UIntPtr)nuint.Parse(s, provider); - public static UIntPtr Parse(string s, NumberStyles style, IFormatProvider? provider) => (UIntPtr)nuint.Parse(s, style, provider); + public static UIntPtr Parse(string s) => (UIntPtr)nuint_t.Parse(s); + public static UIntPtr Parse(string s, NumberStyles style) => (UIntPtr)nuint_t.Parse(s, style); + public static UIntPtr Parse(string s, IFormatProvider? provider) => (UIntPtr)nuint_t.Parse(s, provider); + public static UIntPtr Parse(string s, NumberStyles style, IFormatProvider? provider) => (UIntPtr)nuint_t.Parse(s, style, provider); public static bool TryParse(string? s, out UIntPtr result) { Unsafe.SkipInit(out result); - return nuint.TryParse(s, out Unsafe.As(ref result)); + return nuint_t.TryParse(s, out Unsafe.As(ref result)); } public static bool TryParse(string? s, NumberStyles style, IFormatProvider? provider, out UIntPtr result) { Unsafe.SkipInit(out result); - return nuint.TryParse(s, style, provider, out Unsafe.As(ref result)); + return nuint_t.TryParse(s, style, provider, out Unsafe.As(ref result)); } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Utf8String.cs b/src/libraries/System.Private.CoreLib/src/System/Utf8String.cs index e6cba4d2e4c2b1..0989371e22878e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Utf8String.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Utf8String.cs @@ -13,20 +13,6 @@ using Internal.Runtime.CompilerServices; #endif -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if SYSTEM_PRIVATE_CORELIB -#if TARGET_64BIT -using nint = System.Int64; -using nuint = System.UInt64; -#else -using nint = System.Int32; -using nuint = System.UInt32; -#endif -#else -using nint = System.Int64; // https://github.com/dotnet/runtime/issues/33575 - use long/ulong outside of corelib until the compiler supports it -using nuint = System.UInt64; -#endif - namespace System { /// @@ -133,7 +119,7 @@ internal ref byte DangerousGetMutableReference(nuint index) #if SYSTEM_PRIVATE_CORELIB return ref Unsafe.AddByteOffset(ref DangerousGetMutableReference(), index); #else - return ref Unsafe.AddByteOffset(ref DangerousGetMutableReference(), (IntPtr)index); + return ref Unsafe.AddByteOffset(ref DangerousGetMutableReference(), (nint)index); #endif } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Array.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Array.Mono.cs index 908a3baa8e7615..e04efea520a939 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Array.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Array.Mono.cs @@ -9,13 +9,6 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System { public partial class Array @@ -61,7 +54,7 @@ public static unsafe void Clear(Array array, int index, int length) int lowerBound = array.GetLowerBound(0); int elementSize = array.GetElementSize(); - nuint numComponents = (nuint)Unsafe.As(array).Count; + nuint numComponents = (nuint)(nint)Unsafe.As(array).Count; int offset = index - lowerBound; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Buffer.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Buffer.Mono.cs index b4772965b6ad33..6f04b9742a55a2 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Buffer.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Buffer.Mono.cs @@ -4,13 +4,6 @@ using System.Runtime.CompilerServices; -#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types -#if TARGET_64BIT -using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif - namespace System { public partial class Buffer