Skip to content

Commit

Permalink
Fix "unused identifiers" error when not logging results
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi committed Feb 15, 2024
1 parent 5d82a81 commit e50d062
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 17 deletions.
3 changes: 3 additions & 0 deletions ppx_minidebug.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type log_level =
| Nonempty_entries
| Everything

let no_results = function Nothing | Prefixed _ -> true | _ -> false

type toplevel_opt_arg = Nested | Toplevel_no_arg | Generic | PrintBox

let global_log_count = ref 0
Expand Down Expand Up @@ -753,6 +755,7 @@ let debug_binding context callback vb =
| { pexp_desc = Pexp_function cases; _ } ->
debug_function context callback ~loc:vb.pvb_expr.pexp_loc ?ret_descr ?ret_typ
?arg_typ cases
| _ when no_results context.log_level -> callback nested exp
| _ ->
let result, bound = bound_patterns ~alt_typ:typ pat in
if bound = [] then callback nested exp
Expand Down
49 changes: 49 additions & 0 deletions test/debugger_show_log_prefixed.expected.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,51 @@

BEGIN DEBUG SESSION
loop_exceeded begin "test/test_debug_log_prefixed.ml":7:33-12:55
("INFO: inside loop", 7)
loop_exceeded begin "test/test_debug_log_prefixed.ml":7:33-12:55
("INFO: inside loop", 6)
loop_exceeded begin "test/test_debug_log_prefixed.ml":7:33-12:55
("INFO: inside loop", 5)
loop_exceeded begin "test/test_debug_log_prefixed.ml":7:33-12:55
("INFO: inside loop", 4)
loop_exceeded begin "test/test_debug_log_prefixed.ml":7:33-12:55
("INFO: inside loop", 3)
loop_exceeded begin "test/test_debug_log_prefixed.ml":7:33-12:55
("INFO: inside loop", 2)
loop_exceeded begin "test/test_debug_log_prefixed.ml":7:33-12:55
("INFO: inside loop", 1)
loop_exceeded begin "test/test_debug_log_prefixed.ml":7:33-12:55
("INFO: inside loop", 0)
loop_exceeded end
loop_exceeded end
loop_exceeded end
loop_exceeded end
loop_exceeded end
loop_exceeded end
loop_exceeded end
loop_exceeded end
bar begin "test/test_debug_log_prefixed.ml":18:19-22:6
"test/test_debug_log_prefixed.ml":19:2: <for loop>
"test/test_debug_log_prefixed.ml":19:6: <for i>
("INFO: loop step", 0, "value", 0)
"test/test_debug_log_prefixed.ml":19:6: <for i>
("INFO: loop step", 1, "value", 2)
"test/test_debug_log_prefixed.ml":19:6: <for i>
("INFO: loop step", 2, "value", 4)
"test/test_debug_log_prefixed.ml":19:6: <for i>
("INFO: loop step", 3, "value", 6)
"test/test_debug_log_prefixed.ml":19:6: <for i>
("INFO: loop step", 4, "value", 8)
"test/test_debug_log_prefixed.ml":19:6: <for i>
("INFO: loop step", 5, "value", 10)
"test/test_debug_log_prefixed.ml":19:6: <for i>
("INFO: loop step", 6, "value", 12)
"test/test_debug_log_prefixed.ml":19:6: <for i>
("INFO: loop step", 7, "value", 14)
"test/test_debug_log_prefixed.ml":19:6: <for i>
("INFO: loop step", 8, "value", 16)
"test/test_debug_log_prefixed.ml":19:6: <for i>
("INFO: loop step", 9, "value", 18)
"test/test_debug_log_prefixed.ml":19:6: <for i>
("INFO: loop step", 10, "value", 20)
bar end
21 changes: 6 additions & 15 deletions test/test_debug_log_prefixed.expected.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,16 @@ let rec loop_exceeded (x : int) =
~message:"loop_exceeded" ~entry_id:__entry_id;
());
(match let z : int =
let __entry_id = Debug_runtime.get_entry_id () in
();
Debug_runtime.open_log_preamble_brief
~fname:"test_debug_log_prefixed.ml" ~pos_lnum:8 ~pos_colnum:6
~message:"z" ~entry_id:__entry_id;
(match Debug_runtime.log_value_show ?descr:None
~entry_id:__entry_id ~is_result:false
(([%show : (string * int)])
("INFO: inside loop", (x : int)));
(x - 1) / 2
with
| _z as __res -> (((); ()); Debug_runtime.close_log (); __res)
| exception e -> (Debug_runtime.close_log (); raise e)) in
Debug_runtime.log_value_show ?descr:None ~entry_id:__entry_id
~is_result:false
(([%show : (string * int)]) ("INFO: inside loop", (x : int)));
(x - 1) / 2 in
if x <= 0 then 0 else z + (loop_exceeded (z + (x / 2)))
with
| __res -> ((); Debug_runtime.close_log (); __res)
| exception e -> (Debug_runtime.close_log (); raise e)) : int)
let () =
try print_endline @@ (Int.to_string @@ (loop_exceeded 17))
try print_endline @@ (Int.to_string @@ (loop_exceeded 7))
with | _ -> print_endline "Raised exception."
let bar () =
(let __entry_id = Debug_runtime.get_entry_id () in
Expand All @@ -39,7 +30,7 @@ let bar () =
Debug_runtime.open_log_preamble_brief
~fname:"test_debug_log_prefixed.ml" ~pos_lnum:19 ~pos_colnum:2
~message:"<for loop>" ~entry_id:__entry_id;
(match for i = 0 to 100 do
(match for i = 0 to 10 do
let __entry_id = Debug_runtime.get_entry_id () in
();
Debug_runtime.open_log_preamble_brief
Expand Down
4 changes: 2 additions & 2 deletions test/test_debug_log_prefixed.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ let%debug_show rec loop_exceeded (x : int) : int =
if x <= 0 then 0 else z + loop_exceeded (z + (x / 2))

let () =
try print_endline @@ Int.to_string @@ loop_exceeded 17
try print_endline @@ Int.to_string @@ loop_exceeded 7
with _ -> print_endline "Raised exception."

let%track_show bar () : unit =
for i = 0 to 100 do
for i = 0 to 10 do
let _baz : int = i * 2 in
[%log "INFO: loop step", (i : int), "value", (_baz : int)]
done
Expand Down

0 comments on commit e50d062

Please sign in to comment.