Skip to content

Commit b3cf793

Browse files
committed
Fix post-stmt drop calculations. Closes #106.
1 parent 30c4070 commit b3cf793

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

src/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ TEST_XFAILS_LLVM := $(addprefix test/run-pass/, \
464464
vec-append.rs \
465465
vec-concat.rs \
466466
vec-drop.rs \
467+
vec-late-init.rs \
467468
vec-slice.rs \
468469
vec.rs \
469470
writealias.rs \

src/boot/me/typestate.ml

+30-10
Original file line numberDiff line numberDiff line change
@@ -988,23 +988,30 @@ let lifecycle_visitor
988988
* used later on in translation.
989989
*)
990990

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
992993

993994
let (implicit_init_block_slots:(node_id,node_id) Hashtbl.t) =
994995
Hashtbl.create 0
995996
in
996997

998+
let push_slot sl =
999+
Stack.push sl (Stack.top block_slots)
1000+
in
1001+
9971002
let mark_slot_init sl =
998-
Stack.push sl (Stack.top live_block_slots)
1003+
Hashtbl.replace live_block_slots sl ()
9991004
in
10001005

10011006

10021007
let visit_block_pre b =
1003-
Stack.push (Stack.create()) live_block_slots;
1008+
Stack.push (Stack.create()) block_slots;
10041009
begin
10051010
match htab_search implicit_init_block_slots b.id with
10061011
None -> ()
1007-
| Some slot -> mark_slot_init slot
1012+
| Some slot ->
1013+
push_slot slot;
1014+
mark_slot_init slot
10081015
end;
10091016
inner.Walk.visit_block_pre b
10101017
in
@@ -1026,7 +1033,7 @@ let lifecycle_visitor
10261033

10271034
let visit_block_post b =
10281035
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
10301037
let stmts = b.node in
10311038
let len = Array.length stmts in
10321039
if len > 0
@@ -1038,8 +1045,13 @@ let lifecycle_visitor
10381045
| Ast.STMT_be _ ->
10391046
() (* Taken care of in visit_stmt_post below. *)
10401047
| _ ->
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
10431055
end;
10441056
in
10451057

@@ -1081,6 +1093,9 @@ let lifecycle_visitor
10811093
init_lval lv_dst
10821094
end;
10831095

1096+
| Ast.STMT_decl (Ast.DECL_slot (_, sloti)) ->
1097+
push_slot sloti.id
1098+
10841099
| Ast.STMT_init_rec (lv_dst, _, _)
10851100
| Ast.STMT_init_tup (lv_dst, _)
10861101
| Ast.STMT_init_vec (lv_dst, _)
@@ -1117,9 +1132,14 @@ let lifecycle_visitor
11171132
match s.node with
11181133
Ast.STMT_ret _
11191134
| 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
11231143
| _ -> ()
11241144
in
11251145

src/test/run-pass/vec-late-init.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn main() {
2+
let vec[int] later;
3+
if (true) {
4+
later = vec(1);
5+
} else {
6+
later = vec(2);
7+
}
8+
log later.(0);
9+
}

0 commit comments

Comments
 (0)