]> git.lizzy.rs Git - rust.git/commitdiff
Correct comments about untracked accesses.
authorCamille GILLOT <gillot.camille@gmail.com>
Thu, 20 May 2021 18:17:45 +0000 (20:17 +0200)
committerCamille GILLOT <gillot.camille@gmail.com>
Tue, 6 Jul 2021 17:26:02 +0000 (19:26 +0200)
compiler/rustc_metadata/src/rmeta/encoder.rs
compiler/rustc_middle/src/hir/map/mod.rs
compiler/rustc_middle/src/ty/context.rs
compiler/rustc_query_impl/src/stats.rs

index 2478d15e554c8c005c2e27f560ab63591c3ac083..0e924d644353ce22b9a9c930a9956a2599e86d3f 100644 (file)
@@ -445,7 +445,7 @@ fn encode_info_for_items(&mut self) {
     }
 
     fn encode_def_path_table(&mut self) {
-        let table = self.tcx.hir().definitions().def_path_table();
+        let table = self.tcx.resolutions(()).definitions.def_path_table();
         if self.is_proc_macro {
             for def_index in std::iter::once(CRATE_DEF_INDEX)
                 .chain(self.tcx.hir().krate().proc_macros.iter().map(|p| p.owner.local_def_index))
@@ -1062,7 +1062,7 @@ fn encode_info_for_mod(&mut self, local_def_id: LocalDefId, md: &hir::Mod<'_>) {
 
         let data = ModData {
             reexports,
-            expansion: tcx.hir().definitions().expansion_that_defined(local_def_id),
+            expansion: tcx.resolutions(()).definitions.expansion_that_defined(local_def_id),
         };
 
         record!(self.tables.kind[def_id] <- EntryKind::Mod(self.lazy(data)));
@@ -1759,7 +1759,7 @@ fn encode_impls(&mut self) -> Lazy<[TraitImpls]> {
             .map(|(trait_def_id, mut impls)| {
                 // Bring everything into deterministic order for hashing
                 impls.sort_by_cached_key(|&(index, _)| {
-                    tcx.hir().definitions().def_path_hash(LocalDefId { local_def_index: index })
+                    tcx.hir().def_path_hash(LocalDefId { local_def_index: index })
                 });
 
                 TraitImpls {
index c901f101d942a15aab30013d67a0dbfff75cec26..6f799ea940b05c04bbc9c76a5a90c7b0550610ba 100644 (file)
@@ -9,7 +9,7 @@
 use rustc_data_structures::svh::Svh;
 use rustc_hir::def::{DefKind, Res};
 use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
-use rustc_hir::definitions::{DefKey, DefPath, Definitions};
+use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
 use rustc_hir::intravisit;
 use rustc_hir::intravisit::Visitor;
 use rustc_hir::itemlikevisit::ItemLikeVisitor;
@@ -154,14 +154,8 @@ pub fn krate(&self) -> &'hir Crate<'hir> {
         self.tcx.hir_crate(())
     }
 
-    #[inline]
-    pub fn definitions(&self) -> &'hir Definitions {
-        // Accessing the definitions is ok, since all its contents are tracked by the query system.
-        &self.tcx.untracked_resolutions.definitions
-    }
-
     pub fn def_key(&self, def_id: LocalDefId) -> DefKey {
-        // Accessing the definitions is ok, since all its contents are tracked by the query system.
+        // Accessing the DefKey is ok, since it is part of DefPathHash.
         self.tcx.untracked_resolutions.definitions.def_key(def_id)
     }
 
@@ -170,10 +164,16 @@ pub fn def_path_from_hir_id(&self, id: HirId) -> Option<DefPath> {
     }
 
     pub fn def_path(&self, def_id: LocalDefId) -> DefPath {
-        // Accessing the definitions is ok, since all its contents are tracked by the query system.
+        // Accessing the DefPath is ok, since it is part of DefPathHash.
         self.tcx.untracked_resolutions.definitions.def_path(def_id)
     }
 
+    #[inline]
+    pub fn def_path_hash(self, def_id: LocalDefId) -> DefPathHash {
+        // Accessing the DefPathHash is ok, it is incr. comp. stable.
+        self.tcx.untracked_resolutions.definitions.def_path_hash(def_id)
+    }
+
     #[inline]
     pub fn local_def_id(&self, hir_id: HirId) -> LocalDefId {
         self.opt_local_def_id(hir_id).unwrap_or_else(|| {
@@ -187,18 +187,20 @@ pub fn local_def_id(&self, hir_id: HirId) -> LocalDefId {
 
     #[inline]
     pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<LocalDefId> {
-        // Accessing the definitions is ok, since all its contents are tracked by the query system.
+        // FIXME(#85914) is this access safe for incr. comp.?
         self.tcx.untracked_resolutions.definitions.opt_hir_id_to_local_def_id(hir_id)
     }
 
     #[inline]
     pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId {
-        // Accessing the definitions is ok, since all its contents are tracked by the query system.
+        // FIXME(#85914) is this access safe for incr. comp.?
         self.tcx.untracked_resolutions.definitions.local_def_id_to_hir_id(def_id)
     }
 
     pub fn iter_local_def_id(&self) -> impl Iterator<Item = LocalDefId> + '_ {
-        // Accessing the definitions is ok, since all its contents are tracked by the query system.
+        // Create a dependency to the crate to be sure we reexcute this when the amount of
+        // definitions change.
+        self.tcx.ensure().hir_crate(());
         self.tcx.untracked_resolutions.definitions.iter_local_def_id()
     }
 
index 25fd02bc29c7539dbf1662be38ee9a2e3b8e8bd0..1afeb4a138f9da1334d428a90bf007684ad4186f 100644 (file)
@@ -1240,9 +1240,9 @@ pub fn features(self) -> &'tcx rustc_feature::Features {
     }
 
     pub fn def_key(self, id: DefId) -> rustc_hir::definitions::DefKey {
-        // Accessing the definitions is ok, since all its contents are tracked by the query system.
+        // Accessing the DefKey is ok, since it is part of DefPathHash.
         if let Some(id) = id.as_local() {
-            self.hir().def_key(id)
+            self.untracked_resolutions.definitions.def_key(id)
         } else {
             self.untracked_resolutions.cstore.def_key(id)
         }
@@ -1254,9 +1254,9 @@ pub fn def_key(self, id: DefId) -> rustc_hir::definitions::DefKey {
     /// Note that if `id` is not local to this crate, the result will
     ///  be a non-local `DefPath`.
     pub fn def_path(self, id: DefId) -> rustc_hir::definitions::DefPath {
-        // Accessing the definitions is ok, since all its contents are tracked by the query system.
+        // Accessing the DefPath is ok, since it is part of DefPathHash.
         if let Some(id) = id.as_local() {
-            self.hir().def_path(id)
+            self.untracked_resolutions.definitions.def_path(id)
         } else {
             self.untracked_resolutions.cstore.def_path(id)
         }
@@ -1264,7 +1264,7 @@ pub fn def_path(self, id: DefId) -> rustc_hir::definitions::DefPath {
 
     #[inline]
     pub fn def_path_hash(self, def_id: DefId) -> rustc_hir::definitions::DefPathHash {
-        // Accessing the definitions is ok, since all its contents are tracked by the query system.
+        // Accessing the DefPathHash is ok, it is incr. comp. stable.
         if let Some(def_id) = def_id.as_local() {
             self.untracked_resolutions.definitions.def_path_hash(def_id)
         } else {
index e877034bd7b5b28d9a2ebd91900f4f6618000077..fa48df3ed45c63e2ba1fe338de8e8f2dae996155 100644 (file)
@@ -108,7 +108,7 @@ pub fn print_stats(tcx: TyCtxt<'_>) {
         queries.iter().filter(|q| q.local_def_id_keys.is_some()).collect();
     def_id_density.sort_by_key(|q| q.local_def_id_keys.unwrap());
     eprintln!("\nLocal DefId density:");
-    let total = tcx.hir().definitions().def_index_count() as f64;
+    let total = tcx.resolutions(()).definitions.def_index_count() as f64;
     for q in def_id_density.iter().rev() {
         let local = q.local_def_id_keys.unwrap();
         eprintln!("   {} - {} = ({}%)", q.name, local, (local as f64 * 100.0) / total);