Skip to content

Refine async state machine heuristics, add ConfiguredValueTaskAwaitable #710

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 1 commit into from
Jan 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/coverlet.core/Symbols/CecilSymbolHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ More tha one branch

so we know that current branch are checking that field and we're not interested in.
*/
if (isAsyncStateMachineMoveNext && isRecognizedMoveNextInsideAsyncStateMachineProlog)
if (isRecognizedMoveNextInsideAsyncStateMachineProlog)
{
bool skipInstruction = false;
Instruction current = instruction.Previous;
Expand All @@ -171,16 +171,18 @@ so we know that current branch are checking that field and we're not interested

// Skip get_IsCompleted to avoid unuseful branch due to async/await state machine
if (
isAsyncStateMachineMoveNext && instruction.Previous.Operand is MethodReference operand &&
isRecognizedMoveNextInsideAsyncStateMachineProlog && instruction.Previous.Operand is MethodReference operand &&
operand.Name == "get_IsCompleted" &&
(
operand.DeclaringType.FullName.StartsWith("System.Runtime.CompilerServices.TaskAwaiter") ||
operand.DeclaringType.FullName.StartsWith("System.Runtime.CompilerServices.ConfiguredTaskAwaitable")
operand.DeclaringType.FullName.StartsWith("System.Runtime.CompilerServices.ConfiguredTaskAwaitable") ||
operand.DeclaringType.FullName.StartsWith("System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable")
)
&&
(
operand.DeclaringType.Scope.Name == "System.Runtime" ||
operand.DeclaringType.Scope.Name == "netstandard"
operand.DeclaringType.Scope.Name == "netstandard" ||
operand.DeclaringType.Scope.Name == "System.Threading.Tasks.Extensions"
)
)
{
Expand Down