From 9685e6cb021f8e2bdd1a660b59dd8b286812fc7e Mon Sep 17 00:00:00 2001 From: Aaron R Robinson Date: Wed, 7 Aug 2024 16:03:00 -0700 Subject: [PATCH 1/6] Add DebuggerHidden to helpers --- .../src/System/ThrowHelper.cs | 3 + .../src/System/ThrowHelper.cs | 208 +++++++++--------- 2 files changed, 107 insertions(+), 104 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/ThrowHelper.cs b/src/coreclr/System.Private.CoreLib/src/System/ThrowHelper.cs index 254cc0df8a270..e79d62d9f0533 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/ThrowHelper.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/ThrowHelper.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -13,6 +14,7 @@ internal static unsafe partial class ThrowHelper [LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_ThrowAmbiguousResolutionException")] private static partial void ThrowAmbiguousResolutionException(MethodTable* targetType, MethodTable* interfaceType, void* methodDesc); + [DebuggerHidden] [DoesNotReturn] internal static void ThrowAmbiguousResolutionException( void* method, // MethodDesc* @@ -26,6 +28,7 @@ internal static void ThrowAmbiguousResolutionException( [LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_ThrowEntryPointNotFoundException")] private static partial void ThrowEntryPointNotFoundException(MethodTable* targetType, MethodTable* interfaceType, void* methodDesc); + [DebuggerHidden] [DoesNotReturn] internal static void ThrowEntryPointNotFoundException( void* method, // MethodDesc* diff --git a/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs b/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs index 4dc475742c6db..fcf59e9a64fad 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs @@ -53,275 +53,275 @@ namespace System [StackTraceHidden] internal static partial class ThrowHelper { - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArithmeticException(string message) { throw new ArithmeticException(message); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowAccessViolationException() { throw new AccessViolationException(); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArrayTypeMismatchException() { throw new ArrayTypeMismatchException(); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException() { throw new ArgumentException(); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowInvalidTypeWithPointersNotSupported(Type targetType) { throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, targetType)); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowIndexOutOfRangeException() { throw new IndexOutOfRangeException(); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRangeException() { throw new ArgumentOutOfRangeException(); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowNotImplementedException() { throw new NotImplementedException(); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowPlatformNotSupportedException() { throw new PlatformNotSupportedException(); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowTypeNotSupportedException() { throw new NotSupportedException(SR.Arg_TypeNotSupported); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowVerificationException(int ilOffset) { throw new System.Security.VerificationException(); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException_DestinationTooShort() { throw new ArgumentException(SR.Argument_DestinationTooShort, "destination"); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException_InvalidTimeSpanStyles() { throw new ArgumentException(SR.Argument_InvalidTimeSpanStyles, "styles"); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException_InvalidEnumValue(TEnum value, [CallerArgumentExpression(nameof(value))] string argumentName = "") { throw new ArgumentException(SR.Format(SR.Argument_InvalidEnumValue, value, typeof(TEnum).Name), argumentName); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException_OverlapAlignmentMismatch() { throw new ArgumentException(SR.Argument_OverlapAlignmentMismatch); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException_ArgumentNull_TypedRefType() { throw new ArgumentNullException("value", SR.ArgumentNull_TypedRefType); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException_CannotExtractScalar(ExceptionArgument argument) { throw GetArgumentException(ExceptionResource.Argument_CannotExtractScalar, argument); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException_TupleIncorrectType(object obj) { throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, obj.GetType()), "other"); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRange_IndexMustBeLessException() { throw GetArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException() { throw GetArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException_BadComparer(object? comparer) { throw new ArgumentException(SR.Format(SR.Arg_BogusIComparer, comparer)); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowIndexArgumentOutOfRange_NeedNonNegNumException() { throw GetArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowValueArgumentOutOfRange_NeedNonNegNumException() { throw GetArgumentOutOfRangeException(ExceptionArgument.value, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum() { throw GetArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLessOrEqual() { throw GetArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess() { throw GetArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count() { throw GetArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRange_Year() { throw GetArgumentOutOfRangeException(ExceptionArgument.year, ExceptionResource.ArgumentOutOfRange_Year); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRange_Month(int month) { throw new ArgumentOutOfRangeException(nameof(month), month, SR.ArgumentOutOfRange_Month); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRange_DayNumber(int dayNumber) { throw new ArgumentOutOfRangeException(nameof(dayNumber), dayNumber, SR.ArgumentOutOfRange_DayNumber); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRange_BadYearMonthDay() { throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadYearMonthDay); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRange_BadHourMinuteSecond() { throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadHourMinuteSecond); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRange_TimeSpanTooLong() { throw new ArgumentOutOfRangeException(null, SR.Overflow_TimeSpanTooLong); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRange_RoundingDigits(string name) { throw new ArgumentOutOfRangeException(name, SR.ArgumentOutOfRange_RoundingDigits); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRange_RoundingDigits_MathF(string name) { throw new ArgumentOutOfRangeException(name, SR.ArgumentOutOfRange_RoundingDigits_MathF); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRange_Range(string parameterName, T value, T minInclusive, T maxInclusive) { throw new ArgumentOutOfRangeException(parameterName, value, SR.Format(SR.ArgumentOutOfRange_Range, minInclusive, maxInclusive)); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowOverflowException() { throw new OverflowException(); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowOverflowException_NegateTwosCompNum() { throw new OverflowException(SR.Overflow_NegateTwosCompNum); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowOverflowException_TimeSpanTooLong() { throw new OverflowException(SR.Overflow_TimeSpanTooLong); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowOverflowException_TimeSpanDuration() { throw new OverflowException(SR.Overflow_Duration); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException_Arg_CannotBeNaN() { throw new ArgumentException(SR.Arg_CannotBeNaN); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException_Arg_CannotBeNaN(ExceptionArgument argument) { throw new ArgumentException(SR.Arg_CannotBeNaN, GetArgumentName(argument)); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowWrongKeyTypeArgumentException(T key, Type targetType) { // Generic key to move the boxing to the right hand side of throw throw GetWrongKeyTypeArgumentException((object?)key, targetType); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowWrongValueTypeArgumentException(T value, Type targetType) { // Generic key to move the boxing to the right hand side of throw @@ -333,81 +333,81 @@ private static ArgumentException GetAddingDuplicateWithKeyArgumentException(obje return new ArgumentException(SR.Format(SR.Argument_AddingDuplicateWithKey, key)); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowAddingDuplicateWithKeyArgumentException(T key) { // Generic key to move the boxing to the right hand side of throw throw GetAddingDuplicateWithKeyArgumentException((object?)key); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowKeyNotFoundException(T key) { // Generic key to move the boxing to the right hand side of throw throw GetKeyNotFoundException((object?)key); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException(ExceptionResource resource) { throw GetArgumentException(resource); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException(ExceptionResource resource, ExceptionArgument argument) { throw GetArgumentException(resource, argument); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException_HandleNotSync(string paramName) { throw new ArgumentException(SR.Arg_HandleNotSync, paramName); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException_HandleNotAsync(string paramName) { throw new ArgumentException(SR.Arg_HandleNotAsync, paramName); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentNullException(ExceptionArgument argument) { throw new ArgumentNullException(GetArgumentName(argument)); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentNullException(ExceptionResource resource) { throw new ArgumentNullException(GetResourceString(resource)); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentNullException(ExceptionArgument argument, ExceptionResource resource) { throw new ArgumentNullException(GetArgumentName(argument), GetResourceString(resource)); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument) { throw new ArgumentOutOfRangeException(GetArgumentName(argument)); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) { throw GetArgumentOutOfRangeException(argument, resource); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, int paramNumber, ExceptionResource resource) { throw GetArgumentOutOfRangeException(argument, paramNumber, resource); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowEndOfFileException() { throw CreateEndOfFileException(); @@ -416,259 +416,259 @@ internal static void ThrowEndOfFileException() internal static Exception CreateEndOfFileException() => new EndOfStreamException(SR.IO_EOF_ReadBeyondEOF); - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowInvalidOperationException() { throw new InvalidOperationException(); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowInvalidOperationException(ExceptionResource resource) { throw GetInvalidOperationException(resource); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowInvalidOperationException(ExceptionResource resource, Exception e) { throw new InvalidOperationException(GetResourceString(resource), e); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowNullReferenceException() { throw new NullReferenceException(SR.Arg_NullArgumentNullRef); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowSerializationException(ExceptionResource resource) { throw new SerializationException(GetResourceString(resource)); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowRankException(ExceptionResource resource) { throw new RankException(GetResourceString(resource)); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowNotSupportedException(ExceptionResource resource) { throw new NotSupportedException(GetResourceString(resource)); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowNotSupportedException_UnseekableStream() { throw new NotSupportedException(SR.NotSupported_UnseekableStream); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowNotSupportedException_UnreadableStream() { throw new NotSupportedException(SR.NotSupported_UnreadableStream); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowNotSupportedException_UnwritableStream() { throw new NotSupportedException(SR.NotSupported_UnwritableStream); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowObjectDisposedException(object? instance) { throw new ObjectDisposedException(instance?.GetType().FullName); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowObjectDisposedException(Type? type) { throw new ObjectDisposedException(type?.FullName); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowObjectDisposedException_StreamClosed(string? objectName) { throw new ObjectDisposedException(objectName, SR.ObjectDisposed_StreamClosed); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowObjectDisposedException_FileClosed() { throw new ObjectDisposedException(null, SR.ObjectDisposed_FileClosed); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowObjectDisposedException(ExceptionResource resource) { throw new ObjectDisposedException(null, GetResourceString(resource)); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowNotSupportedException() { throw new NotSupportedException(); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowAggregateException(List exceptions) { throw new AggregateException(exceptions); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowOutOfMemoryException() { throw new OutOfMemoryException(); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowDivideByZeroException() { throw new DivideByZeroException(); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowOutOfMemoryException_StringTooLong() { throw new OutOfMemoryException(SR.OutOfMemory_StringTooLong); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowOutOfMemoryException_LockEnter_WaiterCountOverflow() { throw new OutOfMemoryException(SR.Lock_Enter_WaiterCountOverflow_OutOfMemoryException); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException_Argument_IncompatibleArrayType() { throw new ArgumentException(SR.Argument_IncompatibleArrayType); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentException_InvalidHandle(string? paramName) { throw new ArgumentException(SR.Arg_InvalidHandle, paramName); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowUnexpectedStateForKnownCallback(object? state) { throw new ArgumentOutOfRangeException(nameof(state), state, SR.Argument_UnexpectedStateForKnownCallback); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowInvalidOperationException_InvalidOperation_EnumNotStarted() { throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowInvalidOperationException_InvalidOperation_EnumEnded() { throw new InvalidOperationException(SR.InvalidOperation_EnumEnded); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowInvalidOperationException_EnumCurrent(int index) { throw GetInvalidOperationException_EnumCurrent(index); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion() { throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen() { throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowInvalidOperationException_InvalidOperation_NoValue() { throw new InvalidOperationException(SR.InvalidOperation_NoValue); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowInvalidOperationException_ConcurrentOperationsNotSupported() { throw new InvalidOperationException(SR.InvalidOperation_ConcurrentOperationsNotSupported); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowInvalidOperationException_HandleIsNotInitialized() { throw new InvalidOperationException(SR.InvalidOperation_HandleIsNotInitialized); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowInvalidOperationException_HandleIsNotPinned() { throw new InvalidOperationException(SR.InvalidOperation_HandleIsNotPinned); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArraySegmentCtorValidationFailedExceptions(Array? array, int offset, int count) { throw GetArraySegmentCtorValidationFailedException(array, offset, count); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowInvalidOperationException_InvalidUtf8() { throw new InvalidOperationException(SR.InvalidOperation_InvalidUtf8); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowFormatException_BadFormatSpecifier() { throw new FormatException(SR.Argument_BadFormatSpecifier); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowFormatException_NeedSingleChar() { throw new FormatException(SR.Format_NeedSingleChar); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowFormatException_BadBoolean(ReadOnlySpan value) { throw new FormatException(SR.Format(SR.Format_BadBoolean, new string(value))); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRangeException_PrecisionTooLarge() { throw new ArgumentOutOfRangeException("precision", SR.Format(SR.Argument_PrecisionTooLarge, StandardFormat.MaxPrecision)); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRangeException_SymbolDoesNotFit() { throw new ArgumentOutOfRangeException("symbol", SR.Argument_BadFormatSpecifier); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowArgumentOutOfRangeException_NeedNonNegNum(string paramName) { throw new ArgumentOutOfRangeException(paramName, SR.ArgumentOutOfRange_NeedNonNegNum); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ArgumentOutOfRangeException_Enum_Value() { throw new ArgumentOutOfRangeException("value", SR.ArgumentOutOfRange_Enum); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowApplicationException(int hr) { // Get a message for this HR @@ -686,25 +686,25 @@ internal static void ThrowApplicationException(int hr) throw ex; } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowFormatInvalidString() { throw new FormatException(SR.Format_InvalidString); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowFormatInvalidString(int offset, ExceptionResource resource) { throw new FormatException(SR.Format(SR.Format_InvalidStringWithOffsetAndReason, offset, GetResourceString(resource))); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowFormatIndexOutOfRange() { throw new FormatException(SR.Format_IndexOutOfRange); } - [DoesNotReturn] + [DoesNotReturn, DebuggerHidden] internal static void ThrowSynchronizationLockException_LockExit() { throw new SynchronizationLockException(SR.Lock_Exit_SynchronizationLockException); From dc1c3f9b51834feeb40364d201f9785e48370219 Mon Sep 17 00:00:00 2001 From: Aaron R Robinson Date: Fri, 9 Aug 2024 12:09:07 -0700 Subject: [PATCH 2/6] Consolidate throw helpers --- .../System.Private.CoreLib.csproj | 2 +- .../Runtime/CompilerHelpers/ThrowHelpers.cs} | 10 +- src/coreclr/inc/jithelpers.h | 24 +- .../Runtime/CompilerHelpers/ThrowHelpers.cs | 42 +--- src/coreclr/vm/corelib.h | 26 +- src/coreclr/vm/namespace.h | 1 + .../Runtime/CompilerHelpers/ThrowHelpers.cs | 89 +++++++ .../System.Private.CoreLib.Shared.projitems | 1 + .../src/System/ThrowHelper.cs | 230 ++++++++---------- 9 files changed, 224 insertions(+), 201 deletions(-) rename src/coreclr/System.Private.CoreLib/src/{System/ThrowHelper.cs => Internal/Runtime/CompilerHelpers/ThrowHelpers.cs} (91%) create mode 100644 src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs diff --git a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj index 115e29762b420..5ac4d2d78b58e 100644 --- a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -111,6 +111,7 @@ + @@ -231,7 +232,6 @@ - diff --git a/src/coreclr/System.Private.CoreLib/src/System/ThrowHelper.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs similarity index 91% rename from src/coreclr/System.Private.CoreLib/src/System/ThrowHelper.cs rename to src/coreclr/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs index e79d62d9f0533..726103c55a802 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/ThrowHelper.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs @@ -6,16 +6,18 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace System +namespace Internal.Runtime.CompilerHelpers { - internal static unsafe partial class ThrowHelper + [StackTraceHidden] + [DebuggerStepThrough] + internal static unsafe partial class ThrowHelpers { [DoesNotReturn] [LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_ThrowAmbiguousResolutionException")] private static partial void ThrowAmbiguousResolutionException(MethodTable* targetType, MethodTable* interfaceType, void* methodDesc); - [DebuggerHidden] [DoesNotReturn] + [DebuggerHidden] internal static void ThrowAmbiguousResolutionException( void* method, // MethodDesc* void* interfaceType, // MethodTable* @@ -28,8 +30,8 @@ internal static void ThrowAmbiguousResolutionException( [LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_ThrowEntryPointNotFoundException")] private static partial void ThrowEntryPointNotFoundException(MethodTable* targetType, MethodTable* interfaceType, void* methodDesc); - [DebuggerHidden] [DoesNotReturn] + [DebuggerHidden] internal static void ThrowEntryPointNotFoundException( void* method, // MethodDesc* void* interfaceType, // MethodTable* diff --git a/src/coreclr/inc/jithelpers.h b/src/coreclr/inc/jithelpers.h index 4401a38098921..81d603baaf216 100644 --- a/src/coreclr/inc/jithelpers.h +++ b/src/coreclr/inc/jithelpers.h @@ -119,11 +119,11 @@ DYNAMICJITHELPER(CORINFO_HELP_THROW, IL_Throw, METHOD__NIL) DYNAMICJITHELPER(CORINFO_HELP_RETHROW, IL_Rethrow, METHOD__NIL) JITHELPER(CORINFO_HELP_USER_BREAKPOINT, JIT_UserBreakpoint, METHOD__NIL) - DYNAMICJITHELPER(CORINFO_HELP_RNGCHKFAIL, NULL, METHOD__THROWHELPER__THROWINDEXOUTOFRANGEEXCEPTION) - DYNAMICJITHELPER(CORINFO_HELP_OVERFLOW, NULL, METHOD__THROWHELPER__THROWOVERFLOWEXCEPTION) - DYNAMICJITHELPER(CORINFO_HELP_THROWDIVZERO, NULL, METHOD__THROWHELPER__THROWDIVIDEBYZEROEXCEPTION) - DYNAMICJITHELPER(CORINFO_HELP_THROWNULLREF, NULL, METHOD__THROWHELPER__THROWNULLREFEXCEPTION) - DYNAMICJITHELPER(CORINFO_HELP_VERIFICATION, NULL, METHOD__THROWHELPER__THROWVERIFICATIONEXCEPTION) + DYNAMICJITHELPER(CORINFO_HELP_RNGCHKFAIL, NULL, METHOD__THROWHELPERS__THROWINDEXOUTOFRANGEEXCEPTION) + DYNAMICJITHELPER(CORINFO_HELP_OVERFLOW, NULL, METHOD__THROWHELPERS__THROWOVERFLOWEXCEPTION) + DYNAMICJITHELPER(CORINFO_HELP_THROWDIVZERO, NULL, METHOD__THROWHELPERS__THROWDIVIDEBYZEROEXCEPTION) + DYNAMICJITHELPER(CORINFO_HELP_THROWNULLREF, NULL, METHOD__THROWHELPERS__THROWNULLREFEXCEPTION) + DYNAMICJITHELPER(CORINFO_HELP_VERIFICATION, NULL, METHOD__THROWHELPERS__THROWVERIFICATIONEXCEPTION) JITHELPER(CORINFO_HELP_FAIL_FAST, JIT_FailFast, METHOD__NIL) JITHELPER(CORINFO_HELP_METHOD_ACCESS_EXCEPTION,JIT_ThrowMethodAccessException, METHOD__NIL) JITHELPER(CORINFO_HELP_FIELD_ACCESS_EXCEPTION,JIT_ThrowFieldAccessException, METHOD__NIL) @@ -291,13 +291,13 @@ JITHELPER(CORINFO_HELP_LOOP_CLONE_CHOICE_ADDR, JIT_LoopCloneChoiceAddr, METHOD__NIL) JITHELPER(CORINFO_HELP_DEBUG_LOG_LOOP_CLONING, JIT_DebugLogLoopCloning, METHOD__NIL) - DYNAMICJITHELPER(CORINFO_HELP_THROW_ARGUMENTEXCEPTION, NULL, METHOD__THROWHELPER__THROWARGUMENTEXCEPTION) - DYNAMICJITHELPER(CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION, NULL, METHOD__THROWHELPER__THROWARGUMENTOUTOFRANGEEXCEPTION) - DYNAMICJITHELPER(CORINFO_HELP_THROW_NOT_IMPLEMENTED, NULL, METHOD__THROWHELPER__THROWNOTIMPLEMENTEDEXCEPTION) - DYNAMICJITHELPER(CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED, NULL, METHOD__THROWHELPER__THROWPLATFORMNOTSUPPORTEDEXCEPTION) - DYNAMICJITHELPER(CORINFO_HELP_THROW_TYPE_NOT_SUPPORTED, NULL, METHOD__THROWHELPER__THROWTYPENOTSUPPORTED) - DYNAMICJITHELPER(CORINFO_HELP_THROW_AMBIGUOUS_RESOLUTION_EXCEPTION, NULL, METHOD__THROWHELPER__THROWAMBIGUOUSRESOLUTIONEXCEPTION) - DYNAMICJITHELPER(CORINFO_HELP_THROW_ENTRYPOINT_NOT_FOUND_EXCEPTION, NULL, METHOD__THROWHELPER__THROWENTRYPOINTNOTFOUNDEXCEPTION) + DYNAMICJITHELPER(CORINFO_HELP_THROW_ARGUMENTEXCEPTION, NULL, METHOD__THROWHELPERS__THROWARGUMENTEXCEPTION) + DYNAMICJITHELPER(CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION, NULL, METHOD__THROWHELPERS__THROWARGUMENTOUTOFRANGEEXCEPTION) + DYNAMICJITHELPER(CORINFO_HELP_THROW_NOT_IMPLEMENTED, NULL, METHOD__THROWHELPERS__THROWNOTIMPLEMENTEDEXCEPTION) + DYNAMICJITHELPER(CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED, NULL, METHOD__THROWHELPERS__THROWPLATFORMNOTSUPPORTEDEXCEPTION) + DYNAMICJITHELPER(CORINFO_HELP_THROW_TYPE_NOT_SUPPORTED, NULL, METHOD__THROWHELPERS__THROWTYPENOTSUPPORTED) + DYNAMICJITHELPER(CORINFO_HELP_THROW_AMBIGUOUS_RESOLUTION_EXCEPTION, NULL, METHOD__THROWHELPERS__THROWAMBIGUOUSRESOLUTIONEXCEPTION) + DYNAMICJITHELPER(CORINFO_HELP_THROW_ENTRYPOINT_NOT_FOUND_EXCEPTION, NULL, METHOD__THROWHELPERS__THROWENTRYPOINTNOTFOUNDEXCEPTION) JITHELPER(CORINFO_HELP_JIT_PINVOKE_BEGIN, JIT_PInvokeBegin, METHOD__NIL) JITHELPER(CORINFO_HELP_JIT_PINVOKE_END, JIT_PInvokeEnd, METHOD__NIL) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs index c71b79f8dc0f9..d182694db52c1 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs @@ -11,7 +11,7 @@ namespace Internal.Runtime.CompilerHelpers /// These methods are used to throw exceptions from generated code. The type and methods /// need to be public as they constitute a public contract with the NativeAOT toolchain. /// - public static class ThrowHelpers + public static partial class ThrowHelpers { internal static void ThrowBodyRemoved() { @@ -33,41 +33,11 @@ internal static void ThrowUnavailableType() throw new TypeLoadException(SR.Arg_UnavailableTypeLoadException); } - public static void ThrowOverflowException() - { - throw new OverflowException(); - } - - public static void ThrowIndexOutOfRangeException() - { - throw new IndexOutOfRangeException(); - } - - public static void ThrowNullReferenceException() - { - throw new NullReferenceException(); - } - - public static void ThrowDivideByZeroException() - { - throw new DivideByZeroException(); - } - public static void ThrowArrayTypeMismatchException() { throw new ArrayTypeMismatchException(); } - public static void ThrowPlatformNotSupportedException() - { - throw new PlatformNotSupportedException(); - } - - public static void ThrowNotImplementedException() - { - throw NotImplemented.ByDesign; - } - public static void ThrowNotSupportedException() { throw new NotSupportedException(); @@ -123,16 +93,6 @@ public static void ThrowAmbiguousMatchException(ExceptionStringID id) throw TypeLoaderExceptionHelper.CreateAmbiguousMatchException(id); } - public static void ThrowArgumentException() - { - throw new ArgumentException(); - } - - public static void ThrowArgumentOutOfRangeException() - { - throw new ArgumentOutOfRangeException(); - } - public static void ThrowNotSupportedInlineArrayEqualsGetHashCode() { throw new NotSupportedException(SR.NotSupported_InlineArrayEqualsGetHashCode); diff --git a/src/coreclr/vm/corelib.h b/src/coreclr/vm/corelib.h index a6b278aa708a4..f4b3d60dc830d 100644 --- a/src/coreclr/vm/corelib.h +++ b/src/coreclr/vm/corelib.h @@ -642,19 +642,19 @@ DEFINE_METHOD(SPAN_HELPERS, MEMSET, Fill, SM_RefByte_Byt DEFINE_METHOD(SPAN_HELPERS, MEMZERO, ClearWithoutReferences, SM_RefByte_UIntPtr_RetVoid) DEFINE_METHOD(SPAN_HELPERS, MEMCOPY, Memmove, SM_RefByte_RefByte_UIntPtr_RetVoid) -DEFINE_CLASS(THROWHELPER, System, ThrowHelper) -DEFINE_METHOD(THROWHELPER, THROWARGUMENTEXCEPTION, ThrowArgumentException, SM_RetVoid) -DEFINE_METHOD(THROWHELPER, THROWARGUMENTOUTOFRANGEEXCEPTION, ThrowArgumentOutOfRangeException, SM_RetVoid) -DEFINE_METHOD(THROWHELPER, THROWINDEXOUTOFRANGEEXCEPTION, ThrowIndexOutOfRangeException, SM_RetVoid) -DEFINE_METHOD(THROWHELPER, THROWNOTIMPLEMENTEDEXCEPTION, ThrowNotImplementedException, SM_RetVoid) -DEFINE_METHOD(THROWHELPER, THROWPLATFORMNOTSUPPORTEDEXCEPTION, ThrowPlatformNotSupportedException, SM_RetVoid) -DEFINE_METHOD(THROWHELPER, THROWTYPENOTSUPPORTED, ThrowTypeNotSupportedException, SM_RetVoid) -DEFINE_METHOD(THROWHELPER, THROWOVERFLOWEXCEPTION, ThrowOverflowException, SM_RetVoid) -DEFINE_METHOD(THROWHELPER, THROWDIVIDEBYZEROEXCEPTION, ThrowDivideByZeroException, SM_RetVoid) -DEFINE_METHOD(THROWHELPER, THROWNULLREFEXCEPTION, ThrowNullReferenceException, SM_RetVoid) -DEFINE_METHOD(THROWHELPER, THROWVERIFICATIONEXCEPTION, ThrowVerificationException, SM_Int_RetVoid) -DEFINE_METHOD(THROWHELPER, THROWAMBIGUOUSRESOLUTIONEXCEPTION, ThrowAmbiguousResolutionException, SM_PtrVoid_PtrVoid_PtrVoid_RetVoid) -DEFINE_METHOD(THROWHELPER, THROWENTRYPOINTNOTFOUNDEXCEPTION, ThrowEntryPointNotFoundException, SM_PtrVoid_PtrVoid_PtrVoid_RetVoid) +DEFINE_CLASS(THROWHELPERS, InternalCompilerHelpers, ThrowHelpers) +DEFINE_METHOD(THROWHELPERS, THROWARGUMENTEXCEPTION, ThrowArgumentException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWARGUMENTOUTOFRANGEEXCEPTION, ThrowArgumentOutOfRangeException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWINDEXOUTOFRANGEEXCEPTION, ThrowIndexOutOfRangeException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWNOTIMPLEMENTEDEXCEPTION, ThrowNotImplementedException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWPLATFORMNOTSUPPORTEDEXCEPTION, ThrowPlatformNotSupportedException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWTYPENOTSUPPORTED, ThrowTypeNotSupportedException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWOVERFLOWEXCEPTION, ThrowOverflowException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWDIVIDEBYZEROEXCEPTION, ThrowDivideByZeroException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWNULLREFEXCEPTION, ThrowNullReferenceException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWVERIFICATIONEXCEPTION, ThrowVerificationException, SM_Int_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWAMBIGUOUSRESOLUTIONEXCEPTION, ThrowAmbiguousResolutionException, SM_PtrVoid_PtrVoid_PtrVoid_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWENTRYPOINTNOTFOUNDEXCEPTION, ThrowEntryPointNotFoundException, SM_PtrVoid_PtrVoid_PtrVoid_RetVoid) DEFINE_CLASS(UNSAFE, CompilerServices, Unsafe) DEFINE_METHOD(UNSAFE, AS_POINTER, AsPointer, NoSig) diff --git a/src/coreclr/vm/namespace.h b/src/coreclr/vm/namespace.h index a8ae97a5c1877..f792f6b8bb2a6 100644 --- a/src/coreclr/vm/namespace.h +++ b/src/coreclr/vm/namespace.h @@ -38,6 +38,7 @@ #define g_IntrinsicsNS g_RuntimeNS ".Intrinsics" #define g_NumericsNS g_SystemNS ".Numerics" +#define g_InternalCompilerHelpersNS "Internal.Runtime.CompilerHelpers" #define g_CompilerServicesNS g_RuntimeNS ".CompilerServices" #define g_ConstrainedExecutionNS g_RuntimeNS ".ConstrainedExecution" diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs new file mode 100644 index 0000000000000..5d0d0444a554f --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs @@ -0,0 +1,89 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace Internal.Runtime.CompilerHelpers +{ +#if NATIVEAOT + public +#else + internal +#endif + static unsafe partial class ThrowHelpers + { + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowArgumentException() + { + throw new ArgumentException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowIndexOutOfRangeException() + { + throw new IndexOutOfRangeException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowArgumentOutOfRangeException() + { + throw new ArgumentOutOfRangeException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowNotImplementedException() + { + throw new NotImplementedException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowPlatformNotSupportedException() + { + throw new PlatformNotSupportedException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowTypeNotSupportedException() + { + throw new NotSupportedException(SR.Arg_TypeNotSupported); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowVerificationException(int ilOffset) + { + throw new System.Security.VerificationException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowOverflowException() + { + throw new OverflowException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowDivideByZeroException() + { + throw new DivideByZeroException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowNullReferenceException() + { + throw new NullReferenceException(); + } + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 032299180e78d..412fb8ba8b864 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -71,6 +71,7 @@ + diff --git a/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs b/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs index fcf59e9a64fad..41ab0698b0bd9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs @@ -51,277 +51,247 @@ namespace System { [StackTraceHidden] - internal static partial class ThrowHelper + internal static class ThrowHelper { - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArithmeticException(string message) { throw new ArithmeticException(message); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowAccessViolationException() { throw new AccessViolationException(); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArrayTypeMismatchException() { throw new ArrayTypeMismatchException(); } - [DoesNotReturn, DebuggerHidden] - internal static void ThrowArgumentException() - { - throw new ArgumentException(); - } - - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowInvalidTypeWithPointersNotSupported(Type targetType) { throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, targetType)); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowIndexOutOfRangeException() { throw new IndexOutOfRangeException(); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException() { throw new ArgumentOutOfRangeException(); } - [DoesNotReturn, DebuggerHidden] - internal static void ThrowNotImplementedException() - { - throw new NotImplementedException(); - } - - [DoesNotReturn, DebuggerHidden] - internal static void ThrowPlatformNotSupportedException() - { - throw new PlatformNotSupportedException(); - } - - [DoesNotReturn, DebuggerHidden] - internal static void ThrowTypeNotSupportedException() - { - throw new NotSupportedException(SR.Arg_TypeNotSupported); - } - - [DoesNotReturn, DebuggerHidden] - internal static void ThrowVerificationException(int ilOffset) - { - throw new System.Security.VerificationException(); - } - - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException_DestinationTooShort() { throw new ArgumentException(SR.Argument_DestinationTooShort, "destination"); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException_InvalidTimeSpanStyles() { throw new ArgumentException(SR.Argument_InvalidTimeSpanStyles, "styles"); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException_InvalidEnumValue(TEnum value, [CallerArgumentExpression(nameof(value))] string argumentName = "") { throw new ArgumentException(SR.Format(SR.Argument_InvalidEnumValue, value, typeof(TEnum).Name), argumentName); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException_OverlapAlignmentMismatch() { throw new ArgumentException(SR.Argument_OverlapAlignmentMismatch); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException_ArgumentNull_TypedRefType() { throw new ArgumentNullException("value", SR.ArgumentNull_TypedRefType); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException_CannotExtractScalar(ExceptionArgument argument) { throw GetArgumentException(ExceptionResource.Argument_CannotExtractScalar, argument); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException_TupleIncorrectType(object obj) { throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, obj.GetType()), "other"); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRange_IndexMustBeLessException() { throw GetArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException() { throw GetArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException_BadComparer(object? comparer) { throw new ArgumentException(SR.Format(SR.Arg_BogusIComparer, comparer)); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowIndexArgumentOutOfRange_NeedNonNegNumException() { throw GetArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowValueArgumentOutOfRange_NeedNonNegNumException() { throw GetArgumentOutOfRangeException(ExceptionArgument.value, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum() { throw GetArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLessOrEqual() { throw GetArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess() { throw GetArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count() { throw GetArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRange_Year() { throw GetArgumentOutOfRangeException(ExceptionArgument.year, ExceptionResource.ArgumentOutOfRange_Year); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRange_Month(int month) { throw new ArgumentOutOfRangeException(nameof(month), month, SR.ArgumentOutOfRange_Month); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRange_DayNumber(int dayNumber) { throw new ArgumentOutOfRangeException(nameof(dayNumber), dayNumber, SR.ArgumentOutOfRange_DayNumber); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRange_BadYearMonthDay() { throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadYearMonthDay); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRange_BadHourMinuteSecond() { throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadHourMinuteSecond); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRange_TimeSpanTooLong() { throw new ArgumentOutOfRangeException(null, SR.Overflow_TimeSpanTooLong); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRange_RoundingDigits(string name) { throw new ArgumentOutOfRangeException(name, SR.ArgumentOutOfRange_RoundingDigits); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRange_RoundingDigits_MathF(string name) { throw new ArgumentOutOfRangeException(name, SR.ArgumentOutOfRange_RoundingDigits_MathF); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRange_Range(string parameterName, T value, T minInclusive, T maxInclusive) { throw new ArgumentOutOfRangeException(parameterName, value, SR.Format(SR.ArgumentOutOfRange_Range, minInclusive, maxInclusive)); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowOverflowException() { throw new OverflowException(); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowOverflowException_NegateTwosCompNum() { throw new OverflowException(SR.Overflow_NegateTwosCompNum); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowOverflowException_TimeSpanTooLong() { throw new OverflowException(SR.Overflow_TimeSpanTooLong); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowOverflowException_TimeSpanDuration() { throw new OverflowException(SR.Overflow_Duration); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException_Arg_CannotBeNaN() { throw new ArgumentException(SR.Arg_CannotBeNaN); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException_Arg_CannotBeNaN(ExceptionArgument argument) { throw new ArgumentException(SR.Arg_CannotBeNaN, GetArgumentName(argument)); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowWrongKeyTypeArgumentException(T key, Type targetType) { // Generic key to move the boxing to the right hand side of throw throw GetWrongKeyTypeArgumentException((object?)key, targetType); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowWrongValueTypeArgumentException(T value, Type targetType) { // Generic key to move the boxing to the right hand side of throw @@ -333,81 +303,81 @@ private static ArgumentException GetAddingDuplicateWithKeyArgumentException(obje return new ArgumentException(SR.Format(SR.Argument_AddingDuplicateWithKey, key)); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowAddingDuplicateWithKeyArgumentException(T key) { // Generic key to move the boxing to the right hand side of throw throw GetAddingDuplicateWithKeyArgumentException((object?)key); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowKeyNotFoundException(T key) { // Generic key to move the boxing to the right hand side of throw throw GetKeyNotFoundException((object?)key); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException(ExceptionResource resource) { throw GetArgumentException(resource); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException(ExceptionResource resource, ExceptionArgument argument) { throw GetArgumentException(resource, argument); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException_HandleNotSync(string paramName) { throw new ArgumentException(SR.Arg_HandleNotSync, paramName); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException_HandleNotAsync(string paramName) { throw new ArgumentException(SR.Arg_HandleNotAsync, paramName); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentNullException(ExceptionArgument argument) { throw new ArgumentNullException(GetArgumentName(argument)); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentNullException(ExceptionResource resource) { throw new ArgumentNullException(GetResourceString(resource)); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentNullException(ExceptionArgument argument, ExceptionResource resource) { throw new ArgumentNullException(GetArgumentName(argument), GetResourceString(resource)); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument) { throw new ArgumentOutOfRangeException(GetArgumentName(argument)); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) { throw GetArgumentOutOfRangeException(argument, resource); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, int paramNumber, ExceptionResource resource) { throw GetArgumentOutOfRangeException(argument, paramNumber, resource); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowEndOfFileException() { throw CreateEndOfFileException(); @@ -416,259 +386,259 @@ internal static void ThrowEndOfFileException() internal static Exception CreateEndOfFileException() => new EndOfStreamException(SR.IO_EOF_ReadBeyondEOF); - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowInvalidOperationException() { throw new InvalidOperationException(); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowInvalidOperationException(ExceptionResource resource) { throw GetInvalidOperationException(resource); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowInvalidOperationException(ExceptionResource resource, Exception e) { throw new InvalidOperationException(GetResourceString(resource), e); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowNullReferenceException() { throw new NullReferenceException(SR.Arg_NullArgumentNullRef); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowSerializationException(ExceptionResource resource) { throw new SerializationException(GetResourceString(resource)); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowRankException(ExceptionResource resource) { throw new RankException(GetResourceString(resource)); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowNotSupportedException(ExceptionResource resource) { throw new NotSupportedException(GetResourceString(resource)); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowNotSupportedException_UnseekableStream() { throw new NotSupportedException(SR.NotSupported_UnseekableStream); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowNotSupportedException_UnreadableStream() { throw new NotSupportedException(SR.NotSupported_UnreadableStream); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowNotSupportedException_UnwritableStream() { throw new NotSupportedException(SR.NotSupported_UnwritableStream); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowObjectDisposedException(object? instance) { throw new ObjectDisposedException(instance?.GetType().FullName); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowObjectDisposedException(Type? type) { throw new ObjectDisposedException(type?.FullName); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowObjectDisposedException_StreamClosed(string? objectName) { throw new ObjectDisposedException(objectName, SR.ObjectDisposed_StreamClosed); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowObjectDisposedException_FileClosed() { throw new ObjectDisposedException(null, SR.ObjectDisposed_FileClosed); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowObjectDisposedException(ExceptionResource resource) { throw new ObjectDisposedException(null, GetResourceString(resource)); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowNotSupportedException() { throw new NotSupportedException(); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowAggregateException(List exceptions) { throw new AggregateException(exceptions); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowOutOfMemoryException() { throw new OutOfMemoryException(); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowDivideByZeroException() { throw new DivideByZeroException(); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowOutOfMemoryException_StringTooLong() { throw new OutOfMemoryException(SR.OutOfMemory_StringTooLong); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowOutOfMemoryException_LockEnter_WaiterCountOverflow() { throw new OutOfMemoryException(SR.Lock_Enter_WaiterCountOverflow_OutOfMemoryException); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException_Argument_IncompatibleArrayType() { throw new ArgumentException(SR.Argument_IncompatibleArrayType); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentException_InvalidHandle(string? paramName) { throw new ArgumentException(SR.Arg_InvalidHandle, paramName); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowUnexpectedStateForKnownCallback(object? state) { throw new ArgumentOutOfRangeException(nameof(state), state, SR.Argument_UnexpectedStateForKnownCallback); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowInvalidOperationException_InvalidOperation_EnumNotStarted() { throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowInvalidOperationException_InvalidOperation_EnumEnded() { throw new InvalidOperationException(SR.InvalidOperation_EnumEnded); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowInvalidOperationException_EnumCurrent(int index) { throw GetInvalidOperationException_EnumCurrent(index); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion() { throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen() { throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowInvalidOperationException_InvalidOperation_NoValue() { throw new InvalidOperationException(SR.InvalidOperation_NoValue); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowInvalidOperationException_ConcurrentOperationsNotSupported() { throw new InvalidOperationException(SR.InvalidOperation_ConcurrentOperationsNotSupported); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowInvalidOperationException_HandleIsNotInitialized() { throw new InvalidOperationException(SR.InvalidOperation_HandleIsNotInitialized); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowInvalidOperationException_HandleIsNotPinned() { throw new InvalidOperationException(SR.InvalidOperation_HandleIsNotPinned); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArraySegmentCtorValidationFailedExceptions(Array? array, int offset, int count) { throw GetArraySegmentCtorValidationFailedException(array, offset, count); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowInvalidOperationException_InvalidUtf8() { throw new InvalidOperationException(SR.InvalidOperation_InvalidUtf8); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowFormatException_BadFormatSpecifier() { throw new FormatException(SR.Argument_BadFormatSpecifier); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowFormatException_NeedSingleChar() { throw new FormatException(SR.Format_NeedSingleChar); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowFormatException_BadBoolean(ReadOnlySpan value) { throw new FormatException(SR.Format(SR.Format_BadBoolean, new string(value))); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException_PrecisionTooLarge() { throw new ArgumentOutOfRangeException("precision", SR.Format(SR.Argument_PrecisionTooLarge, StandardFormat.MaxPrecision)); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException_SymbolDoesNotFit() { throw new ArgumentOutOfRangeException("symbol", SR.Argument_BadFormatSpecifier); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException_NeedNonNegNum(string paramName) { throw new ArgumentOutOfRangeException(paramName, SR.ArgumentOutOfRange_NeedNonNegNum); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ArgumentOutOfRangeException_Enum_Value() { throw new ArgumentOutOfRangeException("value", SR.ArgumentOutOfRange_Enum); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowApplicationException(int hr) { // Get a message for this HR @@ -686,25 +656,25 @@ internal static void ThrowApplicationException(int hr) throw ex; } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowFormatInvalidString() { throw new FormatException(SR.Format_InvalidString); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowFormatInvalidString(int offset, ExceptionResource resource) { throw new FormatException(SR.Format(SR.Format_InvalidStringWithOffsetAndReason, offset, GetResourceString(resource))); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowFormatIndexOutOfRange() { throw new FormatException(SR.Format_IndexOutOfRange); } - [DoesNotReturn, DebuggerHidden] + [DoesNotReturn] internal static void ThrowSynchronizationLockException_LockExit() { throw new SynchronizationLockException(SR.Lock_Exit_SynchronizationLockException); From 091282d94201ebab4fbdda310ad7b3c4661cdbdc Mon Sep 17 00:00:00 2001 From: Aaron R Robinson Date: Fri, 9 Aug 2024 13:32:18 -0700 Subject: [PATCH 3/6] Move remaining simply helpers to the shared location. Make members public for native AOT. --- .../Runtime/CompilerHelpers/ThrowHelpers.cs | 10 ---- src/coreclr/vm/corelib.h | 26 ++++----- .../Runtime/CompilerHelpers/ThrowHelpers.cs | 56 +++++++++++++------ 3 files changed, 51 insertions(+), 41 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs index d182694db52c1..2e08df0330fa2 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs @@ -33,16 +33,6 @@ internal static void ThrowUnavailableType() throw new TypeLoadException(SR.Arg_UnavailableTypeLoadException); } - public static void ThrowArrayTypeMismatchException() - { - throw new ArrayTypeMismatchException(); - } - - public static void ThrowNotSupportedException() - { - throw new NotSupportedException(); - } - public static void ThrowBadImageFormatException(ExceptionStringID id) { throw TypeLoaderExceptionHelper.CreateBadImageFormatException(id); diff --git a/src/coreclr/vm/corelib.h b/src/coreclr/vm/corelib.h index f4b3d60dc830d..6919701974a27 100644 --- a/src/coreclr/vm/corelib.h +++ b/src/coreclr/vm/corelib.h @@ -642,19 +642,19 @@ DEFINE_METHOD(SPAN_HELPERS, MEMSET, Fill, SM_RefByte_Byt DEFINE_METHOD(SPAN_HELPERS, MEMZERO, ClearWithoutReferences, SM_RefByte_UIntPtr_RetVoid) DEFINE_METHOD(SPAN_HELPERS, MEMCOPY, Memmove, SM_RefByte_RefByte_UIntPtr_RetVoid) -DEFINE_CLASS(THROWHELPERS, InternalCompilerHelpers, ThrowHelpers) -DEFINE_METHOD(THROWHELPERS, THROWARGUMENTEXCEPTION, ThrowArgumentException, SM_RetVoid) -DEFINE_METHOD(THROWHELPERS, THROWARGUMENTOUTOFRANGEEXCEPTION, ThrowArgumentOutOfRangeException, SM_RetVoid) -DEFINE_METHOD(THROWHELPERS, THROWINDEXOUTOFRANGEEXCEPTION, ThrowIndexOutOfRangeException, SM_RetVoid) -DEFINE_METHOD(THROWHELPERS, THROWNOTIMPLEMENTEDEXCEPTION, ThrowNotImplementedException, SM_RetVoid) -DEFINE_METHOD(THROWHELPERS, THROWPLATFORMNOTSUPPORTEDEXCEPTION, ThrowPlatformNotSupportedException, SM_RetVoid) -DEFINE_METHOD(THROWHELPERS, THROWTYPENOTSUPPORTED, ThrowTypeNotSupportedException, SM_RetVoid) -DEFINE_METHOD(THROWHELPERS, THROWOVERFLOWEXCEPTION, ThrowOverflowException, SM_RetVoid) -DEFINE_METHOD(THROWHELPERS, THROWDIVIDEBYZEROEXCEPTION, ThrowDivideByZeroException, SM_RetVoid) -DEFINE_METHOD(THROWHELPERS, THROWNULLREFEXCEPTION, ThrowNullReferenceException, SM_RetVoid) -DEFINE_METHOD(THROWHELPERS, THROWVERIFICATIONEXCEPTION, ThrowVerificationException, SM_Int_RetVoid) -DEFINE_METHOD(THROWHELPERS, THROWAMBIGUOUSRESOLUTIONEXCEPTION, ThrowAmbiguousResolutionException, SM_PtrVoid_PtrVoid_PtrVoid_RetVoid) -DEFINE_METHOD(THROWHELPERS, THROWENTRYPOINTNOTFOUNDEXCEPTION, ThrowEntryPointNotFoundException, SM_PtrVoid_PtrVoid_PtrVoid_RetVoid) +DEFINE_CLASS(THROWHELPERS, InternalCompilerHelpers, ThrowHelpers) +DEFINE_METHOD(THROWHELPERS, THROWARGUMENTEXCEPTION, ThrowArgumentException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWARGUMENTOUTOFRANGEEXCEPTION, ThrowArgumentOutOfRangeException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWINDEXOUTOFRANGEEXCEPTION, ThrowIndexOutOfRangeException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWNOTIMPLEMENTEDEXCEPTION, ThrowNotImplementedException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWPLATFORMNOTSUPPORTEDEXCEPTION, ThrowPlatformNotSupportedException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWTYPENOTSUPPORTED, ThrowTypeNotSupportedException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWOVERFLOWEXCEPTION, ThrowOverflowException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWDIVIDEBYZEROEXCEPTION, ThrowDivideByZeroException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWNULLREFEXCEPTION, ThrowNullReferenceException, SM_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWVERIFICATIONEXCEPTION, ThrowVerificationException, SM_Int_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWAMBIGUOUSRESOLUTIONEXCEPTION, ThrowAmbiguousResolutionException, SM_PtrVoid_PtrVoid_PtrVoid_RetVoid) +DEFINE_METHOD(THROWHELPERS, THROWENTRYPOINTNOTFOUNDEXCEPTION, ThrowEntryPointNotFoundException, SM_PtrVoid_PtrVoid_PtrVoid_RetVoid) DEFINE_CLASS(UNSAFE, CompilerServices, Unsafe) DEFINE_METHOD(UNSAFE, AS_POINTER, AsPointer, NoSig) diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs index 5d0d0444a554f..db45d4b316e03 100644 --- a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs +++ b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs @@ -9,6 +9,12 @@ namespace Internal.Runtime.CompilerHelpers { + /// + /// These methods are used to throw exceptions from generated code. + /// For NativeAOT, the type and methods used need to be public + /// as they constitute a public contract. + /// For CoreCLR, the type and methods are used as JIT helpers. + /// #if NATIVEAOT public #else @@ -18,72 +24,86 @@ static unsafe partial class ThrowHelpers { [DoesNotReturn] [DebuggerHidden] - internal static void ThrowArgumentException() + public static void ThrowNullReferenceException() { - throw new ArgumentException(); + throw new NullReferenceException(); } [DoesNotReturn] [DebuggerHidden] - internal static void ThrowIndexOutOfRangeException() + public static void ThrowArgumentException() { - throw new IndexOutOfRangeException(); + throw new ArgumentException(); } [DoesNotReturn] [DebuggerHidden] - internal static void ThrowArgumentOutOfRangeException() + public static void ThrowArgumentOutOfRangeException() { throw new ArgumentOutOfRangeException(); } [DoesNotReturn] [DebuggerHidden] - internal static void ThrowNotImplementedException() + public static void ThrowDivideByZeroException() { - throw new NotImplementedException(); + throw new DivideByZeroException(); + } + + [DoesNotReturn] + [DebuggerHidden] + public static void ThrowIndexOutOfRangeException() + { + throw new IndexOutOfRangeException(); + } + + [DoesNotReturn] + [DebuggerHidden] + public static void ThrowOverflowException() + { + throw new OverflowException(); } [DoesNotReturn] [DebuggerHidden] - internal static void ThrowPlatformNotSupportedException() + public static void ThrowPlatformNotSupportedException() { throw new PlatformNotSupportedException(); } [DoesNotReturn] [DebuggerHidden] - internal static void ThrowTypeNotSupportedException() + public static void ThrowNotImplementedException() { - throw new NotSupportedException(SR.Arg_TypeNotSupported); + throw new NotImplementedException(); } [DoesNotReturn] [DebuggerHidden] - internal static void ThrowVerificationException(int ilOffset) + public static void ThrowArrayTypeMismatchException() { - throw new System.Security.VerificationException(); + throw new ArrayTypeMismatchException(); } [DoesNotReturn] [DebuggerHidden] - internal static void ThrowOverflowException() + public static void ThrowNotSupportedException() { - throw new OverflowException(); + throw new NotSupportedException(); } [DoesNotReturn] [DebuggerHidden] - internal static void ThrowDivideByZeroException() + internal static void ThrowTypeNotSupportedException() { - throw new DivideByZeroException(); + throw new NotSupportedException(SR.Arg_TypeNotSupported); } [DoesNotReturn] [DebuggerHidden] - internal static void ThrowNullReferenceException() + internal static void ThrowVerificationException(int ilOffset) { - throw new NullReferenceException(); + throw new System.Security.VerificationException(); } } } From c23547ec2fe3d1641f39ad288a4d46982904191a Mon Sep 17 00:00:00 2001 From: Aaron R Robinson Date: Sun, 11 Aug 2024 10:42:35 -0700 Subject: [PATCH 4/6] PR feedback --- .../Runtime/CompilerHelpers/ThrowHelpers.cs | 2 - .../Runtime/CompilerHelpers/ThrowHelpers.cs | 58 ++++++++++++++----- .../Runtime/CompilerHelpers/ThrowHelpers.cs | 35 +++++------ 3 files changed, 55 insertions(+), 40 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs index 726103c55a802..fd01c28423ecc 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs @@ -8,8 +8,6 @@ namespace Internal.Runtime.CompilerHelpers { - [StackTraceHidden] - [DebuggerStepThrough] internal static unsafe partial class ThrowHelpers { [DoesNotReturn] diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs index 2e08df0330fa2..4304d70c4606b 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs @@ -7,83 +7,109 @@ namespace Internal.Runtime.CompilerHelpers { - /// - /// These methods are used to throw exceptions from generated code. The type and methods - /// need to be public as they constitute a public contract with the NativeAOT toolchain. - /// - public static partial class ThrowHelpers + internal static partial class ThrowHelpers { + [DoesNotReturn] + [DebuggerHidden] internal static void ThrowBodyRemoved() { throw new NotSupportedException(SR.NotSupported_BodyRemoved); } + [DoesNotReturn] + [DebuggerHidden] internal static void ThrowFeatureBodyRemoved() { throw new NotSupportedException(SR.NotSupported_FeatureBodyRemoved); } + [DoesNotReturn] + [DebuggerHidden] internal static void ThrowInstanceBodyRemoved() { throw new NotSupportedException(SR.NotSupported_InstanceBodyRemoved); } + [DoesNotReturn] + [DebuggerHidden] internal static void ThrowUnavailableType() { throw new TypeLoadException(SR.Arg_UnavailableTypeLoadException); } - public static void ThrowBadImageFormatException(ExceptionStringID id) + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowBadImageFormatException(ExceptionStringID id) { throw TypeLoaderExceptionHelper.CreateBadImageFormatException(id); } - public static void ThrowTypeLoadException(ExceptionStringID id, string className, string typeName) + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowTypeLoadException(ExceptionStringID id, string className, string typeName) { throw TypeLoaderExceptionHelper.CreateTypeLoadException(id, className, typeName); } - public static void ThrowTypeLoadExceptionWithArgument(ExceptionStringID id, string className, string typeName, string messageArg) + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowTypeLoadExceptionWithArgument(ExceptionStringID id, string className, string typeName, string messageArg) { throw TypeLoaderExceptionHelper.CreateTypeLoadException(id, className, typeName, messageArg); } - public static void ThrowMissingMethodException(ExceptionStringID id, string methodName) + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowMissingMethodException(ExceptionStringID id, string methodName) { throw TypeLoaderExceptionHelper.CreateMissingMethodException(id, methodName); } - public static void ThrowMissingFieldException(ExceptionStringID id, string fieldName) + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowMissingFieldException(ExceptionStringID id, string fieldName) { throw TypeLoaderExceptionHelper.CreateMissingFieldException(id, fieldName); } - public static void ThrowFileNotFoundException(ExceptionStringID id, string fileName) + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowFileNotFoundException(ExceptionStringID id, string fileName) { throw TypeLoaderExceptionHelper.CreateFileNotFoundException(id, fileName); } - public static void ThrowInvalidProgramException(ExceptionStringID id) + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowInvalidProgramException(ExceptionStringID id) { throw TypeLoaderExceptionHelper.CreateInvalidProgramException(id); } - public static void ThrowInvalidProgramExceptionWithArgument(ExceptionStringID id, string methodName) + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowInvalidProgramExceptionWithArgument(ExceptionStringID id, string methodName) { throw TypeLoaderExceptionHelper.CreateInvalidProgramException(id, methodName); } - public static void ThrowMarshalDirectiveException(ExceptionStringID id) + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowMarshalDirectiveException(ExceptionStringID id) { throw TypeLoaderExceptionHelper.CreateMarshalDirectiveException(id); } - public static void ThrowAmbiguousMatchException(ExceptionStringID id) + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowAmbiguousMatchException(ExceptionStringID id) { throw TypeLoaderExceptionHelper.CreateAmbiguousMatchException(id); } - public static void ThrowNotSupportedInlineArrayEqualsGetHashCode() + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowNotSupportedInlineArrayEqualsGetHashCode() { throw new NotSupportedException(SR.NotSupported_InlineArrayEqualsGetHashCode); } diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs index db45d4b316e03..a10e8c0cb2f6b 100644 --- a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs +++ b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs @@ -9,85 +9,76 @@ namespace Internal.Runtime.CompilerHelpers { - /// - /// These methods are used to throw exceptions from generated code. - /// For NativeAOT, the type and methods used need to be public - /// as they constitute a public contract. - /// For CoreCLR, the type and methods are used as JIT helpers. - /// -#if NATIVEAOT - public -#else - internal -#endif - static unsafe partial class ThrowHelpers + [StackTraceHidden] + [DebuggerStepThrough] + internal static unsafe partial class ThrowHelpers { [DoesNotReturn] [DebuggerHidden] - public static void ThrowNullReferenceException() + internal static void ThrowNullReferenceException() { throw new NullReferenceException(); } [DoesNotReturn] [DebuggerHidden] - public static void ThrowArgumentException() + internal static void ThrowArgumentException() { throw new ArgumentException(); } [DoesNotReturn] [DebuggerHidden] - public static void ThrowArgumentOutOfRangeException() + internal static void ThrowArgumentOutOfRangeException() { throw new ArgumentOutOfRangeException(); } [DoesNotReturn] [DebuggerHidden] - public static void ThrowDivideByZeroException() + internal static void ThrowDivideByZeroException() { throw new DivideByZeroException(); } [DoesNotReturn] [DebuggerHidden] - public static void ThrowIndexOutOfRangeException() + internal static void ThrowIndexOutOfRangeException() { throw new IndexOutOfRangeException(); } [DoesNotReturn] [DebuggerHidden] - public static void ThrowOverflowException() + internal static void ThrowOverflowException() { throw new OverflowException(); } [DoesNotReturn] [DebuggerHidden] - public static void ThrowPlatformNotSupportedException() + internal static void ThrowPlatformNotSupportedException() { throw new PlatformNotSupportedException(); } [DoesNotReturn] [DebuggerHidden] - public static void ThrowNotImplementedException() + internal static void ThrowNotImplementedException() { throw new NotImplementedException(); } [DoesNotReturn] [DebuggerHidden] - public static void ThrowArrayTypeMismatchException() + internal static void ThrowArrayTypeMismatchException() { throw new ArrayTypeMismatchException(); } [DoesNotReturn] [DebuggerHidden] - public static void ThrowNotSupportedException() + internal static void ThrowNotSupportedException() { throw new NotSupportedException(); } From 77f2b61b9faea8310cfd490bfa690d0dbd181d99 Mon Sep 17 00:00:00 2001 From: Aaron R Robinson Date: Mon, 12 Aug 2024 10:28:58 -0700 Subject: [PATCH 5/6] Move direct helpers in native AOT to shared location. --- .../Runtime/Augments/RuntimeAugments.cs | 41 +++++++++++++++++++ .../Runtime/CompilerHelpers/ThrowHelpers.cs | 2 + .../src/Internal/TypeSystem/ThrowHelper.cs | 2 +- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs index d534c9174fb61..7db11a8204177 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs @@ -29,6 +29,7 @@ using Internal.Runtime.CompilerHelpers; using Internal.Runtime.CompilerServices; +using ExceptionStringID = Internal.TypeSystem.ExceptionStringID; using ReflectionPointer = System.Reflection.Pointer; namespace Internal.Runtime.Augments @@ -702,5 +703,45 @@ public static void RhHandleFree(IntPtr handle) { RuntimeImports.RhHandleFree(handle); } + + public static void ThrowTypeLoadExceptionWithArgument(ExceptionStringID id, string className, string typeName, string messageArg) + { + throw TypeLoaderExceptionHelper.CreateTypeLoadException(id, className, typeName, messageArg); + } + + public static void ThrowTypeLoadException(ExceptionStringID id, string className, string typeName) + { + throw TypeLoaderExceptionHelper.CreateTypeLoadException(id, className, typeName); + } + + public static void ThrowMissingMethodException(ExceptionStringID id, string methodName) + { + throw TypeLoaderExceptionHelper.CreateMissingMethodException(id, methodName); + } + + public static void ThrowMissingFieldException(ExceptionStringID id, string fieldName) + { + throw TypeLoaderExceptionHelper.CreateMissingFieldException(id, fieldName); + } + + public static void ThrowFileNotFoundException(ExceptionStringID id, string fileName) + { + throw TypeLoaderExceptionHelper.CreateFileNotFoundException(id, fileName); + } + + public static void ThrowInvalidProgramException(ExceptionStringID id) + { + throw TypeLoaderExceptionHelper.CreateInvalidProgramException(id); + } + + public static void ThrowInvalidProgramExceptionWithArgument(ExceptionStringID id, string methodName) + { + throw TypeLoaderExceptionHelper.CreateInvalidProgramException(id, methodName); + } + + public static void ThrowBadImageFormatException(ExceptionStringID id) + { + throw TypeLoaderExceptionHelper.CreateBadImageFormatException(id); + } } } diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs index 4304d70c4606b..21c68337bcfe8 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using Internal.TypeSystem; diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/ThrowHelper.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/ThrowHelper.cs index 345ce880d80a6..ce7487e2e19a3 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/ThrowHelper.cs +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/ThrowHelper.cs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using CoreLibThrow = Internal.Runtime.CompilerHelpers.ThrowHelpers; +using CoreLibThrow = Internal.Runtime.Augments.RuntimeAugments; namespace Internal.TypeSystem { From de54cb434d9b115fded769aba9ae354bde082e79 Mon Sep 17 00:00:00 2001 From: Aaron R Robinson Date: Mon, 12 Aug 2024 10:38:08 -0700 Subject: [PATCH 6/6] Remove ThrowHelpers from suppression XML --- .../System.Private.CoreLib/src/CompatibilitySuppressions.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml index 5919536924219..507b4c1493692 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml @@ -709,10 +709,6 @@ CP0001 T:Internal.Runtime.CanonTypeKind - - CP0001 - T:Internal.Runtime.CompilerHelpers.ThrowHelpers - CP0001 T:Internal.Runtime.CompilerServices.FunctionPointerOps