Skip to content

Commit 274e7a4

Browse files
committed
auto merge of #7816 : thestinger/rust/header, r=huonw
Note that the headers are still on `~[T]` when `T` is managed. This is continued from #7605, which removed all the code relying on the headers and removed them from `~T` for non-managed `T`.
2 parents 47ba458 + e118555 commit 274e7a4

18 files changed

+234
-140
lines changed

src/librustc/middle/lang_items.rs

+36-42
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,33 @@ pub enum LangItem {
6363
FailFnLangItem, // 24
6464
FailBoundsCheckFnLangItem, // 25
6565
ExchangeMallocFnLangItem, // 26
66-
VectorExchangeMallocFnLangItem, // 27
67-
ClosureExchangeMallocFnLangItem, // 28
68-
ExchangeFreeFnLangItem, // 29
69-
MallocFnLangItem, // 30
70-
FreeFnLangItem, // 31
71-
BorrowAsImmFnLangItem, // 32
72-
BorrowAsMutFnLangItem, // 33
73-
ReturnToMutFnLangItem, // 34
74-
CheckNotBorrowedFnLangItem, // 35
75-
StrDupUniqFnLangItem, // 36
76-
RecordBorrowFnLangItem, // 37
77-
UnrecordBorrowFnLangItem, // 38
78-
79-
StartFnLangItem, // 39
80-
81-
TyDescStructLangItem, // 40
82-
TyVisitorTraitLangItem, // 41
83-
OpaqueStructLangItem, // 42
66+
ClosureExchangeMallocFnLangItem, // 27
67+
ExchangeFreeFnLangItem, // 28
68+
MallocFnLangItem, // 29
69+
FreeFnLangItem, // 30
70+
BorrowAsImmFnLangItem, // 31
71+
BorrowAsMutFnLangItem, // 32
72+
ReturnToMutFnLangItem, // 33
73+
CheckNotBorrowedFnLangItem, // 34
74+
StrDupUniqFnLangItem, // 35
75+
RecordBorrowFnLangItem, // 36
76+
UnrecordBorrowFnLangItem, // 37
77+
78+
StartFnLangItem, // 38
79+
80+
TyDescStructLangItem, // 39
81+
TyVisitorTraitLangItem, // 40
82+
OpaqueStructLangItem, // 41
8483
}
8584

8685
pub struct LanguageItems {
87-
items: [Option<def_id>, ..43]
86+
items: [Option<def_id>, ..42]
8887
}
8988

9089
impl LanguageItems {
9190
pub fn new() -> LanguageItems {
9291
LanguageItems {
93-
items: [ None, ..43 ]
92+
items: [ None, ..42 ]
9493
}
9594
}
9695

@@ -130,24 +129,23 @@ impl LanguageItems {
130129
24 => "fail_",
131130
25 => "fail_bounds_check",
132131
26 => "exchange_malloc",
133-
27 => "vector_exchange_malloc",
134-
28 => "closure_exchange_malloc",
135-
29 => "exchange_free",
136-
30 => "malloc",
137-
31 => "free",
138-
32 => "borrow_as_imm",
139-
33 => "borrow_as_mut",
140-
34 => "return_to_mut",
141-
35 => "check_not_borrowed",
142-
36 => "strdup_uniq",
143-
37 => "record_borrow",
144-
38 => "unrecord_borrow",
145-
146-
39 => "start",
147-
148-
40 => "ty_desc",
149-
41 => "ty_visitor",
150-
42 => "opaque",
132+
27 => "closure_exchange_malloc",
133+
28 => "exchange_free",
134+
29 => "malloc",
135+
30 => "free",
136+
31 => "borrow_as_imm",
137+
32 => "borrow_as_mut",
138+
33 => "return_to_mut",
139+
34 => "check_not_borrowed",
140+
35 => "strdup_uniq",
141+
36 => "record_borrow",
142+
37 => "unrecord_borrow",
143+
144+
38 => "start",
145+
146+
39 => "ty_desc",
147+
40 => "ty_visitor",
148+
41 => "opaque",
151149

152150
_ => "???"
153151
}
@@ -240,9 +238,6 @@ impl LanguageItems {
240238
pub fn exchange_malloc_fn(&self) -> def_id {
241239
self.items[ExchangeMallocFnLangItem as uint].get()
242240
}
243-
pub fn vector_exchange_malloc_fn(&self) -> def_id {
244-
self.items[VectorExchangeMallocFnLangItem as uint].get()
245-
}
246241
pub fn closure_exchange_malloc_fn(&self) -> def_id {
247242
self.items[ClosureExchangeMallocFnLangItem as uint].get()
248243
}
@@ -336,7 +331,6 @@ impl<'self> LanguageItemCollector<'self> {
336331
item_refs.insert(@"fail_bounds_check",
337332
FailBoundsCheckFnLangItem as uint);
338333
item_refs.insert(@"exchange_malloc", ExchangeMallocFnLangItem as uint);
339-
item_refs.insert(@"vector_exchange_malloc", VectorExchangeMallocFnLangItem as uint);
340334
item_refs.insert(@"closure_exchange_malloc", ClosureExchangeMallocFnLangItem as uint);
341335
item_refs.insert(@"exchange_free", ExchangeFreeFnLangItem as uint);
342336
item_refs.insert(@"malloc", MallocFnLangItem as uint);

src/librustc/middle/trans/base.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -294,25 +294,6 @@ pub fn malloc_raw_dyn(bcx: block,
294294
[size],
295295
None);
296296
rslt(r.bcx, PointerCast(r.bcx, r.val, llty_value.ptr_to()))
297-
} else if heap == heap_exchange_vector {
298-
// Grab the TypeRef type of box_ptr_ty.
299-
let element_type = match ty::get(t).sty {
300-
ty::ty_unboxed_vec(e) => e,
301-
_ => fail!("not a vector body")
302-
};
303-
let box_ptr_ty = ty::mk_evec(bcx.tcx(), element_type, ty::vstore_uniq);
304-
let llty = type_of(ccx, box_ptr_ty);
305-
306-
let llty_value = type_of::type_of(ccx, t);
307-
let llalign = llalign_of_min(ccx, llty_value);
308-
309-
// Allocate space:
310-
let r = callee::trans_lang_call(
311-
bcx,
312-
bcx.tcx().lang_items.vector_exchange_malloc_fn(),
313-
[C_i32(llalign as i32), size],
314-
None);
315-
rslt(r.bcx, PointerCast(r.bcx, r.val, llty))
316297
} else {
317298
// we treat ~fn, @fn and @[] as @ here, which isn't ideal
318299
let (mk_fn, langcall) = match heap {
@@ -322,7 +303,7 @@ pub fn malloc_raw_dyn(bcx: block,
322303
heap_exchange_closure => {
323304
(ty::mk_imm_box, bcx.tcx().lang_items.closure_exchange_malloc_fn())
324305
}
325-
_ => fail!("heap_exchange/heap_exchange_vector already handled")
306+
_ => fail!("heap_exchange already handled")
326307
};
327308

328309
// Grab the TypeRef type of box_ptr_ty.

src/librustc/middle/trans/common.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ pub enum heap {
283283
heap_managed,
284284
heap_managed_unique,
285285
heap_exchange,
286-
heap_exchange_vector,
287286
heap_exchange_closure
288287
}
289288

@@ -405,7 +404,7 @@ pub fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
405404
let f: @fn(block) -> block = |a| glue::trans_free(a, ptr);
406405
f
407406
}
408-
heap_exchange | heap_exchange_vector | heap_exchange_closure => {
407+
heap_exchange | heap_exchange_closure => {
409408
let f: @fn(block) -> block = |a| glue::trans_exchange_free(a, ptr);
410409
f
411410
}

src/librustc/middle/trans/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ fn trans_rvalue_datum_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
460460
expr, contents);
461461
}
462462
ast::expr_vstore(contents, ast::expr_vstore_uniq) => {
463-
let heap = tvec::heap_for_unique_vector(bcx, expr_ty(bcx, contents));
463+
let heap = heap_for_unique(bcx, expr_ty(bcx, contents));
464464
return tvec::trans_uniq_or_managed_vstore(bcx, heap,
465465
expr, contents);
466466
}

src/librustc/middle/trans/glue.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,7 @@ pub fn make_free_glue(bcx: block, v: ValueRef, t: ty::t) -> block {
397397
ty::ty_uniq(*) => {
398398
uniq::make_free_glue(bcx, v, t)
399399
}
400-
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) => {
401-
tvec::make_uniq_free_glue(bcx, v, t)
402-
}
400+
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) |
403401
ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_box) => {
404402
make_free_glue(bcx, v, tvec::expand_boxed_vec_ty(bcx.tcx(), t))
405403
}

src/librustc/middle/trans/reflect.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ impl Reflector {
122122
bracket_name: &str,
123123
extra: &[ValueRef],
124124
inner: &fn(&mut Reflector)) {
125-
self.visit(~"enter_" + bracket_name, extra);
125+
self.visit("enter_" + bracket_name, extra);
126126
inner(self);
127-
self.visit(~"leave_" + bracket_name, extra);
127+
self.visit("leave_" + bracket_name, extra);
128128
}
129129

130130
pub fn vstore_name_and_extra(&mut self,
@@ -183,7 +183,11 @@ impl Reflector {
183183
ty::ty_evec(ref mt, vst) => {
184184
let (name, extra) = self.vstore_name_and_extra(t, vst);
185185
let extra = extra + self.c_mt(mt);
186-
self.visit(~"evec_" + name, extra)
186+
if "uniq" == name && ty::type_contents(bcx.tcx(), t).contains_managed() {
187+
self.visit("evec_uniq_managed", extra)
188+
} else {
189+
self.visit(~"evec_" + name, extra)
190+
}
187191
}
188192
ty::ty_box(ref mt) => {
189193
let extra = self.c_mt(mt);

src/librustc/middle/trans/tvec.rs

+27-41
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,6 @@ use std::option::None;
3333
use syntax::ast;
3434
use syntax::codemap;
3535

36-
pub fn make_uniq_free_glue(bcx: block, vptrptr: ValueRef, box_ty: ty::t)
37-
-> block {
38-
let box_datum = immediate_rvalue(Load(bcx, vptrptr), box_ty);
39-
40-
let not_null = IsNotNull(bcx, box_datum.val);
41-
do with_cond(bcx, not_null) |bcx| {
42-
let body_datum = box_datum.box_body(bcx);
43-
let bcx = glue::drop_ty(bcx, body_datum.to_ref_llval(bcx),
44-
body_datum.ty);
45-
if ty::type_contents(bcx.tcx(), box_ty).contains_managed() {
46-
glue::trans_free(bcx, box_datum.val)
47-
} else {
48-
glue::trans_exchange_free(bcx, box_datum.val)
49-
}
50-
}
51-
}
52-
5336
// Boxed vector types are in some sense currently a "shorthand" for a box
5437
// containing an unboxed vector. This expands a boxed vector type into such an
5538
// expanded type. It doesn't respect mutability, but that doesn't matter at
@@ -59,7 +42,7 @@ pub fn expand_boxed_vec_ty(tcx: ty::ctxt, t: ty::t) -> ty::t {
5942
let unboxed_vec_ty = ty::mk_mut_unboxed_vec(tcx, unit_ty);
6043
match ty::get(t).sty {
6144
ty::ty_estr(ty::vstore_uniq) | ty::ty_evec(_, ty::vstore_uniq) => {
62-
fail!("cannot treat vectors/strings as exchange allocations yet");
45+
ty::mk_imm_uniq(tcx, unboxed_vec_ty)
6346
}
6447
ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) => {
6548
ty::mk_imm_box(tcx, unboxed_vec_ty)
@@ -80,8 +63,12 @@ pub fn get_alloc(bcx: block, vptr: ValueRef) -> ValueRef {
8063
Load(bcx, GEPi(bcx, vptr, [0u, abi::vec_elt_alloc]))
8164
}
8265

83-
pub fn get_bodyptr(bcx: block, vptr: ValueRef) -> ValueRef {
84-
GEPi(bcx, vptr, [0u, abi::box_field_body])
66+
pub fn get_bodyptr(bcx: block, vptr: ValueRef, t: ty::t) -> ValueRef {
67+
if ty::type_contents(bcx.tcx(), t).contains_managed() {
68+
GEPi(bcx, vptr, [0u, abi::box_field_body])
69+
} else {
70+
vptr
71+
}
8572
}
8673

8774
pub fn get_dataptr(bcx: block, vptr: ValueRef) -> ValueRef {
@@ -104,25 +91,24 @@ pub fn alloc_raw(bcx: block, unit_ty: ty::t,
10491
let vecbodyty = ty::mk_mut_unboxed_vec(bcx.tcx(), unit_ty);
10592
let vecsize = Add(bcx, alloc, llsize_of(ccx, ccx.opaque_vec_type));
10693

107-
let base::MallocResult {bcx, box: bx, body} =
108-
base::malloc_general_dyn(bcx, vecbodyty, heap, vecsize);
109-
Store(bcx, fill, GEPi(bcx, body, [0u, abi::vec_elt_fill]));
110-
Store(bcx, alloc, GEPi(bcx, body, [0u, abi::vec_elt_alloc]));
111-
base::maybe_set_managed_unique_rc(bcx, bx, heap);
112-
return rslt(bcx, bx);
113-
}
114-
115-
pub fn heap_for_unique_vector(bcx: block, t: ty::t) -> heap {
116-
if ty::type_contents(bcx.tcx(), t).contains_managed() {
117-
heap_managed_unique
94+
if heap == heap_exchange {
95+
let Result { bcx: bcx, val: val } = malloc_raw_dyn(bcx, vecbodyty, heap_exchange, vecsize);
96+
Store(bcx, fill, GEPi(bcx, val, [0u, abi::vec_elt_fill]));
97+
Store(bcx, alloc, GEPi(bcx, val, [0u, abi::vec_elt_alloc]));
98+
return rslt(bcx, val);
11899
} else {
119-
heap_exchange_vector
100+
let base::MallocResult {bcx, box: bx, body} =
101+
base::malloc_general_dyn(bcx, vecbodyty, heap, vecsize);
102+
Store(bcx, fill, GEPi(bcx, body, [0u, abi::vec_elt_fill]));
103+
Store(bcx, alloc, GEPi(bcx, body, [0u, abi::vec_elt_alloc]));
104+
base::maybe_set_managed_unique_rc(bcx, bx, heap);
105+
return rslt(bcx, bx);
120106
}
121107
}
122108

123109
pub fn alloc_uniq_raw(bcx: block, unit_ty: ty::t,
124110
fill: ValueRef, alloc: ValueRef) -> Result {
125-
alloc_raw(bcx, unit_ty, fill, alloc, heap_for_unique_vector(bcx, unit_ty))
111+
alloc_raw(bcx, unit_ty, fill, alloc, base::heap_for_unique(bcx, unit_ty))
126112
}
127113

128114
pub fn alloc_vec(bcx: block,
@@ -146,12 +132,12 @@ pub fn alloc_vec(bcx: block,
146132
pub fn duplicate_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t) -> Result {
147133
let _icx = push_ctxt("tvec::duplicate_uniq");
148134

149-
let fill = get_fill(bcx, get_bodyptr(bcx, vptr));
135+
let fill = get_fill(bcx, get_bodyptr(bcx, vptr, vec_ty));
150136
let unit_ty = ty::sequence_element_type(bcx.tcx(), vec_ty);
151137
let Result {bcx, val: newptr} = alloc_uniq_raw(bcx, unit_ty, fill, fill);
152138

153-
let data_ptr = get_dataptr(bcx, get_bodyptr(bcx, vptr));
154-
let new_data_ptr = get_dataptr(bcx, get_bodyptr(bcx, newptr));
139+
let data_ptr = get_dataptr(bcx, get_bodyptr(bcx, vptr, vec_ty));
140+
let new_data_ptr = get_dataptr(bcx, get_bodyptr(bcx, newptr, vec_ty));
155141
base::call_memcpy(bcx, new_data_ptr, data_ptr, fill, 1);
156142

157143
let bcx = if ty::type_needs_drop(bcx.tcx(), unit_ty) {
@@ -323,7 +309,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
323309

324310
// Handle ~"".
325311
match heap {
326-
heap_exchange_vector => {
312+
heap_exchange => {
327313
match content_expr.node {
328314
ast::expr_lit(@codemap::spanned {
329315
node: ast::lit_str(s), _
@@ -346,7 +332,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
346332
_ => {}
347333
}
348334
}
349-
heap_exchange | heap_exchange_closure => fail!("vectors use vector_exchange_alloc"),
335+
heap_exchange_closure => fail!("vectors use exchange_alloc"),
350336
heap_managed | heap_managed_unique => {}
351337
}
352338

@@ -356,7 +342,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
356342
let Result {bcx, val} = alloc_vec(bcx, vt.unit_ty, count, heap);
357343

358344
add_clean_free(bcx, val, heap);
359-
let dataptr = get_dataptr(bcx, get_bodyptr(bcx, val));
345+
let dataptr = get_dataptr(bcx, get_bodyptr(bcx, val, vt.vec_ty));
360346

361347
debug!("alloc_vec() returned val=%s, dataptr=%s",
362348
bcx.val_to_str(val), bcx.val_to_str(dataptr));
@@ -562,7 +548,7 @@ pub fn get_base_and_len(bcx: block,
562548
(base, len)
563549
}
564550
ty::vstore_uniq | ty::vstore_box => {
565-
let body = get_bodyptr(bcx, llval);
551+
let body = get_bodyptr(bcx, llval, vec_ty);
566552
(get_dataptr(bcx, body), get_fill(bcx, body))
567553
}
568554
}
@@ -604,7 +590,7 @@ pub fn iter_vec_raw(bcx: block, data_ptr: ValueRef, vec_ty: ty::t,
604590
pub fn iter_vec_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t,
605591
fill: ValueRef, f: iter_vec_block) -> block {
606592
let _icx = push_ctxt("tvec::iter_vec_uniq");
607-
let data_ptr = get_dataptr(bcx, get_bodyptr(bcx, vptr));
593+
let data_ptr = get_dataptr(bcx, get_bodyptr(bcx, vptr, vec_ty));
608594
iter_vec_raw(bcx, data_ptr, vec_ty, fill, f)
609595
}
610596

src/librustc/middle/trans/type_of.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {
183183
ty::ty_uint(t) => Type::uint_from_ty(cx, t),
184184
ty::ty_float(t) => Type::float_from_ty(cx, t),
185185
ty::ty_estr(ty::vstore_uniq) => {
186-
Type::unique(cx, &Type::vec(cx.sess.targ_cfg.arch, &Type::i8())).ptr_to()
186+
Type::vec(cx.sess.targ_cfg.arch, &Type::i8()).ptr_to()
187187
}
188188
ty::ty_enum(did, ref substs) => {
189189
// Only create the named struct, but don't fill it in. We
@@ -217,7 +217,11 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {
217217
ty::ty_evec(ref mt, ty::vstore_uniq) => {
218218
let ty = type_of(cx, mt.ty);
219219
let ty = Type::vec(cx.sess.targ_cfg.arch, &ty);
220-
Type::unique(cx, &ty).ptr_to()
220+
if ty::type_contents(cx.tcx, mt.ty).contains_managed() {
221+
Type::unique(cx, &ty).ptr_to()
222+
} else {
223+
ty.ptr_to()
224+
}
221225
}
222226
ty::ty_unboxed_vec(ref mt) => {
223227
let ty = type_of(cx, mt.ty);

src/libstd/reflect.rs

+8
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,14 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
297297
true
298298
}
299299

300+
#[cfg(not(stage0))]
301+
fn visit_evec_uniq_managed(&self, mtbl: uint, inner: *TyDesc) -> bool {
302+
self.align_to::<~[@u8]>();
303+
if ! self.inner.visit_evec_uniq_managed(mtbl, inner) { return false; }
304+
self.bump_past::<~[@u8]>();
305+
true
306+
}
307+
300308
fn visit_evec_slice(&self, mtbl: uint, inner: *TyDesc) -> bool {
301309
self.align_to::<&'static [u8]>();
302310
if ! self.inner.visit_evec_slice(mtbl, inner) { return false; }

0 commit comments

Comments
 (0)