Skip to content

Commit

Permalink
fmt changes & bump to 0.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
memoryleak47 committed Oct 16, 2024
1 parent 49c7f70 commit 86bac40
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "slotted-egraphs"
version = "0.0.8"
version = "0.0.9"
edition = "2021"
description = "E-Graphs with name binding"
license = "Apache-2.0 OR MIT"
Expand Down
4 changes: 2 additions & 2 deletions src/explain/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct ProvenEqRaw {
}

impl ProvenEqRaw {
pub fn null() -> ProvenEq {
pub(crate) fn null() -> ProvenEq {
let app_id = AppliedId::new(Id(0), Default::default());
Arc::new(ProvenEqRaw {
eq: Equation { l: app_id.clone(), r: app_id.clone() },
Expand All @@ -56,7 +56,7 @@ impl ProvenEqRaw {
(**self).clone()
}

pub fn check<L: Language, N: Analysis<L>>(&self, eg: &EGraph<L, N>) {
pub(crate) fn check<L: Language, N: Analysis<L>>(&self, eg: &EGraph<L, N>) {
let Equation { l, r } = self.equ();
eg.check_syn_applied_id(&l);
eg.check_syn_applied_id(&r);
Expand Down
22 changes: 7 additions & 15 deletions src/explain/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@ use crate::*;
type ShowMap = HashMap<*const ProvenEqRaw, (usize, String)>;

impl ProvenEqRaw {
pub fn show(&self) {
println!("{}", self.to_string());
}

pub fn show_expr<L: Language, N: Analysis<L>>(&self, eg: &EGraph<L, N>) {
println!("{}", self.to_string_expr(eg));
}

// to string API:

pub fn to_string(&self) -> String {
self.show_impl(&|i| format!("{i:?}"))
}

pub fn to_string_expr<L: Language, N: Analysis<L>>(&self, eg: &EGraph<L, N>) -> String {
/// Prints the proof steps.
pub fn to_string<L: Language, N: Analysis<L>>(&self, eg: &EGraph<L, N>) -> String {
self.show_impl(&|i| {
eg.get_syn_expr(i).to_string()
})
}

/// Prints the proof steps, using the internal [AppliedId]s to represent terms.
fn to_string_applied_ids(&self) -> String {
self.show_impl(&|i| format!("{i:?}"))
}

// internals:
pub(crate) fn show_impl(&self, f: &impl Fn(&AppliedId) -> String) -> String {
let mut map = Default::default();
Expand Down
4 changes: 2 additions & 2 deletions tests/arith/tst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn assert_reaches(start: &str, goal: &str, steps: usize) {
let i1 = lookup_rec_expr(&start, &eg).unwrap();
if eg.eq(&i1, &i2) {
#[cfg(feature = "explanations")]
eg.explain_equivalence(start, goal).show_expr(&eg);
println!("{}", eg.explain_equivalence(start, goal).to_string(&eg));
return;
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ fn t6() { // z*(x+y) = z*(y+x)
let i1 = lookup_rec_expr(&start, &eg).unwrap();
if eg.eq(&i1, &i2) {
#[cfg(feature = "explanations")]
eg.explain_equivalence(start, goal).show_expr(&eg);
println!("{}", eg.explain_equivalence(start, goal).to_string(&eg));
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/array/tst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn assert_reaches(start: &str, goal: &str, steps: usize, rules: &[&'static str])
if eg.eq(&i1, &i2) {
dbg!(eg.total_number_of_nodes());
#[cfg(feature = "explanations")]
eg.explain_equivalence(start, goal).show_expr(&eg);
println!("{}", eg.explain_equivalence(start, goal).to_string(&eg));
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn explain<L: Language>(s1: &str, s2: &str, eg: &mut EGraph<L>) {
let s1 = term(s1, eg);
let s2 = term(s2, eg);
#[cfg(feature = "explanations")]
eg.explain_equivalence(s1, s2).show_expr(eg);
println!("{}", eg.explain_equivalence(s1, s2).to_string(eg));
eg.check();
}

6 changes: 3 additions & 3 deletions tests/rise/tst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn assert_reaches(start: &str, goal: &str, steps: usize) {
if eg.eq(&i1, &i2) {
dbg!(eg.total_number_of_nodes());
#[cfg(feature = "explanations")]
eg.explain_equivalence(start, goal).show_expr(&eg);
println!("{}", eg.explain_equivalence(start, goal).to_string(&eg));
return;
}
}
Expand Down Expand Up @@ -166,7 +166,7 @@ fn small3() {
dbg!(&x1x3);
dbg!(&x2x3);
#[cfg(feature = "explanations")]
eg.explain_equivalence(x1x3, x2x3).show_expr(&eg);
println!("{}", eg.explain_equivalence(x1x3, x2x3).to_string(&eg));
}

#[test]
Expand All @@ -185,5 +185,5 @@ fn small2() {
eg.union(&y3, &y4);
eg.union(&y2, &y3);
#[cfg(feature = "explanations")]
eg.explain_equivalence(x1, x4).show_expr(&eg);
println!("{}", eg.explain_equivalence(x1, x4).to_string(&eg));
}

0 comments on commit 86bac40

Please sign in to comment.