ocaml-gospel / ortac

Runtime assertion checking based on Gospel specifications
https://ocaml-gospel.github.io/ortac/
MIT License
36 stars 10 forks source link

Add support for function returning tuples #203

Open n-osborne opened 6 months ago

n-osborne commented 6 months ago

Functions returning tuples are filtered out in Ir_of_gospel.no_functional_arg_or_returned_tuple Then it is possible to follow where the code need to be amended as there are some failwith talking about tuples.

jmid commented 6 months ago

I hand-wrote support for a 6-tuple when I first needed it as part of testing weak hash sets: https://github.com/ocaml-multicore/multicoretests/blob/7b9b1c123286f1f4db7d13e773f68198ca9b04cd/src/weak/stm_tests_hashset.ml#L112-L122

IIUC, it should be possible to generate similar lines (on demand) from the plugin, if we encounter a returned (or argument?) tuple. :thinking:

shym commented 6 months ago

As QCheck.Print.tupn are defined up to 9 only, I wondered whether it’s worth the effort of generating them rather than writing them once and for all. (We might still be gentle and include in the generated file only the required tuples, though)

jmid commented 6 months ago

True, tuples in OCaml APIs are relatively rare - and a 2-digit one more so! :smiley: Down the line we may want to extend the support further, e.g., to record types, where a print function is not available. At that point, ppx_deriving show may be an option.