Skip to content

Too eager cycle without backtracking #136

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

Open
hanickadot opened this issue Nov 8, 2020 · 2 comments
Open

Too eager cycle without backtracking #136

hanickadot opened this issue Nov 8, 2020 · 2 comments

Comments

@hanickadot
Copy link
Owner

(a|ab)+ won't match ab

Found a fix, it's in branch fix-for-cycles, created tests to trigger this error, but it's a big performance regression because compiler can't see thru and optimise deep recursion.

@Andersama
Copy link
Contributor

Andersama commented Jan 9, 2021

This also happens for (a|ab){1,1} but does not for (a|ab), for ordinary cases where select isn't repeated there's not much need to keep track too much state, where the branch occurred and what the last branch taken was is sufficient. If we're in a repeating section you'll have to keep track of that state for every step (which means I guess you'll be allocating) in order to unwind and try a different path.

I guess the upside is since this doesn't work properly you're safe from some really awful backtracking. With how this implementation works you could call this a fuzzy match/search/starts_with...there are no false positives, but may be some false negatives.

The pattern / issue holds for all (a|ab){N,N}* manually writing it out will work properly, having it written with the repeat syntax breaks.

@Andersama
Copy link
Contributor

Andersama commented Jan 9, 2021

Started thinking about this a bit more. Another way to consider this is that the current implementation is ok if sequence<<repeat<select<Options...>> Tail...> 's branches not only don't collide with Tail... but also don't collide with themselves. Unfortunately #94 / #166 Unrolling a selection wrapped by a repeat won't work here because they require a distinct branch. Which (a|ab)+ does not have.

It also gets worse, any select<> buried inside a repeat creates this issue sequence<<repeat<A...,select<Options...>,B...> Tail...>. Is equivalent to repeat<select<Options....>>,Tail...> given a bit of rewriting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants