-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Use covariant returns in ILCompiler.TypeSystem #120542
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
Use covariant returns in ILCompiler.TypeSystem #120542
Conversation
…pe.MetadataBaseType and remove EcmaType.EcmaModule
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 updates the ILCompiler.TypeSystem to use covariant returns now that the code uses $(NetCoreAppToolCurrent)
, allowing for more modern C# language features. The main change is replacing MetadataType.MetadataBaseType
with MetadataType.BaseType
that returns MetadataType
instead of DefType
, and updating many property and method return types to be more specific subtypes.
Key changes:
- Replaced
MetadataBaseType
property with covariantBaseType
returningMetadataType
- Updated various method signatures to return more specific types (e.g.,
EcmaType
,EcmaMethod
,EcmaField
) - Removed unnecessary type casts throughout the codebase by leveraging the improved type system
Reviewed Changes
Copilot reviewed 76 out of 76 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
src/coreclr/tools/Common/TypeSystem/Common/MetadataType.cs |
Removed MetadataBaseType property and made BaseType abstract with MetadataType return type |
src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs |
Updated to use covariant return types for methods like GetMethods() , GetFields() , and ContainingType |
src/coreclr/tools/Common/TypeSystem/Ecma/EcmaMethod.cs |
Changed OwningType to return EcmaType and added covariant overrides |
src/coreclr/tools/Common/TypeSystem/Ecma/EcmaField.cs |
Changed OwningType to return EcmaType |
src/coreclr/tools/Common/TypeSystem/Common/FieldDesc.cs |
Updated OwningType to return MetadataType |
Multiple other files | Removed explicit casts by leveraging improved type system and updated references from MetadataBaseType to BaseType |
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.
Nice!
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.
LGTM
/ba-g failures are #120577 but BA didn't pick them up for some reason |
Now that all usages of this code use
$(NetCoreAppToolCurrent)
, we can use more modern C# language features that require runtime support.This PR changes a number of the return types of various properties and methods to help narrow the result types and avoid having to add "known to succeed" casts and instead rely on the type system to give correct answers by design.
This PR also removes
MetadataType.MetadataBaseType
and replaces it withMetadataType.BaseType
withMetadataType
as the return type (as the comments on it and all implementations effectively described it as such).This should make it easier for us to avoid adding hard casts and instead represent constraints via the type system.