Leaf level AOT annotation for CoreLib library#66976
Leaf level AOT annotation for CoreLib library#66976LakshanF wants to merge 1 commit intodotnet:mainfrom
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-reflection Issue DetailsFirst round of CoreLib (
|
MichalStrehovsky
left a comment
There was a problem hiding this comment.
Most of these changes are to files that are not built with NativeAOT's CoreLib (we really only care about NativeAOT's CoreLib).
I wonder if it would be a better strategy to disable the analyzer on CoreCLR's corelib and only run it on NativeAOT's.
| SR.Format(SR.Format_AttributeUsage, type)); | ||
| } | ||
|
|
||
| [RequiresDynamicCode("The code for an array of the specified type might not be available.")] |
There was a problem hiding this comment.
This can be a suppression - we're creating an instance of a reference type array (System.Attribute is a reference type and Type is expected to be deriving from Attribute or the cast would fail).
Array.CreateInstance with a reference type element is safe.
| /// The logic in this method is replicated in vm/compile.cpp to ensure that NGen saves the right instantiations, | ||
| /// and in vm/jitinterface.cpp so the jit can model the behavior of this method. | ||
| /// </remarks> | ||
| [UnconditionalSuppressMessage("AotAnalysis", "IL3050:UnrecognizedReflectionPattern", |
There was a problem hiding this comment.
This file is not used with NativeAOT - src/coreclr/System.Private.Corelib are files specific to the JIT-based CoreCLR.
It would not be safe - NativeAOT approaches comparers differently and does some work in the compiler to support them.
I don't know how best to approach this - suppressing this runs a risk that if we ever move this code under src/libraries/System.Private.CoreLib and for whatever reason it gets activated under NativeAOT, we'll have a bug.
Maybe the suppression is the best we can do, but it gives me a bad feeling.
As an option to consider, we could also disable the analyzer for CoreCLR's CoreLib.
| [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2055:UnrecognizedReflectionPattern", | ||
| Justification = "MakeGenericType is only called on a TypeBuilder which is not subject to trimming")] | ||
| [UnconditionalSuppressMessage("AotAnalysis", "IL3050:UnrecognizedReflectionPattern", | ||
| Justification = "MakeGenericType is only called on a TypeBuilder which is not subject to trimming")] |
There was a problem hiding this comment.
(Similar comments apply below too - the mention of trimming doesn't describe the reason well enough)
| Justification = "MakeGenericType is only called on a TypeBuilder which is not subject to trimming")] | |
| Justification = "First parameter has to be a TypeBuilder, but it's not possible to obtain a TypeBuilder without getting an AOT warning.")] |
| } | ||
| #endregion | ||
|
|
||
| [RequiresDynamicCode("The code for an array of the specified type might not be available.")] |
There was a problem hiding this comment.
Same comment as ComparerHelpers applies - this is not used for NativeAOT and the compiler otherwise ensures custom attribute blobs are constructable.
| return attributeUsageAttribute ?? AttributeUsageAttribute.Default; | ||
| } | ||
|
|
||
| [RequiresDynamicCode("The code for an array of the specified type might not be available.")] |
There was a problem hiding this comment.
This can be suppressed because the type used in CreateInstance is a reference type (we handle IsValueType with an object array).
| Justification = "Calls to GetInterfaces technically require all interfaces on ReflectedType" + | ||
| "But this is not a public API to enumerate reflection items, all the public APIs which do that" + | ||
| "should be annotated accordingly.")] | ||
| [UnconditionalSuppressMessage("AotAnalysis", "IL3050:UnrecognizedReflectionPattern", |
There was a problem hiding this comment.
This would not be safe (and the justification is off) - this code is not active for NativeAOT. Similar comments to the other place applies.
I really wonder if it would be better to disable the analyzer for CoreCLR's corelib.
| enumType.GetEnumUnderlyingType(); | ||
|
|
||
| #if !CORERT | ||
| [RequiresDynamicCode("It might not be possible to create an array of the enum type at runtime. Use the GetValues<TEnum> overload instead.")] |
There was a problem hiding this comment.
The implementation for NativeAOT of this is AOT friendly - we don't want to bubble this out like this because the only form factor that currently cares is safe:
|
Will close this one without merging since the annotations for CoreClr-CoreLib is not as important for the Native Aot form factor |
First round of CoreLib (
coreclr\System.Private.CoreLib\System.Private.CoreLib.csproj) annotation to get feedback on warning suppression strategy for this level before propagating to all impacted public APIs:ComparerHelpersas this internal class seems to be hardened for generic instantiations. The document sample code works inNativeAotmode.TypeBuilderasReflection.Emitis not supported inNativeAotmode and will throw aNotSupportedException. I want to explore if this option works instead of adding multiple annotations for this class.MemberInfoCache<T>.PopulateInterfacesto match the trimmer suppression since this is an internal API.IL3051ones.