Skip to content

[RyuJit Wasm] Fix Signature Generation Bug with Un-called methods#125090

Merged
adamperlin merged 16 commits intodotnet:mainfrom
adamperlin:adamperlin/wasm-crossgen-method-typenode-deps
Mar 11, 2026
Merged

[RyuJit Wasm] Fix Signature Generation Bug with Un-called methods#125090
adamperlin merged 16 commits intodotnet:mainfrom
adamperlin:adamperlin/wasm-crossgen-method-typenode-deps

Conversation

@adamperlin
Copy link
Contributor

@adamperlin adamperlin commented Mar 3, 2026

#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 adds WasmTypeNode as a static dependency of MethodWithGCInfo to make sure we always create a type signature node for every method we compile.

…ithGCInfo on Wasm, clean up signature index assignment logic
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

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 via WasmLowering.GetSignature.
  • Add a static dependency from MethodWithGCInfo to the method’s WasmTypeNode when targeting Wasm32.
  • Simplify signature index assignment in WasmObjectWriter.RecordMethodSignature by 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).

…yAnalysis/ReadyToRun/MethodWithGCInfo.cs

Co-authored-by: Michal Strehovský <[email protected]>
Copilot AI review requested due to automatic review settings March 3, 2026 01:43
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@SingleAccretion
Copy link
Contributor

WasmTypeNode as a static dependency of MethodWithGCInfo to make sure we always create a type signature node for every method we compile.

I don't think this is an unreasonable approach, but MethodWithGCInfo is not going to be the only node that needs a signature in the long run. All nodes that may inspire imports need a signature. Hand-generated WASM helpers will need a signature. It is going to be quite pervasive, especially for NAOT. Still better than handling it implicitly in the object writer?

@adamperlin
Copy link
Contributor Author

adamperlin commented Mar 3, 2026

WasmTypeNode as a static dependency of MethodWithGCInfo to make sure we always create a type signature node for every method we compile.

I don't think this is an unreasonable approach, but MethodWithGCInfo is not going to be the only node that needs a signature in the long run. All nodes that may inspire imports need a signature. Hand-generated WASM helpers will need a signature. It is going to be quite pervasive, especially for NAOT. Still better than handling it implicitly in the object writer?

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.

@kg
Copy link
Member

kg commented Mar 3, 2026

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 <[email protected]>
Copilot AI review requested due to automatic review settings March 3, 2026 23:58
@adamperlin
Copy link
Contributor Author

adamperlin commented Mar 4, 2026

My work is blocked on this, can we land it as-is or is there something wrong with it?

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).

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@kg
Copy link
Member

kg commented Mar 4, 2026

I was able to just apply your changes locally so we can take our time merging this if you want.

…yAnalysis/ReadyToRun/MethodWithGCInfo.cs

Co-authored-by: Copilot <[email protected]>
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

Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.

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
Copilot AI review requested due to automatic review settings March 6, 2026 18:06
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

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

@adamperlin
Copy link
Contributor Author

@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 AssemblyStubNode as an impl of the interface for now, as I think what we need to do there will become clearer shortly as we implement import thunks for Wasm!

Copilot AI review requested due to automatic review settings March 9, 2026 18:41
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

Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.

@adamperlin adamperlin merged commit 32a7ecb into dotnet:main Mar 11, 2026
105 checks passed
@adamperlin adamperlin deleted the adamperlin/wasm-crossgen-method-typenode-deps branch March 11, 2026 16:47
@kg
Copy link
Member

kg commented Mar 13, 2026

EDIT: Ignore this

Copilot AI pushed a commit that referenced this pull request Mar 13, 2026
…25090)

#124685 changed our signature recording logic in favor of using
`WasmTypeNode`s 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 adds `WasmTypeNode` as a static
dependency of `MethodWithGCInfo` to make sure we always create a type
signature node for every method we compile.

---------

Co-authored-by: Michal Strehovský <[email protected]>
Co-authored-by: SingleAccretion <[email protected]>
Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-crossgen2-coreclr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants