Skip to content

Commit 6cc0a44

Browse files
vouillonhhugo
authored andcommitted
Make sure there is a location at the start of functions
If the first block of the function starts with an event, we use the event's location. This is useful in case of tail-calls, where some code is generated before this first block. If we don't have an event, we set the initial location to unkown to prevent previous locations to bleed into the function body.
1 parent 34abdfd commit 6cc0a44

File tree

5 files changed

+877
-872
lines changed

5 files changed

+877
-872
lines changed

compiler/lib/generate.ml

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,19 +1101,6 @@ let rec translate_expr ctx queue loc x e level : _ * J.statement_list =
11011101
let loc = source_location ctx After pc in
11021102
let fv = Addr.Map.find pc ctx.freevars in
11031103
let clo = compile_closure ctx cont in
1104-
let clo =
1105-
match clo with
1106-
| (st, x) :: rem ->
1107-
let loc =
1108-
match x, source_location ctx Before pc with
1109-
| (J.U | J.N), (J.U | J.N) -> J.U
1110-
| x, (J.U | J.N) -> x
1111-
| (J.U | J.N), x -> x
1112-
| _, x -> x
1113-
in
1114-
(st, loc) :: rem
1115-
| _ -> clo
1116-
in
11171104
let clo =
11181105
J.EFun
11191106
( None
@@ -1925,8 +1912,14 @@ and compile_closure ctx (pc, args) =
19251912
let current_blocks = Structure.get_nodes st.structure in
19261913
if debug () then Format.eprintf "@[<hv 2>closure {@;";
19271914
let scope_stack = [] in
1915+
let start_loc =
1916+
let block = Addr.Map.find pc ctx.Ctx.blocks in
1917+
match block.body with
1918+
| (Event loc, _) :: _ -> J.Pi loc
1919+
| _ -> J.U
1920+
in
19281921
let _never, res =
1929-
compile_branch st J.N [] (pc, args) scope_stack ~fall_through:Return
1922+
compile_branch st start_loc [] (pc, args) scope_stack ~fall_through:Return
19301923
in
19311924
if Addr.Set.cardinal !(st.visited_blocks) <> Addr.Set.cardinal current_blocks
19321925
then (

compiler/tests-compiler/gh747.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ end
265265
45: [248,
266266
46: caml_string_of_jsbytes("Test.Unhandled"),
267267
47: runtime.caml_fresh_oo_id(0)],
268-
48: cst_Raised_at = caml_string_of_jsbytes("Raised at"),
268+
48: cst_Raised_at = /*<<?>>*/ caml_string_of_jsbytes("Raised at"),
269269
49: cst_Re_raised_at = caml_string_of_jsbytes("Re-raised at"),
270270
50: cst_Raised_by_primitive_operat =
271271
51: caml_string_of_jsbytes("Raised by primitive operation at"),

compiler/tests-compiler/sourcemap.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ let%expect_test _ =
9090
/dune-root/test.ml:1:11 -> 6:18
9191
/dune-root/test.ml:1:12 -> 6:28
9292
/dune-root/test.ml:1:12 -> 7:7
93-
/dune-root/test.ml:1:12 -> 7:14
94-
null -> 10:2
93+
null -> 7:14
9594
|}]
9695

9796
let%expect_test _ =

0 commit comments

Comments
 (0)