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

Obsolete some protected, unused members of Regex{Runner} #84812

Merged
merged 2 commits into from
Apr 20, 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
1 change: 1 addition & 0 deletions docs/project/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ The PR that reveals the implementation of the `<IncludeInternalObsoleteAttribute
| __`SYSLIB0049`__ | JsonSerializerOptions.AddContext is obsolete. To register a JsonSerializerContext, use either the TypeInfoResolver or TypeInfoResolverChain properties. |
| __`SYSLIB0050`__ | Formatter-based serialization is obsolete and should not be used. |
| __`SYSLIB0051`__ | This API supports obsolete formatter-based serialization. It should not be called or extended by application code. |
| __`SYSLIB0052`__ | This API supports obsolete mechanisms for Regex extensibility. It is not supported. |

## Analyzer Warnings

Expand Down
3 changes: 3 additions & 0 deletions src/libraries/Common/src/System/Obsoletions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,8 @@ internal static class Obsoletions

internal const string LegacyFormatterImplMessage = "This API supports obsolete formatter-based serialization. It should not be called or extended by application code.";
internal const string LegacyFormatterImplDiagId = "SYSLIB0051";

internal const string RegexExtensibilityImplMessage = "This API supports obsolete mechanisms for Regex extensibility. It is not supported.";
internal const string RegexExtensibilityDiagId = "SYSLIB0052";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ public static void CompileToAssembly(System.Text.RegularExpressions.RegexCompila
public int[] GetGroupNumbers() { throw null; }
public string GroupNameFromNumber(int i) { throw null; }
public int GroupNumberFromName(string name) { throw null; }
[System.ObsoleteAttribute("This API supports obsolete mechanisms for Regex extensibility. It is not supported.", DiagnosticId = "SYSLIB0052", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
protected void InitializeReferences() { }
public bool IsMatch(System.ReadOnlySpan<char> input) { throw null; }
public bool IsMatch(System.ReadOnlySpan<char> input, int startat) { throw null; }
Expand Down Expand Up @@ -226,8 +228,12 @@ protected void InitializeReferences() { }
void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo si, System.Runtime.Serialization.StreamingContext context) { }
public override string ToString() { throw null; }
public static string Unescape(string str) { throw null; }
[System.ObsoleteAttribute("This API supports obsolete mechanisms for Regex extensibility. It is not supported.", DiagnosticId = "SYSLIB0052", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
protected bool UseOptionC() { throw null; }
protected internal bool UseOptionR() { throw null; }
[System.ObsoleteAttribute("This API supports obsolete mechanisms for Regex extensibility. It is not supported.", DiagnosticId = "SYSLIB0052", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
protected bool UseOptionR() { throw null; }
protected internal static void ValidateMatchTimeout(System.TimeSpan matchTimeout) { }
public ref partial struct ValueMatchEnumerator
{
Expand Down Expand Up @@ -336,6 +342,7 @@ private RegexParseException() { }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
public abstract partial class RegexRunner
{
protected internal int[]? runcrawl;
Expand All @@ -355,6 +362,7 @@ public abstract partial class RegexRunner
protected internal RegexRunner() { }
protected void Capture(int capnum, int start, int end) { }
public static bool CharInClass(char ch, string charClass) { throw null; }
[System.ObsoleteAttribute("This API supports obsolete mechanisms for Regex extensibility. It is not supported.", DiagnosticId = "SYSLIB0052", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
protected static bool CharInSet(char ch, string @set, string category) { throw null; }
protected void CheckTimeout() { }
protected void Crawl(int i) { }
Expand All @@ -372,12 +380,15 @@ protected void EnsureStorage() { }
protected int MatchIndex(int cap) { throw null; }
protected int MatchLength(int cap) { throw null; }
protected int Popcrawl() { throw null; }
[System.ObsoleteAttribute("This API supports obsolete mechanisms for Regex extensibility. It is not supported.", DiagnosticId = "SYSLIB0052", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
protected internal System.Text.RegularExpressions.Match? Scan(System.Text.RegularExpressions.Regex regex, string text, int textbeg, int textend, int textstart, int prevlen, bool quick) { throw null; }
[System.ObsoleteAttribute("This API supports obsolete mechanisms for Regex extensibility. It is not supported.", DiagnosticId = "SYSLIB0052", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
protected internal System.Text.RegularExpressions.Match? Scan(System.Text.RegularExpressions.Regex regex, string text, int textbeg, int textend, int textstart, int prevlen, bool quick, System.TimeSpan timeout) { throw null; }
protected internal virtual void Scan(System.ReadOnlySpan<char> text) { throw null; }
protected void TransferCapture(int capnum, int uncapnum, int start, int end) { }
protected void Uncapture() { }
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public abstract partial class RegexRunnerFactory
{
protected RegexRunnerFactory() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ public int GroupNumberFromName(string name)
Interlocked.CompareExchange(ref _replref, new WeakReference<RegexReplacement?>(null), null) ??
_replref;

[Obsolete(Obsoletions.RegexExtensibilityImplMessage, DiagnosticId = Obsoletions.RegexExtensibilityDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
[EditorBrowsable(EditorBrowsableState.Never)]
protected void InitializeReferences()
{
// This method no longer has anything to initialize. It continues to exist
Expand Down Expand Up @@ -615,9 +617,13 @@ private RegexRunner CreateRunner() =>
factory!.CreateInstance();

/// <summary>True if the <see cref="RegexOptions.Compiled"/> option was set.</summary>
[Obsolete(Obsoletions.RegexExtensibilityImplMessage, DiagnosticId = Obsoletions.RegexExtensibilityDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
[EditorBrowsable(EditorBrowsableState.Never)]
protected bool UseOptionC() => (roptions & RegexOptions.Compiled) != 0;

/// <summary>True if the <see cref="RegexOptions.RightToLeft"/> option was set.</summary>
protected internal bool UseOptionR() => RightToLeft;
[Obsolete(Obsoletions.RegexExtensibilityImplMessage, DiagnosticId = Obsoletions.RegexExtensibilityDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
[EditorBrowsable(EditorBrowsableState.Never)]
protected bool UseOptionR() => RightToLeft;
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// This RegexRunner class is a base class for compiled regex code.
// This RegexRunner class is a base class for source-generated regex extensibility
// (and the old CompileToAssembly extensibility). It's not intended to be used
// by anything else.

// Implementation notes:

// It provides the driver code that call's the subclass's Go()
// It provides the driver code that call's the subclass's Scan
// method for either scanning or direct execution.
//
// It also maintains memory allocation for the backtracking stack,
// the grouping stack and the longjump crawlstack, and provides
// methods to push new subpattern match results into (or remove
// backtracked results from) the Match instance.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace System.Text.RegularExpressions
{
[EditorBrowsable(EditorBrowsableState.Never)]
public abstract class RegexRunner
{
protected internal int runtextbeg; // Beginning of text to search. We now always use a sliced span of the input
Expand Down Expand Up @@ -118,15 +119,15 @@ protected internal virtual void Scan(ReadOnlySpan<char> text)
InternalScan(runregex!, beginning, beginning + text.Length);
}

// TODO https://github.com/dotnet/runtime/issues/62573: Obsolete this.
[Obsolete(Obsoletions.RegexExtensibilityImplMessage, DiagnosticId = Obsoletions.RegexExtensibilityDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
protected Match? Scan(Regex regex, string text, int textbeg, int textend, int textstart, int prevlen, bool quick) =>
Scan(regex, text, textbeg, textend, textstart, prevlen, quick, regex.MatchTimeout);

// TODO https://github.com/dotnet/runtime/issues/62573: Obsolete this.
/// <summary>
/// This method's body is only kept since it is a protected member that could be called by someone outside
/// the assembly.
/// </summary>
[Obsolete(Obsoletions.RegexExtensibilityImplMessage, DiagnosticId = Obsoletions.RegexExtensibilityDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
protected internal Match? Scan(Regex regex, string text, int textbeg, int textend, int textstart, int prevlen, bool quick, TimeSpan timeout)
{
InitializeTimeout(timeout);
Expand Down Expand Up @@ -393,6 +394,7 @@ internal static bool IsECMABoundary(ReadOnlySpan<char> inputSpan, int index)
((uint)index < (uint)inputSpan.Length && RegexCharClass.IsECMAWordChar(inputSpan[index]));
}

[Obsolete(Obsoletions.RegexExtensibilityImplMessage, DiagnosticId = Obsoletions.RegexExtensibilityDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
protected static bool CharInSet(char ch, string set, string category)
{
string charClass = RegexCharClass.ConvertOldStringsToClass(set, category);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;

namespace System.Text.RegularExpressions
{
[EditorBrowsable(EditorBrowsableState.Never)]
public abstract class RegexRunnerFactory
{
protected RegexRunnerFactory() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ internal class CustomRegexRunnerFactory : RegexRunnerFactory
internal class CustomRegexRunner : RegexRunner
{
public Match? CallScanDirectly(Regex regex, string text, int textbeg, int textend, int textstart, int prevlen, bool quick)
#pragma warning disable SYSLIB0052 // Type or member is obsolete
=> Scan(regex, text, textbeg, textend, textstart, prevlen, quick);
#pragma warning restore SYSLIB0052 // Type or member is obsolete

protected override void InitTrackCount() => base.runtrackcount = 12;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ public RegexTestClass()
capslist[1] = "1";
capslist[2] = "output";
capsize = 3;
#pragma warning disable SYSLIB0052 // Type or member is obsolete
base.InitializeReferences();
#pragma warning restore SYSLIB0052 // Type or member is obsolete
}

public RegexTestClass(TimeSpan timeSpan) : this()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ private sealed class DerivedRegex : Regex
public DerivedRegex() { }
public DerivedRegex(string pattern) : base(pattern) { }

#pragma warning disable SYSLIB0052 // Type or member is obsolete
public new void InitializeReferences() => base.InitializeReferences();
#pragma warning restore SYSLIB0052 // Type or member is obsolete

public new IDictionary Caps { get => base.Caps; set => base.Caps = value; }
public new IDictionary CapNames { get => base.CapNames; set => base.CapNames = value; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,9 @@ public DerivedRunner(string text)

public new bool IsBoundary(int index, int startpos, int endpos) => base.IsBoundary(index, startpos, endpos);

#pragma warning disable SYSLIB0052 // Type or member is obsolete
public static new bool CharInSet(char ch, string set, string category) => RegexRunner.CharInSet(ch, set, category);
#pragma warning restore SYSLIB0052 // Type or member is obsolete

protected override bool FindFirstChar() => throw new NotImplementedException();
protected override void Go() => throw new NotImplementedException();
Expand Down