@@ -133,6 +133,8 @@ module Env : sig
133
133
continuation_after_closing_region :Continuation .t ->
134
134
t
135
135
136
+ val leaving_region : t -> t
137
+
136
138
val entering_try_region : t -> Ident .t -> t
137
139
138
140
val leaving_try_region : t -> t
@@ -364,6 +366,14 @@ end = struct
364
366
t.region_closure_continuations
365
367
}
366
368
369
+ let leaving_region t =
370
+ match t.region_stack with
371
+ | [] -> Misc. fatal_error " Cannot pop region, region stack is empty"
372
+ | Regular _ :: region_stack -> { t with region_stack }
373
+ | Try_with region :: _ ->
374
+ Misc. fatal_errorf " Attempted to pop region but found try region %a"
375
+ Ident. print region
376
+
367
377
let entering_try_region t region =
368
378
{ t with region_stack = Try_with region :: t .region_stack }
369
379
@@ -1430,6 +1440,13 @@ let rec cps acc env ccenv (lam : L.lambda) (k : cps_continuation)
1430
1440
" [Lifused] should have been removed by [Simplif.simplify_lets]"
1431
1441
| Lregion (body , _ ) when not (Flambda_features. stack_allocation_enabled () ) ->
1432
1442
cps acc env ccenv body k k_exn
1443
+ | Ltail body ->
1444
+ let region = Env. current_region env in
1445
+ CC. close_let acc ccenv (Ident. create_local " unit" )
1446
+ Not_user_visible Flambda_kind.With_subkind. tagged_immediate
1447
+ (End_region region) ~body: (fun acc ccenv ->
1448
+ let env = Env. leaving_region env in
1449
+ cps acc env ccenv body k k_exn)
1433
1450
| Lregion (body , layout ) ->
1434
1451
(* Here we need to build the region closure continuation (see long comment
1435
1452
above). Since we're not in tail position, we also need to have a new
@@ -1720,7 +1737,8 @@ and cps_switch acc env ccenv (switch : L.lambda_switch) ~condition_dbg
1720
1737
| Lmutvar _ | Lapply _ | Lfunction _ | Llet _ | Lmutlet _ | Lletrec _
1721
1738
| Lprim _ | Lswitch _ | Lstringswitch _ | Lstaticraise _
1722
1739
| Lstaticcatch _ | Ltrywith _ | Lifthenelse _ | Lsequence _ | Lwhile _
1723
- | Lfor _ | Lassign _ | Lsend _ | Levent _ | Lifused _ | Lregion _ ->
1740
+ | Lfor _ | Lassign _ | Lsend _ | Levent _ | Lifused _ | Lregion _
1741
+ | Ltail _ ->
1724
1742
(* The continuations created here (and for failactions) are local. The
1725
1743
bodies of the let_conts will not modify mutable variables. Hence,
1726
1744
it is safe to exclude them from passing along the extra arguments
0 commit comments