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 https://github.com/rust-lang/rust/pull/108346. r? `@cjgillot`
This commit is contained in:
commit
4d21d302a1
4 changed files with 15 additions and 14 deletions
|
@ -1041,13 +1041,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
self.root.tables.optimized_mir.get(self, id).is_some()
|
self.root.tables.optimized_mir.get(self, id).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn module_expansion(self, id: DefIndex, sess: &Session) -> ExpnId {
|
|
||||||
match self.def_kind(id) {
|
|
||||||
DefKind::Mod | DefKind::Enum | DefKind::Trait => self.get_expn_that_defined(id, sess),
|
|
||||||
_ => panic!("Expected module, found {:?}", self.local_def_id(id)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_fn_has_self_parameter(self, id: DefIndex, sess: &'a Session) -> bool {
|
fn get_fn_has_self_parameter(self, id: DefIndex, sess: &'a Session) -> bool {
|
||||||
self.root
|
self.root
|
||||||
.tables
|
.tables
|
||||||
|
|
|
@ -490,6 +490,9 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
|
||||||
.alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE))
|
.alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE))
|
||||||
},
|
},
|
||||||
crates: |tcx, ()| {
|
crates: |tcx, ()| {
|
||||||
|
// The list of loaded crates is now frozen in query cache,
|
||||||
|
// so make sure cstore is not mutably accessed from here on.
|
||||||
|
tcx.untracked().cstore.leak();
|
||||||
tcx.arena.alloc_from_iter(CStore::from_tcx(tcx).iter_crate_data().map(|(cnum, _)| cnum))
|
tcx.arena.alloc_from_iter(CStore::from_tcx(tcx).iter_crate_data().map(|(cnum, _)| cnum))
|
||||||
},
|
},
|
||||||
..*providers
|
..*providers
|
||||||
|
@ -537,16 +540,16 @@ impl CStore {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_span_untracked(&self, def_id: DefId, sess: &Session) -> Span {
|
pub fn def_span_untracked(&self, def_id: DefId, sess: &Session) -> Span {
|
||||||
self.get_crate_data(def_id.krate).get_span(def_id.index, sess)
|
self.get_crate_data(def_id.krate).get_span(def_id.index, sess)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn def_kind(&self, def: DefId) -> DefKind {
|
pub fn def_kind_untracked(&self, def: DefId) -> DefKind {
|
||||||
self.get_crate_data(def.krate).def_kind(def.index)
|
self.get_crate_data(def.krate).def_kind(def.index)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn module_expansion_untracked(&self, def_id: DefId, sess: &Session) -> ExpnId {
|
pub fn expn_that_defined_untracked(&self, def_id: DefId, sess: &Session) -> ExpnId {
|
||||||
self.get_crate_data(def_id.krate).module_expansion(def_id.index, sess)
|
self.get_crate_data(def_id.krate).get_expn_that_defined(def_id.index, sess)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Only public-facing way to traverse all the definitions in a non-local crate.
|
/// Only public-facing way to traverse all the definitions in a non-local crate.
|
||||||
|
|
|
@ -114,13 +114,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !def_id.is_local() {
|
if !def_id.is_local() {
|
||||||
let def_kind = self.cstore().def_kind(def_id);
|
// Query `def_kind` is not used because query system overhead is too expensive here.
|
||||||
|
let def_kind = self.cstore().def_kind_untracked(def_id);
|
||||||
if let DefKind::Mod | DefKind::Enum | DefKind::Trait = def_kind {
|
if let DefKind::Mod | DefKind::Enum | DefKind::Trait = def_kind {
|
||||||
let parent = self
|
let parent = self
|
||||||
.tcx
|
.tcx
|
||||||
.opt_parent(def_id)
|
.opt_parent(def_id)
|
||||||
.map(|parent_id| self.get_nearest_non_block_module(parent_id));
|
.map(|parent_id| self.get_nearest_non_block_module(parent_id));
|
||||||
let expn_id = self.cstore().module_expansion_untracked(def_id, &self.tcx.sess);
|
// Query `expn_that_defined` is not used because
|
||||||
|
// hashing spans in its result is expensive.
|
||||||
|
let expn_id = self.cstore().expn_that_defined_untracked(def_id, &self.tcx.sess);
|
||||||
return Some(self.new_module(
|
return Some(self.new_module(
|
||||||
parent,
|
parent,
|
||||||
ModuleKind::Def(def_kind, def_id, self.tcx.item_name(def_id)),
|
ModuleKind::Def(def_kind, def_id, self.tcx.item_name(def_id)),
|
||||||
|
@ -194,6 +197,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) {
|
pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) {
|
||||||
|
// Query `module_children` is not used because hashing spans in its result is expensive.
|
||||||
let children =
|
let children =
|
||||||
Vec::from_iter(self.cstore().module_children_untracked(module.def_id(), self.tcx.sess));
|
Vec::from_iter(self.cstore().module_children_untracked(module.def_id(), self.tcx.sess));
|
||||||
for child in children {
|
for child in children {
|
||||||
|
|
|
@ -1875,7 +1875,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
fn def_span(&self, def_id: DefId) -> Span {
|
fn def_span(&self, def_id: DefId) -> Span {
|
||||||
match def_id.as_local() {
|
match def_id.as_local() {
|
||||||
Some(def_id) => self.tcx.source_span(def_id),
|
Some(def_id) => self.tcx.source_span(def_id),
|
||||||
None => self.cstore().get_span_untracked(def_id, self.tcx.sess),
|
// Query `def_span` is not used because hashing its result span is expensive.
|
||||||
|
None => self.cstore().def_span_untracked(def_id, self.tcx.sess),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue