Giter Site home page Giter Site logo

Comments (3)

teymour-aldridge avatar teymour-aldridge commented on May 10, 2024

I think I've solved in my case by reworking the types I'm using to not be mutually recursive.

from fuzzcheck-rs.

loiclec avatar loiclec commented on May 10, 2024

It's possible, but it is pushing of the limits of what is currently possible, and I don't know what the quality of the resulting mutators will be (maybe they're fine, I just haven't tested it).

You can try to write something like:

make_mutator! {
    name: AMutator,
    recursive: true,
    default: false,
    type:
        struct MutuallyRecursiveA {
            b: Vec<MutuallyRecursiveB>,
            #[field_mutator(<Vec<u64> as DefaultMutator>::Mutator = { <Vec<u64>>::default_mutator() })]
            data: Vec<u64>,
        }
}

make_mutator! {
    name: BMutator,
    recursive: true,
    default: true,
    type:
        struct MutuallyRecursiveB {
            #[field_mutator(
                OptionMutator<MutuallyRecursiveA, AMutator<VecMutator<MutuallyRecursiveB, RecurToMutator<BMutator>>>>
            ) = {
                OptionMutator::new(AMutator::new(
                    VecMutator::new(self_.into(), 0..=usize::MAX),
                    <Vec<u64>>::default_mutator(),
                ))
            }]
            a: Option<MutuallyRecursiveA>,
            #[field_mutator(<bool as DefaultMutator>::Mutator = { <bool>::default_mutator() })]
            data: bool
        }
}

It is not a perfect solution: MutuallyRecursiveA has no default mutator, only MutuallyRecursiveB does.
You could however, repeat the snippet above twice except that A and B are switched, giving different names to the mutators. The idea is that for each mutually recursive type, you have a “default mutator” and a “mutator to be used only as a submutator to the other type’s default mutator”.

That's not fundamentally necessary though, and I could improve the procedural macro to make it possible to define these mutually recursive mutators using only one make_mutator! per type. I would need to think about those generic bounds a bit more (again! lol).

Note though that due to a questionable design decision (because of superfluous generic bound, again!) , even the code I posted above doesn't actually work. So you have to construct BMutator with:

 let mutator = RecursiveMutator::new(|self_| {
    BMutator::new(
        OptionMutator::new(AMutator::new(
            VecMutator::new(self_.into(), 0..=usize::MAX),
            <Vec<u64>>::default_mutator(),
        )),
        bool::default_mutator(),
    )
});

I'll try and fix that and post the progress in this issue. It may be a LONG time before mutually-recursive types are easy to work with though.

from fuzzcheck-rs.

teymour-aldridge avatar teymour-aldridge commented on May 10, 2024

Thank you so much!

from fuzzcheck-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.