Skip to content

Commit

Permalink
clear cache primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
oflatt committed Jan 15, 2025
1 parent 8775df9 commit 13f89bd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
36 changes: 35 additions & 1 deletion src/sort/bigrat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ impl Sort for BigRatSort {
eg.add_primitive(MatchOnce {
name: "match-once-unstable".into(),
});

eg.add_primitive(ClearMatchCache {
name: "clear-match-cache-unstable".into(),
});
}

fn extract_term(
Expand Down Expand Up @@ -188,7 +192,7 @@ impl PrimitiveLike for MatchOnce {
self.name
}

fn get_type_constraints(&self, span: &Span) -> Box<dyn TypeConstraint> {
fn get_type_constraints(&self, _span: &Span) -> Box<dyn TypeConstraint> {
Box::new(ReturnsLastConstraint::new())
}

Expand All @@ -209,3 +213,33 @@ impl PrimitiveLike for MatchOnce {
}
}
}

struct ClearMatchCache {
name: Symbol,
}

impl PrimitiveLike for ClearMatchCache {
fn name(&self) -> Symbol {
self.name
}

fn get_type_constraints(&self, span: &Span) -> Box<dyn TypeConstraint> {
Box::new(SimpleTypeConstraint::new(
self.name,
vec![Arc::new(UnitSort)],
span.clone(),
))
}

/// Clear the match cache
fn apply(
&self,
_values: &[Value],
_sorts: (&[ArcSort], &ArcSort),
_egraph: Option<&mut EGraph>,
) -> Option<Value> {
MATCHED.lock().unwrap().clear();
// return a dummy value
Some(Value::unit())
}
}
1 change: 0 additions & 1 deletion tests/match-once-test.egg
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
(relation matched (i64))

(rule ((= lhs (Neg child))
(match-once-unstable "myrule" child lhs)
(= child (Neg (Num n))))
((matched n)))

Expand Down

0 comments on commit 13f89bd

Please sign in to comment.