Skip to content

Commit 96559b6

Browse files
authored
Remove incorrect suppressions from AwaitableInfo (#56360)
These warning suppressions are not correct. The reflection usage in these methods isn't compatible with trimming. Marking the methods correctly with RequiresUnreferencedCode. See dotnet/runtime#103258 for more info.
1 parent 28481ab commit 96559b6

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/Shared/ObjectMethodExecutor/AwaitableInfo.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace Microsoft.Extensions.Internal;
1111

1212
internal readonly struct AwaitableInfo
1313
{
14+
internal const string RequiresUnreferencedCodeMessage = "Uses unbounded reflection to determine awaitability of types.";
15+
1416
private const BindingFlags Everything = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
1517
private static readonly MethodInfo INotifyCompletion_OnCompleted = typeof(INotifyCompletion).GetMethod(nameof(INotifyCompletion.OnCompleted), Everything, new[] { typeof(Action) })!;
1618
private static readonly MethodInfo ICriticalNotifyCompletion_UnsafeOnCompleted = typeof(ICriticalNotifyCompletion).GetMethod(nameof(ICriticalNotifyCompletion.UnsafeOnCompleted), Everything, new[] { typeof(Action) })!;
@@ -41,8 +43,7 @@ public AwaitableInfo(
4143
GetAwaiterMethod = getAwaiterMethod;
4244
}
4345

44-
[UnconditionalSuppressMessage("Trimmer", "IL2070", Justification = "Reflecting over the async Task types contract")]
45-
[UnconditionalSuppressMessage("Trimmer", "IL2075", Justification = "Reflecting over the async Task types contract")]
46+
[RequiresUnreferencedCode(RequiresUnreferencedCodeMessage)]
4647
public static bool IsTypeAwaitable(
4748
Type type,
4849
out AwaitableInfo awaitableInfo)

src/Shared/ObjectMethodExecutor/CoercedAwaitableInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public CoercedAwaitableInfo(Expression coercerExpression, Type coercerResultType
2929
AwaitableInfo = coercedAwaitableInfo;
3030
}
3131

32+
[RequiresUnreferencedCode(AwaitableInfo.RequiresUnreferencedCodeMessage)]
3233
[RequiresDynamicCode("Dynamically generates calls to FSharpAsync.")]
3334
public static bool IsTypeAwaitable(
3435
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] Type type,

src/Shared/ObjectMethodExecutor/ObjectMethodExecutorFSharpSupport.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal static class ObjectMethodExecutorFSharpSupport
5454
/// by the coercer expression, if it was possible to build a coercer; otherwise, <see langword="null"/>.
5555
/// </param>
5656
/// <returns><see langword="true"/> if it was possible to build a coercer; otherwise, <see langword="false"/>.</returns>
57-
[UnconditionalSuppressMessage("Trimmer", "IL2060", Justification = "Reflecting over the async FSharpAsync<> contract.")]
57+
[RequiresUnreferencedCode("Reflecting over the async FSharpAsync<> contract.")]
5858
public static bool TryBuildCoercerFromFSharpAsyncToAwaitable(
5959
Type possibleFSharpAsyncType,
6060
out Expression coerceToAwaitableExpression,
@@ -127,7 +127,7 @@ public static bool TryBuildCoercerFromFSharpAsyncToAwaitable(
127127
/// otherwise, <see langword="null"/>.
128128
/// </param>
129129
/// <returns><see langword="true"/> if it was possible to build a coercer; otherwise, <see langword="false"/>.</returns>
130-
[UnconditionalSuppressMessage("Trimmer", "IL2060", Justification = "Reflecting over FSharp.Core.Unit.")]
130+
[RequiresUnreferencedCode("Reflecting over FSharp.Core.Unit.")]
131131
public static bool TryBuildCoercerFromUnitAwaitableToVoidAwaitable(
132132
Type genericAwaitableType,
133133
out Expression coercerExpression,
@@ -168,12 +168,15 @@ static Expression MakeValueTaskOfUnitToValueTaskExpression(Type type)
168168
}
169169
}
170170

171+
[RequiresUnreferencedCode("Reflecting over the async FSharpAsync<> contract.")]
171172
private static bool IsFSharpAsyncOpenGenericType(Type possibleFSharpAsyncType) =>
172173
IsCoerceableFSharpType(possibleFSharpAsyncType, FSharpAsyncGenericTypeName);
173174

175+
[RequiresUnreferencedCode("Reflecting over the async FSharpAsync<> contract.")]
174176
private static bool IsFSharpUnit(Type possibleFSharpUnitType) =>
175177
IsCoerceableFSharpType(possibleFSharpUnitType, FSharpUnitTypeName);
176178

179+
[RequiresUnreferencedCode("Reflecting over the async FSharpAsync<> contract.")]
177180
private static bool IsCoerceableFSharpType(Type possibleFSharpType, string coerceableFSharpTypeName)
178181
{
179182
var typeFullName = possibleFSharpType?.FullName;
@@ -199,9 +202,7 @@ private static bool IsCoerceableFSharpType(Type possibleFSharpType, string coerc
199202
}
200203
}
201204

202-
[UnconditionalSuppressMessage("Trimmer", "IL2026", Justification = "Reflecting over the async FSharpAsync<> contract")]
203-
[UnconditionalSuppressMessage("Trimmer", "IL2055", Justification = "Reflecting over the async FSharpAsync<> contract")]
204-
[UnconditionalSuppressMessage("Trimmer", "IL2072", Justification = "Reflecting over the async FSharpAsync<> contract")]
205+
[RequiresUnreferencedCode("Reflecting over the async FSharpAsync<> contract.")]
205206
private static bool TryPopulateFSharpValueCaches(Type possibleFSharpType)
206207
{
207208
var assembly = possibleFSharpType.Assembly;

0 commit comments

Comments
 (0)