Skip to content

Commit 0e5e01e

Browse files
committed
---
yaml --- r: 58698 b: refs/heads/try c: 31599fe h: refs/heads/master v: v3
1 parent 1e65023 commit 0e5e01e

File tree

6 files changed

+80
-107
lines changed

6 files changed

+80
-107
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: c081ffbd1e845687202a975ea2e698b623e5722f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 213f7b24ccd9a6833af7e1a329c5e7ffc8f9e3d2
5-
refs/heads/try: 6f2e429041da1990a91477e37316c73729cb6fe2
5+
refs/heads/try: 31599fe34799027939a0541d6e95d0fdd07e3155
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustc/back/abi.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ pub static n_tydesc_fields: uint = 8u;
5757
pub static fn_field_code: uint = 0u;
5858
pub static fn_field_box: uint = 1u;
5959

60+
// The three fields of a trait object/trait instance: vtable, box, and type
61+
// description.
62+
pub static trt_field_vtable: uint = 0u;
63+
pub static trt_field_box: uint = 1u;
64+
// This field is only present in unique trait objects, so it comes last.
65+
pub static trt_field_tydesc: uint = 2u;
66+
6067
pub static vec_elt_fill: uint = 0u;
6168

6269
pub static vec_elt_alloc: uint = 1u;

branches/try/src/librustc/middle/trans/glue.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,12 +537,12 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
537537
closure::make_closure_glue(bcx, v0, t, drop_ty)
538538
}
539539
ty::ty_trait(_, _, ty::BoxTraitStore, _) => {
540-
let llbox = Load(bcx, GEPi(bcx, v0, [0u, 1u]));
540+
let llbox = Load(bcx, GEPi(bcx, v0, [0u, abi::trt_field_box]));
541541
decr_refcnt_maybe_free(bcx, llbox, ty::mk_opaque_box(ccx.tcx))
542542
}
543543
ty::ty_trait(_, _, ty::UniqTraitStore, _) => {
544-
let lluniquevalue = GEPi(bcx, v0, [0, 1]);
545-
let lltydesc = Load(bcx, GEPi(bcx, v0, [0, 2]));
544+
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
545+
let lltydesc = Load(bcx, GEPi(bcx, v0, [0, abi::trt_field_tydesc]));
546546
call_tydesc_glue_full(bcx, lluniquevalue, lltydesc,
547547
abi::tydesc_field_free_glue, None);
548548
bcx
@@ -601,13 +601,13 @@ pub fn make_take_glue(bcx: block, v: ValueRef, t: ty::t) {
601601
closure::make_closure_glue(bcx, v, t, take_ty)
602602
}
603603
ty::ty_trait(_, _, ty::BoxTraitStore, _) => {
604-
let llbox = Load(bcx, GEPi(bcx, v, [0u, 1u]));
604+
let llbox = Load(bcx, GEPi(bcx, v, [0u, abi::trt_field_box]));
605605
incr_refcnt_of_boxed(bcx, llbox);
606606
bcx
607607
}
608608
ty::ty_trait(_, _, ty::UniqTraitStore, _) => {
609-
let llval = GEPi(bcx, v, [0, 1]);
610-
let lltydesc = Load(bcx, GEPi(bcx, v, [0, 2]));
609+
let llval = GEPi(bcx, v, [0, abi::trt_field_box]);
610+
let lltydesc = Load(bcx, GEPi(bcx, v, [0, abi::trt_field_tydesc]));
611611
call_tydesc_glue_full(bcx, llval, lltydesc,
612612
abi::tydesc_field_take_glue, None);
613613
bcx

branches/try/src/librustc/middle/trans/meth.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -637,14 +637,15 @@ pub fn trans_trait_callee_from_llval(bcx: block,
637637
val_str(bcx.ccx().tn, llpair));
638638
let llvtable = Load(bcx,
639639
PointerCast(bcx,
640-
GEPi(bcx, llpair, [0u, 0u]),
640+
GEPi(bcx, llpair,
641+
[0u, abi::trt_field_vtable]),
641642
T_ptr(T_ptr(T_vtable()))));
642643
643644
// Load the box from the @Trait pair and GEP over the box header if
644645
// necessary:
645646
let mut llself;
646647
debug!("(translating trait callee) loading second index from pair");
647-
let llbox = Load(bcx, GEPi(bcx, llpair, [0u, 1u]));
648+
let llbox = Load(bcx, GEPi(bcx, llpair, [0u, abi::trt_field_box]));
648649
649650
// Munge `llself` appropriately for the type of `self` in the method.
650651
let self_mode;
@@ -845,27 +846,30 @@ pub fn trans_trait_cast(bcx: block,
845846

846847
match store {
847848
ty::RegionTraitStore(_) | ty::BoxTraitStore => {
848-
let mut llboxdest = GEPi(bcx, lldest, [0u, 1u]);
849-
// Just store the pointer into the pair.
849+
let mut llboxdest = GEPi(bcx, lldest, [0u, abi::trt_field_box]);
850+
// Just store the pointer into the pair. (Region/borrowed
851+
// and boxed trait objects are represented as pairs, and
852+
// have no type descriptor field.)
850853
llboxdest = PointerCast(bcx,
851854
llboxdest,
852855
T_ptr(type_of(bcx.ccx(), v_ty)));
853856
bcx = expr::trans_into(bcx, val, SaveIn(llboxdest));
854857
}
855858
ty::UniqTraitStore => {
856-
// Translate the uniquely-owned value into the second element of
857-
// the triple. (The first element is the vtable.)
858-
let mut llvaldest = GEPi(bcx, lldest, [0, 1]);
859+
// Translate the uniquely-owned value in the
860+
// triple. (Unique trait objects are represented as
861+
// triples.)
862+
let mut llvaldest = GEPi(bcx, lldest, [0, abi::trt_field_box]);
859863
llvaldest = PointerCast(bcx,
860864
llvaldest,
861865
T_ptr(type_of(bcx.ccx(), v_ty)));
862866
bcx = expr::trans_into(bcx, val, SaveIn(llvaldest));
863867

864-
// Get the type descriptor of the wrapped value and store it into
865-
// the third element of the triple as well.
868+
// Get the type descriptor of the wrapped value and store
869+
// it in the triple as well.
866870
let tydesc = get_tydesc(bcx.ccx(), v_ty);
867871
glue::lazily_emit_all_tydesc_glue(bcx.ccx(), tydesc);
868-
let lltydescdest = GEPi(bcx, lldest, [0, 2]);
872+
let lltydescdest = GEPi(bcx, lldest, [0, abi::trt_field_tydesc]);
869873
Store(bcx, tydesc.tydesc, lltydescdest);
870874
}
871875
}
@@ -875,7 +879,7 @@ pub fn trans_trait_cast(bcx: block,
875879
let orig = resolve_vtable_in_fn_ctxt(bcx.fcx, orig);
876880
let vtable = get_vtable(bcx.ccx(), orig);
877881
Store(bcx, vtable, PointerCast(bcx,
878-
GEPi(bcx, lldest, [0u, 0u]),
882+
GEPi(bcx, lldest, [0u, abi::trt_field_vtable]),
879883
T_ptr(val_ty(vtable))));
880884

881885
bcx

branches/try/src/libstd/arena.rs

Lines changed: 51 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
// overhead when initializing plain-old-data and means we don't need
3333
// to waste time running the destructors of POD.
3434

35-
use list::{MutList, MutCons, MutNil};
3635
use list;
36+
use list::{List, Cons, Nil};
3737

3838
use core::at_vec;
39-
use core::cast::{transmute, transmute_mut_region};
39+
use core::cast::transmute;
4040
use core::cast;
4141
use core::libc::size_t;
4242
use core::ptr;
@@ -74,28 +74,26 @@ static tydesc_drop_glue_index: size_t = 3 as size_t;
7474
// will always stay at 0.
7575
struct Chunk {
7676
data: @[u8],
77-
fill: uint,
77+
mut fill: uint,
7878
is_pod: bool,
7979
}
8080

8181
pub struct Arena {
8282
// The head is seperated out from the list as a unbenchmarked
8383
// microoptimization, to avoid needing to case on the list to
8484
// access the head.
85-
priv head: Chunk,
86-
priv pod_head: Chunk,
87-
priv chunks: @mut MutList<Chunk>,
85+
priv mut head: Chunk,
86+
priv mut pod_head: Chunk,
87+
priv mut chunks: @List<Chunk>,
8888
}
8989

9090
#[unsafe_destructor]
9191
impl Drop for Arena {
9292
fn finalize(&self) {
9393
unsafe {
9494
destroy_chunk(&self.head);
95-
for self.chunks.each |chunk| {
96-
if !chunk.is_pod {
97-
destroy_chunk(chunk);
98-
}
95+
for list::each(self.chunks) |chunk| {
96+
if !chunk.is_pod { destroy_chunk(chunk); }
9997
}
10098
}
10199
}
@@ -115,7 +113,7 @@ pub fn arena_with_size(initial_size: uint) -> Arena {
115113
Arena {
116114
head: chunk(initial_size, false),
117115
pod_head: chunk(initial_size, true),
118-
chunks: @mut MutNil,
116+
chunks: @Nil,
119117
}
120118
}
121119

@@ -172,40 +170,39 @@ unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) {
172170

173171
pub impl Arena {
174172
// Functions for the POD part of the arena
175-
priv fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
173+
priv fn alloc_pod_grow(&self, n_bytes: uint, align: uint) -> *u8 {
176174
// Allocate a new chunk.
177175
let chunk_size = at_vec::capacity(self.pod_head.data);
178176
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
179-
self.chunks = @mut MutCons(copy self.pod_head, self.chunks);
177+
self.chunks = @Cons(copy self.pod_head, self.chunks);
180178
self.pod_head =
181179
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true);
182180

183181
return self.alloc_pod_inner(n_bytes, align);
184182
}
185183

186184
#[inline(always)]
187-
priv fn alloc_pod_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
188-
unsafe {
189-
// XXX: Borrow check
190-
let head = transmute_mut_region(&mut self.pod_head);
185+
priv fn alloc_pod_inner(&self, n_bytes: uint, align: uint) -> *u8 {
186+
let head = &mut self.pod_head;
191187

192-
let start = round_up_to(head.fill, align);
193-
let end = start + n_bytes;
194-
if end > at_vec::capacity(head.data) {
195-
return self.alloc_pod_grow(n_bytes, align);
196-
}
197-
head.fill = end;
188+
let start = round_up_to(head.fill, align);
189+
let end = start + n_bytes;
190+
if end > at_vec::capacity(head.data) {
191+
return self.alloc_pod_grow(n_bytes, align);
192+
}
193+
head.fill = end;
198194

199-
//debug!("idx = %u, size = %u, align = %u, fill = %u",
200-
// start, n_bytes, align, head.fill);
195+
//debug!("idx = %u, size = %u, align = %u, fill = %u",
196+
// start, n_bytes, align, head.fill);
201197

198+
unsafe {
202199
ptr::offset(vec::raw::to_ptr(head.data), start)
203200
}
204201
}
205202

206203
#[inline(always)]
207204
#[cfg(stage0)]
208-
priv fn alloc_pod<T>(&mut self, op: &fn() -> T) -> &'self T {
205+
priv fn alloc_pod<T>(&self, op: &fn() -> T) -> &'self T {
209206
unsafe {
210207
let tydesc = sys::get_type_desc::<T>();
211208
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
@@ -219,7 +216,7 @@ pub impl Arena {
219216
#[cfg(stage1)]
220217
#[cfg(stage2)]
221218
#[cfg(stage3)]
222-
priv fn alloc_pod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
219+
priv fn alloc_pod<'a, T>(&'a self, op: &fn() -> T) -> &'a T {
223220
unsafe {
224221
let tydesc = sys::get_type_desc::<T>();
225222
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
@@ -230,44 +227,42 @@ pub impl Arena {
230227
}
231228

232229
// Functions for the non-POD part of the arena
233-
priv fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint)
234-
-> (*u8, *u8) {
230+
priv fn alloc_nonpod_grow(&self, n_bytes: uint, align: uint) -> (*u8, *u8) {
235231
// Allocate a new chunk.
236232
let chunk_size = at_vec::capacity(self.head.data);
237233
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
238-
self.chunks = @mut MutCons(copy self.head, self.chunks);
234+
self.chunks = @Cons(copy self.head, self.chunks);
239235
self.head =
240236
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false);
241237

242238
return self.alloc_nonpod_inner(n_bytes, align);
243239
}
244240

245241
#[inline(always)]
246-
priv fn alloc_nonpod_inner(&mut self, n_bytes: uint, align: uint)
247-
-> (*u8, *u8) {
248-
unsafe {
249-
let head = transmute_mut_region(&mut self.head);
250-
251-
let tydesc_start = head.fill;
252-
let after_tydesc = head.fill + sys::size_of::<*TypeDesc>();
253-
let start = round_up_to(after_tydesc, align);
254-
let end = start + n_bytes;
255-
if end > at_vec::capacity(head.data) {
256-
return self.alloc_nonpod_grow(n_bytes, align);
257-
}
258-
head.fill = round_up_to(end, sys::pref_align_of::<*TypeDesc>());
242+
priv fn alloc_nonpod_inner(&self, n_bytes: uint, align: uint) -> (*u8, *u8) {
243+
let head = &mut self.head;
259244

260-
//debug!("idx = %u, size = %u, align = %u, fill = %u",
261-
// start, n_bytes, align, head.fill);
245+
let tydesc_start = head.fill;
246+
let after_tydesc = head.fill + sys::size_of::<*TypeDesc>();
247+
let start = round_up_to(after_tydesc, align);
248+
let end = start + n_bytes;
249+
if end > at_vec::capacity(head.data) {
250+
return self.alloc_nonpod_grow(n_bytes, align);
251+
}
252+
head.fill = round_up_to(end, sys::pref_align_of::<*TypeDesc>());
253+
254+
//debug!("idx = %u, size = %u, align = %u, fill = %u",
255+
// start, n_bytes, align, head.fill);
262256

257+
unsafe {
263258
let buf = vec::raw::to_ptr(head.data);
264259
return (ptr::offset(buf, tydesc_start), ptr::offset(buf, start));
265260
}
266261
}
267262

268263
#[inline(always)]
269264
#[cfg(stage0)]
270-
priv fn alloc_nonpod<T>(&mut self, op: &fn() -> T) -> &'self T {
265+
priv fn alloc_nonpod<T>(&self, op: &fn() -> T) -> &'self T {
271266
unsafe {
272267
let tydesc = sys::get_type_desc::<T>();
273268
let (ty_ptr, ptr) =
@@ -291,7 +286,7 @@ pub impl Arena {
291286
#[cfg(stage1)]
292287
#[cfg(stage2)]
293288
#[cfg(stage3)]
294-
priv fn alloc_nonpod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
289+
priv fn alloc_nonpod<'a, T>(&'a self, op: &fn() -> T) -> &'a T {
295290
unsafe {
296291
let tydesc = sys::get_type_desc::<T>();
297292
let (ty_ptr, ptr) =
@@ -314,16 +309,13 @@ pub impl Arena {
314309
// The external interface
315310
#[inline(always)]
316311
#[cfg(stage0)]
317-
fn alloc<T>(&mut self, op: &fn() -> T) -> &'self T {
312+
fn alloc<T>(&self, op: &fn() -> T) -> &'self T {
318313
unsafe {
319-
// XXX: Borrow check
320-
let this = transmute_mut_region(self);
321314
if !rusti::needs_drop::<T>() {
322-
return this.alloc_pod(op);
315+
self.alloc_pod(op)
316+
} else {
317+
self.alloc_nonpod(op)
323318
}
324-
// XXX: Borrow check
325-
let this = transmute_mut_region(self);
326-
this.alloc_nonpod(op)
327319
}
328320
}
329321

@@ -332,16 +324,13 @@ pub impl Arena {
332324
#[cfg(stage1)]
333325
#[cfg(stage2)]
334326
#[cfg(stage3)]
335-
fn alloc<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
327+
fn alloc<'a, T>(&'a self, op: &fn() -> T) -> &'a T {
336328
unsafe {
337-
// XXX: Borrow check
338-
let this = transmute_mut_region(self);
339329
if !rusti::needs_drop::<T>() {
340-
return this.alloc_pod(op);
330+
self.alloc_pod(op)
331+
} else {
332+
self.alloc_nonpod(op)
341333
}
342-
// XXX: Borrow check
343-
let this = transmute_mut_region(self);
344-
this.alloc_nonpod(op)
345334
}
346335
}
347336
}
@@ -359,9 +348,7 @@ fn test_arena_destructors() {
359348
}
360349
}
361350

362-
#[test]
363-
#[should_fail]
364-
#[ignore(cfg(windows))]
351+
#[test] #[should_fail] #[ignore(cfg(windows))]
365352
fn test_arena_destructors_fail() {
366353
let arena = Arena();
367354
// Put some stuff in the arena.

0 commit comments

Comments
 (0)