Skip to content

Commit ccf4e8c

Browse files
committed
Make vectors contain the right type descriptor. Closes rust-lang#2536.
1 parent 4f61dcb commit ccf4e8c

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

src/rustc/middle/trans/tvec.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,14 @@ fn alloc_uniq_raw(bcx: block, unit_ty: ty::t,
5757
fill: ValueRef, alloc: ValueRef) -> result {
5858
let _icx = bcx.insn_ctxt("tvec::alloc_uniq_raw");
5959
let ccx = bcx.ccx();
60-
let llunitty = type_of::type_of(ccx, unit_ty);
61-
let llvecty = T_vec(ccx, llunitty);
62-
let vecsize = Add(bcx, alloc, llsize_of(ccx, llvecty));
63-
let vecbodyty = unit_ty; // FIXME: This is not the correct type (#2536)
60+
61+
let vecbodyty = ty::mk_mut_unboxed_vec(bcx.tcx(), unit_ty);
62+
let vecsize = Add(bcx, alloc, llsize_of(ccx, ccx.opaque_vec_type));
63+
6464
let {box, body} = base::malloc_unique_dyn(bcx, vecbodyty, vecsize);
65-
let boxptr = PointerCast(bcx, box,
66-
T_unique_ptr(T_unique(bcx.ccx(), llvecty)));
67-
let bodyptr = PointerCast(bcx, body, T_ptr(llvecty));
68-
Store(bcx, fill, GEPi(bcx, bodyptr, [0u, abi::vec_elt_fill]));
69-
Store(bcx, alloc, GEPi(bcx, bodyptr, [0u, abi::vec_elt_alloc]));
70-
ret {bcx: bcx, val: boxptr};
65+
Store(bcx, fill, GEPi(bcx, body, [0u, abi::vec_elt_fill]));
66+
Store(bcx, alloc, GEPi(bcx, body, [0u, abi::vec_elt_alloc]));
67+
ret {bcx: bcx, val: box};
7168
}
7269

7370
fn alloc_uniq(bcx: block, unit_ty: ty::t, elts: uint) -> result {
@@ -91,14 +88,9 @@ fn duplicate_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t) -> result {
9188
let size = Add(bcx, fill, llsize_of(ccx, ccx.opaque_vec_type));
9289

9390
let unit_ty = ty::sequence_element_type(bcx.tcx(), vec_ty);
94-
let llunitty = type_of::type_of(ccx, unit_ty);
95-
let llvecty = T_vec(ccx, llunitty);
96-
let vecbodyty = unit_ty; // FIXME: This is not the correct type (#2536)
91+
let vecbodyty = ty::mk_mut_unboxed_vec(bcx.tcx(), unit_ty);
9792
let {box: newptr, body: new_body_ptr} =
9893
base::malloc_unique_dyn(bcx, vecbodyty, size);
99-
let newptr = PointerCast(bcx, newptr,
100-
T_unique_ptr(T_unique(bcx.ccx(), llvecty)));
101-
let new_body_ptr = PointerCast(bcx, new_body_ptr, T_ptr(llvecty));
10294
call_memmove(bcx, new_body_ptr, body_ptr, size);
10395

10496
Store(bcx, fill, GEPi(bcx, new_body_ptr, [0u, abi::vec_elt_alloc]));

src/rustc/middle/ty.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export ty_str, mk_str, type_is_str;
8888
export ty_vec, mk_vec, type_is_vec;
8989
export ty_estr, mk_estr;
9090
export ty_evec, mk_evec;
91-
export ty_unboxed_vec, mk_unboxed_vec;
91+
export ty_unboxed_vec, mk_unboxed_vec, mk_mut_unboxed_vec;
9292
export vstore, vstore_fixed, vstore_uniq, vstore_box, vstore_slice;
9393
export ty_nil, mk_nil, type_is_nil;
9494
export ty_iface, mk_iface;
@@ -677,6 +677,9 @@ fn mk_evec(cx: ctxt, tm: mt, t: vstore) -> t {
677677
fn mk_unboxed_vec(cx: ctxt, tm: mt) -> t {
678678
mk_t(cx, ty_unboxed_vec(tm))
679679
}
680+
fn mk_mut_unboxed_vec(cx: ctxt, ty: t) -> t {
681+
mk_t(cx, ty_unboxed_vec({ty: ty, mutbl: ast::m_imm}))
682+
}
680683

681684

682685
fn mk_rec(cx: ctxt, fs: [field]) -> t { mk_t(cx, ty_rec(fs)) }

0 commit comments

Comments
 (0)