Skip to content

Commit cefc6cc

Browse files
authored
[AOT] Audit dynamic code flags and add comments (#45946)
1 parent e321474 commit cefc6cc

File tree

6 files changed

+11
-2
lines changed

6 files changed

+11
-2
lines changed

src/Hosting/Hosting/src/GenericHost/GenericWebHostBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ static void InvokeContainer(GenericWebHostBuilder genericWebHostBuilder, Configu
341341
{
342342
var containerType = configureContainerBuilder.GetContainerType();
343343

344+
// Configure container uses MakeGenericType with the container type. MakeGenericType + struct container type requires IsDynamicCodeSupported.
344345
if (containerType.IsValueType && !RuntimeFeature.IsDynamicCodeSupported)
345346
{
346347
throw new InvalidOperationException("A ValueType TContainerBuilder isn't supported with AOT.");

src/Hosting/Hosting/src/Internal/StartupLoader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public static StartupMethods LoadMethods(IServiceProvider hostingServiceProvider
6868
Justification = "There is a runtime check for ValueType startup container. It's unlikely anyone will use a ValueType here.")]
6969
static Type CreateConfigureServicesDelegateBuilder(Type type)
7070
{
71+
// Configure container uses MakeGenericType with the container type. MakeGenericType + struct container type requires IsDynamicCodeSupported.
7172
if (type.IsValueType && !RuntimeFeature.IsDynamicCodeSupported)
7273
{
7374
throw new InvalidOperationException("ValueType startup container isn't supported with AOT.");

src/Http/Http.Abstractions/src/Extensions/UseMiddlewareExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ public static IApplicationBuilder UseMiddleware(
109109
return (RequestDelegate)invokeMethod.CreateDelegate(typeof(RequestDelegate), instance);
110110
}
111111

112-
var factory = RuntimeFeature.IsDynamicCodeSupported
112+
// Performance optimization: Use compiled expressions to invoke middleware with services injected in Invoke.
113+
// If IsDynamicCodeCompiled is false then use standard reflection to avoid overhead of interpreting expressions.
114+
var factory = RuntimeFeature.IsDynamicCodeCompiled
113115
? CompileExpression<object>(invokeMethod, parameters)
114116
: ReflectionFallback<object>(invokeMethod, parameters);
115117

src/Http/Http.Extensions/src/RequestDelegateFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ private static Expression[] CreateArgumentsAndInferMetadata(MethodInfo methodInf
422422

423423
for (var i = 0; i < argTypes.Length; i++)
424424
{
425+
// MakeGenericMethod + value type requires IsDynamicCodeSupported to be true.
425426
if (RuntimeFeature.IsDynamicCodeSupported)
426427
{
427428
// Register expressions containing the boxed and unboxed variants
@@ -560,7 +561,7 @@ private static Expression CreateEndpointFilterInvocationContextBase(RequestDeleg
560561
DefaultEndpointFilterInvocationContextConstructor,
561562
new Expression[] { HttpContextExpr, paramArray });
562563

563-
if (!RuntimeFeature.IsDynamicCodeCompiled)
564+
if (!RuntimeFeature.IsDynamicCodeSupported)
564565
{
565566
// For AOT platforms it's not possible to support the closed generic arguments that are based on the
566567
// parameter arguments dynamically (for value types). In that case, fallback to boxing the argument list.

src/Http/Routing/src/Matching/JumpTableBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public static JumpTable Build(int defaultDestination, int exitDestination, (stri
9292
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Guarded by IsDynamicCodeCompiled")]
9393
static JumpTable MakeILEmitTrieJumpTableIfSupported(int defaultDestination, int exitDestination, (string text, int destination)[] pathEntries, JumpTable fallback)
9494
{
95+
// ILEmitTrieJumpTable use IL emit to generate a custom, high-performance jump table.
96+
// EL emit requires IsDynamicCodeCompiled to be true. Fallback to another jump table implementation if not available.
9597
return RuntimeFeature.IsDynamicCodeCompiled
9698
? new ILEmitTrieJumpTable(defaultDestination, exitDestination, pathEntries, vectorize: null, fallback)
9799
: fallback;

src/Shared/PropertyHelper/PropertyHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public static PropertyHelper[] GetVisibleProperties(
211211
Debug.Assert(!getMethod.IsStatic);
212212
Debug.Assert(getMethod.GetParameters().Length == 0);
213213

214+
// MakeGenericMethod + value type requires IsDynamicCodeSupported to be true.
214215
if (RuntimeFeature.IsDynamicCodeSupported)
215216
{
216217
// TODO: Remove disable when https://github.com/dotnet/linker/issues/2715 is complete.
@@ -285,6 +286,7 @@ public static PropertyHelper[] GetVisibleProperties(
285286
var parameters = setMethod.GetParameters();
286287
Debug.Assert(parameters.Length == 1);
287288

289+
// MakeGenericMethod + value type requires IsDynamicCodeSupported to be true.
288290
if (RuntimeFeature.IsDynamicCodeSupported)
289291
{
290292
// TODO: Remove disable when https://github.com/dotnet/linker/issues/2715 is complete.

0 commit comments

Comments
 (0)