@@ -917,8 +917,14 @@ type slot =
917
917
func : lfunction ;
918
918
function_scope : lambda ;
919
919
mutable scope : lambda option ;
920
+ mutable closed_region : lambda option ;
920
921
}
921
922
923
+ type exclave_status =
924
+ | No_exclave
925
+ | Exclave
926
+ | Within_exclave
927
+
922
928
module LamTbl = Hashtbl. Make (struct
923
929
type t = lambda
924
930
let equal = (== )
@@ -963,21 +969,27 @@ let simplify_local_functions lam =
963
969
let r =
964
970
{ func = lf;
965
971
function_scope = ! current_function_scope;
966
- scope = None }
972
+ scope = None ;
973
+ closed_region = None }
967
974
in
968
975
Hashtbl. add slots id r;
969
976
tail cont;
970
977
begin match Hashtbl. find_opt slots id with
971
- | Some {scope = Some scope ; _} ->
978
+ | Some {scope = Some scope ; closed_region; _} ->
972
979
let st = next_raise_count () in
973
- let sc, pop_region =
980
+ let sc, exclave =
974
981
(* Do not move higher than current lambda *)
975
- if scope == ! current_scope then cont, Same_region
976
- else if is_current_region_scope scope then cont, Popped_region
977
- else scope, Same_region
982
+ if scope == ! current_scope then cont, No_exclave
983
+ else if is_current_region_scope scope then begin
984
+ match closed_region with
985
+ | Some region when region == ! current_scope ->
986
+ cont, Exclave
987
+ | _ ->
988
+ cont, Within_exclave
989
+ end else scope, No_exclave
978
990
in
979
991
Hashtbl. add static_id id st;
980
- LamTbl. add static sc (st, lf, pop_region );
992
+ LamTbl. add static sc (st, lf, exclave );
981
993
(* The body of the function will become an handler
982
994
in that "scope". *)
983
995
with_scope ~scope lf.body
@@ -987,11 +999,11 @@ let simplify_local_functions lam =
987
999
function_definition lf
988
1000
end
989
1001
| Lapply {ap_func = Lvar id ; ap_args; ap_region_close; _} ->
990
- let curr_scope =
1002
+ let curr_scope, closed_region =
991
1003
match ap_region_close with
992
- | Rc_normal | Rc_nontail -> ! current_scope
1004
+ | Rc_normal | Rc_nontail -> ! current_scope, None
993
1005
| Rc_close_at_apply ->
994
- Option. get ! current_region_scope
1006
+ Option. get ! current_region_scope, Some ! current_scope
995
1007
in
996
1008
begin match Hashtbl. find_opt slots id with
997
1009
| Some {func; _}
@@ -1007,7 +1019,14 @@ let simplify_local_functions lam =
1007
1019
Hashtbl. remove slots id
1008
1020
| Some ({scope = None ; _} as slot ) ->
1009
1021
(* First use of the function: remember the current tail scope *)
1010
- slot.scope < - Some curr_scope
1022
+ slot.scope < - Some curr_scope;
1023
+ slot.closed_region < - closed_region
1024
+ | Some ({closed_region = Some old_closed_region } as slot ) -> begin
1025
+ match closed_region with
1026
+ | Some closed_region when closed_region == old_closed_region ->
1027
+ ()
1028
+ | _ -> slot.closed_region < - None
1029
+ end
1011
1030
| _ -> ()
1012
1031
end ;
1013
1032
List. iter non_tail ap_args
@@ -1074,8 +1093,14 @@ let simplify_local_functions lam =
1074
1093
(fun p -> (p.name, p.layout)) lf.params
1075
1094
in
1076
1095
List. fold_right
1077
- (fun (st , lf , r ) lam ->
1096
+ (fun (st , lf , exclave ) lam ->
1078
1097
let body = rewrite lf.body in
1098
+ let body, r =
1099
+ match exclave with
1100
+ | No_exclave -> body, Same_region
1101
+ | Exclave -> Lexclave body, Same_region
1102
+ | Within_exclave -> body, Popped_region
1103
+ in
1079
1104
Lstaticcatch (lam, (st, new_params lf), body, r, lf.return)
1080
1105
)
1081
1106
(LamTbl. find_all static lam0)
0 commit comments