[RyuJit Wasm] Fix Signature Generation Bug with Un-called methods#125090
[RyuJit Wasm] Fix Signature Generation Bug with Un-called methods#125090adamperlin wants to merge 16 commits intodotnet:mainfrom
Conversation
…ithGCInfo on Wasm, clean up signature index assignment logic
There was a problem hiding this comment.
Pull request overview
Ensures WebAssembly ReadyToRun compilation always materializes a WasmTypeNode (type signature) for every compiled managed method, fixing missing signature/type-section entries for methods that were compiled but never referenced by relocations.
Changes:
- Add a
NodeFactory.WasmTypeNode(MethodDesc)overload that derives the signature viaWasmLowering.GetSignature. - Add a static dependency from
MethodWithGCInfoto the method’sWasmTypeNodewhen targeting Wasm32. - Simplify signature index assignment in
WasmObjectWriter.RecordMethodSignatureby using_uniqueSignatures.Count.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs | Adds a factory helper to create/cache WasmTypeNode from a MethodDesc signature. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs | Ensures each compiled method depends on (and thus emits/records) its Wasm signature node. |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs | Uses dictionary count as the next signature index (removes redundant counter). |
...r/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs
Outdated
Show resolved
Hide resolved
...r/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs
Outdated
Show resolved
Hide resolved
…yAnalysis/ReadyToRun/MethodWithGCInfo.cs Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
...r/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs
Outdated
Show resolved
Hide resolved
I don't think this is an unreasonable approach, but |
This is a good point, and I wasn't considering all the possible NAOT nodes nodes that may need to have this new dependency. The reason I decided on this approach was for clarity -- it seemed clearer to have all type signatures originate in the dependency graph and to simply process them in the object writer, as opposed to having some originate in the graph (for reloc targets) and others in the object writer. |
|
My work is blocked on this, can we land it as-is or is there something wrong with it? |
…yAnalysis/ReadyToRun/MethodWithGCInfo.cs Co-authored-by: SingleAccretion <62474226+SingleAccretion@users.noreply.github.com>
I think we can merge as-is so you're unblocked. I do have a follow up I'm working on that I'll want to merge shortly (basically, an interface that code nodes can implement so that we enforce that they do indeed produce a type signature in the graph). |
|
I was able to just apply your changes locally so we can take our time merging this if you want. |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/FatFunctionPointerNode.cs
Outdated
Show resolved
Hide resolved
...r/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs
Outdated
Show resolved
Hide resolved
…nalysis/FatFunctionPointerNode.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…yAnalysis/ReadyToRun/MethodWithGCInfo.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
...r/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs
Outdated
Show resolved
Hide resolved
Change IWasmCodeNode to look more like IMethodNode for ease of integration. Implement IWasmMethodCodeNode for code carrying nodes, and a dispatch check in ObjectNode.GetStaticDependencies to ensure we add a new edge and node to represent the type signature of a method code node in the dependency graph.
…b.com:adamperlin/runtime into adamperlin/wasm-crossgen-method-typenode-deps
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs
Show resolved
Hide resolved
|
@MichalStrehovsky I've implemented your suggestions for the interface / ObjectNode implementation. Please feel free to take another look when you have a chance. I'm leaving out |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs
Show resolved
Hide resolved
.../ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/DelayLoadHelperMethodImport.cs
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| private protected virtual void RecordMethodDeclaration(ISymbolDefinitionNode node, MethodDesc desc) | ||
| private protected virtual void RecordMethodDeclaration(IWasmCodeNode node, MethodDesc desc) |
There was a problem hiding this comment.
Hmm, I think we'd want to keep this as something general purpose. The general object writing API surface shouldn't have WASM things in it if we can help it.
We have INodeWithDebugInfo, INodeWithCodeInfo... maybe this interface is not Wasm specific and can be just INodeWithSignatureInfo (i.e. rename IWasmCodeNode to INodeWithSignatureInfo so that we don't add WASM specific virtuals)?
There was a problem hiding this comment.
I can try renaming this to INodeWithSignatureInfo. If we want to keep Wasm-specific things out of the object writing API surface, we may also want to rename WasmTypeNode to PredeclaredSignatureNode or something similar? or we could have: WasmTypeNode : IPredeclaredSignatureNode and check for IPredeclaredSignatureNode in the object writer?
There was a problem hiding this comment.
@MichalStrehovsky this should be addressed now!
There was a problem hiding this comment.
we may also want to rename WasmTypeNode to PredeclaredSignatureNode or something similar? or we could have: WasmTypeNode : IPredeclaredSignatureNode and check for IPredeclaredSignatureNode in the object writer?
I think that part can eventually be done somewhere else. I think we'll be able to stop special casing this node.
…> IMethodCodeNodeWithTypeSignature; remove some redundant interface impl declarations
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs
Show resolved
Hide resolved
| namespace ILCompiler.DependencyAnalysis.ReadyToRun | ||
| { | ||
| public class MethodWithGCInfo : ObjectNode, IMethodBodyNode, ISymbolDefinitionNode | ||
| public class MethodWithGCInfo : ObjectNode, IMethodBodyNode, IMethodCodeNodeWithTypeSignature |
There was a problem hiding this comment.
There’s trailing whitespace at the end of the class declaration line. This tends to cause noisy diffs and can violate repo formatting rules; please remove the extra space.
| using ILCompiler.DependencyAnalysis; | ||
| using ILCompiler.DependencyAnalysis.ReadyToRun; | ||
| using ILCompiler.DependencyAnalysis.Wasm; | ||
|
|
There was a problem hiding this comment.
I don't know if this diff makes sense. The System ones should go all the way up and the last ILCompiler one can stay in this group. I would not touch this. Not sure if it's worth respinning CI just for that though.
#124685 changed our signature recording logic in favor of using
WasmTypeNodes in the dependency graph. However, we do not create these nodes currently unless they are the target of a relocation, but every compiled method will need one. This PR addsWasmTypeNodeas a static dependency ofMethodWithGCInfoto make sure we always create a type signature node for every method we compile.