From c9c1b0f517b69a98b6d1c5ba811449a193d5fa53 Mon Sep 17 00:00:00 2001 From: Ryan Tjoa Date: Fri, 26 Jan 2024 12:55:41 -0800 Subject: [PATCH] Disallow empty all --- tree_unique_args/src/disallow_empty_all.egg | 3 +++ tree_unique_args/src/disallow_empty_all.rs | 7 +++++++ tree_unique_args/src/lib.rs | 2 ++ 3 files changed, 12 insertions(+) create mode 100644 tree_unique_args/src/disallow_empty_all.egg create mode 100644 tree_unique_args/src/disallow_empty_all.rs diff --git a/tree_unique_args/src/disallow_empty_all.egg b/tree_unique_args/src/disallow_empty_all.egg new file mode 100644 index 000000000..0ef2cdc9c --- /dev/null +++ b/tree_unique_args/src/disallow_empty_all.egg @@ -0,0 +1,3 @@ +(rule ((ExprIsValid (All order (Nil)))) + ((panic "UnitExpr should be used instead of an empty All")) + :ruleset error-checking) diff --git a/tree_unique_args/src/disallow_empty_all.rs b/tree_unique_args/src/disallow_empty_all.rs new file mode 100644 index 000000000..0aebd0014 --- /dev/null +++ b/tree_unique_args/src/disallow_empty_all.rs @@ -0,0 +1,7 @@ +#[test] +#[should_panic] +fn empty_all_should_panic() { + let build = "(ExprIsValid (All (Parallel) (Nil)))"; + let check = ""; + let _ = crate::run_test(build, check); +} diff --git a/tree_unique_args/src/lib.rs b/tree_unique_args/src/lib.rs index 1caeddce1..45b478c37 100644 --- a/tree_unique_args/src/lib.rs +++ b/tree_unique_args/src/lib.rs @@ -2,6 +2,7 @@ pub mod ast; pub(crate) mod body_contains; pub(crate) mod conditional_invariant_code_motion; pub(crate) mod deep_copy; +pub(crate) mod disallow_empty_all; pub(crate) mod function_inlining; pub(crate) mod id_analysis; pub mod interpreter; @@ -142,6 +143,7 @@ pub fn run_test(build: &str, check: &str) -> Result { include_str!("sugar.egg"), &util::rules().join("\n"), &id_analysis::id_analysis_rules().join("\n"), + include_str!("disallow_empty_all.egg"), // optimizations include_str!("simple.egg"), include_str!("function_inlining.egg"),