Wrap vtable_methods return type in RC

This commit is contained in:
Jimmy Brisson 2017-10-09 10:39:53 -05:00
parent b640c2b95a
commit 81f9d4e78f
4 changed files with 41 additions and 38 deletions

View File

@ -653,10 +653,11 @@ pub fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
pub fn vtable_methods<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
trait_ref: ty::PolyTraitRef<'tcx>)
-> Vec<Option<(DefId, &'tcx Substs<'tcx>)>>
-> Rc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>
{
debug!("vtable_methods({:?})", trait_ref);
Rc::new(
supertraits(tcx, trait_ref).flat_map(move |trait_ref| {
let trait_methods = tcx.associated_items(trait_ref.def_id())
.filter(|item| item.kind == ty::AssociatedKind::Method);
@ -697,6 +698,7 @@ pub fn vtable_methods<'a, 'tcx>(
Some((def_id, substs))
})
}).collect()
)
}
impl<'tcx,O> Obligation<'tcx,O> {

View File

@ -229,7 +229,7 @@ define_maps! { <'tcx>
[] fn const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
[] fn is_mir_available: IsMirAvailable(DefId) -> bool,
[] fn vtable_methods: vtable_methods_node(ty::PolyTraitRef<'tcx>)
-> Vec<Option<(DefId, &'tcx Substs<'tcx>)>>,
-> Rc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>,
[] fn trans_fulfill_obligation: fulfill_obligation_dep_node(
(ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> Vtable<'tcx, ()>,

View File

@ -850,7 +850,7 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// Walk all methods of the trait, including those of its supertraits
let methods = tcx.vtable_methods(poly_trait_ref);
let methods = methods.into_iter().filter_map(|method| method)
let methods = methods.iter().cloned().filter_map(|method| method)
.map(|(def_id, substs)| ty::Instance::resolve(
tcx,
ty::ParamEnv::empty(traits::Reveal::All),

View File

@ -86,7 +86,8 @@ pub fn get_vtable<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
if let Some(trait_ref) = trait_ref {
let trait_ref = trait_ref.with_self_ty(tcx, ty);
let methods = tcx.vtable_methods(trait_ref).into_iter().map(|opt_mth| {
let methods = tcx.vtable_methods(trait_ref);
let methods = methods.iter().cloned().map(|opt_mth| {
opt_mth.map_or(nullptr, |(def_id, substs)| {
callee::resolve_and_get_fn(ccx, def_id, substs)
})