Skip to content

Use prototype Roslyn compiler for runtime-async #115531

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

Merged
merged 6 commits into from
May 16, 2025

Conversation

agocke
Copy link
Member

@agocke agocke commented May 13, 2025

This pulls in the prototype Roslyn compiler from the Roslyn runtime-async prototype branch. Currently the feature in the runtime is gated on a feature flag, so the tests are disabled.

To run the tests locally, do the following:

  • Uncomment add_compile_definitions(FEATURE_RUNTIME_ASYNC) - to enable the feature in the product.
  • Remove DisableProjectBuild from src\tests\async\Directory.Build.targets

@Copilot Copilot AI review requested due to automatic review settings May 13, 2025 21:32
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 13, 2025
Copy link
Contributor

@Copilot 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 updates the codebase to use the new prototype Roslyn compiler's runtime-async implementation by replacing the deprecated "async2" keyword with the standard "async" keyword and adding runtime async method generation attributes where needed.

  • Replaces "async2" with "async" across multiple test files and implementations.
  • Adds [RuntimeAsyncMethodGeneration(false)] attributes to selected methods to control async state machine generation.
  • Updates project configuration files (Directory.Build.props, NuGet.config) and runtime feature definitions to support the new async feature.

Reviewed Changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/tests/async/pgo/pgo.cs Replaced async2 with async in entry point and aggregate methods.
src/tests/async/override/override.cs Updated method signatures in base and derived classes to use async; added generation attributes.
src/tests/async/objects-captured/objects-captured.cs Updated async method signatures.
src/tests/async/object/object.cs Replaced async2 with async in asynchronous entry and object methods.
src/tests/async/mincallcost-microbench/mincallcost-microbench.cs Multiple async2 methods replaced with async and attributes added where needed.
src/tests/async/implement/implement.cs Simplified interface and implementation method signatures to use async.
src/tests/async/gc-roots-scan/gc-roots-scan.cs Replaced async2 with async in recursive methods.
src/tests/async/fibonacci-without-yields/fibonacci-without-yields.cs Updated async method signatures in Fibonacci test.
src/tests/async/fibonacci-with-yields_struct_return/fibonacci-with-yields_struct_return.cs Updated async method signatures and return types.
src/tests/async/fibonacci-with-yields/fibonacci-with-yields.cs Replaced async2 with async in test and Fibonacci methods.
src/tests/async/eh-microbench/eh-microbench.cs Updated multiple async2 method signatures to async and added attributes to benchmarking methods.
src/tests/async/cse-array-index-byref/cse-array-index-byref.cs Updated async method signature for hoisted byref test.
src/tests/async/collectible-alc/collectible-alc.cs Replaced async2 with async in async entry points and helper methods.
src/tests/async/awaitingnotasync/awaitingnotasync.cs Updated async method signature for the async entry point.
src/tests/async/RuntimeAsyncMethodGenerationAttribute.cs Added the attribute definition for runtime async generation.
src/tests/async/Directory.Build.props Added the features flag for runtime-async and included the attribute file.
src/tests/Directory.Build.props Overrode the compiler version to one that supports async changes.
src/libraries/System.Runtime/ref/System.Runtime.cs Updated runtime feature to include Async.
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeFeature.cs Updated runtime feature support for Async with proper attribute handling.
NuGet.config Added a package source for prototype Roslyn compiler testing.

@am11 am11 added area-Infrastructure-libraries runtime-async and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels May 13, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

@agocke
Copy link
Member Author

agocke commented May 13, 2025

@VSadov any info on what I need to set to run tests locally?

@VSadov
Copy link
Member

VSadov commented May 14, 2025

@VSadov any info on what I need to set to run tests locally?

In #115499 (comment)
I used these steps:

* patch the toolset compiler - basically do `buildroslynnugets.bat` per runtimelab instructions and copy `tasks` 
from the `Microsoft.Net.Compilers.Toolset.5.0.0-async-16.nupkg` (rename to .zip and open) 
to `C:\Users\<user>\.nuget\packages\microsoft.net.compilers.toolset\5.0.0-1.25220.1`, or whatever version is in use by the build.
* uncomment `add_compile_definitions(FEATURE_RUNTIME_ASYNC)`  - to enable the feature in the product.
* delete `src\tests\async\Directory.Build.targets` - to unblock async tests from building.

Then build/run tests as usual. Tests under `async` should build, run and pass.

I think the part about patching the toolset compiler does not apply here. So it is really:

  • uncomment add_compile_definitions(FEATURE_RUNTIME_ASYNC) - to enable the feature in the product.
  • delete src\tests\async\Directory.Build.targets - to unblock async tests from building.

Then do regular:

  • build clr+libs -rc checked -lc release
  • src\tests\build.bat checked
  • src\tests\run.bat checked

@VSadov
Copy link
Member

VSadov commented May 14, 2025

from the failures it looks like it has built the tests successfully 👍, but runtime did not want to load them, because the feature is not enabled in the runtime - the step:
uncomment add_compile_definitions(FEATURE_RUNTIME_ASYNC) - to enable the feature in the product.

@agocke agocke force-pushed the use-prototype-compiler branch from 62739c5 to 03becbe Compare May 14, 2025 02:09
<PropertyGroup>
<!-- Override the compiler version with a private build that supports runtime-async -->
<MicrosoftNetCompilersToolsetVersion>5.0.0-1.25259.6</MicrosoftNetCompilersToolsetVersion>
</PropertyGroup>
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to have this in src/tests/Directory.Build.props instead of src/tests/async/Directory.Build.props?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this worked when I tried it earlier. Let me try again.

Copy link
Member

Choose a reason for hiding this comment

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

It needs to be here because we don't restore individual test projects (there's too many). Instead we restore the test_dependencies projects and point the individual test projects at those restore results.

One day I'll get this cleaned up I hope.

@agocke
Copy link
Member Author

agocke commented May 14, 2025

from the failures it looks like it has built the tests successfully 👍, but runtime did not want to load them, because the feature is not enabled in the runtime - the step: uncomment add_compile_definitions(FEATURE_RUNTIME_ASYNC) - to enable the feature in the product.

Yup, this worked, thanks. For now I've kept the tests disabled in PR since we don't want to enable the ifdef. But it looks like everything passes now except the EH test.

@agocke
Copy link
Member Author

agocke commented May 14, 2025

I believe this is all up-to-date now. This PR still keeps all the tests disabled since I'm not building the runtime with the if-def.

@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
<Features>$(Features);runtime-async</Features>
Copy link
Member

Choose a reason for hiding this comment

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

Why some .csproj need runtime-async=on and not others?

@jakobbotsch
Copy link
Member

it looks like everything passes now except the EH test

Any idea why this breaks the EH test?

@VSadov
Copy link
Member

VSadov commented May 15, 2025

it looks like everything passes now except the EH test

Any idea why this breaks the EH test?

There is a known issue with C# compiler.

@@ -24,7 +25,8 @@ public async Task<int> M1()

class Derived1a : IBase1
{
public async2 Task<int> M1()
[MethodImpl(MethodImplOptions.Async)]
Copy link
Member

Choose a reason for hiding this comment

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

Are these necessary?

Copy link
Member

@VSadov VSadov May 15, 2025

Choose a reason for hiding this comment

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

I think these were a workaround for the change in the numerical value for the async methodimpl, that C# compiler was not updated for.
I thought that has been fixed and the workaround is no longer necessary. Maybe this one was just missed when others were reverted.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, just missed during cleanup

@jakobbotsch
Copy link
Member

I pushed a change that also updates the test I added in #115605 to the new style.

@agocke agocke merged commit 0f0b4b4 into dotnet:main May 16, 2025
146 of 150 checks passed
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.

7 participants