Skip to content

Commit 84c5215

Browse files
committed
---
yaml --- r: 13483 b: refs/heads/master c: af60716 h: refs/heads/master i: 13481: d6e26d1 13479: e07d041 v: v3
1 parent a43b709 commit 84c5215

File tree

6 files changed

+72
-41
lines changed

6 files changed

+72
-41
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 9e9e28044638f6d0446acdc8c87fffd22b861861
2+
refs/heads/master: af6071628106bd1cdbe0ac657d4b8e726cdea9c1
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustc/middle/trans/base.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -706,12 +706,6 @@ fn make_free_glue(bcx: block, v: ValueRef, t: ty::t) {
706706
let bcx = drop_ty(bcx, body, body_mt.ty);
707707
trans_free(bcx, v)
708708
}
709-
710-
ty::ty_estr(ty::vstore_box) {
711-
let v = PointerCast(bcx, v, type_of(ccx, t));
712-
trans_free(bcx, v)
713-
}
714-
715709
ty::ty_opaque_box {
716710
let v = PointerCast(bcx, v, type_of(ccx, t));
717711
let td = Load(bcx, GEPi(bcx, v, [0u, abi::box_field_tydesc]));
@@ -725,8 +719,11 @@ fn make_free_glue(bcx: block, v: ValueRef, t: ty::t) {
725719
uniq::make_free_glue(bcx, v, t)
726720
}
727721
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) |
722+
ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_box) |
728723
ty::ty_vec(_) | ty::ty_str {
729-
tvec::make_free_glue(bcx, PointerCast(bcx, v, type_of(ccx, t)), t)
724+
make_free_glue(bcx, v,
725+
tvec::expand_boxed_vec_ty(bcx.tcx(), t));
726+
ret;
730727
}
731728
ty::ty_evec(_, _) {
732729
bcx.sess().unimpl("trans::base::make_free_glue on other evec");
@@ -794,6 +791,9 @@ fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
794791
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) {
795792
free_ty(bcx, Load(bcx, v0), t)
796793
}
794+
ty::ty_unboxed_vec(_) {
795+
tvec::make_drop_glue_unboxed(bcx, v0, t)
796+
}
797797
ty::ty_res(did, inner, substs) {
798798
trans_res_drop(bcx, v0, did, inner, substs.tps)
799799
}

trunk/src/rustc/middle/trans/shape.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> [u8] {
277277
}
278278
ty::ty_evec(mt, ty::vstore_uniq) |
279279
ty::ty_vec(mt) {
280-
shape_of(ccx,
281-
ty::mk_imm_uniq(ccx.tcx, ty::mk_unboxed_vec(ccx.tcx, mt)))
280+
shape_of(ccx, tvec::expand_boxed_vec_ty(ccx.tcx, t))
282281
}
283282

284283
ty::ty_estr(ty::vstore_fixed(n)) {

trunk/src/rustc/middle/trans/tvec.rs

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,35 @@ import back::abi;
55
import base::{call_memmove,
66
INIT, copy_val, load_if_immediate, get_tydesc,
77
sub_block, do_spill_noroot,
8-
dest, bcx_icx, non_gc_box_cast};
8+
dest, bcx_icx, non_gc_box_cast,
9+
heap, heap_exchange, heap_shared};
910
import syntax::codemap::span;
1011
import shape::llsize_of;
1112
import build::*;
1213
import common::*;
1314
import util::ppaux::ty_to_str;
1415

16+
// Boxed vector types are in some sense currently a "shorthand" for a box
17+
// containing an unboxed vector. This expands a boxed vector type into such an
18+
// expanded type. It doesn't respect mutability, but that doesn't matter at
19+
// this point.
20+
fn expand_boxed_vec_ty(tcx: ty::ctxt, t: ty::t) -> ty::t {
21+
let unit_ty = ty::sequence_element_type(tcx, t);
22+
let unboxed_vec_ty = ty::mk_mut_unboxed_vec(tcx, unit_ty);
23+
alt ty::get(t).struct {
24+
ty::ty_vec(_) | ty::ty_str |
25+
ty::ty_estr(ty::vstore_uniq) | ty::ty_evec(_, ty::vstore_uniq) {
26+
ty::mk_imm_uniq(tcx, unboxed_vec_ty)
27+
}
28+
ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) {
29+
ty::mk_imm_box(tcx, unboxed_vec_ty)
30+
}
31+
_ { tcx.sess.bug("non boxed-vec type \
32+
in tvec::expand_boxed_vec_ty");
33+
}
34+
}
35+
}
36+
1537
fn get_fill(bcx: block, vptr: ValueRef) -> ValueRef {
1638
let _icx = bcx.insn_ctxt("tvec::get_fill");
1739
Load(bcx, GEPi(bcx, vptr, [0u, abi::vec_elt_fill]))
@@ -40,21 +62,25 @@ fn pointer_add(bcx: block, ptr: ValueRef, bytes: ValueRef) -> ValueRef {
4062
ret PointerCast(bcx, InBoundsGEP(bcx, bptr, [bytes]), old_ty);
4163
}
4264

43-
fn alloc_uniq_raw(bcx: block, unit_ty: ty::t,
44-
fill: ValueRef, alloc: ValueRef) -> result {
45-
let _icx = bcx.insn_ctxt("tvec::alloc_uniq_raw");
65+
fn alloc_raw(bcx: block, unit_ty: ty::t,
66+
fill: ValueRef, alloc: ValueRef, heap: heap) -> result {
67+
let _icx = bcx.insn_ctxt("tvec::alloc_uniq");
4668
let ccx = bcx.ccx();
4769

4870
let vecbodyty = ty::mk_mut_unboxed_vec(bcx.tcx(), unit_ty);
4971
let vecsize = Add(bcx, alloc, llsize_of(ccx, ccx.opaque_vec_type));
5072

51-
let {box, body} = base::malloc_unique_dyn(bcx, vecbodyty, vecsize);
73+
let {box, body} = base::malloc_general_dyn(bcx, vecbodyty, heap, vecsize);
5274
Store(bcx, fill, GEPi(bcx, body, [0u, abi::vec_elt_fill]));
5375
Store(bcx, alloc, GEPi(bcx, body, [0u, abi::vec_elt_alloc]));
5476
ret {bcx: bcx, val: box};
5577
}
78+
fn alloc_uniq_raw(bcx: block, unit_ty: ty::t,
79+
fill: ValueRef, alloc: ValueRef) -> result {
80+
alloc_raw(bcx, unit_ty, fill, alloc, heap_exchange)
81+
}
5682

57-
fn alloc_uniq(bcx: block, unit_ty: ty::t, elts: uint) -> result {
83+
fn alloc_vec(bcx: block, unit_ty: ty::t, elts: uint, heap: heap) -> result {
5884
let _icx = bcx.insn_ctxt("tvec::alloc_uniq");
5985
let ccx = bcx.ccx();
6086
let llunitty = type_of::type_of(ccx, unit_ty);
@@ -63,7 +89,7 @@ fn alloc_uniq(bcx: block, unit_ty: ty::t, elts: uint) -> result {
6389
let fill = Mul(bcx, C_uint(ccx, elts), unit_sz);
6490
let alloc = if elts < 4u { Mul(bcx, C_int(ccx, 4), unit_sz) }
6591
else { fill };
66-
let {bcx: bcx, val: vptr} = alloc_uniq_raw(bcx, unit_ty, fill, alloc);
92+
let {bcx: bcx, val: vptr} = alloc_raw(bcx, unit_ty, fill, alloc, heap);
6793
ret {bcx: bcx, val: vptr};
6894
}
6995

@@ -79,20 +105,18 @@ fn duplicate_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t) -> result {
79105
call_memmove(bcx, new_data_ptr, data_ptr, fill);
80106

81107
let bcx = if ty::type_needs_drop(bcx.tcx(), unit_ty) {
82-
iter_vec(bcx, newptr, vec_ty, base::take_ty)
108+
iter_vec_raw(bcx, new_data_ptr, vec_ty, fill, base::take_ty)
83109
} else { bcx };
84110
ret rslt(bcx, newptr);
85111
}
86-
fn make_free_glue(bcx: block, vptr: ValueRef, vec_ty: ty::t) ->
112+
113+
fn make_drop_glue_unboxed(bcx: block, vptr: ValueRef, vec_ty: ty::t) ->
87114
block {
88-
let _icx = bcx.insn_ctxt("tvec::make_free_glue");
115+
let _icx = bcx.insn_ctxt("tvec::make_drop_glue_unboxed");
89116
let tcx = bcx.tcx(), unit_ty = ty::sequence_element_type(tcx, vec_ty);
90-
base::with_cond(bcx, IsNotNull(bcx, vptr)) {|bcx|
91-
let bcx = if ty::type_needs_drop(tcx, unit_ty) {
92-
iter_vec(bcx, vptr, vec_ty, base::drop_ty)
93-
} else { bcx };
94-
base::trans_unique_free(bcx, vptr)
95-
}
117+
if ty::type_needs_drop(tcx, unit_ty) {
118+
iter_vec_unboxed(bcx, vptr, vec_ty, base::drop_ty)
119+
} else { bcx }
96120
}
97121

98122
fn trans_evec(bcx: block, args: [@ast::expr],
@@ -141,13 +165,18 @@ fn trans_evec(bcx: block, args: [@ast::expr],
141165
{bcx: bcx, val: p, dataptr: vp}
142166
}
143167
ast::vstore_uniq {
144-
let {bcx, val} = alloc_uniq(bcx, unit_ty, args.len());
168+
let {bcx, val} = alloc_vec(bcx, unit_ty, args.len(),
169+
heap_exchange);
145170
add_clean_free(bcx, val, true);
146171
let dataptr = get_dataptr(bcx, get_bodyptr(bcx, val));
147172
{bcx: bcx, val: val, dataptr: dataptr}
148173
}
149174
ast::vstore_box {
150-
bcx.ccx().sess.unimpl("unhandled tvec::trans_evec");
175+
let {bcx, val} = alloc_vec(bcx, unit_ty, args.len(),
176+
heap_shared);
177+
add_clean_free(bcx, val, true);
178+
let dataptr = get_dataptr(bcx, get_bodyptr(bcx, val));
179+
{bcx: bcx, val: val, dataptr: dataptr}
151180
}
152181
};
153182

@@ -223,13 +252,11 @@ fn get_base_and_len(cx: block, v: ValueRef, e_ty: ty::t)
223252
let len = Load(cx, GEPi(cx, v, [0u, abi::slice_elt_len]));
224253
(base, len)
225254
}
226-
ty::vstore_uniq {
255+
ty::vstore_uniq | ty::vstore_box {
256+
#debug["get_base_and_len: %s", val_str(ccx.tn, v)];
227257
let body = tvec::get_bodyptr(cx, v);
228258
(tvec::get_dataptr(cx, body), tvec::get_fill(cx, body))
229259
}
230-
ty::vstore_box {
231-
cx.ccx().sess.unimpl("unhandled tvec::get_base_and_len");
232-
}
233260
}
234261
}
235262
@@ -388,7 +415,7 @@ type iter_vec_block = fn(block, ValueRef, ty::t) -> block;
388415

389416
fn iter_vec_raw(bcx: block, data_ptr: ValueRef, vec_ty: ty::t,
390417
fill: ValueRef, f: iter_vec_block) -> block {
391-
let _icx = bcx.insn_ctxt("tvec::iter_vec_uniq");
418+
let _icx = bcx.insn_ctxt("tvec::iter_vec_raw");
392419

393420
let unit_ty = ty::sequence_element_type(bcx.tcx(), vec_ty);
394421

@@ -422,11 +449,12 @@ fn iter_vec_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t,
422449
iter_vec_raw(bcx, data_ptr, vec_ty, fill, f)
423450
}
424451

425-
fn iter_vec(bcx: block, vptr: ValueRef, vec_ty: ty::t,
426-
f: iter_vec_block) -> block {
427-
let _icx = bcx.insn_ctxt("tvec::iter_vec");
428-
let fill = get_fill(bcx, get_bodyptr(bcx, vptr));
429-
ret iter_vec_uniq(bcx, vptr, vec_ty, fill, f);
452+
fn iter_vec_unboxed(bcx: block, body_ptr: ValueRef, vec_ty: ty::t,
453+
f: iter_vec_block) -> block {
454+
let _icx = bcx.insn_ctxt("tvec::iter_vec_unboxed");
455+
let fill = get_fill(bcx, body_ptr);
456+
let dataptr = get_dataptr(bcx, body_ptr);
457+
ret iter_vec_raw(bcx, dataptr, vec_ty, fill, f);
430458
}
431459

432460
//

trunk/src/rustc/middle/trans/type_of.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
9191
}
9292
ty::ty_enum(did, _) { type_of_enum(cx, did, t) }
9393
ty::ty_estr(ty::vstore_box) { T_box_ptr(T_box(cx, T_i8())) }
94-
ty::ty_evec(mt, ty::vstore_box) |
94+
ty::ty_evec(mt, ty::vstore_box) {
95+
T_box_ptr(T_box(cx, T_vec(cx, type_of(cx, mt.ty))))
96+
}
9597
ty::ty_box(mt) { T_box_ptr(T_box(cx, type_of(cx, mt.ty))) }
9698
ty::ty_opaque_box { T_box_ptr(T_box(cx, T_i8())) }
9799
ty::ty_uniq(mt) { T_unique_ptr(T_unique(cx, type_of(cx, mt.ty))) }

trunk/src/rustc/middle/ty.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ fn type_is_str(ty: t) -> bool {
11121112
fn sequence_element_type(cx: ctxt, ty: t) -> t {
11131113
alt get(ty).struct {
11141114
ty_str | ty_estr(_) { ret mk_mach_uint(cx, ast::ty_u8); }
1115-
ty_vec(mt) | ty_evec(mt, _) { ret mt.ty; }
1115+
ty_vec(mt) | ty_evec(mt, _) | ty_unboxed_vec(mt) { ret mt.ty; }
11161116
_ { cx.sess.bug("sequence_element_type called on non-sequence value"); }
11171117
}
11181118
}
@@ -1134,7 +1134,8 @@ pure fn type_is_box(ty: t) -> bool {
11341134

11351135
pure fn type_is_boxed(ty: t) -> bool {
11361136
alt get(ty).struct {
1137-
ty_box(_) | ty_opaque_box { true }
1137+
ty_box(_) | ty_opaque_box |
1138+
ty_evec(_, vstore_box) | ty_estr(vstore_box) { true }
11381139
_ { false }
11391140
}
11401141
}
@@ -1212,6 +1213,7 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
12121213
ty_estr(vstore_fixed(_)) | ty_estr(vstore_slice(_)) |
12131214
ty_evec(_, vstore_slice(_)) { false }
12141215
ty_evec(mt, vstore_fixed(_)) { type_needs_drop(cx, mt.ty) }
1216+
ty_unboxed_vec(mt) { type_needs_drop(cx, mt.ty) }
12151217
ty_rec(flds) {
12161218
for flds.each {|f| if type_needs_drop(cx, f.mt.ty) { accum = true; } }
12171219
accum

0 commit comments

Comments
 (0)