Skip to content

Commit

Permalink
Add a check for bad multipatterns
Browse files Browse the repository at this point in the history
  • Loading branch information
mwillsey committed Jun 12, 2024
1 parent de7086c commit ae2db37
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/multipattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ impl<L: Language, A: Analysis<L>> Searcher<L, A> for MultiPattern<L> {
eclass: Id,
limit: usize,
) -> Option<SearchMatches<L>> {
match self.asts.as_slice() {
[] => panic!("empty multipattern"),
[(_var, pat), ..] => {
if let [ENodeOrVar::Var(_)] = pat.as_ref() {
panic!(
"Bare cannot be first pattern variable in multipattern: {:?}",
self.asts
)
}
}
}
let substs = self.program.run_with_limit(egraph, eclass, limit);
if substs.is_empty() {
None
Expand Down Expand Up @@ -291,4 +302,16 @@ mod tests {
assert_ne!(runner.egraph.find(y1), runner.egraph.find(z1));
assert_ne!(runner.egraph.find(x1), runner.egraph.find(z1));
}

#[test]
fn bare_var() {
let mut g = EGraph::default();

g.add_expr(&"(f a)".parse().unwrap());
g.rebuild();

let p: MultiPattern<S> = "?a = (f ?x), ?y = ?y".parse().unwrap();
let rw = multi_rewrite!("r"; { p } => "?a = (g ?x ?y)");
rw.run(&mut g);
}
}

0 comments on commit ae2db37

Please sign in to comment.