diff --git a/crates/uplc/src/optimize/shrinker.rs b/crates/uplc/src/optimize/shrinker.rs index c351dc48..ff1912a8 100644 --- a/crates/uplc/src/optimize/shrinker.rs +++ b/crates/uplc/src/optimize/shrinker.rs @@ -1653,6 +1653,8 @@ mod tests { optimize::interner::CodeGenInterner, }; + use super::NO_INLINE; + fn compare_optimization( mut expected: Program, mut program: Program, @@ -1890,7 +1892,7 @@ mod tests { } #[test] - fn identity_reduce_0_occurrence() { + fn identity_reduce_usage() { let program: Program = Program { version: (1, 0, 0), term: Term::sha2_256() @@ -1912,6 +1914,29 @@ mod tests { compare_optimization(expected, program, |p| p.identity_reducer()); } + #[test] + fn identity_reduce_0_occurrence() { + let program: Program = Program { + version: (1, 0, 0), + term: Term::sha2_256() + .apply(Term::var("x")) + .lambda("x") + .apply(Term::byte_string(vec![]).delay()) + .lambda("identity") + .apply(Term::var("y").lambda("y")), + }; + + let expected = Program { + version: (1, 0, 0), + term: Term::sha2_256() + .apply(Term::var("x")) + .lambda("x") + .apply(Term::byte_string(vec![]).delay()), + }; + + compare_optimization(expected, program, |p| p.identity_reducer()); + } + #[test] fn identity_reduce_param() { let program: Program = Program { @@ -1959,6 +1984,29 @@ mod tests { compare_optimization(expected, program, |p| p.identity_reducer()); } + #[test] + fn identity_reduce_no_inline() { + let program: Program = Program { + version: (1, 0, 0), + term: Term::sha2_256() + .apply(Term::var("identity").apply(Term::var("x"))) + .lambda("x") + .apply(Term::byte_string(vec![]).delay()) + .lambda("identity") + .apply(Term::var("y").lambda("y").lambda(NO_INLINE)), + }; + + let expected = Program { + version: (1, 0, 0), + term: Term::sha2_256() + .apply(Term::var("x")) + .lambda("x") + .apply(Term::byte_string(vec![]).delay()), + }; + + compare_optimization(expected, program, |p| p.identity_reducer()); + } + #[test] fn inline_reduce_delay_sha() { let program: Program = Program { @@ -1977,6 +2025,23 @@ mod tests { compare_optimization(expected, program, |p| p.inline_reducer()); } + #[test] + fn inline_reduce_0_occurrence() { + let program: Program = Program { + version: (1, 0, 0), + term: Term::sha2_256() + .lambda("x") + .apply(Term::byte_string(vec![]).delay()), + }; + + let expected = Program { + version: (1, 0, 0), + term: Term::sha2_256(), + }; + + compare_optimization(expected, program, |p| p.inline_reducer()); + } + #[test] fn wrap_data_reduce_i_data() { let program: Program = Program {