Skip to content

Commit bf799c8

Browse files
sbomerCopilot
andcommitted
Clean up tests and simplify pending reflection-visible set API
- Remove unnecessary #pragma warning disable IL2060 from tests - Add ExpectedNoWarnings to explicit layout test - Remove issue references from test comments - Clarify comment about IL2026 suppression justification - Expose pending sets as properties, inline clear in ProcessMarkedPending - Separate doc comments for method and field pending sets Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Assisted-by: Claude:claude-opus-4.6-1m
1 parent 530a3cf commit bf799c8

4 files changed

Lines changed: 13 additions & 26 deletions

File tree

src/tools/illink/src/linker/Linker.Steps/MarkStep.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ bool ProcessMarkedPending()
502502
ApplyPreserveInfo(type);
503503
}
504504

505-
foreach (var method in Annotations.GetPendingReflectionVisibleMethods())
505+
foreach (var method in Annotations.PendingReflectionVisibleMethods)
506506
{
507507
marked = true;
508508
var origin = new MessageOrigin(method);
@@ -514,14 +514,16 @@ bool ProcessMarkedPending()
514514
// be used as a generic argument in constrained calls via MakeGenericMethod.
515515
MarkTypeVisibleToReflection(method.DeclaringType, new DependencyInfo(DependencyKind.DeclaringType, method), origin);
516516
}
517+
Annotations.PendingReflectionVisibleMethods.Clear();
517518

518-
foreach (var field in Annotations.GetPendingReflectionVisibleFields())
519+
foreach (var field in Annotations.PendingReflectionVisibleFields)
519520
{
520521
marked = true;
521522
var origin = new MessageOrigin(field);
522523
MarkFieldVisibleToReflection(field, new DependencyInfo(DependencyKind.XmlDescriptor, field), origin);
523524
MarkTypeVisibleToReflection(field.DeclaringType, new DependencyInfo(DependencyKind.DeclaringType, field), origin);
524525
}
526+
Annotations.PendingReflectionVisibleFields.Clear();
525527

526528
return marked;
527529
}

src/tools/illink/src/linker/Linker/Annotations.cs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -246,25 +246,17 @@ public bool IsRelevantToVariantCasting(TypeDefinition type)
246246
}
247247

248248
/// <summary>
249-
/// Schedules a method for reflection-visible treatment by MarkStep.
250-
/// Used by DescriptorMarker to defer to MarkStep which owns MarkMethodVisibleToReflection.
249+
/// Schedules a method for reflection-visible marking by MarkStep.
251250
/// </summary>
252251
public void MarkPendingReflectionVisibleMethod(MethodDefinition method) => pending_reflection_visible_methods.Add(method);
253-
public void MarkPendingReflectionVisibleField(FieldDefinition field) => pending_reflection_visible_fields.Add(field);
254252

255-
public MethodDefinition[] GetPendingReflectionVisibleMethods()
256-
{
257-
var result = pending_reflection_visible_methods.ToArray();
258-
pending_reflection_visible_methods.Clear();
259-
return result;
260-
}
253+
/// <summary>
254+
/// Schedules a field for reflection-visible marking by MarkStep.
255+
/// </summary>
256+
public void MarkPendingReflectionVisibleField(FieldDefinition field) => pending_reflection_visible_fields.Add(field);
261257

262-
public FieldDefinition[] GetPendingReflectionVisibleFields()
263-
{
264-
var result = pending_reflection_visible_fields.ToArray();
265-
pending_reflection_visible_fields.Clear();
266-
return result;
267-
}
258+
public HashSet<MethodDefinition> PendingReflectionVisibleMethods => pending_reflection_visible_methods;
259+
public HashSet<FieldDefinition> PendingReflectionVisibleFields => pending_reflection_visible_fields;
268260

269261
public bool SetProcessed(IMetadataTokenProvider provider)
270262
{

src/tools/illink/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/DescriptorPreservedTypeIsReflectionVisible.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,9 @@ public static void Method () { }
7474
[Kept]
7575
static void UseViaReflection ()
7676
{
77-
#pragma warning disable IL2060
7877
typeof (IStaticAbstract).GetMethod (nameof (IStaticAbstract.Call))
7978
.MakeGenericMethod (ExplicitLayoutPreservedViaDescriptor.GetMyType ())
8079
.Invoke (null, null);
81-
#pragma warning restore IL2060
8280
}
8381

8482
[Kept]

src/tools/illink/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/StaticAbstractMethodsPreservedViaDescriptor.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.StaticInterfaceMethods
1212
/// When a type is preserved via an XML descriptor, its static abstract interface
1313
/// implementations should be kept if the static abstract methods are used through
1414
/// constrained calls elsewhere in the program.
15-
/// Regression test for https://github.com/dotnet/runtime/issues/128120
1615
/// </summary>
1716
[SetupLinkerDescriptorFile ("StaticAbstractMethodsPreservedViaDescriptor.xml")]
1817
[ExpectedNoWarnings]
@@ -64,18 +63,14 @@ public static void Method () { }
6463
public static Type GetMyType () => MethodBase.GetCurrentMethod ().DeclaringType;
6564
}
6665

67-
// Mirrors the pattern from the original repro (dotnet/runtime#128120):
68-
// typeof(IStaticAbstract).GetMethod("Call").MakeGenericMethod(preservedType).Invoke(...)
69-
// The descriptor-preserved method GetMyType returns its DeclaringType, which is then
70-
// used as a type argument to MakeGenericMethod on a method constrained by IStaticAbstract.
66+
// Mirrors the pattern where a descriptor-preserved method's DeclaringType is used
67+
// as a type argument to MakeGenericMethod on a method constrained by IStaticAbstract.
7168
[Kept]
7269
static void UseViaReflection ()
7370
{
74-
#pragma warning disable IL2060
7571
typeof (IStaticAbstract).GetMethod (nameof (IStaticAbstract.Call))
7672
.MakeGenericMethod (PreservedViaDescriptorOnly.GetMyType ())
7773
.Invoke (null, null);
78-
#pragma warning restore IL2060
7974
}
8075

8176
[Kept]

0 commit comments

Comments
 (0)