Skip to content

Commit 4029802

Browse files
vouillonhhugo
authored andcommitted
Mutually recursive functions: add locations in wrapper
1 parent cb8de3a commit 4029802

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

compiler/lib/generate_closure.ml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,27 @@ module Trampoline = struct
133133
; branch = Return return, loc
134134
}
135135

136-
let wrapper_block f ~args ~counter loc =
136+
let wrapper_block f ~args ~counter loc loc' =
137137
let result1 = Code.Var.fresh () in
138138
let result2 = Code.Var.fresh () in
139139
let block =
140140
{ params = []
141141
; body =
142142
(match counter with
143143
| None ->
144-
[ Let (result1, Apply { f; args; exact = true }), loc
144+
[ Event loc, noloc
145+
; Let (result1, Apply { f; args; exact = true }), loc'
146+
; Event Parse_info.zero, noloc
145147
; Let (result2, Prim (Extern "caml_trampoline", [ Pv result1 ])), noloc
146148
]
147149
| Some counter ->
148-
[ Let (counter, Constant (Int Targetint.zero)), noloc
149-
; Let (result1, Apply { f; args = counter :: args; exact = true }), loc
150+
[ Event loc, noloc
151+
; Let (counter, Constant (Int Targetint.zero)), noloc
152+
; Let (result1, Apply { f; args = counter :: args; exact = true }), loc'
153+
; Event Parse_info.zero, noloc
150154
; Let (result2, Prim (Extern "caml_trampoline", [ Pv result1 ])), noloc
151155
])
152-
; branch = Return result2, loc
156+
; branch = Return result2, loc'
153157
}
154158
in
155159
block
@@ -187,8 +191,14 @@ module Trampoline = struct
187191
let wrapper_pc = free_pc in
188192
let free_pc = free_pc + 1 in
189193
let new_counter = Option.map counter ~f:Code.Var.fork in
194+
let start_loc =
195+
let block = Addr.Map.find (fst ci.cont) blocks in
196+
match block.body with
197+
| (Event loc, _) :: _ -> loc
198+
| _ -> Parse_info.zero
199+
in
190200
let wrapper_block =
191-
wrapper_block new_f ~args:new_args ~counter:new_counter ci.loc
201+
wrapper_block new_f ~args:new_args ~counter:new_counter start_loc ci.loc
192202
in
193203
let blocks = Addr.Map.add wrapper_pc wrapper_block blocks in
194204
let instr_wrapper = Let (ci.f_name, wrapper_closure wrapper_pc new_args) in

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

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18059,7 +18059,9 @@
1805918059
}
1806018060
}
1806118061
function make_printf(k, acc, fmt){
18062-
/*<<?>>*/ return caml_trampoline(make_printf$0(0, k, acc, fmt));
18062+
/*<<?>>*/ return caml_trampoline
18063+
( /*<<camlinternalFormat.ml:1518:17>>*/ make_printf$0
18064+
(0, k, acc, fmt)) /*<<?>>*/ ;
1806318065
}
1806418066
function make_ignored_param$0(counter, k, acc, ign, fmt){
1806518067
/*<<camlinternalFormat.ml:1613:21>>*/ if(typeof ign === "number")
@@ -18158,7 +18160,8 @@
1815818160
}
1815918161
function make_ignored_param(k, acc, ign, fmt){
1816018162
/*<<?>>*/ return caml_trampoline
18161-
(make_ignored_param$0(0, k, acc, ign, fmt));
18163+
( /*<<camlinternalFormat.ml:1613:21>>*/ make_ignored_param$0
18164+
(0, k, acc, ign, fmt)) /*<<?>>*/ ;
1816218165
}
1816318166
function make_from_fmtty$0(counter, k, acc, fmtty, fmt){
1816418167
/*<<camlinternalFormat.ml:1637:23>>*/ if(typeof fmtty !== "number")
@@ -18252,7 +18255,8 @@
1825218255
}
1825318256
function make_from_fmtty(k, acc, fmtty, fmt){
1825418257
/*<<?>>*/ return caml_trampoline
18255-
(make_from_fmtty$0(0, k, acc, fmtty, fmt));
18258+
( /*<<camlinternalFormat.ml:1637:23>>*/ make_from_fmtty$0
18259+
(0, k, acc, fmtty, fmt)) /*<<?>>*/ ;
1825618260
}
1825718261
function make_invalid_arg(counter, k, acc, fmt){
1825818262
var
@@ -18440,7 +18444,8 @@
1844018444
}
1844118445
function make_custom(k, acc, rest, arity, f){
1844218446
/*<<?>>*/ return caml_trampoline
18443-
(make_custom$0(0, k, acc, rest, arity, f));
18447+
( /*<<camlinternalFormat.ml:1778:28>>*/ make_custom$0
18448+
(0, k, acc, rest, arity, f)) /*<<?>>*/ ;
1844418449
}
1844518450
function make_iprintf$0(counter, k, o, fmt){
1844618451
var k$0 = /*<<camlinternalFormat.ml:1788:17>>*/ k, fmt$0 = fmt;
@@ -18725,7 +18730,9 @@
1872518730
}
1872618731
}
1872718732
function make_iprintf(k, o, fmt){
18728-
/*<<?>>*/ return caml_trampoline(make_iprintf$0(0, k, o, fmt));
18733+
/*<<?>>*/ return caml_trampoline
18734+
( /*<<camlinternalFormat.ml:1788:17>>*/ make_iprintf$0
18735+
(0, k, o, fmt)) /*<<?>>*/ ;
1872918736
}
1873018737
function fn_of_padding_precision(k, o, fmt, pad, prec){
1873118738
/*<<camlinternalFormat.ml:1863:26>>*/ if(typeof pad === "number"){
@@ -18816,7 +18823,8 @@
1881618823
}
1881718824
function fn_of_custom_arity(k, o, fmt, param){
1881818825
/*<<?>>*/ return caml_trampoline
18819-
(fn_of_custom_arity$0(0, k, o, fmt, param));
18826+
( /*<<camlinternalFormat.ml:1882:4>>*/ fn_of_custom_arity$0
18827+
(0, k, o, fmt, param)) /*<<?>>*/ ;
1882018828
}
1882118829
function output_acc(o, acc){
1882218830
var acc$0 = /*<<camlinternalFormat.ml:1897:27>>*/ acc;
@@ -20301,7 +20309,8 @@
2030120309
/*<<camlinternalFormat.ml:2736:4>>*/ function
2030220310
(str_ind, end_ind, c){
2030320311
/*<<?>>*/ return caml_trampoline
20304-
(parse_char_set_after_char$0(0, str_ind, end_ind, c));
20312+
( /*<<camlinternalFormat.ml:2755:6>>*/ parse_char_set_after_char$0
20313+
(0, str_ind, end_ind, c)) /*<<?>>*/ ;
2030520314
};
2030620315
/*<<camlinternalFormat.ml:2793:4>>*/ if(str_ind === end_ind)
2030720316
/*<<camlinternalFormat.ml:2092:4>>*/ invalid_format_message
@@ -31463,7 +31472,8 @@
3146331472
}
3146431473
}
3146531474
function find_stop(width){
31466-
/*<<?>>*/ return caml_trampoline(find_stop$0(0, width));
31475+
/*<<?>>*/ return caml_trampoline
31476+
( /*<<scanf.ml:1063:10>>*/ find_stop$0(0, width)) /*<<?>>*/ ;
3146731477
}
3146831478
function skip_spaces(counter, width){
3146931479
var width$0 = /*<<scanf.ml:1080:10>>*/ width;
@@ -31739,7 +31749,8 @@
3173931749
}
3174031750
/*<<scanf.ml:1198:45>>*/ }
3174131751
function take_format_readers(k, fmt){
31742-
/*<<?>>*/ return caml_trampoline(take_format_readers$0(0, k, fmt));
31752+
/*<<?>>*/ return caml_trampoline
31753+
( /*<<scanf.ml:1161:13>>*/ take_format_readers$0(0, k, fmt)) /*<<?>>*/ ;
3174331754
}
3174431755
function take_fmtty_format_readers$0(counter, k, fmtty, fmt){
3174531756
var fmtty$0 = /*<<scanf.ml:1204:19>>*/ fmtty;
@@ -31837,7 +31848,8 @@
3183731848
/*<<scanf.ml:1228:58>>*/ }
3183831849
function take_fmtty_format_readers(k, fmtty, fmt){
3183931850
/*<<?>>*/ return caml_trampoline
31840-
(take_fmtty_format_readers$0(0, k, fmtty, fmt));
31851+
( /*<<scanf.ml:1204:19>>*/ take_fmtty_format_readers$0
31852+
(0, k, fmtty, fmt)) /*<<?>>*/ ;
3184131853
}
3184231854
function make_scanf(ib, fmt, readers){
3184331855
var fmt$0 = /*<<scanf.ml:1266:22>>*/ fmt;
@@ -35732,7 +35744,10 @@
3573235744
i$0 = i$1;
3573335745
}
3573435746
/*<<filename.ml:175:48>>*/ }
35735-
function loop(i){ /*<<?>>*/ return caml_trampoline(loop$0(0, i));}
35747+
function loop(i){
35748+
/*<<?>>*/ return caml_trampoline
35749+
( /*<<filename.ml:171:6>>*/ loop$0(0, i)) /*<<?>>*/ ;
35750+
}
3573635751
function loop_bs(counter, n, i){
3573735752
var n$0 = /*<<filename.ml:177:6>>*/ n, i$0 = i;
3573835753
for(;;){

0 commit comments

Comments
 (0)