Skip to content

Commit

Permalink
Replace Debug.Assert(false, with Debug.Fail(
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Jul 22, 2024
1 parent d285c82 commit c7b34c8
Show file tree
Hide file tree
Showing 62 changed files with 165 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ public uint GetFieldOffset(EETypeField eField)
return cbOffset;
}

Debug.Assert(false, "Unknown MethodTable field type");
Debug.Fail("Unknown MethodTable field type");
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,12 @@ internal static void Assert(bool condition)
EH.FallbackFailFast(RhFailFastReason.InternalError, null);
}
}

[System.Diagnostics.Conditional("DEBUG")]
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void Fail(string message)
{
Assert(false, message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private static void OnUnhandledExceptionViaClassLib(object exception)
// disallow all exceptions leaking out of callbacks
}
#else
Debug.Assert(false, "Unhandled exceptions should be processed by the native runtime only");
Debug.Fail("Unhandled exceptions should be processed by the native runtime only");
#endif
}

Expand Down Expand Up @@ -429,7 +429,7 @@ public static Exception GetRuntimeException(ExceptionIDs id)
return new InvalidCastException();

default:
Debug.Assert(false, "unexpected ExceptionID");
Debug.Fail("unexpected ExceptionID");
FallbackFailFast(RhFailFastReason.InternalError, null);
return null;
}
Expand Down Expand Up @@ -696,7 +696,7 @@ public static void RhUnwindAndIntercept(ref ExInfo exInfo, UIntPtr interceptStac
InternalCalls.ResumeAtInterceptionLocation(exInfo._frameIter.RegisterSet);
}

Debug.Assert(false, "unreachable");
Debug.Fail("unreachable");
FallbackFailFast(RhFailFastReason.InternalError, null);
}
#endif // !NATIVEAOT
Expand Down Expand Up @@ -903,7 +903,7 @@ private static void DispatchEx(scoped ref StackFrameIterator frameIter, ref ExIn
pReversePInvokePropagationContext, pReversePInvokePropagationCallback, frameIter.RegisterSet, ref exInfo, frameIter.PreviousTransitionFrame);
// the helper should jump to propagation handler and not return
#endif
Debug.Assert(false, "unreachable");
Debug.Fail("unreachable");
FallbackFailFast(RhFailFastReason.InternalError, null);
}
#endif // FEATURE_OBJCMARSHAL
Expand All @@ -926,7 +926,7 @@ private static void DispatchEx(scoped ref StackFrameIterator frameIter, ref ExIn
}
#endif // NATIVEAOT
// currently, RhpCallCatchFunclet will resume after the catch
Debug.Assert(false, "unreachable");
Debug.Fail("unreachable");
FallbackFailFast(RhFailFastReason.InternalError, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ internal static unsafe IntPtr RhGetRuntimeHelperForType(MethodTable* pEEType, Ru
return (IntPtr)(delegate*<MethodTable*, int, object>)&InternalCalls.RhpNewArray;

default:
Debug.Assert(false, "Unknown RuntimeHelperKind");
Debug.Fail("Unknown RuntimeHelperKind");
return IntPtr.Zero;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ internal static unsafe bool TypeParametersAreCompatible(int arity,
break;

default:
Debug.Assert(false, "unknown generic variance type");
Debug.Fail("unknown generic variance type");
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private void EmitTypeName(Handle typeHandle, Flags flags)
break;

default:
Debug.Assert(false, $"Type handle {typeHandle.HandleType} was not handled");
Debug.Fail($"Type handle {typeHandle.HandleType} was not handled");
_outputBuilder.Append("???");
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,12 @@ internal static void Assert(bool condition)
RuntimeImports.RhpFallbackFailFast();
}
}

[System.Diagnostics.Conditional("DEBUG")]
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void Fail(string message)
{
Assert(false, message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static Exception GetRuntimeException(ExceptionIDs id)
return new PlatformNotSupportedException();

default:
Debug.Assert(false, "unexpected ExceptionID");
Debug.Fail("unexpected ExceptionID");
RuntimeImports.RhpFallbackFailFast();
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private static bool ClassifyEightBytes(TypeDesc typeDesc,
// The field can't span past the end of the struct.
if ((normalizedFieldOffset + fieldSize) > helper.StructSize)
{
Debug.Assert(false, "Invalid struct size. The size of fields and overall size don't agree");
Debug.Fail("Invalid struct size. The size of fields and overall size don't agree");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private int GetFieldSize(TypeDesc fieldType)
}
else
{
Debug.Assert(false, fieldType.ToString());
Debug.Fail(fieldType.ToString());
return fieldType.GetElementSize().AsInt;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ void MapGeneratedTypeTypeParameters(
}
else
{
Debug.Assert(false, "This should be impossible in valid code");
Debug.Fail("This should be impossible in valid code");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void HandleTypeForwarders(Cts.Ecma.EcmaModule module)
}
else
{
Debug.Assert(false, "Multi-module assemblies");
Debug.Fail("Multi-module assemblies");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
return;
}
}
Debug.Assert(false, "Not possible to reach here");
Debug.Fail("Not possible to reach here");
};
// Scan for pre-existing fingerprint entry in buckets
if (hasEntryInBucket(bucketAIndex, fingerprint) || hasEntryInBucket(bucketBIndex, fingerprint))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ private bool ComputeTypeReferenceVersionsWithCode(TypeDesc type)
return true;
}

Debug.Assert(false, "Unhandled form of type in VersionsWithTypeReference");
Debug.Fail("Unhandled form of type in VersionsWithTypeReference");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ private int RelocateRVA(int rva)
return rva + sectionRvaDelta.DeltaRVA;
}
}
Debug.Assert(false, "RVA is not within any of the input sections - output PE may be inconsistent");
Debug.Fail("RVA is not within any of the input sections - output PE may be inconsistent");
return rva;
}

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/tools/r2rdump/TextDumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public override void DumpSectionContents(ReadyToRunSection section)
if (curMethod != (countMethods + 1))
{
Program.WriteWarning("MethodIsGenericMap malformed");
System.Diagnostics.Debug.Assert(false, "MethodIsGenericMap malformed");
System.Diagnostics.Debug.Fail("MethodIsGenericMap malformed");
}
break;
}
Expand All @@ -561,7 +561,7 @@ public override void DumpSectionContents(ReadyToRunSection section)
if (countTypes != NativeReader.ReadUInt16(_r2r.Image, ref mapOffset))
{
Program.WriteWarning("EnclosingTypeMap malformed");
System.Diagnostics.Debug.Assert(false, "EnclosingTypeMap malformed");
System.Diagnostics.Debug.Fail("EnclosingTypeMap malformed");
}
int curType = 1;
while (curType <= (countTypes + 1))
Expand Down Expand Up @@ -594,7 +594,7 @@ public override void DumpSectionContents(ReadyToRunSection section)
if (curType != (countTypes + 1))
{
Program.WriteWarning("TypeGenericInfoMap malformed");
System.Diagnostics.Debug.Assert(false, "TypeGenericInfoMap malformed");
System.Diagnostics.Debug.Fail("TypeGenericInfoMap malformed");
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private static bool IsTargetAttribute(MetadataReader reader, CustomAttribute att
break;

default:
Debug.Assert(false, "Unknown attribute constructor kind");
Debug.Fail("Unknown attribute constructor kind");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected IEnumerable<T> CreateEnumerable(EnumerableType type, IEnumerable<T> en
case EnumerableType.Lazy:
return CreateLazyEnumerable(enumerableToMatchTo, count, numberOfMatchingElements, numberOfDuplicateElements);
default:
Debug.Assert(false, "Check that the 'EnumerableType' Enum returns only types that are special-cased in the CreateEnumerable function within the Iset_Generic_Tests class");
Debug.Fail("Check that the 'EnumerableType' Enum returns only types that are special-cased in the CreateEnumerable function within the Iset_Generic_Tests class");
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Common/tests/System/Xml/XmlDiff/XmlDiff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private bool CompareChildren(XmlDiffNode sourceNode, XmlDiffNode targetNode)
else
{
//Both SourceRead and TargetRead is NULL
Debug.Assert(false, "Impossible Situation for comparison");
Debug.Fail("Impossible Situation for comparison");
}
}
return flag;
Expand Down
14 changes: 7 additions & 7 deletions src/libraries/Common/tests/System/Xml/XmlDiff/XmlDiffDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ internal NodePosition ComparePosition(XmlDiffNode node1, XmlDiffNode node2)
else
{
//something really wrong here, what should we do???
Debug.Assert(false, "ComparePosition meets an indecision situation.");
Debug.Fail("ComparePosition meets an indecision situation.");
return NodePosition.Unknown;
}
}
Expand Down Expand Up @@ -747,7 +747,7 @@ public string GetAttribute(string localName, string namespaceURI)

public string GetNamespace(string name)
{
Debug.Assert(false, "GetNamespace is NYI");
Debug.Fail("GetNamespace is NYI");
return "";
}

Expand Down Expand Up @@ -835,12 +835,12 @@ public bool MoveToFirstChild()
}
public bool MoveToId(string id)
{
Debug.Assert(false, "MoveToId is NYI");
Debug.Fail("MoveToId is NYI");
return false;
}
public bool MoveToNamespace(string name)
{
Debug.Assert(false, "MoveToNamespace is NYI");
Debug.Fail("MoveToNamespace is NYI");
return false;
}
public bool MoveToNext()
Expand Down Expand Up @@ -1000,15 +1000,15 @@ public string BaseURI
{
get
{
Debug.Assert(false, "BaseURI is NYI");
Debug.Fail("BaseURI is NYI");
return "";
}
}
public string XmlLang
{
get
{
Debug.Assert(false, "XmlLang not supported");
Debug.Fail("XmlLang not supported");
return "";
}
}
Expand Down Expand Up @@ -1594,7 +1594,7 @@ public override void WriteTo(XmlWriter w)
w.WriteString(Value);
break;
default:
Debug.Assert(false, $"Wrong type for text-like node : {this._nodetype}");
Debug.Fail($"Wrong type for text-like node : {this._nodetype}");
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ internal Expression InitializeArgumentVariant(MemberExpression variant, Expressi
return Expression.Assign(variant, Expression.Property(null, typeof(ComVariant).GetProperty(nameof(ComVariant.Null), BindingFlags.Public | BindingFlags.Static)));

default:
Debug.Assert(false, "Unexpected VarEnum");
Debug.Fail("Unexpected VarEnum");
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ internal Type GetImplementationType()
}
}

Debug.Assert(false, "ImplementationType, ImplementationInstance, ImplementationFactory or KeyedImplementationFactory must be non null");
Debug.Fail("ImplementationType, ImplementationInstance, ImplementationFactory or KeyedImplementationFactory must be non null");
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void InstrumentPublished(Instrument instrument, MeterListener _)

if (_instruments.ContainsKey(instrument))
{
Debug.Assert(false, "InstrumentPublished called for an instrument we're already listening to.");
Debug.Fail("InstrumentPublished called for an instrument we're already listening to.");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public IReadOnlyList<LoggerClass> GetLogClasses(IEnumerable<ClassDeclarationSynt
break;

default:
Debug.Assert(false, "Unexpected number of arguments in attribute constructor.");
Debug.Fail("Unexpected number of arguments in attribute constructor.");
break;
}
}
Expand Down
Loading

0 comments on commit c7b34c8

Please sign in to comment.