Skip to content

Add CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE_MAYBENULL to ReadyToRun - #132341

Closed
adamperlin wants to merge 2 commits into
dotnet:mainfrom
adamperlin:adamperlin/fix-type-handle-helper-request
Closed

Add CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE_MAYBENULL to ReadyToRun#132341
adamperlin wants to merge 2 commits into
dotnet:mainfrom
adamperlin:adamperlin/fix-type-handle-helper-request

Conversation

@adamperlin

@adamperlin adamperlin commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #132185.
CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE_MAYBENULL does not exist on ReadyToRun and crossgen will throw a RequiresRuntimeJit exception if the helper is requested. CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE (non-null handling variant) exists already though, so this PR adds a fixup kind to expose the MAYBENULL variant for R2R for platforms like Wasm which don't have a runtime JIT.

Validation

refanytype1.il has been updated to:

  1. Ensure non-null TypedReference still works as expected
  2. Ensure CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPEHANDLE_MAYBENULL(default(TypedReference)) = default(TypedReference)
  3. Ensure CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE_MAYBENULL(default(TypedReference))) = null

Use __reftype(TypedReference) to trigger the use of CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE_MAYBENULL and assert that the containing method exists in the Wasm R2R image.

Note

This pull request was generated with GitHub Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0c38eea1-912f-4411-89bc-83b71c52ac1d
Copilot AI lite review requested due to automatic review settings August 14, 2026 21:30
@adamperlin adamperlin changed the title Add CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE{HANDLE}_MAYBENULL to ReadyToRun Add CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE_MAYBENULL to ReadyToRun Aug 14, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a ReadyToRun (R2R) helper/fixup kind for the CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE_MAYBENULL family so Crossgen2 can emit/resolve it during R2R compilation (notably for Wasm targets without a runtime JIT), avoiding RequiresRuntimeJit failures when importing patterns like refanytype + Type.GetTypeFromHandle.

Changes:

  • Introduces ReadyToRunHelper.GetRuntimeTypeHandleMaybeNull (0x57) across CoreCLR headers and tooling, and bumps the R2R minor version to 26.2.
  • Updates the R2R JIT-EE (CorInfoImpl.ReadyToRun) to map *_MAYBENULL TypeHandle→RuntimeType helpers to the new R2R helper cell instead of throwing RequiresRuntimeJitException.
  • Extends test coverage: updates the importer IL test and adds a Wasm Webcil R2R test that ensures a __reftype(TypedReference) path compiles into the Wasm R2R image.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/tests/JIT/Directed/coverage/importer/refanytype1.il Extends IL test to exercise non-null and default TypedReference paths and trigger the MAYBENULL helper.
src/coreclr/tools/Common/Internal/Runtime/ReadyToRunConstants.cs Adds the new ReadyToRunHelper enum value used by tooling.
src/coreclr/tools/Common/Internal/Runtime/ModuleHeaders.cs Bumps R2R header minor version to 26.2 for managed tooling.
src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs Teaches signature pretty-printer to decode/display the new helper.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs Maps the MAYBENULL helpers to the new R2R helper cell and removes the runtime-JIT-only classification.
src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/Webcil/WasmWebcilModule.cs Adds a method using __reftype to ensure the helper is requested during Wasm R2R compilation.
src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.cs Validates the new Webcil method is compiled into the Wasm R2R image.
src/coreclr/nativeaot/Runtime/inc/ModuleHeaders.h Bumps R2R header minor version to 26.2 for NativeAOT runtime.
src/coreclr/inc/readytorunhelpers.h Adds the new helper mapping in the CoreCLR R2R helper table.
src/coreclr/inc/readytorun.h Bumps R2R minor version constant and adds the new helper enum value in native headers.

@EgorBo

EgorBo commented Aug 14, 2026

Copy link
Copy Markdown
Member

Not for this PR, but I think all _MAYBENULL variants should be removed. JIT should just emit a quick nullcheck itself (we would be able to constant fold it then). e.g.

CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE_MAYBENULL(handle)

to

handle == 0 ? null : CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE(handle)

@adamperlin

adamperlin commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Not for this PR, but I think all _MAYBENULL variants should be removed. JIT should just emit a quick nullcheck itself (we would be able to constant fold it then). e.g.

That seems like a good idea. I opened a tracking issue!

EDIT: Closed, I see you already did!

@jkotas

jkotas commented Aug 14, 2026

Copy link
Copy Markdown
Member

all _MAYBENULL variants should be removed. JIT should just emit a quick nullcheck itself

Can we do this instead? Once we add the helper for R2R, it is going to be around forever.

@adamperlin

Copy link
Copy Markdown
Contributor Author

all _MAYBENULL variants should be removed. JIT should just emit a quick nullcheck itself

Can we do this instead? Once we add the helper for R2R, it is going to be around forever.

Yeah, that is a good point. It seems reasonable to do now instead of adding the helper. I'll close this and instead prioritize removing the MAYBENULL variants.

@adamperlin adamperlin closed this Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Wasm] Avoid requesting unsupported type-handle helpers for refanytype during R2R compilation

4 participants