Skip to content

Conversation

@MichalStrehovsky
Copy link
Member

We have an optimization that tries to avoid bringing in constructed MethodTable for struct fields that are reference types. However, if the type of the field is T on a generic type, we had to be conservative because we didn't know if it was a valuetype or not. Use SpecializableILStubMethod instead of ILStubMethod so we know.

Cc @dotnet/ilc-contrib

@Copilot Copilot AI review requested due to automatic review settings July 2, 2025 22:27
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

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 refactors the value-type field helper stub to support per-instantiation specialization and avoids unnecessary MethodTable creation for generic parameters. Key changes include:

  • Switched the ValueTypeMethodHashtable from DefType to MetadataType for broader type keying.
  • Updated ValueTypeGetFieldHelperMethodOverride to inherit from SpecializableILStubMethod and split IL emission into open and specialized paths.
  • Introduced common EmitILCommon to share most of the emitter logic.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.ValueTypeMethods.cs Changed hashtable key and method signatures from DefType to MetadataType.
src/coreclr/tools/Common/TypeSystem/IL/Stubs/ValueTypeGetFieldHelperMethodOverride.cs Converted stub to SpecializableILStubMethod, added overload for specialized IL emission, and centralized IL generation in EmitILCommon.
Comments suppressed due to low confidence (1)

src/coreclr/tools/Common/TypeSystem/IL/Stubs/ValueTypeGetFieldHelperMethodOverride.cs:65

  • Add unit tests for ValueTypeGetFieldHelperMethodOverride covering both the open and specialized IL emission paths, including scenarios with signature-variable fields and inline arrays to ensure correctness after these refactorings.
        public override MethodIL EmitIL(MethodDesc specializedMethod)

@MichalStrehovsky
Copy link
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkotas jkotas added the tenet-performance Performance related issue label Jul 3, 2025
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.

Thanks

@MichalStrehovsky MichalStrehovsky merged commit a7b101f into dotnet:main Jul 3, 2025
95 of 97 checks passed
@MichalStrehovsky MichalStrehovsky deleted the getfieldhelper branch July 3, 2025 12:20
@github-actions github-actions bot locked and limited conversation to collaborators Aug 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants