') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Add crossgen2 --strip-il-bodies runtime-async regression test by kotlarmilos · Pull Request #130075 · dotnet/runtime · GitHub
Skip to content

Add crossgen2 --strip-il-bodies runtime-async regression test - #130075

Merged
kotlarmilos merged 2 commits into
dotnet:mainfrom
kotlarmilos:dev/crossgen2-strip-il-bodies-test
Jul 2, 2026
Merged

Add crossgen2 --strip-il-bodies runtime-async regression test#130075
kotlarmilos merged 2 commits into
dotnet:mainfrom
kotlarmilos:dev/crossgen2-strip-il-bodies-test

Conversation

@kotlarmilos

@kotlarmiloskotlarmilos commented Jul 1, 2026

Copy link
Copy Markdown
Member

Description

The --strip-il-bodies optimization in crossgen2 is applied when building the composite ReadyToRun images that ship in the Apple mobile runtime packs, and in #129813 it regressed by stripping the IL of non-async Task/ValueTask-returning methods. That IL is still needed, because with runtime-async enabled the runtime compiles a runtime-async variant of such a method from its IL, so replacing it with a ldnull throw stub threw NullReferenceException on the mobile packs until #129884 narrowed the pass via MayNeedILAtRuntime.

This PR adds a deterministic ILCompiler.ReadyToRun.Tests tests that inspect the emitted component MSIL to assert every branch of the strip logic. Non-async Task<T>/ValueTask<T>/Task/ValueTask-returning methods, a generic method, and a method on a generic type keep their IL, while plain methods and async Task<T>/ValueTask methods are still stripped.

TODO: This PR should be aligned with #130025

CopilotAI review requested due to automatic review settings July 1, 2026 11:35
@github-actionsgithub-actionsBot added the area-crossgen2-coreclr only use for closed issues label Jul 1, 2026

CopilotAI 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 new ILCompiler.ReadyToRun.Tests regression test that validates crossgen2 --strip-il-bodies behavior under runtime-async, by inspecting the emitted component MSIL and asserting which methods should keep vs. lose their IL.

Changes:

  • Extend the R2R test runner option model to include --strip-il-bodies.
  • Add MSIL IL-body inspection helpers (MethodILIsStripped / MethodILIsPresent) and a new runtime-async test case (StripILBodies.cs) plus an xUnit test that asserts strip/preserve decisions.
  • Modify global UseMonoRuntime behavior in Directory.Build.props for *-android/ios/tvos/maccatalyst TFMs when TargetsMobile != true.
Show a summary per file
FileDescription
src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCasesRunner/R2RResultChecker.csAdds helpers to read method IL from the component MSIL and assert stripped vs present bodies.
src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCasesRunner/R2RDriver.csAdds a new modeled crossgen2 option mapping for --strip-il-bodies.
src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/RuntimeAsync/StripILBodies.csNew embedded test input assembly with a mix of async, non-async Task/ValueTask, and generic cases.
src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.csNew [Fact] that runs a composite crossgen2 compile with runtime-async + --strip-il-bodies and asserts IL preservation/stripping.
Directory.Build.propsChanges global defaulting of UseMonoRuntime for mobile-suffixed TFMs when not TargetsMobile.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 4

Comment threadDirectory.Build.props Outdated
@kotlarmilos
kotlarmilosforce-pushed the dev/crossgen2-strip-il-bodies-test branch from 427550e to c61119eCompareJuly 1, 2026 11:50
Adds an ILCompiler.ReadyToRun.Tests case that crossgen2-composites a small
runtime-async assembly with --strip-il-bodies and inspects the emitted
component MSIL to assert every branch of the strip decision, covering the
regression from dotnet#129813 fixed by dotnet#129884.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings July 1, 2026 11:52
@kotlarmilos
kotlarmilosforce-pushed the dev/crossgen2-strip-il-bodies-test branch from c61119e to 50c77f3CompareJuly 1, 2026 11:52

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

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new

@jakobbotschjakobbotsch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

…enceEqual
The untyped [0x14, 0x7A] collection expression prevented the
MemoryExtensions.SequenceEqual<byte> overload from binding, causing the
CLR_Tools_Tests leg to fail to compile.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kotlarmilos

Copy link
Copy Markdown
MemberAuthor

ILCompiler.ReadyToRun.Tests.TestCases.R2RTestSuites.RuntimeAsyncStripILBodiesPreservesTaskReturningIL - Passed

@kotlarmilos
kotlarmilos merged commit aeac9fb into dotnet:mainJul 2, 2026
111 checks passed
kotlarmilos added a commit to kotlarmilos/runtime that referenced this pull request Jul 2, 2026
… 0x24 stub
PR dotnet#130025 changes the crossgen2 --strip-il-bodies stub from ldnull; throw
(0x14 0x7A) to an invalid opcode (0xFE 0x24). Update the regression test
added in PR dotnet#130075 to check for the new sentinel bytes.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-milestone-botdotnet-milestone-botBot added this to the 11.0-preview7 milestone Jul 3, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
## Description
The `--strip-il-bodies` optimization in crossgen2 is applied when
building the composite ReadyToRun images that ship in the Apple mobile
runtime packs, and in #129813 it regressed by stripping the IL of
non-async `Task`/`ValueTask`-returning methods. That IL is still needed,
because with runtime-async enabled the runtime compiles a runtime-async
variant of such a method from its IL, so replacing it with a `ldnull`
throw stub threw `NullReferenceException` on the mobile packs until
#129884 narrowed the pass via `MayNeedILAtRuntime`.
This PR adds a deterministic `ILCompiler.ReadyToRun.Tests` tests that
inspect the emitted component MSIL to assert every branch of the strip
logic. Non-async `Task<T>`/`ValueTask<T>`/`Task`/`ValueTask`-returning
methods, a generic method, and a method on a generic type keep their IL,
while plain methods and async `Task<T>`/`ValueTask` methods are still
stripped.
TODO: This PR should be aligned with
#130025
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Aug 3, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-crossgen2-coreclronly use for closed issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@kotlarmilos@jakobbotsch