Repository navigation
Support for interface dispatch on native AOT/WASM - #135763
MichalStrehovsky merged 5 commits into
Conversation
Cannot use VSD, so use a resolver. We might want to do something with the perf later. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c78266f3-08e3-4918-b2e5-9fe0ddf2ca17
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
|
Azure Pipelines: Successfully started running 5 pipeline(s). 11 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.
🟡 Changes recommended
Unsupported generic lookups can crash compilation, and standalone virtual function-pointer lookups lack required receiver null checks.
3 open findings
What changed in this PR
Advances NativeAOT/WASI support by resolving interface targets before calling them with their actual signatures.
Changes:
- Selects Wasm-specific interface lookup behavior and the fixed-signature resolver.
- Adds importer support for interface lookups and enables class-virtual function-pointer resolution.
Validation here was limited to source inspection; no builds or tests were run.
| File | Description |
|---|---|
| src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs | Selects Wasm dispatch lookups, resolver, and null-check requirements. |
| src/coreclr/jit/importer.cpp | Imports Wasm interface lookups and enables NativeAOT class-virtual resolution. |
🧠 Review effort: Balanced
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c78266f3-08e3-4918-b2e5-9fe0ddf2ca17
Propagate unsupported generic dictionary lookups out of ldvirtftn import and the indirect-call importer. Request explicit receiver null checks for Wasm interface and class-virtual resolvers, tagging the class helper argument as the this pointer. Simplify the Wasm R2R comment as requested. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c78266f3-08e3-4918-b2e5-9fe0ddf2ca17
|
@dotnet/jit-contrib could someone have a look? this is blocking progress for native AOT WASM. We cannot start testing anything in the CI if interface dispatch doesn't work and native AOT WASM already got broken twice since I started working on it. |
@adamperlin @EgorBo could you have a look please? I thought I can wait for Jakob to be back but he's still not back and this is getting really blocking. |
|
@MichalStrehovsky it looks like we need to apply this patch: bool IsGenericVirtual(Compiler* compiler) const
{
return (gtCallType == CT_INDIRECT && (gtControlExpr->IsHelperCall(CORINFO_HELP_VIRTUAL_FUNC_PTR) ||
gtControlExpr->IsHelperCall(CORINFO_HELP_GVMLOOKUP_FOR_SLOT) ||
+ gtControlExpr->IsHelperCall(CORINFO_HELP_INTERFACELOOKUP_FOR_SLOT)
#ifdef FEATURE_READYTORUN
|| gtControlExpr->IsHelperCall(CORINFO_HELP_READYTORUN_VIRTUAL_FUNC_PTR)
#endif
));
}for divirtualizations to work. |
Treat CORINFO_HELP_INTERFACELOOKUP_FOR_SLOT like the other virtual function lookup helpers: make calls through it devirtualization candidates and model it as a pure helper so lookups can be CSE'd and hoisted. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d0ebd8c9-e09f-4780-8ee2-7381f7a0b5fd
|
Thanks for the reviews! I ran some additional validation - enabled this on Windows and ran a decent subset of src/tests tree with it. This should work, we can do perf fixes later. |


Part of a series of pull requests that enable compiling, linking, and running a
Console.WriteLinehello world on WASI/native AOT.Summary
Resolve NativeAOT Wasm interface targets and call them indirectly with the actual method signature, rather than using the arbitrary-signature
RhpInterfaceDispatchstub.ILC reports
CORINFO_VIRTUALCALL_LDVIRTFTN, retains concrete or generic dispatch-cell lookups, and requests null-instance checks. RyuJIT passes the receiver and cell toCORINFO_HELP_INTERFACELOOKUP_FOR_SLOT; Wasm maps that to the existing fixed-signatureRhpResolveInterfaceMethodrather than the unsupported fast helper.The existing generic-virtual-method path is retained. The importer also enables NativeAOT Wasm's existing ReadyToRun resolver for class-virtual
ldvirtftn, covering delegates bound to class virtual methods. Non-Wasm NativeAOT stub selection and the CoreCLR Wasm fallback are preserved.Validation
verify-interface-codegen.ps1- 6/6 Wasm cases compiled and passed Wasm validation; no case importedRhpInterfaceDispatch, and the concrete/generic call cases importedRhpResolveInterfaceMethod.The cases cover concrete interface calls, shared generic methods/types, interface delegates, and class-virtual delegates. These are codegen checks, not interface-dispatch execution tests.
These results are from the combined local bringup tree, including prerequisite NativeAOT/Wasm enablement, not a fresh build of this isolated main-based branch. The probe script is a local fixture, not a test added by this PR.
Note
This PR description was generated by GitHub Copilot.