dotnet/roslyn

EnC: disallow editing async methods with incompatible constraints on their method builders

Offen

#51.234 geöffnet am 15.02.2021

 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (4.257 Forks)batch import
Area-InteractiveConcept-Continuous ImprovementInteractive-EnChelp wanted

Repository-Metriken

Stars
 (20.414 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (256 gemergte PRs in 30 T)

Beschreibung

Follow up on discussion: https://github.com/dotnet/roslyn/discussions/51189

In debug builds we emit async state machine types as classes so that we can add fields to them as needed during EnC. Emitting the state machine type as reference type instead of a value type might however conflict with a constraint:

If

  1. the return type of an async method specifies a custom builder B via AsyncMethodBuilder, and
  2. B.Start<TStateMachine>(ref TStateMachine), B.AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine), or B.AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) have a constraint on TStateMachine that disallows it to be a reference type.

Fix: The compiler should identify these cases and keep the state machine type as struct. The IDE should disallow editing such async methods.

Contributor Guide