Skip to content
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

Add RuntimeAsyncMethodGenerationAttribute #77543

Merged
merged 5 commits into from
Mar 19, 2025

Conversation

333fred
Copy link
Member

@333fred 333fred commented Mar 11, 2025

Adds control for whether to use runtime async. The flowchart is as follows:

  1. The flag System.Runtime.CompilerServices.RuntimeFeature.Async must be present.
  2. Assuming that flag is present, we look for the presence of System.Runtime.CompilerServices.RuntimeAsyncMethodGenerationAttribute on the method. If that attribute is present, we use the preference expressed in the attribute. The preference does not carry to nested contexts, such as local functions or lambdas.
  3. If the attribute is not present, we look for features:runtime-async=on on the command line. If that is present, then the feature is on by default. Otherwise, the feature is off.

Relates to test plan #75960

Adds control for whether to use runtime async. The flowchart is as follows:

1. The flag `System.Runtime.CompilerServices.RuntimeFeature.Async` must be present.
2. Assuming that flag is present, we look for the presence of `System.Runtime.CompilerServices.RuntimeAsyncMethodGenerationAttribute` on the method. If that attribute is present, we use the preference expressed in the attribute. The preference does not carry to nested contexts, such as local functions or lambdas.
3. If the attribute is not present, we look for `features:runtime-async=on` on the command line. If that is present, then the feature is on by default. Otherwise, the feature is off.
@333fred 333fred requested a review from a team as a code owner March 11, 2025 22:02
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 11, 2025
@jcouv jcouv self-assigned this Mar 11, 2025
@333fred
Copy link
Member Author

333fred commented Mar 13, 2025

@jcouv @RikkiGibson for reviews please.

@jcouv
Copy link
Member

jcouv commented Mar 18, 2025

        if (!Assembly.RuntimeSupportsAsyncMethods)

Just to confirm, my understanding is that the flag will be present in .NET 10, but marked with [Experimental]. Is that correct?


Refers to: src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs:323 in cd76c3b. [](commit_id = cd76c3b, deletion_comment = False)

@333fred
Copy link
Member Author

333fred commented Mar 18, 2025

Just to confirm, my understanding is that the flag will be present in .NET 10, but marked with [Experimental]. Is that correct?

That's my understanding as well. Also RequiresPreviewFeatures.

SourceMethodSymbol { IsRuntimeAsyncEnabledInMethod: ThreeState.True } => true,
SourceMethodSymbol { IsRuntimeAsyncEnabledInMethod: ThreeState.False } => false,
_ => Feature("runtime-async") == "on"
};
Copy link
Member

Choose a reason for hiding this comment

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

Let's update the compiler spec for how those three flags (runtime feature flag, compiler feature flag, method-level attribute) work together

Copy link
Member Author

Choose a reason for hiding this comment

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

Will update in main after this PR.

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 (iteration 3). Tests not looked at yet

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 (iteration 4)

@333fred 333fred enabled auto-merge (squash) March 19, 2025 18:29
@333fred 333fred merged commit f372b6e into dotnet:features/runtime-async Mar 19, 2025
24 checks passed
@333fred 333fred deleted the feature-control branch March 19, 2025 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Runtime Async untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants