Table of Contents

Class AsyncValueTaskBoxingAnalyzer

Namespace
CryptoHives.Foundation.Threading.Analyzers
Assembly
CryptoHives.Foundation.Threading.Analyzers.dll

Detects async methods returning ValueTask whose only job is to await and forward a single inner ValueTask, where the state machine the compiler generates is either pure overhead (CHT011) or a heap allocation the surrounding cleanup is paying for (CHT012).

[DiagnosticAnalyzer("C#", new string[] { })]
public sealed class AsyncValueTaskBoxingAnalyzer : DiagnosticAnalyzer
Inheritance
AsyncValueTaskBoxingAnalyzer
Inherited Members

Remarks

Both rules describe the same underlying cost. An async method's builder boxes its state machine the first time the method suspends; when the method does nothing but forward one ValueTask, that box is bought for nothing the caller could not have had by returning the inner ValueTask itself.

They are split because the remedies differ in kind. CHT011 fires when nothing stands in the way, so the fix is mechanical and can be applied automatically. CHT012 fires when cleanup wraps the await - the async machinery is genuinely load-bearing there, and removing it takes a redesign the analyzer cannot perform or even prove is possible. Reporting them under one ID would force a single severity on two very different asks.

Properties

SupportedDiagnostics

Returns a set of descriptors for the diagnostics that this analyzer is capable of producing.

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }

Property Value

ImmutableArray<DiagnosticDescriptor>

Methods

Initialize(AnalysisContext)

Called once at session start to register actions in the analysis context.

public override void Initialize(AnalysisContext context)

Parameters

context AnalysisContext