-
Notifications
You must be signed in to change notification settings - Fork 5.4k
NativeAOT: make external TypeMap trimming array-aware with MdArray element fallback #127135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
63caaad
fe6adad
41ffdf3
4c2a5da
2c07962
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,8 @@ | |||||||||||
| [assembly: TypeMap<DeadCodeElimination.TestInteropMapArrayTrimming>("E", typeof(DeadCodeElimination.TestInteropMapArrayTrimming.Target5), typeof(DeadCodeElimination.TestInteropMapArrayTrimming.TrimTarget5[]))] | ||||||||||||
| [assembly: TypeMap<DeadCodeElimination.TestInteropMapArrayTrimming>("F", typeof(DeadCodeElimination.TestInteropMapArrayTrimming.Target6), typeof(DeadCodeElimination.TestInteropMapArrayTrimming.TrimTarget6[]))] | ||||||||||||
| [assembly: TypeMap<DeadCodeElimination.TestInteropMapArrayTrimming>("G", typeof(DeadCodeElimination.TestInteropMapArrayTrimming.Target7), typeof(DeadCodeElimination.TestInteropMapArrayTrimming.TrimTarget7[]))] | ||||||||||||
| [assembly: TypeMap<DeadCodeElimination.TestInteropMapArrayTrimming>("H", typeof(DeadCodeElimination.TestInteropMapArrayTrimming.Target8), typeof(DeadCodeElimination.TestInteropMapArrayTrimming.TrimTarget8[]))] | ||||||||||||
| [assembly: TypeMap<DeadCodeElimination.TestInteropMapArrayTrimming>("I", typeof(DeadCodeElimination.TestInteropMapArrayTrimming.Target9), typeof(DeadCodeElimination.TestInteropMapArrayTrimming.TrimTarget9[,]))] | ||||||||||||
|
|
||||||||||||
| class DeadCodeElimination | ||||||||||||
| { | ||||||||||||
|
|
@@ -1387,13 +1389,17 @@ public struct TrimTarget4<T>; | |||||||||||
| public struct TrimTarget5; | ||||||||||||
| public struct TrimTarget6; | ||||||||||||
| public struct TrimTarget7; | ||||||||||||
| public struct TrimTarget8; | ||||||||||||
| public class TrimTarget9; | ||||||||||||
| public class Target1; | ||||||||||||
| public class Target2; | ||||||||||||
| public class Target3; | ||||||||||||
| public class Target4; | ||||||||||||
| public class Target5; | ||||||||||||
| public class Target6; | ||||||||||||
| public class Target7; | ||||||||||||
| public class Target8; | ||||||||||||
| public class Target9; | ||||||||||||
| public class Atom; | ||||||||||||
|
|
||||||||||||
| public static unsafe object[] MakeGenerics<T>() | ||||||||||||
|
|
@@ -1414,18 +1420,36 @@ public static unsafe object[] MakeGenerics<T>() | |||||||||||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||||||||||||
| static object GetUnknown() => null; | ||||||||||||
|
|
||||||||||||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||||||||||||
| public static object MakeSharedGeneric<T>() | ||||||||||||
| => new T[1,1]; | ||||||||||||
|
|
||||||||||||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||||||||||||
| public static bool TestSharedGeneric<T>() | ||||||||||||
| => MakeSharedGeneric<T>() is T[,]; | ||||||||||||
|
|
||||||||||||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||||||||||||
| static Type GetTrimTarget9() => typeof(TrimTarget9); | ||||||||||||
|
|
||||||||||||
| public static void Run() | ||||||||||||
| { | ||||||||||||
| if (GetUnknown() is TrimTarget7[]) | ||||||||||||
| { | ||||||||||||
| Console.WriteLine("Unexpected"); | ||||||||||||
| } | ||||||||||||
| if (GetUnknown() is TrimTarget8) | ||||||||||||
| { | ||||||||||||
| Console.WriteLine("Unexpected"); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| typeof(TestInteropMapArrayTrimming).GetMethod(nameof(MakeGenerics)).MakeGenericMethod([GetAtom()]).Invoke(null, []); | ||||||||||||
|
|
||||||||||||
| typeof(TestInteropMapArrayTrimming).GetMethod(nameof(TestSharedGeneric)).MakeGenericMethod([GetTrimTarget9()]).Invoke(null, []); | ||||||||||||
|
|
||||||||||||
| var map = TypeMapping.GetOrCreateExternalTypeMapping<TestInteropMapArrayTrimming>(); | ||||||||||||
|
|
||||||||||||
| // A, B, C, F, G: trim target element type is reachable — entries must be present | ||||||||||||
| // I: trim target can be constructed at runtime using type loader | ||||||||||||
|
Comment on lines
1451
to
+1452
|
||||||||||||
| // A, B, C, F, G: trim target element type is reachable — entries must be present | |
| // I: trim target can be constructed at runtime using type loader | |
| // A, B, C, F, G: trim target element type is reachable — entries must be present. | |
| // I: expected due to the shared-generic instantiation exercised above via TestSharedGeneric, | |
| // not because TrimTarget9[,] can use the template-based type-loader fallback for canonical element types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description mentions adding only the new "H" regression case in TestInteropMapArrayTrimming, but this diff also adds a new TypeMap entry "I" (TrimTarget9[,] -> Target9) and additional reflection-based helpers to exercise it. Please either update the PR description to cover the new "I" scenario (and why it's needed), or drop the extra test additions if they’re not intended for this change.