Trace_ppx
elpi.trace.ppx provides the following syntax extensions:
type t = { a : T; b : S [@trace] }
let rec f x (w[@trace]) =
[%trace "f" (fun fmt -> .. x ..) begin
match x with
| K1 -> ...
| K2 x -> [%tcall f x]
| K2(x,y) ->
let z = f x in
[%spy "z" ~rid ~gid ~cond (fun fmt z -> .. z ..) z];
[%spyl "z" ~rid ~gid ~cond (fun fmt z -> .. z ..) zs];
[%log "K2" ~rid "whatever" 37];
let x[@trace] = ... in e
let w = { a; b = b[@trace ] } in
match w with
| { a; b = b [@trace] } ->
z + f y (b[@trace])
end]
[%end_trace "stop" ~rid]
If --cookie "elpi_trace=\"true\"" is not passed to the ppx rewriter:
[%end_trace "stop" ~rid]
---> ()
[%trace "foo" pp code]
---> code
[%tcall f x]
---> f x
[%spy ...]
[%spyl ...]
and [%log ...]
---> ()
f x (y[@trace]) z
---> f x z
let x[@trace] = .. in e
---> e
type x = { a : T; b : T [@trace] }
---> type x = { a : T }
{ a; b = b [@trace] }
---> { a }
(in both patterns and expressions)T -> (S[@trace]) -> U
---> T -> U
In records, the shorcut "x" to mean "x = x" does not work, you have to use the longer form.