Skip to content

Commit b8f21e1

Browse files
---
yaml --- r: 69086 b: refs/heads/auto c: 3b06df4 h: refs/heads/master v: v3
1 parent 766f44e commit b8f21e1

File tree

8 files changed

+162
-77
lines changed

8 files changed

+162
-77
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: 7cf0aac6cf2435e068c4bd62cd34e06f8ef0bd91
17+
refs/heads/auto: 3b06df4e35bbde6975575cd137e6f5f65d475d86
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/src/librustc/metadata/decoder.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -753,11 +753,16 @@ pub fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id,
753753
Some(val) => { disr_val = val; }
754754
_ => { /* empty */ }
755755
}
756-
infos.push(@ty::VariantInfo_{args: arg_tys,
757-
ctor_ty: ctor_ty, name: name,
758-
// I'm not even sure if we encode visibility
759-
// for variants -- TEST -- tjc
760-
id: *did, disr_val: disr_val, vis: ast::inherited});
756+
infos.push(@ty::VariantInfo_{
757+
args: arg_tys,
758+
arg_names: None,
759+
ctor_ty: ctor_ty,
760+
name: name,
761+
// I'm not even sure if we encode visibility
762+
// for variants -- TEST -- tjc
763+
id: *did,
764+
disr_val: disr_val,
765+
vis: ast::inherited});
761766
disr_val += 1;
762767
}
763768
return infos;

branches/auto/src/librustc/middle/trans/debuginfo.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,13 @@ fn create_enum_md(cx: &mut CrateContext,
612612

613613
let raw_types : &[ty::t] = vi.args;
614614
let arg_types = do raw_types.map |&raw_type| { ty::subst(cx.tcx, substs, raw_type) };
615-
615+
616616
let mut arg_llvm_types = do arg_types.map |&ty| { type_of::type_of(cx, ty) };
617-
let mut arg_names = arg_types.map(|_| ~"");
617+
let mut arg_names = match vi.arg_names {
618+
Some(ref names) => do names.map |ident| { cx.sess.str_of(*ident).to_owned() },
619+
None => do arg_types.map |_| { ~"" }
620+
};
621+
618622
let mut arg_md = do arg_types.map |&ty| { get_or_create_type(cx, ty, span) };
619623

620624
if !is_univariant {

branches/auto/src/librustc/middle/trans/machine.rs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -119,42 +119,3 @@ pub fn llelement_offset(cx: &CrateContext, struct_ty: Type, element: uint) -> ui
119119
return llvm::LLVMOffsetOfElement(cx.td.lltd, struct_ty.to_ref(), element as u32) as uint;
120120
}
121121
}
122-
123-
// Computes the size of the data part of an enum.
124-
pub fn static_size_of_enum(cx: &mut CrateContext, t: ty::t) -> uint {
125-
if cx.enum_sizes.contains_key(&t) {
126-
return cx.enum_sizes.get_copy(&t);
127-
}
128-
129-
debug!("static_size_of_enum %s", ty_to_str(cx.tcx, t));
130-
131-
match ty::get(t).sty {
132-
ty::ty_enum(tid, ref substs) => {
133-
// Compute max(variant sizes).
134-
let mut max_size = 0;
135-
let variants = ty::enum_variants(cx.tcx, tid);
136-
for variants.iter().advance |variant| {
137-
if variant.args.len() == 0 {
138-
loop;
139-
}
140-
141-
let lltypes = variant.args.map(|&variant_arg| {
142-
let substituted = ty::subst(cx.tcx, substs, variant_arg);
143-
type_of::sizing_type_of(cx, substituted)
144-
});
145-
146-
debug!("static_size_of_enum: variant %s type %s",
147-
cx.tcx.sess.str_of(variant.name),
148-
cx.tn.type_to_str(Type::struct_(lltypes, false)));
149-
150-
let this_size = llsize_of_real(cx, Type::struct_(lltypes, false));
151-
if max_size < this_size {
152-
max_size = this_size;
153-
}
154-
}
155-
cx.enum_sizes.insert(t, max_size);
156-
return max_size;
157-
}
158-
_ => cx.sess.bug("static_size_of_enum called on non-enum")
159-
}
160-
}

branches/auto/src/librustc/middle/ty.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3694,6 +3694,7 @@ fn struct_ctor_id(cx: ctxt, struct_did: ast::def_id) -> Option<ast::def_id> {
36943694
#[deriving(Clone)]
36953695
pub struct VariantInfo_ {
36963696
args: ~[t],
3697+
arg_names: Option<~[ast::ident]>,
36973698
ctor_ty: t,
36983699
name: ast::ident,
36993700
id: ast::def_id,
@@ -3875,6 +3876,7 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
38753876
}
38763877
@VariantInfo_{
38773878
args: arg_tys,
3879+
arg_names: None,
38783880
ctor_ty: ctor_ty,
38793881
name: variant.node.name,
38803882
id: ast_util::local_def(variant.node.id),
@@ -3883,20 +3885,29 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
38833885
}
38843886
},
38853887
ast::struct_variant_kind(struct_def) => {
3886-
let arg_tys =
3887-
// Is this check needed for structs too, or are they always guaranteed
3888-
// to have a valid constructor function?
3889-
if struct_def.fields.len() > 0 {
3890-
ty_fn_args(ctor_ty).map(|a| *a)
3888+
3889+
let fields : &[@struct_field] = struct_def.fields;
3890+
3891+
let (arg_tys, arg_names) =
3892+
if fields.len() > 0 {
3893+
let arg_tys = ty_fn_args(ctor_ty).map(|a| *a);
3894+
let arg_names = do fields.map |field| { match field.node.kind {
3895+
named_field(ident, _visibility) => ident,
3896+
unnamed_field => cx.sess.bug(
3897+
"enum_variants: all fields in struct must have a name")
3898+
}};
3899+
3900+
(arg_tys, Some(arg_names))
38913901
} else {
3892-
~[]
3902+
(~[], None)
38933903
};
38943904

38953905
assert!(variant.node.disr_expr.is_none());
38963906
disr_val += 1;
38973907

38983908
@VariantInfo_{
38993909
args: arg_tys,
3910+
arg_names: arg_names,
39003911
ctor_ty: ctor_ty,
39013912
name: variant.node.name,
39023913
id: ast_util::local_def(variant.node.id),

branches/auto/src/librustc/middle/typeck/check/mod.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3177,29 +3177,34 @@ pub fn check_enum_variants(ccx: @mut CrateCtxt,
31773177
let this_disr_val = *disr_val;
31783178
*disr_val += 1;
31793179

3180-
let arg_tys = match v.node.kind {
3180+
let (arg_tys, arg_names) = match v.node.kind {
31813181
ast::tuple_variant_kind(ref args) if args.len() > 0u => {
3182-
Some(ty::ty_fn_args(ctor_ty).map(|a| *a))
3182+
(ty::ty_fn_args(ctor_ty).map(|a| *a), None)
31833183
}
31843184
ast::tuple_variant_kind(_) => {
3185-
Some(~[])
3185+
(~[], None)
31863186
}
3187-
ast::struct_variant_kind(_) => {
3188-
Some(ty::lookup_struct_fields(
3189-
ccx.tcx, local_def(v.node.id)).map(|cf|
3190-
ty::node_id_to_type(ccx.tcx, cf.id.node)))
3187+
ast::struct_variant_kind(struct_def) => {
3188+
let tys = ty::ty_fn_args(ctor_ty).map(|a| *a);
3189+
let names = do struct_def.fields.map |field| { match field.node.kind {
3190+
ast::named_field(ident, _visibility) => ident,
3191+
ast::unnamed_field => ccx.tcx.sess.bug(
3192+
"enum_variants: all fields in struct must have a name")
3193+
}};
3194+
3195+
(tys, Some(names))
31913196
}
31923197
};
31933198

3194-
match arg_tys {
3195-
None => {}
3196-
Some(arg_tys) => {
3197-
variants.push(
3198-
@VariantInfo_{args: arg_tys, ctor_ty: ctor_ty,
3199-
name: v.node.name, id: local_def(v.node.id),
3200-
disr_val: this_disr_val, vis: v.node.vis});
3201-
}
3202-
}
3199+
variants.push(@VariantInfo_{
3200+
args: arg_tys,
3201+
arg_names: arg_names,
3202+
ctor_ty: ctor_ty,
3203+
name: v.node.name,
3204+
id: local_def(v.node.id),
3205+
disr_val: this_disr_val,
3206+
vis: v.node.vis
3207+
});
32033208
}
32043209
}
32053210

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:-Z extra-debug-info
12+
// debugger:set print union on
13+
// debugger:break zzz
14+
// debugger:run
15+
// debugger:finish
16+
17+
// debugger:print case1
18+
// check:$1 = {{Case1, a = 0, b = 31868, c = 31868, d = 31868, e = 31868}, {Case1, a = 0, b = 2088533116, c = 2088533116}, {Case1, a = 0, b = 8970181431921507452}}
19+
20+
// debugger:print case2
21+
// check:$2 = {{Case2, a = 0, b = 4369, c = 4369, d = 4369, e = 4369}, {Case2, a = 0, b = 286331153, c = 286331153}, {Case2, a = 0, b = 1229782938247303441}}
22+
23+
// debugger:print case3
24+
// check:$3 = {{Case3, a = 0, b = 22873, c = 22873, d = 22873, e = 22873}, {Case3, a = 0, b = 1499027801, c = 1499027801}, {Case3, a = 0, b = 6438275382588823897}}
25+
26+
// debugger:print univariant
27+
// check:$4 = {{a = -1}}
28+
29+
// The first element is to ensure proper alignment, irrespective of the machines word size. Since
30+
// the size of the discriminant value is machine dependent, this has be taken into account when
31+
// datatype layout should be predictable as in this case.
32+
enum Regular {
33+
Case1 { a: u64, b: u16, c: u16, d: u16, e: u16},
34+
Case2 { a: u64, b: u32, c: u32},
35+
Case3 { a: u64, b: u64 }
36+
}
37+
38+
enum Univariant {
39+
TheOnlyCase { a: i64 }
40+
}
41+
42+
fn main() {
43+
44+
// In order to avoid endianess trouble all of the following test values consist of a single
45+
// repeated byte. This way each interpretation of the union should look the same, no matter if
46+
// this is a big or little endian machine.
47+
48+
// 0b0111110001111100011111000111110001111100011111000111110001111100 = 8970181431921507452
49+
// 0b01111100011111000111110001111100 = 2088533116
50+
// 0b0111110001111100 = 31868
51+
// 0b01111100 = 124
52+
let case1 = Case1 { a: 0, b: 31868, c: 31868, d: 31868, e: 31868 };
53+
54+
// 0b0001000100010001000100010001000100010001000100010001000100010001 = 1229782938247303441
55+
// 0b00010001000100010001000100010001 = 286331153
56+
// 0b0001000100010001 = 4369
57+
// 0b00010001 = 17
58+
let case2 = Case2 { a: 0, b: 286331153, c: 286331153 };
59+
60+
// 0b0101100101011001010110010101100101011001010110010101100101011001 = 6438275382588823897
61+
// 0b01011001010110010101100101011001 = 1499027801
62+
// 0b0101100101011001 = 22873
63+
// 0b01011001 = 89
64+
let case3 = Case3 { a: 0, b: 6438275382588823897 };
65+
66+
let univariant = TheOnlyCase { a: -1 };
67+
68+
zzz();
69+
}
70+
71+
fn zzz() {()}

branches/auto/src/test/debug-info/tuple-style-enum.rs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,25 @@
1414
// debugger:run
1515
// debugger:finish
1616

17-
// d ebugger:print case2
18-
// c heck:$1 = {Case1, 0, 1}
17+
// debugger:print case1
18+
// check:$1 = {{Case1, 0, 31868, 31868, 31868, 31868}, {Case1, 0, 2088533116, 2088533116}, {Case1, 0, 8970181431921507452}}
1919

20-
// debugger:print univariant
21-
// check:$1 = {{-1}}
20+
// debugger:print case2
21+
// check:$2 = {{Case2, 0, 4369, 4369, 4369, 4369}, {Case2, 0, 286331153, 286331153}, {Case2, 0, 1229782938247303441}}
22+
23+
// debugger:print case3
24+
// check:$3 = {{Case3, 0, 22873, 22873, 22873, 22873}, {Case3, 0, 1499027801, 1499027801}, {Case3, 0, 6438275382588823897}}
2225

26+
// debugger:print univariant
27+
// check:$4 = {{-1}}
2328

29+
// The first element is to ensure proper alignment, irrespective of the machines word size. Since
30+
// the size of the discriminant value is machine dependent, this has be taken into account when
31+
// datatype layout should be predictable as in this case.
2432
enum Regular {
25-
Case1(i32, i64),
26-
Case2(bool, i16, i32)
33+
Case1(u64, u16, u16, u16, u16),
34+
Case2(u64, u32, u32),
35+
Case3(u64, u64)
2736
}
2837

2938
enum Univariant {
@@ -32,8 +41,27 @@ enum Univariant {
3241

3342
fn main() {
3443

35-
let case1 = Case1(110, 220);
36-
let case2 = Case2(false, 2, 3);
44+
// In order to avoid endianess trouble all of the following test values consist of a single
45+
// repeated byte. This way each interpretation of the union should look the same, no matter if
46+
// this is a big or little endian machine.
47+
48+
// 0b0111110001111100011111000111110001111100011111000111110001111100 = 8970181431921507452
49+
// 0b01111100011111000111110001111100 = 2088533116
50+
// 0b0111110001111100 = 31868
51+
// 0b01111100 = 124
52+
let case1 = Case1(0, 31868, 31868, 31868, 31868);
53+
54+
// 0b0001000100010001000100010001000100010001000100010001000100010001 = 1229782938247303441
55+
// 0b00010001000100010001000100010001 = 286331153
56+
// 0b0001000100010001 = 4369
57+
// 0b00010001 = 17
58+
let case2 = Case2(0, 286331153, 286331153);
59+
60+
// 0b0101100101011001010110010101100101011001010110010101100101011001 = 6438275382588823897
61+
// 0b01011001010110010101100101011001 = 1499027801
62+
// 0b0101100101011001 = 22873
63+
// 0b01011001 = 89
64+
let case3 = Case3(0, 6438275382588823897);
3765

3866
let univariant = TheOnlyCase(-1);
3967

0 commit comments

Comments
 (0)