- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.2k
Use EcmaMethod as the async "impl" variant and create async "thunk" MethodDesc classes #121218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            jtschuster
  wants to merge
  6
  commits into
  dotnet:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
jtschuster:AsyncThunkMethodDescs
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +748
        
        
          −174
        
        
          
        
      
    
  
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      27bef54
              
                Use EcmaMethod as the async Impl variant, create async thunk MethodDe…
              
              
                jtschuster f54a832
              
                Implement GetAsyncOtherVariant on instantiated methods
              
              
                jtschuster f072d09
              
                Formatting and cleanup
              
              
                jtschuster 3ff1a3c
              
                Copilot review feedback. ILVerify still fails
              
              
                jtschuster f22ed2d
              
                Separate methods into sorting, diagnostic, canon, and async source files
              
              
                jtschuster c4523a0
              
                Add InstantiatedMethod.Async.cs to TypeSystem project
              
              
                jtschuster File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
  
    
      
          
            109 changes: 0 additions & 109 deletions
          
          109 
        
  src/coreclr/tools/Common/JitInterface/AsyncMethodDesc.cs
  
  
      
      
   
        
      
      
    This file was deleted.
      
      Oops, something went wrong.
      
    
  
        
          
  
    
      
          
            24 changes: 0 additions & 24 deletions
          
          24 
        
  src/coreclr/tools/Common/JitInterface/AsyncMethodDescFactory.cs
  
  
      
      
   
        
      
      
    This file was deleted.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            16 changes: 16 additions & 0 deletions
          
          16 
        
  src/coreclr/tools/Common/TypeSystem/Canon/AsyncMethodThunk.Canon.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|  | ||
| namespace Internal.TypeSystem | ||
| { | ||
| /// <summary> | ||
| /// Represents the async-callable (CORINFO_CALLCONV_ASYNCCALL) variant of a Task/ValueTask returning method. | ||
| /// </summary> | ||
| public sealed partial class AsyncMethodThunk : MethodDelegator | ||
| { | ||
| public override MethodDesc GetCanonMethodTarget(CanonicalFormKind kind) | ||
| { | ||
| return _wrappedMethod.GetCanonMethodTarget(kind).GetAsyncOtherVariant(); | ||
| } | ||
| } | ||
| } | 
        
          
  
    
      
          
            16 changes: 16 additions & 0 deletions
          
          16 
        
  src/coreclr/tools/Common/TypeSystem/Canon/TaskReturningAsyncThunk.Canon.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|  | ||
| namespace Internal.TypeSystem | ||
| { | ||
| /// <summary> | ||
| /// Represents the Task-returning variant of an async call convention method. | ||
| /// </summary> | ||
| public sealed partial class TaskReturningAsyncThunk : MethodDelegator | ||
| { | ||
| public override MethodDesc GetCanonMethodTarget(CanonicalFormKind kind) | ||
| { | ||
| return _wrappedMethod.GetCanonMethodTarget(kind).GetAsyncOtherVariant(); | ||
| } | ||
| } | ||
| } | 
        
          
  
    
      
          
            21 changes: 21 additions & 0 deletions
          
          21 
        
  src/coreclr/tools/Common/TypeSystem/Common/AsyncMethodThunk.Diagnostic.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // 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; | ||
|  | ||
| namespace Internal.TypeSystem | ||
| { | ||
| /// <summary> | ||
| /// Represents the async-callable (CORINFO_CALLCONV_ASYNCCALL) variant of a Task/ValueTask returning method. | ||
| /// </summary> | ||
| public sealed partial class AsyncMethodThunk : MethodDelegator | ||
| { | ||
| public override string DiagnosticName | ||
| { | ||
| get | ||
| { | ||
| return "Async thunk: " + _wrappedMethod.DiagnosticName; | ||
| } | ||
| } | ||
| } | ||
| } | 
        
          
  
    
      
          
            69 changes: 69 additions & 0 deletions
          
          69 
        
  src/coreclr/tools/Common/TypeSystem/Common/AsyncMethodThunk.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // 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; | ||
|  | ||
| namespace Internal.TypeSystem | ||
| { | ||
| /// <summary> | ||
| /// Represents the async-callable (CORINFO_CALLCONV_ASYNCCALL) variant of a Task/ValueTask returning method. | ||
| /// </summary> | ||
| public sealed partial class AsyncMethodThunk : MethodDelegator | ||
| { | ||
| private readonly AsyncMethodData _asyncMethodData; | ||
|  | ||
| public AsyncMethodThunk(MethodDesc wrappedMethod) | ||
| : base(wrappedMethod) | ||
| { | ||
| Debug.Assert(wrappedMethod.IsTaskReturning); | ||
| Debug.Assert(!wrappedMethod.IsAsync); | ||
| _asyncMethodData = new AsyncMethodData() | ||
| { | ||
| Kind = AsyncMethodKind.AsyncVariantThunk, | ||
| Signature = _wrappedMethod.Signature.CreateAsyncSignature() | ||
| }; | ||
| } | ||
|  | ||
| public override AsyncMethodData AsyncMethodData | ||
| { | ||
| get | ||
| { | ||
| return _asyncMethodData; | ||
| } | ||
| } | ||
|  | ||
| public override MethodDesc GetMethodDefinition() | ||
| { | ||
| return _wrappedMethod.GetMethodDefinition(); | ||
| } | ||
|  | ||
| public override MethodDesc GetTypicalMethodDefinition() | ||
| { | ||
| return _wrappedMethod.GetTypicalMethodDefinition(); | ||
| } | ||
|  | ||
| public override MethodDesc GetAsyncOtherVariant() | ||
| { | ||
| return _wrappedMethod; | ||
| } | ||
|  | ||
| public override MethodDesc InstantiateSignature(Instantiation typeInstantiation, Instantiation methodInstantiation) | ||
| { | ||
| MethodDesc real = _wrappedMethod.InstantiateSignature(typeInstantiation, methodInstantiation); | ||
| return real.GetAsyncOtherVariant(); | ||
| } | ||
|  | ||
| public override MethodSignature Signature | ||
| { | ||
| get | ||
| { | ||
| return _asyncMethodData.Signature; | ||
| } | ||
| } | ||
|  | ||
| public override string ToString() | ||
| { | ||
| return "Async thunk: " + _wrappedMethod.ToString(); | ||
| } | ||
| } | ||
| } | 
        
          
  
    
      
          
            52 changes: 52 additions & 0 deletions
          
          52 
        
  src/coreclr/tools/Common/TypeSystem/Common/InstantiatedMethod.Async.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // 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; | ||
| using System.Threading; | ||
|  | ||
| namespace Internal.TypeSystem | ||
| { | ||
| public sealed partial class InstantiatedMethod | ||
| { | ||
| private AsyncMethodData _asyncMethodData; | ||
| private MethodDesc _asyncOtherVariant; | ||
|  | ||
| public override AsyncMethodData AsyncMethodData | ||
| { | ||
| get | ||
| { | ||
| if (!_asyncMethodData.Equals(default(AsyncMethodData))) | ||
| return _asyncMethodData; | ||
|  | ||
| if (IsAsync) | ||
| { | ||
| // If the method is already async, the template signature should already have been updated to reflect the AsyncCallConv | ||
| Debug.Assert(!Signature.ReturnsTaskOrValueTask() && Signature.IsAsyncCallConv); | ||
| _asyncMethodData = new AsyncMethodData() { Kind = AsyncMethodKind.AsyncVariantImpl, Signature = Signature }; | ||
| } | ||
| else if (Signature.ReturnsTaskOrValueTask()) | ||
| { | ||
| _asyncMethodData = new AsyncMethodData() { Kind = AsyncMethodKind.TaskReturning, Signature = Signature }; | ||
| } | ||
| else | ||
| { | ||
| _asyncMethodData = new AsyncMethodData() { Kind = AsyncMethodKind.NotAsync, Signature = Signature }; | ||
| } | ||
|  | ||
| return _asyncMethodData; | ||
| } | ||
| } | ||
|  | ||
| public override MethodDesc GetAsyncOtherVariant() | ||
| { | ||
| if (_asyncOtherVariant is null) | ||
| { | ||
| MethodDesc otherVariant = IsAsync ? | ||
| new TaskReturningAsyncThunk(this, InstantiateSignature(_methodDef.GetAsyncOtherVariant().Signature)) | ||
| : new AsyncMethodThunk(this); | ||
| Interlocked.CompareExchange(ref _asyncOtherVariant, otherVariant, null); | ||
| } | ||
| return _asyncOtherVariant; | ||
| } | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            15 changes: 15 additions & 0 deletions
          
          15 
        
  src/coreclr/tools/Common/TypeSystem/Common/MethodDelegator.Async.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|  | ||
| using System; | ||
|  | ||
| namespace Internal.TypeSystem | ||
| { | ||
| /// <summary> | ||
| /// Wraps a <see cref="MethodDesc"/> object and delegates methods to that <see cref="MethodDesc"/>. | ||
| /// </summary> | ||
| public abstract partial class MethodDelegator : MethodDesc | ||
| { | ||
| public abstract override AsyncMethodData AsyncMethodData { get; } | ||
| } | ||
| } | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
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 usesInterlocked.CompareExchangeon line 46 but doesn't import theSystem.Threadingnamespace. While the mainInstantiatedMethod.csfile has this import, partial class files need their own using directives for the types they reference.