Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usability in utop: must manually load various stuff before using the ppx #1

Closed
Armael opened this issue Sep 26, 2015 · 13 comments
Closed

Comments

@Armael
Copy link

Armael commented Sep 26, 2015

Hi,

I think this is more a kind of "usability bug": in order to make the following declaration work in utop "type t = int * int [@@deriving sexp];;", I figured out by trial and error that I had to first, in this order:

#require "ppx_deriving";;
#require "sexplib";;
#require "ppx_sexp_conv";;
open Sexplib.Conv;;

The open Sexplib.Conv bit being the most puzzling imo (without it it complains that int_of_sexp is unbound). Could this be shortened/documented a bit? I my head, a #require "ppx_deriving";; #require "ppx_sexp_conv";; should be sufficient...?

Cheers,
Armaël

@ghost
Copy link

ghost commented Sep 28, 2015

Note: you shouldn't have to require "ppx_deriving" manually, can you confirm it works without?

ppx_sexp_conv can probably require sexplib. I'm not sure what to do about the open Sexplib.Conv though, as something the basic converters will come from somewhere else. For instance if you are using core then open Core.Std will bring into scope all the standard converters.

@Armael
Copy link
Author

Armael commented Sep 28, 2015

Without requiring ppx_deriving, I get:

# #require "sexplib";;
# #require "ppx_sexp_conv";;
# open Sexplib.Conv;;
# type t = int * int [@@deriving sexp];; 
Cannot locate deriver sexp

@ghost
Copy link

ghost commented Sep 28, 2015

Not sure what's happening. @whitequark, any idea why we need to load ppx_deriving first?

@whitequark
Copy link

Try utop -dsource:

# #require "ppx_sexp_conv";;
[@@@findlib.ppxopt ("ppx_deriving", "/home/whitequark/.opam/4.02.3/lib/ppx_optcomp/./ppx_optcomp.cma")];;

[@@@findlib.ppxopt ("ppx_deriving", "/home/whitequark/.opam/4.02.3/lib/ppx_driver/./ppx_driver.cma")];;

[@@@findlib.ppxopt ("ppx_deriving", "/home/whitequark/.opam/4.02.3/lib/ppx_sexp_conv/./ppx_sexp_conv_expander.cma")];;

[@@@findlib.ppxopt ("ppx_deriving", "/home/whitequark/.opam/4.02.3/lib/ppx_type_conv/./ppx_type_conv.cma")];;

[@@@findlib.ppxopt ("ppx_deriving", "/home/whitequark/.opam/4.02.3/lib/ppx_type_conv/./ppx_type_conv_deriving.cma")];;

[%%ocaml.error
  let _ =
    "Cannot load /home/whitequark/.opam/4.02.3/lib/ppx_sexp_conv/./ppx_sexp_conv.cmxs: error loading shared library: /home/whitequark/.opam/4.02.3/lib/ppx_sexp_conv/./ppx_sexp_conv.cmxs: undefined symbol: camlPpx_sexp_conv_expander"
  let _ = ""];;

#require  "ppx_sexp_conv";;

@whitequark
Copy link

Now if you #require "ppx_deriving" first:

# #require "ppx_deriving";;
#require  "ppx_deriving";;
# #require "ppx_sexp_conv";;
;;
;;
;;
;;
;;
;;
#require  "ppx_sexp_conv";;

@whitequark
Copy link

@diml oh, I see. Note how e.g. ppx_core supplies the ppxopt(-ppx_driver) = "ppx_deriving,./whatever.cma" option, but does not require ppx_deriving. This means that ppx_deriving might well not be loaded until right before ppx_sexp_conv itself is loaded, and then the ppxopt is lost.

@ghost
Copy link

ghost commented Sep 28, 2015

I see, my bad. I'll add the dependency.

Actually that's a problem I had while creating the packages and wanted to come back to: ppx_core (and a few other packages) are general purpose libraries that are not related to ppx_deriving or ppx_type_conv, so they should have a META file similar to any library. However there is currently no way to specify a dependency from a ppx_deriving plugin to a normal library. For instance I can't write a ppx_deriving plugin that would use pcre.

@whitequark
Copy link

That's a very good point. I think ppx_deriving should use findlib to discover the package archives. I think I used to link findlib before? I don't remember what made me switch to pure-dynlink.

@ghost
Copy link

ghost commented Sep 28, 2015

Yeah I think it would be easier if ppx_deriving was using findlib

@agarwal
Copy link
Contributor

agarwal commented Oct 22, 2015

This is a still a bit frustrating. You have to load ppx_deriving first. If you load ppx_sexp_conv first, there's no way out except to restart utop.

utop # #require "ppx_sexp_conv";;
utop # type t = int [@@deriving sexp];;
Cannot locate deriver sexp

(* Now you google for this error and end up here. You realize you need to load ppx_deriving, so you try it. *)

#require "ppx_deriving";;
utop # type t = int [@@deriving sexp];;
Cannot locate deriver sexp

utop # #require "ppx_deriving";;
utop # #require "ppx_sexp_conv";;
utop # type t = int [@@deriving sexp];;
Cannot locate deriver sexp

Finally, restart utop and do the last sequence, and then it works.

@whitequark
Copy link

Yeah, unfortunately I haven't had time yet to fix that.

@ghost
Copy link

ghost commented Feb 22, 2016

This is fixed with ppx_sexp_conv 113.24.00

@ghost ghost closed this as completed Feb 22, 2016
@Armael
Copy link
Author

Armael commented Feb 22, 2016

Ok, thanks!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants