Skip to content

Conversation

@jtschuster
Copy link
Member

Previously, AsyncMethodDesc was used to represent the Async variant of a method with IsAsync==true, regardless of what was in metadata. I think it makes more sense to use EcmaMethod to represent what is in metadata, and create two MethodDescs to represent the Async and Task-returning thunk variants.

  • EcmaMethod represents the variant encoded in metadata, either async or Task-returning. The Signature is adjusted accordingly to align with the calling convention (Task/Task return becomes void/T, and AsyncCallConv flag is set).
  • AsyncMethodDesc is replaced with AsyncMethodThunk, which is the Async variant thunk of a Task-returning implementation method.
  • TaskReturningAsyncThunk is the variant of an async implementation method
  • AsyncMethodData is a concept borrowed from the runtime implementation and was added to MethodDesc. For performance, it may make sense to move the Kind to MethodFlags and keep the async signature in a separate field, but I opted to keep it similar to the runtime.
  • IsTaskReturning is now on MethodDesc and uses the AsyncMethodData to determine whether the type returns Task/ValueTask. It has different semantics than the runtime method of the same name, as this returns true for Async methods too.
  • MethodSignature.ReturnsTaskOrValueTask() is added to determine if a method is AsyncMethodKind.TaskReturning.
  • GetAsyncOtherVariant() is also borrowed from the runtime implementation. This makes the AsyncMethodDescFactory unnecessary, as the single "other variant" can be retrieved from each impl variant without creating a new instance each time. This is implemented on EcmaMethod and all Instantiated methods, as well as the new AsyncMethodThunk and TaskReturningAsyncThunk.

…sc classes

- EcmaMethod represents the variant encoded in metadata, either async or Task-returning. The Signature is adjusted accordingly to align with the calling convention.
- AsyncMethodDesc is replaced with AsyncMethodThunk, which is the Async variant thunk of a Task-returning implementation method.
- TaskReturningAsyncThunk is the variant of an async implementation method
- AsyncMethodData was borrowed from the runtime implementation and added to the managedTypeSystem.
- IsTaskReturning is now on MethodDesc and uses the AsyncMethodData to determine whether the type returns Task/ValueTask. It has different semantics than the runtime method of the same name, as this returns true for Async methods too.
- GetAsyncOtherVariant() is also borrowed from the runtime implementation. This makes the factory unnecessary, as the unique "other variant" can be retrieved from the definition without creating a new instance each time.
Copy link
Contributor

Copilot AI left a comment

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 handling infrastructure in the CoreCLR AOT compiler's type system. It moves async method variant management from the JIT interface layer into the core type system, making async method thunks first-class citizens with proper lifetimes.

Key changes:

  • Moved async method thunk creation from JitInterface to the core type system with new AsyncMethodThunk and TaskReturningAsyncThunk classes
  • Introduced AsyncMethodData and AsyncMethodKind to track method async characteristics and signatures
  • Updated EcmaMethod, MethodForInstantiatedType, and InstantiatedMethod to support async variant tracking

Reviewed Changes

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

Show a summary per file
File Description
ILCompiler.TypeSystem.csproj Adds new async thunk source files to the project
ILCompiler.ReadyToRun.csproj Removes old JitInterface async method files
EcmaMethod.cs Adds async method data tracking and variant generation, reformats constants
TaskReturningAsyncThunk.cs New thunk class for async-callable variants of Task-returning methods
MethodForInstantiatedType.cs Adds async variant support for instantiated type methods
MethodDesc.cs Adds core async infrastructure: ReturnsTaskOrValueTask(), CreateAsyncSignature(), AsyncMethodData, AsyncMethodKind, GetAsyncOtherVariant()
MethodDelegator.cs Makes AsyncMethodData abstract for delegator implementations
InstantiatedMethod.cs Adds async variant support for generic method instantiations
AsyncMethodThunk.cs New thunk class for async variants of Task-returning methods
AsyncMethodDescFactory.cs Deleted - factory no longer needed with new approach
AsyncMethodDesc.cs Deleted - replaced by new thunk classes in type system

@jtschuster jtschuster requested a review from Copilot October 30, 2025 22:39
Copy link
Contributor

Copilot AI left a comment

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 11 out of 11 changed files in this pull request and generated 2 comments.

@jtschuster jtschuster requested a review from Copilot October 31, 2025 00:03
Copy link
Contributor

Copilot AI left a comment

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 23 out of 23 changed files in this pull request and generated 1 comment.

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

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

Missing using System.Threading; directive. The code uses Interlocked.CompareExchange on line 46 but doesn't import the System.Threading namespace. While the main InstantiatedMethod.cs file has this import, partial class files need their own using directives for the types they reference.

Suggested change
using System.Diagnostics;
using System.Diagnostics;
using System.Threading;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant