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 90% 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 254cc0df8a270..fd01c28423ecc 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/ThrowHelper.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs @@ -1,19 +1,21 @@ // 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; -namespace System +namespace Internal.Runtime.CompilerHelpers { - internal static unsafe partial class ThrowHelper + internal static unsafe partial class ThrowHelpers { [DoesNotReturn] [LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_ThrowAmbiguousResolutionException")] private static partial void ThrowAmbiguousResolutionException(MethodTable* targetType, MethodTable* interfaceType, void* methodDesc); [DoesNotReturn] + [DebuggerHidden] internal static void ThrowAmbiguousResolutionException( void* method, // MethodDesc* void* interfaceType, // MethodTable* @@ -27,6 +29,7 @@ internal static void ThrowAmbiguousResolutionException( private static partial void ThrowEntryPointNotFoundException(MethodTable* targetType, MethodTable* interfaceType, void* methodDesc); [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/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 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 c71b79f8dc0f9..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,138 +2,116 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using Internal.TypeSystem; 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 + 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 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(); - } - - 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 ThrowArgumentException() - { - throw new ArgumentException(); - } - - public static void ThrowArgumentOutOfRangeException() - { - throw new ArgumentOutOfRangeException(); - } - - public static void ThrowNotSupportedInlineArrayEqualsGetHashCode() + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowNotSupportedInlineArrayEqualsGetHashCode() { throw new NotSupportedException(SR.NotSupported_InlineArrayEqualsGetHashCode); } 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 { diff --git a/src/coreclr/vm/corelib.h b/src/coreclr/vm/corelib.h index a6b278aa708a4..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(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..a10e8c0cb2f6b --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs @@ -0,0 +1,100 @@ +// 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 +{ + [StackTraceHidden] + [DebuggerStepThrough] + internal static unsafe partial class ThrowHelpers + { + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowNullReferenceException() + { + throw new NullReferenceException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowArgumentException() + { + throw new ArgumentException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowArgumentOutOfRangeException() + { + throw new ArgumentOutOfRangeException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowDivideByZeroException() + { + throw new DivideByZeroException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowIndexOutOfRangeException() + { + throw new IndexOutOfRangeException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowOverflowException() + { + throw new OverflowException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowPlatformNotSupportedException() + { + throw new PlatformNotSupportedException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowNotImplementedException() + { + throw new NotImplementedException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowArrayTypeMismatchException() + { + throw new ArrayTypeMismatchException(); + } + + [DoesNotReturn] + [DebuggerHidden] + internal static void ThrowNotSupportedException() + { + throw new NotSupportedException(); + } + + [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(); + } + } +} 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 4dc475742c6db..41ab0698b0bd9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs @@ -51,7 +51,7 @@ namespace System { [StackTraceHidden] - internal static partial class ThrowHelper + internal static class ThrowHelper { [DoesNotReturn] internal static void ThrowArithmeticException(string message) @@ -71,12 +71,6 @@ internal static void ThrowArrayTypeMismatchException() throw new ArrayTypeMismatchException(); } - [DoesNotReturn] - internal static void ThrowArgumentException() - { - throw new ArgumentException(); - } - [DoesNotReturn] internal static void ThrowInvalidTypeWithPointersNotSupported(Type targetType) { @@ -95,30 +89,6 @@ internal static void ThrowArgumentOutOfRangeException() throw new ArgumentOutOfRangeException(); } - [DoesNotReturn] - internal static void ThrowNotImplementedException() - { - throw new NotImplementedException(); - } - - [DoesNotReturn] - internal static void ThrowPlatformNotSupportedException() - { - throw new PlatformNotSupportedException(); - } - - [DoesNotReturn] - internal static void ThrowTypeNotSupportedException() - { - throw new NotSupportedException(SR.Arg_TypeNotSupported); - } - - [DoesNotReturn] - internal static void ThrowVerificationException(int ilOffset) - { - throw new System.Security.VerificationException(); - } - [DoesNotReturn] internal static void ThrowArgumentException_DestinationTooShort() {