diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2017-08-30 11:40:02 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2017-09-05 07:37:28 -0700 |
| commit | 1c7294eb54df519d36b7e3904aac11507daf33b4 (patch) | |
| tree | a5ca0a3e61e011958f93c84eedfdccf82df5a8cd | |
| parent | 4dec2a8f81fd42267b9006b939b8c6f0b5e73dcf (diff) | |
| download | rust-1c7294eb54df519d36b7e3904aac11507daf33b4.tar.gz rust-1c7294eb54df519d36b7e3904aac11507daf33b4.zip | |
rustc: Move implementations_of_trait to a query
While we're at it, make it two separate queries so one's for rustdoc and one's for the compiler, hopefully being a bit more targeted.
| -rw-r--r-- | src/librustc/dep_graph/dep_node.rs | 3 | ||||
| -rw-r--r-- | src/librustc/middle/cstore.rs | 6 | ||||
| -rw-r--r-- | src/librustc/ty/maps.rs | 23 | ||||
| -rw-r--r-- | src/librustc/ty/trait_def.rs | 17 | ||||
| -rw-r--r-- | src/librustc_metadata/cstore_impl.rs | 51 | ||||
| -rw-r--r-- | src/librustdoc/clean/inline.rs | 6 |
6 files changed, 71 insertions, 35 deletions
diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index c3285a7ac04..a3e38e5b8ad 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -542,6 +542,9 @@ define_dep_nodes!( <'tcx> [] CrateDisambiguator(CrateNum), [] CrateHash(CrateNum), [] OriginalCrateName(CrateNum), + + [] ImplementationsOfTrait { krate: CrateNum, trait_id: DefId }, + [] AllTraitImplementations(CrateNum), ); trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug { diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index aa84682821e..495b357b613 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -233,9 +233,6 @@ pub trait CrateStore { fn visible_parent_map<'a>(&'a self, sess: &Session) -> ::std::cell::Ref<'a, DefIdMap<DefId>>; fn item_generics_cloned(&self, def: DefId) -> ty::Generics; - // trait info - fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId>; - // trait/impl-item info fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem; @@ -328,9 +325,6 @@ impl CrateStore for DummyCrateStore { fn item_generics_cloned(&self, def: DefId) -> ty::Generics { bug!("item_generics_cloned") } - // trait info - fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId> { vec![] } - // trait/impl-item info fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem { bug!("associated_item_cloned") } diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 4b37b2aa7ec..41caaa30b5c 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -630,6 +630,18 @@ impl<'tcx> QueryDescription for queries::original_crate_name<'tcx> { } } +impl<'tcx> QueryDescription for queries::implementations_of_trait<'tcx> { + fn describe(_tcx: TyCtxt, _: (CrateNum, DefId)) -> String { + format!("looking up implementations of a trait in a crate") + } +} + +impl<'tcx> QueryDescription for queries::all_trait_implementations<'tcx> { + fn describe(_tcx: TyCtxt, _: CrateNum) -> String { + format!("looking up all (?) trait implementations") + } +} + // If enabled, send a message to the profile-queries thread macro_rules! profq_msg { ($tcx:expr, $msg:expr) => { @@ -1213,6 +1225,11 @@ define_maps! { <'tcx> [] fn crate_disambiguator: CrateDisambiguator(CrateNum) -> Symbol, [] fn crate_hash: CrateHash(CrateNum) -> Svh, [] fn original_crate_name: OriginalCrateName(CrateNum) -> Symbol, + + [] fn implementations_of_trait: implementations_of_trait_node((CrateNum, DefId)) + -> Rc<Vec<DefId>>, + [] fn all_trait_implementations: AllTraitImplementations(CrateNum) + -> Rc<Vec<DefId>>, } fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> { @@ -1292,3 +1309,9 @@ fn lint_levels_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> { fn specializes_node<'tcx>((a, b): (DefId, DefId)) -> DepConstructor<'tcx> { DepConstructor::Specializes { impl1: a, impl2: b } } + +fn implementations_of_trait_node<'tcx>((krate, trait_id): (CrateNum, DefId)) + -> DepConstructor<'tcx> +{ + DepConstructor::ImplementationsOfTrait { krate, trait_id } +} diff --git a/src/librustc/ty/trait_def.rs b/src/librustc/ty/trait_def.rs index 9990472c6b4..4687fc65409 100644 --- a/src/librustc/ty/trait_def.rs +++ b/src/librustc/ty/trait_def.rs @@ -141,13 +141,16 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub(super) fn trait_impls_of_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_id: DefId) -> Rc<TraitImpls> { - let remote_impls = if trait_id.is_local() { - // Traits defined in the current crate can't have impls in upstream - // crates, so we don't bother querying the cstore. - Vec::new() - } else { - tcx.sess.cstore.implementations_of_trait(Some(trait_id)) - }; + let mut remote_impls = Vec::new(); + + // Traits defined in the current crate can't have impls in upstream + // crates, so we don't bother querying the cstore. + if !trait_id.is_local() { + for cnum in tcx.sess.cstore.crates() { + let impls = tcx.implementations_of_trait((cnum, trait_id)); + remote_impls.extend(impls.iter().cloned()); + } + } let mut blanket_impls = Vec::new(); let mut non_blanket_impls = FxHashMap(); diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index e08f0f2c752..67fe62d69be 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -42,14 +42,16 @@ use rustc::hir::svh::Svh; use rustc::hir; macro_rules! provide { - (<$lt:tt> $tcx:ident, $def_id:ident, $cdata:ident, $($name:ident => $compute:block)*) => { + (<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident, + $($name:ident => $compute:block)*) => { pub fn provide<$lt>(providers: &mut Providers<$lt>) { $(fn $name<'a, $lt:$lt, T>($tcx: TyCtxt<'a, $lt, $lt>, def_id_arg: T) -> <ty::queries::$name<$lt> as QueryConfig>::Value - where T: IntoDefId, + where T: IntoArgs, { - let $def_id = def_id_arg.into_def_id(); + #[allow(unused_variables)] + let ($def_id, $other) = def_id_arg.into_args(); assert!(!$def_id.is_local()); let def_path_hash = $tcx.def_path_hash($def_id); @@ -71,19 +73,25 @@ macro_rules! provide { } } -trait IntoDefId { - fn into_def_id(self) -> DefId; +// small trait to work around different signature queries all being defined via +// the macro above. +trait IntoArgs { + fn into_args(self) -> (DefId, DefId); } -impl IntoDefId for DefId { - fn into_def_id(self) -> DefId { self } +impl IntoArgs for DefId { + fn into_args(self) -> (DefId, DefId) { (self, self) } } -impl IntoDefId for CrateNum { - fn into_def_id(self) -> DefId { self.as_def_id() } +impl IntoArgs for CrateNum { + fn into_args(self) -> (DefId, DefId) { (self.as_def_id(), self.as_def_id()) } } -provide! { <'tcx> tcx, def_id, cdata, +impl IntoArgs for (CrateNum, DefId) { + fn into_args(self) -> (DefId, DefId) { (self.0.as_def_id(), self.1) } +} + +provide! { <'tcx> tcx, def_id, other, cdata, type_of => { cdata.get_type(def_id.index, tcx) } generics_of => { tcx.alloc_generics(cdata.get_generics(def_id.index)) } predicates_of => { cdata.get_predicates(def_id.index, tcx) } @@ -178,6 +186,19 @@ provide! { <'tcx> tcx, def_id, cdata, crate_disambiguator => { cdata.disambiguator() } crate_hash => { cdata.hash() } original_crate_name => { cdata.name() } + + implementations_of_trait => { + let mut result = vec![]; + let filter = Some(other); + cdata.get_implementations_for_trait(filter, &tcx.dep_graph, &mut result); + Rc::new(result) + } + + all_trait_implementations => { + let mut result = vec![]; + cdata.get_implementations_for_trait(None, &tcx.dep_graph, &mut result); + Rc::new(result) + } } pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) { @@ -217,16 +238,6 @@ impl CrateStore for cstore::CStore { self.get_crate_data(def.krate).get_generics(def.index) } - fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId> - { - let mut result = vec![]; - - self.iter_crate_data(|_, cdata| { - cdata.get_implementations_for_trait(filter, &self.dep_graph, &mut result) - }); - result - } - fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem { self.read_dep_node(def); diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 5d39d1d27f4..bd49e46f6fb 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -236,8 +236,10 @@ pub fn build_impls(cx: &DocContext, did: DefId) -> Vec<clean::Item> { cx.populated_all_crate_impls.set(true); - for did in tcx.sess.cstore.implementations_of_trait(None) { - build_impl(cx, did, &mut impls); + for cnum in tcx.sess.cstore.crates() { + for did in tcx.all_trait_implementations(cnum).iter() { + build_impl(cx, *did, &mut impls); + } } // Also try to inline primitive impls from other crates. |
