Skip to content

Commit

Permalink
Add more issue links to trimmer assertions (#102027)
Browse files Browse the repository at this point in the history
Populates more issue links in the ExpectedWarning attributes, and adds a more targeted test case for #102002.

Some AOT warnings are expected to only be in the analyzer and NativeAOT, so those are marked as "NativeAOT specific warning"
  • Loading branch information
jtschuster committed May 9, 2024
1 parent 209ce2e commit de4fa45
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static void Main ()
AnnotationOnGenerics.Test ();
AnnotationOnInteropMethod.Test ();
DelegateCreation.Test ();
DamOnTypeAccessesMembers.Test ();
}

class AnnotatedField
Expand Down Expand Up @@ -332,8 +333,8 @@ static void Ldvirtftn ()
[ExpectedWarning ("IL2111", nameof (MethodWithSingleAnnotatedParameter))]
[ExpectedWarning ("IL2111", nameof (IWithAnnotatedMethod.AnnotatedMethod))]
[ExpectedWarning ("IL2111", nameof (IWithAnnotatedMethod.AnnotatedMethod))]
[ExpectedWarning ("IL2118", nameof (LdftnOnLambdaTriggersLamdaAnalysis), Tool.Trimmer, "https://github.com/dotnet/runtime/issues/85042")]
[ExpectedWarning ("IL2118", nameof (LdftnOnLocalMethodTriggersLocalMethodAnalysis), Tool.Trimmer, "https://github.com/dotnet/runtime/issues/85042")]
[UnexpectedWarning ("IL2118", nameof (LdftnOnLambdaTriggersLamdaAnalysis), Tool.Trimmer, "https://github.com/dotnet/runtime/issues/85042")]
[UnexpectedWarning ("IL2118", nameof (LdftnOnLocalMethodTriggersLocalMethodAnalysis), Tool.Trimmer, "https://github.com/dotnet/runtime/issues/85042")]
static void DynamicallyAccessedMembersAll1 ()
{
typeof (AnnotatedMethodParameters).RequiresAll ();
Expand All @@ -346,8 +347,8 @@ static void DynamicallyAccessedMembersAll1 ()
[ExpectedWarning ("IL2111", nameof (MethodWithSingleAnnotatedParameter))]
[ExpectedWarning ("IL2111", nameof (IWithAnnotatedMethod.AnnotatedMethod))]
[ExpectedWarning ("IL2111", nameof (IWithAnnotatedMethod.AnnotatedMethod))]
[ExpectedWarning ("IL2118", nameof (LdftnOnLambdaTriggersLamdaAnalysis), Tool.Trimmer, "https://github.com/dotnet/runtime/issues/85042")]
[ExpectedWarning ("IL2118", nameof (LdftnOnLocalMethodTriggersLocalMethodAnalysis), Tool.Trimmer, "https://github.com/dotnet/runtime/issues/85042")]
[UnexpectedWarning ("IL2118", nameof (LdftnOnLambdaTriggersLamdaAnalysis), Tool.Trimmer, "https://github.com/dotnet/runtime/issues/85042")]
[UnexpectedWarning ("IL2118", nameof (LdftnOnLocalMethodTriggersLocalMethodAnalysis), Tool.Trimmer, "https://github.com/dotnet/runtime/issues/85042")]
static void DynamicallyAccessedMembersAll2 ()
{
typeof (AnnotatedMethodParameters).RequiresAll ();
Expand Down Expand Up @@ -868,7 +869,7 @@ struct ValueWithAnnotatedField
static extern ValueWithAnnotatedField GetValueWithAnnotatedField ();

// Analyzer doesn't take into account interop attributes
[ExpectedWarning ("IL2110", nameof (ValueWithAnnotatedField._typeField), Tool.Trimmer, "https://github.com/dotnet/linker/issues/2562")]
[ExpectedWarning ("IL2110", nameof (ValueWithAnnotatedField._typeField), Tool.Trimmer, "https://github.com/dotnet/linker/issues/2562")]
[DllImport ("nonexistent")]
static extern void AcceptValueWithAnnotatedField (ValueWithAnnotatedField value);

Expand Down Expand Up @@ -948,6 +949,39 @@ public static void Test ()
}
}

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
public class DamOnTypeAccessesMembers
{
public DamOnTypeAccessesMembers() { }

[RequiresDynamicCode ("--AnnotatedType--")]
[RequiresUnreferencedCode("--AnnotatedType--")]
public class AnnotatedType
{
[ExpectedWarning("IL2112", [nameof(AnnotatedType), "requires unreferenced code", "--AnnotatedType--"], Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/102002")]
public AnnotatedType () { }
}

[ExpectedWarning("IL2114", nameof(MethodWithDataflow), nameof(DynamicallyAccessedMembersAttribute), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/102002")]
public void MethodWithDataflow ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type type) { }

[RequiresDynamicCode ("--MethodWithRequires--")]
[RequiresUnreferencedCode("--MethodWithRequires--")]
[RequiresAssemblyFiles("--MethodWithRequires--")]
[ExpectedWarning("IL2112", "requires unreferenced code", "--MethodWithRequires--", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/102002")]
public void MethodWithRequires () { }

public static void Test ()
{
var o = new DamOnTypeAccessesMembers ();
var t = o.GetType ();
t.RequiresAll();
t.ToString ();
// This triggers the warnings in the analyzer, but not Object.GetType() on DamOnTypeAccessesMembers
//typeof(DamOnTypeAccessesMembers).RequiresAll();
}
}

class TestType { }

[RequiresUnreferencedCode ("--RequiresUnreferencedCodeType--")]
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static void TestConstructors ()
RequireNothing (type);
}

[ExpectedWarning ("IL2105", "Type 'System.Invalid.TypeName' was not found in the caller assembly nor in the base library. " + "Type name strings used for dynamically accessing a type should be assembly qualified.", Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2105", "Type 'System.Invalid.TypeName' was not found in the caller assembly nor in the base library. " + "Type name strings used for dynamically accessing a type should be assembly qualified.", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/95118")]
static void TestUnqualifiedTypeNameWarns ()
{
RequirePublicConstructors ("System.Invalid.TypeName");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void TestKeepsPublicMethods ()
[Kept]
[KeptAttributeAttribute (typeof (KeepsPublicMethodsAttribute))]
// Trimmer/NativeAot only for now - https://github.com/dotnet/linker/issues/2273
[ExpectedWarning ("IL2026", "--ClassWithKeptPublicMethods--", Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2026", "--ClassWithKeptPublicMethods--", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/95118")]
[KeepsPublicMethods (TypeName = "Mono.Linker.Tests.Cases.DataFlow.AttributeFieldDataflow+ClassWithKeptPublicMethods")]
public static void TestKeepsPublicMethodsString ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public static void TestKeepsPublicMethods ()

[Kept]
[KeptAttributeAttribute (typeof (KeepsPublicMethodsAttribute))]
// Trimmer/NativeAot only for now - https://github.com/dotnet/runtime/issues/95118
[ExpectedWarning ("IL2026", "--ClassWithKeptPublicMethodsKeptByName--", Tool.Trimmer | Tool.NativeAot, "")]
// Trimmer/NativeAot only for now
[ExpectedWarning ("IL2026", "--ClassWithKeptPublicMethodsKeptByName--", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/95118")]
[KeepsPublicMethods (TypeName = "Mono.Linker.Tests.Cases.DataFlow.AttributePropertyDataflow+AttributesOnMethod+ClassWithKeptPublicMethodsKeptByName")]
public static void TestKeepsPublicMethodsByName ()
{
Expand Down Expand Up @@ -211,8 +211,8 @@ class AttributeWithConditionalExpression
{
[Kept]
[KeptAttributeAttribute (typeof (KeepsPublicMethodsAttribute))]
// Trimmer/NativeAot only for now - https://github.com/dotnet/linker/issues/2273
[ExpectedWarning ("IL2026", "--ClassWithKeptPublicMethods--", Tool.Trimmer | Tool.NativeAot, "")]
// Trimmer/NativeAot only for now
[ExpectedWarning ("IL2026", "--ClassWithKeptPublicMethods--", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/95118")]
[KeepsPublicMethods (TypeName = 1 + 1 == 2 ? "Mono.Linker.Tests.Cases.DataFlow.AttributePropertyDataflow+AttributeWithConditionalExpression+ClassWithKeptPublicMethods" : null)]
public static void Test ()
{
Expand All @@ -224,7 +224,7 @@ public static void Test ()
// where the owning symbol is not a method.
[Kept]
[KeptAttributeAttribute (typeof (KeepsPublicMethodsAttribute))]
[ExpectedWarning ("IL2026", "--ClassWithKeptPublicMethods--", Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2026", "--ClassWithKeptPublicMethods--", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/95118")]
[KeepsPublicMethods (TypeName = 1 + 1 == 2 ? "Mono.Linker.Tests.Cases.DataFlow.AttributePropertyDataflow+AttributeWithConditionalExpression+ClassWithKeptPublicMethods" : null)]
public static int field;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public static void Main ()
static Type s_typeWithPublicParameterlessConstructor;

[Kept]
// Trimmer and analyzer use different formats for ref parameters: https://github.com/dotnet/linker/issues/2406
[ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(ref Type)", Tool.Analyzer, "")]
[ExpectedWarning ("IL2069", [nameof (s_typeWithPublicParameterlessConstructor), "parameter 'type'", nameof (MethodWithRefParameter)], Tool.Trimmer | Tool.NativeAot, "")]
// Trimmer and analyzer use different formats for ref parameters
[ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2406")]
[ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(ref Type)", Tool.Analyzer, "https://github.com/dotnet/linker/issues/2406")]
[ExpectedWarning ("IL2069", [nameof (s_typeWithPublicParameterlessConstructor), "parameter 'type'", nameof (MethodWithRefParameter)], Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/101955")]
// MethodWithRefParameter (ref x)
[ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(ref Type)", Tool.Analyzer, "")]
[ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2406")]
[ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(ref Type)", Tool.Analyzer, "https://github.com/dotnet/linker/issues/2406")]
public static void PassRefToField ()
{
MethodWithRefParameter (ref s_typeWithPublicParameterlessConstructor);
Expand All @@ -60,9 +60,9 @@ public static void PassRefToField ()
}

[Kept]
// Trimmer and analyzer use different formats for ref parameters: https://github.com/dotnet/linker/issues/2406
[ExpectedWarning ("IL2067", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2067", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(ref Type)", Tool.Analyzer, "")]
// Trimmer and analyzer use different formats for ref parameters:
[ExpectedWarning ("IL2067", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2406")]
[ExpectedWarning ("IL2067", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(ref Type)", Tool.Analyzer, "https://github.com/dotnet/linker/issues/2406")]
public static void PassRefToParameter (Type parameter)
{
MethodWithRefParameter (ref parameter);
Expand Down Expand Up @@ -242,13 +242,13 @@ static void TestLocalAssignment (bool b = true)
}

[Kept]
[ExpectedWarning ("IL2072", [nameof (GetUnknownType), nameof (DataFlowTypeExtensions.RequiresAll)], Tool.Analyzer, "")]
[ExpectedWarning ("IL2072", [nameof (GetTypeWithPublicConstructors), nameof (DataFlowTypeExtensions.RequiresAll)], Tool.Analyzer, "")]
[ExpectedWarning ("IL2072", [nameof (GetTypeWithPublicFields), nameof (DataFlowTypeExtensions.RequiresAll)], Tool.Analyzer, "")]
[ExpectedWarning ("IL2072", [nameof (GetTypeWithPublicFields), nameof (DataFlowTypeExtensions.RequiresAll)], Tool.Analyzer, "")]
// ILLink/ILCompiler produce different warning code: https://github.com/dotnet/linker/issues/2737
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll), Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll), Tool.Trimmer | Tool.NativeAot, "")]
// ILLink/ILCompiler produce different warning code:
[ExpectedWarning ("IL2072", [nameof (GetUnknownType), nameof (DataFlowTypeExtensions.RequiresAll)], Tool.Analyzer, "https://github.com/dotnet/linker/issues/2737")]
[ExpectedWarning ("IL2072", [nameof (GetTypeWithPublicConstructors), nameof (DataFlowTypeExtensions.RequiresAll)], Tool.Analyzer, "https://github.com/dotnet/linker/issues/2737")]
[ExpectedWarning ("IL2072", [nameof (GetTypeWithPublicFields), nameof (DataFlowTypeExtensions.RequiresAll)], Tool.Analyzer, "https://github.com/dotnet/linker/issues/2737")]
[ExpectedWarning ("IL2072", [nameof (GetTypeWithPublicFields), nameof (DataFlowTypeExtensions.RequiresAll)], Tool.Analyzer, "https://github.com/dotnet/linker/issues/2737")]
[UnexpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2737")]
[UnexpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2737")]
static void TestArrayElementReferenceAssignment (bool b = true)
{
var arr1 = new Type[] { GetUnknownType () };
Expand Down
Loading

0 comments on commit de4fa45

Please sign in to comment.