Skip to content

Commit 2089ec0

Browse files
authored
flambda-backend: tmc: Remove close-on-apply flag when producing a call in non-tail position (#1827)
1 parent 9f304d8 commit 2089ec0

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lambda/tmc.ml

+8
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,14 @@ let rec choice ctx t =
749749
| other -> other
750750
in
751751
{ apply with ap_tailcall } in
752+
(* The call will not be in tail position, so the close-on-apply flag must
753+
not be set. *)
754+
let ap_region_close =
755+
match apply.ap_region_close with
756+
| Rc_close_at_apply -> Rc_normal
757+
| (Rc_normal | Rc_nontail) as reg_close -> reg_close
758+
in
759+
let apply = { apply with ap_region_close } in
752760
{ (Choice.lambda (Lapply apply)) with
753761
direct = (fun () -> Lapply apply_no_bailout);
754762
}

testsuite/tests/tmc/region_close.ml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(* TEST
2+
* bytecode
3+
* native
4+
*)
5+
6+
(* This was producing an error in ocamlopt because the call to [failwith] had
7+
the close-at-apply flag on, which wasn't cleared when tmc rewrote the call to
8+
one not in tail position. *)
9+
10+
let[@tail_mod_cons] rec map2_exn l0 l1 ~f =
11+
match l0, l1 with
12+
| [], [] -> []
13+
| h0 :: t0, h1 :: t1 -> f h0 h1 :: map2_exn t0 t1 ~f
14+
| _ -> failwith (let message () = "urk" in message ())
15+
;;

0 commit comments

Comments
 (0)