Skip to content
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

[AOT] Add RequiresDynamicCode annotation to Microsoft.AspNetCore.Routing #45580

Merged
merged 4 commits into from
Jan 3, 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
3 changes: 3 additions & 0 deletions src/Http/Routing/src/Matching/ILEmitTrieFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#nullable disable

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
Expand All @@ -12,6 +13,7 @@

namespace Microsoft.AspNetCore.Routing.Matching;

[RequiresDynamicCode("ILEmitTrieFactory uses runtime IL generation.")]
internal static class ILEmitTrieFactory
{
// The algorthm we use only works for ASCII text. If we find non-ASCII text in the input
Expand Down Expand Up @@ -477,6 +479,7 @@ private sealed class Labels
public Label ReturnNotAscii { get; set; }
}

[RequiresDynamicCode("ILEmitTrieFactory uses runtime IL generation.")]
private sealed class Methods
{
// Caching because the methods won't change, if we're being called once we're likely to
Expand Down
3 changes: 3 additions & 0 deletions src/Http/Routing/src/Matching/ILEmitTrieJumpTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

#nullable disable

using System.Diagnostics.CodeAnalysis;

namespace Microsoft.AspNetCore.Routing.Matching;

// Uses generated IL to implement the JumpTable contract. This approach requires
// a fallback jump table for two reasons:
// 1. We compute the IL lazily to avoid taking up significant time when processing a request
// 2. The generated IL only supports ASCII in the URL path
[RequiresDynamicCode("ILEmitTrieJumpTable uses runtime IL generation.")]
internal sealed class ILEmitTrieJumpTable : JumpTable
{
private readonly int _defaultDestination;
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 @@ -87,7 +87,9 @@ public static JumpTable Build(int defaultDestination, int exitDestination, (stri
// Use the ILEmitTrieJumpTable if the IL is going to be compiled (not interpreted)
if (RuntimeFeature.IsDynamicCodeCompiled)
{
#pragma warning disable IL3050 // See https://github.com/dotnet/linker/issues/2715.
return new ILEmitTrieJumpTable(defaultDestination, exitDestination, pathEntries, vectorize: null, fallback);
#pragma warning restore IL3050
}

return fallback;
Expand Down