Skip to content

Commit aecca68

Browse files
committed
---
yaml --- r: 12628 b: refs/heads/master c: 5a0c564 h: refs/heads/master v: v3
1 parent e4b4401 commit aecca68

File tree

5 files changed

+96
-181
lines changed

5 files changed

+96
-181
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: b88ecec08c9998c08ef8fafe5ac49c17bc99c516
2+
refs/heads/master: 5a0c564817508604fcb738e15966f2d279139d8c
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustc/middle/trans/base.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,8 +2243,7 @@ fn trans_var(cx: block, def: ast::def, id: ast::node_id)-> lval_maybe_callee {
22432243
// Nullary variant.
22442244
let enum_ty = node_id_type(cx, id);
22452245
let llenumblob = alloc_ty(cx, enum_ty);
2246-
// FIXME: This pointer cast probably isn't necessary
2247-
let llenumty = type_of(ccx, enum_ty);
2246+
let llenumty = type_of_enum(ccx, tid, enum_ty);
22482247
let llenumptr = PointerCast(cx, llenumblob, T_ptr(llenumty));
22492248
let lldiscrimptr = GEPi(cx, llenumptr, [0, 0]);
22502249
let lldiscrim_gv = lookup_discriminant(ccx, vid);

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

Lines changed: 75 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ import std::map::hashmap;
77

88
import ty::*;
99

10-
export type_of;
11-
export type_of_explicit_args;
12-
export type_of_fn_from_ty;
13-
export type_of_fn;
14-
1510
fn type_of_explicit_args(cx: @crate_ctxt, inputs: [ty::arg]) -> [TypeRef] {
1611
vec::map(inputs) {|arg|
1712
let arg_ty = arg.ty;
@@ -44,149 +39,93 @@ fn type_of_fn_from_ty(cx: @crate_ctxt, fty: ty::t) -> TypeRef {
4439

4540
fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
4641
assert !ty::type_has_vars(t);
47-
48-
#debug("type_of %?: %?", t, ty::get(t));
49-
5042
// Check the cache.
51-
if cx.lltypes.contains_key(t) { ret cx.lltypes.get(t); }
5243

53-
// Replace any typedef'd types with their equivalent non-typedef
54-
// type. This ensures that all LLVM nominal types that contain
55-
// Rust types are defined as the same LLVM types. If we don't do
56-
// this then, e.g. `option<{myfield: bool}>` would be a different
57-
// type than `option<myrec>`.
58-
let t_norm = ty::normalize_ty(cx.tcx, t);
59-
let llty = if t != t_norm {
60-
type_of(cx, t_norm)
61-
} else {
62-
alt ty::get(t).struct {
63-
ty::ty_nil | ty::ty_bot { T_nil() }
64-
ty::ty_bool { T_bool() }
65-
ty::ty_int(t) { T_int_ty(cx, t) }
66-
ty::ty_uint(t) { T_uint_ty(cx, t) }
67-
ty::ty_float(t) { T_float_ty(cx, t) }
68-
ty::ty_estr(ty::vstore_uniq) |
69-
ty::ty_str { T_ptr(T_vec(cx, T_i8())) }
70-
ty::ty_enum(did, _) { type_of_enum(cx, did, t) }
71-
ty::ty_estr(ty::vstore_box) { T_ptr(T_box(cx, T_i8())) }
72-
ty::ty_evec(mt, ty::vstore_box) |
73-
ty::ty_box(mt) { T_ptr(T_box(cx, type_of(cx, mt.ty))) }
74-
ty::ty_opaque_box { T_ptr(T_box(cx, T_i8())) }
75-
ty::ty_uniq(mt) { T_ptr(type_of(cx, mt.ty)) }
76-
ty::ty_evec(mt, ty::vstore_uniq) |
77-
ty::ty_vec(mt) { T_ptr(T_vec(cx, type_of(cx, mt.ty))) }
78-
ty::ty_ptr(mt) { T_ptr(type_of(cx, mt.ty)) }
79-
ty::ty_rptr(_, mt) { T_ptr(type_of(cx, mt.ty)) }
80-
81-
ty::ty_evec(mt, ty::vstore_slice(_)) {
82-
T_struct([T_ptr(type_of(cx, mt.ty)),
83-
T_uint_ty(cx, ast::ty_u)])
84-
}
44+
if cx.lltypes.contains_key(t) { ret cx.lltypes.get(t); }
45+
let llty = alt ty::get(t).struct {
46+
ty::ty_nil | ty::ty_bot { T_nil() }
47+
ty::ty_bool { T_bool() }
48+
ty::ty_int(t) { T_int_ty(cx, t) }
49+
ty::ty_uint(t) { T_uint_ty(cx, t) }
50+
ty::ty_float(t) { T_float_ty(cx, t) }
51+
ty::ty_estr(ty::vstore_uniq) |
52+
ty::ty_str { T_ptr(T_vec(cx, T_i8())) }
53+
ty::ty_enum(did, _) { type_of_enum(cx, did, t) }
54+
ty::ty_estr(ty::vstore_box) { T_ptr(T_box(cx, T_i8())) }
55+
ty::ty_evec(mt, ty::vstore_box) |
56+
ty::ty_box(mt) { T_ptr(T_box(cx, type_of(cx, mt.ty))) }
57+
ty::ty_opaque_box { T_ptr(T_box(cx, T_i8())) }
58+
ty::ty_uniq(mt) { T_ptr(type_of(cx, mt.ty)) }
59+
ty::ty_evec(mt, ty::vstore_uniq) |
60+
ty::ty_vec(mt) { T_ptr(T_vec(cx, type_of(cx, mt.ty))) }
61+
ty::ty_ptr(mt) { T_ptr(type_of(cx, mt.ty)) }
62+
ty::ty_rptr(_, mt) { T_ptr(type_of(cx, mt.ty)) }
63+
64+
ty::ty_evec(mt, ty::vstore_slice(_)) {
65+
T_struct([T_ptr(type_of(cx, mt.ty)),
66+
T_uint_ty(cx, ast::ty_u)])
67+
}
8568

86-
ty::ty_estr(ty::vstore_slice(_)) {
87-
T_struct([T_ptr(T_i8()),
88-
T_uint_ty(cx, ast::ty_u)])
89-
}
69+
ty::ty_estr(ty::vstore_slice(_)) {
70+
T_struct([T_ptr(T_i8()),
71+
T_uint_ty(cx, ast::ty_u)])
72+
}
9073

91-
ty::ty_estr(ty::vstore_fixed(n)) {
92-
T_array(T_i8(), n + 1u /* +1 for trailing null */)
93-
}
74+
ty::ty_estr(ty::vstore_fixed(n)) {
75+
T_array(T_i8(), n + 1u /* +1 for trailing null */)
76+
}
9477

95-
ty::ty_evec(mt, ty::vstore_fixed(n)) {
96-
T_array(type_of(cx, mt.ty), n)
97-
}
78+
ty::ty_evec(mt, ty::vstore_fixed(n)) {
79+
T_array(type_of(cx, mt.ty), n)
80+
}
9881

99-
ty::ty_rec(fields) {
100-
let mut tys: [TypeRef] = [];
101-
for vec::each(fields) {|f|
102-
let mt_ty = f.mt.ty;
103-
tys += [type_of(cx, mt_ty)];
104-
}
105-
T_struct(tys)
106-
}
107-
ty::ty_fn(_) { T_fn_pair(cx, type_of_fn_from_ty(cx, t)) }
108-
ty::ty_iface(_, _) { T_opaque_iface(cx) }
109-
ty::ty_res(_, sub, substs) {
110-
let sub1 = ty::subst(cx.tcx, substs, sub);
111-
ret T_struct([T_i8(), type_of(cx, sub1)]);
112-
}
113-
ty::ty_param(_, _) { T_typaram(cx.tn) }
114-
ty::ty_type { T_ptr(cx.tydesc_type) }
115-
ty::ty_tup(elts) {
116-
let mut tys = [];
117-
for vec::each(elts) {|elt|
118-
tys += [type_of(cx, elt)];
119-
}
120-
T_struct(tys)
121-
}
122-
ty::ty_opaque_closure_ptr(_) { T_opaque_box_ptr(cx) }
123-
ty::ty_constr(subt,_) { type_of(cx, subt) }
124-
ty::ty_class(did, ts) {
125-
// only instance vars are record fields at runtime
126-
let fields = lookup_class_fields(cx.tcx, did);
127-
let tys = vec::map(fields) {|f|
128-
let t = ty::lookup_field_type(cx.tcx, did, f.id, ts);
129-
type_of(cx, t)
130-
};
131-
T_struct(tys)
132-
}
133-
ty::ty_self(_) { cx.tcx.sess.unimpl("type_of: ty_self \
134-
not implemented"); }
135-
ty::ty_var(_) { cx.tcx.sess.bug("type_of shouldn't see a ty_var"); }
82+
ty::ty_rec(fields) {
83+
let mut tys: [TypeRef] = [];
84+
for vec::each(fields) {|f|
85+
let mt_ty = f.mt.ty;
86+
tys += [type_of(cx, mt_ty)];
13687
}
88+
T_struct(tys)
89+
}
90+
ty::ty_fn(_) { T_fn_pair(cx, type_of_fn_from_ty(cx, t)) }
91+
ty::ty_iface(_, _) { T_opaque_iface(cx) }
92+
ty::ty_res(_, sub, substs) {
93+
let sub1 = ty::subst(cx.tcx, substs, sub);
94+
ret T_struct([T_i8(), type_of(cx, sub1)]);
95+
}
96+
ty::ty_param(_, _) { T_typaram(cx.tn) }
97+
ty::ty_type { T_ptr(cx.tydesc_type) }
98+
ty::ty_tup(elts) {
99+
let mut tys = [];
100+
for vec::each(elts) {|elt|
101+
tys += [type_of(cx, elt)];
102+
}
103+
T_struct(tys)
104+
}
105+
ty::ty_opaque_closure_ptr(_) { T_opaque_box_ptr(cx) }
106+
ty::ty_constr(subt,_) { type_of(cx, subt) }
107+
ty::ty_class(did, ts) {
108+
// only instance vars are record fields at runtime
109+
let fields = lookup_class_fields(cx.tcx, did);
110+
let tys = vec::map(fields) {|f|
111+
let t = ty::lookup_field_type(cx.tcx, did, f.id, ts);
112+
type_of(cx, t)
113+
};
114+
T_struct(tys)
115+
}
116+
ty::ty_self(_) { cx.tcx.sess.unimpl("type_of: ty_self \
117+
not implemented"); }
118+
ty::ty_var(_) { cx.tcx.sess.bug("type_of shouldn't see a ty_var"); }
137119
};
138120
cx.lltypes.insert(t, llty);
139121
ret llty;
140122
}
141123

142-
// This should only be called from type_of, above, because it
143-
// creates new llvm named struct types lazily that are then
144-
// cached by type_of
145124
fn type_of_enum(cx: @crate_ctxt, did: ast::def_id, t: ty::t)
146125
-> TypeRef {
147-
148-
#debug("type_of_enum %?: %?", t, ty::get(t));
149-
150-
// Every enum type has a unique name. When we find our roots
151-
// for GC and unwinding we will use this name to rediscover
152-
// the Rust type
153-
let name = llvm_type_name(cx, t);
154-
155-
let named_llty = common::T_named_struct(name);
156-
157-
let lltys = {
158-
let degen = (*ty::enum_variants(cx.tcx, did)).len() == 1u;
159-
let size = shape::static_size_of_enum(cx, t);
160-
if !degen {
161-
[T_enum_variant(cx), T_array(T_i8(), size)]
162-
}
163-
else if size == 0u {
164-
[T_enum_variant(cx)]
165-
}
166-
else {
167-
[T_array(T_i8(), size)]
168-
}
169-
};
170-
171-
common::set_struct_body(named_llty, lltys);
172-
ret named_llty;
126+
let degen = (*ty::enum_variants(cx.tcx, did)).len() == 1u;
127+
let size = shape::static_size_of_enum(cx, t);
128+
if !degen { T_enum(cx, size) }
129+
else if size == 0u { T_struct([T_enum_variant(cx)]) }
130+
else { T_array(T_i8(), size) }
173131
}
174-
175-
fn llvm_type_name(cx: @crate_ctxt, t: ty::t) -> str {
176-
let (name, did, tps) = alt check ty::get(t).struct {
177-
ty::ty_enum(did, substs) {
178-
("enum", did, substs.tps)
179-
}
180-
};
181-
ret #fmt(
182-
"%s %s[#%d]",
183-
name,
184-
util::ppaux::parameterized(
185-
cx.tcx,
186-
ty::item_path_str(cx.tcx, did),
187-
none,
188-
tps),
189-
did.crate
190-
);
191-
}
192-

trunk/src/rustc/middle/ty.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ export ast_ty_to_ty_cache_entry;
149149
export atttce_unresolved, atttce_resolved;
150150
export mach_sty;
151151
export ty_sort_str;
152-
export normalize_ty;
153152

154153
// Data types
155154

@@ -2675,27 +2674,6 @@ fn ty_params_to_tys(tcx: ty::ctxt, tps: [ast::ty_param]) -> [t] {
26752674
ty::mk_param(tcx, i, ast_util::local_def(tps[i].id))
26762675
})
26772676
}
2678-
2679-
#[doc = "
2680-
Returns an equivalent type with all the typedefs and self regions removed
2681-
"]
2682-
fn normalize_ty(cx: ctxt, t: t) -> t {
2683-
let t = alt get(t).struct {
2684-
ty_enum(did, r) {
2685-
alt r.self_r {
2686-
some(_) {
2687-
// This enum has a self region. Get rid of it
2688-
mk_enum(cx, did, {self_r: none, tps: r.tps })
2689-
}
2690-
none { t }
2691-
}
2692-
}
2693-
_ { t }
2694-
};
2695-
let sty = fold_sty(get(t).struct) {|t| normalize_ty(cx, t) };
2696-
mk_t(cx, sty)
2697-
}
2698-
26992677
// Local Variables:
27002678
// mode: rust
27012679
// fill-column: 78;

trunk/src/rustc/util/ppaux.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,25 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
128128
fn field_to_str(cx: ctxt, f: field) -> str {
129129
ret f.ident + ": " + mt_to_str(cx, f.mt);
130130
}
131+
fn parameterized(cx: ctxt,
132+
base: str,
133+
self_r: option<ty::region>,
134+
tps: [ty::t]) -> str {
135+
136+
let r_str = alt self_r {
137+
none { "" }
138+
some(r) {
139+
#fmt["/%s", region_to_str(cx, r)]
140+
}
141+
};
142+
143+
if vec::len(tps) > 0u {
144+
let strs = vec::map(tps, {|t| ty_to_str(cx, t)});
145+
#fmt["%s%s<%s>", base, r_str, str::connect(strs, ",")]
146+
} else {
147+
#fmt["%s%s", base, r_str]
148+
}
149+
}
131150

132151
// if there is an id, print that instead of the structural type:
133152
alt ty::type_def_id(typ) {
@@ -214,26 +233,6 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
214233
}
215234
}
216235

217-
fn parameterized(cx: ctxt,
218-
base: str,
219-
self_r: option<ty::region>,
220-
tps: [ty::t]) -> str {
221-
222-
let r_str = alt self_r {
223-
none { "" }
224-
some(r) {
225-
#fmt["/%s", region_to_str(cx, r)]
226-
}
227-
};
228-
229-
if vec::len(tps) > 0u {
230-
let strs = vec::map(tps, {|t| ty_to_str(cx, t)});
231-
#fmt["%s%s<%s>", base, r_str, str::connect(strs, ",")]
232-
} else {
233-
#fmt["%s%s", base, r_str]
234-
}
235-
}
236-
237236
fn ty_to_short_str(cx: ctxt, typ: t) -> str {
238237
let mut s = encoder::encoded_ty(cx, typ);
239238
if str::len(s) >= 32u { s = str::slice(s, 0u, 32u); }

0 commit comments

Comments
 (0)