mutagen icon indicating copy to clipboard operation
mutagen copied to clipboard

Mutation: Clone values to other parts of the function

Open hmvp opened this issue 7 years ago • 3 comments

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()
}

hmvp avatar Feb 19 '18 09:02 hmvp

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.

llogiq avatar Feb 19 '18 10:02 llogiq

I think I have a solution for this and a few other mutations. Will write something up soon.

llogiq avatar Mar 03 '18 09:03 llogiq

See https://llogiq.github.io/2018/03/03/opportune.html

llogiq avatar Mar 03 '18 12:03 llogiq