[ppx_trace] Refactor: Avoid using Ast_mapper for ppxlib 0.16 compatibility

Summary:
Use `Ppxlib.Ast_traverse.map` instead of
`Ppxlib.Selected_ast.Ast.Ast_mapper` which is included from
`Migrate_parsetree` since `Ppxlib.Selected_ast.Ast` reexports one of
the `Migrate_parsetree.Versions` modules. This change is needed to be
compatible with (ocaml-migrate-parsetree 2.0 and) ppxlib 0.16 since it
no longer re-exports the `Ast_mapper` module from
`Migrate_parsetree`. This ppxlib change is one of the headline
simplification enablers noted in the (announcement of
ocaml-migrate-parsetree
2.0)[https://discuss.ocaml.org/t/ocaml-migrate-parsetree-2-0-0/5991].

Reviewed By: jvillard

Differential Revision: D23636203

fbshipit-source-id: 71e24b46b
master
Josh Berdine 4 years ago committed by Facebook GitHub Bot
parent 936ad83650
commit 77f2b7a02f

@ -40,7 +40,6 @@
open Ppxlib open Ppxlib
open Ast_builder.Default open Ast_builder.Default
module Ast_mapper = Selected_ast.Ast.Ast_mapper
let debug = ref false let debug = ref false
@ -75,11 +74,13 @@ let vb_stack_with, vb_stack_top =
(with_, top) (with_, top)
let mapper = let mapper =
let value_binding (m : Ast_mapper.mapper) vb = object
vb_stack_with vb.pvb_pat ~f:(fun () -> inherit Ast_traverse.map as super
Ast_mapper.default_mapper.value_binding m vb )
in method! value_binding vb =
let expr (m : Ast_mapper.mapper) exp = vb_stack_with vb.pvb_pat ~f:(fun () -> super#value_binding vb)
method! expression exp =
let append_here_args args = let append_here_args args =
let mod_name = evar ~loc:Location.none "Stdlib.__MODULE__" in let mod_name = evar ~loc:Location.none "Stdlib.__MODULE__" in
let fun_name = let fun_name =
@ -120,11 +121,10 @@ let mapper =
pexp_apply ~loc:exp.pexp_loc pexp_apply ~loc:exp.pexp_loc
(evar ~loc:retn_loc "Trace.retn") (evar ~loc:retn_loc "Trace.retn")
(append_here_args [(Nolabel, retn_fun)]) (append_here_args [(Nolabel, retn_fun)])
| _ -> Ast_mapper.default_mapper.expr m exp | _ -> super#expression exp
in end
{Ast_mapper.default_mapper with expr; value_binding}
let impl = Selected_ast.Ast.map_structure mapper let impl = mapper#structure
;; ;;
Driver.register_transformation "trace" ~impl Driver.register_transformation "trace" ~impl

Loading…
Cancel
Save