1
Fork 0

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

This commit is contained in:
Patrick Walton 2013-12-11 17:04:50 -08:00
parent 8d52dfbace
commit a87786e3e9
26 changed files with 134 additions and 117 deletions

View file

@ -303,7 +303,7 @@ pub fn opaque_box_body(bcx: @mut Block,
let _icx = push_ctxt("opaque_box_body"); let _icx = push_ctxt("opaque_box_body");
let ccx = bcx.ccx(); let ccx = bcx.ccx();
let ty = type_of(ccx, body_t); 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()); let boxptr = PointerCast(bcx, boxptr, ty.ptr_to());
GEPi(bcx, boxptr, [0u, abi::box_field_body]) GEPi(bcx, boxptr, [0u, abi::box_field_body])
} }
@ -385,12 +385,12 @@ pub fn malloc_raw(bcx: @mut Block, t: ty::t, heap: heap) -> Result {
pub struct MallocResult { pub struct MallocResult {
bcx: @mut Block, bcx: @mut Block,
box: ValueRef, smart_ptr: ValueRef,
body: ValueRef body: ValueRef
} }
// malloc_general_dyn: usefully wraps malloc_raw_dyn; allocates a box, // malloc_general_dyn: usefully wraps malloc_raw_dyn; allocates a smart
// and pulls out the body // pointer, and pulls out the body
pub fn malloc_general_dyn(bcx: @mut Block, t: ty::t, heap: heap, size: ValueRef) pub fn malloc_general_dyn(bcx: @mut Block, t: ty::t, heap: heap, size: ValueRef)
-> MallocResult { -> MallocResult {
assert!(heap != heap_exchange); assert!(heap != heap_exchange);
@ -398,7 +398,11 @@ pub fn malloc_general_dyn(bcx: @mut Block, t: ty::t, heap: heap, size: ValueRef)
let Result {bcx: bcx, val: llbox} = malloc_raw_dyn(bcx, t, heap, size); let Result {bcx: bcx, val: llbox} = malloc_raw_dyn(bcx, t, heap, size);
let body = GEPi(bcx, llbox, [0u, abi::box_field_body]); 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 { pub fn malloc_general(bcx: @mut Block, t: ty::t, heap: heap) -> MallocResult {

View file

@ -1683,7 +1683,7 @@ fn boxed_type_metadata(cx: &mut CrateContext,
None => ~"BoxedType" 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(); let member_llvm_types = box_llvm_type.field_types();
assert!(box_layout_is_correct(cx, member_llvm_types, content_llvm_type)); assert!(box_layout_is_correct(cx, member_llvm_types, content_llvm_type));

View file

@ -1396,8 +1396,11 @@ fn trans_unary_datum(bcx: @mut Block,
revoke_clean(bcx, val); revoke_clean(bcx, val);
return immediate_rvalue_bcx(bcx, val, box_ty); return immediate_rvalue_bcx(bcx, val, box_ty);
} else { } else {
let base::MallocResult { bcx, box: bx, body } = let base::MallocResult {
base::malloc_general(bcx, contents_ty, heap); bcx,
smart_ptr: bx,
body
} = base::malloc_general(bcx, contents_ty, heap);
add_clean_free(bcx, bx, heap); add_clean_free(bcx, bx, heap);
let bcx = trans_into(bcx, contents, SaveIn(body)); let bcx = trans_into(bcx, contents, SaveIn(body));
revoke_clean(bcx, bx); revoke_clean(bcx, bx);

View file

@ -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])); Store(bcx, alloc, GEPi(bcx, val, [0u, abi::vec_elt_alloc]));
return rslt(bcx, val); return rslt(bcx, val);
} else { } else {
let base::MallocResult {bcx, box: bx, body} = let base::MallocResult {bcx, smart_ptr: bx, body} =
base::malloc_general_dyn(bcx, vecbodyty, heap, vecsize); base::malloc_general_dyn(bcx, vecbodyty, heap, vecsize);
Store(bcx, fill, GEPi(bcx, body, [0u, abi::vec_elt_fill])); Store(bcx, fill, GEPi(bcx, body, [0u, abi::vec_elt_fill]));
Store(bcx, alloc, GEPi(bcx, body, [0u, abi::vec_elt_alloc])); Store(bcx, alloc, GEPi(bcx, body, [0u, abi::vec_elt_alloc]));

View file

@ -258,7 +258,7 @@ impl Type {
Type::struct_(Type::box_header_fields(ctx), false) 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) Type::struct_(Type::box_header_fields(ctx) + &[*ty], false)
} }
@ -267,11 +267,11 @@ impl Type {
} }
pub fn opaque_box(ctx: &CrateContext) -> 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 { 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 { pub fn opaque_cbox_ptr(cx: &CrateContext) -> Type {

View file

@ -221,16 +221,18 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {
adt::incomplete_type_of(cx, repr, name) adt::incomplete_type_of(cx, repr, name)
} }
ty::ty_estr(ty::vstore_box) => { 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) => { ty::ty_evec(ref mt, ty::vstore_box) => {
let e_ty = type_of(cx, mt.ty); let e_ty = type_of(cx, mt.ty);
let v_ty = Type::vec(cx.sess.targ_cfg.arch, &e_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) => { ty::ty_box(ref mt) => {
let ty = type_of(cx, mt.ty); 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_opaque_box => Type::opaque_box(cx).ptr_to(),
ty::ty_uniq(ref mt) => { ty::ty_uniq(ref mt) => {

View file

@ -25,8 +25,8 @@ use vec::{ImmutableVector, OwnedVector};
#[inline] #[inline]
pub fn capacity<T>(v: @[T]) -> uint { pub fn capacity<T>(v: @[T]) -> uint {
unsafe { unsafe {
let box = v.repr(); let managed_box = v.repr();
(*box).data.alloc / mem::size_of::<T>() (*managed_box).data.alloc / mem::size_of::<T>()
} }
} }

View file

@ -120,11 +120,11 @@ mod tests {
} }
#[test] #[test]
fn test_bump_box_refcount() { fn test_bump_managed_refcount() {
unsafe { unsafe {
let box = @~"box box box"; // refcount 1 let managed = @~"box box box"; // refcount 1
bump_box_refcount(box); // refcount 2 bump_managed_refcount(managed); // refcount 2
let ptr: *int = transmute(box); // refcount 2 let ptr: *int = transmute(managed); // refcount 2
let _box1: @~str = ::cast::transmute_copy(&ptr); let _box1: @~str = ::cast::transmute_copy(&ptr);
let _box2: @~str = ::cast::transmute_copy(&ptr); let _box2: @~str = ::cast::transmute_copy(&ptr);
assert!(*_box1 == ~"box box box"); assert!(*_box1 == ~"box box box");

View file

@ -157,19 +157,19 @@ impl<T: Eq> Eq for RefCell<T> {
} }
/// Wraps a borrowed reference to a value in a `RefCell` box. /// Wraps a borrowed reference to a value in a `RefCell` box.
pub struct Ref<'box, T> { pub struct Ref<'b, T> {
priv parent: &'box RefCell<T> priv parent: &'b RefCell<T>
} }
#[unsafe_destructor] #[unsafe_destructor]
impl<'box, T> Drop for Ref<'box, T> { impl<'b, T> Drop for Ref<'b, T> {
fn drop(&mut self) { fn drop(&mut self) {
assert!(self.parent.borrow != WRITING && self.parent.borrow != UNUSED); assert!(self.parent.borrow != WRITING && self.parent.borrow != UNUSED);
unsafe { self.parent.as_mut().borrow -= 1; } 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. /// Retrieve an immutable reference to the stored value.
#[inline] #[inline]
pub fn get<'a>(&'a self) -> &'a T { pub fn get<'a>(&'a self) -> &'a T {
@ -178,19 +178,19 @@ impl<'box, T> Ref<'box, T> {
} }
/// Wraps a mutable borrowed reference to a value in a `RefCell` box. /// Wraps a mutable borrowed reference to a value in a `RefCell` box.
pub struct RefMut<'box, T> { pub struct RefMut<'b, T> {
priv parent: &'box mut RefCell<T> priv parent: &'b mut RefCell<T>
} }
#[unsafe_destructor] #[unsafe_destructor]
impl<'box, T> Drop for RefMut<'box, T> { impl<'b, T> Drop for RefMut<'b, T> {
fn drop(&mut self) { fn drop(&mut self) {
assert!(self.parent.borrow == WRITING); assert!(self.parent.borrow == WRITING);
self.parent.borrow = UNUSED; self.parent.borrow = UNUSED;
} }
} }
impl<'box, T> RefMut<'box, T> { impl<'b, T> RefMut<'b, T> {
/// Retrieve a mutable reference to the stored value. /// Retrieve a mutable reference to the stored value.
#[inline] #[inline]
pub fn get<'a>(&'a mut self) -> &'a mut T { pub fn get<'a>(&'a mut self) -> &'a mut T {

View file

@ -30,26 +30,26 @@ struct AnnihilateStats {
} }
unsafe fn each_live_alloc(read_next_before: bool, 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 { -> bool {
//! Walks the internal list of allocations //! Walks the internal list of allocations
use managed; use managed;
use rt::local_heap; use rt::local_heap;
let mut box = local_heap::live_allocs(); let mut alloc = local_heap::live_allocs();
while box != ptr::mut_null() { while alloc != ptr::mut_null() {
let next_before = (*box).next; let next_before = (*alloc).next;
let uniq = (*box).ref_count == managed::RC_MANAGED_UNIQUE; 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; return false;
} }
if read_next_before { if read_next_before {
box = next_before; alloc = next_before;
} else { } else {
box = (*box).next; alloc = (*alloc).next;
} }
} }
return true; return true;
@ -82,12 +82,12 @@ pub unsafe fn annihilate() {
// //
// In this pass, nothing gets freed, so it does not matter whether // In this pass, nothing gets freed, so it does not matter whether
// we read the next field before or after the callback. // 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; stats.n_total_boxes += 1;
if uniq { if uniq {
stats.n_unique_boxes += 1; stats.n_unique_boxes += 1;
} else { } else {
(*box).ref_count = managed::RC_IMMORTAL; (*alloc).ref_count = managed::RC_IMMORTAL;
} }
true true
}); });
@ -97,10 +97,10 @@ pub unsafe fn annihilate() {
// In this pass, unique-managed boxes may get freed, but not // In this pass, unique-managed boxes may get freed, but not
// managed boxes, so we must read the `next` field *after* the // managed boxes, so we must read the `next` field *after* the
// callback, as the original value may have been freed. // callback, as the original value may have been freed.
each_live_alloc(false, |box, uniq| { each_live_alloc(false, |alloc, uniq| {
if !uniq { if !uniq {
let tydesc = (*box).type_desc; let tydesc = (*alloc).type_desc;
let data = &(*box).data as *(); let data = &(*alloc).data as *();
((*tydesc).drop_glue)(data as *i8); ((*tydesc).drop_glue)(data as *i8);
} }
true true
@ -112,12 +112,12 @@ pub unsafe fn annihilate() {
// unique-managed boxes, though I think that none of those are // unique-managed boxes, though I think that none of those are
// left), so we must read the `next` field before, since it will // left), so we must read the `next` field before, since it will
// not be valid after. // not be valid after.
each_live_alloc(true, |box, uniq| { each_live_alloc(true, |alloc, uniq| {
if !uniq { if !uniq {
stats.n_bytes_freed += stats.n_bytes_freed +=
(*((*box).type_desc)).size (*((*alloc).type_desc)).size
+ mem::size_of::<raw::Box<()>>(); + mem::size_of::<raw::Box<()>>();
local_free(box as *i8); local_free(alloc as *i8);
} }
true true
}); });

View file

@ -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 // Move `data` into transmute to get out the memory that it
// owns, we must free it manually later. // owns, we must free it manually later.
let (_vtable, box): (uint, ~T) = unsafe { let (_vtable, alloc): (uint, ~T) = unsafe {
cast::transmute(data) cast::transmute(data)
}; };
// Now that we own `box`, we can just move out of it as we would // Now that we own `alloc`, we can just move out of it as we
// with any other data. // would with any other data.
return Some(*box); return Some(*alloc);
} }
_ => {} _ => {}
} }
@ -254,8 +254,8 @@ fn get_with<T:'static,
// compiler coercions to achieve a '&' pointer. // compiler coercions to achieve a '&' pointer.
unsafe { unsafe {
match *cast::transmute::<&TLSValue, &(uint, ~T)>(data){ match *cast::transmute::<&TLSValue, &(uint, ~T)>(data){
(_vtable, ref box) => { (_vtable, ref alloc) => {
let value: &T = *box; let value: &T = *alloc;
ret = f(Some(value)); ret = f(Some(value));
} }
} }

View file

@ -28,7 +28,7 @@ static ALL_BITS: uint = FROZEN_BIT | MUT_BIT;
#[deriving(Eq)] #[deriving(Eq)]
pub struct BorrowRecord { pub struct BorrowRecord {
priv box: *mut raw::Box<()>, priv alloc: *mut raw::Box<()>,
file: *c_char, file: *c_char,
priv line: size_t priv line: size_t
} }
@ -55,8 +55,9 @@ pub fn clear_task_borrow_list() {
} }
#[cold] #[cold]
unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) -> ! { unsafe fn fail_borrowed(alloc: *mut raw::Box<()>, file: *c_char, line: size_t)
debug_borrow("fail_borrowed: ", box, 0, 0, file, line); -> ! {
debug_borrow("fail_borrowed: ", alloc, 0, 0, file, line);
match try_take_task_borrow_list() { match try_take_task_borrow_list() {
None => { // not recording borrows None => { // not recording borrows
@ -67,7 +68,7 @@ unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) ->
let mut msg = ~"borrowed"; let mut msg = ~"borrowed";
let mut sep = " at "; let mut sep = " at ";
for entry in borrow_list.rev_iter() { for entry in borrow_list.rev_iter() {
if entry.box == box { if entry.alloc == alloc {
msg.push_str(sep); msg.push_str(sep);
let filename = str::raw::from_c_str(entry.file); let filename = str::raw::from_c_str(entry.file);
msg.push_str(filename); msg.push_str(filename);
@ -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); debug_borrow("record_borrow:", a, old_ref_count, 0, file, line);
swap_task_borrow_list(|borrow_list| { swap_task_borrow_list(|borrow_list| {
let mut 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 borrow_list
}) })
} }
@ -172,7 +177,7 @@ pub unsafe fn unrecord_borrow(a: *u8,
let mut borrow_list = borrow_list; let mut borrow_list = borrow_list;
assert!(!borrow_list.is_empty()); assert!(!borrow_list.is_empty());
let br = borrow_list.pop(); 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); let err = format!("wrong borrow found, br={:?}", br);
err.with_c_str(|msg_p| { err.with_c_str(|msg_p| {
task::begin_unwind_raw(msg_p, file, line) task::begin_unwind_raw(msg_p, file, line)

View file

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

View file

@ -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 total_size = get_box_size(size, (*td).align);
let p = malloc_raw(total_size as uint); let p = malloc_raw(total_size as uint);
let box = p as *mut raw::Box<()>; let alloc = p as *mut raw::Box<()>;
(*box).type_desc = td; (*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 // NB: Calls to free CANNOT be allowed to fail, as throwing an exception from

View file

@ -59,10 +59,10 @@ impl LocalHeap {
pub fn alloc(&mut self, td: *TyDesc, size: uint) -> *mut Box { pub fn alloc(&mut self, td: *TyDesc, size: uint) -> *mut Box {
let total_size = global_heap::get_box_size(size, unsafe { (*td).align }); let total_size = global_heap::get_box_size(size, unsafe { (*td).align });
let box = self.memory_region.malloc(total_size); let alloc = self.memory_region.malloc(total_size);
{ {
// Make sure that we can't use `mybox` outside of this scope // Make sure that we can't use `mybox` outside of this scope
let mybox: &mut Box = unsafe { cast::transmute(box) }; let mybox: &mut Box = unsafe { cast::transmute(alloc) };
// Clear out this box, and move it to the front of the live // Clear out this box, and move it to the front of the live
// allocations list // allocations list
mybox.type_desc = td; mybox.type_desc = td;
@ -70,11 +70,11 @@ impl LocalHeap {
mybox.prev = ptr::mut_null(); mybox.prev = ptr::mut_null();
mybox.next = self.live_allocs; mybox.next = self.live_allocs;
if !self.live_allocs.is_null() { if !self.live_allocs.is_null() {
unsafe { (*self.live_allocs).prev = box; } unsafe { (*self.live_allocs).prev = alloc; }
} }
self.live_allocs = box; self.live_allocs = alloc;
} }
return box; return alloc;
} }
pub fn realloc(&mut self, ptr: *mut Box, size: uint) -> *mut Box { pub fn realloc(&mut self, ptr: *mut Box, size: uint) -> *mut Box {
@ -97,10 +97,10 @@ impl LocalHeap {
return new_box; return new_box;
} }
pub fn free(&mut self, box: *mut Box) { pub fn free(&mut self, alloc: *mut Box) {
{ {
// Make sure that we can't use `mybox` outside of this scope // Make sure that we can't use `mybox` outside of this scope
let mybox: &mut Box = unsafe { cast::transmute(box) }; let mybox: &mut Box = unsafe { cast::transmute(alloc) };
assert!(!mybox.type_desc.is_null()); assert!(!mybox.type_desc.is_null());
// Unlink it from the linked list // Unlink it from the linked list
@ -110,7 +110,7 @@ impl LocalHeap {
if !mybox.next.is_null() { if !mybox.next.is_null() {
unsafe { (*mybox.next).prev = mybox.prev; } unsafe { (*mybox.next).prev = mybox.prev; }
} }
if self.live_allocs == box { if self.live_allocs == alloc {
self.live_allocs = mybox.next; self.live_allocs = mybox.next;
} }
@ -126,7 +126,7 @@ impl LocalHeap {
mybox.type_desc = ptr::null(); mybox.type_desc = ptr::null();
} }
self.memory_region.free(box); self.memory_region.free(alloc);
} }
} }
@ -175,7 +175,7 @@ impl AllocHeader {
#[cfg(not(rtdebug))] #[cfg(not(rtdebug))]
fn update_size(&mut self, _size: u32) {} fn update_size(&mut self, _size: u32) {}
fn box(&mut self) -> *mut Box { fn as_box(&mut self) -> *mut Box {
let myaddr: uint = unsafe { cast::transmute(self) }; let myaddr: uint = unsafe { cast::transmute(self) };
(myaddr + AllocHeader::size()) as *mut Box (myaddr + AllocHeader::size()) as *mut Box
} }
@ -187,8 +187,8 @@ impl AllocHeader {
return (header_size + ptr_size - 1) / ptr_size * ptr_size; return (header_size + ptr_size - 1) / ptr_size * ptr_size;
} }
fn from(box: *mut Box) -> *mut AllocHeader { fn from(a_box: *mut Box) -> *mut AllocHeader {
(box as uint - AllocHeader::size()) as *mut AllocHeader (a_box as uint - AllocHeader::size()) as *mut AllocHeader
} }
} }
@ -204,12 +204,12 @@ impl MemoryRegion {
self.claim(alloc); self.claim(alloc);
self.live_allocations += 1; self.live_allocations += 1;
return alloc.box(); return alloc.as_box();
} }
fn realloc(&mut self, box: *mut Box, size: uint) -> *mut Box { fn realloc(&mut self, alloc: *mut Box, size: uint) -> *mut Box {
rtassert!(!box.is_null()); rtassert!(!alloc.is_null());
let orig_alloc = AllocHeader::from(box); let orig_alloc = AllocHeader::from(alloc);
unsafe { (*orig_alloc).assert_sane(); } unsafe { (*orig_alloc).assert_sane(); }
let total_size = size + AllocHeader::size(); let total_size = size + AllocHeader::size();
@ -222,12 +222,12 @@ impl MemoryRegion {
alloc.assert_sane(); alloc.assert_sane();
alloc.update_size(size as u32); alloc.update_size(size as u32);
self.update(alloc, orig_alloc as *AllocHeader); self.update(alloc, orig_alloc as *AllocHeader);
return alloc.box(); return alloc.as_box();
} }
fn free(&mut self, box: *mut Box) { fn free(&mut self, alloc: *mut Box) {
rtassert!(!box.is_null()); rtassert!(!alloc.is_null());
let alloc = AllocHeader::from(box); let alloc = AllocHeader::from(alloc);
unsafe { unsafe {
(*alloc).assert_sane(); (*alloc).assert_sane();
self.release(cast::transmute(alloc)); self.release(cast::transmute(alloc));

View file

@ -2280,10 +2280,10 @@ pub mod raw {
*/ */
#[inline] #[inline]
pub unsafe fn init_elem<T>(v: &mut [T], i: uint, val: T) { pub unsafe fn init_elem<T>(v: &mut [T], i: uint, val: T) {
let mut box = Some(val); let mut alloc = Some(val);
v.as_mut_buf(|p, _len| { v.as_mut_buf(|p, _len| {
intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i as int)), intrinsics::move_val_init(&mut(*ptr::mut_offset(p, i as int)),
box.take_unwrap()); alloc.take_unwrap());
}) })
} }

View file

@ -555,16 +555,18 @@ impl Printer {
} }
// Convenience functions to talk to the printer. // Convenience functions to talk to the printer.
pub fn box(p: @mut Printer, indent: uint, b: breaks) { //
// "raw box"
pub fn rbox(p: @mut Printer, indent: uint, b: breaks) {
p.pretty_print(BEGIN(begin_t { p.pretty_print(BEGIN(begin_t {
offset: indent as int, offset: indent as int,
breaks: b breaks: b
})); }));
} }
pub fn ibox(p: @mut Printer, indent: uint) { box(p, indent, inconsistent); } pub fn ibox(p: @mut Printer, indent: uint) { rbox(p, indent, inconsistent); }
pub fn cbox(p: @mut Printer, indent: uint) { box(p, indent, consistent); } pub fn cbox(p: @mut Printer, indent: uint) { rbox(p, indent, consistent); }
pub fn break_offset(p: @mut Printer, n: uint, off: int) { pub fn break_offset(p: @mut Printer, n: uint, off: int) {
p.pretty_print(BREAK(break_t { p.pretty_print(BREAK(break_t {

View file

@ -242,9 +242,10 @@ pub fn cbox(s: @ps, u: uint) {
pp::cbox(s.s, u); pp::cbox(s.s, u);
} }
pub fn box(s: @ps, u: uint, b: pp::breaks) { // "raw box"
pub fn rbox(s: @ps, u: uint, b: pp::breaks) {
s.boxes.push(b); s.boxes.push(b);
pp::box(s.s, u, b); pp::rbox(s.s, u, b);
} }
pub fn nbsp(s: @ps) { word(s.s, " "); } pub fn nbsp(s: @ps) { word(s.s, " "); }
@ -332,7 +333,7 @@ pub fn synth_comment(s: @ps, text: ~str) {
} }
pub fn commasep<T>(s: @ps, b: breaks, elts: &[T], op: |@ps, &T|) { pub fn commasep<T>(s: @ps, b: breaks, elts: &[T], op: |@ps, &T|) {
box(s, 0u, b); rbox(s, 0u, b);
let mut first = true; let mut first = true;
for elt in elts.iter() { for elt in elts.iter() {
if first { first = false; } else { word_space(s, ","); } if first { first = false; } else { word_space(s, ","); }
@ -348,7 +349,7 @@ pub fn commasep_cmnt<T>(
elts: &[T], elts: &[T],
op: |@ps, &T|, op: |@ps, &T|,
get_span: |&T| -> codemap::Span) { get_span: |&T| -> codemap::Span) {
box(s, 0u, b); rbox(s, 0u, b);
let len = elts.len(); let len = elts.len();
let mut i = 0u; let mut i = 0u;
for elt in elts.iter() { for elt in elts.iter() {
@ -1771,7 +1772,7 @@ pub fn print_fn_args(s: @ps, decl: &ast::fn_decl,
opt_explicit_self: Option<ast::explicit_self_>) { opt_explicit_self: Option<ast::explicit_self_>) {
// It is unfortunate to duplicate the commasep logic, but we want the // It is unfortunate to duplicate the commasep logic, but we want the
// self type and the args all in the same box. // self type and the args all in the same box.
box(s, 0u, inconsistent); rbox(s, 0u, inconsistent);
let mut first = true; let mut first = true;
for explicit_self in opt_explicit_self.iter() { for explicit_self in opt_explicit_self.iter() {
first = !print_explicit_self(s, *explicit_self); first = !print_explicit_self(s, *explicit_self);
@ -2071,7 +2072,7 @@ pub fn print_ty_fn(s: @ps,
// It is unfortunate to duplicate the commasep logic, but we want the // It is unfortunate to duplicate the commasep logic, but we want the
// self type and the args all in the same box. // self type and the args all in the same box.
box(s, 0u, inconsistent); rbox(s, 0u, inconsistent);
let mut first = true; let mut first = true;
for explicit_self in opt_explicit_self.iter() { for explicit_self in opt_explicit_self.iter() {
first = !print_explicit_self(s, *explicit_self); first = !print_explicit_self(s, *explicit_self);

View file

@ -46,7 +46,7 @@ type nillist = List<()>;
// Filled with things that have to be unwound // Filled with things that have to be unwound
struct State { struct State {
box: @nillist, managed: @nillist,
unique: ~nillist, unique: ~nillist,
tuple: (@nillist, ~nillist), tuple: (@nillist, ~nillist),
vec: ~[@nillist], vec: ~[@nillist],
@ -78,7 +78,7 @@ fn recurse_or_fail(depth: int, st: Option<State>) {
let st = match st { let st = match st {
None => { None => {
State { State {
box: @Nil, managed: @Nil,
unique: ~Nil, unique: ~Nil,
tuple: (@Nil, ~Nil), tuple: (@Nil, ~Nil),
vec: ~[@Nil], vec: ~[@Nil],
@ -87,7 +87,7 @@ fn recurse_or_fail(depth: int, st: Option<State>) {
} }
Some(st) => { Some(st) => {
State { State {
box: @Cons((), st.box), managed: @Cons((), st.managed),
unique: ~Cons((), @*st.unique), unique: ~Cons((), @*st.unique),
tuple: (@Cons((), st.tuple.first()), tuple: (@Cons((), st.tuple.first()),
~Cons((), @*st.tuple.second())), ~Cons((), @*st.tuple.second())),

View file

@ -12,10 +12,10 @@
fn borrow<'r, T>(x: &'r T) -> &'r T {x} fn borrow<'r, T>(x: &'r T) -> &'r T {x}
fn foo(cond: || -> bool, box: || -> @int) { fn foo(cond: || -> bool, make_box: || -> @int) {
let mut y: &int; let mut y: &int;
loop { loop {
let x = box(); let x = make_box();
// Here we complain because the resulting region // Here we complain because the resulting region
// of this borrow is the fn body as a whole. // of this borrow is the fn body as a whole.

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
fn f() { fn f() {
let box = ~mut 42; let a_box = ~mut 42;
//~^ ERROR found `mut` in ident position //~^ ERROR found `mut` in ident position
//~^^ ERROR expected `;` but found `42` //~^^ ERROR expected `;` but found `42`
} }

View file

@ -29,19 +29,19 @@ fn fun1() {
// in the past, borrow checker behaved differently when // in the past, borrow checker behaved differently when
// init and decl of `v` were distinct // init and decl of `v` were distinct
let v; let v;
let mut box = Box {x: 0}; let mut a_box = Box {x: 0};
box.set(22); a_box.set(22);
v = *box.get(); v = *a_box.get();
box.set(v+1); a_box.set(v+1);
assert_eq!(23, *box.get()); assert_eq!(23, *a_box.get());
} }
fn fun2() { fn fun2() {
let mut box = Box {x: 0}; let mut a_box = Box {x: 0};
box.set(22); a_box.set(22);
let v = *box.get(); let v = *a_box.get();
box.set(v+1); a_box.set(v+1);
assert_eq!(23, *box.get()); assert_eq!(23, *a_box.get());
} }
pub fn main() { pub fn main() {

View file

@ -30,7 +30,7 @@ fn Box() -> Box {
} }
struct LayoutData { struct LayoutData {
box: Option<@Box> a_box: Option<@Box>
} }
pub fn main() { } pub fn main() { }

View file

@ -16,8 +16,8 @@ enum taggy {
} }
fn f() { fn f() {
let box = @mut nil; let a_box = @mut nil;
*box = cons(box); *a_box = cons(a_box);
} }
pub fn main() { pub fn main() {

View file

@ -10,11 +10,11 @@
#[feature(managed_boxes)]; #[feature(managed_boxes)];
fn box<T:'static>(x: Box<T>) -> @Box<T> { return @x; } fn box_it<T:'static>(x: Box<T>) -> @Box<T> { return @x; }
struct Box<T> {x: T, y: T, z: T} struct Box<T> {x: T, y: T, z: T}
pub fn main() { pub fn main() {
let x: @Box<int> = box::<int>(Box{x: 1, y: 2, z: 3}); let x: @Box<int> = box_it::<int>(Box{x: 1, y: 2, z: 3});
assert_eq!(x.y, 2); assert_eq!(x.y, 2);
} }

View file

@ -10,9 +10,9 @@
struct Triple<T> { x: T, y: T, z: T } struct Triple<T> { x: T, y: T, z: T }
fn box<T>(x: Triple<T>) -> ~Triple<T> { return ~x; } fn box_it<T>(x: Triple<T>) -> ~Triple<T> { return ~x; }
pub fn main() { pub fn main() {
let x: ~Triple<int> = box::<int>(Triple{x: 1, y: 2, z: 3}); let x: ~Triple<int> = box_it::<int>(Triple{x: 1, y: 2, z: 3});
assert_eq!(x.y, 2); assert_eq!(x.y, 2);
} }