-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Don't use whole program analysis results when array covariance is involved #117273
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
base: main
Are you sure you want to change the base?
Conversation
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds logic to abort whole-program analysis when array covariance is involved and includes a regression test for bug #117249.
- Introduces
IsArrayVariantCastable
and related checks in compiler components to detect array variance scenarios. - Updates RyuJIT interface, IL importer, scanner, substituted IL provider, and dependency analysis nodes to respect array variance abort logic.
- Adds a new regression test
RegressionBug117249
toDevirtualization.cs
to verify correct handling.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/tests/nativeaot/SmokeTests/UnitTests/Devirtualization.cs | Add regression test for array covariance abort (RegressionBug117249 ) |
src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs | Abort devirtualization when array covariance applies |
src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs | Add array variance check in branch import logic |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutedILProvider.cs | Add array variance check before expanding isinst |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs | Pass TypeSystemContext to devirtualization manager |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/VariantInterfaceMethodUseNode.cs | Correct reference to ArrayOfTEnumeratorType via context |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs | Remove outdated ArrayOfTEnumeratorType cache |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/GenericDefinitionEETypeNode.cs | Update variance-flag logic to use new context property |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs | Update variance-flag logic to use new context property |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.Aot.cs | Add ArrayOfTEnumeratorType , IsArrayVariantCastable , and IsGenericArrayEnumeratorInterfaceType |
Comments suppressed due to low confidence (3)
src/tests/nativeaot/SmokeTests/UnitTests/Devirtualization.cs:94
- C# does not allow forward declarations of enums; you need to define the enum body (e.g.,
enum IntEnum1 { Member = 0 }
) or provide an empty bodyenum IntEnum1 { }
.
enum IntEnum1;
src/tests/nativeaot/SmokeTests/UnitTests/Devirtualization.cs:126
- Casting an
int[]
toIEnumerable<IntEnum1>
will throw at runtime since variance does not apply to value types. Consider using an array of the enum type (e.g.,new IntEnum1[] { ... }
) or switch to a reference type to exercise covariance.
foreach (var v in (IEnumerable<IntEnum1>)GetIntInstance())
src/tests/nativeaot/SmokeTests/UnitTests/Devirtualization.cs:147
- Casting an
int[]
toIEnumerable<IntEnum3>
will throw at runtime since variance does not apply to value types. Adjust the test to use an enum array or a reference-type scenario for valid covariance behavior.
foreach (var v in (IEnumerable<IntEnum3>)GetIntInstance())
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.Aot.cs
Show resolved
Hide resolved
/azp run runtime-nativeaot-outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
Array covariance makes things difficult to model, so just abort. We already had some abort logic but it wasn't sufficient and it wasn't in all the places where it was necessary.
Fixes #117249.
Cc @dotnet/ilc-contrib