Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/librustc/ty/fold.rs
Original file line number Diff line number Diff line change
@@ -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
22 changes: 12 additions & 10 deletions src/librustc_trans/collector.rs
Original file line number Diff line number Diff line change
@@ -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::<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)));
}
_ => { /* */ }
}
@@ -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();
}

10 changes: 6 additions & 4 deletions src/librustc_trans/glue.rs
Original file line number Diff line number Diff line change
@@ -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<ZeroSizeType>` does not allocate.
tcx.types.i8
} else {
tcx.erase_regions(&t)
t
}
})
}
_ => tcx.erase_regions(&t)
_ => t
}
}

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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