-
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
Add RegexOptions.NonBacktracking #60607
Conversation
The simple API addition (a new RegexOptions.NonBacktracking enum member) is the tip of the iceberg for a new engine in System.Text.RegularExpressions. Setting this option now opts the regex processing into a mode that can guarantee linear-time matching in the length of the input (doing so disables certain features of Regex and regex patterns). This commit is the initial implementation ported over from dotnet/runtimelab, which was itself seeded from the MSR Symbolic Regex Matcher project. Co-authored-by: Olli Saarikivi <[email protected]> Co-authored-by: Stephen Toub <[email protected]> Co-authored-by: Dan Moseley <[email protected]>
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Changes have all been vetted by relevant reviewers in dotnet/runtimelab. Merging. |
protected void InitializeReferences() | ||
{ | ||
if (_refsInitialized) | ||
{ | ||
ThrowHelper.ThrowNotSupportedException(ExceptionResource.OnlyAllowedOnce); | ||
} | ||
|
||
_replref = new WeakReference<RegexReplacement?>(null); | ||
_refsInitialized = true; | ||
// This method no longer has anything to initialize. It continues to exist | ||
// purely for API compat, as it was originally shipped as protected, with | ||
// assemblies generated by Regex.CompileToAssembly calling it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we ever mark defunct protected methods as [Obsolete]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could. I don't know that it would help with a lot. In general the only folks that use the protected surface area of Regex/RegexRunner are ourselves, as part of the CompileToAssembly, RegexOptions.Compiled, and now the source generator. Regardless of [Obsolete], if someone is using this surface area directly, they're probably doing something wrong :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these APIs have
This API supports the product infrastructure and is not intended to be used directly from your code.
in the docs. E.g. https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regexrunner.charinclass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API supports the product infrastructure and is not intended to be used directly from your code.
Should all such API's be annotated so our analyzer flags them on use? I know there's quite a few API's we own that have that blurb.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds similar to EntityFrameworkInternalAttribute.
The simple API addition (a new
RegexOptions.NonBacktracking
enum member) is the tip of the iceberg for a new engine in System.Text.RegularExpressions. Setting this option now opts the regex processing into a mode that can guarantee linear-time matching in the length of the input (doing so disables certain features of Regex and regex patterns and impacts observable behavior for what's matched).This commit is the initial implementation ported over from dotnet/runtimelab, which was in turn seeded from the MSR Symbolic Regex Matcher project. There is still further work required to make it ready to ship, and such remaining work will happen in main.
Fixes #57891
Fixes #18614
Contributes to #1349
cc: @veanes, @olsaarik, @danmoseley, @jeffhandley, @eerhardt, @tannergooding