Uh oh!
There was an error while loading. Please reload this page.
Make Enum.GetValues AOT-safe - #72236
Conversation
...at the cost of a small compat break. We return `int[]` instead of `SomeInt32Enum[]`. Fixesdotnet#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.
ghost
commented
Jul 15, 2022
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
agocke
commented
Jul 15, 2022
Who owns the System.Enum surface area? I presume this needs to go through a back-compat review |
MichalStrehovsky
commented
Jul 15, 2022
Only changing it for NativeAOT. |
agocke
commented
Jul 15, 2022
Woops, missed that this was the nativeaot runtime |
| return result; | ||
| // Compat: we should be returning SomeInt32Enum[]. Instead we return Int32[]. | ||
| // This is a tradeoff since SomeInt32Enum[] type might not have been pregenerated. | ||
| return (Array)Enum.GetEnumInfo(this).ValuesAsUnderlyingType.Clone(); |
There was a problem hiding this comment.
What guarantees that int[] will exist though? Or for that matter other enum backing types, like byte[], short[] and so on.
The comment here assumes that they are available, without explanation. I think it would be good to add a short explanation.
There was a problem hiding this comment.
What guarantees that
int[]will exist though?
Good old new keyword:
I'll add a comment.
There was a problem hiding this comment.
Sorry - I was too lazy to lookup what ValuesAsUnderlyingType does :-(
MichalStrehovsky
commented
Jul 15, 2022
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
LakshanF
left a comment
There was a problem hiding this comment.
LGTM but there seems to be some related test failures
- System.Reflection.Tests
- System.Runtime.Tests
- System.IO.FileSystem.DisabledFileLocking.Tests, not clear if the failure is related to the enum change
- System.Collections.NonGeneric.Tests
- System.Numerics.Vectors.Tests
MichalStrehovsky
commented
Jul 18, 2022
The System.Numerics.Vectors.Tests is #72149. I think that failure is non-deterministic. I'm not sure if it really should be closed unfortunately. I'm looking into the appcompat implications of the other failures (whether we just fixup/disable/add new tests and be done with it, or whether it's blockers). |
MichalStrehovsky
commented
Jul 19, 2022
I looked at the failing tests. The main implication is that if one does So the compat concern is basically that. Would someone call It's basically what the tests do: Couple other alternative:
|
LakshanF
commented
Jul 19, 2022
This is unfortunate. I would expect in most code, the expectations on post operations after the call to this API, would be to see the Enum type and not the underlying type. I think we need to give an indicator to the developer of the behavioral change in native AOT but can see as you indicated. the options you listed above might be getting too late now. I think keeping it unsafe with the recommended message to use the generic API might be the best option :-( |
The biggest issue is that the generic overload wasn't there in .Net Standard 2.0, so a lot of libraries targetting that use the type one. As such, having it work properly would be really useful. Personally I've always copied the data to properly typed arrays, but I've seen samples that just cast the arrays to the enum array type. |
If we cannot fix the existing API, can we introduce a new one? I am thinking Libraries that target NS2.0 would be able to use this API using reflection light-up and still be AOT compatible. It is not the case with the generic overload. Calling the generic overload via reflection requires MakeGenericMethod that comes with the same AOT problem. |
|
jkotas
commented
Jul 19, 2022
Another option that does not require new APIs and that is compatible with NS2.0: Enumerate the enum members as field info. It comes with performance penalty. |
teo-tsirpanis
commented
Jul 19, 2022
Can we make the NativeAOT compiler recognize |
jkotas
commented
Jul 19, 2022
The AOT compiler does that today: The problem is what to do with |
MichalStrehovsky
commented
Jul 19, 2022
Thanks for the data Stephen! The data binding scenario is very likely the reason why .NET Native backtracked on this too (nobody could remember why we backtracked there, only that we backtracked). I've submitted an API proposal for the API Jan proposed here: #72498. I marked it blocking. If we can get it approved soon, I think it would be reasonable to land before RC 1 snaps off. |
jkotas
commented
Jul 20, 2022
The next step is to get #72498 API approved. This PR can be closed. |
...at the cost of a small compat break. We return
int[]instead ofSomeInt32Enum[].Fixes#72140.
We can also delete intrinsic handling of
Enum.GetValuesin dataflow analysis but I don't want to conflict with Vitek's #71485 right now.Cc @dotnet/ilc-contrib