Obsolete some protected, unused members of Regex{Runner} (#84812)
authorStephen Toub <stoub@microsoft.com>
Thu, 20 Apr 2023 10:14:25 +0000 (06:14 -0400)
committerGitHub <noreply@github.com>
Thu, 20 Apr 2023 10:14:25 +0000 (06:14 -0400)
docs/project/list-of-diagnostics.md
src/libraries/Common/src/System/Obsoletions.cs
src/libraries/System.Text.RegularExpressions/ref/System.Text.RegularExpressions.cs
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.cs
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexRunner.cs
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexRunnerFactory.cs
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/CustomDerivedRegexScenarioTest.cs
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/PrecompiledRegexScenarioTest.cs
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Ctor.Tests.cs
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexCharacterSetTests.cs

index 4ed4d31..2dfe110 100644 (file)
@@ -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
 
index 3f35696..668e38d 100644 (file)
@@ -165,5 +165,8 @@ namespace System
 
         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";
     }
 }
index 71800c8..949f493 100644 (file)
@@ -183,6 +183,8 @@ namespace System.Text.RegularExpressions
         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; }
@@ -226,8 +228,12 @@ namespace System.Text.RegularExpressions
         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
         {
@@ -336,6 +342,7 @@ namespace System.Text.RegularExpressions
         [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)]
     public abstract partial class RegexRunner
     {
         protected internal int[]? runcrawl;
@@ -355,6 +362,7 @@ namespace System.Text.RegularExpressions
         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) { }
@@ -372,12 +380,15 @@ namespace System.Text.RegularExpressions
         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() { }
index d41516f..3053eb2 100644 (file)
@@ -367,6 +367,8 @@ namespace System.Text.RegularExpressions
             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
@@ -615,9 +617,13 @@ namespace System.Text.RegularExpressions
             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;
     }
 }
index dd1097a..c1ea7cb 100644 (file)
@@ -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
@@ -118,15 +119,15 @@ namespace System.Text.RegularExpressions
             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);
@@ -393,6 +394,7 @@ namespace System.Text.RegularExpressions
                    ((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);
index 93860f2..4fd0c89 100644 (file)
@@ -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() { }
index b2659ae..50149bf 100644 (file)
@@ -54,7 +54,9 @@ namespace System.Text.RegularExpressions.Tests
             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;
 
index 55854df..768e0b4 100644 (file)
@@ -120,7 +120,9 @@ namespace RegexTestNamespace
             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()
index 1311f15..17adb8a 100644 (file)
@@ -213,7 +213,9 @@ namespace System.Text.RegularExpressions.Tests
             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; }
index e3b1c95..ab7602c 100644 (file)
@@ -508,7 +508,9 @@ namespace System.Text.RegularExpressions.Tests
 
             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();