Skip to content

Commit 71927ad

Browse files
committed
resolve: Rename some cstore methods to match queries and add comments
about costs associated with replacing them with query calls.
1 parent 99c49d9 commit 71927ad

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-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

+4-4
Original file line numberDiff line numberDiff line change
@@ -537,16 +537,16 @@ impl CStore {
537537
)
538538
}
539539

540-
pub fn get_span_untracked(&self, def_id: DefId, sess: &Session) -> Span {
540+
pub fn def_span_untracked(&self, def_id: DefId, sess: &Session) -> Span {
541541
self.get_crate_data(def_id.krate).get_span(def_id.index, sess)
542542
}
543543

544-
pub fn def_kind(&self, def: DefId) -> DefKind {
544+
pub fn def_kind_untracked(&self, def: DefId) -> DefKind {
545545
self.get_crate_data(def.krate).def_kind(def.index)
546546
}
547547

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)
548+
pub fn expn_that_defined_untracked(&self, def_id: DefId, sess: &Session) -> ExpnId {
549+
self.get_crate_data(def_id.krate).get_expn_that_defined(def_id.index, sess)
550550
}
551551

552552
/// 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
@@ -1871,7 +1871,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
18711871
fn def_span(&self, def_id: DefId) -> Span {
18721872
match def_id.as_local() {
18731873
Some(def_id) => self.tcx.source_span(def_id),
1874-
None => self.cstore().get_span_untracked(def_id, self.tcx.sess),
1874+
// Query `def_span` is not used because hashing its result span is expensive.
1875+
None => self.cstore().def_span_untracked(def_id, self.tcx.sess),
18751876
}
18761877
}
18771878

0 commit comments

Comments
 (0)