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

Loading…
Cancel
Save