From f8971ff4d2d90b259984e6b88f5bb934babe13d5 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 13 Apr 2023 21:08:48 -0400 Subject: [PATCH] Obsolete some protected, unused members of Regex{Runner} --- docs/project/list-of-diagnostics.md | 1 + src/libraries/Common/src/System/Obsoletions.cs | 3 +++ .../ref/System.Text.RegularExpressions.cs | 13 ++++++++++++- .../src/System/Text/RegularExpressions/Regex.cs | 8 +++++++- .../Text/RegularExpressions/RegexRunner.cs | 16 +++++++++------- .../RegularExpressions/RegexRunnerFactory.cs | 3 +++ .../CustomDerivedRegexScenarioTest.cs | 2 ++ .../PrecompiledRegexScenarioTest.cs | 2 ++ .../tests/FunctionalTests/Regex.Ctor.Tests.cs | 2 ++ .../FunctionalTests/RegexCharacterSetTests.cs | 2 ++ 10 files changed, 43 insertions(+), 9 deletions(-) diff --git a/docs/project/list-of-diagnostics.md b/docs/project/list-of-diagnostics.md index 4ed4d318fd746..2dfe110075e86 100644 --- a/docs/project/list-of-diagnostics.md +++ b/docs/project/list-of-diagnostics.md @@ -106,6 +106,7 @@ The PR that reveals the implementation of the ` input) { throw null; } public bool IsMatch(System.ReadOnlySpan input, int startat) { throw null; } @@ -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 { @@ -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)] public abstract partial class RegexRunner { protected internal int[]? runcrawl; @@ -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) { } @@ -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 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() { } diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.cs index d41516f57bde6..3053eb2055099 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.cs @@ -367,6 +367,8 @@ public int GroupNumberFromName(string name) Interlocked.CompareExchange(ref _replref, new WeakReference(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 @@ private RegexRunner CreateRunner() => factory!.CreateInstance(); /// True if the option was set. + [Obsolete(Obsoletions.RegexExtensibilityImplMessage, DiagnosticId = Obsoletions.RegexExtensibilityDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] + [EditorBrowsable(EditorBrowsableState.Never)] protected bool UseOptionC() => (roptions & RegexOptions.Compiled) != 0; /// True if the option was set. - protected internal bool UseOptionR() => RightToLeft; + [Obsolete(Obsoletions.RegexExtensibilityImplMessage, DiagnosticId = Obsoletions.RegexExtensibilityDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] + [EditorBrowsable(EditorBrowsableState.Never)] + protected bool UseOptionR() => RightToLeft; } } diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexRunner.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexRunner.cs index dd1097a0d51e2..c1ea7cb3be905 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexRunner.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexRunner.cs @@ -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 @@ protected internal virtual void Scan(ReadOnlySpan 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. /// /// This method's body is only kept since it is a protected member that could be called by someone outside /// the assembly. /// + [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 @@ internal static bool IsECMABoundary(ReadOnlySpan 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); diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexRunnerFactory.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexRunnerFactory.cs index 93860f20cdf47..4fd0c89cb040f 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexRunnerFactory.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexRunnerFactory.cs @@ -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() { } diff --git a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/CustomDerivedRegexScenarioTest.cs b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/CustomDerivedRegexScenarioTest.cs index b2659ae08bf4e..50149bf5e3e51 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/CustomDerivedRegexScenarioTest.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/CustomDerivedRegexScenarioTest.cs @@ -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; diff --git a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/PrecompiledRegexScenarioTest.cs b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/PrecompiledRegexScenarioTest.cs index 55854df2094d9..768e0b4ec1ff4 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/PrecompiledRegexScenarioTest.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/PrecompiledRegexScenarioTest.cs @@ -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() diff --git a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Ctor.Tests.cs b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Ctor.Tests.cs index 1311f15aa8bb5..17adb8aa72320 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Ctor.Tests.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Ctor.Tests.cs @@ -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; } diff --git a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexCharacterSetTests.cs b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexCharacterSetTests.cs index e3b1c95eeb253..ab7602ccb78bf 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexCharacterSetTests.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexCharacterSetTests.cs @@ -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();