janestreet-deprecated/ppx_type_conv

Not working with ppx_deriving (separate from 4.03 compatibility)

kitfre opened this issue · 6 comments

When trying to use ppx_deriving on say a type like
type int_tree = Leaf | Branch of int_tree * int * int_tree [@@deriving show]
This error occurs:
ppx_type_conv: 'show' is not a supported type type-conv generator.
The same happens with any directive, show, map, fold, enum, etc.
I'm using 4.02.3 and here's my .ocamlinit for reference:

#use "topfind";;
#thread;;

#require "ppx_import";;
#ppx "ppx-jane -as-ppx";;
#require "core.top";;
#require "async";;
#require "core_extended";;

(* Added by OPAM *)
let () =
  try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
  with Not_found -> ()
;;

open Core.Std;;

Update:

If I replace #ppx "ppx-jane -as-ppx" with #require "ppx_jane" then everything works correctly, but this causes utop to run incredibly slowly and take upwards of a minute to start.

Basically you should either use ppx_type_conv based derivers with ppx_driver or with the ppx_deriving compatibility layer. You are using the latter when you do #require "ppx_jane". When using ppx_driver, ppx_type_conv needs to know about all derivers.

The solution to this problem is to allow to bridge things the other way around, i.e. allow ppx_deriving plugins to be used with ppx_type_conv. That shouldn't be too hard to do, but for things to work well we need a few more things from ppx_deriving: a way to list all the derivers registered so far and a hook for newly registered deriviers. Something like this would do:

(** [add_register_hook f] calls [f] on all existing deriviers as well as
    on all new deriviers registered from this point.  *)
val add_register_hook : (deriver -> unit) -> unit

If you are happy to get this functionality in ppx_deriving, we can do the rest in ppx_type_conv.

I wrote the code on the ppx_type_conv side, we'll release it when the next version of ppx_deriving is released

Once ocaml/opam-repository#10885 is merged we'll have a better solution to this problem.

Indeed, that works. I still had to conflict with ppx_driver.v0.9.1 manually, but it seems that the fix works. Thanks!

(note, I'm not OP)

hhugo commented

This looks solved.