Skip to content

Commit ebbd30b

Browse files
committed
auto merge of #10929 : pcwalton/rust/deboxing, r=pcwalton
...eyword. r? @brson
2 parents 8d52dfb + 998a3bb commit ebbd30b

29 files changed

+167
-124
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ pub fn opaque_box_body(bcx: @mut Block,
303303
let _icx = push_ctxt("opaque_box_body");
304304
let ccx = bcx.ccx();
305305
let ty = type_of(ccx, body_t);
306-
let ty = Type::box(ccx, &ty);
306+
let ty = Type::smart_ptr(ccx, &ty);
307307
let boxptr = PointerCast(bcx, boxptr, ty.ptr_to());
308308
GEPi(bcx, boxptr, [0u, abi::box_field_body])
309309
}
@@ -385,20 +385,24 @@ pub fn malloc_raw(bcx: @mut Block, t: ty::t, heap: heap) -> Result {
385385

386386
pub struct MallocResult {
387387
bcx: @mut Block,
388-
box: ValueRef,
388+
smart_ptr: ValueRef,
389389
body: ValueRef
390390
}
391391

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

401-
MallocResult { bcx: bcx, box: llbox, body: body }
401+
MallocResult {
402+
bcx: bcx,
403+
smart_ptr: llbox,
404+
body: body,
405+
}
402406
}
403407

404408
pub fn malloc_general(bcx: @mut Block, t: ty::t, heap: heap) -> MallocResult {

src/librustc/middle/trans/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ fn boxed_type_metadata(cx: &mut CrateContext,
16831683
None => ~"BoxedType"
16841684
};
16851685

1686-
let box_llvm_type = Type::box(cx, &content_llvm_type);
1686+
let box_llvm_type = Type::smart_ptr(cx, &content_llvm_type);
16871687
let member_llvm_types = box_llvm_type.field_types();
16881688
assert!(box_layout_is_correct(cx, member_llvm_types, content_llvm_type));
16891689

src/librustc/middle/trans/expr.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,8 +1396,11 @@ fn trans_unary_datum(bcx: @mut Block,
13961396
revoke_clean(bcx, val);
13971397
return immediate_rvalue_bcx(bcx, val, box_ty);
13981398
} else {
1399-
let base::MallocResult { bcx, box: bx, body } =
1400-
base::malloc_general(bcx, contents_ty, heap);
1399+
let base::MallocResult {
1400+
bcx,
1401+
smart_ptr: bx,
1402+
body
1403+
} = base::malloc_general(bcx, contents_ty, heap);
14011404
add_clean_free(bcx, bx, heap);
14021405
let bcx = trans_into(bcx, contents, SaveIn(body));
14031406
revoke_clean(bcx, bx);

src/librustc/middle/trans/tvec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn alloc_raw(bcx: @mut Block, unit_ty: ty::t,
9898
Store(bcx, alloc, GEPi(bcx, val, [0u, abi::vec_elt_alloc]));
9999
return rslt(bcx, val);
100100
} else {
101-
let base::MallocResult {bcx, box: bx, body} =
101+
let base::MallocResult {bcx, smart_ptr: bx, body} =
102102
base::malloc_general_dyn(bcx, vecbodyty, heap, vecsize);
103103
Store(bcx, fill, GEPi(bcx, body, [0u, abi::vec_elt_fill]));
104104
Store(bcx, alloc, GEPi(bcx, body, [0u, abi::vec_elt_alloc]));

src/librustc/middle/trans/type_.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl Type {
258258
Type::struct_(Type::box_header_fields(ctx), false)
259259
}
260260

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

@@ -267,11 +267,11 @@ impl Type {
267267
}
268268

269269
pub fn opaque_box(ctx: &CrateContext) -> Type {
270-
Type::box(ctx, &Type::opaque())
270+
Type::smart_ptr(ctx, &Type::opaque())
271271
}
272272

273273
pub fn unique(ctx: &CrateContext, ty: &Type) -> Type {
274-
Type::box(ctx, ty)
274+
Type::smart_ptr(ctx, ty)
275275
}
276276

277277
pub fn opaque_cbox_ptr(cx: &CrateContext) -> Type {

src/librustc/middle/trans/type_of.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,18 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {
221221
adt::incomplete_type_of(cx, repr, name)
222222
}
223223
ty::ty_estr(ty::vstore_box) => {
224-
Type::box(cx, &Type::vec(cx.sess.targ_cfg.arch, &Type::i8())).ptr_to()
224+
Type::smart_ptr(cx,
225+
&Type::vec(cx.sess.targ_cfg.arch,
226+
&Type::i8())).ptr_to()
225227
}
226228
ty::ty_evec(ref mt, ty::vstore_box) => {
227229
let e_ty = type_of(cx, mt.ty);
228230
let v_ty = Type::vec(cx.sess.targ_cfg.arch, &e_ty);
229-
Type::box(cx, &v_ty).ptr_to()
231+
Type::smart_ptr(cx, &v_ty).ptr_to()
230232
}
231233
ty::ty_box(ref mt) => {
232234
let ty = type_of(cx, mt.ty);
233-
Type::box(cx, &ty).ptr_to()
235+
Type::smart_ptr(cx, &ty).ptr_to()
234236
}
235237
ty::ty_opaque_box => Type::opaque_box(cx).ptr_to(),
236238
ty::ty_uniq(ref mt) => {

src/libstd/at_vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use vec::{ImmutableVector, OwnedVector};
2525
#[inline]
2626
pub fn capacity<T>(v: @[T]) -> uint {
2727
unsafe {
28-
let box = v.repr();
29-
(*box).data.alloc / mem::size_of::<T>()
28+
let managed_box = v.repr();
29+
(*managed_box).data.alloc / mem::size_of::<T>()
3030
}
3131
}
3232

src/libstd/cast.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ mod tests {
120120
}
121121

122122
#[test]
123-
fn test_bump_box_refcount() {
123+
fn test_bump_managed_refcount() {
124124
unsafe {
125-
let box = @~"box box box"; // refcount 1
126-
bump_box_refcount(box); // refcount 2
127-
let ptr: *int = transmute(box); // refcount 2
125+
let managed = @~"box box box"; // refcount 1
126+
bump_box_refcount(managed); // refcount 2
127+
let ptr: *int = transmute(managed); // refcount 2
128128
let _box1: @~str = ::cast::transmute_copy(&ptr);
129129
let _box2: @~str = ::cast::transmute_copy(&ptr);
130130
assert!(*_box1 == ~"box box box");

src/libstd/cell.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,19 @@ impl<T: Eq> Eq for RefCell<T> {
157157
}
158158

159159
/// Wraps a borrowed reference to a value in a `RefCell` box.
160-
pub struct Ref<'box, T> {
161-
priv parent: &'box RefCell<T>
160+
pub struct Ref<'b, T> {
161+
priv parent: &'b RefCell<T>
162162
}
163163

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

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

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

185185
#[unsafe_destructor]
186-
impl<'box, T> Drop for RefMut<'box, T> {
186+
impl<'b, T> Drop for RefMut<'b, T> {
187187
fn drop(&mut self) {
188188
assert!(self.parent.borrow == WRITING);
189189
self.parent.borrow = UNUSED;
190190
}
191191
}
192192

193-
impl<'box, T> RefMut<'box, T> {
193+
impl<'b, T> RefMut<'b, T> {
194194
/// Retrieve a mutable reference to the stored value.
195195
#[inline]
196196
pub fn get<'a>(&'a mut self) -> &'a mut T {

src/libstd/cleanup.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,26 @@ struct AnnihilateStats {
3030
}
3131

3232
unsafe fn each_live_alloc(read_next_before: bool,
33-
f: |box: *mut raw::Box<()>, uniq: bool| -> bool)
33+
f: |alloc: *mut raw::Box<()>, uniq: bool| -> bool)
3434
-> bool {
3535
//! Walks the internal list of allocations
3636
3737
use managed;
3838
use rt::local_heap;
3939

40-
let mut box = local_heap::live_allocs();
41-
while box != ptr::mut_null() {
42-
let next_before = (*box).next;
43-
let uniq = (*box).ref_count == managed::RC_MANAGED_UNIQUE;
40+
let mut alloc = local_heap::live_allocs();
41+
while alloc != ptr::mut_null() {
42+
let next_before = (*alloc).next;
43+
let uniq = (*alloc).ref_count == managed::RC_MANAGED_UNIQUE;
4444

45-
if !f(box as *mut raw::Box<()>, uniq) {
45+
if !f(alloc as *mut raw::Box<()>, uniq) {
4646
return false;
4747
}
4848

4949
if read_next_before {
50-
box = next_before;
50+
alloc = next_before;
5151
} else {
52-
box = (*box).next;
52+
alloc = (*alloc).next;
5353
}
5454
}
5555
return true;
@@ -82,12 +82,12 @@ pub unsafe fn annihilate() {
8282
//
8383
// In this pass, nothing gets freed, so it does not matter whether
8484
// we read the next field before or after the callback.
85-
each_live_alloc(true, |box, uniq| {
85+
each_live_alloc(true, |alloc, uniq| {
8686
stats.n_total_boxes += 1;
8787
if uniq {
8888
stats.n_unique_boxes += 1;
8989
} else {
90-
(*box).ref_count = managed::RC_IMMORTAL;
90+
(*alloc).ref_count = managed::RC_IMMORTAL;
9191
}
9292
true
9393
});
@@ -97,10 +97,10 @@ pub unsafe fn annihilate() {
9797
// In this pass, unique-managed boxes may get freed, but not
9898
// managed boxes, so we must read the `next` field *after* the
9999
// callback, as the original value may have been freed.
100-
each_live_alloc(false, |box, uniq| {
100+
each_live_alloc(false, |alloc, uniq| {
101101
if !uniq {
102-
let tydesc = (*box).type_desc;
103-
let data = &(*box).data as *();
102+
let tydesc = (*alloc).type_desc;
103+
let data = &(*alloc).data as *();
104104
((*tydesc).drop_glue)(data as *i8);
105105
}
106106
true
@@ -112,12 +112,12 @@ pub unsafe fn annihilate() {
112112
// unique-managed boxes, though I think that none of those are
113113
// left), so we must read the `next` field before, since it will
114114
// not be valid after.
115-
each_live_alloc(true, |box, uniq| {
115+
each_live_alloc(true, |alloc, uniq| {
116116
if !uniq {
117117
stats.n_bytes_freed +=
118-
(*((*box).type_desc)).size
118+
(*((*alloc).type_desc)).size
119119
+ mem::size_of::<raw::Box<()>>();
120-
local_free(box as *i8);
120+
local_free(alloc as *i8);
121121
}
122122
true
123123
});

src/libstd/local_data.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ pub fn pop<T: 'static>(key: Key<T>) -> Option<T> {
157157

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

164-
// Now that we own `box`, we can just move out of it as we would
165-
// with any other data.
166-
return Some(*box);
164+
// Now that we own `alloc`, we can just move out of it as we
165+
// would with any other data.
166+
return Some(*alloc);
167167
}
168168
_ => {}
169169
}
@@ -254,8 +254,8 @@ fn get_with<T:'static,
254254
// compiler coercions to achieve a '&' pointer.
255255
unsafe {
256256
match *cast::transmute::<&TLSValue, &(uint, ~T)>(data){
257-
(_vtable, ref box) => {
258-
let value: &T = *box;
257+
(_vtable, ref alloc) => {
258+
let value: &T = *alloc;
259259
ret = f(Some(value));
260260
}
261261
}

src/libstd/rt/borrowck.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static ALL_BITS: uint = FROZEN_BIT | MUT_BIT;
2828

2929
#[deriving(Eq)]
3030
pub struct BorrowRecord {
31-
priv box: *mut raw::Box<()>,
31+
priv alloc: *mut raw::Box<()>,
3232
file: *c_char,
3333
priv line: size_t
3434
}
@@ -55,8 +55,9 @@ pub fn clear_task_borrow_list() {
5555
}
5656

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

6162
match try_take_task_borrow_list() {
6263
None => { // not recording borrows
@@ -67,7 +68,7 @@ unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) ->
6768
let mut msg = ~"borrowed";
6869
let mut sep = " at ";
6970
for entry in borrow_list.rev_iter() {
70-
if entry.box == box {
71+
if entry.alloc == alloc {
7172
msg.push_str(sep);
7273
let filename = str::raw::from_c_str(entry.file);
7374
msg.push_str(filename);
@@ -153,7 +154,11 @@ pub unsafe fn record_borrow(a: *u8, old_ref_count: uint,
153154
debug_borrow("record_borrow:", a, old_ref_count, 0, file, line);
154155
swap_task_borrow_list(|borrow_list| {
155156
let mut borrow_list = borrow_list;
156-
borrow_list.push(BorrowRecord {box: a, file: file, line: line});
157+
borrow_list.push(BorrowRecord {
158+
alloc: a,
159+
file: file,
160+
line: line,
161+
});
157162
borrow_list
158163
})
159164
}
@@ -172,7 +177,7 @@ pub unsafe fn unrecord_borrow(a: *u8,
172177
let mut borrow_list = borrow_list;
173178
assert!(!borrow_list.is_empty());
174179
let br = borrow_list.pop();
175-
if br.box != a || br.file != file || br.line != line {
180+
if br.alloc != a || br.file != file || br.line != line {
176181
let err = format!("wrong borrow found, br={:?}", br);
177182
err.with_c_str(|msg_p| {
178183
task::begin_unwind_raw(msg_p, file, line)

src/libstd/rt/deque.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,9 @@ mod tests {
599599

600600
let (threads, hits) = vec::unzip(range(0, NTHREADS).map(|_| {
601601
let s = s.clone();
602-
let box = ~AtomicUint::new(0);
602+
let unique_box = ~AtomicUint::new(0);
603603
let thread_box = unsafe {
604-
*cast::transmute::<&~AtomicUint, **mut AtomicUint>(&box)
604+
*cast::transmute::<&~AtomicUint,**mut AtomicUint>(&unique_box)
605605
};
606606
(do Thread::start {
607607
unsafe {
@@ -617,7 +617,7 @@ mod tests {
617617
}
618618
}
619619
}
620-
}, box)
620+
}, unique_box)
621621
}));
622622

623623
let mut rng = rand::task_rng();

src/libstd/rt/global_heap.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ pub unsafe fn closure_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
7878
let total_size = get_box_size(size, (*td).align);
7979
let p = malloc_raw(total_size as uint);
8080

81-
let box = p as *mut raw::Box<()>;
82-
(*box).type_desc = td;
81+
let alloc = p as *mut raw::Box<()>;
82+
(*alloc).type_desc = td;
8383

84-
box as *c_char
84+
alloc as *c_char
8585
}
8686

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

0 commit comments

Comments
 (0)