Skip to content

Eagerly resolve intrinsic ReadyToRun type handles and arrays - #135806

Merged
davidwrighton merged 5 commits into
dotnet:mainfrom
davidwrighton:split/r2r-intrinsic-eager
Oct 19, 2026
Merged

davidwrighton merged 5 commits into
dotnet:mainfrom
davidwrighton:split/r2r-intrinsic-eager

Conversation

@davidwrighton

Copy link
Copy Markdown
Member

Description

Extract the independent eager intrinsic type-handle change from #135553 onto main.

Place concrete TYPE_HANDLE imports for built-in types encoded directly by CorElementType, including string, object, and TypedReference, in module-eager import sections. Apply the same rule to arrays of those types, including multidimensional and nested arrays. Enums, other token-dependent types, pointers, and byrefs retain their existing handling.

Only imports reached by the final dependency traversal are emitted; this does not root a predefined inventory of intrinsic types. Eager cells are resolved at module load instead of appearing in per-method fixup lists.

Current main already provides the supporting behavior: classMustBeLoadedBeforeCodeIsRun retains eager type handles through additional dependencies, and the eager import section disables precode emission for relocation-derived method fixups. No two-phase/transitive-fixup machinery or extra dependency adaptation is needed for this extraction.

This changes common crossgen2 import selection, not just Wasm. Add a regression theory covering optimized/unoptimized and regular/composite compilation, checking exact intrinsic import placement and uniqueness, omission from method fixup lists, and retention of non-eager token-dependent type fixups. Document the eager type-handle rule.

Source commit: eaec645e68f16afacf80aecb3941edd93d3e69f1. This PR does not include two-phase compilation, direct calls, or the prolog/frame-identity changes.

Historical size measurements and tradeoff

These matched before/after Wasm measurements were collected on the original development branch, not on this newly extracted/rebased PR. The recorded JIT hashes and input hashes match between baseline and updated builds. Brotli used quality 11 and window 22.

Wasm image Raw before Raw after Raw savings Brotli before Brotli after Brotli savings
Retail CoreLib 19,108,544 19,105,632 2,912 3,586,039 3,584,618 1,421
CoreLib + CallPerformance composite 12,809,630 12,806,974 2,656 2,811,171 2,808,474 2,697

These are historical size measurements, not throughput benchmarks or a guarantee of equivalent savings on current main. This trades per-method fixup work and storage for module-eager type resolution; no new startup-latency measurements were collected for this extraction.

Validation

  • git diff --check upstream/main...split/r2r-intrinsic-eager — passed.
  • Inspected the extracted four-file diff and traced eager-import dependency preservation and per-method fixup emission in current main.
  • Builds, runtime tests, and new benchmarks for this extracted branch — not run, at the user's explicit request.

This remains a draft; build and runtime validation on the independent branch are outstanding.

Note

This PR was prepared with GitHub Copilot.

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

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/crossgen-contrib
See info in area-owners.md if you want to be subscribed.

@davidwrighton
davidwrighton marked this pull request as ready for review October 14, 2026 22:16
@davidwrighton
davidwrighton requested review from jtschuster and a balanced review from Copilot October 14, 2026 22:16

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.

🟡 Changes recommended

Eager array resolution can violate the VM’s type-loading guard and assert during non-CoreLib module loading on Checked/Debug runtimes.

1 open finding
What changed in this PR

Moves intrinsic ReadyToRun type-handle imports, including arrays, from per-method fixups to module-eager resolution in crossgen2.

Changes:

  • Selects eager imports for intrinsic types and nested arrays.
  • Adds optimized/unoptimized and regular/composite image-validation coverage.
  • Documents eager import placement and dependency retention.

Builds and runtime tests were not run during this review.

File Description
src/​coreclr/​tools/​aot/​ILCompiler.ReadyToRun/​Compiler/​DependencyAnalysis/​ReadyToRunSymbolNodeFactory.cs Selects eager intrinsic type-handle imports.
src/​coreclr/​tools/​aot/​ILCompiler.ReadyToRun.Tests/​TestCases/​Webcil/​WasmWebcilModule.cs Adds intrinsic and token-dependent type fixtures.
src/​coreclr/​tools/​aot/​ILCompiler.ReadyToRun.Tests/​TestCases/​R2RTestSuites.cs Verifies import placement, uniqueness, and method fixups.
docs/​design/​coreclr/​botr/​readytorun-format.md Documents the eager type-handle rule.

🧠 Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Only eagerly resolve direct SZ arrays over intrinsic elements in images that compile CoreLib. Leave multidimensional and jagged arrays lazy.

Check each expected type's import and method fixup independently so legitimate RuntimeTypeHandle signature fixups do not fail the unoptimized theory cases. Extend array-shape coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d46c9015-c682-46e1-ba8d-4c38af3c6c05
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 10d80301-646f-4535-ade2-60e9b5364796
@davidwrighton
davidwrighton merged commit 42a7edd into dotnet:main Oct 19, 2026
102 of 104 checks passed
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.

4 participants