From 4386d19185a1059ba89bcd9eb186cbc32f5b477f Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Sun, 22 May 2016 00:47:21 -0400 Subject: [PATCH] trans::collector: Remove some redundant calls to erase_regions(). --- src/librustc/ty/fold.rs | 10 +++++++++ src/librustc_trans/collector.rs | 22 ++++++++++--------- src/librustc_trans/glue.rs | 10 +++++---- .../instantiation-through-vtable.rs | 2 ++ .../codegen-units/item-collection/unsizing.rs | 2 ++ 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs index 4a14185b6e3ad..f76f4c01df344 100644 --- a/src/librustc/ty/fold.rs +++ b/src/librustc/ty/fold.rs @@ -99,6 +99,16 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { TypeFlags::HAS_RE_INFER | 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' /// types/lifetimes that are the same regardless of what fn we are /// in. This is used for caching. Errs on the side of returning diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index d278c3c8320fd..bbc01f0935f2b 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -523,7 +523,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { let ty = monomorphize::apply_param_substs(self.scx.tcx(), self.param_substs, &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); 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); 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); // 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, param_substs, &fn_substs); - let concrete_substs = tcx.erase_regions(&concrete_substs); - - let trans_item = - TransItem::Fn(Instance::new(def_id, concrete_substs)); - return trans_item; + assert!(concrete_substs.is_normalized_for_trans()); + TransItem::Fn(Instance::new(def_id, concrete_substs)) } /// 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 { None } - }) - .collect::>(); + }); + + output.extend(items); - output.extend(items.into_iter()); + // 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 { - return scx.sess().opts.cg.debug_assertions == Some(true) && + return cfg!(debug_assertions) && scx.sess().opts.debugging_opts.print_trans_items.is_some(); } diff --git a/src/librustc_trans/glue.rs b/src/librustc_trans/glue.rs index 10e33195305f6..64e178bf91962 100644 --- a/src/librustc_trans/glue.rs +++ b/src/librustc_trans/glue.rs @@ -20,7 +20,7 @@ use llvm::{ValueRef, get_param}; use middle::lang_items::ExchangeFreeFnLangItem; use rustc::ty::subst::{Substs}; use rustc::traits; -use rustc::ty::{self, Ty, TyCtxt}; +use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; use abi::{Abi, FnType}; use adt; 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>, 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 // might need to pass in the vtable ptr. if !type_is_sized(tcx, t) { - return tcx.erase_regions(&t); + return t; } // 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` does not allocate. tcx.types.i8 } else { - tcx.erase_regions(&t) + t } }) } - _ => tcx.erase_regions(&t) + _ => t } } diff --git a/src/test/codegen-units/item-collection/instantiation-through-vtable.rs b/src/test/codegen-units/item-collection/instantiation-through-vtable.rs index b772525122001..06e547f0dd037 100644 --- a/src/test/codegen-units/item-collection/instantiation-through-vtable.rs +++ b/src/test/codegen-units/item-collection/instantiation-through-vtable.rs @@ -40,3 +40,5 @@ fn main() { //~ TRANS_ITEM fn instantiation_through_vtable::{{impl}}[0]::bar[0] let _ = &s1 as &Trait; } + +//~ TRANS_ITEM drop-glue i8 diff --git a/src/test/codegen-units/item-collection/unsizing.rs b/src/test/codegen-units/item-collection/unsizing.rs index 45ba441bc8ba6..5c67ab7a82646 100644 --- a/src/test/codegen-units/item-collection/unsizing.rs +++ b/src/test/codegen-units/item-collection/unsizing.rs @@ -78,3 +78,5 @@ fn main() //~ TRANS_ITEM fn unsizing::{{impl}}[3]::foo[0] let _wrapper_sized = wrapper_sized as Wrapper; } + +//~ TRANS_ITEM drop-glue i8