Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ILLink: Keep parameter names unless DebuggerSupport is disabled #105714

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Reflection;

/// <summary>
/// Ensures setting DebuggerSupport = false causes parameter names to be removed
/// </summary>
class Program
{
static int Main(string[] args)
{
// Ensure the method is kept
MethodWithParameter ("");

// Get parameter name via trim-incompatible reflection
var parameterName = reflectedType.GetMethod("MethodWithParameter")!.GetParameters()[0].Name;

// Parameter name should be removed
if (!string.IsNullOrEmpty(parameterName))
return -1;

return 100;
}

static Type reflectedType = typeof(Program);

public static void MethodWithParameter(string parameter) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Reflection;

/// <summary>
/// Ensures setting DebuggerSupport = true causes parameter names to be kept
/// </summary>
class Program
{
static int Main(string[] args)
{
// Ensure the method is kept
MethodWithParameter ("");

// Get parameter name via trim-incompatible reflection
var parameterName = reflectedType.GetMethod("MethodWithParameter")!.GetParameters()[0].Name;

// Parameter name should be kept
if (parameterName != "parameter")
return -1;

return 100;
}

static Type reflectedType = typeof(Program);

public static void MethodWithParameter(string parameter) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
<TestConsoleAppSourceFiles Include="AppDomainGetThreadWindowsPrincipalTest.cs">
<SkipOnTestRuntimes>osx-x64;linux-x64;browser-wasm</SkipOnTestRuntimes>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="DebuggerSupportTrue.cs">
<EnabledProperties>DebuggerSupport</EnabledProperties>
<NativeAotIncompatible>true</NativeAotIncompatible>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="DebuggerSupportFalse.cs">
<DisabledProperties>DebuggerSupport</DisabledProperties>
<NativeAotIncompatible>true</NativeAotIncompatible>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="DebuggerTypeProxyAttributeTests.cs" >
<EnabledProperties>DebuggerSupport</EnabledProperties>
</TestConsoleAppSourceFiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Copyright (c) .NET Foundation. All rights reserved.
UnusedInterfaces="$(_TrimmerUnusedInterfaces)"
IPConstProp="$(_TrimmerIPConstProp)"
Sealer="$(_TrimmerSealer)"
KeepMetadata="@(_TrimmerKeepMetadata)"

Warn="$(ILLinkWarningLevel)"
NoWarn="$(NoWarn)"
Expand Down Expand Up @@ -240,6 +241,11 @@ Copyright (c) .NET Foundation. All rights reserved.
<TrimmerRemoveSymbols Condition=" '$(DebuggerSupport)' != 'false' ">false</TrimmerRemoveSymbols>
</PropertyGroup>

<ItemGroup>
<!-- Keep parameter name and other metadata unless debugger support is disabled. -->
<_TrimmerKeepMetadata Include="all" Condition=" '$(DebuggerSupport)' != 'false' " />
</ItemGroup>

<PropertyGroup>
<_TrimmerPreserveSymbolPaths Condition=" '$(_TrimmerPreserveSymbolPaths)' == '' and '$(DeterministicSourcePaths)' == 'true' ">true</_TrimmerPreserveSymbolPaths>
<_TrimmerPreserveSymbolPaths Condition=" '$(_TrimmerPreserveSymbolPaths)' == '' ">false</_TrimmerPreserveSymbolPaths>
Expand Down
Loading