Make sure clean up doesn't add case and constr to comp time eval. Also had fun with test_1 mint script context validator

This commit is contained in:
microproofs 2025-01-09 21:23:48 +07:00
parent 33392f1532
commit 2c214186b6
No known key found for this signature in database
GPG Key ID: 14F93C84DE6AFD17
4 changed files with 47 additions and 14 deletions

View File

@ -3712,7 +3712,7 @@ impl<'a> CodeGenerator<'a> {
interner.program(&mut program);
let eval_program: Program<NamedDeBruijn> =
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<NamedDeBruijn> =
program.clean_up().try_into().unwrap();
program.clean_up(false).try_into().unwrap();
let evaluated_term: Term<NamedDeBruijn> = eval_program
.eval(ExBudget::default())
@ -4364,7 +4364,7 @@ impl<'a> CodeGenerator<'a> {
interner.program(&mut program);
let eval_program: Program<NamedDeBruijn> =
program.clean_up().try_into().unwrap();
program.clean_up(false).try_into().unwrap();
let evaluated_term: Term<NamedDeBruijn> = eval_program
.eval(ExBudget::default())
@ -4389,7 +4389,7 @@ impl<'a> CodeGenerator<'a> {
interner.program(&mut program);
let eval_program: Program<NamedDeBruijn> =
program.clean_up().try_into().unwrap();
program.clean_up(false).try_into().unwrap();
let evaluated_term: Term<NamedDeBruijn> = eval_program
.eval(ExBudget::default())
@ -4802,7 +4802,7 @@ impl<'a> CodeGenerator<'a> {
interner.program(&mut program);
let eval_program: Program<NamedDeBruijn> =
program.clean_up().try_into().unwrap();
program.clean_up(false).try_into().unwrap();
let evaluated_term: Term<NamedDeBruijn> = eval_program
.eval(ExBudget::default())

View File

@ -38,5 +38,5 @@ pub fn aiken_optimize_and_intern(program: Program<Name>) -> Program<Name> {
}
}
prog.clean_up()
prog.clean_up(true)
}

View File

@ -984,9 +984,6 @@ impl Term<Name> {
inline_lambda,
);
}
Term::Constr { .. } => todo!(),
Term::Case { .. } => todo!(),
other => other.traverse_uplc_with_helper(
scope,
arg_stack,
@ -1012,8 +1009,40 @@ impl Term<Name> {
}
}
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<Name> {
.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
}

View File

@ -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
}