Repository navigation
[NativeAOT] Enum.GetValues(Type) should have an aot safe implementation #72140
Description
Activity
- ghost addeduntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
on Jul 13, 2022 Looks like this already exists as
Enum.GetValues<Type>- ghost removeduntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
on Jul 14, 2022 I think we still need an implementation when the source of the type is not known and not able to use the generic one
Reacted by Michal Strehovský- ghost addeduntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
on Jul 14, 2022 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
Array GetValues(Type). It currently returnsSomeInt32Enum[]forSomeInt32Enum. But it could also returnint[]and still satisfy the contract. There's an upper bound on primitive type arrays and we can pregenerate that.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
SomeInt32Enum[]by basing it off the underlying type? Given that they have identical layouts and calling conventions, etc.@MichalStrehovsky couldn't the TypeLoader dynamically typeload
SomeInt32Enum[]by basing it off the underlying type? Given that they have identical layouts and calling conventions, etc.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.
- added a commit that references this issue
on Jul 15, 2022 - ghost addedin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
on Jul 15, 2022 - ghost removedin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
on Jul 20, 2022 #72498 is the way forward for this.
- ghost removeduntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
on Jul 21, 2022 - ghost locked as resolved and limited conversation to collaborators
on Aug 20, 2022
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
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.