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 ~@T and ~[@T] allocations #8035

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ fn compile_submatch_continue(mut bcx: @mut Block,
let pat_ty = node_id_type(bcx, pat_id);
let llbox = Load(bcx, val);
let unboxed = match ty::get(pat_ty).sty {
ty::ty_uniq(*) if !ty::type_contents(bcx.tcx(), pat_ty).contains_managed() => llbox,
ty::ty_uniq(*) => llbox,
_ => GEPi(bcx, llbox, [0u, abi::box_field_body])
};
compile_submatch(bcx, enter_uniq(bcx, dm, m, col, val),
Expand Down
8 changes: 0 additions & 8 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,6 @@ pub fn malloc_boxed(bcx: @mut Block, t: ty::t)
malloc_general(bcx, t, heap_managed)
}

pub fn heap_for_unique(bcx: @mut Block, t: ty::t) -> heap {
if ty::type_contents(bcx.tcx(), t).contains_managed() {
heap_managed_unique
} else {
heap_exchange
}
}

pub fn maybe_set_managed_unique_rc(bcx: @mut Block, bx: ValueRef, heap: heap) {
assert!(heap != heap_exchange);
if heap == heap_managed_unique {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/datum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ impl Datum {
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) => {
let unit_ty = ty::sequence_element_type(bcx.tcx(), self.ty);
let unboxed_vec_ty = ty::mk_mut_unboxed_vec(bcx.tcx(), unit_ty);
(unboxed_vec_ty, true)
(unboxed_vec_ty, false)
}
_ => {
bcx.tcx().sess.bug(fmt!(
Expand All @@ -579,7 +579,7 @@ impl Datum {
}
};

if !header && !ty::type_contents(bcx.tcx(), content_ty).contains_managed() {
if !header {
let ptr = self.to_value_llval(bcx);
let ty = type_of(bcx.ccx(), content_ty);
let body = PointerCast(bcx, ptr, ty.ptr_to());
Expand Down
7 changes: 0 additions & 7 deletions src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,10 +1124,6 @@ fn type_metadata(cx: &mut CrateContext,
ty::vstore_fixed(len) => {
fixed_vec_metadata(cx, mt.ty, len, span)
}
ty::vstore_uniq if ty::type_contents(cx.tcx, mt.ty).contains_managed() => {
let boxed_vec_metadata = boxed_vec_metadata(cx, mt.ty, span);
pointer_type_metadata(cx, t, boxed_vec_metadata)
}
ty::vstore_uniq => {
let vec_metadata = vec_metadata(cx, mt.ty, span);
pointer_type_metadata(cx, t, vec_metadata)
Expand All @@ -1141,9 +1137,6 @@ fn type_metadata(cx: &mut CrateContext,
}
}
},
ty::ty_uniq(ref mt) if ty::type_contents(cx.tcx, mt.ty).contains_managed() => {
create_pointer_to_box_metadata(cx, t, mt.ty)
},
ty::ty_uniq(ref mt) |
ty::ty_ptr(ref mt) |
ty::ty_rptr(_, ref mt) => {
Expand Down
6 changes: 2 additions & 4 deletions src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,7 @@ fn trans_rvalue_datum_unadjusted(bcx: @mut Block, expr: @ast::expr) -> DatumBloc
expr, contents);
}
ast::expr_vstore(contents, ast::expr_vstore_uniq) => {
let heap = heap_for_unique(bcx, expr_ty(bcx, contents));
return tvec::trans_uniq_or_managed_vstore(bcx, heap,
return tvec::trans_uniq_or_managed_vstore(bcx, heap_exchange,
expr, contents);
}
ast::expr_lit(lit) => {
Expand Down Expand Up @@ -1306,8 +1305,7 @@ fn trans_unary_datum(bcx: @mut Block,
heap_managed)
}
ast::uniq => {
let heap = heap_for_unique(bcx, un_ty);
trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty, heap)
trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty, heap_exchange)
}
ast::deref => {
bcx.sess().bug("deref expressions should have been \
Expand Down
12 changes: 2 additions & 10 deletions src/librustc/middle/trans/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,15 @@ 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);
if "uniq" == name && ty::type_contents(bcx.tcx(), t).contains_managed() {
self.visit("evec_uniq_managed", extra)
} else {
self.visit(~"evec_" + name, extra)
}
self.visit(~"evec_" + name, extra)
}
ty::ty_box(ref mt) => {
let extra = self.c_mt(mt);
self.visit("box", extra)
}
ty::ty_uniq(ref mt) => {
let extra = self.c_mt(mt);
if ty::type_contents(bcx.tcx(), t).contains_managed() {
self.visit("uniq_managed", extra)
} else {
self.visit("uniq", extra)
}
self.visit("uniq", extra)
}
ty::ty_ptr(ref mt) => {
let extra = self.c_mt(mt);
Expand Down
12 changes: 7 additions & 5 deletions src/librustc/middle/trans/tvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ pub fn get_alloc(bcx: @mut Block, vptr: ValueRef) -> ValueRef {
}

pub fn get_bodyptr(bcx: @mut 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
info!("%?", ty::get(t).sty);
match ty::get(t).sty {
ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) => {
GEPi(bcx, vptr, [0u, abi::box_field_body])
}
_ => { vptr }
}
}

Expand Down Expand Up @@ -109,7 +111,7 @@ pub fn alloc_raw(bcx: @mut Block, unit_ty: ty::t,

pub fn alloc_uniq_raw(bcx: @mut Block, unit_ty: ty::t,
fill: ValueRef, alloc: ValueRef) -> Result {
alloc_raw(bcx, unit_ty, fill, alloc, base::heap_for_unique(bcx, unit_ty))
alloc_raw(bcx, unit_ty, fill, alloc, heap_exchange)
}

pub fn alloc_vec(bcx: @mut Block,
Expand Down
12 changes: 2 additions & 10 deletions src/librustc/middle/trans/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,12 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {
ty::ty_opaque_box => Type::opaque_box(cx).ptr_to(),
ty::ty_uniq(ref mt) => {
let ty = type_of(cx, mt.ty);
if ty::type_contents(cx.tcx, mt.ty).contains_managed() {
Type::unique(cx, &ty).ptr_to()
} else {
ty.ptr_to()
}
ty.ptr_to()
}
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);
if ty::type_contents(cx.tcx, mt.ty).contains_managed() {
Type::unique(cx, &ty).ptr_to()
} else {
ty.ptr_to()
}
ty.ptr_to()
}
ty::ty_unboxed_vec(ref mt) => {
let ty = type_of(cx, mt.ty);
Expand Down
6 changes: 1 addition & 5 deletions src/librustc/middle/trans/uniq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ pub fn make_free_glue(bcx: @mut Block, vptrptr: ValueRef, box_ty: ty::t)
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)
}
glue::trans_exchange_free(bcx, box_datum.val)
}
}
34 changes: 13 additions & 21 deletions src/libstd/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct AnnihilateStats {
}

unsafe fn each_live_alloc(read_next_before: bool,
f: &fn(box: *mut raw::Box<()>, uniq: bool) -> bool) -> bool {
f: &fn(box: *mut raw::Box<()>) -> bool) -> bool {
//! Walks the internal list of allocations

use managed;
Expand All @@ -41,7 +41,7 @@ unsafe fn each_live_alloc(read_next_before: bool,
let next_before = (*box).next;
let uniq = (*box).ref_count == managed::RC_MANAGED_UNIQUE;

if !f(box as *mut raw::Box<()>, uniq) {
if !uniq && !f(box as *mut raw::Box<()>) {
return false;
}

Expand Down Expand Up @@ -94,26 +94,20 @@ pub unsafe fn annihilate() {
//
// In this pass, nothing gets freed, so it does not matter whether
// we read the next field before or after the callback.
for each_live_alloc(true) |box, uniq| {
for each_live_alloc(true) |box| {
stats.n_total_boxes += 1;
if uniq {
stats.n_unique_boxes += 1;
} else {
(*box).ref_count = managed::RC_IMMORTAL;
}
(*box).ref_count = managed::raw::RC_IMMORTAL;
}

// Pass 2: Drop all boxes.
//
// In this pass, unique-managed boxes may get freed, but not
// managed boxes, so we must read the `next` field *after* the
// callback, as the original value may have been freed.
for each_live_alloc(false) |box, uniq| {
if !uniq {
let tydesc = (*box).type_desc;
let data = &(*box).data as *();
((*tydesc).drop_glue)(data as *i8);
}
for each_live_alloc(false) |box| {
let tydesc: *TyDesc = (*box).type_desc;
let data = &(*box).data as *();
((*tydesc).drop_glue)(data as *i8);
}

// Pass 3: Free all boxes.
Expand All @@ -122,13 +116,11 @@ pub unsafe fn annihilate() {
// unique-managed boxes, though I think that none of those are
// left), so we must read the `next` field before, since it will
// not be valid after.
for each_live_alloc(true) |box, uniq| {
if !uniq {
stats.n_bytes_freed +=
(*((*box).type_desc)).size
+ sys::size_of::<raw::Box<()>>();
local_free(box as *i8);
}
for each_live_alloc(true) |box| {
stats.n_bytes_freed +=
(*((*box).type_desc)).size
+ sys::size_of::<raw::Box<()>>();
local_free(box as *i8);
}

if debug_mem() {
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
true
}

#[cfg(stage0)]
fn visit_uniq_managed(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<~u8>();
if ! self.inner.visit_uniq_managed(mtbl, inner) { return false; }
Expand Down Expand Up @@ -286,6 +287,7 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
true
}

#[cfg(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; }
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ impl TyVisitor for ReprVisitor {
}
}

#[cfg(stage0)]
fn visit_uniq_managed(&self, _mtbl: uint, inner: *TyDesc) -> bool {
self.writer.write_char('~');
do self.get::<&raw::Box<()>> |b| {
Expand Down Expand Up @@ -346,6 +347,7 @@ impl TyVisitor for ReprVisitor {
}
}

#[cfg(stage0)]
fn visit_evec_uniq_managed(&self, mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<&raw::Box<raw::Vec<()>>> |b| {
self.writer.write_char('~');
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/unstable/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub trait TyVisitor {

fn visit_box(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool;
#[cfg(stage0)]
fn visit_uniq_managed(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_ptr(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_rptr(&self, mtbl: uint, inner: *TyDesc) -> bool;
Expand All @@ -94,6 +95,7 @@ pub trait TyVisitor {
fn visit_unboxed_vec(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_box(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool;
#[cfg(stage0)]
fn visit_evec_uniq_managed(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_slice(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_fixed(&self, n: uint, sz: uint, align: uint,
Expand Down
4 changes: 1 addition & 3 deletions src/libstd/unstable/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,4 @@ impl<'self, T> Repr<Slice<T>> for &'self [T] {}
impl<'self> Repr<Slice<u8>> for &'self str {}
impl<T> Repr<*Box<T>> for @T {}
impl<T> Repr<*Box<Vec<T>>> for @[T] {}

// sure would be nice to have this
// impl<T> Repr<*Vec<T>> for ~[T] {}
impl<T> Repr<*Vec<T>> for ~[T] {}
Loading