package elpi

  1. Overview
  2. Docs

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.

val err : loc:Ppxlib.Location.t -> string -> 'a
val enabled : bool Stdlib.ref
val has_iftrace_attribute : Ppxlib.attributes -> bool
val has_iftrace : Ppxlib.core_type -> bool
val map_trace : Ppxlib.Ast_traverse.map
val is_string_literal : Ppxlib.expression -> bool
val is_gid : Ppxlib.arg_label -> bool
val is_rid : Ppxlib.arg_label -> bool
val is_cond : Ppxlib.arg_label -> bool
val pull : ('a -> bool) -> ('b * 'c) list -> 'd option * ('b * 'c) list
val err_spy : loc:Ppxlib.Location.t -> unit -> 'a
val spyl_expand_function : loc:Ppxlib.location -> path:'a -> Ppxlib.expression -> Ppxlib_ast.Ast.expression
val spyl_extension : Ppxlib.Extension.t
val spy_expand_function : loc:Ppxlib.location -> path:'a -> Ppxlib.expression -> Ppxlib_ast.Ast.expression
val spy_extension : Ppxlib.Extension.t
val tcall_expand_function : loc:Ppxlib.location -> path:'a -> Ppxlib.expression -> Ppxlib_ast.Ast.expression
val tcall_extension : Ppxlib.Extension.t
val trace_expand_function : loc:Ppxlib.location -> path:'a -> Ppxlib.expression -> Ppxlib_ast.Ast.expression
val trace_extension : Ppxlib.Extension.t
val cur_pred_expand_function : loc:Ppxlib.location -> path:'a -> Ppxlib_ast.Ast.expression -> Ppxlib_ast.Ast.expression
val cur_pred_extension : Ppxlib.Extension.t
val cur_pred_rule : Ppxlib.Context_free.Rule.t
val log_expand_function : loc:Ppxlib.location -> path:'a -> Ppxlib.expression -> Ppxlib_ast.Ast.expression
val log_extension : Ppxlib.Extension.t
val end_trace_expand_function : loc:Ppxlib.location -> path:'a -> Ppxlib.expression -> Ppxlib_ast.Ast.expression
val end_trace_extension : Ppxlib.Extension.t
val end_trace_rule : Ppxlib.Context_free.Rule.t
val arg_trace : Ppxlib.Driver.Cookies.t -> unit
OCaml

Innovation. Community. Security.