Skip to content

Resolve generic descriptor method signatures in ILC#128123

Merged
MichalStrehovsky merged 11 commits into
mainfrom
copilot/fix-generic-method-warning
May 14, 2026
Merged

Resolve generic descriptor method signatures in ILC#128123
MichalStrehovsky merged 11 commits into
mainfrom
copilot/fix-generic-method-warning

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 13, 2026

Description

NativeAOT could not resolve XML descriptor method signatures that reference generic parameters, e.g. System.Void Method(T), while ILLink accepted the same descriptor.

  • Descriptor matching

    • Formats method signatures with method/type generic context.
    • Resolves signature variables back to their generic parameter names for XML comparison.
  • ILTrim coverage and parity

    • Re-enables existing ILTrim coverage for descriptor-rooted methods by removing expected-failure entries that now pass.
    • Removes the test-specific --disable-opt unreachablebodies test workaround.
    • Adds an ILTrim IsWorthConvertingToThrow approximation so empty method bodies composed of an optional nop followed by ret are preserved as-is, matching ILLink behavior closely enough for these tests.
    • Uses that heuristic when deciding whether to rewrite unreachable method bodies.
  • ILCompiler test coverage

    • Updates the shared LinkXml test expectation so NativeAOT/ILCompiler now expects the generic descriptor-rooted method to be kept.

Example descriptor now handled consistently:

<type fullname="MyGenericClass`1">
  <method signature="System.Void GenericMethod(T)" />
</type>

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/391677e2-3e7d-4e0f-a9c2-1fa5d5657d9e

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 13, 2026 08:28
@dotnet-policy-service dotnet-policy-service Bot added the linkable-framework Issues associated with delivering a linker friendly framework label May 13, 2026
Copilot AI changed the title [WIP] Fix issue with resolving generic methods in xml descriptor Resolve generic descriptor method signatures in ILC May 13, 2026
Copilot AI requested a review from MichalStrehovsky May 13, 2026 08:29
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/913290c3-43f1-4e16-9827-4fb7db797640

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 13, 2026 08:51
Copilot AI requested a review from MichalStrehovsky May 13, 2026 08:53
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/810611fa-e03c-4232-813d-f8de8ad62578

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 13, 2026 11:36
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/810611fa-e03c-4232-813d-f8de8ad62578

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 13, 2026 11:37
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/810611fa-e03c-4232-813d-f8de8ad62578

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 13, 2026 11:42
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/810611fa-e03c-4232-813d-f8de8ad62578

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 13, 2026 11:44
Copilot AI requested a review from MichalStrehovsky May 13, 2026 11:45
@MichalStrehovsky
Copy link
Copy Markdown
Member

@copilot ILCompiler.Trimming.Tests are failing, I think it's because we actually fixed this for ILCompiler: Method Mono.Linker.Tests.Cases.LinkXml.UnusedMethodPreservedByLinkXmlIsKept.Unused.PreservedMethod5(T)' should have been removed`

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/e85e6e55-0409-469d-9288-7283c85af2f8

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 13, 2026 13:18
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 13, 2026

@copilot ILCompiler.Trimming.Tests are failing, I think it's because we actually fixed this for ILCompiler: Method Mono.Linker.Tests.Cases.LinkXml.UnusedMethodPreservedByLinkXmlIsKept.Unused...

Addressed in 5c81b46. Since ILCompiler now resolves the generic descriptor signature, I updated the shared test expectation so PreservedMethod5<T> is kept for NativeAOT too; ILCompiler.Trimming.Tests LinkXml tests now pass locally.

@MichalStrehovsky MichalStrehovsky marked this pull request as ready for review May 13, 2026 13:37
@MichalStrehovsky MichalStrehovsky requested a review from sbomer as a code owner May 13, 2026 13:37
Copilot AI review requested due to automatic review settings May 13, 2026 13:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves descriptor-driven method signature matching so XML descriptors that reference generic parameters (e.g., System.Void GenericMethod(T)) resolve consistently across toolchains, and adjusts ILTrim’s unreachable-body rewriting behavior/tests to align more closely with ILLink/NativeAOT expectations.

Changes:

  • Update XML descriptor signature formatting to include method/type generic context and print signature variables using their generic parameter names.
  • Refine ILTrim unreachable-body rewriting to preserve extremely small bodies (ret and nop; ret) instead of converting them to a shared ldnull; throw stub.
  • Re-enable/adjust test coverage by removing ILTrim expected-failure entries and updating LinkXml expectations.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/tools/illink/test/Mono.Linker.Tests.Cases/LinkXml/UnusedMethodPreservedByLinkXmlIsKept.cs Updates test expectation so the descriptor-rooted generic method is expected to be kept generally.
src/coreclr/tools/ILTrim.Tests/ILTrimExpectedFailures.txt Removes several entries that should now pass with the improved signature matching and unreachable-body behavior.
src/coreclr/tools/ILTrim.Core/DependencyAnalysis/TokenBased/MethodDefinitionNode.cs Adds a small-body heuristic to avoid converting ret / nop; ret methods to an unreachable throw body when optimizing.
src/coreclr/tools/Common/Compiler/ProcessLinkerXmlBase.cs Formats method signatures with generic context so signature variables can be emitted as generic parameter names for XML comparison.

Copy link
Copy Markdown
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@MichalStrehovsky
Copy link
Copy Markdown
Member

/ba-g the tests completed successfully, but there was some Python error after they were done. looks like infra hiccup

@MichalStrehovsky MichalStrehovsky merged commit 78a3f96 into main May 14, 2026
134 of 137 checks passed
@MichalStrehovsky MichalStrehovsky deleted the copilot/fix-generic-method-warning branch May 14, 2026 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Infrastructure linkable-framework Issues associated with delivering a linker friendly framework

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

ILC: can't resolve methods in generic types with generic type arguments as a parameter type in xml descriptor

4 participants