mutagen
mutagen copied to clipboard
Mutation: Clone values to other parts of the function
Instead of using default to generate different values for assignments or arguments we can clone values from different places in the same function and use them instead
fn times_two(arg: u8) -> u8 {
arg * 2
}
mutate to
fn times_two(arg: u8) -> u8 {
// Original value as head, all other similar typed values as tail
mutagen::clone(&[arg * 2, arg], n)
}
with:
fn clone<T>(choices: &[T], n: usize ) -> T {
let x = n.wrapper_sub(self.get());
let x = if x < 0 && x >= choices.len() {0} else { x };
choices[x].clone()
}
Wouldn't that at least require T: Clone? Also we already do early return with arguments, so a part of this is already taken care of.
I think I have a solution for this and a few other mutations. Will write something up soon.
See https://llogiq.github.io/2018/03/03/opportune.html