-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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 members of Regex{Runner} #62573
Comments
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions Issue DetailsRegex and RegexRunner have a relatively large protected surface area in support of the old CompileToAssembly, which is now obsolete. Some of that functionality is used by code generated by the source generator, but some of the surface area is defunct (at least for external consumption... some is still used internally). We should consider obsoleting:
|
If there's any way to remove the RegexRunner.runtext* fields, that would help as well. I've been looking at possible codegen optimizations within the Regex type itself, but they're stymied by the fact that those fields are accessible by external code and thus can't be refactored in a way that would improve throughput. |
Any in particular? These are used by external Regex implementations, those created by CompileToAssembly and the source generator. Only some of them are used by the source generated implementations, but even if we found a different way to pass that state in and around, removing these fields would break any existing assemblies generated by CompileToAssembly. That said, CompileToAssembly is obsoleted as of .NET 7, so we're talking about compat with assemblies generated on .NET Framework. At some point in the future, we could consider dropping that compat support. We contemplated having the new Scan virtual method accept and return all the necessary state, but I'm not sure that would be a net win. It would also be complicated, e.g. various helpers like Capture need access to it. Suggestions? |
Honestly, I don't know. I'm mostly lamenting that the int fields are true fields rather than properties, since it's preventing me from moving the actual storage to a more optimal location. Maybe it's one of those things that we just accept as overhead for now and revisit if we ever make more radical changes to Regex in the future. |
@joperezr, were you going to push on this for .NET 7? |
Sorry @stephentoub I missed the ping. Unless you think otherwise, since this is just obsoleting I'm fine with doing this on 8.0 |
Added
Tagging @dotnet/compat for awareness of the breaking change. |
Because the proposal mentions removing the body of CharInSet, I've marked it as a breaking change. Since CharInSet is having its body removed, it probably warrants obsolete-as-error, the rest being obsolete-as-warning. Obsoletions should just use the next available SYSLIB code. (The same code can apply to all of them, even though it's mixing warning and error) EditorBrowsable-Never is also fine if it makes you happy. namespace System.Text.RegularExpressions;
public class Regex
{
+ [Obsolete(...)]
protected void InitializeReferences();
+ [Obsolete(...)]
protected bool UseOptionC()
+ [Obsolete(...)]
protected bool UseOptionR();
}
public abstract class RegexRunner
{
+ [Obsolete(...)]
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);
+ [Obsolete(...)]
protected internal Match? Scan(Regex regex, string text, int textbeg, int textend, int textstart, int prevlen, bool quick, TimeSpan timeout)
+ [Obsolete(...)]
protected static bool CharInSet(char ch, string set, string category);
} |
Regex and RegexRunner have a relatively large protected surface area in support of the old CompileToAssembly, which is now obsolete. Some of that functionality is used by code generated by the source generator, but some of the surface area is completely defunct, and some was never used (who knows why it was exposed initially).
I would like to also make that last
CharInSet
not only obsolete but alsothrow new NotSupportedException()
. This was never used by the implementation, and we've never generated assets that use whatever format it's trying to support.The text was updated successfully, but these errors were encountered: