Skip to content

Commit 5c81a18

Browse files
committed
auto merge of #14869 : nick29581/rust/tstore, r=nmatsakis
Use ty_rptr/ty_uniq(ty_trait) rather than TraitStore to represent trait types. Also addresses (but doesn't close) #12470. Part of the work towards DST (#12938).
2 parents 1bb42e5 + 8e7213f commit 5c81a18

30 files changed

+451
-364
lines changed

src/librustc/metadata/tydecode.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,9 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
346346
assert_eq!(next(st), '[');
347347
let def = parse_def(st, NominalType, |x,y| conv(x,y));
348348
let substs = parse_substs(st, |x,y| conv(x,y));
349-
let store = parse_trait_store(st, |x,y| conv(x,y));
350349
let bounds = parse_bounds(st, |x,y| conv(x,y));
351350
assert_eq!(next(st), ']');
352-
return ty::mk_trait(st.tcx, def, substs, store, bounds.builtin_bounds);
351+
return ty::mk_trait(st.tcx, def, substs, bounds.builtin_bounds);
353352
}
354353
'p' => {
355354
let did = parse_def(st, TypeParameter, |x,y| conv(x,y));

src/librustc/metadata/tyencode.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,10 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
232232
ty::ty_trait(box ty::TyTrait {
233233
def_id,
234234
ref substs,
235-
store,
236235
bounds
237236
}) => {
238237
mywrite!(w, "x[{}|", (cx.ds)(def_id));
239238
enc_substs(w, cx, substs);
240-
enc_trait_store(w, cx, store);
241239
let bounds = ty::ParamBounds {builtin_bounds: bounds,
242240
trait_bounds: Vec::new()};
243241
enc_bounds(w, cx, &bounds);

src/librustc/middle/kind.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,12 @@ fn check_bounds_on_type_parameters(cx: &mut Context, e: &Expr) {
361361
fn check_trait_cast(cx: &mut Context, source_ty: ty::t, target_ty: ty::t, span: Span) {
362362
check_cast_for_escaping_regions(cx, source_ty, target_ty, span);
363363
match ty::get(target_ty).sty {
364-
ty::ty_trait(box ty::TyTrait { bounds, .. }) => {
365-
check_trait_cast_bounds(cx, span, source_ty, bounds);
366-
}
364+
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ ty, .. }) => match ty::get(ty).sty {
365+
ty::ty_trait(box ty::TyTrait { bounds, .. }) => {
366+
check_trait_cast_bounds(cx, span, source_ty, bounds);
367+
}
368+
_ => {}
369+
},
367370
_ => {}
368371
}
369372
}
@@ -530,9 +533,8 @@ pub fn check_cast_for_escaping_regions(
530533
{
531534
// Determine what type we are casting to; if it is not a trait, then no
532535
// worries.
533-
match ty::get(target_ty).sty {
534-
ty::ty_trait(..) => {}
535-
_ => { return; }
536+
if !ty::type_is_trait(target_ty) {
537+
return;
536538
}
537539

538540
// Collect up the regions that appear in the target type. We want to

src/librustc/middle/lint.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -980,9 +980,6 @@ fn check_heap_type(cx: &Context, span: Span, ty: ty::t) {
980980
n_box += 1;
981981
}
982982
ty::ty_uniq(_) |
983-
ty::ty_trait(box ty::TyTrait {
984-
store: ty::UniqTraitStore, ..
985-
}) |
986983
ty::ty_closure(box ty::ClosureTy {
987984
store: ty::UniqTraitStore,
988985
..

src/librustc/middle/mem_categorization.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ pub enum deref_kind {
174174
pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
175175
match ty::get(t).sty {
176176
ty::ty_uniq(_) |
177-
ty::ty_trait(box ty::TyTrait { store: ty::UniqTraitStore, .. }) |
178177
ty::ty_closure(box ty::ClosureTy {store: ty::UniqTraitStore, ..}) => {
179178
Some(deref_ptr(OwnedPtr))
180179
}
@@ -183,13 +182,6 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
183182
let kind = ty::BorrowKind::from_mutbl(mt.mutbl);
184183
Some(deref_ptr(BorrowedPtr(kind, r)))
185184
}
186-
ty::ty_trait(box ty::TyTrait {
187-
store: ty::RegionTraitStore(r, mutbl),
188-
..
189-
}) => {
190-
let kind = ty::BorrowKind::from_mutbl(mutbl);
191-
Some(deref_ptr(BorrowedPtr(kind, r)))
192-
}
193185

194186
ty::ty_closure(box ty::ClosureTy {
195187
store: ty::RegionTraitStore(r, _),

src/librustc/middle/trans/adt.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,11 @@ impl Case {
292292
fn find_ptr(&self) -> Option<uint> {
293293
self.tys.iter().position(|&ty| {
294294
match ty::get(ty).sty {
295-
ty::ty_rptr(_, mt) => match ty::get(mt.ty).sty {
296-
ty::ty_vec(_, None) | ty::ty_str => false,
295+
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty::get(ty).sty {
296+
ty::ty_vec(_, None) | ty::ty_str| ty::ty_trait(..) => false,
297297
_ => true,
298298
},
299-
ty::ty_uniq(..) | ty::ty_box(..) |
300-
ty::ty_bare_fn(..) => true,
299+
ty::ty_box(..) | ty::ty_bare_fn(..) => true,
301300
// Is that everything? Would closures or slices qualify?
302301
_ => false
303302
}

src/librustc/middle/trans/base.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,9 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6
17941794
match ty::get(ret_ty).sty {
17951795
// `~` pointer return values never alias because ownership
17961796
// is transferred
1797+
ty::ty_uniq(it) if match ty::get(it).sty {
1798+
ty::ty_str | ty::ty_vec(..) | ty::ty_trait(..) => true, _ => false
1799+
} => {}
17971800
ty::ty_uniq(_) => {
17981801
attrs.push((lib::llvm::ReturnIndex as uint, lib::llvm::NoAliasAttribute as u64));
17991802
}
@@ -1803,9 +1806,9 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6
18031806
// We can also mark the return value as `nonnull` in certain cases
18041807
match ty::get(ret_ty).sty {
18051808
// These are not really pointers but pairs, (pointer, len)
1806-
ty::ty_rptr(_, ty::mt { ty: it, .. }) |
1809+
ty::ty_uniq(it) |
18071810
ty::ty_rptr(_, ty::mt { ty: it, .. }) if match ty::get(it).sty {
1808-
ty::ty_str | ty::ty_vec(..) => true, _ => false
1811+
ty::ty_str | ty::ty_vec(..) | ty::ty_trait(..) => true, _ => false
18091812
} => {}
18101813
ty::ty_uniq(_) | ty::ty_rptr(_, _) => {
18111814
attrs.push((lib::llvm::ReturnIndex as uint, lib::llvm::NonNullAttribute as u64));

src/librustc/middle/trans/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn type_is_immediate(ccx: &CrateContext, ty: ty::t) -> bool {
6767
ty::type_is_unique(ty) || ty::type_is_region_ptr(ty) ||
6868
type_is_newtype_immediate(ccx, ty) || ty::type_is_bot(ty) ||
6969
ty::type_is_simd(tcx, ty);
70-
if simple {
70+
if simple && !ty::type_is_trait(ty) {
7171
return true;
7272
}
7373
match ty::get(ty).sty {

src/librustc/middle/trans/consts.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ fn const_deref(cx: &CrateContext, v: ValueRef, t: ty::t, explicit: bool)
143143
let dv = match ty::get(t).sty {
144144
ty::ty_ptr(mt) | ty::ty_rptr(_, mt) => {
145145
match ty::get(mt.ty).sty {
146-
ty::ty_vec(_, None) | ty::ty_str => cx.sess().bug("unexpected slice"),
146+
ty::ty_vec(_, None) | ty::ty_str | ty::ty_trait(..) => {
147+
cx.sess().bug("unexpected unsized type")
148+
}
147149
_ => const_deref_ptr(cx, v),
148150
}
149151
}

src/librustc/middle/trans/datum.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ pub fn appropriate_rvalue_mode(ccx: &CrateContext, ty: ty::t) -> RvalueMode {
157157
* on whether type is immediate or not.
158158
*/
159159

160-
if type_is_zero_size(ccx, ty) {
161-
ByValue
162-
} else if type_is_immediate(ccx, ty) {
160+
if type_is_immediate(ccx, ty) {
163161
ByValue
164162
} else {
165163
ByRef

0 commit comments

Comments
 (0)