rustc_metadata: Switch module children decoding to an iterator
This commit is contained in:
parent
f3b5791a47
commit
6a233b5e2a
@ -35,11 +35,10 @@ use rustc_span::symbol::{kw, Ident, Symbol};
|
|||||||
use rustc_span::{self, BytePos, ExpnId, Pos, Span, SyntaxContext, DUMMY_SP};
|
use rustc_span::{self, BytePos, ExpnId, Pos, Span, SyntaxContext, DUMMY_SP};
|
||||||
|
|
||||||
use proc_macro::bridge::client::ProcMacro;
|
use proc_macro::bridge::client::ProcMacro;
|
||||||
use std::io;
|
|
||||||
use std::iter::TrustedLen;
|
use std::iter::TrustedLen;
|
||||||
use std::mem;
|
|
||||||
use std::num::NonZeroUsize;
|
use std::num::NonZeroUsize;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::{io, iter, mem};
|
||||||
|
|
||||||
pub(super) use cstore_impl::provide;
|
pub(super) use cstore_impl::provide;
|
||||||
pub use cstore_impl::provide_extern;
|
pub use cstore_impl::provide_extern;
|
||||||
@ -994,12 +993,12 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
|||||||
/// including both proper items and reexports.
|
/// including both proper items and reexports.
|
||||||
/// Module here is understood in name resolution sense - it can be a `mod` item,
|
/// Module here is understood in name resolution sense - it can be a `mod` item,
|
||||||
/// or a crate root, or an enum, or a trait.
|
/// or a crate root, or an enum, or a trait.
|
||||||
fn for_each_module_child(
|
fn get_module_children(
|
||||||
self,
|
self,
|
||||||
id: DefIndex,
|
id: DefIndex,
|
||||||
mut callback: impl FnMut(ModChild),
|
sess: &'a Session,
|
||||||
sess: &Session,
|
) -> impl Iterator<Item = ModChild> + 'a {
|
||||||
) {
|
iter::from_generator(move || {
|
||||||
if let Some(data) = &self.root.proc_macro_data {
|
if let Some(data) = &self.root.proc_macro_data {
|
||||||
// If we are loading as a proc macro, we want to return
|
// If we are loading as a proc macro, we want to return
|
||||||
// the view of this crate as a proc macro crate.
|
// the view of this crate as a proc macro crate.
|
||||||
@ -1011,13 +1010,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
|||||||
self.local_def_id(def_index),
|
self.local_def_id(def_index),
|
||||||
);
|
);
|
||||||
let ident = self.item_ident(def_index, sess);
|
let ident = self.item_ident(def_index, sess);
|
||||||
callback(ModChild {
|
yield ModChild {
|
||||||
ident,
|
ident,
|
||||||
res,
|
res,
|
||||||
vis: ty::Visibility::Public,
|
vis: ty::Visibility::Public,
|
||||||
span: ident.span,
|
span: ident.span,
|
||||||
macro_rules: false,
|
macro_rules: false,
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -1039,15 +1038,16 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
|||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
callback(ModChild { ident, res, vis, span, macro_rules });
|
yield ModChild { ident, res, vis, span, macro_rules };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(exports) = self.root.tables.module_reexports.get(self, id) {
|
if let Some(exports) = self.root.tables.module_reexports.get(self, id) {
|
||||||
for exp in exports.decode((self, sess)) {
|
for exp in exports.decode((self, sess)) {
|
||||||
callback(exp);
|
yield exp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_ctfe_mir_available(self, id: DefIndex) -> bool {
|
fn is_ctfe_mir_available(self, id: DefIndex) -> bool {
|
||||||
|
@ -21,7 +21,6 @@ use rustc_span::source_map::{Span, Spanned};
|
|||||||
use rustc_span::symbol::{kw, Symbol};
|
use rustc_span::symbol::{kw, Symbol};
|
||||||
|
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use smallvec::SmallVec;
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
|
||||||
use super::{Decodable, DecodeContext, DecodeIterator};
|
use super::{Decodable, DecodeContext, DecodeIterator};
|
||||||
@ -298,9 +297,7 @@ provide! { tcx, def_id, other, cdata,
|
|||||||
r
|
r
|
||||||
}
|
}
|
||||||
module_children => {
|
module_children => {
|
||||||
let mut result = SmallVec::<[_; 8]>::new();
|
tcx.arena.alloc_from_iter(cdata.get_module_children(def_id.index, tcx.sess))
|
||||||
cdata.for_each_module_child(def_id.index, |child| result.push(child), tcx.sess);
|
|
||||||
tcx.arena.alloc_slice(&result)
|
|
||||||
}
|
}
|
||||||
defined_lib_features => { cdata.get_lib_features(tcx) }
|
defined_lib_features => { cdata.get_lib_features(tcx) }
|
||||||
stability_implications => {
|
stability_implications => {
|
||||||
@ -503,14 +500,12 @@ impl CStore {
|
|||||||
self.get_crate_data(def.krate).get_visibility(def.index)
|
self.get_crate_data(def.krate).get_visibility(def.index)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn module_children_untracked(&self, def_id: DefId, sess: &Session) -> Vec<ModChild> {
|
pub fn module_children_untracked<'a>(
|
||||||
let mut result = vec![];
|
&'a self,
|
||||||
self.get_crate_data(def_id.krate).for_each_module_child(
|
def_id: DefId,
|
||||||
def_id.index,
|
sess: &'a Session,
|
||||||
|child| result.push(child),
|
) -> impl Iterator<Item = ModChild> + 'a {
|
||||||
sess,
|
self.get_crate_data(def_id.krate).get_module_children(def_id.index, sess)
|
||||||
);
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro {
|
pub fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro {
|
||||||
|
@ -204,7 +204,9 @@ impl<'a> Resolver<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) {
|
pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) {
|
||||||
for child in self.cstore().module_children_untracked(module.def_id(), self.session) {
|
for child in
|
||||||
|
Vec::from_iter(self.cstore().module_children_untracked(module.def_id(), self.session))
|
||||||
|
{
|
||||||
let parent_scope = ParentScope::module(module, self);
|
let parent_scope = ParentScope::module(module, self);
|
||||||
BuildReducedGraphVisitor { r: self, parent_scope }
|
BuildReducedGraphVisitor { r: self, parent_scope }
|
||||||
.build_reduced_graph_for_external_crate_res(child);
|
.build_reduced_graph_for_external_crate_res(child);
|
||||||
|
@ -1920,7 +1920,7 @@ impl<'a> Resolver<'a> {
|
|||||||
if let Some(def_id) = def_id.as_local() {
|
if let Some(def_id) = def_id.as_local() {
|
||||||
self.reexport_map.get(&def_id).cloned().unwrap_or_default()
|
self.reexport_map.get(&def_id).cloned().unwrap_or_default()
|
||||||
} else {
|
} else {
|
||||||
self.cstore().module_children_untracked(def_id, self.session)
|
self.cstore().module_children_untracked(def_id, self.session).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user