Skip to content

Commit 9f6d7e7

Browse files
committed
Correct comments about untracked accesses.
1 parent 071a047 commit 9f6d7e7

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+3-3
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)));
@@ -1759,7 +1759,7 @@ impl EncodeContext<'a, 'tcx> {
17591759
.map(|(trait_def_id, mut impls)| {
17601760
// Bring everything into deterministic order for hashing
17611761
impls.sort_by_cached_key(|&(index, _)| {
1762-
tcx.hir().definitions().def_path_hash(LocalDefId { local_def_index: index })
1762+
tcx.hir().def_path_hash(LocalDefId { local_def_index: index })
17631763
});
17641764

17651765
TraitImpls {

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

+14-12
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,20 @@ 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+
// FIXME(#85914) is this access safe for incr. comp.?
191191
self.tcx.untracked_resolutions.definitions.opt_hir_id_to_local_def_id(hir_id)
192192
}
193193

194194
#[inline]
195195
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.
196+
// FIXME(#85914) is this access safe for incr. comp.?
197197
self.tcx.untracked_resolutions.definitions.local_def_id_to_hir_id(def_id)
198198
}
199199

200200
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.
201+
// Create a dependency to the crate to be sure we reexcute this when the amount of
202+
// definitions change.
203+
self.tcx.ensure().hir_crate(());
202204
self.tcx.untracked_resolutions.definitions.iter_local_def_id()
203205
}
204206

compiler/rustc_middle/src/ty/context.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1240,9 +1240,9 @@ impl<'tcx> TyCtxt<'tcx> {
12401240
}
12411241

12421242
pub fn def_key(self, id: DefId) -> rustc_hir::definitions::DefKey {
1243-
// Accessing the definitions is ok, since all its contents are tracked by the query system.
1243+
// Accessing the DefKey is ok, since it is part of DefPathHash.
12441244
if let Some(id) = id.as_local() {
1245-
self.hir().def_key(id)
1245+
self.untracked_resolutions.definitions.def_key(id)
12461246
} else {
12471247
self.untracked_resolutions.cstore.def_key(id)
12481248
}
@@ -1254,17 +1254,17 @@ impl<'tcx> TyCtxt<'tcx> {
12541254
/// Note that if `id` is not local to this crate, the result will
12551255
/// be a non-local `DefPath`.
12561256
pub fn def_path(self, id: DefId) -> rustc_hir::definitions::DefPath {
1257-
// Accessing the definitions is ok, since all its contents are tracked by the query system.
1257+
// Accessing the DefPath is ok, since it is part of DefPathHash.
12581258
if let Some(id) = id.as_local() {
1259-
self.hir().def_path(id)
1259+
self.untracked_resolutions.definitions.def_path(id)
12601260
} else {
12611261
self.untracked_resolutions.cstore.def_path(id)
12621262
}
12631263
}
12641264

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

compiler/rustc_query_impl/src/stats.rs

+1-1
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)