@@ -988,23 +988,30 @@ let lifecycle_visitor
988
988
* used later on in translation.
989
989
*)
990
990
991
- let (live_block_slots:(node_id Stack.t) Stack. t ) = Stack. create () in
991
+ let (live_block_slots:(node_id, unit) Hashtbl. t ) = Hashtbl. create 0 in
992
+ let (block_slots:(node_id Stack.t) Stack. t ) = Stack. create () in
992
993
993
994
let (implicit_init_block_slots:(node_id,node_id) Hashtbl. t ) =
994
995
Hashtbl. create 0
995
996
in
996
997
998
+ let push_slot sl =
999
+ Stack. push sl (Stack. top block_slots)
1000
+ in
1001
+
997
1002
let mark_slot_init sl =
998
- Stack. push sl (Stack. top live_block_slots )
1003
+ Hashtbl. replace live_block_slots sl ()
999
1004
in
1000
1005
1001
1006
1002
1007
let visit_block_pre b =
1003
- Stack. push (Stack. create() ) live_block_slots ;
1008
+ Stack. push (Stack. create() ) block_slots ;
1004
1009
begin
1005
1010
match htab_search implicit_init_block_slots b.id with
1006
1011
None -> ()
1007
- | Some slot -> mark_slot_init slot
1012
+ | Some slot ->
1013
+ push_slot slot;
1014
+ mark_slot_init slot
1008
1015
end ;
1009
1016
inner.Walk. visit_block_pre b
1010
1017
in
@@ -1026,7 +1033,7 @@ let lifecycle_visitor
1026
1033
1027
1034
let visit_block_post b =
1028
1035
inner.Walk. visit_block_post b;
1029
- let blk_live = Stack. pop live_block_slots in
1036
+ let blk_slots = Stack. pop block_slots in
1030
1037
let stmts = b.node in
1031
1038
let len = Array. length stmts in
1032
1039
if len > 0
@@ -1038,8 +1045,13 @@ let lifecycle_visitor
1038
1045
| Ast. STMT_be _ ->
1039
1046
() (* Taken care of in visit_stmt_post below. *)
1040
1047
| _ ->
1041
- let slots = stk_elts_from_top blk_live in
1042
- note_drops s slots
1048
+ let slots = stk_elts_from_bot blk_slots in
1049
+ let live =
1050
+ List. filter
1051
+ (fun i -> Hashtbl. mem live_block_slots i)
1052
+ slots
1053
+ in
1054
+ note_drops s live
1043
1055
end ;
1044
1056
in
1045
1057
@@ -1081,6 +1093,9 @@ let lifecycle_visitor
1081
1093
init_lval lv_dst
1082
1094
end;
1083
1095
1096
+ | Ast. STMT_decl (Ast. DECL_slot (_ , sloti )) ->
1097
+ push_slot sloti.id
1098
+
1084
1099
| Ast. STMT_init_rec (lv_dst, _, _)
1085
1100
| Ast. STMT_init_tup (lv_dst, _)
1086
1101
| Ast. STMT_init_vec (lv_dst, _)
@@ -1117,9 +1132,14 @@ let lifecycle_visitor
1117
1132
match s.node with
1118
1133
Ast. STMT_ret _
1119
1134
| Ast. STMT_be _ ->
1120
- let stks = stk_elts_from_top live_block_slots in
1121
- let slots = List. concat (List. map stk_elts_from_top stks) in
1122
- note_drops s slots
1135
+ let stks = stk_elts_from_top block_slots in
1136
+ let slots = List. concat (List. map stk_elts_from_bot stks) in
1137
+ let live =
1138
+ List. filter
1139
+ (fun i -> Hashtbl. mem live_block_slots i)
1140
+ slots
1141
+ in
1142
+ note_drops s live
1123
1143
| _ -> ()
1124
1144
in
1125
1145
0 commit comments