Fix type map assembly target traversal in ILC#124247
Fix type map assembly target traversal in ILC#124247jkoritzinsky merged 4 commits intodotnet:mainfrom
Conversation
…rovided type map group type (ie, type maps in target assemblies that aren't referenced by AssemblyTarget shouldn't preserve types).
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the ILC (IL Compiler) type map assembly target traversal logic. The issue was that when processing TypeMapAssemblyTarget attributes, the compiler would include ALL type maps from target assemblies, not just the type maps for the specific type map group referenced by the attribute.
Changes:
- Modified
TypeMapMetadata.CreateFromAssemblyto properly scope assembly traversal to specific type map groups - Added
TypeMapAssemblyTargetsModeenum to control whether target assemblies are traversed or just recorded - Implemented a pending maps mechanism to handle cross-assembly type map references efficiently
- Added test coverage for the UsedTypeMapUniverse scenario to validate the fix
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypeMapMetadata.cs | Core fix: tracks assembly+group pairs instead of just assemblies, passes type map group when enqueuing target assemblies, adds pending maps mechanism, adds TypeMapAssemblyTargetsMode enum |
| src/coreclr/tools/aot/ILCompiler/Program.cs | Updates three call sites to pass new parameters (throwHelperEmitModule and TypeMapAssemblyTargetsMode.Traverse) |
| src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/TrimmingDriver.cs | Updates two call sites to pass new parameters (throwHelperEmitModule and TypeMapAssemblyTargetsMode.Traverse) |
| src/tools/illink/test/Mono.Linker.Tests.Cases/Reflection/TypeMap.cs | Adds test case for UsedTypeMapUniverse to verify type maps in library2.dll aren't included when traversing from library.dll's TypeMapAssemblyTarget |
jtschuster
left a comment
There was a problem hiding this comment.
LGTM if/once we have negative tests.
|
@jkoritzinsky is this something we'd hit too in CsWinRT 3.0 and that would be nice to get back ported after it's merged? |
|
I don't expect CsWinRT 3.0 to need this change as all of the different type map groups are in the same or similar assemblies and you are correctly emitting the assembly target attributes. This is more a correctness fix to ensure that when an assembly target attribute is not present, that we won't pick up additional entries. For the expected use cases, there's never a scenario where that would happen intentionally (ie this causing a behavior change in CsWinRT 3.0 would be exposing a bug there). |
|
I see, thank you for explaining! 🙂 |
🤖 Copilot Code Review — PR #124247Holistic AssessmentMotivation: The PR addresses a real bug where Approach: The fix correctly changes the tracking from just assemblies to Summary: Detailed Findings✅ Correct pendingMaps KeyingThe Gemini model initially raised a concern about Dictionary<(EcmaAssembly assembly, TypeDesc typeMapGroup), (TypeDesc scannedDuringGroup, Map map)> pendingMaps = [];This ensures that pending maps are only merged when the specific ✅ MergePendingMap Exception HandlingThe
The existing
|
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypeMapMetadata.cs
Outdated
Show resolved
Hide resolved
Type map assembly target references should only be followed for the provided type map group type (ie, type maps in target assemblies that aren't referenced by AssemblyTarget for that type group shouldn't preserve types).
Type map assembly target references should only be followed for the provided type map group type (ie, type maps in target assemblies that aren't referenced by AssemblyTarget for that type group shouldn't preserve types).