Skip to content

Commit 1119b48

Browse files
committed
Correct comments about untracked accesses.
1 parent f0e5e22 commit 1119b48

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
445445
}
446446

447447
fn encode_def_path_table(&mut self) {
448-
let table = self.tcx.hir().definitions().def_path_table();
448+
let table = self.tcx.resolutions(()).definitions.def_path_table();
449449
if self.is_proc_macro {
450450
for def_index in std::iter::once(CRATE_DEF_INDEX)
451451
.chain(self.tcx.hir().krate().proc_macros.iter().map(|p| p.owner.local_def_index))
@@ -1062,7 +1062,7 @@ impl EncodeContext<'a, 'tcx> {
10621062

10631063
let data = ModData {
10641064
reexports,
1065-
expansion: tcx.hir().definitions().expansion_that_defined(local_def_id),
1065+
expansion: tcx.resolutions(()).definitions.expansion_that_defined(local_def_id),
10661066
};
10671067

10681068
record!(self.tables.kind[def_id] <- EntryKind::Mod(self.lazy(data)));
@@ -1754,7 +1754,7 @@ impl EncodeContext<'a, 'tcx> {
17541754
.map(|(trait_def_id, mut impls)| {
17551755
// Bring everything into deterministic order for hashing
17561756
impls.sort_by_cached_key(|&(index, _)| {
1757-
tcx.hir().definitions().def_path_hash(LocalDefId { local_def_index: index })
1757+
tcx.hir().def_path_hash(LocalDefId { local_def_index: index })
17581758
});
17591759

17601760
TraitImpls {

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
99
use rustc_data_structures::svh::Svh;
1010
use rustc_hir::def::{DefKind, Res};
1111
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
12-
use rustc_hir::definitions::{DefKey, DefPath, Definitions};
12+
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
1313
use rustc_hir::intravisit;
1414
use rustc_hir::intravisit::Visitor;
1515
use rustc_hir::itemlikevisit::ItemLikeVisitor;
@@ -154,14 +154,8 @@ impl<'hir> Map<'hir> {
154154
self.tcx.hir_crate(())
155155
}
156156

157-
#[inline]
158-
pub fn definitions(&self) -> &'hir Definitions {
159-
// Accessing the definitions is ok, since all its contents are tracked by the query system.
160-
&self.tcx.untracked_resolutions.definitions
161-
}
162-
163157
pub fn def_key(&self, def_id: LocalDefId) -> DefKey {
164-
// Accessing the definitions is ok, since all its contents are tracked by the query system.
158+
// Accessing the DefKey is ok, since it is part of DefPathHash.
165159
self.tcx.untracked_resolutions.definitions.def_key(def_id)
166160
}
167161

@@ -170,10 +164,16 @@ impl<'hir> Map<'hir> {
170164
}
171165

172166
pub fn def_path(&self, def_id: LocalDefId) -> DefPath {
173-
// Accessing the definitions is ok, since all its contents are tracked by the query system.
167+
// Accessing the DefPath is ok, since it is part of DefPathHash.
174168
self.tcx.untracked_resolutions.definitions.def_path(def_id)
175169
}
176170

171+
#[inline]
172+
pub fn def_path_hash(self, def_id: LocalDefId) -> DefPathHash {
173+
// Accessing the DefPathHash is ok, it is incr. comp. stable.
174+
self.tcx.untracked_resolutions.definitions.def_path_hash(def_id)
175+
}
176+
177177
#[inline]
178178
pub fn local_def_id(&self, hir_id: HirId) -> LocalDefId {
179179
self.opt_local_def_id(hir_id).unwrap_or_else(|| {
@@ -187,18 +187,25 @@ impl<'hir> Map<'hir> {
187187

188188
#[inline]
189189
pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<LocalDefId> {
190-
// Accessing the definitions is ok, since all its contents are tracked by the query system.
190+
// Create a dependency to the owner to ensure the query gets re-executed when the amount of
191+
// children changes.
192+
self.tcx.ensure().hir_owner_nodes(hir_id.owner);
191193
self.tcx.untracked_resolutions.definitions.opt_hir_id_to_local_def_id(hir_id)
192194
}
193195

194196
#[inline]
195197
pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId {
196-
// Accessing the definitions is ok, since all its contents are tracked by the query system.
197-
self.tcx.untracked_resolutions.definitions.local_def_id_to_hir_id(def_id)
198+
let ret = self.tcx.untracked_resolutions.definitions.local_def_id_to_hir_id(def_id);
199+
// Create a dependency to the owner to ensure the query gets re-executed when the amount of
200+
// children changes.
201+
self.tcx.ensure().hir_owner_nodes(ret.owner);
202+
ret
198203
}
199204

200205
pub fn iter_local_def_id(&self) -> impl Iterator<Item = LocalDefId> + '_ {
201-
// Accessing the definitions is ok, since all its contents are tracked by the query system.
206+
// Create a dependency to the crate to be sure we reexcute this when the amount of
207+
// definitions change.
208+
self.tcx.ensure().hir_crate(());
202209
self.tcx.untracked_resolutions.definitions.iter_local_def_id()
203210
}
204211

compiler/rustc_middle/src/ty/context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,9 +1211,9 @@ impl<'tcx> TyCtxt<'tcx> {
12111211
}
12121212

12131213
pub fn def_key(self, id: DefId) -> rustc_hir::definitions::DefKey {
1214-
// Accessing the definitions is ok, since all its contents are tracked by the query system.
1214+
// Accessing the DefKey is ok, since it is part of DefPathHash.
12151215
if let Some(id) = id.as_local() {
1216-
self.hir().def_key(id)
1216+
self.untracked_resolutions.definitions.def_key(id)
12171217
} else {
12181218
self.untracked_resolutions.cstore.def_key(id)
12191219
}
@@ -1225,17 +1225,17 @@ impl<'tcx> TyCtxt<'tcx> {
12251225
/// Note that if `id` is not local to this crate, the result will
12261226
/// be a non-local `DefPath`.
12271227
pub fn def_path(self, id: DefId) -> rustc_hir::definitions::DefPath {
1228-
// Accessing the definitions is ok, since all its contents are tracked by the query system.
1228+
// Accessing the DefPath is ok, since it is part of DefPathHash.
12291229
if let Some(id) = id.as_local() {
1230-
self.hir().def_path(id)
1230+
self.untracked_resolutions.definitions.def_path(id)
12311231
} else {
12321232
self.untracked_resolutions.cstore.def_path(id)
12331233
}
12341234
}
12351235

12361236
#[inline]
12371237
pub fn def_path_hash(self, def_id: DefId) -> rustc_hir::definitions::DefPathHash {
1238-
// Accessing the definitions is ok, since all its contents are tracked by the query system.
1238+
// Accessing the DefPathHash is ok, it is incr. comp. stable.
12391239
if let Some(def_id) = def_id.as_local() {
12401240
self.untracked_resolutions.definitions.def_path_hash(def_id)
12411241
} else {

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,7 +1867,7 @@ impl<'tcx> TyCtxt<'tcx> {
18671867
match scope.as_local() {
18681868
// Parsing and expansion aren't incremental, so we don't
18691869
// need to go through a query for the same-crate case.
1870-
Some(scope) => self.hir().definitions().expansion_that_defined(scope),
1870+
Some(scope) => self.resolutions(()).definitions.expansion_that_defined(scope),
18711871
None => self.expn_that_defined(scope),
18721872
}
18731873
}
@@ -1887,7 +1887,7 @@ impl<'tcx> TyCtxt<'tcx> {
18871887
match ident.span.normalize_to_macros_2_0_and_adjust(self.expansion_that_defined(scope))
18881888
{
18891889
Some(actual_expansion) => {
1890-
self.hir().definitions().parent_module_of_macro_def(actual_expansion)
1890+
self.resolutions(()).definitions.parent_module_of_macro_def(actual_expansion)
18911891
}
18921892
None => self.parent_module(block).to_def_id(),
18931893
};

compiler/rustc_query_impl/src/stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub fn print_stats(tcx: TyCtxt<'_>) {
108108
queries.iter().filter(|q| q.local_def_id_keys.is_some()).collect();
109109
def_id_density.sort_by_key(|q| q.local_def_id_keys.unwrap());
110110
eprintln!("\nLocal DefId density:");
111-
let total = tcx.hir().definitions().def_index_count() as f64;
111+
let total = tcx.resolutions(()).definitions.def_index_count() as f64;
112112
for q in def_id_density.iter().rev() {
113113
let local = q.local_def_id_keys.unwrap();
114114
eprintln!(" {} - {} = ({}%)", q.name, local, (local as f64 * 100.0) / total);

0 commit comments

Comments
 (0)