Skip to content

Rename AsyncMethodKind enum values: NotAsync→Ordinary, RuntimeAsync→TaskReturningILAsync - #121649

Merged
VSadov merged 21 commits into
mainfrom
copilot/rename-asyncmethodkind-taskreturning
Nov 27, 2025
Merged

VSadov merged 21 commits into
mainfrom
copilot/rename-asyncmethodkind-taskreturning

Conversation

Copilot AI commented Nov 14, 2025 •

Copy link
Copy Markdown
Contributor

Rename AsyncMethodKind enum values

Based on VSadov's proposal in the issue discussion:

  • Verify baseline build (CoreCLR) passes
  • Rename AsyncMethodKind::NotAsync to AsyncMethodKind::Ordinary
  • Rename AsyncMethodKind::RuntimeAsync to AsyncMethodKind::TaskReturningILAsync
  • Convert enum to bitfield flags (AsyncMethodFlags)
  • Rename all kind variables/fields to flags for AsyncMethodFlags type
  • Rename hasAsyncKindFlags to hasAsyncFlags
  • Update comments to reflect new naming
  • Fix typo in comment (representaton → representation)
  • Rename parameter AsyncMethodFlags → asyncMethodFlags (per @jkotas suggestion)
  • Rename field m_AsyncMethodFlags → m_asyncMethodFlags (per @jkotas suggestion)
  • Build CoreCLR with the changes - PASSED

Latest changes:

  • Renamed parameter AsyncMethodFlags to asyncMethodFlags in bmtMDMethod constructor
  • Renamed field m_AsyncMethodFlags to m_asyncMethodFlags (camelCase)
Original prompt

This section details on the original issue you should resolve

<issue_title>[Suggestion] Rename AsyncMethodKind.TaskReturning</issue_title>
<issue_description>I got a bit confused by the naming and comments here

Hopefully I understand it correctly now, but if not please correct me. It appears we are using the term "Task Returning" to mean different things in different places:

AsyncMethodKind.TaskReturning - The MethodDesc variant whose entrypoint returns a task and it corresponds to a C# method not marked with the MethodImpl::Async attribute.
// Task-returning methods - Any C# method returning a Task regardless if it has the MethodImpl::Async attribute

I think if you renamed AsyncMethodKind.TaskReturning -> AsyncMethodKind.CompilerAsync it would remove the naming collision and it would also contrast nicely: RuntimeAsync vs CompilerAsync.
</issue_description>

<agent_instructions>Rename AsyncMethodKind::NotAsync to AsyncMethodKind::Ordinary
Rename AsyncMethodKind::RuntimeAsync to AsyncMethodKind::TaskReturningILAsync
Update corresponding comments</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@jakobbotsch > I think if you renamed AsyncMethodKind.TaskReturning -> AsyncMethodKind.CompilerAsync it would remove the naming collision and it would also contrast nicely: RuntimeAsync vs CompilerAsync.

Compiler async is quite confusing to me, since in the context of the runtime/VM the only compiler I see is the JIT/interpreter's compiler. But IIUC, here it would refer to something that originally produced the IL that we are seeing? Such a compiler doesn't even need to exist.

Originally these were the names:
https://github.com/dotnet/runtimelab/blame/d95f6eadeeb696071635d9662fbe33f8a0e0d645/src/coreclr/vm/method.hpp#L58-L64

I quite liked those names, but the enum grew and things changed so it wouldn't really map anymore.</comment_new>
<comment_new>@VSadov

AsyncMethodKind.TaskReturning - The MethodDesc variant whose entrypoint returns a task and it corresponds to a C# method marked with the MethodImpl::Async attribute.

No. AsyncMethodKind.TaskReturning is a method that returns Task, ValueTask or generic version of that and the method's definition in metadata is NOT marked as MethodImpl::Async

Basically, these methoddescs represent ordinary Task-returning methods. The IL may contain a state machine produced by C#/VB/?? or may contain whatever else code.

The IL for these methods is compiled as-is. To participate in runtime async such methods get paired with a thunk that has runtime-async calling convention.

I think TaskReturning is appropriate as the part that they return tasks is what makes them special, while NotAsync are not special at all. </comment_new>
<comment_new>@VSadov
Perhaps it is NotAsync that is confusing and should be called something else. NotAsync is for ordinary methods not interesting to runtime async in any way.
Ordinary could probably be a better name, but I think we have other classifications that use Ordinary so it may be confusing that these are also ordinary but in async sense.</comment_new>
<comment_new>@noahfalk

No. AsyncMethodKind.TaskReturning is a method that returns Task, ValueTask or generic version of that and the method's definition in metadata is NOT marked as MethodImpl::Async

Oops I had the right idea in my head but then still wrote the wrong text. I stink. I edited it in the original post so hopefully its correct now.

I think TaskReturning is appropriate as the part that they return tasks is what makes them special, while NotAsync are not special at all.

The key thing that I am suggesting we fix is that "TaskReturning" should have only one definition. I discovered this function which I think really exemplifies it:

    inline bool IsTaskReturningMethod() const
    {
        ...
        return asyncKind == AsyncMethodKind::RuntimeAsync ||
            asyncKind == AsyncMethodKind::TaskReturning;
    }

The meaning of "TaskReturning" in the method name isn't the same as the meaning of "TaskReturning" in the enum value. Right now AsyncMethodKind::RuntimeAsync is task-returning (IsTaskReturningMethod()==true) and also isn't task-returning (asyncKind != AsyncMethodKind::TaskReturning).

IMO ...


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 14, 2025
Copilot AI changed the title [WIP] Rename AsyncMethodKind.TaskReturning for clarity Rename AsyncMethodKind enum values: NotAsync→Ordinary, RuntimeAsync→TaskReturningILAsync Nov 14, 2025
Copilot AI requested a review from VSadov November 14, 2025 23:05
@VSadov VSadov added area-VM-coreclr runtime-async and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Nov 14, 2025
@VSadov

VSadov commented Nov 14, 2025 •

Copy link
Copy Markdown
Member

TODO: this may need to run CI with commits from #119420 - to see if everything works with async enabled.

Those commits would need to be reverted once we ready to merge. (we are not yet enabling async in the main)

@VSadov

VSadov commented Nov 14, 2025

Copy link
Copy Markdown
Member

CC: @jakobbotsch @agocke - mostly an FYI on renames.

@noahfalk

Copy link
Copy Markdown
Member

#119565 (comment)

Comment thread src/coreclr/vm/method.hpp Resolved
Comment thread src/coreclr/vm/method.hpp Resolved
Comment thread src/coreclr/inc/clrconfigvalues.h Resolved
Comment thread src/coreclr/vm/method.hpp Resolved
Comment thread src/coreclr/vm/jitinterface.cpp Resolved
Comment thread src/coreclr/vm/method.hpp Resolved
Comment thread src/coreclr/vm/method.hpp Resolved
Comment thread src/coreclr/vm/method.hpp Resolved
Comment thread src/coreclr/vm/methodtablebuilder.h Resolved
Comment thread src/coreclr/vm/method.hpp Resolved
Comment thread src/coreclr/vm/method.hpp Resolved

@jkotas jkotas 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.

LGTM otherwise.

@noahfalk ?

Comment thread src/coreclr/vm/asyncthunks.cpp Resolved
Comment thread src/coreclr/vm/asyncthunks.cpp Resolved
Comment thread src/coreclr/vm/jitinterface.cpp Resolved
Comment thread src/coreclr/vm/method.hpp Resolved

@jkotas jkotas 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.

LGTM

@VSadov
VSadov marked this pull request as ready for review November 26, 2025 22:45
Copilot AI review requested due to automatic review settings November 26, 2025 22:45
@VSadov
VSadov enabled auto-merge (squash) November 26, 2025 22:46
@VSadov

VSadov commented Nov 26, 2025

Copy link
Copy Markdown
Member

Thanks!

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

This PR refactors the async method representation in CoreCLR by converting the AsyncMethodKind enum to a bitfield-based AsyncMethodFlags system. The change improves clarity by using descriptive flag names (AsyncCall, ReturnsTaskOrValueTask, IsAsyncVariant, Thunk, None) instead of enum values that were confusing due to naming collisions (e.g., "TaskReturning" having different meanings in different contexts).

Key changes:

  • Converted enum to bitfield flags with operator overloads for flag manipulation
  • Renamed variables/fields from kind/m_asyncMethodKind to flags/m_asyncMethodFlags throughout the codebase
  • Introduced helper methods (GetAsyncVariant, GetAsyncVariantNoCreate) alongside existing GetAsyncOtherVariant
  • Updated method implementations to use flag checks (hasAsyncFlags) instead of enum equality
  • Fixed typo "varian" → "variant" in comment

Reviewed changes

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

Show a summary per file
File Description
src/coreclr/vm/method.hpp Defined AsyncMethodFlags bitfield enum with operators, added flag-checking helper function, updated method implementations to use flags, added new GetAsyncVariant methods, fixed comments
src/coreclr/vm/method.cpp Updated to use GetAsyncVariantNoCreate in ResetCodeEntryPointForEnC
src/coreclr/vm/methodtablebuilder.h Changed parameter/field types from AsyncMethodKind to AsyncMethodFlags, renamed variables to use flags naming
src/coreclr/vm/methodtablebuilder.cpp Updated method initialization to use flag combinations, improved comments explaining flag usage, changed flag assignments throughout
src/coreclr/vm/jitinterface.cpp Updated method calls from IsTaskReturningMethod/GetAsyncOtherVariant to ReturnsTaskOrValueTask/GetAsyncVariant
src/coreclr/vm/ilstubcache.cpp Changed flag assignment for async stubs from enum to bitfield
src/coreclr/vm/genericdict.cpp Updated method calls to use GetAsyncVariant
src/coreclr/vm/class.cpp Changed initialization from AsyncMethodKind::NotAsync to AsyncMethodFlags::None
src/coreclr/vm/asyncthunks.cpp Renamed parameters from pAsyncOtherVariant to pAsyncCallVariant/pTaskReturningVariant for clarity

Comment thread src/coreclr/vm/method.hpp Resolved
Comment thread src/coreclr/vm/method.hpp Resolved
Comment thread src/coreclr/vm/method.hpp Resolved
Comment thread src/coreclr/vm/method.hpp Resolved
@VSadov
VSadov merged commit 8c2b75f into main Nov 27, 2025
@VSadov
VSadov deleted the copilot/rename-asyncmethodkind-taskreturning branch November 27, 2025 03:25
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Suggestion] Rename AsyncMethodKind.TaskReturning

6 participants