Skip to content

librustc: Remove identifiers named box, since it's about to become a k... #10929

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
Dec 15, 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
14 changes: 9 additions & 5 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ pub fn opaque_box_body(bcx: @mut Block,
let _icx = push_ctxt("opaque_box_body");
let ccx = bcx.ccx();
let ty = type_of(ccx, body_t);
let ty = Type::box(ccx, &ty);
let ty = Type::smart_ptr(ccx, &ty);
let boxptr = PointerCast(bcx, boxptr, ty.ptr_to());
GEPi(bcx, boxptr, [0u, abi::box_field_body])
}
Expand Down Expand Up @@ -385,20 +385,24 @@ pub fn malloc_raw(bcx: @mut Block, t: ty::t, heap: heap) -> Result {

pub struct MallocResult {
bcx: @mut Block,
box: ValueRef,
smart_ptr: ValueRef,
body: ValueRef
}

// malloc_general_dyn: usefully wraps malloc_raw_dyn; allocates a box,
// and pulls out the body
// malloc_general_dyn: usefully wraps malloc_raw_dyn; allocates a smart
// pointer, and pulls out the body
pub fn malloc_general_dyn(bcx: @mut Block, t: ty::t, heap: heap, size: ValueRef)
-> MallocResult {
assert!(heap != heap_exchange);
let _icx = push_ctxt("malloc_general");
let Result {bcx: bcx, val: llbox} = malloc_raw_dyn(bcx, t, heap, size);
let body = GEPi(bcx, llbox, [0u, abi::box_field_body]);

MallocResult { bcx: bcx, box: llbox, body: body }
MallocResult {
bcx: bcx,
smart_ptr: llbox,
body: body,
}
}

pub fn malloc_general(bcx: @mut Block, t: ty::t, heap: heap) -> MallocResult {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ fn boxed_type_metadata(cx: &mut CrateContext,
None => ~"BoxedType"
};

let box_llvm_type = Type::box(cx, &content_llvm_type);
let box_llvm_type = Type::smart_ptr(cx, &content_llvm_type);
let member_llvm_types = box_llvm_type.field_types();
assert!(box_layout_is_correct(cx, member_llvm_types, content_llvm_type));

Expand Down
7 changes: 5 additions & 2 deletions src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1396,8 +1396,11 @@ fn trans_unary_datum(bcx: @mut Block,
revoke_clean(bcx, val);
return immediate_rvalue_bcx(bcx, val, box_ty);
} else {
let base::MallocResult { bcx, box: bx, body } =
base::malloc_general(bcx, contents_ty, heap);
let base::MallocResult {
bcx,
smart_ptr: bx,
body
} = base::malloc_general(bcx, contents_ty, heap);
add_clean_free(bcx, bx, heap);
let bcx = trans_into(bcx, contents, SaveIn(body));
revoke_clean(bcx, bx);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/tvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub fn alloc_raw(bcx: @mut Block, unit_ty: ty::t,
Store(bcx, alloc, GEPi(bcx, val, [0u, abi::vec_elt_alloc]));
return rslt(bcx, val);
} else {
let base::MallocResult {bcx, box: bx, body} =
let base::MallocResult {bcx, smart_ptr: 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]));
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl Type {
Type::struct_(Type::box_header_fields(ctx), false)
}

pub fn box(ctx: &CrateContext, ty: &Type) -> Type {
pub fn smart_ptr(ctx: &CrateContext, ty: &Type) -> Type {
Type::struct_(Type::box_header_fields(ctx) + &[*ty], false)
}

Expand All @@ -267,11 +267,11 @@ impl Type {
}

pub fn opaque_box(ctx: &CrateContext) -> Type {
Type::box(ctx, &Type::opaque())
Type::smart_ptr(ctx, &Type::opaque())
}

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

pub fn opaque_cbox_ptr(cx: &CrateContext) -> Type {
Expand Down
8 changes: 5 additions & 3 deletions src/librustc/middle/trans/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,18 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {
adt::incomplete_type_of(cx, repr, name)
}
ty::ty_estr(ty::vstore_box) => {
Type::box(cx, &Type::vec(cx.sess.targ_cfg.arch, &Type::i8())).ptr_to()
Type::smart_ptr(cx,
&Type::vec(cx.sess.targ_cfg.arch,
&Type::i8())).ptr_to()
}
ty::ty_evec(ref mt, ty::vstore_box) => {
let e_ty = type_of(cx, mt.ty);
let v_ty = Type::vec(cx.sess.targ_cfg.arch, &e_ty);
Type::box(cx, &v_ty).ptr_to()
Type::smart_ptr(cx, &v_ty).ptr_to()
}
ty::ty_box(ref mt) => {
let ty = type_of(cx, mt.ty);
Type::box(cx, &ty).ptr_to()
Type::smart_ptr(cx, &ty).ptr_to()
}
ty::ty_opaque_box => Type::opaque_box(cx).ptr_to(),
ty::ty_uniq(ref mt) => {
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/at_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use vec::{ImmutableVector, OwnedVector};
#[inline]
pub fn capacity<T>(v: @[T]) -> uint {
unsafe {
let box = v.repr();
(*box).data.alloc / mem::size_of::<T>()
let managed_box = v.repr();
(*managed_box).data.alloc / mem::size_of::<T>()
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/libstd/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ mod tests {
}

#[test]
fn test_bump_box_refcount() {
fn test_bump_managed_refcount() {
unsafe {
let box = @~"box box box"; // refcount 1
bump_box_refcount(box); // refcount 2
let ptr: *int = transmute(box); // refcount 2
let managed = @~"box box box"; // refcount 1
bump_box_refcount(managed); // refcount 2
let ptr: *int = transmute(managed); // refcount 2
let _box1: @~str = ::cast::transmute_copy(&ptr);
let _box2: @~str = ::cast::transmute_copy(&ptr);
assert!(*_box1 == ~"box box box");
Expand Down
16 changes: 8 additions & 8 deletions src/libstd/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,19 @@ impl<T: Eq> Eq for RefCell<T> {
}

/// Wraps a borrowed reference to a value in a `RefCell` box.
pub struct Ref<'box, T> {
priv parent: &'box RefCell<T>
pub struct Ref<'b, T> {
priv parent: &'b RefCell<T>
}

#[unsafe_destructor]
impl<'box, T> Drop for Ref<'box, T> {
impl<'b, T> Drop for Ref<'b, T> {
fn drop(&mut self) {
assert!(self.parent.borrow != WRITING && self.parent.borrow != UNUSED);
unsafe { self.parent.as_mut().borrow -= 1; }
}
}

impl<'box, T> Ref<'box, T> {
impl<'b, T> Ref<'b, T> {
/// Retrieve an immutable reference to the stored value.
#[inline]
pub fn get<'a>(&'a self) -> &'a T {
Expand All @@ -178,19 +178,19 @@ impl<'box, T> Ref<'box, T> {
}

/// Wraps a mutable borrowed reference to a value in a `RefCell` box.
pub struct RefMut<'box, T> {
priv parent: &'box mut RefCell<T>
pub struct RefMut<'b, T> {
priv parent: &'b mut RefCell<T>
}

#[unsafe_destructor]
impl<'box, T> Drop for RefMut<'box, T> {
impl<'b, T> Drop for RefMut<'b, T> {
fn drop(&mut self) {
assert!(self.parent.borrow == WRITING);
self.parent.borrow = UNUSED;
}
}

impl<'box, T> RefMut<'box, T> {
impl<'b, T> RefMut<'b, T> {
/// Retrieve a mutable reference to the stored value.
#[inline]
pub fn get<'a>(&'a mut self) -> &'a mut T {
Expand Down
32 changes: 16 additions & 16 deletions src/libstd/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@ struct AnnihilateStats {
}

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

use managed;
use rt::local_heap;

let mut box = local_heap::live_allocs();
while box != ptr::mut_null() {
let next_before = (*box).next;
let uniq = (*box).ref_count == managed::RC_MANAGED_UNIQUE;
let mut alloc = local_heap::live_allocs();
while alloc != ptr::mut_null() {
let next_before = (*alloc).next;
let uniq = (*alloc).ref_count == managed::RC_MANAGED_UNIQUE;

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

if read_next_before {
box = next_before;
alloc = next_before;
} else {
box = (*box).next;
alloc = (*alloc).next;
}
}
return true;
Expand Down Expand Up @@ -82,12 +82,12 @@ 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.
each_live_alloc(true, |box, uniq| {
each_live_alloc(true, |alloc, uniq| {
stats.n_total_boxes += 1;
if uniq {
stats.n_unique_boxes += 1;
} else {
(*box).ref_count = managed::RC_IMMORTAL;
(*alloc).ref_count = managed::RC_IMMORTAL;
}
true
});
Expand All @@ -97,10 +97,10 @@ pub unsafe fn annihilate() {
// 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.
each_live_alloc(false, |box, uniq| {
each_live_alloc(false, |alloc, uniq| {
if !uniq {
let tydesc = (*box).type_desc;
let data = &(*box).data as *();
let tydesc = (*alloc).type_desc;
let data = &(*alloc).data as *();
((*tydesc).drop_glue)(data as *i8);
}
true
Expand All @@ -112,12 +112,12 @@ 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.
each_live_alloc(true, |box, uniq| {
each_live_alloc(true, |alloc, uniq| {
if !uniq {
stats.n_bytes_freed +=
(*((*box).type_desc)).size
(*((*alloc).type_desc)).size
+ mem::size_of::<raw::Box<()>>();
local_free(box as *i8);
local_free(alloc as *i8);
}
true
});
Expand Down
12 changes: 6 additions & 6 deletions src/libstd/local_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ pub fn pop<T: 'static>(key: Key<T>) -> Option<T> {

// Move `data` into transmute to get out the memory that it
// owns, we must free it manually later.
let (_vtable, box): (uint, ~T) = unsafe {
let (_vtable, alloc): (uint, ~T) = unsafe {
cast::transmute(data)
};

// Now that we own `box`, we can just move out of it as we would
// with any other data.
return Some(*box);
// Now that we own `alloc`, we can just move out of it as we
// would with any other data.
return Some(*alloc);
}
_ => {}
}
Expand Down Expand Up @@ -254,8 +254,8 @@ fn get_with<T:'static,
// compiler coercions to achieve a '&' pointer.
unsafe {
match *cast::transmute::<&TLSValue, &(uint, ~T)>(data){
(_vtable, ref box) => {
let value: &T = *box;
(_vtable, ref alloc) => {
let value: &T = *alloc;
ret = f(Some(value));
}
}
Expand Down
17 changes: 11 additions & 6 deletions src/libstd/rt/borrowck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static ALL_BITS: uint = FROZEN_BIT | MUT_BIT;

#[deriving(Eq)]
pub struct BorrowRecord {
priv box: *mut raw::Box<()>,
priv alloc: *mut raw::Box<()>,
file: *c_char,
priv line: size_t
}
Expand All @@ -55,8 +55,9 @@ pub fn clear_task_borrow_list() {
}

#[cold]
unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) -> ! {
debug_borrow("fail_borrowed: ", box, 0, 0, file, line);
unsafe fn fail_borrowed(alloc: *mut raw::Box<()>, file: *c_char, line: size_t)
-> ! {
debug_borrow("fail_borrowed: ", alloc, 0, 0, file, line);

match try_take_task_borrow_list() {
None => { // not recording borrows
Expand All @@ -67,7 +68,7 @@ unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) ->
let mut msg = ~"borrowed";
let mut sep = " at ";
for entry in borrow_list.rev_iter() {
if entry.box == box {
if entry.alloc == alloc {
msg.push_str(sep);
let filename = str::raw::from_c_str(entry.file);
msg.push_str(filename);
Expand Down Expand Up @@ -153,7 +154,11 @@ pub unsafe fn record_borrow(a: *u8, old_ref_count: uint,
debug_borrow("record_borrow:", a, old_ref_count, 0, file, line);
swap_task_borrow_list(|borrow_list| {
let mut borrow_list = borrow_list;
borrow_list.push(BorrowRecord {box: a, file: file, line: line});
borrow_list.push(BorrowRecord {
alloc: a,
file: file,
line: line,
});
borrow_list
})
}
Expand All @@ -172,7 +177,7 @@ pub unsafe fn unrecord_borrow(a: *u8,
let mut borrow_list = borrow_list;
assert!(!borrow_list.is_empty());
let br = borrow_list.pop();
if br.box != a || br.file != file || br.line != line {
if br.alloc != a || br.file != file || br.line != line {
let err = format!("wrong borrow found, br={:?}", br);
err.with_c_str(|msg_p| {
task::begin_unwind_raw(msg_p, file, line)
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/rt/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,9 @@ mod tests {

let (threads, hits) = vec::unzip(range(0, NTHREADS).map(|_| {
let s = s.clone();
let box = ~AtomicUint::new(0);
let unique_box = ~AtomicUint::new(0);
let thread_box = unsafe {
*cast::transmute::<&~AtomicUint, **mut AtomicUint>(&box)
*cast::transmute::<&~AtomicUint,**mut AtomicUint>(&unique_box)
};
(do Thread::start {
unsafe {
Expand All @@ -617,7 +617,7 @@ mod tests {
}
}
}
}, box)
}, unique_box)
}));

let mut rng = rand::task_rng();
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/rt/global_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ pub unsafe fn closure_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
let total_size = get_box_size(size, (*td).align);
let p = malloc_raw(total_size as uint);

let box = p as *mut raw::Box<()>;
(*box).type_desc = td;
let alloc = p as *mut raw::Box<()>;
(*alloc).type_desc = td;

box as *c_char
alloc as *c_char
}

// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
Expand Down
Loading