-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[NativeAOT] Enum.GetValues(Type) should have an aot safe implementation #72140
Comments
Looks like this already exists as |
I think we still need an implementation when the source of the type is not known and not able to use the generic one |
Well the issue is that AOT generally requires the type to be known since it can't generate code for every enum possible. So I'm not sure if this would be possible without keeping metadata about every enum. |
The problem is with creating the array type at runtime, not with "what values to fill in". We keep enough metadata to be able to fill it in. We are discussing "fixing" this by having the API return the underlying type of the array. The signature is We did this in the early days of .NET Native. Backtracked on that, but nobody remembers why. We want to try again :). |
@MichalStrehovsky couldn't the TypeLoader dynamically typeload |
It would probably leak out from the implementation of generic interfaces on the arrays. Maybe something like cast to IEnumerator(SomeEnum), do GetEnumerator and on the returned enumerator call the non-generic IEnumerator.Current. It would return a boxed Int because it's hardcoded in code. We need shared code over enums to get around that. |
...at the cost of a small compat break. We return `int[]` instead of `SomeInt32Enum[]`. Fixes dotnet#72140. We can also delete intrinsic handling of `Enum.GetValues` in dataflow analysis but I don't want to conflict with Vitek's dotnet#71485.
#72498 is the way forward for this. |
We have annotated the above API, public static
System.Array GetValues(System.Type enumType)
, as dangerous (RequiresDynamicCode("It might not be possible to create an array of the enum type at runtime. Use the GetValues<TEnum> overload instead.")
).Consider removing the RDC and providing a native AOT safe implementation.
The text was updated successfully, but these errors were encountered: