Skip to content

Commit fa19cf7

Browse files
committed
---
yaml --- r: 45009 b: refs/heads/master c: 5e2302a h: refs/heads/master i: 45007: 8222f9f v: v3
1 parent 8150eb8 commit fa19cf7

File tree

2 files changed

+12
-89
lines changed

2 files changed

+12
-89
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: c4682dcabedaa5451d377aedfb9167f4f299e5e5
2+
refs/heads/master: 5e2302a56f7615b73e42daaa242da4bd64b25d93
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d9689399d091c3265f00434a69c551a61c28dc
55
refs/heads/try: ef355f6332f83371e4acf04fc4eb940ab41d78d3

trunk/src/librustc/middle/trans/type_of.rs

Lines changed: 11 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use lib::llvm::llvm;
1313
use lib::llvm::{TypeRef};
14+
use middle::trans::adt;
1415
use middle::trans::base;
1516
use middle::trans::common::*;
1617
use middle::trans::common;
@@ -143,32 +144,12 @@ pub fn sizing_type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
143144

144145
ty::ty_unboxed_vec(mt) => T_vec(cx, sizing_type_of(cx, mt.ty)),
145146

146-
ty::ty_tup(ref elems) => {
147-
T_struct(elems.map(|&t| sizing_type_of(cx, t)))
147+
ty::ty_tup(*) | ty::ty_rec(*) | ty::ty_struct(*)
148+
| ty::ty_enum(*) => {
149+
let repr = adt::represent_type(cx, t);
150+
T_struct(adt::sizing_fields_of(cx, &repr))
148151
}
149152

150-
ty::ty_rec(ref fields) => {
151-
T_struct(fields.map(|f| sizing_type_of(cx, f.mt.ty)))
152-
}
153-
154-
ty::ty_struct(def_id, ref substs) => {
155-
let fields = ty::lookup_struct_fields(cx.tcx, def_id);
156-
let lltype = T_struct(fields.map(|field| {
157-
let field_type = ty::lookup_field_type(cx.tcx,
158-
def_id,
159-
field.id,
160-
substs);
161-
sizing_type_of(cx, field_type)
162-
}));
163-
if ty::ty_dtor(cx.tcx, def_id).is_present() {
164-
T_struct(~[lltype, T_i8()])
165-
} else {
166-
lltype
167-
}
168-
}
169-
170-
ty::ty_enum(def_id, _) => T_struct(enum_body_types(cx, def_id, t)),
171-
172153
ty::ty_self | ty::ty_infer(*) | ty::ty_param(*) | ty::ty_err(*) => {
173154
cx.tcx.sess.bug(
174155
fmt!("fictitious type %? in sizing_type_of()",
@@ -257,28 +238,13 @@ pub fn type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
257238
T_array(type_of(cx, mt.ty), n)
258239
}
259240

260-
ty::ty_rec(fields) => {
261-
let mut tys: ~[TypeRef] = ~[];
262-
for vec::each(fields) |f| {
263-
let mt_ty = f.mt.ty;
264-
tys.push(type_of(cx, mt_ty));
265-
}
266-
267-
// n.b.: introduce an extra layer of indirection to match
268-
// structs
269-
T_struct(~[T_struct(tys)])
270-
}
271-
272241
ty::ty_bare_fn(_) => T_ptr(type_of_fn_from_ty(cx, t)),
273242
ty::ty_closure(_) => T_fn_pair(cx, type_of_fn_from_ty(cx, t)),
274243
ty::ty_trait(_, _, vstore) => T_opaque_trait(cx, vstore),
275244
ty::ty_type => T_ptr(cx.tydesc_type),
276-
ty::ty_tup(elts) => {
277-
let mut tys = ~[];
278-
for vec::each(elts) |elt| {
279-
tys.push(type_of(cx, *elt));
280-
}
281-
T_struct(tys)
245+
ty::ty_tup(*) | ty::ty_rec(*) => {
246+
let repr = adt::represent_type(cx, t);
247+
T_struct(adt::fields_of(cx, &repr))
282248
}
283249
ty::ty_opaque_closure_ptr(_) => T_opaque_box_ptr(cx),
284250
ty::ty_struct(did, ref substs) => {
@@ -301,59 +267,16 @@ pub fn type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
301267

302268
// If this was an enum or struct, fill in the type now.
303269
match ty::get(t).sty {
304-
ty::ty_enum(did, _) => {
305-
fill_type_of_enum(cx, did, t, llty);
306-
}
307-
ty::ty_struct(did, ref substs) => {
308-
// Only instance vars are record fields at runtime.
309-
let fields = ty::lookup_struct_fields(cx.tcx, did);
310-
let mut tys = do vec::map(fields) |f| {
311-
let t = ty::lookup_field_type(cx.tcx, did, f.id, substs);
312-
type_of(cx, t)
313-
};
314-
315-
// include a byte flag if there is a dtor so that we know when we've
316-
// been dropped
317-
if ty::ty_dtor(cx.tcx, did).is_present() {
318-
common::set_struct_body(llty, ~[T_struct(tys), T_i8()]);
319-
} else {
320-
common::set_struct_body(llty, ~[T_struct(tys)]);
321-
}
270+
ty::ty_enum(*) | ty::ty_struct(*) => {
271+
let repr = adt::represent_type(cx, t);
272+
common::set_struct_body(llty, adt::fields_of(cx, &repr));
322273
}
323274
_ => ()
324275
}
325276

326277
return llty;
327278
}
328279

329-
pub fn enum_body_types(cx: @CrateContext, did: ast::def_id, t: ty::t)
330-
-> ~[TypeRef] {
331-
let univar = ty::enum_is_univariant(cx.tcx, did);
332-
if !univar {
333-
let size = machine::static_size_of_enum(cx, t);
334-
~[T_enum_discrim(cx), T_array(T_i8(), size)]
335-
}
336-
else {
337-
// Use the actual fields, so we get the alignment right.
338-
match ty::get(t).sty {
339-
ty::ty_enum(_, ref substs) => {
340-
do ty::enum_variants(cx.tcx, did)[0].args.map |&field_ty| {
341-
sizing_type_of(cx, ty::subst(cx.tcx, substs, field_ty))
342-
}
343-
}
344-
_ => cx.sess.bug(~"enum is not an enum")
345-
}
346-
}
347-
}
348-
349-
pub fn fill_type_of_enum(cx: @CrateContext,
350-
did: ast::def_id,
351-
t: ty::t,
352-
llty: TypeRef) {
353-
debug!("type_of_enum %?: %?", t, ty::get(t));
354-
common::set_struct_body(llty, enum_body_types(cx, did, t));
355-
}
356-
357280
// Want refinements! (Or case classes, I guess
358281
pub enum named_ty { a_struct, an_enum }
359282

0 commit comments

Comments
 (0)