Skip to content

Add support for HandleAsyncEntryPoint API in async Main code generation#80939

Merged
333fred merged 13 commits intomainfrom
copilot/update-async-main-code-generation
Nov 7, 2025
Merged

Add support for HandleAsyncEntryPoint API in async Main code generation#80939
333fred merged 13 commits intomainfrom
copilot/update-async-main-code-generation

Conversation

Copy link
Contributor

Copilot AI commented Oct 28, 2025

  • Understand the current async Main code generation
  • Add new SpecialMember entries for HandleAsyncEntryPoint methods
  • Update SpecialMembers.cs with method descriptors
  • Modify AsyncForwardEntryPoint to use new APIs when available
  • Create tests with minimal corelib that includes the new APIs
  • Refactor per code review feedback
    • Use Binder.TryGetSpecialTypeMember with isOptional: true
    • Compute entry point call in constructor (rename to _userEntryPointCall)
    • Create minimal corelib for tests and verify IL
    • Extract shared minimal corelib constant
    • Use MakeMemberMissing for fallback tests
    • Add fallback tests for both void and int mains
    • Fix formatting and update AllSpecialTypeMembers tests

Test Status:

  • AsyncMainWithHandleAsyncEntryPoint_Task: ✅ PASS
  • AsyncMainWithHandleAsyncEntryPoint_TaskOfInt: ✅ PASS
  • AsyncMainFallbackToOldPattern_Task: ✅ PASS
  • AsyncMainFallbackToOldPattern_TaskOfInt: ✅ PASS
  • AllSpecialTypeMembers (C#): ✅ PASS
  • AllSpecialTypeMembers (VB): ✅ PASS
  • All 59 existing async Main tests: ✅ PASS
Original prompt

This section details on the original issue you should resolve

<issue_title>Update async Main code generation</issue_title>
<issue_description>dotnet/runtime#121046 proposes a new api for async Main methods to allow WASM to understand the entry point correctly. If approved, we will want to react and update the codegen for our stub entrypoint methods in the case the user uses async Main:

static async void Main() { }

// Generated stub will now be:
static void <Main>(string[] args) => AsyncHelpers.ExecuteAsyncEntryPoint(Main(args));
```</issue_description>

<agent_instructions>The runtime finalized the API names as:
```cs
namespace System.Runtime.CompilerServices;

[EditorBrowsable(EditorBrowsableState.Never)]
public static partial class AsyncHelpers
{
    public static void HandleAsyncEntryPoint(Task task);
    public static int HandleAsyncEntryPoint(Task<int> task);
}

Implement this change by adding the apis to SpecialMember, and updating the code generation for the async entrypoint code to call those APIs if, and only if, they exist at runtime. In order to write a unit test for this, you will need to define a minimal corelib as a string and add these APIs to it.</agent_instructions>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits October 28, 2025 18:56
…generation

Co-authored-by: 333fred <2371880+333fred@users.noreply.github.com>
…ixes)

Co-authored-by: 333fred <2371880+333fred@users.noreply.github.com>
Co-authored-by: 333fred <2371880+333fred@users.noreply.github.com>
Copilot AI changed the title [WIP] Update async Main code generation for WASM compatibility Add support for HandleAsyncEntryPoint API in async Main code generation Oct 28, 2025
Copilot AI requested a review from 333fred October 28, 2025 19:24
…back

- Use Binder.TryGetSpecialTypeMember with isOptional: true
- Simplify CreateBody by computing entry point call in constructor
- Create minimal corelib tests that verify IL generation
- All existing tests pass, 2 of 3 new tests pass

Co-authored-by: 333fred <2371880+333fred@users.noreply.github.com>
Copilot AI requested a review from 333fred October 29, 2025 21:32
… tests

- Created MinimalAsyncCorelibWithAsyncHelpers constant with both HandleAsyncEntryPoint methods
- Updated all tests to use the shared corelib
- Used MakeMemberMissing to test fallback scenarios instead of separate corelib
- Added fallback tests for both Task and Task<int>
- All 4 new tests pass, all 63 async Main tests pass

Co-authored-by: 333fred <2371880+333fred@users.noreply.github.com>
Copilot AI requested a review from 333fred October 29, 2025 21:47
@333fred 333fred marked this pull request as ready for review October 29, 2025 21:57
@333fred 333fred requested a review from a team as a code owner October 29, 2025 21:57
@333fred
Copy link
Member

333fred commented Oct 29, 2025

@dotnet/roslyn-compiler for review

@333fred
Copy link
Member

333fred commented Oct 29, 2025

@copilot you need to fix your formatting, check by running ./build.sh --runAnalyzers. You also need to update both AllSpecialTypeMembers tests.

- Fixed whitespace formatting in CodeGenAsyncMainTests.cs
- Added HandleAsyncEntryPoint members to C# AllSpecialTypeMembers test
- Added HandleAsyncEntryPoint members to VB AllSpecialTypeMembers test
- All tests pass

Co-authored-by: 333fred <2371880+333fred@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 29, 2025

@copilot you need to fix your formatting, check by running ./build.sh --runAnalyzers. You also need to update both AllSpecialTypeMembers tests.

Fixed in commit 98c7207:

  • Fixed whitespace formatting in CodeGenAsyncMainTests.cs
  • Updated C# AllSpecialTypeMembers test to include new HandleAsyncEntryPoint members
  • Updated VB AllSpecialTypeMembers test to include new HandleAsyncEntryPoint members
  • All tests pass

Copilot AI requested a review from 333fred October 29, 2025 22:40
@333fred
Copy link
Member

333fred commented Nov 7, 2025

@AlekseyTs @jjonescz for another look please

System_Runtime_CompilerServices_AsyncHelpers__AwaitAwaiter_TAwaiter,
System_Runtime_CompilerServices_AsyncHelpers__UnsafeAwaitAwaiter_TAwaiter,
System_Runtime_CompilerServices_AsyncHelpers__HandleAsyncEntryPoint_Task,
System_Runtime_CompilerServices_AsyncHelpers__HandleAsyncEntryPoint_Task_Int32,
Copy link
Member

Choose a reason for hiding this comment

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

Question not related to this code location:
The "async Main" feature spec included details about codegen: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-7.1/async-main.md
Do we need a corresponding spec change for this work? Should LDM be made aware?

Copy link
Member

Choose a reason for hiding this comment

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

Well, the spec uses the works "equivalent of" for the codegen. These are the equivalent of that, so IMO that's enough weasel-wording for the implementation. I can send an email to LDM if you feel strongly though.

Copy link
Member

Choose a reason for hiding this comment

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

I'd at least at link to the new design from the async-main spec

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Done with review pass (commit 11)

@jcouv jcouv self-assigned this Nov 7, 2025
@AlekseyTs
Copy link
Contributor

AlekseyTs commented Nov 7, 2025

Done with review pass (commit 11) #Closed

@333fred
Copy link
Member

333fred commented Nov 7, 2025

@AlekseyTs @jjonescz for another review please

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 12), assuming CI is passing

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (commit 13)

@333fred 333fred enabled auto-merge (squash) November 7, 2025 22:26
@333fred 333fred merged commit 5138002 into main Nov 7, 2025
24 of 25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Nov 7, 2025
@333fred 333fred deleted the copilot/update-async-main-code-generation branch November 7, 2025 23:04
@davidwengier davidwengier modified the milestones: Next, 18.3 Jan 6, 2026
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.

Update async Main code generation

6 participants