-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add GetEcmaDefinition extension method for MethodDesc in crossgen2 #122123
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
…eadyToRun This extension method returns the EcmaMethod that defines metadata for a method, handling AsyncMethodVariant by returning its Target property. This provides a crossgen2-specific way to get the ECMA metadata definition for methods that may be wrapped in synthetic method types. Co-authored-by: jtschuster <36744439+jtschuster@users.noreply.github.com>
…dback Co-authored-by: jtschuster <36744439+jtschuster@users.noreply.github.com>
src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunTableManager.cs
Outdated
Show resolved
Hide resolved
Update GetEcmaDefinition to handle PInvokeTargetNativeMethod by mapping to its Target property, and use the helper in CorInfoImpl.ReadyToRun.cs to remove the explicit if statement for PInvokeTargetNativeMethod. Co-authored-by: jtschuster <36744439+jtschuster@users.noreply.github.com>
…nTableManager.cs Co-authored-by: Jan Kotas <jkotas@microsoft.com>
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 a new extension method GetEcmaDefinition() for MethodDesc in the ReadyToRun compiler to cleanly separate "getting the uninstantiated method" from "getting the method with ECMA metadata". This solves an issue where GetTypicalMethodDefinition() was overloaded to mean both concepts, which broke down with the introduction of AsyncMethodVariant.
Key changes:
- Created
R2RMethodExtensions.cswith theGetEcmaDefinition()extension method that handles special wrapper types likeAsyncMethodVariantandPInvokeTargetNativeMethod - Replaced ~15 instances across the codebase where
GetTypicalMethodDefinition()was cast toEcmaMethodwith calls to the new extension method - Improved code clarity by using pattern matching in many locations
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| R2RMethodExtensions.cs | New extension method file containing GetEcmaDefinition() to unwrap method wrappers and return the underlying EcmaMethod |
| ILCompiler.ReadyToRun.csproj | Added the new R2RMethodExtensions.cs file to the project |
| CorInfoImpl.ReadyToRun.cs | Replaced multiple casts of GetTypicalMethodDefinition() to EcmaMethod with calls to GetEcmaDefinition(), including removal of explicit PInvokeTargetNativeMethod handling |
| ReadyToRunCompilationModuleGroupBase.cs | Updated token translation check to use GetEcmaDefinition() |
| ReadyToRunTableManager.cs | Updated module extraction logic to use GetEcmaDefinition() |
| ReadyToRunCodegenNodeFactory.cs | Updated module extraction in debug code to use GetEcmaDefinition() |
| InstanceEntryPointTableNode.cs | Updated signature building to use GetEcmaDefinition() |
| InstrumentationDataTableNode.cs | Updated method-to-int conversion to use GetEcmaDefinition() |
| InliningInfoNode.cs | Updated inlining info collection to use GetEcmaDefinition() and removed redundant cast |
| ProfileDataManager.cs | Updated PGO data synthesis check to use GetEcmaDefinition() with null check |
| ModuleTokenResolver.cs | Updated module token retrieval to use GetEcmaDefinition() with pattern matching |
| ReadyToRunCodegenCompilation.cs | Updated cross-module inlineable check to use GetEcmaDefinition() |
| ReadyToRunVisibilityRootProvider.cs | Updated visibility checks to use GetEcmaDefinition() in two locations |
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/R2RMethodExtensions.cs
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/R2RMethodExtensions.cs
Show resolved
Hide resolved
| MethodDesc[] inlinees = methodNode.InlinedMethods; | ||
| MethodDesc inliner = methodNode.Method; | ||
| EcmaMethod inlinerDefinition = (EcmaMethod)inliner.GetTypicalMethodDefinition(); | ||
| EcmaMethod inlinerDefinition = inliner.GetEcmaDefinition(); |
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.
Is this what we want here?
If we inline async thunk but not the method body itself, we do not want to create an artificial dependency on the method body itself.
| sb.Append("__ReadyToRunInstanceEntryPointTable"u8); | ||
| } | ||
|
|
||
| public static byte[] BuildSignatureForMethodDefinedInModule(MethodDesc method, NodeFactory factory) |
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.
InstanceEntryPointTableNode seems to use this to build a hashtable of all methods stored in a R2R module. I would expect that we want to capture whether the method is the async call variant or not as part of the hashcode key.
|
The implementation of the extension method looks fine. I am not sure whether all uses of it are right. Is your expectation that number of the uses that you are introducing in this PR will need to be revisited? |
Your point about the InliningInfoNode makes me think these changes should wait until we hit issues in the compiler once we start generating async thunks. I'm not familiar enough with the code to know if these changes might cause subtle issues. |
R2RMethodExtensions.csinILCompiler.ReadyToRun/Compilerthat adds aGetEcmaDefinition()extension method forMethodDescEcmaMethod?and handlesAsyncMethodVariantby returning itsTargetpropertyPInvokeTargetNativeMethodby mapping to itsTargetproperty in the extension methodCorInfoImpl.ReadyToRun.csthat castGetTypicalMethodDefinition()toEcmaMethodto use the new extension methodReadyToRunCompilationModuleGroupBase.csthat castGetTypicalMethodDefinition()toEcmaMethodto use the new extension methodReadyToRunTableManager.csthat castGetTypicalMethodDefinition()toEcmaMethodto use the new extension methodReadyToRunCodegenNodeFactory.csthat castGetTypicalMethodDefinition()toEcmaMethodto use the new extension methodInstanceEntryPointTableNode.csthat castGetTypicalMethodDefinition()toEcmaMethodto use the new extension methodInstrumentationDataTableNode.csthat castGetTypicalMethodDefinition()toEcmaMethodto use the new extension methodInliningInfoNode.csthat castGetTypicalMethodDefinition()toEcmaMethodto use the new extension methodProfileDataManager.csthat checkGetTypicalMethodDefinition() is EcmaMethodto use the new extension methodModuleTokenResolver.csthat pattern matchGetTypicalMethodDefinition() is EcmaMethodto use the new extension methodReadyToRunCodegenCompilation.csthat pattern matchGetTypicalMethodDefinition() is EcmaMethodto use the new extension methodReadyToRunVisibilityRootProvider.csthat pattern matchGetTypicalMethodDefinition() is EcmaMethodto use the new extension methodOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.