js_of_ocaml
js_of_ocaml copied to clipboard
[BUG] js_of_ocaml-ppx doesn't emit sufficient locations for sourcemap.
Hi, dear ocsigen guys!
I'm recently playing with js_of_ocaml and notice an issue that jsoo_link has no --debug-info option and after all the separate js files are linked together, the debug-info seems lost, that is, the source map still works but I can't add a breakpoint in the debug tool of firefox/chrome
I've tried to build these files by dune(switch on/off separate compilation by dune profile) or by hand, they all behave as described above.
I don't think jsoo debug info (js comments in the generated source) is relevant here. Are things working fine when not using separate compilation ? How do you know sourcemap works if you cannot set breakpoint ? Would you be able to share a repro case ?
Hi, hhugo
compiler and build system:
ocaml 4.06 or 4.08 js_of_ocaml 3.5.2 dune 2.0.1
pictures will explain better
with release profile, dune won't perform separate compilation, and I can see the source map and can set breakpoint from line 18-24, 26-31

then if I use the dev profile or compile it by hand using the separate compilation, I get:

as you can see, we can still see the souremap, l.bc.js and its original source code, l.ml m.ml but there's no place where I can set a breakpoint, all the line number are gray and clicking on it react nothing.
Can you reproduce? If not, may I provide some more info?
I'm not able to reproduce. Can you share the code and the dune file ?
I don't think this has anything to do with separate compilation.
It's rather related to the the ppx syntax extension and how it uses locations.
Here is an extract of your example (jo.tar.gz) using --no-inline and --debug-info
let context= canvas##getContext Dom_html._2d_ in
context##.lineWidth:= 5.;
context##.strokeStyle:= Js.string "#ffff00";
context##moveTo 20. 20.;
context##lineTo 80. 80.;
context##stroke;
function _x_(x)
{ /*<<src/l.ml 13 17>>*/ return /*<<src/l.ml 13 17>>*/ caml_call1
( /*<<src/l.ml 13 17>>*/ caml_get_public_method
(x,-388424711,5),
x) /*<<src/l.ml 13 35>>*/ }
var _y_=Js_of_ocaml_Dom_html[1];
function _z_(t9,t8,param){ /*<<?>>*/ return t9.getContext(t8)}
var context=_z_(canvas,_y_,_x_);
function _A_(x)
{ /*<<src/l.ml 14 4>>*/ return /*<<src/l.ml 14 4>>*/ caml_call1
( /*<<src/l.ml 14 4>>*/ caml_get_public_method(x,291354994,6),
x) /*<<src/l.ml 14 23>>*/ }
var _B_=5.;
function _C_(t11,t10,param){ /*<<?>>*/ return t11.lineWidth = t10}
_C_(context,_B_,_A_);
function _D_(x)
{ /*<<src/l.ml 15 4>>*/ return /*<<src/l.ml 15 4>>*/ caml_call1
( /*<<src/l.ml 15 4>>*/ caml_get_public_method(x,483911257,7),
x) /*<<src/l.ml 15 25>>*/ }
/*<<src/l.ml 15 28>>*/ /*<<src/l.ml 15 28>>*/ var _E_="#ffff00";
/*<<src/l.ml 15 28>>*/ function _F_(t13,t12,param)
{ /*<<?>>*/ return t13.strokeStyle = t12}
_F_(context,_E_,_D_);
function _G_(x)
{ /*<<src/l.ml 16 4>>*/ return /*<<src/l.ml 16 4>>*/ caml_call1
( /*<<src/l.ml 16 4>>*/ caml_get_public_method(x,-861089044,8),
x) /*<<src/l.ml 16 19>>*/ }
var _H_=20.,_I_=20.;
function _J_(t16,t14,t15,param){ /*<<?>>*/ return t16.moveTo(t14,t15)}
_J_(context,_I_,_H_,_G_);
function _K_(x)
{ /*<<src/l.ml 17 4>>*/ return /*<<src/l.ml 17 4>>*/ caml_call1
( /*<<src/l.ml 17 4>>*/ caml_get_public_method(x,-325040497,9),
x) /*<<src/l.ml 17 19>>*/ }
var _L_=80.,_M_=80.;
function _N_(t19,t17,t18,param){ /*<<?>>*/ return t19.lineTo(t17,t18)}
_N_(context,_M_,_L_,_K_);
We can see here that there are locations attached to functions generated by js_of_ocaml-ppx but theses functions are actually deadcode and get removed once you drop the --no-inline flag. Real/Live function don't have locations once inlined (/*<<?>>*/)
Can not longer reproduce, I suspect the issues got fixed at some point.