You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AOT/analyzer should not warn for MakeGenericType of reference type #97408
(The latter idea is something that has come up in discussion with @vitek-karas and @MichalStrehovsky, not sure if there's another tracking issue for it already.)
Based on some experimentation, it looks like it doesn't always generate the shared impl. I'm not sure exactly what is enough to generate the shared impl. Just calling G<SomeOtherReferenceType>.Method() won't do it - but accessing some of the generic type's methods via reflection will. For example MakeGenericType fails here:
Based on some experimentation, it looks like it doesn't always generate the shared impl. I'm not sure exactly what is enough to generate the shared impl. Just calling G<SomeOtherReferenceType>.Method() won't do it - but accessing some of the generic type's methods via reflection will. For example MakeGenericType fails here:
It works if a method/constructor/field is subsequently accessed because dataflow will report "G<>.Foo is reflection accessed" and then the compiler will try to make G<>.Foo work on at least something.
It shouldn't be hard to make this work for an unused type.
Activity
MichalPetryka commentedon Jan 23, 2024
Does NativeAOT always generate a shared generic impl for this or would it need to scan for
MakeGenericTypeand generate it then?sbomer commentedon Jan 24, 2024
Based on some experimentation, it looks like it doesn't always generate the shared impl. I'm not sure exactly what is enough to generate the shared impl. Just calling
G<SomeOtherReferenceType>.Method()won't do it - but accessing some of the generic type's methods via reflection will. For exampleMakeGenericTypefails here:but succeeds if you uncomment the
GetMethod("Foo").@MichalStrehovsky could probably give a better answer.
MichalStrehovsky commentedon Jan 25, 2024
Looks like we don't treat
MakeGenericTypespecially in dataflow analysis - the only special handling is to trigger the AOT warning here:runtime/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs
Lines 376 to 382 in 135fec0
It works if a method/constructor/field is subsequently accessed because dataflow will report "
G<>.Foois reflection accessed" and then the compiler will try to makeG<>.Foowork on at least something.It shouldn't be hard to make this work for an unused type.
Do not warn on `MakeGeneric` when `class` constraint present
Do not warn on `MakeGeneric` when `class` constraint present (#104029)