Skip to content

Commit

Permalink
candidate fix for Chia-Network/clvm_tools#83
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed Aug 23, 2022
1 parent 7a082dd commit 1d9f9cc
Showing 1 changed file with 53 additions and 59 deletions.
112 changes: 53 additions & 59 deletions src/classic/clvm_tools/stages/stage_2/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
}
Expand Down

0 comments on commit 1d9f9cc

Please sign in to comment.