diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index 588edc00..55ba6ec6 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -3712,7 +3712,7 @@ impl<'a> CodeGenerator<'a> { interner.program(&mut program); let eval_program: Program = - program.clean_up().try_into().unwrap(); + program.clean_up(false).try_into().unwrap(); Some( eval_program @@ -3822,7 +3822,7 @@ impl<'a> CodeGenerator<'a> { interner.program(&mut program); let eval_program: Program = - program.clean_up().try_into().unwrap(); + program.clean_up(false).try_into().unwrap(); let evaluated_term: Term = eval_program .eval(ExBudget::default()) @@ -4364,7 +4364,7 @@ impl<'a> CodeGenerator<'a> { interner.program(&mut program); let eval_program: Program = - program.clean_up().try_into().unwrap(); + program.clean_up(false).try_into().unwrap(); let evaluated_term: Term = eval_program .eval(ExBudget::default()) @@ -4389,7 +4389,7 @@ impl<'a> CodeGenerator<'a> { interner.program(&mut program); let eval_program: Program = - program.clean_up().try_into().unwrap(); + program.clean_up(false).try_into().unwrap(); let evaluated_term: Term = eval_program .eval(ExBudget::default()) @@ -4802,7 +4802,7 @@ impl<'a> CodeGenerator<'a> { interner.program(&mut program); let eval_program: Program = - program.clean_up().try_into().unwrap(); + program.clean_up(false).try_into().unwrap(); let evaluated_term: Term = eval_program .eval(ExBudget::default()) diff --git a/crates/uplc/src/optimize.rs b/crates/uplc/src/optimize.rs index fd00a2c9..0b171217 100644 --- a/crates/uplc/src/optimize.rs +++ b/crates/uplc/src/optimize.rs @@ -38,5 +38,5 @@ pub fn aiken_optimize_and_intern(program: Program) -> Program { } } - prog.clean_up() + prog.clean_up(true) } diff --git a/crates/uplc/src/optimize/shrinker.rs b/crates/uplc/src/optimize/shrinker.rs index 1c67979a..54061831 100644 --- a/crates/uplc/src/optimize/shrinker.rs +++ b/crates/uplc/src/optimize/shrinker.rs @@ -984,9 +984,6 @@ impl Term { inline_lambda, ); } - - Term::Constr { .. } => todo!(), - Term::Case { .. } => todo!(), other => other.traverse_uplc_with_helper( scope, arg_stack, @@ -1012,8 +1009,40 @@ impl Term { } } - Term::Case { .. } => todo!(), - Term::Constr { .. } => todo!(), + Term::Case { constr, branches } => { + let constr = Rc::make_mut(constr); + constr.traverse_uplc_with_helper( + scope, + vec![], + id_gen, + with, + context, + inline_lambda, + ); + + for branch in branches { + branch.traverse_uplc_with_helper( + scope, + arg_stack.clone(), + id_gen, + with, + context, + inline_lambda, + ); + } + } + Term::Constr { fields, .. } => { + for field in fields { + field.traverse_uplc_with_helper( + scope, + vec![], + id_gen, + with, + context, + inline_lambda, + ); + } + } Term::Builtin(func) => { let mut args = vec![]; @@ -2051,10 +2080,12 @@ impl Program { .0 } - pub fn clean_up(self) -> Self { + pub fn clean_up(self, case: bool) -> Self { self.traverse_uplc_with(true, &mut |id, term, _arg_stack, scope, context| { term.remove_no_inlines(id, vec![], scope, context); - term.case_constr_apply_reducer(id, vec![], scope, context); + if case { + term.case_constr_apply_reducer(id, vec![], scope, context); + } }) .0 } diff --git a/examples/acceptance_tests/script_context/v3/validators/mint.ak b/examples/acceptance_tests/script_context/v3/validators/mint.ak index 7c7a59ef..8c6517df 100644 --- a/examples/acceptance_tests/script_context/v3/validators/mint.ak +++ b/examples/acceptance_tests/script_context/v3/validators/mint.ak @@ -83,6 +83,8 @@ fn assert_outputs( }, ) == list.at(outputs, 0) + trace @"This test validator has a higher hash than the one below. Change and try again." + expect Some( Output { @@ -134,7 +136,7 @@ fn assert_mint(mint: Value, our_policy_id: PolicyId, other_policy_id: PolicyId) /// validator test_2 { mint(_tmp2: Void, _policy_id: PolicyId, _transaction: Transaction) { - trace @"slfhioer7w8yru" + trace @"slhhioer7w8ypuga" True }