Skip to content

remove reference counting headers from ~ #11535

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

Merged
merged 3 commits into from
Jan 15, 2014
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
5 changes: 2 additions & 3 deletions src/librustc/back/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ pub static tydesc_field_align: uint = 1u;
pub static tydesc_field_take_glue: uint = 2u;
pub static tydesc_field_drop_glue: uint = 3u;
pub static tydesc_field_visit_glue: uint = 4u;
pub static tydesc_field_borrow_offset: uint = 5u;
pub static tydesc_field_name_offset: uint = 6u;
pub static n_tydesc_fields: uint = 7u;
pub static tydesc_field_name_offset: uint = 5u;
pub static n_tydesc_fields: uint = 6u;

// The two halves of a closure: code and environment.
pub static fn_field_code: uint = 0u;
Expand Down
14 changes: 2 additions & 12 deletions src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,14 +1584,9 @@ fn compile_submatch_continue<'r,
}

if any_uniq_pat(m, col) {
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).owns_managed() => llbox,
_ => GEPi(bcx, llbox, [0u, abi::box_field_body])
};
compile_submatch(bcx, enter_uniq(bcx, dm, m, col, val),
vec::append(~[unboxed], vals_left), chk);
vec::append(~[llbox], vals_left), chk);
return;
}

Expand Down Expand Up @@ -2231,13 +2226,8 @@ fn bind_irrefutable_pat<'a>(
}
}
ast::PatUniq(inner) => {
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).owns_managed() => llbox,
_ => GEPi(bcx, llbox, [0u, abi::box_field_body])
};
bcx = bind_irrefutable_pat(bcx, inner, unboxed, binding_mode);
bcx = bind_irrefutable_pat(bcx, inner, llbox, binding_mode);
}
ast::PatRegion(inner) => {
let loaded_val = Load(bcx, val);
Expand Down
27 changes: 2 additions & 25 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ pub fn malloc_raw_dyn<'a>(
} else {
// we treat ~fn, @fn and @[] as @ here, which isn't ideal
let langcall = match heap {
heap_managed | heap_managed_unique => {
heap_managed => {
require_alloc_fn(bcx, t, MallocFnLangItem)
}
heap_exchange_closure => {
Expand All @@ -382,9 +382,7 @@ pub fn malloc_raw_dyn<'a>(
langcall,
[tydesc, size],
None);
let r = rslt(r.bcx, PointerCast(r.bcx, r.val, llty));
maybe_set_managed_unique_rc(r.bcx, r.val, heap);
r
rslt(r.bcx, PointerCast(r.bcx, r.val, llty))
}
}

Expand Down Expand Up @@ -431,27 +429,6 @@ pub fn malloc_general<'a>(bcx: &'a Block, t: ty::t, heap: heap)
malloc_general_dyn(bcx, t, heap, llsize_of(bcx.ccx(), ty))
}

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

pub fn maybe_set_managed_unique_rc(bcx: &Block, bx: ValueRef, heap: heap) {
assert!(heap != heap_exchange);
if heap == heap_managed_unique {
// In cases where we are looking at a unique-typed allocation in the
// managed heap (thus have refcount 1 from the managed allocator),
// such as a ~(@foo) or such. These need to have their refcount forced
// to -2 so the annihilator ignores them.
let rc = GEPi(bcx, bx, [0u, abi::box_field_refcnt]);
let rc_val = C_int(bcx.ccx(), -2);
Store(bcx, rc_val, rc);
}
}

// Type descriptor and type glue stuff

pub fn get_tydesc_simple(ccx: &CrateContext, t: ty::t) -> ValueRef {
Expand Down
10 changes: 1 addition & 9 deletions src/librustc/middle/trans/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,6 @@ pub fn mk_closure_tys(tcx: ty::ctxt,
return cdata_ty;
}

fn heap_for_unique_closure(bcx: &Block, t: ty::t) -> heap {
if ty::type_contents(bcx.tcx(), t).owns_managed() {
heap_managed_unique
} else {
heap_exchange_closure
}
}

pub fn allocate_cbox<'a>(
bcx: &'a Block<'a>,
sigil: ast::Sigil,
Expand All @@ -173,7 +165,7 @@ pub fn allocate_cbox<'a>(
tcx.sess.bug("trying to trans allocation of @fn")
}
ast::OwnedSigil => {
malloc_raw(bcx, cdata_ty, heap_for_unique_closure(bcx, cdata_ty))
malloc_raw(bcx, cdata_ty, heap_exchange_closure)
}
ast::BorrowedSigil => {
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ pub struct tydesc_info {
tydesc: ValueRef,
size: ValueRef,
align: ValueRef,
borrow_offset: ValueRef,
name: ValueRef,
take_glue: Cell<Option<ValueRef>>,
drop_glue: Cell<Option<ValueRef>>,
Expand Down Expand Up @@ -316,7 +315,6 @@ pub fn warn_not_to_commit(ccx: &CrateContext, msg: &str) {
#[deriving(Eq)]
pub enum heap {
heap_managed,
heap_managed_unique,
heap_exchange,
heap_exchange_closure
}
Expand Down Expand Up @@ -498,7 +496,7 @@ pub fn add_clean_temp_mem_in_scope_(bcx: &Block, scope_id: Option<ast::NodeId>,

pub fn add_clean_free(cx: &Block, ptr: ValueRef, heap: heap) {
let free_fn = match heap {
heap_managed | heap_managed_unique => {
heap_managed => {
@GCHeapFreeingCleanupFunction {
ptr: ptr,
} as @CleanupFunction
Expand Down
7 changes: 1 addition & 6 deletions src/librustc/middle/trans/datum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,19 +570,14 @@ impl Datum {
let (content_ty, header) = match ty::get(self.ty).sty {
ty::ty_box(typ) => (typ, true),
ty::ty_uniq(typ) => (typ, false),
ty::ty_vec(_, ty::vstore_uniq) | ty::ty_str(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)
}
_ => {
bcx.tcx().sess.bug(format!(
"box_body() invoked on non-box type {}",
ty_to_str(bcx.tcx(), self.ty)));
}
};

if !header && !ty::type_contents(bcx.tcx(), content_ty).owns_managed() {
if !header {
let ptr = self.to_value_llval(bcx);
let ty = type_of::type_of(bcx.ccx(), content_ty);
let body = PointerCast(bcx, ptr, ty.ptr_to());
Expand Down
12 changes: 2 additions & 10 deletions src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2147,10 +2147,6 @@ fn type_metadata(cx: &CrateContext,
ty::vstore_fixed(len) => {
fixed_vec_metadata(cx, mt.ty, len, usage_site_span)
}
ty::vstore_uniq if ty::type_contents(cx.tcx, mt.ty).owns_managed() => {
let boxed_vec_metadata = boxed_vec_metadata(cx, mt.ty, usage_site_span);
pointer_type_metadata(cx, t, boxed_vec_metadata)
}
ty::vstore_uniq => {
let vec_metadata = vec_metadata(cx, mt.ty, usage_site_span);
pointer_type_metadata(cx, t, vec_metadata)
Expand All @@ -2165,12 +2161,8 @@ fn type_metadata(cx: &CrateContext,
}
},
ty::ty_uniq(typ) => {
if ty::type_contents(cx.tcx, typ).owns_managed() {
create_pointer_to_box_metadata(cx, t, typ)
} else {
let pointee = type_metadata(cx, typ, usage_site_span);
pointer_type_metadata(cx, t, pointee)
}
let pointee = type_metadata(cx, typ, usage_site_span);
pointer_type_metadata(cx, t, pointee)
}
ty::ty_ptr(ref mt) | ty::ty_rptr(_, ref mt) => {
let pointee = type_metadata(cx, mt.ty, usage_site_span);
Expand Down
32 changes: 4 additions & 28 deletions src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,29 +398,7 @@ pub fn trans_to_datum<'a>(bcx: &'a Block<'a>, expr: &ast::Expr)
autoderefs));
derefd_datum.to_rptr(bcx).to_value_llval(bcx)
}
ty::UniqTraitStore(..) => {
// For a ~T box, there may or may not be a header,
// depending on whether the type T references managed
// boxes. However, since we do not *know* the type T
// for objects, this presents a hurdle. Our solution is
// to load the "borrow offset" from the type descriptor;
// this value will either be 0 or sizeof(BoxHeader), depending
// on the type T.
let llopaque =
PointerCast(bcx, source_data, Type::opaque().ptr_to());
let lltydesc_ptr_ptr =
PointerCast(bcx, vtable,
bcx.ccx().tydesc_type.ptr_to().ptr_to());
let lltydesc_ptr =
Load(bcx, lltydesc_ptr_ptr);
let borrow_offset_ptr =
GEPi(bcx, lltydesc_ptr,
[0, abi::tydesc_field_borrow_offset]);
let borrow_offset =
Load(bcx, borrow_offset_ptr);
InBoundsGEP(bcx, llopaque, [borrow_offset])
}
ty::RegionTraitStore(..) => {
ty::UniqTraitStore(..) | ty::RegionTraitStore(..) => {
source_data
}
};
Expand Down Expand Up @@ -608,16 +586,15 @@ fn trans_rvalue_datum_unadjusted<'a>(bcx: &'a Block<'a>, expr: &ast::Expr)
expr, contents);
}
ast::ExprVstore(contents, ast::ExprVstoreUniq) => {
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::ExprBox(_, contents) => {
// Special case for `~T`. (The other case, for GC, is handled in
// `trans_rvalue_dps_unadjusted`.)
let box_ty = expr_ty(bcx, expr);
let contents_ty = expr_ty(bcx, contents);
let heap = heap_for_unique(bcx, contents_ty);
let heap = heap_exchange;
return trans_boxed_expr(bcx, box_ty, contents, contents_ty, heap)
}
ast::ExprLit(lit) => {
Expand Down Expand Up @@ -1461,8 +1438,7 @@ fn trans_unary_datum<'a>(
trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty, heap_managed)
}
ast::UnUniq => {
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::UnDeref => {
bcx.sess().bug("deref expressions should have been \
Expand Down
22 changes: 1 addition & 21 deletions src/librustc/middle/trans/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,7 @@ pub fn make_free_glue<'a>(bcx: &'a Block<'a>, v: ValueRef, t: ty::t)
with_cond(bcx, not_null, |bcx| {
let body_datum = box_datum.box_body(bcx);
let bcx = drop_ty(bcx, body_datum.to_ref_llval(bcx), body_datum.ty);
if ty::type_contents(bcx.tcx(), t).owns_managed() {
trans_free(bcx, box_datum.val)
} else {
trans_exchange_free(bcx, box_datum.val)
}
trans_exchange_free(bcx, box_datum.val)
})
}
ty::ty_vec(_, ty::vstore_uniq) | ty::ty_str(ty::vstore_uniq) |
Expand Down Expand Up @@ -550,18 +546,6 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
ppaux::ty_to_str(ccx.tcx, t));
}

let has_header = match ty::get(t).sty {
ty::ty_box(..) => true,
ty::ty_uniq(..) => ty::type_contents(ccx.tcx, t).owns_managed(),
_ => false
};

let borrow_offset = if has_header {
ccx.offsetof_gep(llty, [0u, abi::box_field_body])
} else {
C_uint(ccx, 0)
};

let llsize = llsize_of(ccx, llty);
let llalign = llalign_of(ccx, llty);
let name = mangle_internal_name_by_type_and_seq(ccx, t, "tydesc").to_managed();
Expand All @@ -580,7 +564,6 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
tydesc: gvar,
size: llsize,
align: llalign,
borrow_offset: borrow_offset,
name: ty_name,
take_glue: Cell::new(None),
drop_glue: Cell::new(None),
Expand Down Expand Up @@ -690,15 +673,12 @@ pub fn emit_tydescs(ccx: &CrateContext) {
}
};

debug!("ti.borrow_offset: {}", ccx.tn.val_to_str(ti.borrow_offset));

let tydesc = C_named_struct(ccx.tydesc_type,
[ti.size, // size
ti.align, // align
take_glue, // take_glue
drop_glue, // drop_glue
visit_glue, // visit_glue
ti.borrow_offset, // borrow_offset
ti.name]); // name

unsafe {
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 @@ -184,11 +184,7 @@ impl<'a> Reflector<'a> {
ty::ty_vec(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).owns_managed() {
self.visit("evec_uniq_managed", extra)
} else {
self.visit(~"evec_" + name, extra)
}
self.visit(~"evec_" + name, extra)
}
// Should remove mt from box and uniq.
ty::ty_box(typ) => {
Expand All @@ -203,11 +199,7 @@ impl<'a> Reflector<'a> {
ty: typ,
mutbl: ast::MutImmutable,
});
if ty::type_contents(bcx.tcx(), t).owns_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
14 changes: 10 additions & 4 deletions src/librustc/middle/trans/tvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ pub fn get_alloc(bcx: &Block, vptr: ValueRef) -> ValueRef {
}

pub fn get_bodyptr(bcx: &Block, vptr: ValueRef, t: ty::t) -> ValueRef {
if ty::type_contents(bcx.tcx(), t).owns_managed() {
let vt = vec_types(bcx, t);

let managed = match ty::get(vt.vec_ty).sty {
ty::ty_str(ty::vstore_box) | ty::ty_vec(_, ty::vstore_box) => true,
_ => false
};

if managed {
GEPi(bcx, vptr, [0u, abi::box_field_body])
} else {
vptr
Expand Down Expand Up @@ -106,7 +113,6 @@ pub fn alloc_raw<'a>(
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);
}
}
Expand All @@ -117,7 +123,7 @@ pub fn alloc_uniq_raw<'a>(
fill: ValueRef,
alloc: ValueRef)
-> Result<'a> {
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<'a>(
Expand Down Expand Up @@ -350,7 +356,7 @@ pub fn trans_uniq_or_managed_vstore<'a>(
}
}
heap_exchange_closure => fail!("vectors use exchange_alloc"),
heap_managed | heap_managed_unique => {}
heap_managed => {}
}

let vt = vec_types_from_expr(bcx, vstore_expr);
Expand Down
7 changes: 1 addition & 6 deletions src/librustc/middle/trans/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ impl Type {
glue_fn_ty, // take
glue_fn_ty, // drop
glue_fn_ty, // visit
int_ty, // borrow_offset
Type::struct_([Type::i8p(), Type::int(arch)], false)]; // name
tydesc.set_struct_body(elems, false);

Expand Down Expand Up @@ -269,10 +268,6 @@ impl Type {
Type::smart_ptr(ctx, &Type::opaque())
}

pub fn unique(ctx: &CrateContext, ty: &Type) -> Type {
Type::smart_ptr(ctx, ty)
}

pub fn opaque_cbox_ptr(cx: &CrateContext) -> Type {
Type::opaque_box(cx).ptr_to()
}
Expand All @@ -281,7 +276,7 @@ impl Type {
let tydesc_ptr = ctx.tydesc_type.ptr_to();
let box_ty = match store {
ty::BoxTraitStore => Type::opaque_box(ctx),
ty::UniqTraitStore => Type::unique(ctx, &Type::i8()),
ty::UniqTraitStore => Type::i8(),
ty::RegionTraitStore(..) => Type::i8()
};
Type::struct_([tydesc_ptr, box_ty.ptr_to()], false)
Expand Down
Loading