Skip to content

Commit 4d21d30

Browse files
authored
Rollup merge of #109536 - petrochenkov:qcstore3, r=cjgillot
resolve: Rename some cstore methods to match queries and add comments about costs associated with replacing them with query calls. Supersedes #108346. r? `@cjgillot`
2 parents 686bd46 + 1cec923 commit 4d21d30

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1041,13 +1041,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10411041
self.root.tables.optimized_mir.get(self, id).is_some()
10421042
}
10431043

1044-
fn module_expansion(self, id: DefIndex, sess: &Session) -> ExpnId {
1045-
match self.def_kind(id) {
1046-
DefKind::Mod | DefKind::Enum | DefKind::Trait => self.get_expn_that_defined(id, sess),
1047-
_ => panic!("Expected module, found {:?}", self.local_def_id(id)),
1048-
}
1049-
}
1050-
10511044
fn get_fn_has_self_parameter(self, id: DefIndex, sess: &'a Session) -> bool {
10521045
self.root
10531046
.tables

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
490490
.alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE))
491491
},
492492
crates: |tcx, ()| {
493+
// The list of loaded crates is now frozen in query cache,
494+
// so make sure cstore is not mutably accessed from here on.
495+
tcx.untracked().cstore.leak();
493496
tcx.arena.alloc_from_iter(CStore::from_tcx(tcx).iter_crate_data().map(|(cnum, _)| cnum))
494497
},
495498
..*providers
@@ -537,16 +540,16 @@ impl CStore {
537540
)
538541
}
539542

540-
pub fn get_span_untracked(&self, def_id: DefId, sess: &Session) -> Span {
543+
pub fn def_span_untracked(&self, def_id: DefId, sess: &Session) -> Span {
541544
self.get_crate_data(def_id.krate).get_span(def_id.index, sess)
542545
}
543546

544-
pub fn def_kind(&self, def: DefId) -> DefKind {
547+
pub fn def_kind_untracked(&self, def: DefId) -> DefKind {
545548
self.get_crate_data(def.krate).def_kind(def.index)
546549
}
547550

548-
pub fn module_expansion_untracked(&self, def_id: DefId, sess: &Session) -> ExpnId {
549-
self.get_crate_data(def_id.krate).module_expansion(def_id.index, sess)
551+
pub fn expn_that_defined_untracked(&self, def_id: DefId, sess: &Session) -> ExpnId {
552+
self.get_crate_data(def_id.krate).get_expn_that_defined(def_id.index, sess)
550553
}
551554

552555
/// Only public-facing way to traverse all the definitions in a non-local crate.

compiler/rustc_resolve/src/build_reduced_graph.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
114114
}
115115

116116
if !def_id.is_local() {
117-
let def_kind = self.cstore().def_kind(def_id);
117+
// Query `def_kind` is not used because query system overhead is too expensive here.
118+
let def_kind = self.cstore().def_kind_untracked(def_id);
118119
if let DefKind::Mod | DefKind::Enum | DefKind::Trait = def_kind {
119120
let parent = self
120121
.tcx
121122
.opt_parent(def_id)
122123
.map(|parent_id| self.get_nearest_non_block_module(parent_id));
123-
let expn_id = self.cstore().module_expansion_untracked(def_id, &self.tcx.sess);
124+
// Query `expn_that_defined` is not used because
125+
// hashing spans in its result is expensive.
126+
let expn_id = self.cstore().expn_that_defined_untracked(def_id, &self.tcx.sess);
124127
return Some(self.new_module(
125128
parent,
126129
ModuleKind::Def(def_kind, def_id, self.tcx.item_name(def_id)),
@@ -194,6 +197,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
194197
}
195198

196199
pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) {
200+
// Query `module_children` is not used because hashing spans in its result is expensive.
197201
let children =
198202
Vec::from_iter(self.cstore().module_children_untracked(module.def_id(), self.tcx.sess));
199203
for child in children {

compiler/rustc_resolve/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
18751875
fn def_span(&self, def_id: DefId) -> Span {
18761876
match def_id.as_local() {
18771877
Some(def_id) => self.tcx.source_span(def_id),
1878-
None => self.cstore().get_span_untracked(def_id, self.tcx.sess),
1878+
// Query `def_span` is not used because hashing its result span is expensive.
1879+
None => self.cstore().def_span_untracked(def_id, self.tcx.sess),
18791880
}
18801881
}
18811882

0 commit comments

Comments
 (0)