Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

candidate fix for https://github.com/Chia-Network/clvm_tools/issues/83 #65

Merged
merged 5 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 53 additions & 57 deletions src/classic/clvm_tools/stages/stage_2/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/tests/classic/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
2 changes: 0 additions & 2 deletions support/recompile_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down