Skip to content

Commit 81f9d4e

Browse files
committed
Wrap vtable_methods return type in RC
1 parent b640c2b commit 81f9d4e

File tree

4 files changed

+47
-44
lines changed

4 files changed

+47
-44
lines changed

src/librustc/traits/mod.rs

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -653,50 +653,52 @@ pub fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
653653
pub fn vtable_methods<'a, 'tcx>(
654654
tcx: TyCtxt<'a, 'tcx, 'tcx>,
655655
trait_ref: ty::PolyTraitRef<'tcx>)
656-
-> Vec<Option<(DefId, &'tcx Substs<'tcx>)>>
656+
-> Rc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>
657657
{
658658
debug!("vtable_methods({:?})", trait_ref);
659659

660-
supertraits(tcx, trait_ref).flat_map(move |trait_ref| {
661-
let trait_methods = tcx.associated_items(trait_ref.def_id())
662-
.filter(|item| item.kind == ty::AssociatedKind::Method);
663-
664-
// Now list each method's DefId and Substs (for within its trait).
665-
// If the method can never be called from this object, produce None.
666-
trait_methods.map(move |trait_method| {
667-
debug!("vtable_methods: trait_method={:?}", trait_method);
668-
let def_id = trait_method.def_id;
669-
670-
// Some methods cannot be called on an object; skip those.
671-
if !tcx.is_vtable_safe_method(trait_ref.def_id(), &trait_method) {
672-
debug!("vtable_methods: not vtable safe");
673-
return None;
674-
}
675-
676-
// the method may have some early-bound lifetimes, add
677-
// regions for those
678-
let substs = Substs::for_item(tcx, def_id,
679-
|_, _| tcx.types.re_erased,
680-
|def, _| trait_ref.substs().type_for_def(def));
681-
682-
// the trait type may have higher-ranked lifetimes in it;
683-
// so erase them if they appear, so that we get the type
684-
// at some particular call site
685-
let substs = tcx.erase_late_bound_regions_and_normalize(&ty::Binder(substs));
686-
687-
// It's possible that the method relies on where clauses that
688-
// do not hold for this particular set of type parameters.
689-
// Note that this method could then never be called, so we
690-
// do not want to try and trans it, in that case (see #23435).
691-
let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, substs);
692-
if !normalize_and_test_predicates(tcx, predicates.predicates) {
693-
debug!("vtable_methods: predicates do not hold");
694-
return None;
695-
}
696-
697-
Some((def_id, substs))
698-
})
699-
}).collect()
660+
Rc::new(
661+
supertraits(tcx, trait_ref).flat_map(move |trait_ref| {
662+
let trait_methods = tcx.associated_items(trait_ref.def_id())
663+
.filter(|item| item.kind == ty::AssociatedKind::Method);
664+
665+
// Now list each method's DefId and Substs (for within its trait).
666+
// If the method can never be called from this object, produce None.
667+
trait_methods.map(move |trait_method| {
668+
debug!("vtable_methods: trait_method={:?}", trait_method);
669+
let def_id = trait_method.def_id;
670+
671+
// Some methods cannot be called on an object; skip those.
672+
if !tcx.is_vtable_safe_method(trait_ref.def_id(), &trait_method) {
673+
debug!("vtable_methods: not vtable safe");
674+
return None;
675+
}
676+
677+
// the method may have some early-bound lifetimes, add
678+
// regions for those
679+
let substs = Substs::for_item(tcx, def_id,
680+
|_, _| tcx.types.re_erased,
681+
|def, _| trait_ref.substs().type_for_def(def));
682+
683+
// the trait type may have higher-ranked lifetimes in it;
684+
// so erase them if they appear, so that we get the type
685+
// at some particular call site
686+
let substs = tcx.erase_late_bound_regions_and_normalize(&ty::Binder(substs));
687+
688+
// It's possible that the method relies on where clauses that
689+
// do not hold for this particular set of type parameters.
690+
// Note that this method could then never be called, so we
691+
// do not want to try and trans it, in that case (see #23435).
692+
let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, substs);
693+
if !normalize_and_test_predicates(tcx, predicates.predicates) {
694+
debug!("vtable_methods: predicates do not hold");
695+
return None;
696+
}
697+
698+
Some((def_id, substs))
699+
})
700+
}).collect()
701+
)
700702
}
701703

702704
impl<'tcx,O> Obligation<'tcx,O> {

src/librustc/ty/maps/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ define_maps! { <'tcx>
229229
[] fn const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
230230
[] fn is_mir_available: IsMirAvailable(DefId) -> bool,
231231
[] fn vtable_methods: vtable_methods_node(ty::PolyTraitRef<'tcx>)
232-
-> Vec<Option<(DefId, &'tcx Substs<'tcx>)>>,
232+
-> Rc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>,
233233

234234
[] fn trans_fulfill_obligation: fulfill_obligation_dep_node(
235235
(ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> Vtable<'tcx, ()>,

src/librustc_trans/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
850850

851851
// Walk all methods of the trait, including those of its supertraits
852852
let methods = tcx.vtable_methods(poly_trait_ref);
853-
let methods = methods.into_iter().filter_map(|method| method)
853+
let methods = methods.iter().cloned().filter_map(|method| method)
854854
.map(|(def_id, substs)| ty::Instance::resolve(
855855
tcx,
856856
ty::ParamEnv::empty(traits::Reveal::All),

src/librustc_trans/meth.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ pub fn get_vtable<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
8686

8787
if let Some(trait_ref) = trait_ref {
8888
let trait_ref = trait_ref.with_self_ty(tcx, ty);
89-
let methods = tcx.vtable_methods(trait_ref).into_iter().map(|opt_mth| {
89+
let methods = tcx.vtable_methods(trait_ref);
90+
let methods = methods.iter().cloned().map(|opt_mth| {
9091
opt_mth.map_or(nullptr, |(def_id, substs)| {
9192
callee::resolve_and_get_fn(ccx, def_id, substs)
9293
})

0 commit comments

Comments
 (0)