Demystify truncating internals of F# async/task expressions
This commit is contained in:
@@ -114,6 +114,13 @@ namespace System.Diagnostics
|
||||
|
||||
methodName = method.Name;
|
||||
}
|
||||
else if (IsFSharpAsync(method))
|
||||
{
|
||||
methodDisplayInfo.IsAsync = true;
|
||||
methodDisplayInfo.SubMethodBase = null;
|
||||
subMethodName = null;
|
||||
methodName = null;
|
||||
}
|
||||
|
||||
// Method name
|
||||
methodDisplayInfo.MethodBase = method;
|
||||
@@ -241,6 +248,20 @@ namespace System.Diagnostics
|
||||
return methodDisplayInfo;
|
||||
}
|
||||
|
||||
private static bool IsFSharpAsync(MethodBase method)
|
||||
{
|
||||
if (method is MethodInfo minfo)
|
||||
{
|
||||
var returnType = minfo.ReturnType;
|
||||
if (returnType.Namespace == "Microsoft.FSharp.Control" && returnType.Name == "FSharpAsync`1")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool TryResolveGeneratedName(ref MethodBase method, out Type type, out string methodName, out string subMethodName, out GeneratedNameKind kind, out int? ordinal)
|
||||
{
|
||||
kind = GeneratedNameKind.None;
|
||||
@@ -662,6 +683,29 @@ namespace System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
if (type.Namespace == "Microsoft.FSharp.Control")
|
||||
{
|
||||
switch (type.Name)
|
||||
{
|
||||
case "AsyncPrimitives":
|
||||
case "Trampoline":
|
||||
return false;
|
||||
case var typeName when type.IsGenericType:
|
||||
{
|
||||
if (typeName == "AsyncResult`1") return false;
|
||||
else break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type.Namespace == "Ply")
|
||||
{
|
||||
if (type.DeclaringType.Name == "TplPrimitives")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (StackTraceHiddenAttributeType != null)
|
||||
{
|
||||
// Don't show any types marked with the StackTraceHiddenAttribute
|
||||
|
||||
@@ -18,6 +18,9 @@ namespace System.Diagnostics
|
||||
|
||||
internal StringBuilder Append(StringBuilder sb)
|
||||
{
|
||||
if (ResolvedType.Assembly.ManifestModule.Name == "FSharp.Core.dll" && ResolvedType.Name == "Unit")
|
||||
return sb;
|
||||
|
||||
if (!string.IsNullOrEmpty(Prefix))
|
||||
{
|
||||
sb.Append(Prefix)
|
||||
|
||||
@@ -28,6 +28,15 @@ namespace System.Diagnostics
|
||||
{ typeof(ulong), "ulong" },
|
||||
{ typeof(ushort), "ushort" }
|
||||
};
|
||||
|
||||
public static readonly Dictionary<string, string> FSharpTypeNames = new Dictionary<string, string>
|
||||
{
|
||||
{ "Unit", "void" },
|
||||
{ "FSharpOption", "Option" },
|
||||
{ "FSharpAsync", "Async" },
|
||||
{ "FSharpOption`1", "Option" },
|
||||
{ "FSharpAsync`1", "Async" }
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Pretty print a type name.
|
||||
@@ -93,6 +102,11 @@ namespace System.Diagnostics
|
||||
{
|
||||
builder.Append(type.Name);
|
||||
}
|
||||
else if (type.Assembly.ManifestModule.Name == "FSharp.Core.dll"
|
||||
&& FSharpTypeNames.TryGetValue(type.Name, out builtInName))
|
||||
{
|
||||
builder.Append(builtInName);
|
||||
}
|
||||
else if (type.IsGenericParameter)
|
||||
{
|
||||
if (options.IncludeGenericParameterNames)
|
||||
@@ -154,7 +168,15 @@ namespace System.Diagnostics
|
||||
return;
|
||||
}
|
||||
|
||||
builder.Append(type.Name, 0, genericPartIndex);
|
||||
if (type.Assembly.ManifestModule.Name == "FSharp.Core.dll"
|
||||
&& FSharpTypeNames.TryGetValue(type.Name, out var builtInName))
|
||||
{
|
||||
builder.Append(builtInName);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Append(type.Name, 0, genericPartIndex);
|
||||
}
|
||||
|
||||
builder.Append('<');
|
||||
for (var i = offset; i < length; i++)
|
||||
|
||||
Reference in New Issue
Block a user