diff --git a/dune-project b/dune-project index bee2199..e1f7b54 100644 --- a/dune-project +++ b/dune-project @@ -15,7 +15,7 @@ (documentation https://lukstafi.github.io/ppx_minidebug/ppx_minidebug) -(version 0.6.0) +(version 0.7.0) (package (name ppx_minidebug) diff --git a/ppx_minidebug.ml b/ppx_minidebug.ml index 24f3447..14a4d7a 100644 --- a/ppx_minidebug.ml +++ b/ppx_minidebug.ml @@ -164,24 +164,24 @@ let debug_fun callback bind descr_loc typ_opt1 exp = let result = pat2pat_res bind in let body = [%expr - [%e arg_logs]; - if Debug_runtime.exceeds_max_nesting () then ( - [%e log_string ~loc ~descr_loc ""]; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") - else if Debug_runtime.exceeds_max_children () then ( + if Debug_runtime.exceeds_max_children () then ( [%e log_string ~loc ~descr_loc ""]; - Debug_runtime.close_log (); failwith "ppx_minidebug: max_num_children exceeded") - else - match [%e callback body] with - | [%p result] -> - [%e !log_value ~loc ~typ ~descr_loc (pat2expr result)]; - Debug_runtime.close_log (); - [%e pat2expr result] - | exception e -> - Debug_runtime.close_log (); - raise e] + else ( + [%e arg_logs]; + if Debug_runtime.exceeds_max_nesting () then ( + [%e log_string ~loc ~descr_loc ""]; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + match [%e callback body] with + | [%p result] -> + [%e !log_value ~loc ~typ ~descr_loc (pat2expr result)]; + Debug_runtime.close_log (); + [%e pat2expr result] + | exception e -> + Debug_runtime.close_log (); + raise e)] in let body = match typ_opt2 with None -> body | Some typ -> [%expr ([%e body] : [%t typ])] diff --git a/ppx_minidebug.opam b/ppx_minidebug.opam index 6984176..1d8a1d7 100644 --- a/ppx_minidebug.opam +++ b/ppx_minidebug.opam @@ -1,6 +1,6 @@ # This file is generated by dune, edit dune-project instead opam-version: "2.0" -version: "0.6.0" +version: "0.7.0" synopsis: "Debug logs for selected functions and let-bindings" description: "A poor man's `ppx_debug` with formatted logs of let-bound values, function arguments and results." diff --git a/test/test_debug_pp.expected.ml b/test/test_debug_pp.expected.ml index 1bf9b8f..270c844 100644 --- a/test/test_debug_pp.expected.ml +++ b/test/test_debug_pp.expected.ml @@ -5,200 +5,198 @@ type t = { second: int }[@@deriving show] type num = int[@@deriving show] let bar (x : t) = - ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_pp.ml" - ~start_lnum:7 ~start_colnum:17 ~end_lnum:9 ~end_colnum:14 - ~message:"bar"; - Debug_runtime.log_value_pp ~descr:"x" ~pp ~v:x); - if Debug_runtime.exceeds_max_nesting () + (if Debug_runtime.exceeds_max_children () then (Debug_runtime.log_value_show ~descr:"bar" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") else - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"bar" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_num_children exceeded") - else - (match let y : num = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_pp.ml" ~pos_lnum:8 ~pos_colnum:6 - ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") - else - (match (x.first + 1 : num) with - | y__res -> - (Debug_runtime.log_value_pp ~descr:"y" ~pp:pp_num - ~v:y__res; - Debug_runtime.close_log (); - y__res) - | exception e -> (Debug_runtime.close_log (); raise e))) in - x.second * y - with - | bar__res -> - (Debug_runtime.log_value_pp ~descr:"bar" ~pp:pp_num ~v:bar__res; - Debug_runtime.close_log (); - bar__res) - | exception e -> (Debug_runtime.close_log (); raise e)) : num) + ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_pp.ml" + ~start_lnum:7 ~start_colnum:17 ~end_lnum:9 ~end_colnum:14 + ~message:"bar"; + Debug_runtime.log_value_pp ~descr:"x" ~pp ~v:x); + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"bar" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match let y : num = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_pp.ml" ~pos_lnum:8 ~pos_colnum:6 + ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match (x.first + 1 : num) with + | y__res -> + (Debug_runtime.log_value_pp ~descr:"y" ~pp:pp_num + ~v:y__res; + Debug_runtime.close_log (); + y__res) + | exception e -> (Debug_runtime.close_log (); raise e))) in + x.second * y + with + | bar__res -> + (Debug_runtime.log_value_pp ~descr:"bar" ~pp:pp_num ~v:bar__res; + Debug_runtime.close_log (); + bar__res) + | exception e -> (Debug_runtime.close_log (); raise e))) : num) let () = ignore @@ (bar { first = 7; second = 42 }) let baz (x : t) = - ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_pp.ml" - ~start_lnum:13 ~start_colnum:17 ~end_lnum:15 ~end_colnum:20 - ~message:"baz"; - Debug_runtime.log_value_pp ~descr:"x" ~pp ~v:x); - if Debug_runtime.exceeds_max_nesting () + (if Debug_runtime.exceeds_max_children () then (Debug_runtime.log_value_show ~descr:"baz" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") else - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"baz" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_num_children exceeded") - else - (match let (({ first = y; second = z } as _yz) : t) = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"_yz" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_pp.ml" ~pos_lnum:14 ~pos_colnum:36 - ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"_yz" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") - else - (match { first = (x.first + 1); second = 3 } with - | _yz__res -> - (Debug_runtime.log_value_pp ~descr:"_yz" ~pp - ~v:_yz__res; - Debug_runtime.close_log (); - _yz__res) - | exception e -> (Debug_runtime.close_log (); raise e))) in - (x.second * y) + z - with - | baz__res -> - (Debug_runtime.log_value_pp ~descr:"baz" ~pp:pp_num ~v:baz__res; - Debug_runtime.close_log (); - baz__res) - | exception e -> (Debug_runtime.close_log (); raise e)) : num) + ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_pp.ml" + ~start_lnum:13 ~start_colnum:17 ~end_lnum:15 ~end_colnum:20 + ~message:"baz"; + Debug_runtime.log_value_pp ~descr:"x" ~pp ~v:x); + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"baz" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match let (({ first = y; second = z } as _yz) : t) = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"_yz" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_pp.ml" ~pos_lnum:14 ~pos_colnum:36 + ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"_yz" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match { first = (x.first + 1); second = 3 } with + | _yz__res -> + (Debug_runtime.log_value_pp ~descr:"_yz" ~pp + ~v:_yz__res; + Debug_runtime.close_log (); + _yz__res) + | exception e -> (Debug_runtime.close_log (); raise e))) in + (x.second * y) + z + with + | baz__res -> + (Debug_runtime.log_value_pp ~descr:"baz" ~pp:pp_num ~v:baz__res; + Debug_runtime.close_log (); + baz__res) + | exception e -> (Debug_runtime.close_log (); raise e))) : num) let () = ignore @@ (baz { first = 7; second = 42 }) let rec loop (depth : num) (x : t) = - (((Debug_runtime.open_log_preamble_full ~fname:"test_debug_pp.ml" - ~start_lnum:19 ~start_colnum:22 ~end_lnum:25 ~end_colnum:9 - ~message:"loop"; - Debug_runtime.log_value_pp ~descr:"depth" ~pp:pp_num ~v:depth); - Debug_runtime.log_value_pp ~descr:"x" ~pp ~v:x); - if Debug_runtime.exceeds_max_nesting () + (if Debug_runtime.exceeds_max_children () then (Debug_runtime.log_value_show ~descr:"loop" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") else - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"loop" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_num_children exceeded") - else - (match if depth > 6 - then x.first + x.second - else - if depth > 3 - then - loop (depth + 1) - { first = (x.second + 1); second = (x.first / 2) } - else - (let y : num = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_pp.ml" ~pos_lnum:23 - ~pos_colnum:8 ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - Debug_runtime.close_log (); - failwith - "ppx_minidebug: max_nesting_depth exceeded") - else - (match (loop (depth + 1) - { - first = (x.second - 1); - second = (x.first + 2) - } : num) - with - | y__res -> - (Debug_runtime.log_value_pp ~descr:"y" - ~pp:pp_num ~v:y__res; - Debug_runtime.close_log (); - y__res) - | exception e -> - (Debug_runtime.close_log (); raise e))) in - let z : num = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"z" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_pp.ml" ~pos_lnum:24 - ~pos_colnum:8 ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"z" - ~v:""; - Debug_runtime.close_log (); - failwith - "ppx_minidebug: max_nesting_depth exceeded") - else - (match (loop (depth + 1) - { first = (x.second + 1); second = y } : - num) - with - | z__res -> - (Debug_runtime.log_value_pp ~descr:"z" - ~pp:pp_num ~v:z__res; - Debug_runtime.close_log (); - z__res) - | exception e -> - (Debug_runtime.close_log (); raise e))) in - z + 7) - with - | loop__res -> - (Debug_runtime.log_value_pp ~descr:"loop" ~pp:pp_num ~v:loop__res; - Debug_runtime.close_log (); - loop__res) - | exception e -> (Debug_runtime.close_log (); raise e)) : num) + (((Debug_runtime.open_log_preamble_full ~fname:"test_debug_pp.ml" + ~start_lnum:19 ~start_colnum:22 ~end_lnum:25 ~end_colnum:9 + ~message:"loop"; + Debug_runtime.log_value_pp ~descr:"depth" ~pp:pp_num ~v:depth); + Debug_runtime.log_value_pp ~descr:"x" ~pp ~v:x); + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"loop" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match if depth > 6 + then x.first + x.second + else + if depth > 3 + then + loop (depth + 1) + { first = (x.second + 1); second = (x.first / 2) } + else + (let y : num = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_pp.ml" ~pos_lnum:23 + ~pos_colnum:8 ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + Debug_runtime.close_log (); + failwith + "ppx_minidebug: max_nesting_depth exceeded") + else + (match (loop (depth + 1) + { + first = (x.second - 1); + second = (x.first + 2) + } : num) + with + | y__res -> + (Debug_runtime.log_value_pp ~descr:"y" + ~pp:pp_num ~v:y__res; + Debug_runtime.close_log (); + y__res) + | exception e -> + (Debug_runtime.close_log (); raise e))) in + let z : num = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"z" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_pp.ml" ~pos_lnum:24 + ~pos_colnum:8 ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"z" + ~v:""; + Debug_runtime.close_log (); + failwith + "ppx_minidebug: max_nesting_depth exceeded") + else + (match (loop (depth + 1) + { first = (x.second + 1); second = y } : + num) + with + | z__res -> + (Debug_runtime.log_value_pp ~descr:"z" + ~pp:pp_num ~v:z__res; + Debug_runtime.close_log (); + z__res) + | exception e -> + (Debug_runtime.close_log (); raise e))) in + z + 7) + with + | loop__res -> + (Debug_runtime.log_value_pp ~descr:"loop" ~pp:pp_num + ~v:loop__res; + Debug_runtime.close_log (); + loop__res) + | exception e -> (Debug_runtime.close_log (); raise e))) : num) let () = ignore @@ (loop 0 { first = 7; second = 42 }) diff --git a/test/test_debug_sexp.expected.ml b/test/test_debug_sexp.expected.ml index 08c0b01..da17e9e 100644 --- a/test/test_debug_sexp.expected.ml +++ b/test/test_debug_sexp.expected.ml @@ -2,335 +2,330 @@ open Sexplib0.Sexp_conv module Debug_runtime = (Minidebug_runtime.PrintBox)((val Minidebug_runtime.debug_ch "debugger_sexp_printbox.log")) let foo (x : int) = - ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_sexp.ml" - ~start_lnum:7 ~start_colnum:19 ~end_lnum:9 ~end_colnum:17 - ~message:"foo"; - Debug_runtime.log_value_sexp ~descr:"x" ~sexp:(([%sexp_of : int]) x)); - if Debug_runtime.exceeds_max_nesting () + (if Debug_runtime.exceeds_max_children () then (Debug_runtime.log_value_show ~descr:"foo" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") else - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"foo" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_num_children exceeded") - else - (match let y : int = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_sexp.ml" ~pos_lnum:8 ~pos_colnum:6 - ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") - else - (match (x + 1 : int) with - | y__res -> - (Debug_runtime.log_value_sexp ~descr:"y" - ~sexp:(([%sexp_of : int]) y__res); - Debug_runtime.close_log (); - y__res) - | exception e -> (Debug_runtime.close_log (); raise e))) in - [x; y; 2 * y] - with - | foo__res -> - (Debug_runtime.log_value_sexp ~descr:"foo" - ~sexp:(([%sexp_of : int list]) foo__res); - Debug_runtime.close_log (); - foo__res) - | exception e -> (Debug_runtime.close_log (); raise e)) : int list) + ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_sexp.ml" + ~start_lnum:7 ~start_colnum:19 ~end_lnum:9 ~end_colnum:17 + ~message:"foo"; + Debug_runtime.log_value_sexp ~descr:"x" ~sexp:(([%sexp_of : int]) x)); + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"foo" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match let y : int = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_sexp.ml" ~pos_lnum:8 ~pos_colnum:6 + ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match (x + 1 : int) with + | y__res -> + (Debug_runtime.log_value_sexp ~descr:"y" + ~sexp:(([%sexp_of : int]) y__res); + Debug_runtime.close_log (); + y__res) + | exception e -> (Debug_runtime.close_log (); raise e))) in + [x; y; 2 * y] + with + | foo__res -> + (Debug_runtime.log_value_sexp ~descr:"foo" + ~sexp:(([%sexp_of : int list]) foo__res); + Debug_runtime.close_log (); + foo__res) + | exception e -> (Debug_runtime.close_log (); raise e))) : int list) let () = ignore @@ (List.hd @@ (foo 7)) type t = { first: int ; second: int }[@@deriving sexp] let bar (x : t) = - ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_sexp.ml" - ~start_lnum:15 ~start_colnum:19 ~end_lnum:17 ~end_colnum:14 - ~message:"bar"; - Debug_runtime.log_value_sexp ~descr:"x" ~sexp:(([%sexp_of : t]) x)); - if Debug_runtime.exceeds_max_nesting () + (if Debug_runtime.exceeds_max_children () then (Debug_runtime.log_value_show ~descr:"bar" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") else - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"bar" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_num_children exceeded") - else - (match let y : int = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_sexp.ml" ~pos_lnum:16 ~pos_colnum:6 - ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") - else - (match (x.first + 1 : int) with - | y__res -> - (Debug_runtime.log_value_sexp ~descr:"y" - ~sexp:(([%sexp_of : int]) y__res); - Debug_runtime.close_log (); - y__res) - | exception e -> (Debug_runtime.close_log (); raise e))) in - x.second * y - with - | bar__res -> - (Debug_runtime.log_value_sexp ~descr:"bar" - ~sexp:(([%sexp_of : int]) bar__res); - Debug_runtime.close_log (); - bar__res) - | exception e -> (Debug_runtime.close_log (); raise e)) : int) + ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_sexp.ml" + ~start_lnum:15 ~start_colnum:19 ~end_lnum:17 ~end_colnum:14 + ~message:"bar"; + Debug_runtime.log_value_sexp ~descr:"x" ~sexp:(([%sexp_of : t]) x)); + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"bar" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match let y : int = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_sexp.ml" ~pos_lnum:16 ~pos_colnum:6 + ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match (x.first + 1 : int) with + | y__res -> + (Debug_runtime.log_value_sexp ~descr:"y" + ~sexp:(([%sexp_of : int]) y__res); + Debug_runtime.close_log (); + y__res) + | exception e -> (Debug_runtime.close_log (); raise e))) in + x.second * y + with + | bar__res -> + (Debug_runtime.log_value_sexp ~descr:"bar" + ~sexp:(([%sexp_of : int]) bar__res); + Debug_runtime.close_log (); + bar__res) + | exception e -> (Debug_runtime.close_log (); raise e))) : int) let () = ignore @@ (bar { first = 7; second = 42 }) let baz (x : t) = - ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_sexp.ml" - ~start_lnum:21 ~start_colnum:19 ~end_lnum:24 ~end_colnum:28 - ~message:"baz"; - Debug_runtime.log_value_sexp ~descr:"x" ~sexp:(([%sexp_of : t]) x)); - if Debug_runtime.exceeds_max_nesting () + (if Debug_runtime.exceeds_max_children () then (Debug_runtime.log_value_show ~descr:"baz" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") else - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"baz" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_num_children exceeded") - else - (match let (((y, z) as _yz) : (int * int)) = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"_yz" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_sexp.ml" ~pos_lnum:22 ~pos_colnum:17 - ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"_yz" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") - else - (match ((x.first + 1), 3) with - | _yz__res -> - (Debug_runtime.log_value_sexp ~descr:"_yz" - ~sexp:(([%sexp_of : (int * int)]) _yz__res); - Debug_runtime.close_log (); - _yz__res) - | exception e -> (Debug_runtime.close_log (); raise e))) in - let (((u, w) as _uw) : (int * int)) = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"_uw" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_sexp.ml" ~pos_lnum:23 ~pos_colnum:17 - ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"_uw" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") - else - (match (7, 13) with - | _uw__res -> - (Debug_runtime.log_value_sexp ~descr:"_uw" - ~sexp:(([%sexp_of : (int * int)]) _uw__res); - Debug_runtime.close_log (); - _uw__res) - | exception e -> (Debug_runtime.close_log (); raise e))) in - (((x.second * y) + z) + u) + w - with - | baz__res -> - (Debug_runtime.log_value_sexp ~descr:"baz" - ~sexp:(([%sexp_of : int]) baz__res); - Debug_runtime.close_log (); - baz__res) - | exception e -> (Debug_runtime.close_log (); raise e)) : int) + ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_sexp.ml" + ~start_lnum:21 ~start_colnum:19 ~end_lnum:24 ~end_colnum:28 + ~message:"baz"; + Debug_runtime.log_value_sexp ~descr:"x" ~sexp:(([%sexp_of : t]) x)); + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"baz" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match let (((y, z) as _yz) : (int * int)) = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"_yz" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_sexp.ml" ~pos_lnum:22 ~pos_colnum:17 + ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"_yz" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match ((x.first + 1), 3) with + | _yz__res -> + (Debug_runtime.log_value_sexp ~descr:"_yz" + ~sexp:(([%sexp_of : (int * int)]) _yz__res); + Debug_runtime.close_log (); + _yz__res) + | exception e -> (Debug_runtime.close_log (); raise e))) in + let (((u, w) as _uw) : (int * int)) = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"_uw" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_sexp.ml" ~pos_lnum:23 ~pos_colnum:17 + ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"_uw" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match (7, 13) with + | _uw__res -> + (Debug_runtime.log_value_sexp ~descr:"_uw" + ~sexp:(([%sexp_of : (int * int)]) _uw__res); + Debug_runtime.close_log (); + _uw__res) + | exception e -> (Debug_runtime.close_log (); raise e))) in + (((x.second * y) + z) + u) + w + with + | baz__res -> + (Debug_runtime.log_value_sexp ~descr:"baz" + ~sexp:(([%sexp_of : int]) baz__res); + Debug_runtime.close_log (); + baz__res) + | exception e -> (Debug_runtime.close_log (); raise e))) : int) let () = ignore @@ (baz { first = 7; second = 42 }) let lab ~x:(x : int) = - ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_sexp.ml" - ~start_lnum:28 ~start_colnum:19 ~end_lnum:30 ~end_colnum:17 - ~message:"lab"; - Debug_runtime.log_value_sexp ~descr:"x" ~sexp:(([%sexp_of : int]) x)); - if Debug_runtime.exceeds_max_nesting () + (if Debug_runtime.exceeds_max_children () then (Debug_runtime.log_value_show ~descr:"lab" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") else - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"lab" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_num_children exceeded") - else - (match let y : int = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_sexp.ml" ~pos_lnum:29 ~pos_colnum:6 - ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") - else - (match (x + 1 : int) with - | y__res -> - (Debug_runtime.log_value_sexp ~descr:"y" - ~sexp:(([%sexp_of : int]) y__res); - Debug_runtime.close_log (); - y__res) - | exception e -> (Debug_runtime.close_log (); raise e))) in - [x; y; 2 * y] - with - | lab__res -> - (Debug_runtime.log_value_sexp ~descr:"lab" - ~sexp:(([%sexp_of : int list]) lab__res); - Debug_runtime.close_log (); - lab__res) - | exception e -> (Debug_runtime.close_log (); raise e)) : int list) + ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_sexp.ml" + ~start_lnum:28 ~start_colnum:19 ~end_lnum:30 ~end_colnum:17 + ~message:"lab"; + Debug_runtime.log_value_sexp ~descr:"x" ~sexp:(([%sexp_of : int]) x)); + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"lab" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match let y : int = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_sexp.ml" ~pos_lnum:29 ~pos_colnum:6 + ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match (x + 1 : int) with + | y__res -> + (Debug_runtime.log_value_sexp ~descr:"y" + ~sexp:(([%sexp_of : int]) y__res); + Debug_runtime.close_log (); + y__res) + | exception e -> (Debug_runtime.close_log (); raise e))) in + [x; y; 2 * y] + with + | lab__res -> + (Debug_runtime.log_value_sexp ~descr:"lab" + ~sexp:(([%sexp_of : int list]) lab__res); + Debug_runtime.close_log (); + lab__res) + | exception e -> (Debug_runtime.close_log (); raise e))) : int list) let () = ignore @@ (List.hd @@ (lab ~x:7)) let rec loop (depth : int) (x : t) = - (((Debug_runtime.open_log_preamble_full ~fname:"test_debug_sexp.ml" - ~start_lnum:34 ~start_colnum:24 ~end_lnum:40 ~end_colnum:9 - ~message:"loop"; - Debug_runtime.log_value_sexp ~descr:"depth" - ~sexp:(([%sexp_of : int]) depth)); - Debug_runtime.log_value_sexp ~descr:"x" ~sexp:(([%sexp_of : t]) x)); - if Debug_runtime.exceeds_max_nesting () + (if Debug_runtime.exceeds_max_children () then (Debug_runtime.log_value_show ~descr:"loop" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") else - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"loop" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_num_children exceeded") - else - (match if depth > 4 - then x.first + x.second - else - if depth > 1 - then - loop (depth + 1) - { first = (x.second + 1); second = (x.first / 2) } - else - (let y : int = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_sexp.ml" ~pos_lnum:38 - ~pos_colnum:8 ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - Debug_runtime.close_log (); - failwith - "ppx_minidebug: max_nesting_depth exceeded") - else - (match (loop (depth + 1) - { - first = (x.second - 1); - second = (x.first + 2) - } : int) - with - | y__res -> - (Debug_runtime.log_value_sexp ~descr:"y" - ~sexp:(([%sexp_of : int]) y__res); - Debug_runtime.close_log (); - y__res) - | exception e -> - (Debug_runtime.close_log (); raise e))) in - let z : int = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"z" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_sexp.ml" ~pos_lnum:39 - ~pos_colnum:8 ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"z" - ~v:""; - Debug_runtime.close_log (); - failwith - "ppx_minidebug: max_nesting_depth exceeded") - else - (match (loop (depth + 1) - { first = (x.second + 1); second = y } : - int) - with - | z__res -> - (Debug_runtime.log_value_sexp ~descr:"z" - ~sexp:(([%sexp_of : int]) z__res); - Debug_runtime.close_log (); - z__res) - | exception e -> - (Debug_runtime.close_log (); raise e))) in - z + 7) - with - | loop__res -> - (Debug_runtime.log_value_sexp ~descr:"loop" - ~sexp:(([%sexp_of : int]) loop__res); - Debug_runtime.close_log (); - loop__res) - | exception e -> (Debug_runtime.close_log (); raise e)) : int) + (((Debug_runtime.open_log_preamble_full ~fname:"test_debug_sexp.ml" + ~start_lnum:34 ~start_colnum:24 ~end_lnum:40 ~end_colnum:9 + ~message:"loop"; + Debug_runtime.log_value_sexp ~descr:"depth" + ~sexp:(([%sexp_of : int]) depth)); + Debug_runtime.log_value_sexp ~descr:"x" ~sexp:(([%sexp_of : t]) x)); + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"loop" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match if depth > 4 + then x.first + x.second + else + if depth > 1 + then + loop (depth + 1) + { first = (x.second + 1); second = (x.first / 2) } + else + (let y : int = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_sexp.ml" ~pos_lnum:38 + ~pos_colnum:8 ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + Debug_runtime.close_log (); + failwith + "ppx_minidebug: max_nesting_depth exceeded") + else + (match (loop (depth + 1) + { + first = (x.second - 1); + second = (x.first + 2) + } : int) + with + | y__res -> + (Debug_runtime.log_value_sexp ~descr:"y" + ~sexp:(([%sexp_of : int]) y__res); + Debug_runtime.close_log (); + y__res) + | exception e -> + (Debug_runtime.close_log (); raise e))) in + let z : int = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"z" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_sexp.ml" ~pos_lnum:39 + ~pos_colnum:8 ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"z" + ~v:""; + Debug_runtime.close_log (); + failwith + "ppx_minidebug: max_nesting_depth exceeded") + else + (match (loop (depth + 1) + { first = (x.second + 1); second = y } : + int) + with + | z__res -> + (Debug_runtime.log_value_sexp ~descr:"z" + ~sexp:(([%sexp_of : int]) z__res); + Debug_runtime.close_log (); + z__res) + | exception e -> + (Debug_runtime.close_log (); raise e))) in + z + 7) + with + | loop__res -> + (Debug_runtime.log_value_sexp ~descr:"loop" + ~sexp:(([%sexp_of : int]) loop__res); + Debug_runtime.close_log (); + loop__res) + | exception e -> (Debug_runtime.close_log (); raise e))) : int) let () = ignore @@ (loop 0 { first = 7; second = 42 }) diff --git a/test/test_debug_show.expected.ml b/test/test_debug_show.expected.ml index e212285..1c3aecc 100644 --- a/test/test_debug_show.expected.ml +++ b/test/test_debug_show.expected.ml @@ -1,258 +1,255 @@ module Debug_runtime = (Minidebug_runtime.Flushing)((val Minidebug_runtime.debug_ch "debugger_show_flushing.log")) let foo (x : int) = - ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_show.ml" - ~start_lnum:5 ~start_colnum:19 ~end_lnum:7 ~end_colnum:17 - ~message:"foo"; - Debug_runtime.log_value_show ~descr:"x" ~v:(([%show : int]) x)); - if Debug_runtime.exceeds_max_nesting () + (if Debug_runtime.exceeds_max_children () then (Debug_runtime.log_value_show ~descr:"foo" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") else - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"foo" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_num_children exceeded") - else - (match let y : int = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_show.ml" ~pos_lnum:6 ~pos_colnum:6 - ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") - else - (match (x + 1 : int) with - | y__res -> - (Debug_runtime.log_value_show ~descr:"y" - ~v:(([%show : int]) y__res); - Debug_runtime.close_log (); - y__res) - | exception e -> (Debug_runtime.close_log (); raise e))) in - [x; y; 2 * y] - with - | foo__res -> - (Debug_runtime.log_value_show ~descr:"foo" - ~v:(([%show : int list]) foo__res); - Debug_runtime.close_log (); - foo__res) - | exception e -> (Debug_runtime.close_log (); raise e)) : int list) + ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_show.ml" + ~start_lnum:5 ~start_colnum:19 ~end_lnum:7 ~end_colnum:17 + ~message:"foo"; + Debug_runtime.log_value_show ~descr:"x" ~v:(([%show : int]) x)); + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"foo" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match let y : int = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_show.ml" ~pos_lnum:6 ~pos_colnum:6 + ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match (x + 1 : int) with + | y__res -> + (Debug_runtime.log_value_show ~descr:"y" + ~v:(([%show : int]) y__res); + Debug_runtime.close_log (); + y__res) + | exception e -> (Debug_runtime.close_log (); raise e))) in + [x; y; 2 * y] + with + | foo__res -> + (Debug_runtime.log_value_show ~descr:"foo" + ~v:(([%show : int list]) foo__res); + Debug_runtime.close_log (); + foo__res) + | exception e -> (Debug_runtime.close_log (); raise e))) : int list) let () = ignore @@ (List.hd @@ (foo 7)) type t = { first: int ; second: int }[@@deriving show] let bar (x : t) = - ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_show.ml" - ~start_lnum:13 ~start_colnum:19 ~end_lnum:15 ~end_colnum:14 - ~message:"bar"; - Debug_runtime.log_value_show ~descr:"x" ~v:(([%show : t]) x)); - if Debug_runtime.exceeds_max_nesting () + (if Debug_runtime.exceeds_max_children () then (Debug_runtime.log_value_show ~descr:"bar" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") else - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"bar" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_num_children exceeded") - else - (match let y : int = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_show.ml" ~pos_lnum:14 ~pos_colnum:6 - ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") - else - (match (x.first + 1 : int) with - | y__res -> - (Debug_runtime.log_value_show ~descr:"y" - ~v:(([%show : int]) y__res); - Debug_runtime.close_log (); - y__res) - | exception e -> (Debug_runtime.close_log (); raise e))) in - x.second * y - with - | bar__res -> - (Debug_runtime.log_value_show ~descr:"bar" - ~v:(([%show : int]) bar__res); - Debug_runtime.close_log (); - bar__res) - | exception e -> (Debug_runtime.close_log (); raise e)) : int) + ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_show.ml" + ~start_lnum:13 ~start_colnum:19 ~end_lnum:15 ~end_colnum:14 + ~message:"bar"; + Debug_runtime.log_value_show ~descr:"x" ~v:(([%show : t]) x)); + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"bar" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match let y : int = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_show.ml" ~pos_lnum:14 ~pos_colnum:6 + ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match (x.first + 1 : int) with + | y__res -> + (Debug_runtime.log_value_show ~descr:"y" + ~v:(([%show : int]) y__res); + Debug_runtime.close_log (); + y__res) + | exception e -> (Debug_runtime.close_log (); raise e))) in + x.second * y + with + | bar__res -> + (Debug_runtime.log_value_show ~descr:"bar" + ~v:(([%show : int]) bar__res); + Debug_runtime.close_log (); + bar__res) + | exception e -> (Debug_runtime.close_log (); raise e))) : int) let () = ignore @@ (bar { first = 7; second = 42 }) let baz (x : t) = - ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_show.ml" - ~start_lnum:19 ~start_colnum:19 ~end_lnum:21 ~end_colnum:20 - ~message:"baz"; - Debug_runtime.log_value_show ~descr:"x" ~v:(([%show : t]) x)); - if Debug_runtime.exceeds_max_nesting () + (if Debug_runtime.exceeds_max_children () then (Debug_runtime.log_value_show ~descr:"baz" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") else - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"baz" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_num_children exceeded") - else - (match let (((y, z) as _yz) : (int * int)) = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"_yz" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_show.ml" ~pos_lnum:20 ~pos_colnum:17 - ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"_yz" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") - else - (match ((x.first + 1), 3) with - | _yz__res -> - (Debug_runtime.log_value_show ~descr:"_yz" - ~v:(([%show : (int * int)]) _yz__res); - Debug_runtime.close_log (); - _yz__res) - | exception e -> (Debug_runtime.close_log (); raise e))) in - (x.second * y) + z - with - | baz__res -> - (Debug_runtime.log_value_show ~descr:"baz" - ~v:(([%show : int]) baz__res); - Debug_runtime.close_log (); - baz__res) - | exception e -> (Debug_runtime.close_log (); raise e)) : int) + ((Debug_runtime.open_log_preamble_full ~fname:"test_debug_show.ml" + ~start_lnum:19 ~start_colnum:19 ~end_lnum:21 ~end_colnum:20 + ~message:"baz"; + Debug_runtime.log_value_show ~descr:"x" ~v:(([%show : t]) x)); + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"baz" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match let (((y, z) as _yz) : (int * int)) = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"_yz" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_show.ml" ~pos_lnum:20 ~pos_colnum:17 + ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"_yz" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match ((x.first + 1), 3) with + | _yz__res -> + (Debug_runtime.log_value_show ~descr:"_yz" + ~v:(([%show : (int * int)]) _yz__res); + Debug_runtime.close_log (); + _yz__res) + | exception e -> (Debug_runtime.close_log (); raise e))) in + (x.second * y) + z + with + | baz__res -> + (Debug_runtime.log_value_show ~descr:"baz" + ~v:(([%show : int]) baz__res); + Debug_runtime.close_log (); + baz__res) + | exception e -> (Debug_runtime.close_log (); raise e))) : int) let () = ignore @@ (baz { first = 7; second = 42 }) let rec loop (depth : int) (x : t) = - (((Debug_runtime.open_log_preamble_full ~fname:"test_debug_show.ml" - ~start_lnum:25 ~start_colnum:24 ~end_lnum:31 ~end_colnum:9 - ~message:"loop"; - Debug_runtime.log_value_show ~descr:"depth" ~v:(([%show : int]) depth)); - Debug_runtime.log_value_show ~descr:"x" ~v:(([%show : t]) x)); - if Debug_runtime.exceeds_max_nesting () + (if Debug_runtime.exceeds_max_children () then (Debug_runtime.log_value_show ~descr:"loop" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_nesting_depth exceeded") + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") else - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"loop" - ~v:""; - Debug_runtime.close_log (); - failwith "ppx_minidebug: max_num_children exceeded") - else - (match if depth > 6 - then x.first + x.second - else - if depth > 3 - then - loop (depth + 1) - { first = (x.second + 1); second = (x.first / 2) } - else - (let y : int = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_show.ml" ~pos_lnum:29 - ~pos_colnum:8 ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"y" - ~v:""; - Debug_runtime.close_log (); - failwith - "ppx_minidebug: max_nesting_depth exceeded") - else - (match (loop (depth + 1) - { - first = (x.second - 1); - second = (x.first + 2) - } : int) - with - | y__res -> - (Debug_runtime.log_value_show ~descr:"y" - ~v:(([%show : int]) y__res); - Debug_runtime.close_log (); - y__res) - | exception e -> - (Debug_runtime.close_log (); raise e))) in - let z : int = - if Debug_runtime.exceeds_max_children () - then - (Debug_runtime.log_value_show ~descr:"z" - ~v:""; - failwith "ppx_minidebug: max_num_children exceeded") - else - (Debug_runtime.open_log_preamble_brief - ~fname:"test_debug_show.ml" ~pos_lnum:30 - ~pos_colnum:8 ~message:" "; - if Debug_runtime.exceeds_max_nesting () - then - (Debug_runtime.log_value_show ~descr:"z" - ~v:""; - Debug_runtime.close_log (); - failwith - "ppx_minidebug: max_nesting_depth exceeded") - else - (match (loop (depth + 1) - { first = (x.second + 1); second = y } : - int) - with - | z__res -> - (Debug_runtime.log_value_show ~descr:"z" - ~v:(([%show : int]) z__res); - Debug_runtime.close_log (); - z__res) - | exception e -> - (Debug_runtime.close_log (); raise e))) in - z + 7) - with - | loop__res -> - (Debug_runtime.log_value_show ~descr:"loop" - ~v:(([%show : int]) loop__res); - Debug_runtime.close_log (); - loop__res) - | exception e -> (Debug_runtime.close_log (); raise e)) : int) + (((Debug_runtime.open_log_preamble_full ~fname:"test_debug_show.ml" + ~start_lnum:25 ~start_colnum:24 ~end_lnum:31 ~end_colnum:9 + ~message:"loop"; + Debug_runtime.log_value_show ~descr:"depth" + ~v:(([%show : int]) depth)); + Debug_runtime.log_value_show ~descr:"x" ~v:(([%show : t]) x)); + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"loop" + ~v:""; + Debug_runtime.close_log (); + failwith "ppx_minidebug: max_nesting_depth exceeded") + else + (match if depth > 6 + then x.first + x.second + else + if depth > 3 + then + loop (depth + 1) + { first = (x.second + 1); second = (x.first / 2) } + else + (let y : int = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_show.ml" ~pos_lnum:29 + ~pos_colnum:8 ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"y" + ~v:""; + Debug_runtime.close_log (); + failwith + "ppx_minidebug: max_nesting_depth exceeded") + else + (match (loop (depth + 1) + { + first = (x.second - 1); + second = (x.first + 2) + } : int) + with + | y__res -> + (Debug_runtime.log_value_show ~descr:"y" + ~v:(([%show : int]) y__res); + Debug_runtime.close_log (); + y__res) + | exception e -> + (Debug_runtime.close_log (); raise e))) in + let z : int = + if Debug_runtime.exceeds_max_children () + then + (Debug_runtime.log_value_show ~descr:"z" + ~v:""; + failwith "ppx_minidebug: max_num_children exceeded") + else + (Debug_runtime.open_log_preamble_brief + ~fname:"test_debug_show.ml" ~pos_lnum:30 + ~pos_colnum:8 ~message:" "; + if Debug_runtime.exceeds_max_nesting () + then + (Debug_runtime.log_value_show ~descr:"z" + ~v:""; + Debug_runtime.close_log (); + failwith + "ppx_minidebug: max_nesting_depth exceeded") + else + (match (loop (depth + 1) + { first = (x.second + 1); second = y } : + int) + with + | z__res -> + (Debug_runtime.log_value_show ~descr:"z" + ~v:(([%show : int]) z__res); + Debug_runtime.close_log (); + z__res) + | exception e -> + (Debug_runtime.close_log (); raise e))) in + z + 7) + with + | loop__res -> + (Debug_runtime.log_value_show ~descr:"loop" + ~v:(([%show : int]) loop__res); + Debug_runtime.close_log (); + loop__res) + | exception e -> (Debug_runtime.close_log (); raise e))) : int) let () = ignore @@ (loop 0 { first = 7; second = 42 }) diff --git a/test/test_expect_test.ml b/test/test_expect_test.ml index d22d032..e87b602 100644 --- a/test/test_expect_test.ml +++ b/test/test_expect_test.ml @@ -274,39 +274,39 @@ let%expect_test "%debug_show PrintBox to stdout num children exceeded nested" = [%expect {| BEGIN DEBUG SESSION - "test/test_expect_test.ml":258:40-264:69: loop_exceeded + "test/test_expect_test.ml":262:40-268:69: loop_exceeded ├─x = 3 - ├─"test/test_expect_test.ml":263:15: + ├─"test/test_expect_test.ml":267:15: │ └─z = 1 - └─"test/test_expect_test.ml":258:40-264:69: loop_exceeded + └─"test/test_expect_test.ml":262:40-268:69: loop_exceeded ├─x = 2 - ├─"test/test_expect_test.ml":263:15: + ├─"test/test_expect_test.ml":267:15: │ └─z = 0 - └─"test/test_expect_test.ml":258:40-264:69: loop_exceeded + └─"test/test_expect_test.ml":262:40-268:69: loop_exceeded ├─x = 1 - ├─"test/test_expect_test.ml":263:15: + ├─"test/test_expect_test.ml":267:15: │ └─z = 0 - └─"test/test_expect_test.ml":258:40-264:69: loop_exceeded + └─"test/test_expect_test.ml":262:40-268:69: loop_exceeded ├─x = 0 - ├─"test/test_expect_test.ml":263:15: + ├─"test/test_expect_test.ml":267:15: │ └─z = 0 - ├─"test/test_expect_test.ml":263:15: + ├─"test/test_expect_test.ml":267:15: │ └─z = 1 - ├─"test/test_expect_test.ml":263:15: + ├─"test/test_expect_test.ml":267:15: │ └─z = 2 - ├─"test/test_expect_test.ml":263:15: + ├─"test/test_expect_test.ml":267:15: │ └─z = 3 - ├─"test/test_expect_test.ml":263:15: + ├─"test/test_expect_test.ml":267:15: │ └─z = 4 - ├─"test/test_expect_test.ml":263:15: + ├─"test/test_expect_test.ml":267:15: │ └─z = 5 - ├─"test/test_expect_test.ml":263:15: + ├─"test/test_expect_test.ml":267:15: │ └─z = 6 - ├─"test/test_expect_test.ml":263:15: + ├─"test/test_expect_test.ml":267:15: │ └─z = 7 - ├─"test/test_expect_test.ml":263:15: + ├─"test/test_expect_test.ml":267:15: │ └─z = 8 - ├─"test/test_expect_test.ml":263:15: + ├─"test/test_expect_test.ml":267:15: │ └─z = 9 └─z = Raised exception: ppx_minidebug: max_num_children exceeded |}]