From 9023546976dbc85c299b047f6156bc40dfce90fc Mon Sep 17 00:00:00 2001 From: Andrew Cheung Date: Wed, 13 Nov 2024 15:36:11 -0800 Subject: [PATCH 1/3] First pass at adding condition --- src/condition.rs | 183 +++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 4 +- 2 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 src/condition.rs diff --git a/src/condition.rs b/src/condition.rs new file mode 100644 index 0000000..1c34366 --- /dev/null +++ b/src/condition.rs @@ -0,0 +1,183 @@ +use std::{str::FromStr, sync::Arc}; + +use egglog::{ + ast::{Span, Symbol}, + constraint::{SimpleTypeConstraint, TypeConstraint}, + sort::{BoolSort, Sort}, + ArcSort, PrimitiveLike, +}; +use ruler::enumo::Sexp; + +#[derive(Debug)] +pub struct DummySort { + // the language that a condition will operate on + sort: ArcSort, +} + +impl Sort for DummySort { + fn name(&self) -> Symbol { + "dummy".into() + } + + fn as_arc_any( + self: std::sync::Arc, + ) -> std::sync::Arc { + self + } + + fn make_expr( + &self, + _egraph: &egglog::EGraph, + _value: egglog::Value, + ) -> (usize, egglog::ast::Expr) { + (0, egglog::ast::Expr::lit_no_span(Symbol::from("dummy"))) + } + + fn register_primitives(self: std::sync::Arc, info: &mut egglog::TypeInfo) { + info.add_primitive(Condition { + name: "condition".into(), + sort: self.sort.clone(), + }); + } +} + +pub struct Condition { + name: Symbol, + sort: Arc, +} + +// (condition expr) -> bool +impl PrimitiveLike for Condition { + fn name(&self) -> Symbol { + self.name.clone() + } + + fn get_type_constraints(&self, span: &Span) -> Box { + SimpleTypeConstraint::new( + self.name(), + vec![self.sort.clone(), Arc::new(BoolSort::new("bool".into()))], + span.clone(), + ) + .into_box() + } + + fn apply( + &self, + values: &[egglog::Value], + egraph: Option<&mut egglog::EGraph>, + ) -> Option { + let sexp = Sexp::from_str(&egraph?.extract_value_to_string(values[0])).unwrap(); + + fn interp(sexp: &Sexp) -> i64 { + match sexp { + Sexp::Atom(_) => panic!(), + Sexp::List(l) => { + if let Sexp::Atom(op) = &l[0] { + match op.as_str() { + "Num" => { + if let Sexp::Atom(a) = &l[1] { + a.parse().unwrap() + } else { + panic!() + } + } + "Eq" => { + let a = interp(&l[1]); + let b = interp(&l[2]); + if a == b { + 1 + } else { + 0 + } + } + _ => panic!("Weird op {}", op), + } + } else { + panic!() + } + } + } + } + + println!("result of evaluating {}: {}", sexp, interp(&sexp) != 0); + + Some(egglog::Value::from(interp(&sexp) != 0)) + } +} + +pub mod tests { + use egglog::{sort::EqSort, SerializeConfig}; + + use super::*; + + #[test] + fn test_condition_create() { + let math_sort = Arc::new(EqSort { + name: "Math".into(), + }); + let dummy_sort = Arc::new(DummySort { + sort: math_sort.clone(), + }); + + let mut egraph = egglog::EGraph::default(); + + egraph.add_arcsort(math_sort.clone()).unwrap(); + egraph.add_arcsort(dummy_sort).unwrap(); + + egraph + .parse_and_run_program( + None, + r#" + (function Num (i64) Math) + (function Mul (Math Math) Math) + (function Eq (Math Math) Math) + + (relation universe (Math)) + (relation has-val (Math bool)) + "#, + ) + .unwrap(); + + egraph + .parse_and_run_program( + None, + r#" + (rule + ( + (universe ?e) + (= ?e (Eq ?a ?b)) + ) + ((has-val ?e (condition ?e))) + ) + + (rule + ( + (has-val ?c true) + (= ?c (Eq ?e (Num 1))) + ) + ( + (union ?e (Mul ?e ?e)) + ) + ) + "#, + ) + .unwrap(); + + egraph + .parse_and_run_program( + None, + r#" + (universe (Num 1)) + (universe (Eq (Num 1) (Num 1))) + "#, + ) + .unwrap(); + + egraph.parse_and_run_program(None, "(run 1000)").unwrap(); + + let serialized = egraph.serialize(SerializeConfig::default()); + serialized.to_svg_file("condition.svg").unwrap(); + } +} + +// small accessibility nit: slide 4 has similar colors. diff --git a/src/lib.rs b/src/lib.rs index c23baff..c6c5f36 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,10 +7,10 @@ use std::fmt::Debug; use std::hash::Hash; use std::str::FromStr; -use ruler::enumo::{Sexp, Workload}; - use log::info; +use ruler::enumo::{Sexp, Workload}; +pub mod condition; pub mod utils; pub type Constant = ::Constant; From 55bca121830dbb9aae7bbb59bf77b6eeac47e933 Mon Sep 17 00:00:00 2001 From: Andrew Cheung Date: Thu, 14 Nov 2024 15:00:37 -0800 Subject: [PATCH 2/3] Apply condition more-betterly --- src/condition.rs | 183 ------------------------------------ src/ite.rs | 199 ++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 64 ++++++------- src/utils.rs | 1 + tests/egglog/halide.egg | 44 ++++----- tests/halide.rs | 47 +++++++++- 6 files changed, 292 insertions(+), 246 deletions(-) delete mode 100644 src/condition.rs create mode 100644 src/ite.rs diff --git a/src/condition.rs b/src/condition.rs deleted file mode 100644 index 1c34366..0000000 --- a/src/condition.rs +++ /dev/null @@ -1,183 +0,0 @@ -use std::{str::FromStr, sync::Arc}; - -use egglog::{ - ast::{Span, Symbol}, - constraint::{SimpleTypeConstraint, TypeConstraint}, - sort::{BoolSort, Sort}, - ArcSort, PrimitiveLike, -}; -use ruler::enumo::Sexp; - -#[derive(Debug)] -pub struct DummySort { - // the language that a condition will operate on - sort: ArcSort, -} - -impl Sort for DummySort { - fn name(&self) -> Symbol { - "dummy".into() - } - - fn as_arc_any( - self: std::sync::Arc, - ) -> std::sync::Arc { - self - } - - fn make_expr( - &self, - _egraph: &egglog::EGraph, - _value: egglog::Value, - ) -> (usize, egglog::ast::Expr) { - (0, egglog::ast::Expr::lit_no_span(Symbol::from("dummy"))) - } - - fn register_primitives(self: std::sync::Arc, info: &mut egglog::TypeInfo) { - info.add_primitive(Condition { - name: "condition".into(), - sort: self.sort.clone(), - }); - } -} - -pub struct Condition { - name: Symbol, - sort: Arc, -} - -// (condition expr) -> bool -impl PrimitiveLike for Condition { - fn name(&self) -> Symbol { - self.name.clone() - } - - fn get_type_constraints(&self, span: &Span) -> Box { - SimpleTypeConstraint::new( - self.name(), - vec![self.sort.clone(), Arc::new(BoolSort::new("bool".into()))], - span.clone(), - ) - .into_box() - } - - fn apply( - &self, - values: &[egglog::Value], - egraph: Option<&mut egglog::EGraph>, - ) -> Option { - let sexp = Sexp::from_str(&egraph?.extract_value_to_string(values[0])).unwrap(); - - fn interp(sexp: &Sexp) -> i64 { - match sexp { - Sexp::Atom(_) => panic!(), - Sexp::List(l) => { - if let Sexp::Atom(op) = &l[0] { - match op.as_str() { - "Num" => { - if let Sexp::Atom(a) = &l[1] { - a.parse().unwrap() - } else { - panic!() - } - } - "Eq" => { - let a = interp(&l[1]); - let b = interp(&l[2]); - if a == b { - 1 - } else { - 0 - } - } - _ => panic!("Weird op {}", op), - } - } else { - panic!() - } - } - } - } - - println!("result of evaluating {}: {}", sexp, interp(&sexp) != 0); - - Some(egglog::Value::from(interp(&sexp) != 0)) - } -} - -pub mod tests { - use egglog::{sort::EqSort, SerializeConfig}; - - use super::*; - - #[test] - fn test_condition_create() { - let math_sort = Arc::new(EqSort { - name: "Math".into(), - }); - let dummy_sort = Arc::new(DummySort { - sort: math_sort.clone(), - }); - - let mut egraph = egglog::EGraph::default(); - - egraph.add_arcsort(math_sort.clone()).unwrap(); - egraph.add_arcsort(dummy_sort).unwrap(); - - egraph - .parse_and_run_program( - None, - r#" - (function Num (i64) Math) - (function Mul (Math Math) Math) - (function Eq (Math Math) Math) - - (relation universe (Math)) - (relation has-val (Math bool)) - "#, - ) - .unwrap(); - - egraph - .parse_and_run_program( - None, - r#" - (rule - ( - (universe ?e) - (= ?e (Eq ?a ?b)) - ) - ((has-val ?e (condition ?e))) - ) - - (rule - ( - (has-val ?c true) - (= ?c (Eq ?e (Num 1))) - ) - ( - (union ?e (Mul ?e ?e)) - ) - ) - "#, - ) - .unwrap(); - - egraph - .parse_and_run_program( - None, - r#" - (universe (Num 1)) - (universe (Eq (Num 1) (Num 1))) - "#, - ) - .unwrap(); - - egraph.parse_and_run_program(None, "(run 1000)").unwrap(); - - let serialized = egraph.serialize(SerializeConfig::default()); - serialized.to_svg_file("condition.svg").unwrap(); - } -} - -// small accessibility nit: slide 4 has similar colors. diff --git a/src/ite.rs b/src/ite.rs new file mode 100644 index 0000000..58efd09 --- /dev/null +++ b/src/ite.rs @@ -0,0 +1,199 @@ +use std::{str::FromStr, sync::Arc}; + +use std::fmt::Debug; + +use egglog::{ + ast::{Span, Symbol}, + constraint::{SimpleTypeConstraint, TypeConstraint}, + sort::{BoolSort, Sort}, + ArcSort, PrimitiveLike, +}; +use ruler::enumo::Sexp; + +pub trait PredicateInterpreter: Debug + Send + Sync { + fn interp_cond(&self, sexp: &Sexp) -> bool; +} + +#[derive(Debug)] +pub struct DummySort { + // the language that a condition will operate on + pub sort: ArcSort, + pub interpreter: Arc, +} + +impl Sort for DummySort { + fn name(&self) -> Symbol { + "dummy".into() + } + + fn as_arc_any( + self: std::sync::Arc, + ) -> std::sync::Arc { + self + } + + fn make_expr( + &self, + _egraph: &egglog::EGraph, + _value: egglog::Value, + ) -> (usize, egglog::ast::Expr) { + (0, egglog::ast::Expr::lit_no_span(Symbol::from("dummy"))) + } + + fn register_primitives(self: std::sync::Arc, info: &mut egglog::TypeInfo) { + info.add_primitive(Ite { + name: "ite".into(), + sort: self.sort.clone(), + interpreter: self.interpreter.clone(), + }); + } +} + +pub struct Ite { + name: Symbol, + sort: Arc, + interpreter: Arc, +} + +// (ite pred_expr expr expr) -> expr. +// will evaluate to first expr if pred_expr = true (according to interpreter semantics), else the other expr. +impl PrimitiveLike for Ite { + fn name(&self) -> Symbol { + self.name.clone() + } + + fn get_type_constraints(&self, span: &Span) -> Box { + SimpleTypeConstraint::new( + self.name(), + vec![ + self.sort.clone(), + self.sort.clone(), + self.sort.clone(), + self.sort.clone(), + ], + span.clone(), + ) + .into_box() + } + + fn apply( + &self, + values: &[egglog::Value], + egraph: Option<&mut egglog::EGraph>, + ) -> Option { + let egraph = egraph.unwrap(); + let sexp = Sexp::from_str(&egraph.extract_value_to_string(values[0])).unwrap(); + + println!("apply on {}", sexp); + + if self.interpreter.interp_cond(&sexp) { + Some(values[1].clone()) + } else { + Some(values[2].clone()) + } + } +} + +pub mod tests { + use egglog::{sort::EqSort, SerializeConfig}; + + use super::*; + + #[test] + fn test_ite_create() { + #[derive(Debug)] + struct MathInterpreter; + + impl PredicateInterpreter for MathInterpreter { + fn interp_cond(&self, sexp: &Sexp) -> bool { + fn interp_internal(sexp: &Sexp) -> i64 { + match sexp { + Sexp::Atom(atom) => panic!("Unexpected atom: {}", atom), + Sexp::List(l) => { + if let Sexp::Atom(op) = &l[0] { + match op.as_str() { + "Eq" => { + let a = interp_internal(&l[1]); + let b = interp_internal(&l[2]); + if a == b { + 1 + } else { + 0 + } + } + "Mul" => interp_internal(&l[1]) * interp_internal(&l[2]), + "Num" => l[1].to_string().parse().unwrap(), + _ => panic!("Unexpected operator: {:?}", op), + } + } else { + panic!("Unexpected list operator: {:?}", l[0]); + } + } + } + } + + interp_internal(sexp) == 1 + } + } + + let math_sort = Arc::new(EqSort { + name: "Math".into(), + }); + let dummy_sort = Arc::new(DummySort { + sort: math_sort.clone(), + interpreter: Arc::new(MathInterpreter), + }); + + let mut egraph = egglog::EGraph::default(); + + egraph.add_arcsort(math_sort.clone()).unwrap(); + egraph.add_arcsort(dummy_sort).unwrap(); + + egraph + .parse_and_run_program( + None, + r#" + (function Num (i64) Math) + (function Mul (Math Math) Math) + (function Eq (Math Math) Math) + + (relation universe (Math)) + "#, + ) + .unwrap(); + + egraph + .parse_and_run_program( + None, + r#" + (rule + ((universe ?e)) + ((union ?e (ite (Eq ?e (Num 1)) (Mul ?e ?e) ?e))) + ) + + "#, + ) + .unwrap(); + + egraph + .parse_and_run_program( + None, + r#" + (universe (Mul (Num 1) (Num 1))) + (universe (Num 1)) + (universe (Num 2)) + "#, + ) + .unwrap(); + + egraph.parse_and_run_program(None, "(run 1000)").unwrap(); + + egraph + .parse_and_run_program(None, "(check (= (Mul (Num 1) (Num 1)) (Num 1)))") + .unwrap(); + + egraph + .parse_and_run_program(None, "(fail (check (= (Mul (Num 2) (Num 2)) (Num 2))))") + .unwrap(); + } +} diff --git a/src/lib.rs b/src/lib.rs index c6c5f36..5f92d59 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ use egglog::{EGraph, SerializeConfig}; use ruler::enumo::Pattern; use ruler::{HashMap, HashSet, ValidationResult}; -use utils::TERM_PLACEHOLDER; +use utils::{TERM_PLACEHOLDER, UNIVERSAL_RELATION}; use std::fmt::Debug; use std::hash::Hash; @@ -10,7 +10,7 @@ use std::str::FromStr; use log::info; use ruler::enumo::{Sexp, Workload}; -pub mod condition; +pub mod ite; pub mod utils; pub type Constant = ::Constant; @@ -71,11 +71,6 @@ pub trait Chomper { for current_size in 0..MAX_SIZE { info!("adding programs of size {}:", current_size); - // let mut filter = Filter::MetricEq(Metric::Atoms, current_size); - // if current_size > 4 { - // filter = Filter::And(vec![filter, Filter::Excludes(self.constant_pattern())]); - // } - info!("finding eclass term map..."); let eclass_term_map = self .reset_eclass_term_map(egraph) @@ -388,35 +383,31 @@ pub trait Chomper { .unwrap(); } - fn add_conditional_rewrite( - &mut self, - _egraph: &mut EGraph, - _cond: Sexp, - _lhs: Sexp, - _rhs: Sexp, - ) { + fn add_conditional_rewrite(&mut self, egraph: &mut EGraph, cond: Sexp, lhs: Sexp, rhs: Sexp) { // TODO: @ninehusky: let's brainstorm ways to encode conditional equality with respect to a // specific condition (see #20). - // let _pred = self.make_string_not_bad(cond.to_string().as_str()); - // let term1 = self.make_string_not_bad(lhs.to_string().as_str()); - // let term2 = self.make_string_not_bad(rhs.to_string().as_str()); - // info!( - // "adding conditional rewrite: {} -> {} if {}", - // term1, term2, _pred - // ); - // info!("term2 has cvec: {:?}", self.interpret_term(&rhs)); - // egraph - // .parse_and_run_program( - // None, - // format!( - // r#" - // (cond-equal {term1} {term2}) - // (cond-equal {term2} {term1}) - // "# - // ) - // .as_str(), - // ) - // .unwrap(); + let cond = self.make_string_not_bad(cond.to_string().as_str()); + let term1 = self.make_string_not_bad(lhs.to_string().as_str()); + let term2 = self.make_string_not_bad(rhs.to_string().as_str()); + + info!( + "adding conditional rewrite: if {} then {} -> {}", + cond, term1, term2 + ); + + let cond_rewrite_prog = format!( + r#" + (rule + (({UNIVERSAL_RELATION} {term1})) + ((union {term1} (ite {cond} {term2} {term1})))) + "# + ); + + println!("cond rewrite prog: {}", cond_rewrite_prog); + + egraph + .parse_and_run_program(None, &cond_rewrite_prog) + .unwrap(); } fn has_var(&self, term: &Sexp) -> bool { @@ -433,13 +424,14 @@ pub trait Chomper { } } + fn language_name() -> String; fn productions(&self) -> Workload; fn atoms(&self) -> Workload; fn make_preds(&self) -> Workload; fn get_env(&self) -> &HashMap>; fn validate_rule(&self, rule: &Rule) -> ValidationResult; - fn interpret_term(&mut self, term: &ruler::enumo::Sexp) -> CVec; - fn interpret_pred(&mut self, term: &ruler::enumo::Sexp) -> Vec; + fn interpret_term(&self, term: &ruler::enumo::Sexp) -> CVec; + fn interpret_pred(&self, term: &ruler::enumo::Sexp) -> Vec; fn constant_pattern(&self) -> Pattern; fn matches_var_pattern(&self, term: &Sexp) -> bool; } diff --git a/src/utils.rs b/src/utils.rs index 3d3c5db..09ec5b7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,6 +4,7 @@ use ruler::enumo::Sexp; // Atoms with this name will `not` count in a production // toward its size. pub const TERM_PLACEHOLDER: &str = "?term"; +pub const UNIVERSAL_RELATION: &str = "universe"; pub fn get_production_size(term: &Sexp) -> usize { get_size(term, true) diff --git a/tests/egglog/halide.egg b/tests/egglog/halide.egg index e5b15d7..72f0b49 100644 --- a/tests/egglog/halide.egg +++ b/tests/egglog/halide.egg @@ -1,29 +1,29 @@ ;;; Halide language definition. -(datatype Expr - (Lit i64) - (Var String) - (Lt Expr Expr) - (Leq Expr Expr) - (Eq Expr Expr) - (Neq Expr Expr) - (Implies Expr Expr) - (Not Expr) - (Neg Expr) - (And Expr Expr) - (Or Expr Expr) - (Xor Expr Expr) - (Add Expr Expr) - (Sub Expr Expr) - (Mul Expr Expr) - (Div Expr Expr) - (Min Expr Expr) - (Max Expr Expr) - (Select Expr Expr Expr) -) +(function Lit (i64) HalideExpr) +(function Var (String) HalideExpr) +(function Lt (HalideExpr HalideExpr) HalideExpr) +(function Leq (HalideExpr HalideExpr) HalideExpr) +(function Eq (HalideExpr HalideExpr) HalideExpr) +(function Neq (HalideExpr HalideExpr) HalideExpr) +(function Implies (HalideExpr HalideExpr) HalideExpr) +(function Not (HalideExpr) HalideExpr) +(function Neg (HalideExpr) HalideExpr) +(function And (HalideExpr HalideExpr) HalideExpr) +(function Or (HalideExpr HalideExpr) HalideExpr) +(function Xor (HalideExpr HalideExpr) HalideExpr) +(function Add (HalideExpr HalideExpr) HalideExpr) +(function Sub (HalideExpr HalideExpr) HalideExpr) +(function Mul (HalideExpr HalideExpr) HalideExpr) +(function Div (HalideExpr HalideExpr) HalideExpr) +(function Min (HalideExpr HalideExpr) HalideExpr) +(function Max (HalideExpr HalideExpr) HalideExpr) +(function Select (HalideExpr HalideExpr HalideExpr) HalideExpr) -(function eclass (Expr) i64 :merge (min old new)) +(function eclass (HalideExpr) i64 :merge (min old new)) + +(relation universe (HalideExpr)) (ruleset eclass-report) (ruleset non-cond-rewrites) diff --git a/tests/halide.rs b/tests/halide.rs index a51ec00..3c1ddd2 100644 --- a/tests/halide.rs +++ b/tests/halide.rs @@ -5,6 +5,8 @@ use ruler::{ HashMap, ValidationResult, }; +use std::str::FromStr; + use z3::ast::Ast; use chompy::utils::TERM_PLACEHOLDER; @@ -12,6 +14,7 @@ use num::Zero; pub const CVEC_LEN: usize = 20; +#[derive(Debug, Clone)] pub struct HalideChomper { pub env: ruler::HashMap>, } @@ -20,6 +23,10 @@ impl Chomper for HalideChomper { type Constant = i64; type Value = i64; + fn language_name() -> String { + "HalideExpr".to_string() + } + fn productions(&self) -> ruler::enumo::Workload { Workload::new(&[ format!( @@ -54,7 +61,7 @@ impl Chomper for HalideChomper { fn constant_pattern(&self) -> ruler::enumo::Pattern { "(Lit ?x)".parse().unwrap() } - fn interpret_term(&mut self, term: &ruler::enumo::Sexp) -> chompy::CVec { + fn interpret_term(&self, term: &ruler::enumo::Sexp) -> chompy::CVec { match term { Sexp::Atom(a) => panic!("Unexpected atom {}", a), Sexp::List(l) => { @@ -216,7 +223,7 @@ impl Chomper for HalideChomper { } } - fn interpret_pred(&mut self, term: &ruler::enumo::Sexp) -> Vec { + fn interpret_pred(&self, term: &ruler::enumo::Sexp) -> Vec { let cvec = self.interpret_term(term); cvec.iter() .map(|x| { @@ -407,17 +414,47 @@ fn sexp_to_z3<'a>(ctx: &'a z3::Context, sexp: &Sexp) -> z3::ast::Int<'a> { } pub mod tests { - use chompy::init_egraph; - use egglog::EGraph; + use std::sync::Arc; + + use chompy::{init_egraph, ite::DummySort}; + use egglog::{sort::EqSort, EGraph}; use super::*; #[test] - fn try_inference() { + fn run_halide_chomper() { let env = HalideChomper::make_env(&mut StdRng::seed_from_u64(0)); let mut chomper = HalideChomper { env }; let mut egraph = EGraph::default(); + + #[derive(Debug)] + struct HalidePredicateInterpreter { + chomper: HalideChomper, + } + + impl chompy::ite::PredicateInterpreter for HalidePredicateInterpreter { + fn interp_cond(&self, sexp: &Sexp) -> bool { + let cvec = self.chomper.clone().interpret_term(sexp); + cvec.iter().all(|x| x.is_some() && x.unwrap() != 0) + } + } + + // TODO: this is only safe if we make sure the chomper doesn't actually store any state. + let pred_interpreter = HalidePredicateInterpreter { + chomper: chomper.clone(), + }; + + let halide_sort = Arc::new(EqSort { + name: "HalideExpr".into(), + }); + let dummy_sort = Arc::new(DummySort { + sort: halide_sort.clone(), + interpreter: Arc::new(pred_interpreter), + }); + egraph.add_arcsort(halide_sort.clone()).unwrap(); + egraph.add_arcsort(dummy_sort).unwrap(); init_egraph!(egraph, "./egglog/halide.egg"); + chomper.run_chompy(&mut egraph); } } From 7f64be36c377641b2a831479e388579444d27bba Mon Sep 17 00:00:00 2001 From: Andrew Cheung Date: Thu, 14 Nov 2024 15:12:23 -0800 Subject: [PATCH 3/3] Clippy --- src/ite.rs | 17 ++++++++++------- tests/halide.rs | 2 -- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/ite.rs b/src/ite.rs index 58efd09..941bdfb 100644 --- a/src/ite.rs +++ b/src/ite.rs @@ -1,11 +1,13 @@ use std::{str::FromStr, sync::Arc}; +use log::info; + use std::fmt::Debug; use egglog::{ ast::{Span, Symbol}, constraint::{SimpleTypeConstraint, TypeConstraint}, - sort::{BoolSort, Sort}, + sort::Sort, ArcSort, PrimitiveLike, }; use ruler::enumo::Sexp; @@ -59,7 +61,7 @@ pub struct Ite { // will evaluate to first expr if pred_expr = true (according to interpreter semantics), else the other expr. impl PrimitiveLike for Ite { fn name(&self) -> Symbol { - self.name.clone() + self.name } fn get_type_constraints(&self, span: &Span) -> Box { @@ -84,20 +86,21 @@ impl PrimitiveLike for Ite { let egraph = egraph.unwrap(); let sexp = Sexp::from_str(&egraph.extract_value_to_string(values[0])).unwrap(); - println!("apply on {}", sexp); + info!("apply on {}", sexp); if self.interpreter.interp_cond(&sexp) { - Some(values[1].clone()) + Some(values[1]) } else { - Some(values[2].clone()) + Some(values[2]) } } } +// idk why clippy complains about the two use statements below. +#[allow(unused_imports)] pub mod tests { - use egglog::{sort::EqSort, SerializeConfig}; - use super::*; + use egglog::sort::EqSort; #[test] fn test_ite_create() { diff --git a/tests/halide.rs b/tests/halide.rs index 3c1ddd2..06d6335 100644 --- a/tests/halide.rs +++ b/tests/halide.rs @@ -5,8 +5,6 @@ use ruler::{ HashMap, ValidationResult, }; -use std::str::FromStr; - use z3::ast::Ast; use chompy::utils::TERM_PLACEHOLDER;