dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.91k stars 4.63k forks source link

Parameter name stripping breaks debugger #102873

Closed MichalStrehovsky closed 1 month ago

MichalStrehovsky commented 3 months ago

We've been weary of doing optimizations that might affect debuggability, such as stripping unused properties. On the other hand, we strip parameter names. The following program:

class Program
{
    static void Main()
    {
        Test(null, null, null);
    }

    static void Test(string a, string b, string c)
    {
        string d = a;
        KeepLocal(ref d);
    }

    static void KeepLocal<T>(ref T t) { }
}

Looks like this under debugger:

image

We should probably decide whether we're fine breaking debugger and either stop doing this optimization unless DebuggerSupport is false, or open floodgates to more optimizations like this.

dotnet-policy-service[bot] commented 3 months ago

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas See info in area-owners.md if you want to be subscribed.

sbomer commented 3 months ago

Thanks for pointing this out! Putting it under DebuggerSupport would make sense to me.