From 86bac40666429c78c6d19b2a2e71bf6ebdfa211a Mon Sep 17 00:00:00 2001 From: memoryleak47 Date: Wed, 16 Oct 2024 14:04:49 +0200 Subject: [PATCH] fmt changes & bump to 0.0.9 --- Cargo.toml | 2 +- src/explain/proof.rs | 4 ++-- src/explain/show.rs | 22 +++++++--------------- tests/arith/tst.rs | 4 ++-- tests/array/tst.rs | 2 +- tests/entry.rs | 2 +- tests/rise/tst.rs | 6 +++--- 7 files changed, 17 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 85e7959..15a5cad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/explain/proof.rs b/src/explain/proof.rs index 8e712c1..237d820 100644 --- a/src/explain/proof.rs +++ b/src/explain/proof.rs @@ -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() }, @@ -56,7 +56,7 @@ impl ProvenEqRaw { (**self).clone() } - pub fn check>(&self, eg: &EGraph) { + pub(crate) fn check>(&self, eg: &EGraph) { let Equation { l, r } = self.equ(); eg.check_syn_applied_id(&l); eg.check_syn_applied_id(&r); diff --git a/src/explain/show.rs b/src/explain/show.rs index 5bcca30..f100859 100644 --- a/src/explain/show.rs +++ b/src/explain/show.rs @@ -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>(&self, eg: &EGraph) { - 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>(&self, eg: &EGraph) -> String { + /// Prints the proof steps. + pub fn to_string>(&self, eg: &EGraph) -> 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(); diff --git a/tests/arith/tst.rs b/tests/arith/tst.rs index f85d7bf..74c6d7b 100644 --- a/tests/arith/tst.rs +++ b/tests/arith/tst.rs @@ -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; } } @@ -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; } } diff --git a/tests/array/tst.rs b/tests/array/tst.rs index f307de1..15ccbdb 100644 --- a/tests/array/tst.rs +++ b/tests/array/tst.rs @@ -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; } } diff --git a/tests/entry.rs b/tests/entry.rs index 836ee5f..08a86f5 100644 --- a/tests/entry.rs +++ b/tests/entry.rs @@ -63,7 +63,7 @@ pub fn explain(s1: &str, s2: &str, eg: &mut EGraph) { 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(); } diff --git a/tests/rise/tst.rs b/tests/rise/tst.rs index 60760cf..1f925c2 100644 --- a/tests/rise/tst.rs +++ b/tests/rise/tst.rs @@ -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; } } @@ -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] @@ -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)); }