for now comment out curry code so the rest of the changes

can be merged to main
This commit is contained in:
microproofs 2023-12-13 18:57:49 -05:00 committed by Kasey
parent c0c9f2f432
commit 2cd1379aec
2 changed files with 82 additions and 83 deletions

View File

@ -26,7 +26,6 @@ pub fn aiken_optimize_and_intern(program: Program<Name>) -> Program<Name> {
.cast_data_reducer() .cast_data_reducer()
.lambda_reducer() .lambda_reducer()
.inline_reducer() .inline_reducer()
.builtin_curry_reducer()
.lambda_reducer() .lambda_reducer()
.inline_reducer() .inline_reducer()
} }

View File

@ -17,7 +17,7 @@ pub enum BuiltinArgs {
} }
impl BuiltinArgs { impl BuiltinArgs {
fn args_from_arg_stack(stack: Vec<(usize, Term<Name>)>, is_order_agnostic: bool) -> Self { fn _args_from_arg_stack(stack: Vec<(usize, Term<Name>)>, is_order_agnostic: bool) -> Self {
let mut ordered_arg_stack = let mut ordered_arg_stack =
stack stack
.into_iter() .into_iter()
@ -907,100 +907,100 @@ impl Program<Name> {
}) })
} }
// WIP // WIP
pub fn builtin_curry_reducer(self) -> Program<Name> { // pub fn builtin_curry_reducer(self) -> Program<Name> {
let mut curried_terms = vec![]; // let mut curried_terms = vec![];
let mut curry_applied_ids: Vec<usize> = vec![]; // let mut curry_applied_ids: Vec<usize> = vec![];
let a = self.traverse_uplc_with(&mut |_id, term, arg_stack, scope| match term { // let a = self.traverse_uplc_with(&mut |_id, term, arg_stack, scope| match term {
Term::Builtin(func) => { // Term::Builtin(func) => {
if can_curry_builtin(*func) && arg_stack.len() == func.arity() { // if can_curry_builtin(*func) && arg_stack.len() == func.arity() {
let mut scope = scope.clone(); // let mut scope = scope.clone();
// Get upper scope of the function plus args // // Get upper scope of the function plus args
// So for example if the scope is [.., ARG, ARG, FUNC] // // So for example if the scope is [.., ARG, ARG, FUNC]
// we want to pop off the last 3 to get the scope right above the function applications // // we want to pop off the last 3 to get the scope right above the function applications
for _ in 0..func.arity() { // for _ in 0..func.arity() {
scope = scope.pop(); // scope = scope.pop();
} // }
let is_order_agnostic = is_order_agnostic_builtin(*func); // let is_order_agnostic = is_order_agnostic_builtin(*func);
// In the case of order agnostic builtins we want to sort the args by constant first // // In the case of order agnostic builtins we want to sort the args by constant first
// This gives us the opportunity to curry constants that often pop up in the code // // This gives us the opportunity to curry constants that often pop up in the code
let builtin_args = // let builtin_args =
BuiltinArgs::args_from_arg_stack(arg_stack, is_order_agnostic); // BuiltinArgs::args_from_arg_stack(arg_stack, is_order_agnostic);
// First we see if we have already curried this builtin before // // First we see if we have already curried this builtin before
if let Some(curried_builtin) = curried_terms // if let Some(curried_builtin) = curried_terms
.iter_mut() // .iter_mut()
.find(|curried_term: &&mut CurriedBuiltin| curried_term.func == *func) // .find(|curried_term: &&mut CurriedBuiltin| curried_term.func == *func)
{ // {
// We found it the builtin was curried before // // We found it the builtin was curried before
// So now we merge the new args into the existing curried builtin // // So now we merge the new args into the existing curried builtin
*curried_builtin = (*curried_builtin) // *curried_builtin = (*curried_builtin)
.clone() // .clone()
.merge_node_by_path(builtin_args, &scope); // .merge_node_by_path(builtin_args, &scope);
} else { // } else {
// Brand new buitlin so we add it to the list // // Brand new buitlin so we add it to the list
curried_terms.push(CurriedBuiltin { // curried_terms.push(CurriedBuiltin {
func: *func, // func: *func,
children: vec![builtin_args.args_to_curried_tree(&scope)], // children: vec![builtin_args.args_to_curried_tree(&scope)],
}); // });
} // }
} // }
} // }
Term::Constr { .. } => todo!(), // Term::Constr { .. } => todo!(),
Term::Case { .. } => todo!(), // Term::Case { .. } => todo!(),
_ => {} // _ => {}
}); // });
curried_terms = curried_terms // curried_terms = curried_terms
.into_iter() // .into_iter()
.map(|func| func.prune_single_occurrences()) // .map(|func| func.prune_single_occurrences())
.filter(|func| !func.children.is_empty()) // .filter(|func| !func.children.is_empty())
.collect_vec(); // .collect_vec();
println!("CURRIED ARGS"); // println!("CURRIED ARGS");
for (index, curried_term) in curried_terms.iter().enumerate() { // for (index, curried_term) in curried_terms.iter().enumerate() {
println!("index is {:#?}, term is {:#?}", index, curried_term); // println!("index is {:#?}, term is {:#?}", index, curried_term);
} // }
// TODO: add function to generate names for curried_terms for generating vars to insert // // TODO: add function to generate names for curried_terms for generating vars to insert
a.traverse_uplc_with(&mut |_id, term, arg_stack, scope| match term { // a.traverse_uplc_with(&mut |_id, term, arg_stack, scope| match term {
Term::Builtin(func) => { // Term::Builtin(func) => {
if can_curry_builtin(*func) { // if can_curry_builtin(*func) {
let Some(curried_builtin) = // let Some(curried_builtin) =
curried_terms.iter().find(|curry| curry.func == *func) // curried_terms.iter().find(|curry| curry.func == *func)
else { // else {
return; // return;
}; // };
let arg_stack_ids = arg_stack.iter().map(|(id, _)| *id).collect_vec(); // let arg_stack_ids = arg_stack.iter().map(|(id, _)| *id).collect_vec();
let builtin_args = BuiltinArgs::args_from_arg_stack( // let builtin_args = BuiltinArgs::args_from_arg_stack(
arg_stack, // arg_stack,
is_order_agnostic_builtin(*func), // is_order_agnostic_builtin(*func),
); // );
if let Some(_) = curried_builtin.children.iter().find(|child| { // if let Some(_) = curried_builtin.children.iter().find(|child| {
let x = (*child) // let x = (*child)
.clone() // .clone()
.merge_node_by_path(builtin_args.clone(), scope); // .merge_node_by_path(builtin_args.clone(), scope);
*child == &x // *child == &x
}) { // }) {
curry_applied_ids.extend(arg_stack_ids); // curry_applied_ids.extend(arg_stack_ids);
} else { // } else {
} // }
} // }
} // }
Term::Apply { function, argument } => todo!(), // Term::Apply { function, argument } => todo!(),
Term::Constr { .. } => todo!(), // Term::Constr { .. } => todo!(),
Term::Case { .. } => todo!(), // Term::Case { .. } => todo!(),
_ => {} // _ => {}
}) // })
} // }
} }
fn var_occurrences(term: &Term<Name>, search_for: Rc<Name>) -> usize { fn var_occurrences(term: &Term<Name>, search_for: Rc<Name>) -> usize {