Skip to content

Commit

Permalink
Move issue links from comments to the warning attributes in trimming …
Browse files Browse the repository at this point in the history
…tests. (dotnet#101819)

There's a lot of places that we have comments with links to bugs that should be moved to the new warning assertion attributes. This moves most of them to the attributes.
  • Loading branch information
jtschuster committed May 8, 2024
1 parent bca9f0f commit fdac34d
Show file tree
Hide file tree
Showing 30 changed files with 135 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Mono.Linker.Tests.Cases.Expectations.Assertions
[Flags]
public enum Tool
{
None = 0,
Trimmer = 1,
Analyzer = 2,
NativeAot = 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ static void TestArraySetElementOneElementMix ()

[ExpectedWarning ("IL2072", nameof (GetUnknownType), nameof (DataFlowTypeExtensions.RequiresAll), Tool.Analyzer, "")]
[ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), nameof (DataFlowTypeExtensions.RequiresAll), Tool.Analyzer, "")]
// 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, "https://github.com/dotnet/linker/issues/2737")]
static void TestArraySetElementOneElementMerged ()
{
Type[] arr = new Type[1];
Expand Down Expand Up @@ -243,10 +242,8 @@ static void TestArrayResetStoreUnknownIndex (int i = 0)
arr[0].RequiresPublicFields (); // Warns
}

// https://github.com/dotnet/linker/issues/2680 - analyzer doesn't reset array in this case
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresPublicFields), Tool.Trimmer | Tool.NativeAot, "")]
// https://github.com/dotnet/linker/issues/2680 - analyzer doesn't reset array in this case
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresPublicMethods), Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresPublicFields), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2680")]
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresPublicMethods), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2680")]
static void TestArrayResetGetElementOnByRefArray (int i = 0)
{
Type[] arr = new Type[] { typeof (TestType), typeof (TestType) };
Expand Down Expand Up @@ -277,8 +274,7 @@ static void TestArrayResetAfterCall ()

static void TakesTypesArray (Type[] types) { }

// https://github.com/dotnet/linker/issues/2680
// [ExpectedSharedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresPublicFields))]
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresPublicFields), Tool.None, "https://github.com/dotnet/linker/issues/2680")]
static void TestArrayResetAfterAssignment ()
{
Type[] arr = new Type[] { typeof (TestType) };
Expand Down Expand Up @@ -491,8 +487,8 @@ static void TestArrayResetStoreUnknownIndex (int i = 0)
arr[0, 0].RequiresPublicFields (); // Warns
}

// https://github.com/dotnet/linker/issues/2680 - analyzer doesn't reset array in this case
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresPublicFields), Tool.Trimmer | Tool.NativeAot, "")]
// Analyzer doesn't reset array in this case
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresPublicFields), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2680")]
// Multidimensional Arrays not handled -- assumed to be UnknownValue
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresPublicProperties), Tool.Trimmer | Tool.NativeAot, "")]
// Multidimensional Arrays not handled -- assumed to be UnknownValue
Expand Down Expand Up @@ -528,8 +524,7 @@ static void TestArrayResetAfterCall ()

static void TakesTypesArray (Type[,] types) { }

// https://github.com/dotnet/linker/issues/2680
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresPublicFields), Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresPublicFields), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2680")]
// Multidimensional Arrays not handled -- assumed to be UnknownValue
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresPublicProperties), Tool.Trimmer | Tool.NativeAot, "")]
static void TestArrayResetAfterAssignment ()
Expand Down Expand Up @@ -560,8 +555,7 @@ class WriteCapturedArrayElement
{
[ExpectedWarning ("IL2072", nameof (GetUnknownType), nameof (DataFlowTypeExtensions.RequiresAll), Tool.Analyzer, "")]
[ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), nameof (DataFlowTypeExtensions.RequiresAll), Tool.Analyzer, "")]
// 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, "https://github.com/dotnet/linker/issues/2737")]
static void TestNullCoalesce ()
{
Type[] arr = new Type[1];
Expand All @@ -580,8 +574,7 @@ static void TestNullCoalescingAssignment ()
}

[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll), Tool.Analyzer, "")]
// https://github.com/dotnet/linker/issues/2746
[ExpectedWarning ("IL2072", nameof (GetUnknownType), nameof (DataFlowTypeExtensions.RequiresAll), Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2072", nameof (GetUnknownType), nameof (DataFlowTypeExtensions.RequiresAll), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2746")]
static void TestNullCoalescingAssignmentToEmpty ()
{
Type[] arr = new Type[1];
Expand All @@ -590,9 +583,9 @@ static void TestNullCoalescingAssignmentToEmpty ()
}

[ExpectedWarning ("IL2072", nameof (GetWithPublicMethods), nameof (DataFlowTypeExtensions.RequiresAll))]
// https://github.com/dotnet/linker/issues/2746 (ILLink produces incomplete set of IL2072 warnings)
[ExpectedWarning ("IL2072", nameof (GetUnknownType), nameof (DataFlowTypeExtensions.RequiresAll), Tool.Analyzer, "")]
[ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), nameof (DataFlowTypeExtensions.RequiresAll), Tool.Analyzer, "")]
// (ILLink produces incomplete set of IL2072 warnings)
[ExpectedWarning ("IL2072", nameof (GetUnknownType), nameof (DataFlowTypeExtensions.RequiresAll), Tool.Analyzer, "https://github.com/dotnet/linker/issues/2746")]
[ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), nameof (DataFlowTypeExtensions.RequiresAll), Tool.Analyzer, "https://github.com/dotnet/linker/issues/2746")]
static void TestNullCoalescingAssignmentComplex ()
{
Type[] arr = new Type[1];
Expand All @@ -602,8 +595,9 @@ static void TestNullCoalescingAssignmentComplex ()
}

// ILLink only incidentally matches the analyzer behavior here.
// https://github.com/dotnet/linker/issues/2737
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll))]
[UnexpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll), Tool.TrimmerAnalyzerAndNativeAot, "https://github.com/dotnet/linker/issues/2737")]
[ExpectedWarning("IL2072", nameof(GetUnknownType), nameof(DataFlowTypeExtensions.RequiresAll), Tool.None, "https://github.com/dotnet/linker/issues/2737")]
[ExpectedWarning("IL2072", nameof(GetTypeWithPublicConstructors), nameof(DataFlowTypeExtensions.RequiresAll), Tool.None, "https://github.com/dotnet/linker/issues/2737")]
static void TestNullCoalescingAssignmentToEmptyComplex ()
{
Type[] arr = new Type[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
using Mono.Linker.Tests.Cases.Expectations.Assertions;

[assembly: KeptAttributeAttribute (typeof (AttributeConstructorDataflow.KeepsPublicPropertiesAttribute))]
// https://github.com/dotnet/linker/issues/2273
[assembly: ExpectedWarning ("IL2026", "--ClassWithKeptPublicProperties--", Tool.Trimmer | Tool.NativeAot, "")]
[assembly: ExpectedWarning ("IL2026", "--ClassWithKeptPublicProperties--", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2273")]
[assembly: AttributeConstructorDataflow.KeepsPublicProperties (typeof (AttributeConstructorDataflow.ClassWithKeptPublicProperties))]

namespace Mono.Linker.Tests.Cases.DataFlow
Expand All @@ -26,8 +25,7 @@ class AttributeConstructorDataflow
[KeepsPublicMethods ("Mono.Linker.Tests.Cases.DataFlow.AttributeConstructorDataflow+ClassWithKeptPublicMethods")]
[KeepsPublicFields (null, null)]
[TypeArray (new Type[] { typeof (AttributeConstructorDataflow) })]
// 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/linker/issues/2273")]
public static void Main ()
{
typeof (AttributeConstructorDataflow).GetMethod ("Main").GetCustomAttribute (typeof (KeepsPublicConstructorAttribute));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,8 @@ static void TwoOutRefs (
}

[Kept]
// https://github.com/dotnet/runtime/issues/85464
[ExpectedWarning ("IL2069", Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2069", Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2069", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/85464")]
[ExpectedWarning ("IL2069", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/85464")]
public static void Test ()
{
TwoOutRefs (out _publicMethodsField, out _publicPropertiesField);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public static void WithLocalFunctionInner ()
LocalWithWarning<int> ();
}

// https://github.com/dotnet/linker/issues/2937
[ExpectedWarning ("IL2091", Tool.Trimmer, "")]
[ExpectedWarning ("IL2091", Tool.Trimmer, "https://github.com/dotnet/linker/issues/2937")]
void LocalWithWarning<T> ()
{
// Warning!
Expand All @@ -54,8 +53,7 @@ public static void WithLocalFunction ()
LocalWithWarning<int> ();
}

// https://github.com/dotnet/linker/issues/2937
[ExpectedWarning ("IL2091", Tool.Trimmer, "")]
[ExpectedWarning ("IL2091", Tool.Trimmer, "https://github.com/dotnet/linker/issues/2937")]
void LocalWithWarning<T> ()
{
// No warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public ArrayCreateInstanceByNameElement ()
}

[Kept]
[ExpectedWarning ("IL2032", Tool.NativeAot, "")] // https://github.com/dotnet/runtime/issues/82447
[ExpectedWarning ("IL2032", Tool.NativeAot, "https://github.com/dotnet/runtime/issues/82447")]
static void TestArrayCreateInstanceByName ()
{
Activator.CreateInstance ("test", "Mono.Linker.Tests.Cases.DataFlow.ComplexTypeHandling+ArrayCreateInstanceByNameElement[]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public static void Main ()

class DeconstructedVariable
{
// https://github.com/dotnet/linker/issues/3158
[ExpectedWarning ("IL2077", Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2077", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/3158")]
static void DeconstructVariableNoAnnotation ((Type type, object instance) input)
{
var (type, instance) = input;
Expand All @@ -30,8 +29,7 @@ static void DeconstructVariableNoAnnotation ((Type type, object instance) input)

static (Type type, object instance) GetInput (int unused) => (typeof (string), null);

// https://github.com/dotnet/linker/issues/3158
[ExpectedWarning ("IL2077", Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2077", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/3158")]
static void DeconstructVariableFlowCapture (bool b = true)
{
// This creates a control-flow graph where the tuple elements assigned to
Expand All @@ -50,9 +48,8 @@ static void DeconstructVariableFlowCapture (bool b = true)
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
static ref Type AnnotatedProperty => ref annotatedfield;

// https://github.com/dotnet/linker/issues/3158
[ExpectedWarning ("IL2062", Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2078", Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2062", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/3158")]
[ExpectedWarning ("IL2078", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/3158")]
static void DeconstructVariablePropertyReference ((Type type, object instance) input)
{
object instance;
Expand All @@ -72,7 +69,7 @@ record TypeAndInstance (
// For analyzer, this is currently
// https://github.com/dotnet/linker/issues/3158
// But it's possible that with that fixed there won't be a warning from the analyzer anyway (depends on the implementation)
[ExpectedWarning ("IL2067", Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2067", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/3158")]
static void DeconstructRecordWithAnnotation (TypeAndInstance value)
{
var (type, instance) = value;
Expand Down Expand Up @@ -118,8 +115,7 @@ static void DeconstructRecordManualWithAnnotation (TypeAndInstanceRecordManual v
type.RequiresPublicMethods ();
}

// https://github.com/dotnet/linker/issues/3158
[ExpectedWarning ("IL2067", Tool.Trimmer | Tool.NativeAot, "")]
[ExpectedWarning ("IL2067", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/3158")]
static void DeconstructRecordManualWithMismatchAnnotation (TypeAndInstanceRecordManual value)
{
var (type, instance) = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public DataFlowInConstructor ()
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)]
Type annotatedField = GetUnknown ();

[ExpectedWarning ("IL2074", nameof (GetUnknown), nameof (AnnotatedProperty), Tool.Trimmer | Tool.NativeAot, "", CompilerGeneratedCode = true)] // https://github.com/dotnet/runtime/issues/93277
[ExpectedWarning ("IL2074", nameof (GetUnknown), nameof (AnnotatedProperty), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/93277", CompilerGeneratedCode = true)]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)]
Type AnnotatedProperty { get; } = GetUnknown ();

[ExpectedWarning ("IL2074", nameof (GetUnknown), nameof (AnnotatedPropertyWithSetter), Tool.Trimmer | Tool.NativeAot, "", CompilerGeneratedCode = true)] // https://github.com/dotnet/runtime/issues/93277
[ExpectedWarning ("IL2074", nameof (GetUnknown), nameof (AnnotatedPropertyWithSetter), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/93277", CompilerGeneratedCode = true)]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)]
Type AnnotatedPropertyWithSetter { get; set; } = GetUnknown ();

Expand Down Expand Up @@ -79,10 +79,10 @@ public DataFlowInConstructor ()

int PropertyWithThrowStatementInInitializer { get; } = string.Empty.Length == 0 ? throw new Exception() : 0;

[ExpectedWarning ("IL2067", nameof (TryGetUnknown), nameof (RequireAll), Tool.Trimmer | Tool.NativeAot, "", CompilerGeneratedCode = true)] // https://github.com/dotnet/linker/issues/2158
[ExpectedWarning ("IL2067", nameof (TryGetUnknown), nameof (RequireAll), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2158", CompilerGeneratedCode = true)]
int fieldWithLocalReferenceInInitializer = TryGetUnknown (out var type) ? RequireAll (type) : 0;

[ExpectedWarning ("IL2067", nameof (TryGetUnknown), nameof (RequireAll), Tool.Trimmer | Tool.NativeAot, "", CompilerGeneratedCode = true)] // https://github.com/dotnet/linker/issues/2158
[ExpectedWarning ("IL2067", nameof (TryGetUnknown), nameof (RequireAll), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/linker/issues/2158", CompilerGeneratedCode = true)]
int PropertyWithLocalReferenceInInitializer { get; } = TryGetUnknown (out var type) ? RequireAll (type) : 0;

public static void Test ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void Main ()
class InvocationOnDynamicType
{
[ExpectedWarning ("IL2026", "Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember")]
[ExpectedWarning ("IL3050", Tool.NativeAot, "")] // https://github.com/dotnet/runtime/issues/94427
[ExpectedWarning ("IL3050", Tool.NativeAot, "https://github.com/dotnet/runtime/issues/94427")]
static void DynamicArgument ()
{
dynamic dynamicObject = "Some string";
Expand All @@ -48,15 +48,15 @@ static void MethodWithDynamicParameterDoNothing (dynamic arg)
}

[ExpectedWarning ("IL2026", "Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember")]
[ExpectedWarning ("IL3050", Tool.NativeAot, "")] // https://github.com/dotnet/runtime/issues/94427
[ExpectedWarning ("IL3050", Tool.NativeAot, "https://github.com/dotnet/runtime/issues/94427")]
static void MethodWithDynamicParameter (dynamic arg)
{
arg.MethodWithDynamicParameter (arg);
}

// Roslyn codegen no longer produces a call to Binder.InvokeConstructor.
// [ExpectedSharedWarning ("IL2026", "Microsoft.CSharp.RuntimeBinder.Binder.InvokeConstructor")]
// [ExpectedWarning ("IL3050", Tool.NativeAot, "")] // https://github.com/dotnet/runtime/issues/94427
// [ExpectedWarning ("IL3050", Tool.NativeAot, "https://github.com/dotnet/runtime/issues/94427")]
// static void ObjectCreationDynamicArgument ()
// {
// dynamic dynamicObject = "Some string";
Expand All @@ -81,14 +81,14 @@ public static void Test ()
class DynamicMemberReference
{
[ExpectedWarning ("IL2026", "Microsoft.CSharp.RuntimeBinder.Binder.GetMember")]
[ExpectedWarning ("IL3050", Tool.NativeAot, "")] // https://github.com/dotnet/runtime/issues/94427
[ExpectedWarning ("IL3050", Tool.NativeAot, "https://github.com/dotnet/runtime/issues/94427")]
static void Read (dynamic d)
{
var x = d.Member;
}

[ExpectedWarning ("IL2026", "Microsoft.CSharp.RuntimeBinder.Binder.SetMember")]
[ExpectedWarning ("IL3050", Tool.NativeAot, "")] // https://github.com/dotnet/runtime/issues/94427
[ExpectedWarning ("IL3050", Tool.NativeAot, "https://github.com/dotnet/runtime/issues/94427")]
static void Write (dynamic d)
{
d.Member = 0;
Expand All @@ -104,14 +104,14 @@ public static void Test ()
class DynamicIndexerAccess
{
[ExpectedWarning ("IL2026", "Microsoft.CSharp.RuntimeBinder.Binder.GetIndex")]
[ExpectedWarning ("IL3050", Tool.NativeAot, "")] // https://github.com/dotnet/runtime/issues/94427
[ExpectedWarning ("IL3050", Tool.NativeAot, "https://github.com/dotnet/runtime/issues/94427")]
static void Read (dynamic d)
{
var x = d[0];
}

[ExpectedWarning ("IL2026", "Microsoft.CSharp.RuntimeBinder.Binder.SetIndex")]
[ExpectedWarning ("IL3050", Tool.NativeAot, "")] // https://github.com/dotnet/runtime/issues/94427
[ExpectedWarning ("IL3050", Tool.NativeAot, "https://github.com/dotnet/runtime/issues/94427")]
static void Write (dynamic d)
{
d[0] = 0;
Expand All @@ -129,7 +129,7 @@ class DynamicInRequiresUnreferencedCodeClass
[RequiresUnreferencedCode("message")]
class ClassWithRequires
{
[ExpectedWarning ("IL3050", Tool.NativeAot, "")] // https://github.com/dotnet/runtime/issues/94427
[ExpectedWarning ("IL3050", Tool.NativeAot, "https://github.com/dotnet/runtime/issues/94427")]
public static void MethodWithDynamicArg (dynamic arg)
{
arg.DynamicInvocation ();
Expand Down
Loading

0 comments on commit fdac34d

Please sign in to comment.