Skip to content

[AOT] Audit dynamic code flags and add comments #45946

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 8, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ static void InvokeContainer(GenericWebHostBuilder genericWebHostBuilder, Configu
{
var containerType = configureContainerBuilder.GetContainerType();

// Configure container uses MakeGenericType with the container type. MakeGenericType + struct container type requires IsDynamicCodeSupported.
if (containerType.IsValueType && !RuntimeFeature.IsDynamicCodeSupported)
{
throw new InvalidOperationException("A ValueType TContainerBuilder isn't supported with AOT.");
Expand Down
1 change: 1 addition & 0 deletions src/Hosting/Hosting/src/Internal/StartupLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static StartupMethods LoadMethods(IServiceProvider hostingServiceProvider
Justification = "There is a runtime check for ValueType startup container. It's unlikely anyone will use a ValueType here.")]
static Type CreateConfigureServicesDelegateBuilder(Type type)
{
// Configure container uses MakeGenericType with the container type. MakeGenericType + struct container type requires IsDynamicCodeSupported.
if (type.IsValueType && !RuntimeFeature.IsDynamicCodeSupported)
{
throw new InvalidOperationException("ValueType startup container isn't supported with AOT.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public static IApplicationBuilder UseMiddleware(
return (RequestDelegate)invokeMethod.CreateDelegate(typeof(RequestDelegate), instance);
}

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

Expand Down
3 changes: 2 additions & 1 deletion src/Http/Http.Extensions/src/RequestDelegateFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ private static Expression[] CreateArgumentsAndInferMetadata(MethodInfo methodInf

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

if (!RuntimeFeature.IsDynamicCodeCompiled)
if (!RuntimeFeature.IsDynamicCodeSupported)
{
// For AOT platforms it's not possible to support the closed generic arguments that are based on the
// parameter arguments dynamically (for value types). In that case, fallback to boxing the argument list.
Expand Down
2 changes: 2 additions & 0 deletions src/Http/Routing/src/Matching/JumpTableBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public static JumpTable Build(int defaultDestination, int exitDestination, (stri
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Guarded by IsDynamicCodeCompiled")]
static JumpTable MakeILEmitTrieJumpTableIfSupported(int defaultDestination, int exitDestination, (string text, int destination)[] pathEntries, JumpTable fallback)
{
// ILEmitTrieJumpTable use IL emit to generate a custom, high-performance jump table.
// EL emit requires IsDynamicCodeCompiled to be true. Fallback to another jump table implementation if not available.
return RuntimeFeature.IsDynamicCodeCompiled
? new ILEmitTrieJumpTable(defaultDestination, exitDestination, pathEntries, vectorize: null, fallback)
: fallback;
Expand Down
2 changes: 2 additions & 0 deletions src/Shared/PropertyHelper/PropertyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public static PropertyHelper[] GetVisibleProperties(
Debug.Assert(!getMethod.IsStatic);
Debug.Assert(getMethod.GetParameters().Length == 0);

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

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