Skip to content

RegexOptions.NonBacktracking fixed-length markers never triggered #65532

Closed

Description

@stephentoub

Running our regex tests with code coverage shows this for SymbolicRegexMatcher.FindMatch:
image
This suggests that there's something very wrong with that logic, as we definitely have tests that should trigger it, and it should either be fixed or all the "watchdog" logic deleted.

cc: @olsaarik, @veanes

Activity

  1. added this to the 7.0.0 milestone on Feb 17, 2022
  2. ghost added
    untriaged
    on Feb 17, 2022
  3. veanes commented on Feb 18, 2022

    @veanes
    Contributor

    @olsaarik The watchdog logic may have become something that is no longer triggered because of all the other optimizations.
    If this is the case it should be deleted, it may also cause conflict inside ordered-or. We'll discuss it also next week (Tuesday) on our separate weekly meeting with Olli.

  4. stephentoub commented on Feb 18, 2022

    @stephentoub
    MemberAuthor

    If we end up deleting it, presumably it would be sound to extend the phase 3 skipping based on whole-pattern fixed length from #65531 to also skip phase 2. That's not as comprehensive as the "watchdog" was meant to be, but it will get some of the cases, and it'd be easy.

  5. veanes commented on Feb 21, 2022

    @veanes
    Contributor

    I did some debugging. It seems there is a change in the converter code that at some point turned this feature off, so watchdogs are not inserted although they should be inserted:
    RegexNodeToSymbolicConverter.cs:
    where the concatenation topLevel:false in line 240, I think this is a bug
    not sure when or why this happened:

                    case RegexNodeKind.Capture when node.N == -1:
                        int captureNum;
                        if (_caps == null || !_caps.TryGetValue(node.M, out captureNum))
                            captureNum = node.M;
                        return _builder.MkCapture(Convert(node.Child(0), topLevel: false), captureNum);
    

    I believe the correct code should be the following where topLevel is the input parameter of the Convert method, unless there is another reason why topLevel was turned off (related to captures maybe?)
    @olsaarik could also take a look at this.

                    case RegexNodeKind.Capture when node.N == -1:
                        int captureNum;
                        if (_caps == null || !_caps.TryGetValue(node.M, out captureNum))
                            captureNum = node.M;
                        return _builder.MkCapture(Convert(node.Child(0), topLevel), captureNum);
    

    Watchdogs were only appended after top level concatenations, but here this info is turned off, so that later on, any potential watchdog is never appended even when fixed length is clearly detected.

  6. olsaarik commented on Feb 22, 2022

    @olsaarik
    Contributor

    @veanes Good find. This was not intended and that Convert call should indeed just pass in topLevel.

  7. veanes commented on Feb 22, 2022

    @veanes
    Contributor

    @olsaarik thanks for confirming this. I'll fix it with my next edits and also add an extra unit test I was using that should clearly trigger it, no matter what other optimizations are in place.

  8. stephentoub commented on Feb 28, 2022

    @stephentoub
    MemberAuthor

    The value is now being just passed along for a capture:

    return _builder.CreateCapture(ConvertToSymbolicRegexNode(node.Child(0), tryCreateFixedLengthMarker), captureNum);

    but it's still not being hit:
    image

  9. added and removed
    untriaged
    on Feb 28, 2022
  10. stephentoub commented on Apr 20, 2022

    @stephentoub
    MemberAuthor

    I was hoping this may have been addressed by #68199, but alas, it was not:
    image

  11. olsaarik commented on Jun 7, 2022

    @olsaarik
    Contributor

    This was fixed in #69839. Fixed length marker use was also further improved in #70217.

  12. ghost locked as resolved and limited conversation to collaborators on Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions