ILLink AOT analyzer: recognize statically-known Enum.GetValues(Type) as intrinsically handled#127258
ILLink AOT analyzer: recognize statically-known Enum.GetValues(Type) as intrinsically handled#127258
Enum.GetValues(Type) as intrinsically handled#127258Conversation
…d tests Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/50b8fa00-f801-423f-8d88-ad7abceb0df6 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Enum.GetValues(Type) as intrinsically handled
|
@copilot the test is failing. next time do not abort running tests. it is expected to run for 40 minutes: |
…cidental generated file Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/eb06220d-4ee6-40c5-8e2d-393941d2c4d5 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
... Fixed in 12710a0. The test expectation had incorrect span |
There was a problem hiding this comment.
Pull request overview
Aligns the ILLink Roslyn AOT analyzer (RequiresDynamicCodeAnalyzer) with NativeAOT/ILC intrinsic handling so Enum.GetValues(Type) does not warn (IL3050) when the enum Type argument is statically known at the callsite.
Changes:
- Added
IntrinsicId.Enum_GetValueshandling toRequiresDynamicCodeAnalyzer.IsIntrinsicallyHandledto suppress IL3050 when the argument value-set is exclusivelySystemTypeValue. - Added Roslyn analyzer unit tests validating known-type (no warning) vs unknown-type (warning) behavior for
Enum.GetValues(Type). - Added shared dataflow intrinsic test coverage in
MakeGenericDataflowIntrinsicsfor known/unknown enumTypecases.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/tools/illink/src/ILLink.RoslynAnalyzer/RequiresDynamicCodeAnalyzer.cs | Adds intrinsic handling for Enum.GetValues(Type) when the type argument is statically known. |
| src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/RequiresDynamicCodeAnalyzerTests.cs | Adds analyzer tests to ensure IL3050 is suppressed/emitted appropriately for Enum.GetValues. |
| src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MakeGenericDataflowIntrinsics.cs | Extends shared dataflow intrinsic coverage with Enum.GetValues scenarios. |
| src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/TypeForwardingTests.g.cs | Updates generated test wrapper to include additional TypeForwarding test cases. |
RequiresDynamicCodeAnalyzercurrently warns onEnum.GetValues(Type)even when the enum type is statically known, while ILC already treats that shape as safe. This change aligns analyzer behavior with the existing ILCIntrinsicId.Enum_GetValueshandling.Analyzer intrinsic parity
IntrinsicId.Enum_GetValueshandling inRequiresDynamicCodeAnalyzer.IsIntrinsicallyHandled.arguments[0]contains exclusivelySystemTypeValue; otherwise warning behavior is unchanged.Roslyn analyzer coverage
EnumGetValuesWithKnownType(no IL3050):Enum.GetValues(typeof(MyEnum))EnumGetValuesWithUnknownType(expects IL3050):Enum.GetValues(GetUnknownType())Shared dataflow intrinsic coverage
MakeGenericDataflowIntrinsicswithEnumGetValuestest cases:Original prompt
This pull request was created from Copilot chat.