From 714f35f76cc46e205d6c5b549ca0a41f0726b3f0 Mon Sep 17 00:00:00 2001 From: arty Date: Mon, 26 Sep 2022 06:57:09 -0700 Subject: [PATCH] candidate fix for https://github.com/Chia-Network/clvm_tools/issues/83 (#65) * candidate fix for https://github.com/Chia-Network/clvm_tools/issues/83 * Update for now-absent build products * Add a test that compiles and runs the user's program from the github issue: a fancy way of doing 'ident' on an un-destructured module argument. the expected result is the full env we give * Add unit test for un-destructured args --- .../clvm_tools/stages/stage_2/optimize.rs | 110 +++++++++--------- src/tests/classic/smoke.rs | 25 ++++ support/recompile_check.py | 2 - 3 files changed, 78 insertions(+), 59 deletions(-) diff --git a/src/classic/clvm_tools/stages/stage_2/optimize.rs b/src/classic/clvm_tools/stages/stage_2/optimize.rs index 061f74e0d..6014adeba 100644 --- a/src/classic/clvm_tools/stages/stage_2/optimize.rs +++ b/src/classic/clvm_tools/stages/stage_2/optimize.rs @@ -329,76 +329,72 @@ pub 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_else(|| 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| { map_m( allocator, &mut new_operands.iter(), &|allocator, item| { optimize_sexp(allocator, *item, eval_f.clone()) } - ); - - non_constant_count <- fold_m( - 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 <- fold_m( + 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().copied() - ); + }; - let _ = if DIAG_OPTIMIZATIONS { - print!( - "XXX non_constant_count {}\n", - non_constant_count - ); - }; + Ok(acc + increment) + }, + 0, + &mut opt_operands.iter().copied() + ); - 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(r) + }).unwrap_or(r)) + } } } } diff --git a/src/tests/classic/smoke.rs b/src/tests/classic/smoke.rs index cc9c44ea1..a471e304b 100644 --- a/src/tests/classic/smoke.rs +++ b/src/tests/classic/smoke.rs @@ -476,3 +476,28 @@ fn pool_member_innerpuz() { let result = s.get_value().decode().trim().to_string(); assert_eq!(result, desired); } + +// Tests a fancy identity function using an un-destructured parameter at the +// module level. +#[test] +fn test_non_consed_args() { + let program = + "(mod params (defun ident (arg) (f (list arg))) (ident (ident params)))".to_string(); + let mut s = Stream::new(None); + launch_tool( + &mut s, + &vec!["run".to_string(), program], + &"run".to_string(), + 2, + ); + let result = s.get_value().decode().trim().to_string(); + let mut t = Stream::new(None); + launch_tool( + &mut t, + &vec!["brun".to_string(), result, "99".to_string()], + &"brun".to_string(), + 0, + ); + let run_result = t.get_value().decode().trim().to_string(); + assert_eq!(run_result, "99"); +} diff --git a/support/recompile_check.py b/support/recompile_check.py index b9b902abf..1cec2c4de 100644 --- a/support/recompile_check.py +++ b/support/recompile_check.py @@ -30,8 +30,6 @@ 'p2_singleton_or_delayed_puzhash.clvm', 'pool_member_innerpuz.clvm', 'pool_waitingroom_innerpuz.clvm', - 'rl_aggregation.clvm', - 'rl.clvm', 'rom_bootstrap_generator.clvm', 'settlement_payments.clvm', 'sha256tree_module.clvm',