about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2021-05-20 20:17:45 +0200
committerCamille GILLOT <gillot.camille@gmail.com>2021-05-30 20:04:37 +0200
commit1119b48e0202796d7dec8ae09cfb2112c7b47ebd (patch)
treea297e5b8388e7cfd67f500081e840927c14f5b95 /compiler/rustc_middle/src
parentf0e5e228066f8e307bc5680ed62c11bb6b692411 (diff)
downloadrust-1119b48e0202796d7dec8ae09cfb2112c7b47ebd.tar.gz
rust-1119b48e0202796d7dec8ae09cfb2112c7b47ebd.zip
Correct comments about untracked accesses.
Diffstat (limited to 'compiler/rustc_middle/src')
-rw-r--r--compiler/rustc_middle/src/hir/map/mod.rs33
-rw-r--r--compiler/rustc_middle/src/ty/context.rs10
-rw-r--r--compiler/rustc_middle/src/ty/mod.rs4
3 files changed, 27 insertions, 20 deletions
diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs
index 7e13d42459d..eb2715503be 100644
--- a/compiler/rustc_middle/src/hir/map/mod.rs
+++ b/compiler/rustc_middle/src/hir/map/mod.rs
@@ -9,7 +9,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
 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 @@ impl<'hir> Map<'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,11 +164,17 @@ impl<'hir> Map<'hir> {
     }
 
     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(|| {
             bug!(
@@ -187,18 +187,25 @@ impl<'hir> Map<'hir> {
 
     #[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.
+        // Create a dependency to the owner to ensure the query gets re-executed when the amount of
+        // children changes.
+        self.tcx.ensure().hir_owner_nodes(hir_id.owner);
         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.
-        self.tcx.untracked_resolutions.definitions.local_def_id_to_hir_id(def_id)
+        let ret = self.tcx.untracked_resolutions.definitions.local_def_id_to_hir_id(def_id);
+        // Create a dependency to the owner to ensure the query gets re-executed when the amount of
+        // children changes.
+        self.tcx.ensure().hir_owner_nodes(ret.owner);
+        ret
     }
 
     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()
     }
 
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index 657ce0b3a80..6dd6c1630a8 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -1211,9 +1211,9 @@ impl<'tcx> TyCtxt<'tcx> {
     }
 
     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)
         }
@@ -1225,9 +1225,9 @@ impl<'tcx> TyCtxt<'tcx> {
     /// 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)
         }
@@ -1235,7 +1235,7 @@ impl<'tcx> TyCtxt<'tcx> {
 
     #[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 {
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs
index 37f2f36a403..81325021ad4 100644
--- a/compiler/rustc_middle/src/ty/mod.rs
+++ b/compiler/rustc_middle/src/ty/mod.rs
@@ -1867,7 +1867,7 @@ impl<'tcx> TyCtxt<'tcx> {
         match scope.as_local() {
             // Parsing and expansion aren't incremental, so we don't
             // need to go through a query for the same-crate case.
-            Some(scope) => self.hir().definitions().expansion_that_defined(scope),
+            Some(scope) => self.resolutions(()).definitions.expansion_that_defined(scope),
             None => self.expn_that_defined(scope),
         }
     }
@@ -1887,7 +1887,7 @@ impl<'tcx> TyCtxt<'tcx> {
             match ident.span.normalize_to_macros_2_0_and_adjust(self.expansion_that_defined(scope))
             {
                 Some(actual_expansion) => {
-                    self.hir().definitions().parent_module_of_macro_def(actual_expansion)
+                    self.resolutions(()).definitions.parent_module_of_macro_def(actual_expansion)
                 }
                 None => self.parent_module(block).to_def_id(),
             };