Skip to content

tmc: Remove close-on-apply flag when producing a call in non-tail position #1827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ocaml/lambda/tmc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,14 @@ let rec choice ctx t =
| other -> other
in
{ apply with ap_tailcall } in
(* The call will not be in tail position, so the close-on-apply flag must
not be set. *)
let ap_region_close =
match apply.ap_region_close with
| Rc_close_at_apply -> Rc_normal
| (Rc_normal | Rc_nontail) as reg_close -> reg_close
in
let apply = { apply with ap_region_close } in
{ (Choice.lambda (Lapply apply)) with
direct = (fun () -> Lapply apply_no_bailout);
}
Expand Down
15 changes: 15 additions & 0 deletions ocaml/testsuite/tests/tmc/region_close.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(* TEST
* bytecode
* native
*)

(* This was producing an error in ocamlopt because the call to [failwith] had
the close-at-apply flag on, which wasn't cleared when tmc rewrote the call to
one not in tail position. *)

let[@tail_mod_cons] rec map2_exn l0 l1 ~f =
match l0, l1 with
| [], [] -> []
| h0 :: t0, h1 :: t1 -> f h0 h1 :: map2_exn t0 t1 ~f
| _ -> failwith (let message () = "urk" in message ())
;;