Skip to content

Conversation

@MichalStrehovsky
Copy link
Member

Fixes #122598.

Cc @dotnet/ilc-contrib

Copy link
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 fixes an issue where proxy type map entries for generic types that could be instantiated at runtime were being incorrectly trimmed. The fix ensures that when a generic type in a proxy type map has a canonical form (indicating it could be created dynamically by the type loader), the compiler creates a dependency to preserve the necessary type instantiation.

  • Adds logic to detect generic proxy type map entries that could be loaded at runtime
  • Creates conditional dependencies to ensure type loader templates are available
  • Adds comprehensive test coverage for the trimming behavior with both used and unused generic proxy types

Reviewed changes

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

File Description
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ProxyTypeMapNode.cs Adds logic to create conditional dependencies for generic types with canonical forms in proxy type maps, ensuring the type loader template is available for runtime instantiation
src/tests/nativeaot/SmokeTests/TrimmingBehaviors/DeadCodeElimination.cs Adds test cases with generic types in proxy type maps to validate that used generic instantiations are preserved while unused ones are trimmed

Copy link
Member

@jtschuster jtschuster left a comment

Choose a reason for hiding this comment

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

Do we need a correspoding change in ILLink?

@MichalStrehovsky
Copy link
Member Author

Do we need a correspoding change in ILLink?

I don't think so. ILLink doesn't analyze instantiated generic code, everything works off definitions. My expectation is that if Gen<> is kept, Gen<object>, Gen<string>,... etc. would all be kept in the proxy map since we don't track generic creation at all.

@MichalStrehovsky MichalStrehovsky merged commit 8ff528f into dotnet:main Jan 9, 2026
112 of 113 checks passed
@MichalStrehovsky MichalStrehovsky deleted the fix122598 branch January 9, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proxy type map doesn't keep entries that can be created dynamically

3 participants