@@ -27,7 +27,11 @@ module Function_decl = Closure_conversion_aux.Function_decls.Function_decl
27
27
module Env : sig
28
28
type t
29
29
30
- type region_stack_element
30
+ type region_stack_element = private
31
+ | Regular of Ident .t
32
+ | Try_with of Ident .t
33
+
34
+ val same_region : region_stack_element -> region_stack_element -> bool
31
35
32
36
val create :
33
37
current_unit :Compilation_unit .t ->
@@ -152,7 +156,8 @@ module Env : sig
152
156
(* * Hack for staticfail (which should eventually use
153
157
[pop_regions_up_to_context]) *)
154
158
val pop_region :
155
- region_stack_element list -> (Ident .t * region_stack_element list ) option
159
+ region_stack_element list ->
160
+ (region_stack_element * region_stack_element list ) option
156
161
157
162
val pop_regions_up_to_context : t -> Continuation .t -> Ident .t option
158
163
@@ -172,6 +177,12 @@ end = struct
172
177
| Regular of Ident .t
173
178
| Try_with of Ident .t
174
179
180
+ let same_region region1 region2 =
181
+ match region1, region2 with
182
+ | Regular _ , Try_with _ | Try_with _ , Regular _ -> false
183
+ | Regular id1 , Regular id2 | Try_with id1 , Try_with id2 ->
184
+ Ident. same id1 id2
185
+
175
186
type t =
176
187
{ current_unit : Compilation_unit .t ;
177
188
current_values_of_mutables_in_scope :
@@ -407,7 +418,7 @@ end = struct
407
418
408
419
let pop_region = function
409
420
| [] -> None
410
- | (Try_with region | Regular region ) :: rest -> Some (region, rest)
421
+ | (( Try_with _ | Regular _ ) as region ) :: rest -> Some (region, rest)
411
422
412
423
let pop_regions_up_to_context t continuation =
413
424
let initial_stack_context = region_stack_in_cont_scope t continuation in
@@ -535,32 +546,36 @@ let compile_staticfail acc env ccenv ~(continuation : Continuation.t) ~args :
535
546
allocation region"
536
547
Continuation. print continuation;
537
548
let rec add_end_regions acc ~region_stack_now =
538
- (* CR pchambart: this probably can't be exercised right now, no lambda
539
- jumping through a region seems to be generated . *)
549
+ (* This can maybe only be exercised right now using "match with exception",
550
+ since that causes jumps out of try-regions (but not normal regions) . *)
540
551
(* CR pchambart: This closes all the regions between region_stack_now and
541
552
region_stack_at_handler, but closing only the last one should be
542
553
sufficient. *)
543
- let add_end_region region ~region_stack_now after_everything =
554
+ let add_end_region (region : Env.region_stack_element ) ~region_stack_now
555
+ after_everything =
544
556
let add_remaining_end_regions acc =
545
557
add_end_regions acc ~region_stack_now
546
558
in
547
559
let body = add_remaining_end_regions acc after_everything in
548
560
fun acc ccenv ->
549
- CC. close_let acc ccenv
550
- (Ident. create_local " unit" )
551
- Not_user_visible Flambda_kind.With_subkind. tagged_immediate
552
- (End_region region) ~body
561
+ match region with
562
+ | Try_with _ -> body acc ccenv
563
+ | Regular region_ident ->
564
+ CC. close_let acc ccenv
565
+ (Ident. create_local " unit" )
566
+ Not_user_visible Flambda_kind.With_subkind. tagged_immediate
567
+ (End_region region_ident) ~body
553
568
in
554
569
let no_end_region after_everything = after_everything in
555
570
match
556
571
Env. pop_region region_stack_now, Env. pop_region region_stack_at_handler
557
572
with
558
573
| None , None -> no_end_region
559
574
| Some (region1 , region_stack_now ), Some (region2 , _ ) ->
560
- if Ident. same region1 region2
575
+ if Env. same_region region1 region2
561
576
then no_end_region
562
577
else add_end_region region1 ~region_stack_now
563
- | Some (region , region_stack_now ), None ->
578
+ | Some ((( Regular _ | Try_with _ ) as region ) , region_stack_now ), None ->
564
579
add_end_region region ~region_stack_now
565
580
| None , Some _ -> assert false
566
581
(* see above *)
0 commit comments