Skip to content

Add RuntimeHelpers.IsRuntimeAsync intrinsic - #130899

Merged
jakobbotsch merged 5 commits into
dotnet:mainfrom
jakobbotsch:is-runtime-async-intrinsic
Jul 17, 2026
Merged

Add RuntimeHelpers.IsRuntimeAsync intrinsic#130899
jakobbotsch merged 5 commits into
dotnet:mainfrom
jakobbotsch:is-runtime-async-intrinsic

Conversation

@jakobbotsch

Copy link
Copy Markdown
Member

The interpreter and JIT fold this intrinsic to a constant based on whether the calling function is runtime async.

The motivation is cases like #130872 and #130689 where there is a worry about potentially regressing async1 callers, especially for .NET 11 where runtime async is opt-in in Roslyn.

The interpreter and JIT fold this intrinsic to a constant based on
whether the calling function is runtime async.
CopilotAI review requested due to automatic review settings July 16, 2026 18:02
@github-actionsgithub-actionsBot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 16, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
10 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: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

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

This PR introduces a new RuntimeHelpers.IsRuntimeAsync() intrinsic in System.Private.CoreLib, and wires it up so both the CoreCLR JIT and the CoreCLR interpreter fold it to a compile-time constant based on whether the current compilation is for an async-calling-convention method (runtime-async).

Changes:

  • Add RuntimeHelpers.IsRuntimeAsync() as an [Intrinsic] internal API stub in CoreLib.
  • Extend CoreCLR JIT named-intrinsic plumbing to recognize the method and expand it to true / false during import based on compIsAsync().
  • Extend CoreCLR interpreter named-intrinsic plumbing to recognize and constant-fold the method based on sig.isAsyncCall().

Reviewed changes

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

Show a summary per file
FileDescription
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.csAdds the new internal [Intrinsic] method stub IsRuntimeAsync().
src/coreclr/jit/namedintrinsiclist.hAdds a new NamedIntrinsic enum value for RuntimeHelpers.IsRuntimeAsync.
src/coreclr/jit/importercalls.cppRecognizes and expands the intrinsic during import to a constant using compIsAsync().
src/coreclr/jit/fgbasic.cppMarks the intrinsic as foldable during IL stack simulation for jump target discovery.
src/coreclr/interpreter/intrinsics.cppMaps RuntimeHelpers.IsRuntimeAsync to the new NamedIntrinsic.
src/coreclr/interpreter/compiler.cppExpands the intrinsic to an ldc.i4 constant based on isAsyncCall(), and treats it as “must expand” for interpretation.

CopilotAI review requested due to automatic review settings July 16, 2026 18:27
@jakobbotsch

Copy link
Copy Markdown
MemberAuthor

@EgorBot -intel -amd -arm --envvars DOTNET_JitDisasm:ReadLineAsync

usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Text;usingSystem.Threading.Tasks;usingBenchmarkDotNet.Attributes;publicclassStreamReaderReadLineTests{privatestring_text;privatebyte[]_bytes;[ParamsSource(nameof(GetLineLengthRanges))]publicRangeLineLengthRange{get;set;}publicstaticIEnumerable<Range>GetLineLengthRanges(){yieldreturnnewRange(){Min=0,Max=0};yieldreturnnewRange(){Min=1,Max=1};yieldreturnnewRange(){Min=1,Max=8};yieldreturnnewRange(){Min=9,Max=32};yieldreturnnewRange(){Min=33,Max=128};yieldreturnnewRange(){Min=129,Max=1024};yieldreturnnewRange(){Min=1025,Max=2048};yieldreturnnewRange(){Min=0,Max=1024};}publicclassRange{publicintMin{get;set;}publicintMax{get;set;}publicoverridestringToString()=>$"[{Min,4}, {Max,4}]";}[GlobalSetup]publicvoidGlobalSetup(){_text=GenerateLinesText(LineLengthRange,16*1024);_bytes=Encoding.UTF8.GetBytes(_text);}[Benchmark]publicasyncTaskReadLineAsync(){using(StreamReaderreader=newStreamReader(newMemoryStream(_bytes))){while(awaitreader.ReadLineAsync()!=null);}}privatestaticstringGenerateLinesText(RangelineLengthRange,inttextTargetLength){intmin=lineLengthRange.Min;intmax=lineLengthRange.Max;stringnewLine=Environment.NewLine;varsb=newStringBuilder(textTargetLength+max+newLine.Length);varrandom=newRandom(42);while(sb.Length<textTargetLength){intcharsCount=random.Next(min,max);for(intc=0;c<charsCount;c++)sb.Append((char)random.Next('0','z'));sb.Append(newLine);}returnsb.ToString();}}

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/StreamReader.cs Outdated
Comment threadsrc/coreclr/jit/importercalls.cpp Outdated
CopilotAI review requested due to automatic review settings July 16, 2026 21:34
@jakobbotsch
jakobbotsch marked this pull request as ready for review July 16, 2026 21:36
@azure-pipelines

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

@jakobbotsch

Copy link
Copy Markdown
MemberAuthor

cc @dotnet/jit-contrib PTAL @EgorBo@BrzVlad

Reverted the StreamReader change, I will fold it into #130689 instead, I was just checking that the intrinsic worked.

@jakobbotsch
jakobbotsch requested a review from EgorBoJuly 16, 2026 21:40

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment threadsrc/coreclr/jit/importercalls.cpp
@tannergooding

Copy link
Copy Markdown
Member

Is this something we're going to consider making public longer term, or is it one of the internal-only APIs? -- Mostly wondering if I need to be tracking something for api-review, not asking for it to be or not.

CopilotAI review requested due to automatic review settings July 16, 2026 22:03
@jakobbotsch

Copy link
Copy Markdown
MemberAuthor

Is this something we're going to consider making public longer term, or is it one of the internal-only APIs? -- Mostly wondering if I need to be tracking something for api-review, not asking for it to be or not.

I'm not sure yet. I think if everything was runtime async by default we would not need it. I think time will tell how often we end up needing this.

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

CopilotAI review requested due to automatic review settings July 16, 2026 22:16

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@jakobbotsch

Copy link
Copy Markdown
MemberAuthor

/ba-g Timeouts

@jakobbotsch
jakobbotsch merged commit 5a5020c into dotnet:mainJul 17, 2026
167 of 178 checks passed
@jakobbotsch
jakobbotsch deleted the is-runtime-async-intrinsic branch July 17, 2026 14:21
@dotnet-milestone-botdotnet-milestone-botBot added this to the 11.0-preview7 milestone Jul 18, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIruntime-async

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@jakobbotsch@tannergooding@EgorBo