diff --git a/src/classic/clvm_tools/stages/stage_2/optimize.rs b/src/classic/clvm_tools/stages/stage_2/optimize.rs index ac3137c39..953d3d420 100644 --- a/src/classic/clvm_tools/stages/stage_2/optimize.rs +++ b/src/classic/clvm_tools/stages/stage_2/optimize.rs @@ -338,78 +338,72 @@ fn var_change_optimizer_cons_eval( new_eval_sexp_args, eval_f ) - } else { m! { - let _ = if DIAG_OPTIMIZATIONS { + } else { + if DIAG_OPTIMIZATIONS { print!("XXX does not seems_constant\n"); - }; + } - new_operands <- - proper_list( - allocator, - new_eval_sexp_args, - true).ok_or( - EvalErr( - new_eval_sexp_args, - "Must be a proper list".to_string() - ) - ); - - opt_operands <- + Ok(proper_list( + allocator, + new_eval_sexp_args, + true + ).map(|new_operands| { mapM( allocator, &mut new_operands.iter(), &|allocator, item| { optimize_sexp(allocator, *item, eval_f.clone()) } - ); - - non_constant_count <- foldM( - allocator, - &|allocator, acc, val| { - if DIAG_OPTIMIZATIONS { - print!( - "XXX opt_operands {} {}\n", - acc, - disassemble(allocator, val) - ); - } - let increment = - match allocator.sexp(val) { - SExp::Pair(val_first,_) => { - match allocator.sexp(val_first) { - SExp::Atom(b) => { - let vf_buf = allocator.buf(&b); - if vf_buf.len() != 1 || vf_buf[0] != 1 { - 1 - } else { - 0 + ).and_then(|opt_operands| m! { + non_constant_count <- foldM( + allocator, + &|allocator, acc, val| { + if DIAG_OPTIMIZATIONS { + print!( + "XXX opt_operands {} {}\n", + acc, + disassemble(allocator, val) + ); + } + let increment = + match allocator.sexp(val) { + SExp::Pair(val_first,_) => { + match allocator.sexp(val_first) { + SExp::Atom(b) => { + let vf_buf = allocator.buf(&b); + if vf_buf.len() != 1 || vf_buf[0] != 1 { + 1 + } else { + 0 + } + }, + _ => 0 } }, _ => 0 - } - }, - _ => 0 - }; - - Ok(acc + increment) - }, - 0, - &mut opt_operands.iter().map(|x| *x) - ); + }; - let _ = if DIAG_OPTIMIZATIONS { - print!( - "XXX non_constant_count {}\n", - non_constant_count - ); - }; + Ok(acc + increment) + }, + 0, + &mut opt_operands.iter().map(|x| *x) + ); - if non_constant_count < 1 { - enlist(allocator, &opt_operands) - } else { - Ok(r) - } - } } + let _ = if DIAG_OPTIMIZATIONS { + print!( + "XXX non_constant_count {}\n", + non_constant_count + ); + }; + + if non_constant_count < 1 { + enlist(allocator, &opt_operands) + } else { + Ok(r) + } + }).unwrap_or_else(|_| r) + }).unwrap_or(r)) + } } } }