Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove headers from unique vectors/strings #7816

Merged
merged 1 commit into from
Jul 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 36 additions & 42 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,33 @@ pub enum LangItem {
FailFnLangItem, // 24
FailBoundsCheckFnLangItem, // 25
ExchangeMallocFnLangItem, // 26
VectorExchangeMallocFnLangItem, // 27
ClosureExchangeMallocFnLangItem, // 28
ExchangeFreeFnLangItem, // 29
MallocFnLangItem, // 30
FreeFnLangItem, // 31
BorrowAsImmFnLangItem, // 32
BorrowAsMutFnLangItem, // 33
ReturnToMutFnLangItem, // 34
CheckNotBorrowedFnLangItem, // 35
StrDupUniqFnLangItem, // 36
RecordBorrowFnLangItem, // 37
UnrecordBorrowFnLangItem, // 38

StartFnLangItem, // 39

TyDescStructLangItem, // 40
TyVisitorTraitLangItem, // 41
OpaqueStructLangItem, // 42
ClosureExchangeMallocFnLangItem, // 27
ExchangeFreeFnLangItem, // 28
MallocFnLangItem, // 29
FreeFnLangItem, // 30
BorrowAsImmFnLangItem, // 31
BorrowAsMutFnLangItem, // 32
ReturnToMutFnLangItem, // 33
CheckNotBorrowedFnLangItem, // 34
StrDupUniqFnLangItem, // 35
RecordBorrowFnLangItem, // 36
UnrecordBorrowFnLangItem, // 37

StartFnLangItem, // 38

TyDescStructLangItem, // 39
TyVisitorTraitLangItem, // 40
OpaqueStructLangItem, // 41
}

pub struct LanguageItems {
items: [Option<def_id>, ..43]
items: [Option<def_id>, ..42]
}

impl LanguageItems {
pub fn new() -> LanguageItems {
LanguageItems {
items: [ None, ..43 ]
items: [ None, ..42 ]
}
}

Expand Down Expand Up @@ -130,24 +129,23 @@ impl LanguageItems {
24 => "fail_",
25 => "fail_bounds_check",
26 => "exchange_malloc",
27 => "vector_exchange_malloc",
28 => "closure_exchange_malloc",
29 => "exchange_free",
30 => "malloc",
31 => "free",
32 => "borrow_as_imm",
33 => "borrow_as_mut",
34 => "return_to_mut",
35 => "check_not_borrowed",
36 => "strdup_uniq",
37 => "record_borrow",
38 => "unrecord_borrow",

39 => "start",

40 => "ty_desc",
41 => "ty_visitor",
42 => "opaque",
27 => "closure_exchange_malloc",
28 => "exchange_free",
29 => "malloc",
30 => "free",
31 => "borrow_as_imm",
32 => "borrow_as_mut",
33 => "return_to_mut",
34 => "check_not_borrowed",
35 => "strdup_uniq",
36 => "record_borrow",
37 => "unrecord_borrow",

38 => "start",

39 => "ty_desc",
40 => "ty_visitor",
41 => "opaque",

_ => "???"
}
Expand Down Expand Up @@ -240,9 +238,6 @@ impl LanguageItems {
pub fn exchange_malloc_fn(&self) -> def_id {
self.items[ExchangeMallocFnLangItem as uint].get()
}
pub fn vector_exchange_malloc_fn(&self) -> def_id {
self.items[VectorExchangeMallocFnLangItem as uint].get()
}
pub fn closure_exchange_malloc_fn(&self) -> def_id {
self.items[ClosureExchangeMallocFnLangItem as uint].get()
}
Expand Down Expand Up @@ -336,7 +331,6 @@ impl<'self> LanguageItemCollector<'self> {
item_refs.insert(@"fail_bounds_check",
FailBoundsCheckFnLangItem as uint);
item_refs.insert(@"exchange_malloc", ExchangeMallocFnLangItem as uint);
item_refs.insert(@"vector_exchange_malloc", VectorExchangeMallocFnLangItem as uint);
item_refs.insert(@"closure_exchange_malloc", ClosureExchangeMallocFnLangItem as uint);
item_refs.insert(@"exchange_free", ExchangeFreeFnLangItem as uint);
item_refs.insert(@"malloc", MallocFnLangItem as uint);
Expand Down
21 changes: 1 addition & 20 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,25 +294,6 @@ pub fn malloc_raw_dyn(bcx: block,
[size],
None);
rslt(r.bcx, PointerCast(r.bcx, r.val, llty_value.ptr_to()))
} else if heap == heap_exchange_vector {
// Grab the TypeRef type of box_ptr_ty.
let element_type = match ty::get(t).sty {
ty::ty_unboxed_vec(e) => e,
_ => fail!("not a vector body")
};
let box_ptr_ty = ty::mk_evec(bcx.tcx(), element_type, ty::vstore_uniq);
let llty = type_of(ccx, box_ptr_ty);

let llty_value = type_of::type_of(ccx, t);
let llalign = llalign_of_min(ccx, llty_value);

// Allocate space:
let r = callee::trans_lang_call(
bcx,
bcx.tcx().lang_items.vector_exchange_malloc_fn(),
[C_i32(llalign as i32), size],
None);
rslt(r.bcx, PointerCast(r.bcx, r.val, llty))
} else {
// we treat ~fn, @fn and @[] as @ here, which isn't ideal
let (mk_fn, langcall) = match heap {
Expand All @@ -322,7 +303,7 @@ pub fn malloc_raw_dyn(bcx: block,
heap_exchange_closure => {
(ty::mk_imm_box, bcx.tcx().lang_items.closure_exchange_malloc_fn())
}
_ => fail!("heap_exchange/heap_exchange_vector already handled")
_ => fail!("heap_exchange already handled")
};

// Grab the TypeRef type of box_ptr_ty.
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ pub enum heap {
heap_managed,
heap_managed_unique,
heap_exchange,
heap_exchange_vector,
heap_exchange_closure
}

Expand Down Expand Up @@ -405,7 +404,7 @@ pub fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
let f: @fn(block) -> block = |a| glue::trans_free(a, ptr);
f
}
heap_exchange | heap_exchange_vector | heap_exchange_closure => {
heap_exchange | heap_exchange_closure => {
let f: @fn(block) -> block = |a| glue::trans_exchange_free(a, ptr);
f
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ fn trans_rvalue_datum_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
expr, contents);
}
ast::expr_vstore(contents, ast::expr_vstore_uniq) => {
let heap = tvec::heap_for_unique_vector(bcx, expr_ty(bcx, contents));
let heap = heap_for_unique(bcx, expr_ty(bcx, contents));
return tvec::trans_uniq_or_managed_vstore(bcx, heap,
expr, contents);
}
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/middle/trans/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,7 @@ pub fn make_free_glue(bcx: block, v: ValueRef, t: ty::t) -> block {
ty::ty_uniq(*) => {
uniq::make_free_glue(bcx, v, t)
}
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) => {
tvec::make_uniq_free_glue(bcx, v, t)
}
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) |
ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_box) => {
make_free_glue(bcx, v, tvec::expand_boxed_vec_ty(bcx.tcx(), t))
}
Expand Down
10 changes: 7 additions & 3 deletions src/librustc/middle/trans/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ impl Reflector {
bracket_name: &str,
extra: &[ValueRef],
inner: &fn(&mut Reflector)) {
self.visit(~"enter_" + bracket_name, extra);
self.visit("enter_" + bracket_name, extra);
inner(self);
self.visit(~"leave_" + bracket_name, extra);
self.visit("leave_" + bracket_name, extra);
}

pub fn vstore_name_and_extra(&mut self,
Expand Down Expand Up @@ -183,7 +183,11 @@ impl Reflector {
ty::ty_evec(ref mt, vst) => {
let (name, extra) = self.vstore_name_and_extra(t, vst);
let extra = extra + self.c_mt(mt);
self.visit(~"evec_" + name, extra)
if "uniq" == name && ty::type_contents(bcx.tcx(), t).contains_managed() {
self.visit("evec_uniq_managed", extra)
} else {
self.visit(~"evec_" + name, extra)
}
}
ty::ty_box(ref mt) => {
let extra = self.c_mt(mt);
Expand Down
68 changes: 27 additions & 41 deletions src/librustc/middle/trans/tvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,6 @@ use std::option::None;
use syntax::ast;
use syntax::codemap;

pub fn make_uniq_free_glue(bcx: block, vptrptr: ValueRef, box_ty: ty::t)
-> block {
let box_datum = immediate_rvalue(Load(bcx, vptrptr), box_ty);

let not_null = IsNotNull(bcx, box_datum.val);
do with_cond(bcx, not_null) |bcx| {
let body_datum = box_datum.box_body(bcx);
let bcx = glue::drop_ty(bcx, body_datum.to_ref_llval(bcx),
body_datum.ty);
if ty::type_contents(bcx.tcx(), box_ty).contains_managed() {
glue::trans_free(bcx, box_datum.val)
} else {
glue::trans_exchange_free(bcx, box_datum.val)
}
}
}

// Boxed vector types are in some sense currently a "shorthand" for a box
// containing an unboxed vector. This expands a boxed vector type into such an
// expanded type. It doesn't respect mutability, but that doesn't matter at
Expand All @@ -59,7 +42,7 @@ pub fn expand_boxed_vec_ty(tcx: ty::ctxt, t: ty::t) -> ty::t {
let unboxed_vec_ty = ty::mk_mut_unboxed_vec(tcx, unit_ty);
match ty::get(t).sty {
ty::ty_estr(ty::vstore_uniq) | ty::ty_evec(_, ty::vstore_uniq) => {
fail!("cannot treat vectors/strings as exchange allocations yet");
ty::mk_imm_uniq(tcx, unboxed_vec_ty)
}
ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) => {
ty::mk_imm_box(tcx, unboxed_vec_ty)
Expand All @@ -80,8 +63,12 @@ pub fn get_alloc(bcx: block, vptr: ValueRef) -> ValueRef {
Load(bcx, GEPi(bcx, vptr, [0u, abi::vec_elt_alloc]))
}

pub fn get_bodyptr(bcx: block, vptr: ValueRef) -> ValueRef {
GEPi(bcx, vptr, [0u, abi::box_field_body])
pub fn get_bodyptr(bcx: block, vptr: ValueRef, t: ty::t) -> ValueRef {
if ty::type_contents(bcx.tcx(), t).contains_managed() {
GEPi(bcx, vptr, [0u, abi::box_field_body])
} else {
vptr
}
}

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

let base::MallocResult {bcx, box: bx, body} =
base::malloc_general_dyn(bcx, vecbodyty, heap, vecsize);
Store(bcx, fill, GEPi(bcx, body, [0u, abi::vec_elt_fill]));
Store(bcx, alloc, GEPi(bcx, body, [0u, abi::vec_elt_alloc]));
base::maybe_set_managed_unique_rc(bcx, bx, heap);
return rslt(bcx, bx);
}

pub fn heap_for_unique_vector(bcx: block, t: ty::t) -> heap {
if ty::type_contents(bcx.tcx(), t).contains_managed() {
heap_managed_unique
if heap == heap_exchange {
let Result { bcx: bcx, val: val } = malloc_raw_dyn(bcx, vecbodyty, heap_exchange, vecsize);
Store(bcx, fill, GEPi(bcx, val, [0u, abi::vec_elt_fill]));
Store(bcx, alloc, GEPi(bcx, val, [0u, abi::vec_elt_alloc]));
return rslt(bcx, val);
} else {
heap_exchange_vector
let base::MallocResult {bcx, box: bx, body} =
base::malloc_general_dyn(bcx, vecbodyty, heap, vecsize);
Store(bcx, fill, GEPi(bcx, body, [0u, abi::vec_elt_fill]));
Store(bcx, alloc, GEPi(bcx, body, [0u, abi::vec_elt_alloc]));
base::maybe_set_managed_unique_rc(bcx, bx, heap);
return rslt(bcx, bx);
}
}

pub fn alloc_uniq_raw(bcx: block, unit_ty: ty::t,
fill: ValueRef, alloc: ValueRef) -> Result {
alloc_raw(bcx, unit_ty, fill, alloc, heap_for_unique_vector(bcx, unit_ty))
alloc_raw(bcx, unit_ty, fill, alloc, base::heap_for_unique(bcx, unit_ty))
}

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

let fill = get_fill(bcx, get_bodyptr(bcx, vptr));
let fill = get_fill(bcx, get_bodyptr(bcx, vptr, vec_ty));
let unit_ty = ty::sequence_element_type(bcx.tcx(), vec_ty);
let Result {bcx, val: newptr} = alloc_uniq_raw(bcx, unit_ty, fill, fill);

let data_ptr = get_dataptr(bcx, get_bodyptr(bcx, vptr));
let new_data_ptr = get_dataptr(bcx, get_bodyptr(bcx, newptr));
let data_ptr = get_dataptr(bcx, get_bodyptr(bcx, vptr, vec_ty));
let new_data_ptr = get_dataptr(bcx, get_bodyptr(bcx, newptr, vec_ty));
base::call_memcpy(bcx, new_data_ptr, data_ptr, fill, 1);

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

// Handle ~"".
match heap {
heap_exchange_vector => {
heap_exchange => {
match content_expr.node {
ast::expr_lit(@codemap::spanned {
node: ast::lit_str(s), _
Expand All @@ -346,7 +332,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
_ => {}
}
}
heap_exchange | heap_exchange_closure => fail!("vectors use vector_exchange_alloc"),
heap_exchange_closure => fail!("vectors use exchange_alloc"),
heap_managed | heap_managed_unique => {}
}

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

add_clean_free(bcx, val, heap);
let dataptr = get_dataptr(bcx, get_bodyptr(bcx, val));
let dataptr = get_dataptr(bcx, get_bodyptr(bcx, val, vt.vec_ty));

debug!("alloc_vec() returned val=%s, dataptr=%s",
bcx.val_to_str(val), bcx.val_to_str(dataptr));
Expand Down Expand Up @@ -562,7 +548,7 @@ pub fn get_base_and_len(bcx: block,
(base, len)
}
ty::vstore_uniq | ty::vstore_box => {
let body = get_bodyptr(bcx, llval);
let body = get_bodyptr(bcx, llval, vec_ty);
(get_dataptr(bcx, body), get_fill(bcx, body))
}
}
Expand Down Expand Up @@ -604,7 +590,7 @@ pub fn iter_vec_raw(bcx: block, data_ptr: ValueRef, vec_ty: ty::t,
pub fn iter_vec_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t,
fill: ValueRef, f: iter_vec_block) -> block {
let _icx = push_ctxt("tvec::iter_vec_uniq");
let data_ptr = get_dataptr(bcx, get_bodyptr(bcx, vptr));
let data_ptr = get_dataptr(bcx, get_bodyptr(bcx, vptr, vec_ty));
iter_vec_raw(bcx, data_ptr, vec_ty, fill, f)
}

Expand Down
8 changes: 6 additions & 2 deletions src/librustc/middle/trans/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {
ty::ty_uint(t) => Type::uint_from_ty(cx, t),
ty::ty_float(t) => Type::float_from_ty(cx, t),
ty::ty_estr(ty::vstore_uniq) => {
Type::unique(cx, &Type::vec(cx.sess.targ_cfg.arch, &Type::i8())).ptr_to()
Type::vec(cx.sess.targ_cfg.arch, &Type::i8()).ptr_to()
}
ty::ty_enum(did, ref substs) => {
// Only create the named struct, but don't fill it in. We
Expand Down Expand Up @@ -217,7 +217,11 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {
ty::ty_evec(ref mt, ty::vstore_uniq) => {
let ty = type_of(cx, mt.ty);
let ty = Type::vec(cx.sess.targ_cfg.arch, &ty);
Type::unique(cx, &ty).ptr_to()
if ty::type_contents(cx.tcx, mt.ty).contains_managed() {
Type::unique(cx, &ty).ptr_to()
} else {
ty.ptr_to()
}
}
ty::ty_unboxed_vec(ref mt) => {
let ty = type_of(cx, mt.ty);
Expand Down
8 changes: 8 additions & 0 deletions src/libstd/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
true
}

#[cfg(not(stage0))]
fn visit_evec_uniq_managed(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<~[@u8]>();
if ! self.inner.visit_evec_uniq_managed(mtbl, inner) { return false; }
self.bump_past::<~[@u8]>();
true
}

fn visit_evec_slice(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<&'static [u8]>();
if ! self.inner.visit_evec_slice(mtbl, inner) { return false; }
Expand Down
Loading