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

Annotating Regex library for Native Aot apps #67841

Merged
merged 3 commits into from
Apr 12, 2022
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 @@ -74,6 +74,8 @@ internal Regex(string pattern, CultureInfo? culture)
// if no options are ever used.
}

[UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode",
Justification = "Compiled Regex is only used when RuntimeFeature.IsDynamicCodeCompiled is true. Workaround https://github.com/dotnet/linker/issues/2715.")]
internal Regex(string pattern, RegexOptions options, TimeSpan matchTimeout, CultureInfo? culture)
{
// Validate arguments.
Expand Down Expand Up @@ -201,6 +203,7 @@ protected IDictionary? CapNames
/// Regex constructor, we don't load RegexCompiler and its reflection classes when
/// instantiating a non-compiled regex.
/// </summary>
[RequiresDynamicCode("Compiling a RegEx requires dynamic code.")]
[MethodImpl(MethodImplOptions.NoInlining)]
private static RegexRunnerFactory? Compile(string pattern, RegexTree regexTree, RegexOptions options, bool hasTimeout) =>
RegexCompiler.Compile(pattern, regexTree, options, hasTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace System.Text.RegularExpressions
/// <summary>
/// RegexCompiler translates a block of RegexCode to MSIL, and creates a subclass of the RegexRunner type.
/// </summary>
[RequiresDynamicCode("Compiling a RegEx requires dynamic code.")]
internal abstract class RegexCompiler
{
private static readonly FieldInfo s_runtextstartField = RegexRunnerField("runtextstart");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;
Expand Down Expand Up @@ -30,6 +31,7 @@ internal sealed class RegexLWCGCompiler : RegexCompiler
private static int s_regexCount;

/// <summary>The top-level driver. Initializes everything then calls the Generate* methods.</summary>
[RequiresDynamicCode("Compiling a RegEx requires dynamic code.")]
public RegexRunnerFactory? FactoryInstanceFromCode(string pattern, RegexTree regexTree, RegexOptions options, bool hasTimeout)
{
if (!regexTree.Root.SupportsCompilation(out _))
Expand Down Expand Up @@ -65,6 +67,7 @@ internal sealed class RegexLWCGCompiler : RegexCompiler
}

/// <summary>Begins the definition of a new method (no args) with a specified return value.</summary>
[RequiresDynamicCode("Compiling a RegEx requires dynamic code.")]
private DynamicMethod DefineDynamicMethod(string methname, Type? returntype, Type hostType, Type[] paramTypes)
{
// We're claiming that these are static methods, but really they are instance methods.
Expand Down