Fallback regex vec#3
Conversation
| pub enum DisjunctionRegex { | ||
| Single(Regex), | ||
| Multi(Vec<Regex>), | ||
| } |
There was a problem hiding this comment.
I didn't implement Automaton because I think it's better if the caller handles the disjunction and the calling code is monomorphized.
|
|
||
| /// Same as [`Regex::from_hir`], with an explicit compiled-size limit. | ||
| fn from_hir_with_size_limit(size: usize, hir: regex_syntax::hir::Hir) -> Result<Regex, Error> { | ||
| // `Hir`'s Display impl renders a valid, semantically-equivalent pattern |
There was a problem hiding this comment.
from what I've seen Hir's display actually shows a horrible representation of the Hir
| /// least one pattern should enforce that themselves. | ||
| #[inline] | ||
| pub fn from_patterns<I, S>(patterns: I) -> Result<Regex, Error> | ||
| pub fn from_patterns<S>(patterns: &[S]) -> Result<DisjunctionRegex, Error> |
There was a problem hiding this comment.
changing to a slice here because we want to iterate over it 2x, and it's what we have in QW anyway
5e99ba9 to
8929d01
Compare
There was a problem hiding this comment.
Pull request overview
This PR changes regex alternation compilation to avoid pathological DFA state explosion by falling back to compiling each pattern separately when a combined DFA exceeds the state limit.
Changes:
- Introduces
DisjunctionRegexto represent either a single combined DFA (Single) or a fallback set of per-pattern DFAs (Multi). - Updates
Regex::from_patternsto compile a combined alternation first and fall back to per-pattern compilation onError::TooManyStates. - Adds an
Automatonimplementation forVec<Regex>and updates tests to cover the fallback behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8929d01 to
7d06262
Compare
7d06262 to
6dabdf2
Compare
No description provided.