Repository navigation
Centralize virtual method invocation dependencies - #121740
Conversation
`ReflectionVirtualInvokeMapNode` should be solely responsible for declaring dependencies necessary to generate the invocation table entries. Instead we had them partially duplicated between `ReflectedMethodNode` and `ReflectionVirtualInvokeMapNode.GetVirtualInvokeMapDependencies`. This can lead to subtle problems in the unsupported `IlcTrimMetadata`==`false` mode that needs this work to happen in `ReflectionVirtualInvokeMapNode` since we don't make `ReflectedMethodNode` there (because everything is reflected).
|
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the dependency analysis for virtual method invocation in reflection scenarios by centralizing the logic in ReflectionVirtualInvokeMapNode. Previously, these dependencies were duplicated between ReflectedMethodNode and ReflectionVirtualInvokeMapNode.GetVirtualInvokeMapDependencies.
Key changes:
- Moved virtual method invocation dependency logic entirely from
ReflectedMethodNodetoReflectionVirtualInvokeMapNode.GetVirtualInvokeMapDependencies - Removed early return for generic definitions in
ReflectedMethodNode, as these checks are now handled through the metadata category and reflection invokability checks - Consolidated the handling of both instantiated and non-instantiated virtual methods in
GetVirtualInvokeMapDependencies
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectedMethodNode.cs | Removes virtual method invocation dependencies logic and generic definition early return, simplifying the node to focus on reflection visibility concerns |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectionVirtualInvokeMapNode.cs | Enhances GetVirtualInvokeMapDependencies to handle both generic and non-generic virtual methods, consolidating previously duplicated logic |
Comments suppressed due to low confidence (1)
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectionVirtualInvokeMapNode.cs:104
- [nitpick] The refactoring removes the
NeedsVirtualInvokeInfo(factory, slotDefiningMethod)check that existed in the originalReflectedMethodNode.cscode (line 38 of the old version):
if (ReflectionVirtualInvokeMapNode.NeedsVirtualInvokeInfo(factory, slotDefiningMethod) && !factory.VTable(slotDefiningMethod.OwningType).HasKnownVirtualMethodUse)After refactoring, GetVirtualInvokeMapDependencies only checks NeedsVirtualInvokeInfo(factory, method) before being called (line 83), but not for slotDefiningMethod.
Since FindSlotDefiningMethodForVirtualMethod can return a base class method that may have different devirtualization characteristics (e.g., effectively sealed in a different way), consider whether the check should be preserved:
if (!factory.VTable(slotDefiningMethod.OwningType).HasKnownVirtualMethodUse)
{
if (NeedsVirtualInvokeInfo(factory, slotDefiningMethod))
{
dependencies.Add(factory.VirtualMethodUse(slotDefiningMethod), "Reflection virtual invoke method");
}
}Note: The old ReflectionVirtualInvokeMapNode code path (for non-instantiated methods) didn't have this check either, so this may have been redundant defensive programming in ReflectedMethodNode. However, it's worth verifying whether there are edge cases where method needs virtual invoke info but slotDefiningMethod does not.
else
{
if (!factory.VTable(slotDefiningMethod.OwningType).HasKnownVirtualMethodUse)
{
dependencies.Add(factory.VirtualMethodUse(slotDefiningMethod), "Reflection virtual invoke method");
}
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/ba-g arm64 failure is #121757 |
ReflectionVirtualInvokeMapNodeshould be solely responsible for declaring dependencies necessary to generate the invocation table entries. Instead we had them partially duplicated betweenReflectedMethodNodeandReflectionVirtualInvokeMapNode.GetVirtualInvokeMapDependencies.This can lead to subtle problems in the unsupported
IlcTrimMetadata==falsemode that needs this work to happen inReflectionVirtualInvokeMapNodesince we don't makeReflectedMethodNodethere (because everything is reflected).Cc @dotnet/ilc-contrib