trans::collector: Remove some redundant calls to erase_regions().

This commit is contained in:
Michael Woerister 2016-05-22 00:47:21 -04:00
parent da41920919
commit 4386d19185
5 changed files with 32 additions and 14 deletions

View File

@ -99,6 +99,16 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
TypeFlags::HAS_RE_INFER | TypeFlags::HAS_RE_INFER |
TypeFlags::HAS_FREE_REGIONS) TypeFlags::HAS_FREE_REGIONS)
} }
fn is_normalized_for_trans(&self) -> bool {
!self.has_type_flags(TypeFlags::HAS_RE_EARLY_BOUND |
TypeFlags::HAS_RE_INFER |
TypeFlags::HAS_FREE_REGIONS |
TypeFlags::HAS_TY_INFER |
TypeFlags::HAS_PARAMS |
TypeFlags::HAS_PROJECTION |
TypeFlags::HAS_TY_ERR |
TypeFlags::HAS_SELF)
}
/// Indicates whether this value references only 'global' /// Indicates whether this value references only 'global'
/// types/lifetimes that are the same regardless of what fn we are /// types/lifetimes that are the same regardless of what fn we are
/// in. This is used for caching. Errs on the side of returning /// in. This is used for caching. Errs on the side of returning

View File

@ -523,7 +523,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
let ty = monomorphize::apply_param_substs(self.scx.tcx(), let ty = monomorphize::apply_param_substs(self.scx.tcx(),
self.param_substs, self.param_substs,
&ty); &ty);
let ty = self.scx.tcx().erase_regions(&ty); assert!(ty.is_normalized_for_trans());
let ty = glue::get_drop_glue_type(self.scx.tcx(), ty); let ty = glue::get_drop_glue_type(self.scx.tcx(), ty);
self.output.push(TransItem::DropGlue(DropGlueKind::Ty(ty))); self.output.push(TransItem::DropGlue(DropGlueKind::Ty(ty)));
} }
@ -859,6 +859,7 @@ fn do_static_trait_method_dispatch<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
&callee_substs); &callee_substs);
let trait_ref = ty::Binder(rcvr_substs.to_trait_ref(tcx, trait_id)); let trait_ref = ty::Binder(rcvr_substs.to_trait_ref(tcx, trait_id));
let trait_ref = tcx.normalize_associated_type(&trait_ref);
let vtbl = fulfill_obligation(scx, DUMMY_SP, trait_ref); let vtbl = fulfill_obligation(scx, DUMMY_SP, trait_ref);
// Now that we know which impl is being used, we can dispatch to // 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>,
let concrete_substs = monomorphize::apply_param_substs(tcx, let concrete_substs = monomorphize::apply_param_substs(tcx,
param_substs, param_substs,
&fn_substs); &fn_substs);
let concrete_substs = tcx.erase_regions(&concrete_substs); assert!(concrete_substs.is_normalized_for_trans());
TransItem::Fn(Instance::new(def_id, concrete_substs))
let trans_item =
TransItem::Fn(Instance::new(def_id, concrete_substs));
return trans_item;
} }
/// Creates a `TransItem` for each method that is referenced by the vtable for /// 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,
} else { } else {
None None
} }
}) });
.collect::<Vec<_>>();
output.extend(items.into_iter()); output.extend(items);
// Also add the destructor
let dg_type = glue::get_drop_glue_type(scx.tcx(),
trait_ref.self_ty());
output.push(TransItem::DropGlue(DropGlueKind::Ty(dg_type)));
} }
_ => { /* */ } _ => { /* */ }
} }
@ -1234,7 +1236,7 @@ pub enum TransItemState {
} }
pub fn collecting_debug_information(scx: &SharedCrateContext) -> bool { pub fn collecting_debug_information(scx: &SharedCrateContext) -> bool {
return scx.sess().opts.cg.debug_assertions == Some(true) && return cfg!(debug_assertions) &&
scx.sess().opts.debugging_opts.print_trans_items.is_some(); scx.sess().opts.debugging_opts.print_trans_items.is_some();
} }

View File

@ -20,7 +20,7 @@ use llvm::{ValueRef, get_param};
use middle::lang_items::ExchangeFreeFnLangItem; use middle::lang_items::ExchangeFreeFnLangItem;
use rustc::ty::subst::{Substs}; use rustc::ty::subst::{Substs};
use rustc::traits; use rustc::traits;
use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
use abi::{Abi, FnType}; use abi::{Abi, FnType};
use adt; use adt;
use adt::GetDtorType; // for tcx.dtor_type() use adt::GetDtorType; // for tcx.dtor_type()
@ -96,10 +96,12 @@ pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
pub fn get_drop_glue_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pub fn get_drop_glue_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
t: Ty<'tcx>) -> Ty<'tcx> { t: Ty<'tcx>) -> Ty<'tcx> {
assert!(t.is_normalized_for_trans());
// Even if there is no dtor for t, there might be one deeper down and we // Even if there is no dtor for t, there might be one deeper down and we
// might need to pass in the vtable ptr. // might need to pass in the vtable ptr.
if !type_is_sized(tcx, t) { if !type_is_sized(tcx, t) {
return tcx.erase_regions(&t); return t;
} }
// FIXME (#22815): note that type_needs_drop conservatively // 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>,
// `Box<ZeroSizeType>` does not allocate. // `Box<ZeroSizeType>` does not allocate.
tcx.types.i8 tcx.types.i8
} else { } else {
tcx.erase_regions(&t) t
} }
}) })
} }
_ => tcx.erase_regions(&t) _ => t
} }
} }

View File

@ -40,3 +40,5 @@ fn main() {
//~ TRANS_ITEM fn instantiation_through_vtable::{{impl}}[0]::bar[0]<u64> //~ TRANS_ITEM fn instantiation_through_vtable::{{impl}}[0]::bar[0]<u64>
let _ = &s1 as &Trait; let _ = &s1 as &Trait;
} }
//~ TRANS_ITEM drop-glue i8

View File

@ -78,3 +78,5 @@ fn main()
//~ TRANS_ITEM fn unsizing::{{impl}}[3]::foo[0] //~ TRANS_ITEM fn unsizing::{{impl}}[3]::foo[0]
let _wrapper_sized = wrapper_sized as Wrapper<Trait>; let _wrapper_sized = wrapper_sized as Wrapper<Trait>;
} }
//~ TRANS_ITEM drop-glue i8