- 
  Notifications
 You must be signed in to change notification settings 
- Fork 484
 automata: make behavior more consistent when WhichCaptures::None is used
 #1303
 
 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
 
 
 
 
 
 +86
 
 
 −7
 
 
 
 
 
 
 
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
 
 
 
 
 ... used Specifically, when used with `meta::Regex`. Before this PR, if callers built a `meta::Regex` with `WhichCaptures::None`, then it was possible for `find` to _sometimes_ return `Some` and _sometimes_ return `None`, just based on the sequence of previous search calls. In particular, when `WhichCaptures::None` is used, some regex engines (like the `PikeVM`) cannot report match offsets while some (like the lazy DFA) can. This meant that if the meta regex engine _happened_ to select the lazy DFA for a `Regex::find` call, then it would return `Some`. But if it _happened_ to select the Pike VM, then it would return `None`. Since engine selection can be influenced by the haystack itself, this leads to the behavior of `find` being tied to the contents of the haystack. Instead, what we should do is make it so anything that returns match offsets on a `meta::Regex` will always return `None` when `WhichCaptures::None` is used, _even_ if `Regex::is_match` returns `true`. (Yes, this is a weird option and it's crazy that `Regex::is_match` can return `true` while `Regex::find` can return `None`. This was already true before this PR and is a result of a very low level option that optimizes for memory usage in specific circumstances. This sort of whacky behavior can't be observed in the `regex` crate API. Only in `regex-automata`.)
 
 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.
 
 
 
 
Specifically, when used with
meta::Regex. Before this PR, if callersbuilt a
meta::RegexwithWhichCaptures::None, then it was possiblefor
findto sometimes returnSomeand sometimes returnNone,just based on the sequence of previous search calls.
In particular, when
WhichCaptures::Noneis used, some regex engines(like the
PikeVM) cannot report match offsets while some (like thelazy DFA) can. This meant that if the meta regex engine happened to
select the lazy DFA for a
Regex::findcall, then it would returnSome. But if it happened to select the Pike VM, then it would returnNone. Since engine selection can be influenced by the haystack itself,this leads to the behavior of
findbeing tied to the contents of thehaystack.
Instead, what we should do is make it so anything that returns match
offsets on a
meta::Regexwill always returnNonewhenWhichCaptures::Noneis used, even ifRegex::is_matchreturnstrue.(Yes, this is a weird option and it's crazy that
Regex::is_matchcanreturn
truewhileRegex::findcan returnNone. This was alreadytrue before this PR and is a result of a very low level option that
optimizes for memory usage in specific circumstances. This sort of
whacky behavior can't be observed in the
regexcrate API. Only inregex-automata.)