Skip to content

Commit 5d9f96a

Browse files
committed
Make resolutions a query.
1 parent 139f7ad commit 5d9f96a

File tree

13 files changed

+120
-101
lines changed

13 files changed

+120
-101
lines changed

compiler/rustc_hir/src/definitions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use tracing::debug;
2525
/// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey`
2626
/// stores the `DefIndex` of its parent.
2727
/// There is one `DefPathTable` for each crate.
28-
#[derive(Clone, Default)]
28+
#[derive(Clone, Default, Debug)]
2929
pub struct DefPathTable {
3030
index_to_key: IndexVec<DefIndex, DefKey>,
3131
def_path_hashes: IndexVec<DefIndex, DefPathHash>,
@@ -107,7 +107,7 @@ impl DefPathTable {
107107
/// The definition table containing node definitions.
108108
/// It holds the `DefPathTable` for `LocalDefId`s/`DefPath`s.
109109
/// It also stores mappings to convert `LocalDefId`s to/from `HirId`s.
110-
#[derive(Clone)]
110+
#[derive(Clone, Debug)]
111111
pub struct Definitions {
112112
table: DefPathTable,
113113

compiler/rustc_metadata/src/creader.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ pub struct CStore {
5151
unused_externs: Vec<Symbol>,
5252
}
5353

54+
impl std::fmt::Debug for CStore {
55+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56+
f.debug_struct("CStore").finish_non_exhaustive()
57+
}
58+
}
59+
5460
pub struct CrateLoader<'a> {
5561
// Immutable configuration.
5662
sess: &'a Session,

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
285285
// required that their size stay the same, but we don't want to change
286286
// it inadvertently. This assert just ensures we're aware of any change.
287287
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
288-
static_assert_size!(DepNode, 17);
288+
static_assert_size!(DepNode, 18);
289289

290290
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
291291
static_assert_size!(DepNode, 24);

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,22 @@ impl<'hir> Map<'hir> {
156156

157157
#[inline]
158158
pub fn definitions(&self) -> &'hir Definitions {
159-
&self.tcx.definitions
159+
// Accessing the definitions is ok, since all its contents are tracked by the query system.
160+
&self.tcx.untracked_resolutions.definitions
160161
}
161162

162163
pub fn def_key(&self, def_id: LocalDefId) -> DefKey {
163-
self.tcx.definitions.def_key(def_id)
164+
// Accessing the definitions is ok, since all its contents are tracked by the query system.
165+
self.tcx.untracked_resolutions.definitions.def_key(def_id)
164166
}
165167

166168
pub fn def_path_from_hir_id(&self, id: HirId) -> Option<DefPath> {
167169
self.opt_local_def_id(id).map(|def_id| self.def_path(def_id))
168170
}
169171

170172
pub fn def_path(&self, def_id: LocalDefId) -> DefPath {
171-
self.tcx.definitions.def_path(def_id)
173+
// Accessing the definitions is ok, since all its contents are tracked by the query system.
174+
self.tcx.untracked_resolutions.definitions.def_path(def_id)
172175
}
173176

174177
#[inline]
@@ -184,16 +187,19 @@ impl<'hir> Map<'hir> {
184187

185188
#[inline]
186189
pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<LocalDefId> {
187-
self.tcx.definitions.opt_hir_id_to_local_def_id(hir_id)
190+
// Accessing the definitions is ok, since all its contents are tracked by the query system.
191+
self.tcx.untracked_resolutions.definitions.opt_hir_id_to_local_def_id(hir_id)
188192
}
189193

190194
#[inline]
191195
pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId {
192-
self.tcx.definitions.local_def_id_to_hir_id(def_id)
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)
193198
}
194199

195200
pub fn iter_local_def_id(&self) -> impl Iterator<Item = LocalDefId> + '_ {
196-
self.tcx.definitions.iter_local_def_id()
201+
// Accessing the definitions is ok, since all its contents are tracked by the query system.
202+
self.tcx.untracked_resolutions.definitions.iter_local_def_id()
197203
}
198204

199205
pub fn opt_def_kind(&self, local_def_id: LocalDefId) -> Option<DefKind> {
@@ -932,9 +938,15 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> {
932938
pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> &'tcx IndexedHir<'tcx> {
933939
let _prof_timer = tcx.sess.prof.generic_activity("build_hir_map");
934940

941+
// We can access untracked state since we are an eval_always query.
935942
let hcx = tcx.create_stable_hashing_context();
936-
let mut collector =
937-
NodeCollector::root(tcx.sess, &**tcx.arena, tcx.untracked_crate, &tcx.definitions, hcx);
943+
let mut collector = NodeCollector::root(
944+
tcx.sess,
945+
&**tcx.arena,
946+
tcx.untracked_crate,
947+
&tcx.untracked_resolutions.definitions,
948+
hcx,
949+
);
938950
intravisit::walk_crate(&mut collector, tcx.untracked_crate);
939951

940952
let map = collector.finalize_and_compute_crate_hash();
@@ -944,14 +956,15 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> &'tcx IndexedHir<'tc
944956
pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
945957
assert_eq!(crate_num, LOCAL_CRATE);
946958

959+
// We can access untracked state since we are an eval_always query.
947960
let mut hcx = tcx.create_stable_hashing_context();
948961

949962
let mut hir_body_nodes: Vec<_> = tcx
950963
.index_hir(())
951964
.map
952965
.iter_enumerated()
953966
.filter_map(|(def_id, hod)| {
954-
let def_path_hash = tcx.definitions.def_path_hash(def_id);
967+
let def_path_hash = tcx.untracked_resolutions.definitions.def_path_hash(def_id);
955968
let mut hasher = StableHasher::new();
956969
hod.with_bodies.as_ref()?.hash_stable(&mut hcx, &mut hasher);
957970
AttributeMap { map: &tcx.untracked_crate.attrs, prefix: def_id }
@@ -968,7 +981,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
968981
},
969982
);
970983

971-
let upstream_crates = upstream_crates(&*tcx.cstore);
984+
let upstream_crates = upstream_crates(&*tcx.untracked_resolutions.cstore);
972985

973986
// We hash the final, remapped names of all local source files so we
974987
// don't have to include the path prefix remapping commandline args.

compiler/rustc_middle/src/middle/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pub type MetadataLoaderDyn = dyn MetadataLoader + Sync;
182182
/// that it's *not* tracked for dependency information throughout compilation
183183
/// (it'd break incremental compilation) and should only be called pre-HIR (e.g.
184184
/// during resolve)
185-
pub trait CrateStore {
185+
pub trait CrateStore: std::fmt::Debug {
186186
fn as_any(&self) -> &dyn Any;
187187

188188
// resolve

compiler/rustc_middle/src/query/mod.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ rustc_queries! {
1414
desc { "trigger a delay span bug" }
1515
}
1616

17+
query resolutions(_: ()) -> &'tcx ty::ResolverOutputs {
18+
eval_always
19+
no_hash
20+
desc { "get the resolver outputs" }
21+
}
22+
1723
/// Represents crate as a whole (as distinct from the top-level crate module).
1824
/// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
1925
/// we will have to assume that any change means that you need to be recompiled.
@@ -1133,7 +1139,6 @@ rustc_queries! {
11331139

11341140
query module_exports(def_id: LocalDefId) -> Option<&'tcx [Export<LocalDefId>]> {
11351141
desc { |tcx| "looking up items exported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1136-
eval_always
11371142
}
11381143

11391144
query impl_defaultness(def_id: DefId) -> hir::Defaultness {
@@ -1327,7 +1332,6 @@ rustc_queries! {
13271332
}
13281333

13291334
query visibility(def_id: DefId) -> ty::Visibility {
1330-
eval_always
13311335
desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
13321336
}
13331337

@@ -1352,8 +1356,6 @@ rustc_queries! {
13521356
desc { |tcx| "collecting child items of `{}`", tcx.def_path_str(def_id) }
13531357
}
13541358
query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1355-
// This depends on untracked global state (`tcx.extern_crate_map`)
1356-
eval_always
13571359
desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
13581360
}
13591361

@@ -1420,16 +1422,12 @@ rustc_queries! {
14201422
eval_always
14211423
}
14221424
query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
1423-
eval_always
14241425
desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
14251426
}
14261427
query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1427-
eval_always
14281428
desc { "looking up all possibly unused extern crates" }
14291429
}
1430-
query names_imported_by_glob_use(def_id: LocalDefId)
1431-
-> &'tcx FxHashSet<Symbol> {
1432-
eval_always
1430+
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
14331431
desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
14341432
}
14351433

@@ -1439,7 +1437,6 @@ rustc_queries! {
14391437
desc { "calculating the stability index for the local crate" }
14401438
}
14411439
query all_crate_nums(_: ()) -> &'tcx [CrateNum] {
1442-
eval_always
14431440
desc { "fetching all foreign CrateNum instances" }
14441441
}
14451442

0 commit comments

Comments
 (0)