[wasm][R2R] Create manifest token when type reference wasn't pre-registered - #131651
[wasm][R2R] Create manifest token when type reference wasn't pre-registered#131651pavelsavara wants to merge 1 commit into
Conversation
…stered When crossgen2 targets WebAssembly, a method that would have registered a type token during IL token resolution can be skipped by the JIT (JitWasmNyiToR2RUnsupported) while a TypeFixupSignature for that type still exists. GetModuleTokenForType's reverse lookup (TryGetExistingEntityHandle) then returns null and the resolver throws NotImplementedException, failing the R2R compile. Create the manifest reference on demand via TryGetEntityHandle while new tokens are still allowed (before ManifestMetadataTableNode sets DisableNewTokens), mirroring how other manifest references are produced.
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
Fixes a crossgen2 ReadyToRun compilation failure path by allowing ModuleTokenResolver.GetModuleTokenForType to create a manifest metadata reference on-demand when the existing reverse lookup can’t find a pre-registered handle.
Changes:
- Add a fallback in
GetModuleTokenForTypeto callMutableModule.TryGetEntityHandle(type)whenTryGetExistingEntityHandle(type)returns null. - Guard the fallback on
DisableNewTokensto avoid creating new metadata tokens during the “no new tokens” phase.
| // method that would have registered it was skipped by the JIT (JitWasmNyiToR2RUnsupported) yet a | ||
| // fixup for the type still exists. Dynamically create the manifest reference while new tokens are | ||
| // still allowed (this runs before ManifestMetadataTableNode sets DisableNewTokens). | ||
| if (!_manifestMutableModule.DisableNewTokens) |
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
|
This looks reasonable to me aside from the copilot feedback above about a possible synchronization issue. Can we open an issue to revisit this if possible? Hopefully |
Is there better way how to do this ? This is a lookup with side-effects. |
|
I think we will still need/want the ability for the JIT to fail to produce R2R even after we've removed the blanket NYI_WASM fail-over. So crossgen needs to tolerate this failure cleanly. It feels to me like it is committing to emit some things too early, before we know for sure if the method is going to be R2R'd. And so we end up trying to emit something partial. This fix may be a reasonable workaround for now, but I think there may be a better approach out there. |
|
I think this fixing a similar issue as #131610. Can we do a similar fix here as we have in that pr? |
Summary
Fixes a crossgen2 ReadyToRun compilation failure that is specific to the WebAssembly target.
Problem
When crossgen2 targets WebAssembly, a method that would normally register a type token during IL token resolution can be skipped by the JIT (
JitWasmNyiToR2RUnsupported), while aTypeFixupSignaturefor that type is still emitted. At manifest emission time,ModuleTokenResolver.GetModuleTokenForTypedoes a reverse lookup via_manifestMutableModule.TryGetExistingEntityHandle(type), which returnsnullbecause nothing pre-registered the reference. The resolver then falls through tothrow new NotImplementedException(...), which aborts the R2R compile.This was observed while R2R-compiling
System.Runtime.InteropServices.JavaScript.dllforbrowser-wasm, where the reverse lookup fails for[S.P.CoreLib]System.Reflection.MemberInfo.Fix
In the
allowDynamicallyCreatedReferencebranch, when the existing-handle lookup returnsnull, create the manifest reference on demand via_manifestMutableModule.TryGetEntityHandle(type), guarded by!DisableNewTokensso it only runs while new tokens are still allowed (this path executes beforeManifestMetadataTableNodesetsDisableNewTokens). This mirrors how other manifest references are produced.Notes
Note
This change and description were prepared with the assistance of GitHub Copilot.