Skip to content

Commit 8559a85

Browse files
committed
When copying function values, null out the destination's binding iff the source's binding is null.
1 parent ee04c02 commit 8559a85

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/boot/me/trans.ml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2933,12 +2933,18 @@ let trans_visitor
29332933
: unit =
29342934
drop_ty (get_ty_params_of_current_frame()) cell ty None
29352935

2936+
(* Returns a mark for a jmp that must be patched to the continuation of
2937+
* the null case (i.e. fall-through means not null).
2938+
*)
29362939
and null_check (cell:Il.cell) : quad_idx =
29372940
emit (Il.cmp (Il.Cell cell) zero);
29382941
let j = mark() in
29392942
emit (Il.jmp Il.JE Il.CodeNone);
29402943
j
29412944

2945+
(* Returns a mark for a jmp that must be patched to the continuation of
2946+
* the non-zero refcount case (i.e. fall-through means zero refcount).
2947+
*)
29422948
and drop_refcount_and_cmp (boxed:Il.cell) : quad_idx =
29432949
iflog (fun _ -> annotate "drop refcount and maybe free");
29442950
let rc = box_rc_cell boxed in
@@ -3268,7 +3274,14 @@ let trans_visitor
32683274
dst_binding (Ast.TY_box Ast.TY_int)
32693275
src_binding (Ast.TY_box Ast.TY_int)
32703276
curr_iso;
3271-
patch null_jmp
3277+
let end_jmp = mark() in
3278+
emit (Il.jmp Il.JMP Il.CodeNone);
3279+
patch null_jmp;
3280+
(* The src had a null binding, so make sure the dst
3281+
* does now too.
3282+
*)
3283+
mov dst_binding zero;
3284+
patch end_jmp
32723285
end
32733286

32743287
| _ ->

src/test/run-pass/lib-map.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ fn test_simple() {
1313
ret u;
1414
}
1515

16-
// FIXME we don't really want to bind here but if we don't then the
17-
// hashmap's drop glue UMRs when trying to drop these functions, which
18-
// it stores internally.
19-
let map.hashfn[uint] hasher = bind hash(_);
20-
let map.eqfn[uint] eqer = bind eq(_, _);
16+
let map.hashfn[uint] hasher = hash;
17+
let map.eqfn[uint] eqer = eq;
2118
let map.hashmap[uint, uint] hm = map.mk_hashmap[uint, uint](hasher, eqer);
2219

2320
hm.insert(10u, 12u);
@@ -43,7 +40,7 @@ fn test_simple() {
4340
fn test_growth() {
4441
log "*** starting test_growth";
4542

46-
let uint map_capacity = 64u; // Keep in sync with map.mk_hashmap
43+
let uint num_to_insert = 64u;
4744

4845
fn eq(&uint x, &uint y) -> bool { ret x == y; }
4946
fn hash(&uint u) -> uint {
@@ -52,13 +49,12 @@ fn test_growth() {
5249
ret u;
5350
}
5451

55-
// FIXME: as in test_simple(), don't really want to bind.
56-
let map.hashfn[uint] hasher = bind hash(_);
57-
let map.eqfn[uint] eqer = bind eq(_, _);
52+
let map.hashfn[uint] hasher = hash;
53+
let map.eqfn[uint] eqer = eq;
5854
let map.hashmap[uint, uint] hm = map.mk_hashmap[uint, uint](hasher, eqer);
5955

6056
let uint i = 0u;
61-
while (i < map_capacity) {
57+
while (i < num_to_insert) {
6258
hm.insert(i, i * i);
6359
log "inserting " + std._uint.to_str(i, 10u)
6460
+ " -> " + std._uint.to_str(i * i, 10u);
@@ -68,22 +64,22 @@ fn test_growth() {
6864
log "-----";
6965
7066
i = 0u;
71-
while (i < map_capacity) {
67+
while (i < num_to_insert) {
7268
log "get(" + std._uint.to_str(i, 10u) + ") = "
7369
+ std._uint.to_str(hm.get(i), 10u);
7470
check (hm.get(i) == i * i);
7571
i += 1u;
7672
}
7773
78-
hm.insert(map_capacity, 17u);
79-
check (hm.get(map_capacity) == 17u);
74+
hm.insert(num_to_insert, 17u);
75+
check (hm.get(num_to_insert) == 17u);
8076
8177
log "-----";
8278
8379
hm.rehash();
8480
8581
i = 0u;
86-
while (i < map_capacity) {
82+
while (i < num_to_insert) {
8783
log "get(" + std._uint.to_str(i, 10u) + ") = "
8884
+ std._uint.to_str(hm.get(i), 10u);
8985
check (hm.get(i) == i * i);

0 commit comments

Comments
 (0)