Don't show AggressiveInlining items in exception stacks (#25408)
authorBen Adams <thundercat@illyriad.co.uk>
Wed, 26 Jun 2019 12:55:14 +0000 (14:55 +0200)
committerJan Kotas <jkotas@microsoft.com>
Wed, 26 Jun 2019 12:55:13 +0000 (05:55 -0700)
src/System.Private.CoreLib/shared/System/Diagnostics/StackTrace.cs
src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs
src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs
src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs
src/System.Private.CoreLib/src/System/Utf8String.Manipulation.cs

index 8365c48..3855a5c 100644 (file)
@@ -339,7 +339,32 @@ namespace System.Diagnostics
         private static bool ShowInStackTrace(MethodBase mb)
         {
             Debug.Assert(mb != null);
-            return !(mb.IsDefined(typeof(StackTraceHiddenAttribute)) || (mb.DeclaringType?.IsDefined(typeof(StackTraceHiddenAttribute)) ?? false));
+
+            if (mb.MethodImplementationFlags.HasFlag(MethodImplAttributes.AggressiveInlining))
+            {
+                // Aggressive Inlines won't normally show in the StackTrace; however for Tier0 Jit and
+                // cross-assembly AoT/R2R these inlines will be blocked until Tier1 Jit re-Jits 
+                // them when they will inline. We don't show them in the StackTrace to bring consitency
+                // between this first-pass asm and fully optimized asm.
+                return false;
+            }
+
+            if (mb.IsDefined(typeof(StackTraceHiddenAttribute), inherit: false))
+            {
+                // Don't show where StackTraceHidden is applied to the method.
+                return false;
+            }
+
+            Type? declaringType = mb.DeclaringType;
+            // Methods don't always have containing types, for example dynamic RefEmit generated methods.
+            if (declaringType != null && 
+                declaringType.IsDefined(typeof(StackTraceHiddenAttribute), inherit: false))
+            {
+                // Don't show where StackTraceHidden is applied to the containing Type of the method.
+                return false;
+            }
+
+            return true;
         }
 
         private static bool TryResolveStateMachineMethod(ref MethodBase method, out Type declaringType)
index 9a153ae..f3b63c5 100644 (file)
@@ -51,7 +51,6 @@ namespace System.Runtime.CompilerServices
 
             /// <summary>Gets the result of the ValueTask.</summary>
             [MethodImpl(MethodImplOptions.AggressiveInlining)]
-            [StackTraceHidden]
             public void GetResult() => _value.ThrowIfCompletedUnsuccessfully();
 
             /// <summary>Schedules the continuation action for the <see cref="ConfiguredValueTaskAwaitable"/>.</summary>
@@ -157,7 +156,6 @@ namespace System.Runtime.CompilerServices
 
             /// <summary>Gets the result of the ValueTask.</summary>
             [MethodImpl(MethodImplOptions.AggressiveInlining)]
-            [StackTraceHidden]
             public TResult GetResult() => _value.Result;
 
             /// <summary>Schedules the continuation action for the <see cref="ConfiguredValueTaskAwaitable{TResult}"/>.</summary>
index d7bc41b..db63f7f 100644 (file)
@@ -43,7 +43,6 @@ namespace System.Runtime.CompilerServices
         }
 
         /// <summary>Gets the result of the ValueTask.</summary>
-        [StackTraceHidden]
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         public void GetResult() => _value.ThrowIfCompletedUnsuccessfully();
 
@@ -126,7 +125,6 @@ namespace System.Runtime.CompilerServices
         }
 
         /// <summary>Gets the result of the ValueTask.</summary>
-        [StackTraceHidden]
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         public TResult GetResult() => _value.Result;
 
index 75c6fd9..cfb8040 100644 (file)
@@ -350,7 +350,6 @@ namespace System.Threading.Tasks
 
         /// <summary>Throws the exception that caused the <see cref="ValueTask"/> to fail.  If it completed successfully, nothing is thrown.</summary>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        [StackTraceHidden]
         internal void ThrowIfCompletedUnsuccessfully()
         {
             object? obj = _obj;
index 6fcdf17..bd71883 100644 (file)
@@ -82,8 +82,6 @@ namespace System
         [ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)]
         public Utf8String Slice(int startIndex, int length) => Substring(startIndex, length);
 
-
-        [StackTraceHidden]
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         private void ValidateStartIndexAndLength(int startIndex, int length)
         {