ppx_deriving
ppx_deriving copied to clipboard
Unused values when deriving show for private types
Hi,
The following piece of code triggers warning 32 (unused value show_x
). This is a common pattern, it happens whenever an exposed type uses a type that is not exposed.
module M : sig
type t
[@@deriving show]
val make : int -> t
end = struct
type x = int
[@@deriving show]
type t = C of x
[@@deriving show]
let make n = C n
end
The problem is the following:
- 4 bindings are created:
pp_x
,show_x
,pp
, andshow
. -
pp
, andshow
are exposed -
pp_x
is used in the generated definition forpp
-
show_x
is not, so a warning is triggered.
The root cause is similar to ocaml-ppx/ppx_deriving_yojson#76: there is a "convenience function" (here show
) that is not meant to be used recursively.
I am not sure how to best fix this without breaking existing code, but here are some possibilities:
- generate
let _ = show_x
to suppress the warning - similarly, wrap the generated structure within
[@@@warning "-32"]
- add an option so that we can
[@@derive show { only_pp = true }]
- introduce a
[@@deriving pp]
that only derivespp
. This would enable[%pp: t]
as well.
What do you think?
Thanks!
I think [@@warning "-32"]
and [@deriving pp]
both seem like good options; we can simply do both of them.
Hi,
What's the status on this issue?
I'm happy to contribute for the [@deriving pp]
if that's fine by you!
@NathanReb As mentioned above in https://github.com/ocaml-ppx/ppx_deriving/issues/171#issuecomment-400598844, I think both [@@warning "-32"]
and [@deriving pp]
ought to be implemented. If you can do one of them, great!