Skip to content

Fallback regex vec#3

Merged
rdettai-sk merged 1 commit into
sekoiafrom
fallback-regex-vec
Jun 23, 2026
Merged

Fallback regex vec#3
rdettai-sk merged 1 commit into
sekoiafrom
fallback-regex-vec

Conversation

@rdettai-sk

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread src/regex/mod.rs
Comment on lines +74 to +77
pub enum DisjunctionRegex {
Single(Regex),
Multi(Vec<Regex>),
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't implement Automaton because I think it's better if the caller handles the disjunction and the calling code is monomorphized.

Comment thread src/regex/mod.rs

/// 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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from what I've seen Hir's display actually shows a horrible representation of the Hir

Comment thread src/regex/mod.rs
/// 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>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing to a slice here because we want to iterate over it 2x, and it's what we have in QW anyway

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DisjunctionRegex to represent either a single combined DFA (Single) or a fallback set of per-pattern DFAs (Multi).
  • Updates Regex::from_patterns to compile a combined alternation first and fall back to per-pattern compilation on Error::TooManyStates.
  • Adds an Automaton implementation for Vec<Regex> and updates tests to cover the fallback behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/regex/mod.rs
Comment thread src/regex/mod.rs
Comment thread src/regex/mod.rs Outdated
Comment thread src/regex/mod.rs
Comment thread src/regex/mod.rs
@rdettai-sk
rdettai-sk force-pushed the fallback-regex-vec branch from 8929d01 to 7d06262 Compare June 23, 2026 13:10
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

Successfully merging this pull request may close these issues.

3 participants