Skip to content

Commit b640c2b

Browse files
committed
get_vtable_methods => vtable_methods query
1 parent 4e116e1 commit b640c2b

File tree

8 files changed

+32
-8
lines changed

8 files changed

+32
-8
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ define_dep_nodes!( <'tcx>
506506
[] SpecializationGraph(DefId),
507507
[] ObjectSafety(DefId),
508508
[] FulfillObligation { param_env: ParamEnv<'tcx>, trait_ref: PolyTraitRef<'tcx> },
509+
[] VtableMethods { trait_ref: PolyTraitRef<'tcx> },
509510

510511
[] IsCopy { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },
511512
[] IsSized { param_env: ParamEnvAnd<'tcx, Ty<'tcx>> },

src/librustc/traits/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -650,12 +650,12 @@ pub fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
650650
/// Given a trait `trait_ref`, iterates the vtable entries
651651
/// that come from `trait_ref`, including its supertraits.
652652
#[inline] // FIXME(#35870) Avoid closures being unexported due to impl Trait.
653-
pub fn get_vtable_methods<'a, 'tcx>(
653+
pub fn vtable_methods<'a, 'tcx>(
654654
tcx: TyCtxt<'a, 'tcx, 'tcx>,
655655
trait_ref: ty::PolyTraitRef<'tcx>)
656656
-> Vec<Option<(DefId, &'tcx Substs<'tcx>)>>
657657
{
658-
debug!("get_vtable_methods({:?})", trait_ref);
658+
debug!("vtable_methods({:?})", trait_ref);
659659

660660
supertraits(tcx, trait_ref).flat_map(move |trait_ref| {
661661
let trait_methods = tcx.associated_items(trait_ref.def_id())
@@ -664,12 +664,12 @@ pub fn get_vtable_methods<'a, 'tcx>(
664664
// Now list each method's DefId and Substs (for within its trait).
665665
// If the method can never be called from this object, produce None.
666666
trait_methods.map(move |trait_method| {
667-
debug!("get_vtable_methods: trait_method={:?}", trait_method);
667+
debug!("vtable_methods: trait_method={:?}", trait_method);
668668
let def_id = trait_method.def_id;
669669

670670
// Some methods cannot be called on an object; skip those.
671671
if !tcx.is_vtable_safe_method(trait_ref.def_id(), &trait_method) {
672-
debug!("get_vtable_methods: not vtable safe");
672+
debug!("vtable_methods: not vtable safe");
673673
return None;
674674
}
675675

@@ -690,7 +690,7 @@ pub fn get_vtable_methods<'a, 'tcx>(
690690
// do not want to try and trans it, in that case (see #23435).
691691
let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, substs);
692692
if !normalize_and_test_predicates(tcx, predicates.predicates) {
693-
debug!("get_vtable_methods: predicates do not hold");
693+
debug!("vtable_methods: predicates do not hold");
694694
return None;
695695
}
696696

@@ -836,6 +836,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
836836
specialization_graph_of: specialize::specialization_graph_provider,
837837
specializes: specialize::specializes,
838838
trans_fulfill_obligation: trans::trans_fulfill_obligation,
839+
vtable_methods,
839840
..*providers
840841
};
841842
}
@@ -846,6 +847,7 @@ pub fn provide_extern(providers: &mut ty::maps::Providers) {
846847
specialization_graph_of: specialize::specialization_graph_provider,
847848
specializes: specialize::specializes,
848849
trans_fulfill_obligation: trans::trans_fulfill_obligation,
850+
vtable_methods,
849851
..*providers
850852
};
851853
}

src/librustc/ty/maps/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,12 @@ impl<'tcx> QueryDescription for queries::has_clone_closures<'tcx> {
503503
}
504504
}
505505

506+
impl<'tcx> QueryDescription for queries::vtable_methods<'tcx> {
507+
fn describe(tcx: TyCtxt, key: ty::PolyTraitRef<'tcx> ) -> String {
508+
format!("finding all methods for trait {}", tcx.item_path_str(key.def_id()))
509+
}
510+
}
511+
506512
impl<'tcx> QueryDescription for queries::has_copy_closures<'tcx> {
507513
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
508514
format!("seeing if the crate has enabled `Copy` closures")

src/librustc/ty/maps/keys.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) {
143143
}
144144
}
145145

146+
impl<'tcx> Key for ty::PolyTraitRef<'tcx>{
147+
fn map_crate(&self) -> CrateNum {
148+
self.def_id().krate
149+
}
150+
fn default_span(&self, tcx: TyCtxt) -> Span {
151+
tcx.def_span(self.def_id())
152+
}
153+
}
154+
146155
impl<'tcx> Key for Ty<'tcx> {
147156
fn map_crate(&self) -> CrateNum {
148157
LOCAL_CRATE

src/librustc/ty/maps/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ define_maps! { <'tcx>
228228
[] fn item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> ExternBodyNestedBodies,
229229
[] fn const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
230230
[] fn is_mir_available: IsMirAvailable(DefId) -> bool,
231+
[] fn vtable_methods: vtable_methods_node(ty::PolyTraitRef<'tcx>)
232+
-> Vec<Option<(DefId, &'tcx Substs<'tcx>)>>,
231233

232234
[] fn trans_fulfill_obligation: fulfill_obligation_dep_node(
233235
(ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> Vtable<'tcx, ()>,
@@ -470,3 +472,7 @@ fn collect_and_partition_translation_items_node<'tcx>(_: CrateNum) -> DepConstru
470472
fn output_filenames_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
471473
DepConstructor::OutputFilenames
472474
}
475+
476+
fn vtable_methods_node<'tcx>(trait_ref: ty::PolyTraitRef<'tcx>) -> DepConstructor<'tcx> {
477+
DepConstructor::VtableMethods{ trait_ref }
478+
}

src/librustc/ty/maps/plumbing.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
749749
DepKind::CodegenUnit |
750750
DepKind::CompileCodegenUnit |
751751
DepKind::FulfillObligation |
752+
DepKind::VtableMethods |
752753

753754
// These are just odd
754755
DepKind::Null |

src/librustc_trans/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
849849
assert!(!poly_trait_ref.has_escaping_regions());
850850

851851
// Walk all methods of the trait, including those of its supertraits
852-
let methods = traits::get_vtable_methods(tcx, poly_trait_ref);
852+
let methods = tcx.vtable_methods(poly_trait_ref);
853853
let methods = methods.into_iter().filter_map(|method| method)
854854
.map(|(def_id, substs)| ty::Instance::resolve(
855855
tcx,

src/librustc_trans/meth.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use llvm::ValueRef;
12-
use rustc::traits;
1312
use callee;
1413
use common::*;
1514
use builder::Builder;
@@ -87,7 +86,7 @@ pub fn get_vtable<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
8786

8887
if let Some(trait_ref) = trait_ref {
8988
let trait_ref = trait_ref.with_self_ty(tcx, ty);
90-
let methods = traits::get_vtable_methods(tcx, trait_ref).into_iter().map(|opt_mth| {
89+
let methods = tcx.vtable_methods(trait_ref).into_iter().map(|opt_mth| {
9190
opt_mth.map_or(nullptr, |(def_id, substs)| {
9291
callee::resolve_and_get_fn(ccx, def_id, substs)
9392
})

0 commit comments

Comments
 (0)