Skip to content

improve repr #8899

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

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ impl Reflector {
let tcx = bcx.ccx().tcx;
let fields = ty::struct_fields(tcx, did, substs);

let extra = ~[self.c_uint(fields.len())]
+ self.c_size_and_align(t);
let extra = ~[self.c_slice(ty_to_str(tcx, t).to_managed()),
self.c_uint(fields.len())] + self.c_size_and_align(t);
do self.bracketed("class", extra) |this| {
for (i, field) in fields.iter().enumerate() {
let extra = ~[this.c_uint(i),
Expand Down
13 changes: 5 additions & 8 deletions src/libstd/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,15 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
true
}

fn visit_enter_class(&mut self, n_fields: uint, sz: uint, align: uint)
-> bool {
fn visit_enter_class(&mut self, name: &str, n_fields: uint, sz: uint, align: uint) -> bool {
self.align(align);
if ! self.inner.visit_enter_class(n_fields, sz, align) {
if ! self.inner.visit_enter_class(name, n_fields, sz, align) {
return false;
}
true
}

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

fn visit_leave_class(&mut self, n_fields: uint, sz: uint, align: uint)
-> bool {
if ! self.inner.visit_leave_class(n_fields, sz, align) {
fn visit_leave_class(&mut self, name: &str, n_fields: uint, sz: uint, align: uint) -> bool {
if ! self.inner.visit_leave_class(name, n_fields, sz, align) {
return false;
}
true
Expand Down
29 changes: 20 additions & 9 deletions src/libstd/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
// Type no longer exists, vestigial function.
fn visit_vec(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool { fail!(); }


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

fn visit_enter_class(&mut self, _n_fields: uint,
fn visit_enter_class(&mut self, name: &str, n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write(['{' as u8]);
self.writer.write(name.as_bytes());
if n_fields != 0 {
self.writer.write(['{' as u8]);
}
true
}

fn visit_class_field(&mut self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool {
if i != 0 {
Expand All @@ -429,9 +432,12 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
self.visit_inner(inner);
true
}
fn visit_leave_class(&mut self, _n_fields: uint,

fn visit_leave_class(&mut self, _name: &str, n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write(['}' as u8]);
if n_fields != 0 {
self.writer.write(['}' as u8]);
}
true
}

Expand All @@ -440,13 +446,15 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
self.writer.write(['(' as u8]);
true
}

fn visit_tup_field(&mut self, i: uint, inner: *TyDesc) -> bool {
if i != 0 {
self.writer.write(", ".as_bytes());
}
self.visit_inner(inner);
true
}

fn visit_leave_tup(&mut self, _n_fields: uint,
_sz: uint, _align: uint) -> bool {
if _n_fields == 1 {
Expand Down Expand Up @@ -544,12 +552,15 @@ impl<'self> TyVisitor for ReprVisitor<'self> {

fn visit_enter_fn(&mut self, _purity: uint, _proto: uint,
_n_inputs: uint, _retstyle: uint) -> bool { true }

fn visit_fn_input(&mut self, _i: uint, _mode: uint, _inner: *TyDesc) -> bool {
true
}

fn visit_fn_output(&mut self, _retstyle: uint, _inner: *TyDesc) -> bool {
true
}

fn visit_leave_fn(&mut self, _purity: uint, _proto: uint,
_n_inputs: uint, _retstyle: uint) -> bool { true }

Expand Down Expand Up @@ -628,11 +639,11 @@ fn test_repr() {
exact_test(&(&["hi", "there"]),
"&[\"hi\", \"there\"]");
exact_test(&(P{a:10, b:1.234}),
"{a: 10, b: 1.234}");
"repr::P{a: 10, b: 1.234}");
exact_test(&(@P{a:10, b:1.234}),
"@{a: 10, b: 1.234}");
"@repr::P{a: 10, b: 1.234}");
exact_test(&(~P{a:10, b:1.234}),
"~{a: 10, b: 1.234}");
"~repr::P{a: 10, b: 1.234}");
exact_test(&(10u8, ~"hello"),
"(10u8, ~\"hello\")");
exact_test(&(10u16, ~"hello"),
Expand All @@ -643,5 +654,5 @@ fn test_repr() {
"(10u64, ~\"hello\")");

struct Foo;
exact_test(&(~[Foo, Foo, Foo]), "~[{}, {}, {}]");
exact_test(&(~[Foo, Foo]), "~[repr::test_repr::Foo, repr::test_repr::Foo]");
}
4 changes: 2 additions & 2 deletions src/libstd/unstable/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ pub trait TyVisitor {
fn visit_leave_rec(&mut self, n_fields: uint,
sz: uint, align: uint) -> bool;

fn visit_enter_class(&mut self, n_fields: uint,
fn visit_enter_class(&mut self, name: &str, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_class_field(&mut self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool;
fn visit_leave_class(&mut self, n_fields: uint,
fn visit_leave_class(&mut self, name: &str, n_fields: uint,
sz: uint, align: uint) -> bool;

fn visit_enter_tup(&mut self, n_fields: uint,
Expand Down
6 changes: 4 additions & 2 deletions src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3681,10 +3681,12 @@ mod tests {
assert_eq!(cnt, 11);

let xs = ~[Foo, Foo, Foo];
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()), ~"~[{}, {}]");
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()),
~"~[vec::tests::Foo, vec::tests::Foo]");

let xs: [Foo, ..3] = [Foo, Foo, Foo];
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()), ~"~[{}, {}]");
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()),
~"~[vec::tests::Foo, vec::tests::Foo]");
cnt = 0;
for f in xs.iter() {
assert!(*f == Foo);
Expand Down
4 changes: 3 additions & 1 deletion src/test/run-pass/fixed_length_vec_glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// xfail-fast: check-fast screws up repr paths

use std::sys;

struct Struc { a: u8, b: [int, ..3], c: int }
Expand All @@ -16,5 +18,5 @@ pub fn main() {
let arr = [1,2,3];
let struc = Struc {a: 13u8, b: arr, c: 42};
let s = sys::log_str(&struc);
assert_eq!(s, ~"{a: 13u8, b: [1, 2, 3], c: 42}");
assert_eq!(s, ~"Struc{a: 13u8, b: [1, 2, 3], c: 42}");
}
4 changes: 3 additions & 1 deletion src/test/run-pass/ifmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// xfail-fast: check-fast screws up repr paths

use std::fmt;

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

// Make sure there's a poly formatter that takes anything
t!(format!("{:?}", 1), "1");
t!(format!("{:?}", A), "{}");
t!(format!("{:?}", A), "A");
t!(format!("{:?}", ()), "()");
t!(format!("{:?}", @(~1, "foo")), "@(~1, \"foo\")");

Expand Down
4 changes: 3 additions & 1 deletion src/test/run-pass/rec-align-u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// xfail-fast: check-fast screws up repr paths

// Issue #2303

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

assert_eq!(y, ~"{c8: 22u8, t: {c64: 44u32}}");
assert_eq!(y, ~"Outer{c8: 22u8, t: Inner{c64: 44u32}}");
}
}
4 changes: 3 additions & 1 deletion src/test/run-pass/rec-align-u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// xfail-fast: check-fast screws up repr paths

// Issue #2303

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

assert_eq!(y, ~"{c8: 22u8, t: {c64: 44u64}}");
assert_eq!(y, ~"Outer{c8: 22u8, t: Inner{c64: 44u64}}");
}
}
12 changes: 6 additions & 6 deletions src/test/run-pass/reflect-visit-data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
true
}

fn visit_enter_class(&mut self, n_fields: uint, sz: uint, align: uint)
fn visit_enter_class(&mut self, name: &str, n_fields: uint, sz: uint, align: uint)
-> bool {
self.align(align);
if ! self.inner.visit_enter_class(n_fields, sz, align) {
if ! self.inner.visit_enter_class(name, n_fields, sz, align) {
return false;
}
true
Expand All @@ -335,9 +335,9 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
true
}

fn visit_leave_class(&mut self, n_fields: uint, sz: uint, align: uint)
fn visit_leave_class(&mut self, name: &str, n_fields: uint, sz: uint, align: uint)
-> bool {
if ! self.inner.visit_leave_class(n_fields, sz, align) {
if ! self.inner.visit_leave_class(name, n_fields, sz, align) {
return false;
}
true
Expand Down Expand Up @@ -566,13 +566,13 @@ impl TyVisitor for my_visitor {
fn visit_leave_rec(&mut self, _n_fields: uint,
_sz: uint, _align: uint) -> bool { true }

fn visit_enter_class(&mut self, _n_fields: uint,
fn visit_enter_class(&mut self, _name: &str, _n_fields: uint,
_sz: uint, _align: uint) -> bool { true }
fn visit_class_field(&mut self, _i: uint, _name: &str,
_mtbl: uint, inner: *TyDesc) -> bool {
self.visit_inner(inner)
}
fn visit_leave_class(&mut self, _n_fields: uint,
fn visit_leave_class(&mut self, _name: &str, _n_fields: uint,
_sz: uint, _align: uint) -> bool { true }

fn visit_enter_tup(&mut self, _n_fields: uint,
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/reflect-visit-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ impl TyVisitor for MyVisitor {
fn visit_leave_rec(&mut self, _n_fields: uint,
_sz: uint, _align: uint) -> bool { true }

fn visit_enter_class(&mut self, _n_fields: uint,
fn visit_enter_class(&mut self, _name: &str, _n_fields: uint,
_sz: uint, _align: uint) -> bool { true }
fn visit_class_field(&mut self, _i: uint, _name: &str,
_mtbl: uint, _inner: *TyDesc) -> bool { true }
fn visit_leave_class(&mut self, _n_fields: uint,
fn visit_leave_class(&mut self, _name: &str, _n_fields: uint,
_sz: uint, _align: uint) -> bool { true }

fn visit_enter_tup(&mut self, _n_fields: uint,
Expand Down
4 changes: 3 additions & 1 deletion src/test/run-pass/tag-align-shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// xfail-fast: check-fast screws up repr paths

enum a_tag {
a_tag(u64)
}
Expand All @@ -21,5 +23,5 @@ pub fn main() {
let x = t_rec {c8: 22u8, t: a_tag(44u64)};
let y = fmt!("%?", x);
info!("y = %s", y);
assert_eq!(y, ~"{c8: 22u8, t: a_tag(44u64)}");
assert_eq!(y, ~"t_rec{c8: 22u8, t: a_tag(44u64)}");
}