-
Notifications
You must be signed in to change notification settings - Fork 1.6k
<regex>: Process generic loops non-recursively
#5798
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
Merged
StephanTLavavej
merged 9 commits into
microsoft:main
from
muellerj2:regex-process-generic-loops-nonrecursively
Oct 29, 2025
Merged
<regex>: Process generic loops non-recursively
#5798
StephanTLavavej
merged 9 commits into
microsoft:main
from
muellerj2:regex-process-generic-loops-nonrecursively
Oct 29, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I made the domain slightly longer, and kept '.' characters in the same relative locations, since they appear to be the one character that's relevant to the regex.
StephanTLavavej
approved these changes
Oct 24, 2025
Member
|
Thanks, this is incredible! 😻 I pushed some changes to the test, please double-check that I didn't mess anything up. If the CLA Bot is snoozy I may need to close and reopen this PR. |
Member
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Member
|
An incredible achievement, thank you! 😻 🎉 😸 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #997. Fixes #1528.
This is the final change to make the matcher non-recursive, but it will be followed by a few more PRs to clean up the code and simplify the data stored in
_Rx_state_frames.The new code in
_Match_pat()is closer to the structure of the original code than for simple loops, but also quite similar to the non-recursive code for simple loops, so I chose not to split it into several PRs.Differences compared to simple loops:
_Rx_state_frameto store the original values of these loop variables and have to add an unwinding opcode just for resetting these loop variables. Moreover, we have to completely restore the match state whenever we backtrack after failure (ECMAScript) or while matching a POSIX regex._Do_rep()and is a bit simpler for generic loops, I think, because the logic for handling the minimum number of repetitions isn't affected much by whether the last encountered match is empty or not (except for the optimization of increasing_Loop_idxby more than one when a match is empty). This is different from simple loops, where the easy case was an empty match: Because simple loops are branchless, one empty match means all are empty, so the minimum number of repetitions essentially becomes meaningless when an empty match appears.Most of the test coverage is derived from the new coverage for simple loops, with a minor change to make the loops non-simple by making them branch. I also added another test to make sure we correctly handle an empty match that only appears in the final repetition to reach the minimum number of repetitions.
As for the two tests to verify that stack overflows no longer occur (copied from the original issues), I deliberately set one of them up to fail when matching no longer results in an exception, because the code should be changed to use the regex tester when an exception is no longer thrown. (I can't easily do this for the other test case because it currently succeeds for x86 but fails for x64. It seems out of proportion to add preprocessor logic just to make the test fail on 64-bit systems when it succeeds unexpectedly.)