Skip to content

Conversation

jkoritzinsky
Copy link
Member

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 with MetadataType.BaseType with MetadataType 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.

@Copilot Copilot AI review requested due to automatic review settings October 8, 2025 18:12
Copy link
Contributor

@Copilot Copilot AI left a 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 covariant BaseType returning MetadataType
  • 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

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jkoritzinsky
Copy link
Member Author

/ba-g failures are #120577 but BA didn't pick them up for some reason

@jkoritzinsky jkoritzinsky merged commit f8796dc into dotnet:main Oct 9, 2025
113 of 122 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants