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
Changes from 1 commit
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
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