Skip to content
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

Taking preconditions seriously #102

Closed
5 tasks
jakobnissen opened this issue Jul 28, 2022 · 1 comment · Fixed by #119
Closed
5 tasks

Taking preconditions seriously #102

jakobnissen opened this issue Jul 28, 2022 · 1 comment · Fixed by #119

Comments

@jakobnissen
Copy link
Member

jakobnissen commented Jul 28, 2022

Automa already has preconditions - these are named Expr objects attached to edges, similar to actions. When encountering an edge, its code generators first check the byteset membership, then it evaluated the precondition's Expr, which must evaluate to a Bool, and takes the edge if evaluated to true. Preconditions are attached to regex, and apply to all transitions inside that regex.

In other words, preconditions enable you to state: Only move within this regex if this condition is fulfilled. This is particularly useful when dealing with ambiguous DFAs that can be disambiguated using preconditions - essentially, this is like manually inserting an if-statement into the finite state machine.

However, Automa's support for preconditions is shaky, and frankly, I believe, might be buggy. I did some experiments that seemed to suggest that Automa would collapse two NFA paths with different preconditions... which sort of defeats the purpose.
This needs to be thoroughly tested

  • Enable preconditions on "enter" only, in addition to the already existing "all"
  • Make sure not to collapse NFA paths with disambiguating preconditions on DFA creation. Then remove precond check in DFA validation code path
  • Have table-based generators support predond. Simply insert an if statement after state transition.
  • Check that edges with preconditions do not allow SIMD loops (just to be sure!)
  • Test, test, test and test more

In particular, I want something like this to work:

a1 = re"A"
a2 = re"A"
b1 = re"B"
b2 = re"B"
b2.when = :foo
c1 = re"C"
c1.actions[:enter] = [:bar]
Automa.compile((a1 * b1 * c1) | (a2 * b2 * re"C"))

, i.e. where otherwise indistinguishable paths a1-b1-c1 and a2-b2-c2 with conflicting actions are disambiguated by a precondition on b2.

@kescobo
Copy link
Member

kescobo commented Jul 28, 2022

Cool! This seems like it adds some complexity (or rather fixes something complicated... I didn't know this functionality existed), but that's probably necessary for a lot of biological formats.

@jakobnissen jakobnissen added this to the v1.0 milestone Mar 1, 2023
This was referenced Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants