Repository navigation
Rename AsyncMethodKind enum values: NotAsync→Ordinary, RuntimeAsync→TaskReturningILAsync - #121649
Conversation
|
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) |
|
CC: @jakobbotsch @agocke - mostly an FYI on renames. |
6fd26bf to
7f7870f
Compare
…>TaskReturningILAsync Co-authored-by: VSadov <[email protected]>
Co-authored-by: VSadov <[email protected]>
Co-authored-by: VSadov <[email protected]>
Co-authored-by: VSadov <[email protected]>
Co-authored-by: Jan Kotas <[email protected]>
Co-authored-by: Jan Kotas <[email protected]>
This reverts commit f5f41cf.
|
Thanks! |
There was a problem hiding this comment.
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_asyncMethodKindtoflags/m_asyncMethodFlagsthroughout the codebase - Introduced helper methods (
GetAsyncVariant,GetAsyncVariantNoCreate) alongside existingGetAsyncOtherVariant - 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 |
Co-authored-by: Copilot <[email protected]>
Rename AsyncMethodKind enum values
Based on VSadov's proposal in the issue discussion:
AsyncMethodKind::NotAsynctoAsyncMethodKind::OrdinaryAsyncMethodKind::RuntimeAsynctoAsyncMethodKind::TaskReturningILAsyncAsyncMethodFlags)kindvariables/fields toflagsforAsyncMethodFlagstypehasAsyncKindFlagstohasAsyncFlagsAsyncMethodFlags→asyncMethodFlags(per @jkotas suggestion)m_AsyncMethodFlags→m_asyncMethodFlags(per @jkotas suggestion)Latest changes:
AsyncMethodFlagstoasyncMethodFlagsin bmtMDMethod constructorm_AsyncMethodFlagstom_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
No.
AsyncMethodKind.TaskReturningis a method that returnsTask,ValueTaskor generic version of that and the method's definition in metadata is NOT marked asMethodImpl::AsyncBasically, 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
TaskReturningis appropriate as the part that they return tasks is what makes them special, whileNotAsyncare not special at all. </comment_new><comment_new>@VSadov
Perhaps it is
NotAsyncthat is confusing and should be called something else.NotAsyncis for ordinary methods not interesting to runtime async in any way.Ordinarycould probably be a better name, but I think we have other classifications that useOrdinaryso it may be confusing that these are also ordinary but in async sense.</comment_new><comment_new>@noahfalk
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.
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:
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.