Skip to content

Stabilize Arbitrary trait? #2035

Open

Description

@Kixunil

Requested feature: Officially stabilize the Arbitrary trait
Use case: Crates that define public types could implement Arbitrary for those type so that downstream crates can more easily use them or implement Arbitrary for types containing them.

Activity

  1. added
    [C] Feature / Enhancement
    on Dec 22, 2022
  2. added
    T-User
    on Dec 22, 2022
  3. tedinski commented on Dec 22, 2022

    @tedinski
    Contributor

    Thanks for the request, it helps us prioritize. In this case, there are some pretty tricky design problems to think through, so it's probably not going to be short-term, unfortunately.

    One possible short-term solution is to use Bolero and bolero-generator[-derive]. This lets you depend on those crates (which are published normally on crates.io) and we did write a recent blog post about using Bolero with Kani: https://model-checking.github.io/kani-verifier-blog/2022/10/27/using-kani-with-the-bolero-property-testing-framework.html

    Do you think this might work for you?

  4. Kixunil commented on Dec 22, 2022

    @Kixunil
    Author

    Oh, nice that's even better since it supports a fuzzer too! But now I feel like there are way too many fuzzing traits. There's quickcheck::Arbitrary and I'm pretty sure I've seen another one somewhere. Would be great if there was just one but that's a different topic.

  5. JustusAdam commented on Sep 22, 2023

    @JustusAdam
    Contributor

    Hey @Kixunil, just wanted to chime in that there is also a way to create instances for Arbitrary in a library and expose them, though it is a bit roundabout and relies on internal details in how Kani operates. So this should not be considered a reliable approach, but if you need it it is available.

    struct MyType(usize);
    
    #[cfg(kani)]
    impl kani::Arbitrary for MyType {
        fn any() -> Self {
            MyType(kani::any())
        }
    }

    When this code is compiled with kani, wether that be in your workspace or in a dependency, the cfg(kani) will have been set and also the kani library will be implicitly in scope (as if you had done extern crate kani at the top).

    You could even push this to crates.io and it should work to depend on it.

  6. JustusAdam commented on Sep 22, 2023

    @JustusAdam
    Contributor

    In terms of a common trait there is an arbitrary crate on creates.io https://crates.io/crates/arbitrary, created by rust-fuzz. Kani could support that by "simply" overwriting the Arbitrary impl for basic types like usize via GOTO hook.

  7. Kixunil commented on Sep 22, 2023

    @Kixunil
    Author

    Yeah, my point was to have something that could be included in a serious library. But goo to know if I ever have a less serious one. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

T-User[C] Feature / Enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions