Skip to content

[Suggestion] Rename AsyncMethodKind.TaskReturning #119565

Closed

Description

@noahfalk

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.

Activity

  1. added
    needs-area-label
    on Sep 11, 2025
  2. added
    untriaged
    on Sep 11, 2025
  3. jakobbotsch commented on Sep 11, 2025

    @jakobbotsch
    Member

    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.

  4. added and removed
    needs-area-label
    on Sep 11, 2025
  5. VSadov commented on Sep 11, 2025

    @VSadov
    Member

    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.

  6. VSadov commented on Sep 11, 2025

    @VSadov
    Member

    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.

  7. noahfalk commented on Sep 12, 2025

    @noahfalk
    MemberAuthor

    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 "TaskReturning" as used in the method name feels intuitive. Its what I would guess the term meant if I saw it in a comment or a document and thats the one I'd recommend we keep.

    If folks don't like CompilerAsync I'd have no qualms calling it anything else. CompileAsync was just the first thought that came to mind.

  8. removed
    untriaged
    on Sep 15, 2025
  9. added this to the 11.0.0 milestone on Sep 15, 2025
  10. added
    untriaged
    on Sep 19, 2025
  11. removed
    untriaged
    on Sep 19, 2025
  12. VSadov commented on Nov 14, 2025

    @VSadov
    Member

    I think the root cause for the confusion is that this is one place where we touch two kinds of "async". Most of the runtime deals only with the kind of async where a method is called via async calling convention. This enum also needs to distinguish task-returning methods that are marked with MethodImpl.Async in metadata.

    From the runtime point of view the definitions are not by themselves async methods (in runtime meaning of "async"). In either case a method that returns a Task will result in a pair of task-returning and async callconv methods. What the IL async marker changes is how the IL is used to emit the bodies.

    I propose renaming the enum members to:

    enum AsyncMethodKind
    {
      Ordinary              // was NotAsync
      TaskReturning         // not changed
      TaskReturningILAsync  // was RuntimeAsync
      
    // not changed
      AsyncVariantImpl
      AsyncVariantThunk
      AsyncExplicitImpl
    }

    Everything that starts with Async is an async method in terms of "runtime async" - called with async callconv.

    Does this make things less confusing?

  13. VSadov commented on Nov 14, 2025

    @VSadov
    Member

    I think the above makes it incrementally better. Let's do it:

    • Rename AsyncMethodKind::NotAsync to AsyncMethodKind::Ordinary
    • Rename AsyncMethodKind::RuntimeAsync to AsyncMethodKind::TaskReturningILAsync
    • Update corresponding comments
  14. assigned and unassigned on Nov 14, 2025
  15. noahfalk commented on Nov 15, 2025

    @noahfalk
    MemberAuthor

    Thanks, I appreciate you thinking about it @VSadov. Maybe I'm still not doing a good job of describing it though.

    If anyone says "TaskReturning" right now then the reader/listener has to search for extra contextual clues to figure out whether they mean it in the MethodDesc::IsTaskReturningMethod() sense which includes RuntimeAsync or do they mean it in the AsyncMethodKind.TaskReturning sense which does not include RuntimeAsync. I think the best way to resolve that ambiguity is if "AsyncMethodKind.TaskReturning" changes its name, at least a little bit.

    For example I think this adjustment could work:

    Ordinary // was NotAsync
    TaskReturningUserIL // was TaskReturning
    TaskReturningStub // was RuntimeAsync

    // not changed
    AsyncVariantImpl
    AsyncVariantThunk
    AsyncExplicitImpl

    I'm not particular about those names. I think any name that isn't "AsyncMethodKind.TaskReturning" could work.

  16. added a commit that references this issue on Nov 27, 2025
    8c2b75f
  17. locked and limited conversation to collaborators on Dec 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions