-
Notifications
You must be signed in to change notification settings - Fork 90
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
Restore ocamlfind loader #243
Conversation
We had a look at this with @kit-ty-kate. To be complete, we need a |
Thanks @kit-ty-kate and @diml for looking at this. Tell me if I understand correctly:
Are there plans to lift the limitations in ppxlib? (Would that then take the form of a minor 0.16 release, rather than continuing from 0.18?) |
My guess is that the loader was removed prematurely by accident. It is required to use deriving plugins with ocamlfind. It is indeed not used by Dune. It is quite complex and could be replaced by a simpler system, but that would require a bit of preparation.
Not really, it restores the dynamic loader. In a nutshell, when you use ppx rewriters with ocamlfind, you get one Without this loader, deriving plugins cannot be used with ocamlfind at all.
I didn't notice that, but I'm not sure that was the intent. It might have been just for testing. I'll let @kit-ty-kate comment on that.
We talked about it, Kate is going to add the missing function in ppxlib and do any necessary minor release. |
31c9f89
to
53586c5
Compare
@jeremiedimino actually we might not need any change in Here is the diff between the diff --git a/src/ppx_deriving_main.cppo.ml b/src/ppx_deriving_main.cppo.ml
index 375889e..3ca76de 100644
--- a/src/ppx_deriving_main.cppo.ml
+++ b/src/ppx_deriving_main.cppo.ml
@@ -6,12 +6,10 @@ open Ast_helper
module Ast_mapper = Ocaml_common.Ast_mapper
module From_current =
- Migrate_parsetree.Convert (Migrate_parsetree.OCaml_current)
- (Migrate_parsetree.OCaml_410)
+ Ppxlib_ast.Selected_ast.Of_ocaml
module To_current =
- Migrate_parsetree.Convert (Migrate_parsetree.OCaml_410)
- (Migrate_parsetree.OCaml_current)
+ Ppxlib_ast.Selected_ast.To_ocaml
let raise_errorf = Ppx_deriving.raise_errorf
@@ -70,21 +68,15 @@ let add_plugins plugins =
let mapper argv =
get_plugins () |> List.iter load_plugin;
add_plugins argv;
- let copy_structure_item item =
- match From_current.copy_structure [item] with
- | [item] -> item
- | _ -> failwith "Ppx_deriving_main.copy_structure_item" in
- let module Current_ast = Migrate_parsetree.OCaml_current.Ast in
- let omp_mapper = Migrate_parsetree.Driver.run_as_ast_mapper [] in
- let structure mapper s =
+ let module Current_ast = Ppxlib_ast.Selected_ast in
+ let structure s =
match s with
| [] -> []
| hd :: tl ->
match
- try Some (copy_structure_item hd)
- with Migrate_parsetree.Def.Migration_error (_, _) -> None
+ hd
with
- | Some ([%stri [@@@findlib.ppxopt [%e? { pexp_desc = Pexp_tuple (
+ | ([%stri [@@@findlib.ppxopt [%e? { pexp_desc = Pexp_tuple (
[%expr "ppx_deriving"] :: elems) }]]]) ->
elems |>
List.map (fun elem ->
@@ -93,9 +85,15 @@ let mapper argv =
file
| _ -> assert false) |>
add_plugins;
- mapper.Current_ast.Ast_mapper.structure mapper tl
- | _ -> omp_mapper.Current_ast.Ast_mapper.structure mapper s in
- { omp_mapper with Current_ast.Ast_mapper.structure }
+ Ppxlib.Driver.map_structure tl
+ | _ -> Ppxlib.Driver.map_structure s
+ in
+ let structure _ st =
+ Current_ast.of_ocaml Structure st
+ |> structure
+ |> Current_ast.to_ocaml Structure
+ in
+ { Ast_mapper.default_mapper with structure }
let () =
Ast_mapper.register "ppx_deriving" mapper @gasche The code reverts to ppxlib 0.16 to allow users to have a more choice in their opam switches as some packages don't have stable versions compatible with ppxlib 0.18 yet and it might conflicts with them. So having two releases of ppx_deriving, 5.2 for ppxlib 0.16 and 5.3 for ppxlib 0.18 allow users to have this choice and avoid them to be in a configuration where they require older versions of everything to satisfy the constraints. If @jeremiedimino gives me the go-ahead I'll merge this, and re-release ppx_deriving 5.2 and 5.3 right away. |
Ah nevermind, I just tested and we really need |
We indeed need The diff looks correct to me. |
Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
…ly functional again)
9cde1ba
to
9cba2ee
Compare
Final diff compared to diff --git a/src/ppx_deriving_main.cppo.ml b/src/ppx_deriving_main.cppo.ml
index 375889e..762dcb8 100644
--- a/src/ppx_deriving_main.cppo.ml
+++ b/src/ppx_deriving_main.cppo.ml
@@ -6,12 +6,10 @@ open Ast_helper
module Ast_mapper = Ocaml_common.Ast_mapper
module From_current =
- Migrate_parsetree.Convert (Migrate_parsetree.OCaml_current)
- (Migrate_parsetree.OCaml_410)
+ Ppxlib_ast.Selected_ast.Of_ocaml
module To_current =
- Migrate_parsetree.Convert (Migrate_parsetree.OCaml_410)
- (Migrate_parsetree.OCaml_current)
+ Ppxlib_ast.Selected_ast.To_ocaml
let raise_errorf = Ppx_deriving.raise_errorf
@@ -53,7 +51,7 @@ let get_plugins () =
| { pexp_desc = Pexp_tuple exprs } ->
exprs |> List.map (fun expr ->
match expr with
- | { pexp_desc = Pexp_constant (Pconst_string (file, None)) } -> file
+ | { pexp_desc = Pexp_constant (Pconst_string (file, _, None)) } -> file
| _ -> assert false)
| _ -> assert false
@@ -64,38 +62,42 @@ let add_plugins plugins =
let loaded = loaded @ plugins in
Ast_mapper.set_cookie "ppx_deriving"
(To_current.copy_expression
- (Exp.tuple (List.map (fun file ->
- Exp.constant (Pconst_string (file, None))) loaded)))
+ (Exp.tuple (List.map (Ast_builder.Default.estring ~loc:Location.none) loaded)))
let mapper argv =
get_plugins () |> List.iter load_plugin;
add_plugins argv;
- let copy_structure_item item =
- match From_current.copy_structure [item] with
- | [item] -> item
- | _ -> failwith "Ppx_deriving_main.copy_structure_item" in
- let module Current_ast = Migrate_parsetree.OCaml_current.Ast in
- let omp_mapper = Migrate_parsetree.Driver.run_as_ast_mapper [] in
- let structure mapper s =
+ let module Current_ast = Ppxlib_ast.Selected_ast in
+ let structure s =
match s with
| [] -> []
| hd :: tl ->
match
- try Some (copy_structure_item hd)
- with Migrate_parsetree.Def.Migration_error (_, _) -> None
+ hd
with
- | Some ([%stri [@@@findlib.ppxopt [%e? { pexp_desc = Pexp_tuple (
+ | ([%stri [@@@findlib.ppxopt [%e? { pexp_desc = Pexp_tuple (
[%expr "ppx_deriving"] :: elems) }]]]) ->
elems |>
List.map (fun elem ->
match elem with
- | { pexp_desc = Pexp_constant (Pconst_string (file, None))} ->
+ | { pexp_desc = Pexp_constant (Pconst_string (file, _, None))} ->
file
| _ -> assert false) |>
add_plugins;
- mapper.Current_ast.Ast_mapper.structure mapper tl
- | _ -> omp_mapper.Current_ast.Ast_mapper.structure mapper s in
- { omp_mapper with Current_ast.Ast_mapper.structure }
+ Ppxlib.Driver.map_structure tl
+ | _ -> Ppxlib.Driver.map_structure s
+ in
+ let structure _ st =
+ Current_ast.of_ocaml Structure st
+ |> structure
+ |> Current_ast.to_ocaml Structure
+ in
+ let signature _ si =
+ Current_ast.of_ocaml Signature si
+ |> Ppxlib.Driver.map_signature
+ |> Current_ast.to_ocaml Signature
+ in
+ { Ast_mapper.default_mapper with structure; signature }
let () =
Ast_mapper.register "ppx_deriving" mapper Thanks a lot @jeremiedimino! |
CHANGES: * Update to ppxlib 0.20.0 ocaml-ppx/ppx_deriving#237 ocaml-ppx/ppx_deriving#239 ocaml-ppx/ppx_deriving#243 ocaml-ppx/ppx_deriving#245 (Kate Deplaix, Jérémie Dimino, Thierry Martinez, Gabriel Scherer) * Upgrade testsuite from ounit to ounit2 ocaml-ppx/ppx_deriving#241 (Kate Deplaix) * (almost) use the set of standard flags from dune ocaml-ppx/ppx_deriving#246 (Kate Deplaix)
CHANGES: * Update to ppxlib 0.20.0 ocaml-ppx/ppx_deriving#237 ocaml-ppx/ppx_deriving#239 ocaml-ppx/ppx_deriving#243 ocaml-ppx/ppx_deriving#245 (Kate Deplaix, Jérémie Dimino, Thierry Martinez, Gabriel Scherer) * Upgrade testsuite from ounit to ounit2 ocaml-ppx/ppx_deriving#241 (Kate Deplaix) * (almost) use the set of standard flags from dune ocaml-ppx/ppx_deriving#246 (Kate Deplaix)
CHANGES: * Update to ppxlib 0.20.0 ocaml-ppx/ppx_deriving#237 ocaml-ppx/ppx_deriving#239 ocaml-ppx/ppx_deriving#243 ocaml-ppx/ppx_deriving#245 (Kate Deplaix, Jérémie Dimino, Thierry Martinez, Gabriel Scherer) * Upgrade testsuite from ounit to ounit2 ocaml-ppx/ppx_deriving#241 (Kate Deplaix) * (almost) use the set of standard flags from dune ocaml-ppx/ppx_deriving#246 (Kate Deplaix)
CHANGES: * Update to ppxlib 0.20.0 ocaml-ppx/ppx_deriving#237 ocaml-ppx/ppx_deriving#239 ocaml-ppx/ppx_deriving#243 ocaml-ppx/ppx_deriving#245 (Kate Deplaix, Jérémie Dimino, Thierry Martinez, Gabriel Scherer) * Upgrade testsuite from ounit to ounit2 ocaml-ppx/ppx_deriving#241 (Kate Deplaix) * (almost) use the set of standard flags from dune ocaml-ppx/ppx_deriving#246 (Kate Deplaix)
CHANGES: * Update to ppxlib 0.20.0 ocaml-ppx/ppx_deriving#237 ocaml-ppx/ppx_deriving#239 ocaml-ppx/ppx_deriving#243 ocaml-ppx/ppx_deriving#245 (Kate Deplaix, Jérémie Dimino, Thierry Martinez, Gabriel Scherer) * Upgrade testsuite from ounit to ounit2 ocaml-ppx/ppx_deriving#241 (Kate Deplaix) * (almost) use the set of standard flags from dune ocaml-ppx/ppx_deriving#246 (Kate Deplaix)
No description provided.