Skip to content

Commit 3419641

Browse files
vouillonhhugo
authored andcommitted
Consider more precisely all debug event kinds
1 parent 2288d66 commit 3419641

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

compiler/lib/parse_bytecode.ml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -952,25 +952,36 @@ and compile infos pc state instrs =
952952
(* Ignore allocation events (not very interesting) *)
953953
if debug_parser () then Format.eprintf "Ignored allocation event@.";
954954
instrs
955-
| ( { ev_kind = Event_pseudo | Event_after _; _ }
955+
| ( { ev_kind = Event_pseudo | Event_after _; ev_info = Event_return _; _ }
956956
, ((Let (_, (Apply _ | Prim _)), _) as i) :: rem ) ->
957+
(* Event after a call. If it is followed by another event,
958+
it may have been weaken to a pseudo-event but was kept
959+
for stack traces *)
957960
if debug_parser () then Format.eprintf "Added event across call@.";
958961
push_event After source event (i :: push_event Before source event rem)
959962
| { ev_kind = Event_pseudo; ev_info = Event_function; _ }, [] ->
960963
(* At beginning of function *)
961964
if debug_parser () then Format.eprintf "Added event at function start@.";
962965
push_event Before source event instrs
963-
| { ev_kind = Event_after _ | Event_pseudo; _ }, _ ->
964-
if debug_parser () then Format.eprintf "Ignored useless event@.";
965-
(* Not interesting:
966-
- before a throw instruction, but we already have an event
967-
for the exception
968-
- omitted else clause
969-
*)
966+
| { ev_kind = Event_after _ | Event_pseudo; ev_info = Event_return _; _ }, _ ->
967+
if debug_parser ()
968+
then
969+
Format.eprintf "Ignored useless event (beginning of a block after a call)@.";
970970
instrs
971-
| _, _ ->
971+
| { ev_kind = Event_after _; ev_info = Event_other; _ }, _ ->
972+
if debug_parser ()
973+
then Format.eprintf "Ignored useless event (before a raise)@.";
974+
(* We already have an event for the exception. The
975+
compiler add these events for stack traces. *)
976+
instrs
977+
| { ev_kind = Event_before; ev_info = Event_other; _ }, _
978+
| { ev_kind = Event_before | Event_pseudo; ev_info = Event_function; _ }, _ ->
972979
if debug_parser () then Format.eprintf "added event@.";
973-
push_event Before source event instrs)
980+
push_event Before source event instrs
981+
| { ev_kind = Event_after _; ev_info = Event_function; _ }, _
982+
| { ev_kind = Event_before; ev_info = Event_return _; _ }, _ ->
983+
(* Nonsensical events *)
984+
assert false)
974985
in
975986

976987
if pc = infos.limit

compiler/tests-full/stdlib.cma.expected.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23386,9 +23386,9 @@
2338623386
bt = /*<<fun.ml:31:15>>*/ caml_call1(Stdlib_Printexc[12], 0),
2338723387
exn = /*<<fun.ml:32:6>>*/ [0, Finally_raised, e];
2338823388
caml_restore_raw_backtrace(exn, bt);
23389-
/*<<fun.ml:32:57>>*/ throw caml_maybe_attach_backtrace(exn, 0);
23389+
throw caml_maybe_attach_backtrace(exn, 0);
2339023390
}
23391-
}
23391+
/*<<fun.ml:32:57>>*/ }
2339223392
/*<<fun.ml:34:2>>*/ try{
2339323393
var result = /*<<fun.ml:34:8>>*/ caml_call1(work, 0);
2339423394
}
@@ -23397,8 +23397,8 @@
2339723397
work_exn = /*<<?>>*/ caml_wrap_exception(work_exn$0),
2339823398
work_bt = /*<<fun.ml:37:20>>*/ caml_call1(Stdlib_Printexc[12], 0);
2339923399
/*<<fun.ml:38:6>>*/ finally_no_exn(0);
23400-
/*<<fun.ml:39:6>>*/ caml_restore_raw_backtrace(work_exn, work_bt);
23401-
/*<<fun.ml:39:52>>*/ throw caml_maybe_attach_backtrace(work_exn, 0);
23400+
/*<<fun.ml:38:23>>*/ caml_restore_raw_backtrace(work_exn, work_bt);
23401+
throw caml_maybe_attach_backtrace(work_exn, 0);
2340223402
}
2340323403
/*<<fun.ml:35:14>>*/ finally_no_exn(0);
2340423404
/*<<fun.ml:35:31>>*/ return result;
@@ -36172,8 +36172,8 @@
3617236172
var _d_ = /*<<effect.ml:68:11>>*/ caml_continuation_use_noexc(k);
3617336173
function _c_(e){
3617436174
/*<<effect.ml:68:41>>*/ caml_restore_raw_backtrace(e, bt);
36175-
/*<<effect.ml:68:75>>*/ throw caml_maybe_attach_backtrace(e, 0);
36176-
}
36175+
throw caml_maybe_attach_backtrace(e, 0);
36176+
/*<<effect.ml:68:75>>*/ }
3617736177
/*<<effect.ml:68:30>>*/ return jsoo_effect_not_supported() /*<<effect.ml:69:27>>*/ ;
3617836178
}
3617936179
function match_with(comp, arg, handler){
@@ -36292,9 +36292,8 @@
3629236292
(k,
3629336293
function(e){
3629436294
/*<<effect.ml:174:29>>*/ caml_restore_raw_backtrace(e, bt);
36295-
/*<<effect.ml:174:63>>*/ throw caml_maybe_attach_backtrace
36296-
(e, 0);
36297-
},
36295+
throw caml_maybe_attach_backtrace(e, 0);
36296+
/*<<effect.ml:174:63>>*/ },
3629836297
v,
3629936298
handler) /*<<effect.ml:174:74>>*/ ;
3630036299
}

0 commit comments

Comments
 (0)