Skip to content

Commit

Permalink
trans::collector: Remove some redundant calls to erase_regions().
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed May 23, 2016
1 parent da41920 commit 4386d19
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
10 changes: 10 additions & 0 deletions src/librustc/ty/fold.rs
Expand Up @@ -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
Expand Down
22 changes: 12 additions & 10 deletions src/librustc_trans/collector.rs
Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1034,10 +1032,14 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(scx: &SharedCrateContext<'a,
} else {
None
}
})
.collect::<Vec<_>>();
});

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)));
}
_ => { /* */ }
}
Expand Down Expand Up @@ -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();
}

Expand Down
10 changes: 6 additions & 4 deletions src/librustc_trans/glue.rs
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -123,11 +125,11 @@ pub fn get_drop_glue_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// `Box<ZeroSizeType>` does not allocate.
tcx.types.i8
} else {
tcx.erase_regions(&t)
t
}
})
}
_ => tcx.erase_regions(&t)
_ => t
}
}

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

//~ TRANS_ITEM drop-glue i8
2 changes: 2 additions & 0 deletions src/test/codegen-units/item-collection/unsizing.rs
Expand Up @@ -78,3 +78,5 @@ fn main()
//~ TRANS_ITEM fn unsizing::{{impl}}[3]::foo[0]
let _wrapper_sized = wrapper_sized as Wrapper<Trait>;
}

//~ TRANS_ITEM drop-glue i8

0 comments on commit 4386d19

Please sign in to comment.