From 5ed9796ef31c1564c289f4a3a3422626662f9afb Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Fri, 28 Feb 2020 15:20:00 -0800 Subject: [PATCH] Implement `Arbitrary::size_hint` for `ApiCalls` --- crates/fuzzing/src/generators/api.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/fuzzing/src/generators/api.rs b/crates/fuzzing/src/generators/api.rs index 9ffe8c5e26..33fb27b0cd 100644 --- a/crates/fuzzing/src/generators/api.rs +++ b/crates/fuzzing/src/generators/api.rs @@ -140,6 +140,25 @@ impl Arbitrary for ApiCalls { Ok(ApiCalls { calls }) } + + fn size_hint(depth: usize) -> (usize, Option) { + arbitrary::size_hint::recursion_guard(depth, |depth| { + arbitrary::size_hint::or( + // This is the stuff we unconditionally need, which affects the + // minimum size. + arbitrary::size_hint::and( + ::size_hint(depth), + // `arbitrary_config` uses two bools when + // `swarm.config_debug_info` is true. + <(bool, bool) as Arbitrary>::size_hint(depth), + ), + // We can generate arbitrary `WasmOptTtf` instances, which have + // no upper bound on the number of bytes they consume. This sets + // the upper bound to `None`. + ::size_hint(depth), + ) + }) + } } fn arbitrary_config(