From cf7a9747ff17ac18491e2a7cb591d81b4f6f87a0 Mon Sep 17 00:00:00 2001 From: oflatt Date: Mon, 29 Jan 2024 12:19:57 -0800 Subject: [PATCH] fix unused results in tests --- tree_shared/src/id_analysis.rs | 8 +- tree_shared/src/ir.rs | 11 +- tree_shared/src/lib.rs | 2 + tree_shared/src/switch_rewrites.rs | 193 ----------------------------- tree_shared/src/type_analysis.rs | 6 +- 5 files changed, 19 insertions(+), 201 deletions(-) delete mode 100644 tree_shared/src/switch_rewrites.rs diff --git a/tree_shared/src/id_analysis.rs b/tree_shared/src/id_analysis.rs index c394e48fc..f1211c693 100644 --- a/tree_shared/src/id_analysis.rs +++ b/tree_shared/src/id_analysis.rs @@ -122,7 +122,7 @@ fn test_id_analysis_no_invalid_entry() { let build = "(let some-expr (Not (Boolean (Id (i64-fresh!)) false))"; let check = "(fail (check (ExprHasRefId some-expr any-id)))"; - let _ = crate::run_test(build, check); + crate::run_test(build, check).unwrap() } // Create an id conflict for an Expr on purpose and check that we catch it @@ -136,7 +136,7 @@ fn test_id_analysis_expr_id_conflict_panics_if_valid() { (ExprIsValid conflict-expr)"; let check = ""; - let _ = crate::run_test(build, check); + crate::run_test(build, check).unwrap() } #[test] @@ -150,7 +150,7 @@ fn test_id_analysis_listexpr_id_conflict_panics() { (ListExprIsValid conflict-expr)"; let check = ""; - let _ = crate::run_test(build, check); + crate::run_test(build, check).unwrap() } #[test] @@ -165,5 +165,5 @@ fn test_shared_unique_id_mix_panics() { (Num id2 1))) (ExprIsValid conflict-expr)"; let check = ""; - let _ = crate::run_test(build, check); + crate::run_test(build, check).unwrap() } diff --git a/tree_shared/src/ir.rs b/tree_shared/src/ir.rs index 00a4fe6bd..3693bd4fa 100644 --- a/tree_shared/src/ir.rs +++ b/tree_shared/src/ir.rs @@ -1,4 +1,7 @@ -use std::iter; +use std::{ + fmt::{Display, Formatter}, + iter, +}; use strum_macros::EnumIter; #[derive(Clone, Copy, Debug, PartialEq)] @@ -118,6 +121,12 @@ impl Field { } } +impl Display for Constructor { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.name()) + } +} + impl Constructor { pub(crate) fn name(&self) -> &'static str { match self { diff --git a/tree_shared/src/lib.rs b/tree_shared/src/lib.rs index 6f923d073..26659dfc4 100644 --- a/tree_shared/src/lib.rs +++ b/tree_shared/src/lib.rs @@ -1,5 +1,6 @@ pub mod ast; pub(crate) mod deep_copy; +pub(crate) mod error_checking; pub(crate) mod id_analysis; pub mod interpreter; pub(crate) mod ir; @@ -142,6 +143,7 @@ pub fn run_test(build: &str, check: &str) -> Result { &deep_copy::deep_copy_rules().join("\n"), include_str!("sugar.egg"), &util::rules().join("\n"), + &error_checking::error_checking_rules().join("\n"), &id_analysis::id_analysis_rules().join("\n"), // optimizations include_str!("simple.egg"), diff --git a/tree_shared/src/switch_rewrites.rs b/tree_shared/src/switch_rewrites.rs deleted file mode 100644 index c416ce594..000000000 --- a/tree_shared/src/switch_rewrites.rs +++ /dev/null @@ -1,193 +0,0 @@ -pub(crate) fn rules() -> String { - let equiv_when_b_pure = [ - ( - "(Switch (And a b) (Cons A (Cons B (Nil))))", - "(Switch a (Pair (Switch b (Pair A B)) B))", - ), - ( - "(Switch (Or a b) (Cons A (Cons B (Nil))))", - "(Switch a (Pair A (Switch b (Pair A B))))", - ), - ]; - let rules_needing_purity = equiv_when_b_pure - .map(|(e1, e2)| { - format!( - "(rewrite {e1} {e2} :when ((ExprIsPure b) (ExprIsValid {e1})) - :ruleset switch-rewrites) - (rewrite {e2} {e1} :when ((ExprIsPure b) (ExprIsValid {e2})) - :ruleset switch-rewrites)" - ) - }) - .join("\n"); - format!( - "(ruleset switch-rewrites) - - ; Constant condition elimination - (rewrite (Switch (Boolean id true) (Cons A (Cons B (Nil)))) - A - :when ((ExprIsValid (Switch (Boolean id true) (Cons A (Cons B (Nil)))))) - :ruleset switch-rewrites) - (rewrite (Switch (Boolean id false) (Cons A (Cons B (Nil)))) - B - :when ((ExprIsValid (Switch (Boolean id false) (Cons A (Cons B (Nil)))))) - :ruleset switch-rewrites) - - ; (if E then S1 else S2); S3 ==> if E then S1;S3 else S2;S3 - (rewrite (All id ord (Cons (Switch e (Cons S1 (Cons S2 (Nil)))) S3)) - (Switch e (Cons (All id ord (Cons S1 S3)) (Cons (All id ord (Cons S2 S3)) (Nil)))) - :ruleset switch-rewrites) - - {rules_needing_purity}" - ) -} - -#[test] -fn switch_rewrite_and() -> crate::Result { - let build = " -(let id (Id (i64-fresh!))) -(let switch (Switch (And (Boolean id false) (Boolean id true)) - (Pair (Num id 1) (Num id 2)))) -(ExprIsValid switch) - "; - let check = " -(check (= switch (Switch (Boolean id false) - (Pair (Switch (Boolean id true) - (Pair (Num id 1) (Num id 2))) - (Num id 2))))) - "; - crate::run_test(build, check) -} - -#[test] -fn switch_rewrite_or() -> crate::Result { - let build = " -(let id (Id (i64-fresh!))) -(let switch (Switch (Or (Boolean id false) (Boolean id true)) - (Pair (Num id 1) (Num id 2)))) -(ExprIsValid switch) - "; - let check = " -(check (= switch (Switch (Boolean id false) - (Pair (Num id 1) - (Switch (Boolean id true) - (Pair (Num id 1) (Num id 2))))))) - "; - crate::run_test(build, check) -} - -#[test] -fn switch_rewrite_purity() -> crate::Result { - let build = " -(let switch-id (Id (i64-fresh!))) -(let let-id (Id (i64-fresh!))) -(let impure (Let let-id (All switch-id (Parallel) (Nil)) (All let-id (Sequential) (Pair (Boolean let-id true) (Print (Num let-id 1)))))) -(let switch (Switch (And (Boolean switch-id false) (Get impure 0)) - (Pair (Num switch-id 1) (Num switch-id 2)))) -(ExprIsValid switch) - "; - let check = " -(fail (check (= switch (Switch (Boolean switch-id false) - (Pair (Switch (Get impure 0) - (Pair (Num switch-id 1) (Num switch-id 2))) - (Num switch-id 2)))))) - "; - crate::run_test(build, check)?; - - let build = " -(let switch-id (Id (i64-fresh!))) -(let let-id (Id (i64-fresh!))) -(let impure (Let let-id (All switch-id (Parallel) (Nil)) (All let-id (Sequential) (Cons (Boolean let-id true) (Nil))))) -(let switch (Switch (And (Boolean switch-id false) (Get impure 0)) - (Pair (Num switch-id 1) (Num switch-id 2)))) -(ExprIsValid switch) - "; - let check = " -(check (= switch (Switch (Boolean switch-id false) - (Pair (Switch (Get impure 0) - (Pair (Num switch-id 1) (Num switch-id 2))) - (Num switch-id 2))))) - "; - crate::run_test(build, check) -} - -#[test] -fn test_constant_condition() -> Result<(), egglog::Error> { - let build = " - (let id (Id (i64-fresh!))) - (let t (Boolean id true)) - (let f (Boolean id false)) - (let a (Num id 3)) - (let b (Num id 4)) - (let switch_t (Switch t (Cons a (Cons b (Nil))))) - (let switch_f (Switch f (Cons a (Cons b (Nil))))) - (ExprIsValid switch_t) - (ExprIsValid switch_f) - "; - let check = " - (check (= switch_t a)) - (check (= switch_f b)) - "; - crate::run_test(build, check) -} - -#[test] -fn switch_pull_in_below() -> Result<(), egglog::Error> { - let build = " - (let id (Id (i64-fresh!))) - (let c (Read (Num id 3))) - (let s1 (Read (Num id 4))) - (let s2 (Read (Num id 5))) - (let s3 (Read (Num id 6))) - - (let switch (Switch c (Cons s1 (Cons s2 (Nil))))) - (let lhs (All id (Sequential) (Cons switch (Cons s3 (Nil))))) - "; - let check = " - (let s1s3 (All id (Sequential) (Cons s1 (Cons s3 (Nil))))) - (let s2s3 (All id (Sequential) (Cons s2 (Cons s3 (Nil))))) - (let expected (Switch c (Cons s1s3 (Cons s2s3 (Nil))))) - (check (= lhs expected)) - "; - crate::run_test(build, check) -} - -#[test] -fn switch_interval() -> Result<(), egglog::Error> { - let build = " - (let id (Id (i64-fresh!))) - (let one (Num id 1)) - (let two (Num id 2)) - (let three (Num id 3)) - (let four (Num id 4)) - (let five (Num id 5)) - (let cc (LessThan two three)) - (let switch (Switch cc (Cons four (Cons five (Nil))))) - (ExprIsValid switch) - "; - let check = " - (check (= switch four)) - "; - crate::run_test(build, check) -} - -#[test] -fn switch_interval2() -> Result<(), egglog::Error> { - let build = " - (let id (Id (i64-fresh!))) - (let one (Num id 1)) - (let two (Num id 2)) - (let three (Num id 3)) - (let four (Num id 4)) - (let five (Num id 5)) - (let ten (Num id 10)) - (let c (Arg id)) - (let cc (LessThan two three)) - (let switch1 (Switch c (Cons four (Cons five (Nil))))) - (let switch (Switch (LessThan switch1 ten) (Cons two (Cons two (Nil))))) - (ExprIsValid switch) - "; - let check = " - (check (= switch two)) - "; - crate::run_test(build, check) -} diff --git a/tree_shared/src/type_analysis.rs b/tree_shared/src/type_analysis.rs index 2b950998a..0bc2d9b2c 100644 --- a/tree_shared/src/type_analysis.rs +++ b/tree_shared/src/type_analysis.rs @@ -163,7 +163,7 @@ fn loop_pred_boolean() { (run-schedule (saturate type-analysis))"; let check = ""; - let _ = crate::run_test(build, check); + crate::run_test(build, check).unwrap() } #[test] @@ -176,7 +176,7 @@ fn loop_args1() { (run-schedule (saturate type-analysis))"; let check = ""; - let _ = crate::run_test(build, check); + crate::run_test(build, check).unwrap() } #[test] @@ -194,5 +194,5 @@ fn loop_args3() { (run-schedule (saturate type-analysis))"; let check = ""; - let _ = crate::run_test(build, check); + crate::run_test(build, check).unwrap() }