Skip to content

Commit 97e3a24

Browse files
committed
Auto merge of rust-lang#33783 - michaelwoerister:collector-cleanup-2, r=nikomatsakis
trans::collector: Remove some redundant calls to erase_regions(). r? @Aatch
2 parents dc91467 + 4386d19 commit 97e3a24

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

src/librustc/ty/fold.rs

+10
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
9999
TypeFlags::HAS_RE_INFER |
100100
TypeFlags::HAS_FREE_REGIONS)
101101
}
102+
fn is_normalized_for_trans(&self) -> bool {
103+
!self.has_type_flags(TypeFlags::HAS_RE_EARLY_BOUND |
104+
TypeFlags::HAS_RE_INFER |
105+
TypeFlags::HAS_FREE_REGIONS |
106+
TypeFlags::HAS_TY_INFER |
107+
TypeFlags::HAS_PARAMS |
108+
TypeFlags::HAS_PROJECTION |
109+
TypeFlags::HAS_TY_ERR |
110+
TypeFlags::HAS_SELF)
111+
}
102112
/// Indicates whether this value references only 'global'
103113
/// types/lifetimes that are the same regardless of what fn we are
104114
/// in. This is used for caching. Errs on the side of returning

src/librustc_trans/collector.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
523523
let ty = monomorphize::apply_param_substs(self.scx.tcx(),
524524
self.param_substs,
525525
&ty);
526-
let ty = self.scx.tcx().erase_regions(&ty);
526+
assert!(ty.is_normalized_for_trans());
527527
let ty = glue::get_drop_glue_type(self.scx.tcx(), ty);
528528
self.output.push(TransItem::DropGlue(DropGlueKind::Ty(ty)));
529529
}
@@ -859,6 +859,7 @@ fn do_static_trait_method_dispatch<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
859859
&callee_substs);
860860

861861
let trait_ref = ty::Binder(rcvr_substs.to_trait_ref(tcx, trait_id));
862+
let trait_ref = tcx.normalize_associated_type(&trait_ref);
862863
let vtbl = fulfill_obligation(scx, DUMMY_SP, trait_ref);
863864

864865
// Now that we know which impl is being used, we can dispatch to
@@ -992,11 +993,8 @@ fn create_fn_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
992993
let concrete_substs = monomorphize::apply_param_substs(tcx,
993994
param_substs,
994995
&fn_substs);
995-
let concrete_substs = tcx.erase_regions(&concrete_substs);
996-
997-
let trans_item =
998-
TransItem::Fn(Instance::new(def_id, concrete_substs));
999-
return trans_item;
996+
assert!(concrete_substs.is_normalized_for_trans());
997+
TransItem::Fn(Instance::new(def_id, concrete_substs))
1000998
}
1001999

10021000
/// Creates a `TransItem` for each method that is referenced by the vtable for
@@ -1034,10 +1032,14 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(scx: &SharedCrateContext<'a,
10341032
} else {
10351033
None
10361034
}
1037-
})
1038-
.collect::<Vec<_>>();
1035+
});
1036+
1037+
output.extend(items);
10391038

1040-
output.extend(items.into_iter());
1039+
// Also add the destructor
1040+
let dg_type = glue::get_drop_glue_type(scx.tcx(),
1041+
trait_ref.self_ty());
1042+
output.push(TransItem::DropGlue(DropGlueKind::Ty(dg_type)));
10411043
}
10421044
_ => { /* */ }
10431045
}
@@ -1234,7 +1236,7 @@ pub enum TransItemState {
12341236
}
12351237

12361238
pub fn collecting_debug_information(scx: &SharedCrateContext) -> bool {
1237-
return scx.sess().opts.cg.debug_assertions == Some(true) &&
1239+
return cfg!(debug_assertions) &&
12381240
scx.sess().opts.debugging_opts.print_trans_items.is_some();
12391241
}
12401242

src/librustc_trans/glue.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use llvm::{ValueRef, get_param};
2020
use middle::lang_items::ExchangeFreeFnLangItem;
2121
use rustc::ty::subst::{Substs};
2222
use rustc::traits;
23-
use rustc::ty::{self, Ty, TyCtxt};
23+
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
2424
use abi::{Abi, FnType};
2525
use adt;
2626
use adt::GetDtorType; // for tcx.dtor_type()
@@ -96,10 +96,12 @@ pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
9696

9797
pub fn get_drop_glue_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
9898
t: Ty<'tcx>) -> Ty<'tcx> {
99+
assert!(t.is_normalized_for_trans());
100+
99101
// Even if there is no dtor for t, there might be one deeper down and we
100102
// might need to pass in the vtable ptr.
101103
if !type_is_sized(tcx, t) {
102-
return tcx.erase_regions(&t);
104+
return t;
103105
}
104106

105107
// FIXME (#22815): note that type_needs_drop conservatively
@@ -123,11 +125,11 @@ pub fn get_drop_glue_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
123125
// `Box<ZeroSizeType>` does not allocate.
124126
tcx.types.i8
125127
} else {
126-
tcx.erase_regions(&t)
128+
t
127129
}
128130
})
129131
}
130-
_ => tcx.erase_regions(&t)
132+
_ => t
131133
}
132134
}
133135

src/test/codegen-units/item-collection/instantiation-through-vtable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ fn main() {
4040
//~ TRANS_ITEM fn instantiation_through_vtable::{{impl}}[0]::bar[0]<u64>
4141
let _ = &s1 as &Trait;
4242
}
43+
44+
//~ TRANS_ITEM drop-glue i8

src/test/codegen-units/item-collection/unsizing.rs

+2
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,5 @@ fn main()
7878
//~ TRANS_ITEM fn unsizing::{{impl}}[3]::foo[0]
7979
let _wrapper_sized = wrapper_sized as Wrapper<Trait>;
8080
}
81+
82+
//~ TRANS_ITEM drop-glue i8

0 commit comments

Comments
 (0)