]> git.lizzy.rs Git - rust.git/commitdiff
Update `trait_impls`
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Sat, 8 Feb 2020 03:14:29 +0000 (04:14 +0100)
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Sat, 14 Mar 2020 21:52:29 +0000 (22:52 +0100)
src/librustc/hir/map/mod.rs
src/librustc/query/mod.rs
src/librustc/ty/mod.rs
src/librustc/ty/query/mod.rs
src/librustc/ty/trait_def.rs

index f9b9c7a3cfe87063eccc8cadb2cfa24c30cc1ca6..1a816e6b2cbed57fa5ff6159d27792dc8a260325 100644 (file)
@@ -4,7 +4,7 @@
 };
 
 use crate::arena::Arena;
-use crate::dep_graph::{DepGraph, DepKind, DepNode, DepNodeIndex};
+use crate::dep_graph::{DepGraph, DepNodeIndex};
 use crate::hir::{HirOwner, HirOwnerItems};
 use crate::middle::cstore::CrateStoreDyn;
 use crate::ty::query::Providers;
@@ -13,7 +13,7 @@
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::svh::Svh;
 use rustc_hir::def::{DefKind, Res};
-use rustc_hir::def_id::{DefId, DefIndex, LocalDefId};
+use rustc_hir::def_id::{DefId, DefIndex, LocalDefId, LOCAL_CRATE};
 use rustc_hir::intravisit;
 use rustc_hir::itemlikevisit::ItemLikeVisitor;
 use rustc_hir::print::Nested;
@@ -532,11 +532,7 @@ pub fn ty_param_name(&self, id: HirId) -> Name {
     }
 
     pub fn trait_impls(&self, trait_did: DefId) -> &'hir [HirId] {
-        self.dep_graph.read(DepNode::new_no_params(DepKind::AllLocalTraitImpls));
-
-        // N.B., intentionally bypass `self.krate()` so that we
-        // do not trigger a read of the whole krate here
-        self.krate.trait_impls.get(&trait_did).map_or(&[], |xs| &xs[..])
+        self.tcx.all_local_trait_impls(LOCAL_CRATE).get(&trait_did).map_or(&[], |xs| &xs[..])
     }
 
     /// Gets the attributes on the crate. This is preferable to
index 2a8e34ddc2521b684a3cfe05f4061a1b01b09eb3..5dafa462ca89eb8cd268410b2eb655cb6de5b4ba 100644 (file)
@@ -671,6 +671,9 @@ fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String {
     }
 
     TypeChecking {
+        query all_local_trait_impls(key: CrateNum) -> &'tcx BTreeMap<DefId, Vec<hir::HirId>> {
+            desc { "local trait impls" }
+        }
         query trait_impls_of(key: DefId) -> &'tcx ty::trait_def::TraitImpls {
             desc { |tcx| "trait impls of `{}`", tcx.def_path_str(key) }
         }
index c2697570dda2785040b750570f39ff7db7a9f79b..d3c4ddf1ed30a834745d70f6197d332818b2fee8 100644 (file)
@@ -3142,8 +3142,11 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
     context::provide(providers);
     erase_regions::provide(providers);
     layout::provide(providers);
-    *providers =
-        ty::query::Providers { trait_impls_of: trait_def::trait_impls_of_provider, ..*providers };
+    *providers = ty::query::Providers {
+        trait_impls_of: trait_def::trait_impls_of_provider,
+        all_local_trait_impls: trait_def::all_local_trait_impls,
+        ..*providers
+    };
 }
 
 /// A map for the local crate mapping each type to a vector of its
index b6976221ef7da5de8bb5159f05240a454586fd3e..3dbcf9228d237b5dc49780c02606e29317a360e5 100644 (file)
@@ -56,6 +56,7 @@
 use rustc_span::symbol::Symbol;
 use rustc_span::{Span, DUMMY_SP};
 use std::borrow::Cow;
+use std::collections::BTreeMap;
 use std::convert::TryFrom;
 use std::ops::Deref;
 use std::sync::Arc;
index 0cf1c397648edcfe29787d6ac570f1b53cbceffc..91a99ec43e6a973ae32edea2ea89ff430c23dd6e 100644 (file)
@@ -5,11 +5,13 @@
 use crate::ty::fold::TypeFoldable;
 use crate::ty::{Ty, TyCtxt};
 use rustc_hir as hir;
-use rustc_hir::def_id::DefId;
+use rustc_hir::def_id::{CrateNum, DefId};
+use rustc_hir::HirId;
 
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
 use rustc_macros::HashStable;
+use std::collections::BTreeMap;
 
 /// A trait's definition with type information.
 #[derive(HashStable)]
@@ -146,6 +148,14 @@ pub fn all_impls(self, def_id: DefId) -> Vec<DefId> {
     }
 }
 
+// Query provider for `all_local_trait_impls`.
+pub(super) fn all_local_trait_impls<'tcx>(
+    tcx: TyCtxt<'tcx>,
+    krate: CrateNum,
+) -> &'tcx BTreeMap<DefId, Vec<HirId>> {
+    &tcx.hir_crate(krate).trait_impls
+}
+
 // Query provider for `trait_impls_of`.
 pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> &TraitImpls {
     let mut impls = TraitImpls::default();