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

remove hashbrown from id_to_pattern API #324

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/egraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ impl<L: Language, N: Analysis<L>> EGraph<L, N> {
let right_unions = other.get_union_equalities();
for (left, right, why) in right_unions {
self.union_instantiations(
&other.id_to_pattern(left, &Default::default()).0.ast,
&other.id_to_pattern(right, &Default::default()).0.ast,
&other.id_to_pattern(left, |_| None).0.ast,
&other.id_to_pattern(right, |_| None).0.ast,
&Default::default(),
why,
);
Expand Down Expand Up @@ -376,28 +376,32 @@ impl<L: Language, N: Analysis<L>> EGraph<L, N> {
/// When an eclass listed in the given substitutions is found, it creates a variable.
/// It also adds this variable and the corresponding Id value to the resulting [`Subst`]
/// Otherwise it behaves like [`id_to_expr`](EGraph::id_to_expr).
pub fn id_to_pattern(&self, id: Id, substitutions: &HashMap<Id, Id>) -> (Pattern<L>, Subst) {
pub fn id_to_pattern(
&self,
id: Id,
mut substitutions: impl FnMut(Id) -> Option<Id>,
) -> (Pattern<L>, Subst) {
let mut res = Default::default();
let mut subst = Default::default();
let mut cache = Default::default();
self.id_to_pattern_internal(&mut res, id, substitutions, &mut subst, &mut cache);
self.id_to_pattern_internal(&mut res, id, &mut substitutions, &mut subst, &mut cache);
(Pattern::new(res), subst)
}

fn id_to_pattern_internal(
&self,
res: &mut PatternAst<L>,
node_id: Id,
var_substitutions: &HashMap<Id, Id>,
var_substitutions: &mut impl FnMut(Id) -> Option<Id>,
subst: &mut Subst,
cache: &mut HashMap<Id, Id>,
) -> Id {
if let Some(existing) = cache.get(&node_id) {
return *existing;
}
let res_id = if let Some(existing) = var_substitutions.get(&node_id) {
let res_id = if let Some(existing) = var_substitutions(node_id) {
let var = format!("?{}", node_id).parse().unwrap();
subst.insert(var, *existing);
subst.insert(var, existing);
res.add(ENodeOrVar::Var(var))
} else {
let new_node = self.id_to_node(node_id).clone().map_children(|child| {
Expand Down
Loading