Merge pull request #38 from c-cube/simon/fix-ppxlib-0.37

adapt to ppxlib 0.37
This commit is contained in:
Simon Cruanes 2025-12-12 08:54:29 -05:00 committed by GitHub
commit ef35cc1d79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 23 additions and 7 deletions

View file

@ -44,7 +44,7 @@
; we use __FUNCTION__ ; we use __FUNCTION__
(ppxlib (ppxlib
(and (and
(>= 0.28) (>= 0.37)
(< 0.38))) (< 0.38)))
(trace (trace
(= :version)) (= :version))

View file

@ -10,7 +10,7 @@ homepage: "https://github.com/c-cube/ocaml-trace"
bug-reports: "https://github.com/c-cube/ocaml-trace/issues" bug-reports: "https://github.com/c-cube/ocaml-trace/issues"
depends: [ depends: [
"ocaml" {>= "4.12"} "ocaml" {>= "4.12"}
"ppxlib" {>= "0.28" & < "0.38"} "ppxlib" {>= "0.37" & < "0.38"}
"trace" {= version} "trace" {= version}
"trace-tef" {= version & with-test} "trace-tef" {= version & with-test}
"dune" {>= "2.9"} "dune" {>= "2.9"}

View file

@ -39,7 +39,7 @@ let extension_let =
(let open! Ast_pattern in (let open! Ast_pattern in
single_expr_payload single_expr_payload
(pexp_let nonrecursive (pexp_let nonrecursive
(value_binding (value_binding ~constraint_:none
~pat: ~pat:
(let pat_var = ppat_var __' |> map ~f:(fun f v -> f (`Var v)) in (let pat_var = ppat_var __' |> map ~f:(fun f v -> f (`Var v)) in
let pat_unit = let pat_unit =
@ -62,8 +62,23 @@ let expand_top_let ~ctxt rec_flag (vbs : _ list) =
(* go in functions, and add tracing around the body *) (* go in functions, and add tracing around the body *)
let rec push_into_fun (e : expression) : expression = let rec push_into_fun (e : expression) : expression =
match e.pexp_desc with match e.pexp_desc with
| Pexp_fun (lbl, lbl_expr, pat, body) -> | Pexp_function (args, ty, Pfunction_body body) ->
pexp_fun ~loc:e.pexp_loc lbl lbl_expr pat @@ push_into_fun body pexp_function ~loc args ty @@ Pfunction_body (push_into_fun body)
| Pexp_function (_args, _ty, Pfunction_cases _) ->
(* explicitly fail on [let%trace foo = function …], for now *)
Ast_helper.Exp.extension
( { txt = "ocaml.error"; loc },
PStr
[
pstr_eval ~loc
(pexp_constant ~loc
(Pconst_string
( "ppxtrace: cannot trace `function`, please unsugar \
to `fun`+`match`.",
loc,
None )))
[];
] )
| _ -> | _ ->
[%expr [%expr
let _trace_span = let _trace_span =

File diff suppressed because one or more lines are too long

View file

@ -71,5 +71,6 @@ let () =
output_string oc data; output_string oc data;
close_out_noerr oc); close_out_noerr oc);
print_endline (to_hex data); (* print_endline (to_hex data); *)
Printf.printf "data: %d bytes\n" (String.length data);
flush stdout flush stdout