diff --git a/src/jit/compiler.h b/src/jit/compiler.h index b53f52488054..30051a10d2a9 100644 --- a/src/jit/compiler.h +++ b/src/jit/compiler.h @@ -4355,7 +4355,7 @@ class Compiler void fgLinkBasicBlocks(); - void fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, BYTE* jumpTarget); + unsigned fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, BYTE* jumpTarget); void fgCheckBasicBlockControlFlow(); diff --git a/src/jit/flowgraph.cpp b/src/jit/flowgraph.cpp index 8a007b2b8efa..ac3d322db6bc 100644 --- a/src/jit/flowgraph.cpp +++ b/src/jit/flowgraph.cpp @@ -4269,6 +4269,7 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, BYTE* const bool isForceInline = (info.compFlags & CORINFO_FLG_FORCEINLINE) != 0; const bool makeInlineObservations = (compInlineResult != nullptr); const bool isInlining = compIsForInlining(); + unsigned retBlocks = 0; if (makeInlineObservations) { @@ -4638,6 +4639,7 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, BYTE* break; case CEE_JMP: + retBlocks++; #if !defined(_TARGET_X86_) && !defined(_TARGET_ARM_) if (!isInlining) @@ -4730,6 +4732,8 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, BYTE* fgObserveInlineConstants(opcode, pushedStack, isInlining); } break; + case CEE_RET: + retBlocks++; default: break; @@ -4758,6 +4762,21 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, BYTE* { compInlineResult->Note(InlineObservation::CALLEE_END_OPCODE_SCAN); + if (!compInlineResult->UsesLegacyPolicy()) + { + // If there are no return blocks we know it does not return, however if there + // return blocks we don't know it returns as it may be counting unreachable code. + // However we will still make the CALLEE_DOES_NOT_RETURN observation. + + compInlineResult->NoteBool(InlineObservation::CALLEE_DOES_NOT_RETURN, retBlocks == 0); + + if (retBlocks == 0 && isInlining) + { + // Mark the call node as "no return" as it can impact caller's code quality. + impInlineInfo->iciCall->gtCallMoreFlags |= GTF_CALL_M_DOES_NOT_RETURN; + } + } + // If the inline is viable and discretionary, do the // profitability screening. if (compInlineResult->IsDiscretionaryCandidate()) @@ -5062,17 +5081,19 @@ void Compiler::fgLinkBasicBlocks() /***************************************************************************** * - * Walk the instrs to create the basic blocks. + * Walk the instrs to create the basic blocks. Returns the number of BBJ_RETURN in method */ -void Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, BYTE* jumpTarget) +unsigned Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, BYTE* jumpTarget) { + unsigned retBlocks; const BYTE* codeBegp = codeAddr; const BYTE* codeEndp = codeAddr + codeSize; bool tailCall = false; unsigned curBBoffs; BasicBlock* curBBdesc; + retBlocks = 0; /* Clear the beginning offset for the first BB */ curBBoffs = 0; @@ -5280,7 +5301,8 @@ void Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, BYTE* // TODO-CQ: We can inline some callees with explicit tail calls if we can guarantee that the calls // can be dispatched as tail calls from the caller. compInlineResult->NoteFatal(InlineObservation::CALLEE_EXPLICIT_TAIL_PREFIX); - return; + retBlocks++; + return retBlocks; } __fallthrough; @@ -5391,6 +5413,7 @@ void Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, BYTE* But instead of directly returning to the caller we jump and execute something else in between */ case CEE_RET: + retBlocks++; jmpKind = BBJ_RETURN; break; @@ -5581,6 +5604,8 @@ void Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, BYTE* /* Finally link up the bbJumpDest of the blocks together */ fgLinkBasicBlocks(); + + return retBlocks; } /***************************************************************************** @@ -5726,44 +5751,14 @@ void Compiler::fgFindBasicBlocks() /* Now create the basic blocks */ - fgMakeBasicBlocks(info.compCode, info.compILCodeSize, jumpTarget); + unsigned retBlocks = fgMakeBasicBlocks(info.compCode, info.compILCodeSize, jumpTarget); if (compIsForInlining()) { - if (compInlineResult->IsFailure()) - { - return; - } - - bool hasReturnBlocks = false; - bool hasMoreThanOneReturnBlock = false; - - for (BasicBlock* block = fgFirstBB; block != nullptr; block = block->bbNext) - { - if (block->bbJumpKind == BBJ_RETURN) - { - if (hasReturnBlocks) - { - hasMoreThanOneReturnBlock = true; - break; - } - - hasReturnBlocks = true; - } - } - - if (!hasReturnBlocks && !compInlineResult->UsesLegacyPolicy()) - { - // - // Mark the call node as "no return". The inliner might ignore CALLEE_DOES_NOT_RETURN and - // fail inline for a different reasons. In that case we still want to make the "no return" - // information available to the caller as it can impact caller's code quality. - // - - impInlineInfo->iciCall->gtCallMoreFlags |= GTF_CALL_M_DOES_NOT_RETURN; - } - - compInlineResult->NoteBool(InlineObservation::CALLEE_DOES_NOT_RETURN, !hasReturnBlocks); + // If fgFindJumpTargets marked this as "no return" there really should be no BBJ_RETURN blocks in the method + assert((retBlocks == 0 && ((impInlineInfo->iciCall->gtCallMoreFlags & GTF_CALL_M_DOES_NOT_RETURN) == + GTF_CALL_M_DOES_NOT_RETURN)) || + (retBlocks >= 1 && ((impInlineInfo->iciCall->gtCallMoreFlags & GTF_CALL_M_DOES_NOT_RETURN) == 0))); if (compInlineResult->IsFailure()) { @@ -5777,7 +5772,7 @@ void Compiler::fgFindBasicBlocks() compHndBBtabCount = impInlineInfo->InlinerCompiler->compHndBBtabCount; info.compXcptnsCount = impInlineInfo->InlinerCompiler->info.compXcptnsCount; - if (info.compRetNativeType != TYP_VOID && hasMoreThanOneReturnBlock) + if (info.compRetNativeType != TYP_VOID && retBlocks > 1) { // The lifetime of this var might expand multiple BBs. So it is a long lifetime compiler temp. lvaInlineeReturnSpillTemp = lvaGrabTemp(false DEBUGARG("Inline candidate multiple BBJ_RETURN spill temp")); diff --git a/src/mscorlib/src/System/Array.cs b/src/mscorlib/src/System/Array.cs index 2260fd72675f..f191bf8b08a7 100644 --- a/src/mscorlib/src/System/Array.cs +++ b/src/mscorlib/src/System/Array.cs @@ -70,7 +70,7 @@ public unsafe static Array CreateInstance(Type elementType, int length) if ((object)elementType == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementType); if (length < 0) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum(); Contract.Ensures(Contract.Result() != null); Contract.Ensures(Contract.Result().Length == length); Contract.Ensures(Contract.Result().Rank == 1); @@ -904,7 +904,7 @@ public static int BinarySearch(Array array, int index, int length, Object value, if (index < lb) ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); if (length < 0) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum(); if (array.Length - (index - lb) < length) ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); if (array.Rank != 1) @@ -1002,7 +1002,7 @@ public static int BinarySearch(T[] array, int index, int length, T value, Sys if (index < 0) ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); if (length < 0) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum(); if (array.Length - index < length) ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); @@ -1136,11 +1136,11 @@ public static int FindIndex(T[] array, int startIndex, int count, Predicate array.Length ) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } if (count < 0 || startIndex > array.Length - count) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); + ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(); } if( match == null) { @@ -1205,19 +1205,19 @@ public static int FindLastIndex(T[] array, int startIndex, int count, Predica if(array.Length == 0) { // Special case for 0 length List if( startIndex != -1) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } } else { // Make sure we're not out of range if ( startIndex < 0 || startIndex >= array.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } } // 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0. if (count < 0 || startIndex - count + 1 < 0) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); + ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(); } int endIndex = startIndex - count; @@ -1305,9 +1305,9 @@ public static int IndexOf(Array array, Object value, int startIndex, int count) int lb = array.GetLowerBound(0); if (startIndex < lb || startIndex > array.Length + lb) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); if (count < 0 || count > array.Length - startIndex + lb) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); + ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(); // Try calling a quick native method to handle primitive types. int retVal; @@ -1376,11 +1376,11 @@ public static int IndexOf(T[] array, T value, int startIndex, int count) { } if (startIndex < 0 || startIndex > array.Length ) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } if (count < 0 || count > array.Length - startIndex) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); + ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(); } Contract.Ensures(Contract.Result() < array.Length); Contract.EndContractBlock(); @@ -1442,9 +1442,9 @@ public static int LastIndexOf(Array array, Object value, int startIndex, int cou } if (startIndex < lb || startIndex >= array.Length + lb) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); if (count < 0) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); + ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(); if (count > startIndex - lb + 1) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.endIndex, ExceptionResource.ArgumentOutOfRange_EndIndexStartIndex); if (array.Rank != 1) @@ -1518,24 +1518,24 @@ public static int LastIndexOf(T[] array, T value, int startIndex, int count) // accept -1 and 0 as valid startIndex for compablility reason. // if( startIndex != -1 && startIndex != 0) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } // only 0 is a valid value for count if array is empty if( count != 0) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); + ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(); } return -1; } // Make sure we're not out of range if ( startIndex < 0 || startIndex >= array.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } // 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0. if (count < 0 || startIndex - count + 1 < 0) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); + ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(); } return EqualityComparer.Default.LastIndexOf(array, value, startIndex, count); @@ -1575,7 +1575,7 @@ public static void Reverse(Array array, int index, int length) { if (index < lowerBound) ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); if (length < 0) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum(); if (array.Length - (index - lowerBound) < length) ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); @@ -1632,7 +1632,7 @@ public static void Reverse(T[] array, int index, int length) if (index < 0) ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); if (length < 0) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum(); if (array.Length - index < length) ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); Contract.EndContractBlock(); @@ -1757,7 +1757,7 @@ public static void Sort(Array keys, Array items, int index, int length, ICompare if (index < keysLowerBound) ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); if (length < 0) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum(); if (keys.Length - (index - keysLowerBound) < length || (items != null && (index - keysLowerBound) > items.Length - length)) ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); @@ -1841,7 +1841,7 @@ public static void Sort(T[] array, int index, int length, System.Collections. if (index < 0) ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); if (length < 0) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum(); if (array.Length - index < length) ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); Contract.EndContractBlock(); @@ -1865,7 +1865,7 @@ public static void Sort(TKey[] keys, TValue[] items, int index, in if (index < 0) ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); if (length < 0) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum(); if (keys.Length - index < length || (items != null && index > items.Length - length)) ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); Contract.EndContractBlock(); @@ -2589,8 +2589,8 @@ public bool MoveNext() { public Object Current { get { - if (_index < 0) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); - if (_index >= _endIndex) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); + if (_index < 0) ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumNotStarted(); + if (_index >= _endIndex) ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumEnded(); return _array.GetValue(_index); } } @@ -2667,8 +2667,8 @@ public bool MoveNext() { public Object Current { get { - if (index < startIndex) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); - if (_complete) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); + if (index < startIndex) ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumNotStarted(); + if (_complete) ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumEnded(); return array.GetValue(_indices); } } @@ -2866,8 +2866,8 @@ public bool MoveNext() { public T Current { get { - if (_index < 0) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); - if (_index >= _endIndex) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); + if (_index < 0) ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumNotStarted(); + if (_index >= _endIndex) ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumEnded(); return _array[_index]; } } diff --git a/src/mscorlib/src/System/ArraySegment.cs b/src/mscorlib/src/System/ArraySegment.cs index bc39c2474f6b..95254bfea2db 100644 --- a/src/mscorlib/src/System/ArraySegment.cs +++ b/src/mscorlib/src/System/ArraySegment.cs @@ -315,8 +315,8 @@ public T Current { get { - if (_current < _start) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); - if (_current >= _end) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); + if (_current < _start) ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumNotStarted(); + if (_current >= _end) ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumEnded(); return _array[_current]; } } diff --git a/src/mscorlib/src/System/BitConverter.cs b/src/mscorlib/src/System/BitConverter.cs index e4bb9ddc882a..5ecb1302d65e 100644 --- a/src/mscorlib/src/System/BitConverter.cs +++ b/src/mscorlib/src/System/BitConverter.cs @@ -156,7 +156,7 @@ public static char ToChar(byte[] value, int startIndex) } if ((uint)startIndex >= value.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } if (startIndex > value.Length - 2) { @@ -175,7 +175,7 @@ public static unsafe short ToInt16(byte[] value, int startIndex) { } if ((uint) startIndex >= value.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } if (startIndex > value.Length -2) { @@ -207,7 +207,7 @@ public static unsafe int ToInt32 (byte[] value, int startIndex) { } if ((uint) startIndex >= value.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } if (startIndex > value.Length -4) { @@ -238,7 +238,7 @@ public static unsafe long ToInt64 (byte[] value, int startIndex) { } if ((uint) startIndex >= value.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } if (startIndex > value.Length -8) { @@ -274,7 +274,7 @@ public static ushort ToUInt16(byte[] value, int startIndex) if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if ((uint)startIndex >= value.Length) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); if (startIndex > value.Length - 2) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); Contract.EndContractBlock(); @@ -290,7 +290,7 @@ public static uint ToUInt32(byte[] value, int startIndex) if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if ((uint)startIndex >= value.Length) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); if (startIndex > value.Length - 4) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); Contract.EndContractBlock(); @@ -306,7 +306,7 @@ public static ulong ToUInt64(byte[] value, int startIndex) if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if ((uint)startIndex >= value.Length) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); if (startIndex > value.Length - 8) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); Contract.EndContractBlock(); @@ -321,7 +321,7 @@ unsafe public static float ToSingle (byte[] value, int startIndex) if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if ((uint)startIndex >= value.Length) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); if (startIndex > value.Length - 4) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); Contract.EndContractBlock(); @@ -337,7 +337,7 @@ unsafe public static double ToDouble (byte[] value, int startIndex) if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if ((uint)startIndex >= value.Length) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); if (startIndex > value.Length - 8) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Collections/Generic/Dictionary.cs b/src/mscorlib/src/System/Collections/Generic/Dictionary.cs index 9cbfff5a5708..25b9c384d4dc 100644 --- a/src/mscorlib/src/System/Collections/Generic/Dictionary.cs +++ b/src/mscorlib/src/System/Collections/Generic/Dictionary.cs @@ -263,7 +263,7 @@ private void CopyTo(KeyValuePair[] array, int index) { } if (index < 0 || index > array.Length ) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < Count) { @@ -557,7 +557,7 @@ void ICollection.CopyTo(Array array, int index) { } if (index < 0 || index > array.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < Count) { @@ -580,7 +580,7 @@ void ICollection.CopyTo(Array array, int index) { else { object[] objects = array as object[]; if (objects == null) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } try { @@ -593,7 +593,7 @@ void ICollection.CopyTo(Array array, int index) { } } catch(ArrayTypeMismatchException) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } } } @@ -733,7 +733,7 @@ internal Enumerator(Dictionary dictionary, int getEnumeratorRetType public bool MoveNext() { if (version != dictionary.version) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion(); } // Use unsigned comparison since we set index to dictionary.count+1 when the enumeration ends. @@ -762,7 +762,7 @@ public void Dispose() { object IEnumerator.Current { get { if( index == 0 || (index == dictionary.count + 1)) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen(); } if (getEnumeratorRetType == DictEntry) { @@ -775,7 +775,7 @@ object IEnumerator.Current { void IEnumerator.Reset() { if (version != dictionary.version) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion(); } index = 0; @@ -785,7 +785,7 @@ void IEnumerator.Reset() { DictionaryEntry IDictionaryEnumerator.Entry { get { if( index == 0 || (index == dictionary.count + 1)) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen(); } return new DictionaryEntry(current.Key, current.Value); @@ -795,7 +795,7 @@ DictionaryEntry IDictionaryEnumerator.Entry { object IDictionaryEnumerator.Key { get { if( index == 0 || (index == dictionary.count + 1)) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen(); } return current.Key; @@ -805,7 +805,7 @@ object IDictionaryEnumerator.Key { object IDictionaryEnumerator.Value { get { if( index == 0 || (index == dictionary.count + 1)) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen(); } return current.Value; @@ -837,7 +837,7 @@ public void CopyTo(TKey[] array, int index) { } if (index < 0 || index > array.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < dictionary.Count) { @@ -898,7 +898,7 @@ void ICollection.CopyTo(Array array, int index) { } if (index < 0 || index > array.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < dictionary.Count) { @@ -912,7 +912,7 @@ void ICollection.CopyTo(Array array, int index) { else { object[] objects = array as object[]; if (objects == null) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } int count = dictionary.count; @@ -923,7 +923,7 @@ void ICollection.CopyTo(Array array, int index) { } } catch(ArrayTypeMismatchException) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } } } @@ -956,7 +956,7 @@ public void Dispose() { public bool MoveNext() { if (version != dictionary.version) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion(); } while ((uint)index < (uint)dictionary.count) { @@ -982,7 +982,7 @@ public TKey Current { Object System.Collections.IEnumerator.Current { get { if( index == 0 || (index == dictionary.count + 1)) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen(); } return currentKey; @@ -991,7 +991,7 @@ Object System.Collections.IEnumerator.Current { void System.Collections.IEnumerator.Reset() { if (version != dictionary.version) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion(); } index = 0; @@ -1024,7 +1024,7 @@ public void CopyTo(TValue[] array, int index) { } if (index < 0 || index > array.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < dictionary.Count) { @@ -1085,7 +1085,7 @@ void ICollection.CopyTo(Array array, int index) { } if (index < 0 || index > array.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < dictionary.Count) @@ -1098,7 +1098,7 @@ void ICollection.CopyTo(Array array, int index) { else { object[] objects = array as object[]; if (objects == null) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } int count = dictionary.count; @@ -1109,7 +1109,7 @@ void ICollection.CopyTo(Array array, int index) { } } catch(ArrayTypeMismatchException) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } } } @@ -1142,7 +1142,7 @@ public void Dispose() { public bool MoveNext() { if (version != dictionary.version) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion(); } while ((uint)index < (uint)dictionary.count) { @@ -1167,7 +1167,7 @@ public TValue Current { Object System.Collections.IEnumerator.Current { get { if( index == 0 || (index == dictionary.count + 1)) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen(); } return currentValue; @@ -1176,7 +1176,7 @@ Object System.Collections.IEnumerator.Current { void System.Collections.IEnumerator.Reset() { if (version != dictionary.version) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion(); } index = 0; currentValue = default(TValue); diff --git a/src/mscorlib/src/System/Collections/Generic/List.cs b/src/mscorlib/src/System/Collections/Generic/List.cs index 262939416ff0..70054e1c8942 100644 --- a/src/mscorlib/src/System/Collections/Generic/List.cs +++ b/src/mscorlib/src/System/Collections/Generic/List.cs @@ -274,7 +274,7 @@ public ReadOnlyCollection AsReadOnly() { // public int BinarySearch(int index, int count, T item, IComparer comparer) { if (index < 0) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); if (count < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); if (_size - index < count) @@ -369,7 +369,7 @@ void System.Collections.ICollection.CopyTo(Array array, int arrayIndex) { Array.Copy(_items, 0, array, arrayIndex, _size); } catch(ArrayTypeMismatchException){ - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } } @@ -454,11 +454,11 @@ public int FindIndex(int startIndex, Predicate match) { public int FindIndex(int startIndex, int count, Predicate match) { if( (uint)startIndex > (uint)_size ) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } if (count < 0 || startIndex > _size - count) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); + ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(); } if( match == null) { @@ -512,19 +512,19 @@ public int FindLastIndex(int startIndex, int count, Predicate match) { if(_size == 0) { // Special case for 0 length List if( startIndex != -1) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } } else { // Make sure we're not out of range if ( (uint)startIndex >= (uint)_size) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } } // 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0. if (count < 0 || startIndex - count + 1 < 0) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); + ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(); } int endIndex = startIndex - count; @@ -552,7 +552,7 @@ public void ForEach(Action action) { } if (version != _version && BinaryCompatibility.TargetsAtLeast_Desktop_V4_5) - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion(); } // Returns an enumerator for this list with the given @@ -575,7 +575,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { public List GetRange(int index, int count) { if (index < 0) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (count < 0) { @@ -628,7 +628,7 @@ int System.Collections.IList.IndexOf(Object item) // public int IndexOf(T item, int index) { if (index > _size) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRange_IndexException(); Contract.Ensures(Contract.Result() >= -1); Contract.Ensures(Contract.Result() < Count); Contract.EndContractBlock(); @@ -646,9 +646,9 @@ public int IndexOf(T item, int index) { // public int IndexOf(T item, int index, int count) { if (index > _size) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRange_IndexException(); - if (count <0 || index > _size - count) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); + if (count <0 || index > _size - count) ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(); Contract.Ensures(Contract.Result() >= -1); Contract.Ensures(Contract.Result() < Count); Contract.EndContractBlock(); @@ -698,7 +698,7 @@ public void InsertRange(int index, IEnumerable collection) { } if ((uint)index > (uint)_size) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRange_IndexException(); } Contract.EndContractBlock(); @@ -766,7 +766,7 @@ public int LastIndexOf(T item) public int LastIndexOf(T item, int index) { if (index >= _size) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRange_IndexException(); Contract.Ensures(Contract.Result() >= -1); Contract.Ensures(((Count == 0) && (Contract.Result() == -1)) || ((Count > 0) && (Contract.Result() <= index))); Contract.EndContractBlock(); @@ -784,7 +784,7 @@ public int LastIndexOf(T item, int index) // public int LastIndexOf(T item, int index, int count) { if ((Count != 0) && (index < 0)) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if ((Count !=0) && (count < 0)) { @@ -883,7 +883,7 @@ public void RemoveAt(int index) { // public void RemoveRange(int index, int count) { if (index < 0) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (count < 0) { @@ -917,7 +917,7 @@ public void Reverse() { // public void Reverse(int index, int count) { if (index < 0) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (count < 0) { @@ -956,7 +956,7 @@ public void Sort(IComparer comparer) // public void Sort(int index, int count, IComparer comparer) { if (index < 0) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (count < 0) { @@ -1065,7 +1065,7 @@ public bool MoveNext() { private bool MoveNextRare() { if (version != list._version) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion(); } index = list._size + 1; @@ -1082,7 +1082,7 @@ public T Current { Object System.Collections.IEnumerator.Current { get { if( index == 0 || index == list._size + 1) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen(); } return Current; } @@ -1090,7 +1090,7 @@ Object System.Collections.IEnumerator.Current { void System.Collections.IEnumerator.Reset() { if (version != list._version) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion(); } index = 0; diff --git a/src/mscorlib/src/System/Collections/ObjectModel/Collection.cs b/src/mscorlib/src/System/Collections/ObjectModel/Collection.cs index 54aa7bb09db0..a3804ad7ab17 100644 --- a/src/mscorlib/src/System/Collections/ObjectModel/Collection.cs +++ b/src/mscorlib/src/System/Collections/ObjectModel/Collection.cs @@ -183,7 +183,7 @@ void ICollection.CopyTo(Array array, int index) { } if (index < 0 ) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < Count) { @@ -204,7 +204,7 @@ void ICollection.CopyTo(Array array, int index) { Type targetType = array.GetType().GetElementType(); Type sourceType = typeof(T); if(!(targetType.IsAssignableFrom(sourceType) || sourceType.IsAssignableFrom(targetType))) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } // @@ -213,7 +213,7 @@ void ICollection.CopyTo(Array array, int index) { // object[] objects = array as object[]; if( objects == null) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } int count = items.Count; @@ -223,7 +223,7 @@ void ICollection.CopyTo(Array array, int index) { } } catch(ArrayTypeMismatchException) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } } } diff --git a/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyCollection.cs b/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyCollection.cs index ec7149e4f553..a0b8b3b45959 100644 --- a/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyCollection.cs +++ b/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyCollection.cs @@ -128,7 +128,7 @@ void ICollection.CopyTo(Array array, int index) { } if (index < 0) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.arrayIndex, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < Count) { @@ -149,7 +149,7 @@ void ICollection.CopyTo(Array array, int index) { Type targetType = array.GetType().GetElementType(); Type sourceType = typeof(T); if(!(targetType.IsAssignableFrom(sourceType) || sourceType.IsAssignableFrom(targetType))) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } // @@ -158,7 +158,7 @@ void ICollection.CopyTo(Array array, int index) { // object[] objects = array as object[]; if( objects == null) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } int count = list.Count; @@ -168,7 +168,7 @@ void ICollection.CopyTo(Array array, int index) { } } catch(ArrayTypeMismatchException) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } } } diff --git a/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs b/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs index 11833c2c1b10..57dd34dc62b0 100644 --- a/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs +++ b/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs @@ -240,7 +240,7 @@ void ICollection.CopyTo(Array array, int index) { } if (index < 0 || index > array.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < Count) { @@ -261,7 +261,7 @@ void ICollection.CopyTo(Array array, int index) { else { object[] objects = array as object[]; if (objects == null) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } try { @@ -270,7 +270,7 @@ void ICollection.CopyTo(Array array, int index) { } } catch (ArrayTypeMismatchException) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } } } @@ -596,7 +596,7 @@ internal static void CopyToNonGenericICollectionHelper(ICollection collect Type targetType = array.GetType().GetElementType(); Type sourceType = typeof(T); if (!(targetType.IsAssignableFrom(sourceType) || sourceType.IsAssignableFrom(targetType))) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } // @@ -605,7 +605,7 @@ internal static void CopyToNonGenericICollectionHelper(ICollection collect // object[] objects = array as object[]; if (objects == null) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } try { @@ -614,7 +614,7 @@ internal static void CopyToNonGenericICollectionHelper(ICollection collect } } catch (ArrayTypeMismatchException) { - ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType); + ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType(); } } } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IteratorToEnumeratorAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IteratorToEnumeratorAdapter.cs index f1b799aa843e..061a732b0459 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IteratorToEnumeratorAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IteratorToEnumeratorAdapter.cs @@ -123,10 +123,10 @@ public T Current { // The enumerator has not been advanced to the first element yet. if (!m_isInitialized) - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumNotStarted(); // The enumerator has reached the end of the collection if (!m_hadCurrent) - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumEnded(); return m_current; } } @@ -137,10 +137,10 @@ object IEnumerator.Current { // The enumerator has not been advanced to the first element yet. if (!m_isInitialized) - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumNotStarted(); // The enumerator has reached the end of the collection if (!m_hadCurrent) - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumEnded(); return m_current; } } @@ -187,7 +187,7 @@ public bool MoveNext() // Translate E_CHANGED_STATE into an InvalidOperationException for an updated enumeration if (Marshal.GetHRForException(e) == __HResults.E_CHANGED_STATE) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion(); } else { diff --git a/src/mscorlib/src/System/ThrowHelper.cs b/src/mscorlib/src/System/ThrowHelper.cs index d3f06ac0dad4..1e0251e3f31f 100644 --- a/src/mscorlib/src/System/ThrowHelper.cs +++ b/src/mscorlib/src/System/ThrowHelper.cs @@ -44,27 +44,46 @@ namespace System { [Pure] internal static class ThrowHelper { internal static void ThrowArgumentOutOfRange_IndexException() { - throw new ArgumentOutOfRangeException(GetArgumentName(ExceptionArgument.index), - Environment.GetResourceString(GetResourceName(ExceptionResource.ArgumentOutOfRange_Index))); + throw GetArgumentOutOfRangeException(ExceptionArgument.index, + ExceptionResource.ArgumentOutOfRange_Index); } internal static void ThrowIndexArgumentOutOfRange_NeedNonNegNumException() { - throw new ArgumentOutOfRangeException( - GetArgumentName(ExceptionArgument.index), - Environment.GetResourceString(GetResourceName(ExceptionResource.ArgumentOutOfRange_NeedNonNegNum))); + throw GetArgumentOutOfRangeException(ExceptionArgument.index, + ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + } + + internal static void ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum() { + throw GetArgumentOutOfRangeException(ExceptionArgument.length, + ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + } + + internal static void ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index() { + throw GetArgumentOutOfRangeException(ExceptionArgument.startIndex, + ExceptionResource.ArgumentOutOfRange_Index); + } + + internal static void ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count() { + throw GetArgumentOutOfRangeException(ExceptionArgument.count, + ExceptionResource.ArgumentOutOfRange_Count); } internal static void ThrowWrongKeyTypeArgumentException(object key, Type targetType) { - throw new ArgumentException(Environment.GetResourceString("Arg_WrongType", key, targetType), "key"); + throw GetWrongKeyTypeArgumentException(key, targetType); } internal static void ThrowWrongValueTypeArgumentException(object value, Type targetType) { - throw new ArgumentException(Environment.GetResourceString("Arg_WrongType", value, targetType), "value"); + throw GetWrongValueTypeArgumentException(value, targetType); } + #if FEATURE_CORECLR + private static ArgumentException GetAddingDuplicateWithKeyArgumentException(object key) { + return new ArgumentException(Environment.GetResourceString("Argument_AddingDuplicateWithKey", key)); + } + internal static void ThrowAddingDuplicateWithKeyArgumentException(object key) { - throw new ArgumentException(Environment.GetResourceString("Argument_AddingDuplicateWithKey", key)); + throw GetAddingDuplicateWithKeyArgumentException(key); } #endif @@ -73,20 +92,19 @@ internal static void ThrowKeyNotFoundException() { } internal static void ThrowArgumentException(ExceptionResource resource) { - throw new ArgumentException(Environment.GetResourceString(GetResourceName(resource))); + throw GetArgumentException(resource); } internal static void ThrowArgumentException(ExceptionResource resource, ExceptionArgument argument) { - throw new ArgumentException(Environment.GetResourceString(GetResourceName(resource)), GetArgumentName(argument)); + throw GetArgumentException(resource, argument); } internal static void ThrowArgumentNullException(ExceptionArgument argument) { throw new ArgumentNullException(GetArgumentName(argument)); } - internal static void ThrowArgumentNullException(ExceptionResource resource) - { - throw new ArgumentNullException(Environment.GetResourceString(GetResourceName(resource))); + internal static void ThrowArgumentNullException(ExceptionResource resource) { + throw new ArgumentNullException(GetResourceString(resource)); } internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument) { @@ -94,62 +112,105 @@ internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument } internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) { - throw new ArgumentOutOfRangeException(GetArgumentName(argument), - Environment.GetResourceString(GetResourceName(resource))); + throw GetArgumentOutOfRangeException(argument, resource); } internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, int paramNumber, ExceptionResource resource) { - throw new ArgumentOutOfRangeException(GetArgumentName(argument) + "[" + paramNumber.ToString() + "]", - Environment.GetResourceString(GetResourceName(resource))); + throw GetArgumentOutOfRangeException(argument, paramNumber, resource); } internal static void ThrowInvalidOperationException(ExceptionResource resource) { - throw new InvalidOperationException(Environment.GetResourceString(GetResourceName(resource))); + throw GetInvalidOperationException(resource); } internal static void ThrowInvalidOperationException(ExceptionResource resource, Exception e) { - throw new InvalidOperationException(Environment.GetResourceString(GetResourceName(resource)), e); + throw new InvalidOperationException(GetResourceString(resource), e); } internal static void ThrowSerializationException(ExceptionResource resource) { - throw new SerializationException(Environment.GetResourceString(GetResourceName(resource))); + throw new SerializationException(GetResourceString(resource)); } internal static void ThrowSecurityException(ExceptionResource resource) { - throw new System.Security.SecurityException(Environment.GetResourceString(GetResourceName(resource))); + throw new System.Security.SecurityException(GetResourceString(resource)); } internal static void ThrowRankException(ExceptionResource resource) { - throw new RankException(Environment.GetResourceString(GetResourceName(resource))); + throw new RankException(GetResourceString(resource)); } internal static void ThrowNotSupportedException(ExceptionResource resource) { - throw new NotSupportedException(Environment.GetResourceString(GetResourceName(resource))); + throw new NotSupportedException(GetResourceString(resource)); } internal static void ThrowUnauthorizedAccessException(ExceptionResource resource) { - throw new UnauthorizedAccessException(Environment.GetResourceString(GetResourceName(resource))); + throw new UnauthorizedAccessException(GetResourceString(resource)); } internal static void ThrowObjectDisposedException(string objectName, ExceptionResource resource) { - throw new ObjectDisposedException(objectName, Environment.GetResourceString(GetResourceName(resource))); + throw new ObjectDisposedException(objectName, GetResourceString(resource)); } - internal static void ThrowObjectDisposedException(ExceptionResource resource) - { - throw new ObjectDisposedException(null, Environment.GetResourceString(GetResourceName(resource))); + internal static void ThrowObjectDisposedException(ExceptionResource resource) { + throw new ObjectDisposedException(null, GetResourceString(resource)); } - internal static void ThrowNotSupportedException() - { + internal static void ThrowNotSupportedException() { throw new NotSupportedException(); } - internal static void ThrowAggregateException(List exceptions) - { + internal static void ThrowAggregateException(List exceptions) { throw new AggregateException(exceptions); } + internal static void ThrowArgumentException_Argument_InvalidArrayType() { + throw GetArgumentException(ExceptionResource.Argument_InvalidArrayType); + } + + internal static void ThrowInvalidOperationException_InvalidOperation_EnumNotStarted() { + throw GetInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); + } + + internal static void ThrowInvalidOperationException_InvalidOperation_EnumEnded() { + throw GetInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); + } + + internal static void ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion() { + throw GetInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); + } + + internal static void ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen() { + throw GetInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen); + } + + private static ArgumentException GetArgumentException(ExceptionResource resource) { + return new ArgumentException(GetResourceString(resource)); + } + + private static InvalidOperationException GetInvalidOperationException(ExceptionResource resource) { + return new InvalidOperationException(GetResourceString(resource)); + } + + private static ArgumentException GetWrongKeyTypeArgumentException(object key, Type targetType) { + return new ArgumentException(Environment.GetResourceString("Arg_WrongType", key, targetType), "key"); + } + + private static ArgumentException GetWrongValueTypeArgumentException(object value, Type targetType) { + return new ArgumentException(Environment.GetResourceString("Arg_WrongType", value, targetType), "value"); + } + + private static ArgumentOutOfRangeException GetArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) { + return new ArgumentOutOfRangeException(GetArgumentName(argument), GetResourceString(resource)); + } + + private static ArgumentException GetArgumentException(ExceptionResource resource, ExceptionArgument argument) { + return new ArgumentException(GetResourceString(resource), GetArgumentName(argument)); + } + + private static ArgumentOutOfRangeException GetArgumentOutOfRangeException(ExceptionArgument argument, int paramNumber, ExceptionResource resource) { + return new ArgumentOutOfRangeException(GetArgumentName(argument) + "[" + paramNumber.ToString() + "]", GetResourceString(resource)); + } + // Allow nulls for reference types and Nullable, but not for value types. // Aggressively inline so the jit evaluates the if in place and either drops the call altogether // Or just leaves null test and call to the Non-returning ThrowHelper.ThrowArgumentNullException @@ -160,26 +221,43 @@ internal static void IfNullAndNullsAreIllegalThenThrow(object value, Exceptio ThrowHelper.ThrowArgumentNullException(argName); } - // // This function will convert an ExceptionArgument enum value to the argument name string. - // - internal static string GetArgumentName(ExceptionArgument argument) { + private static string GetArgumentName(ExceptionArgument argument) { + // This is indirected through a second NoInlining function it has a special meaning + // in System.Private.CoreLib of indicatating it takes a StackMark which cause + // the caller to also be not inlined; so we can't mark it directly. + // So is the effect of marking this function as non-inlining in a regular situation. + return GetArgumentNameInner(argument); + } + + // This function will convert an ExceptionArgument enum value to the argument name string. + // Second function in chain so as to not propergate the non-inlining to outside caller + [MethodImpl(MethodImplOptions.NoInlining)] + private static string GetArgumentNameInner(ExceptionArgument argument) { Contract.Assert(Enum.IsDefined(typeof(ExceptionArgument), argument), "The enum value is not defined, please check the ExceptionArgument Enum."); return argument.ToString(); } - // // This function will convert an ExceptionResource enum value to the resource string. - // - internal static string GetResourceName(ExceptionResource resource) { + private static string GetResourceString(ExceptionResource resource) { + // This is indirected through a second NoInlining function it has a special meaning + // in System.Private.CoreLib of indicatating it takes a StackMark which cause + // the caller to also be not inlined; so we can't mark it directly. + // So is the effect of marking this function as non-inlining in a regular situation. + return GetResourceStringInner(resource); + } + + // This function will convert an ExceptionResource enum value to the resource string. + // Second function in chain so as to not propergate the non-inlining to outside caller + [MethodImpl(MethodImplOptions.NoInlining)] + private static string GetResourceStringInner(ExceptionResource resource) { Contract.Assert(Enum.IsDefined(typeof(ExceptionResource), resource), "The enum value is not defined, please check the ExceptionResource Enum."); - return resource.ToString(); + return Environment.GetResourceString(resource.ToString()); } - } //