Skip to content

Commit 9deff55

Browse files
committed
auto merge of #8899 : thestinger/rust/repr, r=huonw
2 parents c8db9e2 + 17f9382 commit 9deff55

12 files changed

+56
-36
lines changed

src/librustc/middle/trans/reflect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ impl Reflector {
252252
let tcx = bcx.ccx().tcx;
253253
let fields = ty::struct_fields(tcx, did, substs);
254254

255-
let extra = ~[self.c_uint(fields.len())]
256-
+ self.c_size_and_align(t);
255+
let extra = ~[self.c_slice(ty_to_str(tcx, t).to_managed()),
256+
self.c_uint(fields.len())] + self.c_size_and_align(t);
257257
do self.bracketed("class", extra) |this| {
258258
for (i, field) in fields.iter().enumerate() {
259259
let extra = ~[this.c_uint(i),

src/libstd/reflect.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,15 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
331331
true
332332
}
333333

334-
fn visit_enter_class(&mut self, n_fields: uint, sz: uint, align: uint)
335-
-> bool {
334+
fn visit_enter_class(&mut self, name: &str, n_fields: uint, sz: uint, align: uint) -> bool {
336335
self.align(align);
337-
if ! self.inner.visit_enter_class(n_fields, sz, align) {
336+
if ! self.inner.visit_enter_class(name, n_fields, sz, align) {
338337
return false;
339338
}
340339
true
341340
}
342341

343-
fn visit_class_field(&mut self, i: uint, name: &str,
344-
mtbl: uint, inner: *TyDesc) -> bool {
342+
fn visit_class_field(&mut self, i: uint, name: &str, mtbl: uint, inner: *TyDesc) -> bool {
345343
unsafe { self.align((*inner).align); }
346344
if ! self.inner.visit_class_field(i, name, mtbl, inner) {
347345
return false;
@@ -350,9 +348,8 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
350348
true
351349
}
352350

353-
fn visit_leave_class(&mut self, n_fields: uint, sz: uint, align: uint)
354-
-> bool {
355-
if ! self.inner.visit_leave_class(n_fields, sz, align) {
351+
fn visit_leave_class(&mut self, name: &str, n_fields: uint, sz: uint, align: uint) -> bool {
352+
if ! self.inner.visit_leave_class(name, n_fields, sz, align) {
356353
return false;
357354
}
358355
true

src/libstd/repr.rs

+20-9
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
346346
// Type no longer exists, vestigial function.
347347
fn visit_vec(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool { fail!(); }
348348

349-
350349
fn visit_unboxed_vec(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
351350
do self.get::<raw::Vec<()>> |this, b| {
352351
this.write_unboxed_vec_repr(mtbl, b, inner);
@@ -413,11 +412,15 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
413412
true
414413
}
415414

416-
fn visit_enter_class(&mut self, _n_fields: uint,
415+
fn visit_enter_class(&mut self, name: &str, n_fields: uint,
417416
_sz: uint, _align: uint) -> bool {
418-
self.writer.write(['{' as u8]);
417+
self.writer.write(name.as_bytes());
418+
if n_fields != 0 {
419+
self.writer.write(['{' as u8]);
420+
}
419421
true
420422
}
423+
421424
fn visit_class_field(&mut self, i: uint, name: &str,
422425
mtbl: uint, inner: *TyDesc) -> bool {
423426
if i != 0 {
@@ -429,9 +432,12 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
429432
self.visit_inner(inner);
430433
true
431434
}
432-
fn visit_leave_class(&mut self, _n_fields: uint,
435+
436+
fn visit_leave_class(&mut self, _name: &str, n_fields: uint,
433437
_sz: uint, _align: uint) -> bool {
434-
self.writer.write(['}' as u8]);
438+
if n_fields != 0 {
439+
self.writer.write(['}' as u8]);
440+
}
435441
true
436442
}
437443

@@ -440,13 +446,15 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
440446
self.writer.write(['(' as u8]);
441447
true
442448
}
449+
443450
fn visit_tup_field(&mut self, i: uint, inner: *TyDesc) -> bool {
444451
if i != 0 {
445452
self.writer.write(", ".as_bytes());
446453
}
447454
self.visit_inner(inner);
448455
true
449456
}
457+
450458
fn visit_leave_tup(&mut self, _n_fields: uint,
451459
_sz: uint, _align: uint) -> bool {
452460
if _n_fields == 1 {
@@ -544,12 +552,15 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
544552

545553
fn visit_enter_fn(&mut self, _purity: uint, _proto: uint,
546554
_n_inputs: uint, _retstyle: uint) -> bool { true }
555+
547556
fn visit_fn_input(&mut self, _i: uint, _mode: uint, _inner: *TyDesc) -> bool {
548557
true
549558
}
559+
550560
fn visit_fn_output(&mut self, _retstyle: uint, _inner: *TyDesc) -> bool {
551561
true
552562
}
563+
553564
fn visit_leave_fn(&mut self, _purity: uint, _proto: uint,
554565
_n_inputs: uint, _retstyle: uint) -> bool { true }
555566

@@ -628,11 +639,11 @@ fn test_repr() {
628639
exact_test(&(&["hi", "there"]),
629640
"&[\"hi\", \"there\"]");
630641
exact_test(&(P{a:10, b:1.234}),
631-
"{a: 10, b: 1.234}");
642+
"repr::P{a: 10, b: 1.234}");
632643
exact_test(&(@P{a:10, b:1.234}),
633-
"@{a: 10, b: 1.234}");
644+
"@repr::P{a: 10, b: 1.234}");
634645
exact_test(&(~P{a:10, b:1.234}),
635-
"~{a: 10, b: 1.234}");
646+
"~repr::P{a: 10, b: 1.234}");
636647
exact_test(&(10u8, ~"hello"),
637648
"(10u8, ~\"hello\")");
638649
exact_test(&(10u16, ~"hello"),
@@ -643,5 +654,5 @@ fn test_repr() {
643654
"(10u64, ~\"hello\")");
644655

645656
struct Foo;
646-
exact_test(&(~[Foo, Foo, Foo]), "~[{}, {}, {}]");
657+
exact_test(&(~[Foo, Foo]), "~[repr::test_repr::Foo, repr::test_repr::Foo]");
647658
}

src/libstd/unstable/intrinsics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ pub trait TyVisitor {
220220
fn visit_leave_rec(&mut self, n_fields: uint,
221221
sz: uint, align: uint) -> bool;
222222

223-
fn visit_enter_class(&mut self, n_fields: uint,
223+
fn visit_enter_class(&mut self, name: &str, n_fields: uint,
224224
sz: uint, align: uint) -> bool;
225225
fn visit_class_field(&mut self, i: uint, name: &str,
226226
mtbl: uint, inner: *TyDesc) -> bool;
227-
fn visit_leave_class(&mut self, n_fields: uint,
227+
fn visit_leave_class(&mut self, name: &str, n_fields: uint,
228228
sz: uint, align: uint) -> bool;
229229

230230
fn visit_enter_tup(&mut self, n_fields: uint,

src/libstd/vec.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -3681,10 +3681,12 @@ mod tests {
36813681
assert_eq!(cnt, 11);
36823682

36833683
let xs = ~[Foo, Foo, Foo];
3684-
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()), ~"~[{}, {}]");
3684+
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()),
3685+
~"~[vec::tests::Foo, vec::tests::Foo]");
36853686
36863687
let xs: [Foo, ..3] = [Foo, Foo, Foo];
3687-
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()), ~"~[{}, {}]");
3688+
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()),
3689+
~"~[vec::tests::Foo, vec::tests::Foo]");
36883690
cnt = 0;
36893691
for f in xs.iter() {
36903692
assert!(*f == Foo);

src/test/run-pass/fixed_length_vec_glue.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// xfail-fast: check-fast screws up repr paths
12+
1113
use std::sys;
1214

1315
struct Struc { a: u8, b: [int, ..3], c: int }
@@ -16,5 +18,5 @@ pub fn main() {
1618
let arr = [1,2,3];
1719
let struc = Struc {a: 13u8, b: arr, c: 42};
1820
let s = sys::log_str(&struc);
19-
assert_eq!(s, ~"{a: 13u8, b: [1, 2, 3], c: 42}");
21+
assert_eq!(s, ~"Struc{a: 13u8, b: [1, 2, 3], c: 42}");
2022
}

src/test/run-pass/ifmt.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// xfail-fast: check-fast screws up repr paths
12+
1113
use std::fmt;
1214

1315
struct A;
@@ -27,7 +29,7 @@ pub fn main() {
2729

2830
// Make sure there's a poly formatter that takes anything
2931
t!(format!("{:?}", 1), "1");
30-
t!(format!("{:?}", A), "{}");
32+
t!(format!("{:?}", A), "A");
3133
t!(format!("{:?}", ()), "()");
3234
t!(format!("{:?}", @(~1, "foo")), "@(~1, \"foo\")");
3335

src/test/run-pass/rec-align-u32.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// xfail-fast: check-fast screws up repr paths
12+
1113
// Issue #2303
1214

1315
use std::sys;
@@ -64,6 +66,6 @@ pub fn main() {
6466
// because `inner`s alignment was 4.
6567
assert_eq!(sys::size_of::<Outer>(), m::size());
6668

67-
assert_eq!(y, ~"{c8: 22u8, t: {c64: 44u32}}");
69+
assert_eq!(y, ~"Outer{c8: 22u8, t: Inner{c64: 44u32}}");
6870
}
6971
}

src/test/run-pass/rec-align-u64.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// xfail-fast: check-fast screws up repr paths
12+
1113
// Issue #2303
1214

1315
use std::sys;
@@ -86,6 +88,6 @@ pub fn main() {
8688
// because `Inner`s alignment was 4.
8789
assert_eq!(sys::size_of::<Outer>(), m::m::size());
8890

89-
assert_eq!(y, ~"{c8: 22u8, t: {c64: 44u64}}");
91+
assert_eq!(y, ~"Outer{c8: 22u8, t: Inner{c64: 44u64}}");
9092
}
9193
}

src/test/run-pass/reflect-visit-data.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
317317
true
318318
}
319319

320-
fn visit_enter_class(&mut self, n_fields: uint, sz: uint, align: uint)
320+
fn visit_enter_class(&mut self, name: &str, n_fields: uint, sz: uint, align: uint)
321321
-> bool {
322322
self.align(align);
323-
if ! self.inner.visit_enter_class(n_fields, sz, align) {
323+
if ! self.inner.visit_enter_class(name, n_fields, sz, align) {
324324
return false;
325325
}
326326
true
@@ -334,9 +334,9 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
334334
true
335335
}
336336

337-
fn visit_leave_class(&mut self, n_fields: uint, sz: uint, align: uint)
337+
fn visit_leave_class(&mut self, name: &str, n_fields: uint, sz: uint, align: uint)
338338
-> bool {
339-
if ! self.inner.visit_leave_class(n_fields, sz, align) {
339+
if ! self.inner.visit_leave_class(name, n_fields, sz, align) {
340340
return false;
341341
}
342342
true
@@ -565,13 +565,13 @@ impl TyVisitor for my_visitor {
565565
fn visit_leave_rec(&mut self, _n_fields: uint,
566566
_sz: uint, _align: uint) -> bool { true }
567567

568-
fn visit_enter_class(&mut self, _n_fields: uint,
568+
fn visit_enter_class(&mut self, _name: &str, _n_fields: uint,
569569
_sz: uint, _align: uint) -> bool { true }
570570
fn visit_class_field(&mut self, _i: uint, _name: &str,
571571
_mtbl: uint, inner: *TyDesc) -> bool {
572572
self.visit_inner(inner)
573573
}
574-
fn visit_leave_class(&mut self, _n_fields: uint,
574+
fn visit_leave_class(&mut self, _name: &str, _n_fields: uint,
575575
_sz: uint, _align: uint) -> bool { true }
576576

577577
fn visit_enter_tup(&mut self, _n_fields: uint,

src/test/run-pass/reflect-visit-type.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ impl TyVisitor for MyVisitor {
9999
fn visit_leave_rec(&mut self, _n_fields: uint,
100100
_sz: uint, _align: uint) -> bool { true }
101101

102-
fn visit_enter_class(&mut self, _n_fields: uint,
102+
fn visit_enter_class(&mut self, _name: &str, _n_fields: uint,
103103
_sz: uint, _align: uint) -> bool { true }
104104
fn visit_class_field(&mut self, _i: uint, _name: &str,
105105
_mtbl: uint, _inner: *TyDesc) -> bool { true }
106-
fn visit_leave_class(&mut self, _n_fields: uint,
106+
fn visit_leave_class(&mut self, _name: &str, _n_fields: uint,
107107
_sz: uint, _align: uint) -> bool { true }
108108

109109
fn visit_enter_tup(&mut self, _n_fields: uint,

src/test/run-pass/tag-align-shape.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// xfail-fast: check-fast screws up repr paths
12+
1113
enum a_tag {
1214
a_tag(u64)
1315
}
@@ -21,5 +23,5 @@ pub fn main() {
2123
let x = t_rec {c8: 22u8, t: a_tag(44u64)};
2224
let y = fmt!("%?", x);
2325
info!("y = %s", y);
24-
assert_eq!(y, ~"{c8: 22u8, t: a_tag(44u64)}");
26+
assert_eq!(y, ~"t_rec{c8: 22u8, t: a_tag(44u64)}");
2527
}

0 commit comments

Comments
 (0)