@@ -89,21 +89,23 @@ internal static string ToHttpMethodExpression(string httpMethod) =>
8989 _ => $"new global::System.Net.Http.HttpMethod({ToCSharpStringLiteral(httpMethod)})"
9090 };
9191
92- /// <summary>Gets the invocation text used for a generated method return type.</summary>
92+ /// <summary>Gets the statement prefix used for a generated method return type.</summary>
9393 /// <param name="returnTypeInfo">The method return type shape.</param>
94- /// <returns>The async flag, return prefix, and configure-await suffix .</returns>
94+ /// <returns>The return statement prefix, empty for a shape that discards the call's result .</returns>
9595 /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="returnTypeInfo"/> is unsupported.</exception>
96- internal static (bool IsAsync, string ReturnPrefix, string ConfigureAwaitSuffix) GetReturnInvocationParts(
97- ReturnTypeInfo returnTypeInfo) =>
96+ /// <remarks>An awaitable shape hands its task straight back rather than awaiting it. Awaiting here would build a
97+ /// second state machine per call that forwards the task the request builder already produced, changing nothing but
98+ /// the allocation count; the awaitable is the caller's to consume.</remarks>
99+ internal static string GetReturnStatementPrefix(ReturnTypeInfo returnTypeInfo) =>
98100 returnTypeInfo switch
99101 {
100- ReturnTypeInfo.AsyncVoid => (true, "await (", ").ConfigureAwait(false)"),
101- ReturnTypeInfo.AsyncResult => (true, "return await (", ").ConfigureAwait(false)"),
102- ReturnTypeInfo.AsyncEnumerable
102+ ReturnTypeInfo.AsyncVoid
103+ or ReturnTypeInfo.AsyncResult
104+ or ReturnTypeInfo.AsyncEnumerable
103105 or ReturnTypeInfo.Observable
104106 or ReturnTypeInfo.RequestMessage
105- or ReturnTypeInfo.Return => (false, ReturnStatementPrefix, string.Empty) ,
106- ReturnTypeInfo.SyncVoid => (false, string.Empty, string.Empty) ,
107+ or ReturnTypeInfo.Return => ReturnStatementPrefix,
108+ ReturnTypeInfo.SyncVoid => string.Empty,
107109 _ => throw new ArgumentOutOfRangeException(
108110 nameof(returnTypeInfo),
109111 returnTypeInfo,
@@ -223,26 +225,25 @@ internal static string StripExplicitInterfacePrefix(string name)
223225 /// <param name="isDerivedExplicitImpl">True if the method is a derived explicit implementation.</param>
224226 /// <param name="isExplicitInterface">True if the method is an explicit interface implementation.</param>
225227 /// <param name="supportsNullable">Whether the consumer compilation supports nullable reference type syntax.</param>
226- /// <param name="isAsync">True if the method should be emitted as async.</param>
227228 /// <param name="methodAttributes">Attribute lines emitted between the documentation and the signature.</param>
229+ /// <remarks>Every generated method is emitted synchronously: an awaitable return type is handed back to the caller
230+ /// rather than awaited, so no generated method carries an async state machine.</remarks>
228231 internal static void AppendMethodOpening(
229232 PooledStringBuilder builder,
230233 in MethodModel methodModel,
231234 bool isDerivedExplicitImpl,
232235 bool isExplicitInterface,
233236 bool supportsNullable,
234- bool isAsync = false,
235237 string methodAttributes = "")
236238 {
237239 var visibility = !isExplicitInterface ? "public " : string.Empty;
238- var asyncKeyword = isAsync ? "async " : string.Empty;
239240 var explicitInterface = BuildExplicitInterfacePrefix(methodModel, isExplicitInterface);
240241 var methodIndent = Indent(MethodMemberIndentation);
241242
242243 _ = builder
243244 .AppendLine()
244245 .Append(methodIndent).AppendLine("/// <inheritdoc />")
245- .Append(methodAttributes).Append(methodIndent).Append(visibility).Append(asyncKeyword)
246+ .Append(methodAttributes).Append(methodIndent).Append(visibility)
246247 .Append(methodModel.ReturnType).Append(' ').Append(explicitInterface).Append(methodModel.DeclaredMethod)
247248 .Append('(').Append(BuildParameterList(methodModel.Parameters, supportsNullable)).Append(')').AppendLine();
248249 AppendConstraints(builder, methodModel.Constraints, isDerivedExplicitImpl || isExplicitInterface, MethodBodyIndentation);
@@ -254,19 +255,17 @@ internal static void AppendMethodOpening(
254255 /// <param name="isDerivedExplicitImpl">True if the method is a derived explicit implementation.</param>
255256 /// <param name="isExplicitInterface">True if the method is an explicit interface implementation.</param>
256257 /// <param name="supportsNullable">Whether the consumer compilation supports nullable reference type syntax.</param>
257- /// <param name="isAsync">True if the method should be emitted as async.</param>
258258 /// <param name="methodAttributes">Attribute lines emitted between the documentation and the signature.</param>
259259 /// <returns>The generated method opening.</returns>
260260 internal static string BuildMethodOpening(
261261 in MethodModel methodModel,
262262 bool isDerivedExplicitImpl,
263263 bool isExplicitInterface,
264264 bool supportsNullable,
265- bool isAsync = false,
266265 string methodAttributes = "")
267266 {
268267 var builder = new PooledStringBuilder();
269- AppendMethodOpening(builder, methodModel, isDerivedExplicitImpl, isExplicitInterface, supportsNullable, isAsync, methodAttributes);
268+ AppendMethodOpening(builder, methodModel, isDerivedExplicitImpl, isExplicitInterface, supportsNullable, methodAttributes);
270269 return builder.ToString();
271270 }
272271
0 commit comments