Skip to content

Commit

Permalink
Rpc_genfake.genall add a ?maxcomb parameter
Browse files Browse the repository at this point in the history
For a struct with `n` field, each with `m` values, this might otherwise try to generate `m`^`n` values.

Signed-off-by: Edwin Török <[email protected]>
  • Loading branch information
edwintorok committed Sep 25, 2024
1 parent f77a744 commit 202eb0c
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/lib/rpc_genfake.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ let rec gentest : type a. Seen.t -> a typ -> a Seq.t =
v.treview content)
| Abstract { test_data; _ } -> test_data |> List.to_seq

let thin d result =
if d < 0 then Seq.take 1 result else result

let rec genall: type a. Seen.t -> int -> string -> a typ -> a Seq.t =
fun seen depth strhint t ->
let rec genall: type a. maxcomb:int -> Seen.t -> int -> string -> a typ -> a Seq.t =
fun ~maxcomb seen depth strhint t ->
let thin d result =
if d < 0 then Seq.take 1 result else Seq.take maxcomb result
in
let seen_t = SeenType.T t in
if Seen.mem seen_t seen then Seq.empty
else
let genall depth strhint t = genall (Seen.add seen_t seen) depth strhint t in
let genall depth strhint t = genall ~maxcomb (Seen.add seen_t seen) depth strhint t in
match t with
| Basic Int -> Seq.return 0
| Basic Int32 -> Seq.return 0l
Expand Down Expand Up @@ -219,5 +219,4 @@ let rec gen_nice : type a. a typ -> string -> a =

(** don't use this on recursive types! *)
let gentest t = gentest Seen.empty t |> List.of_seq

let genall depth strhint t = genall Seen.empty depth strhint t |> List.of_seq
let genall ?(maxcomb=Sys.max_array_length) depth strhint t = genall ~maxcomb Seen.empty depth strhint t |> List.of_seq

0 comments on commit 202eb0c

Please sign in to comment.