mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
rustc_metadata: Split children
into multiple tables
instead of merging everything into a single bag. If it's acceptable from performance point of view, then it's more clear to keep this stuff organized more in accordance with its use.
This commit is contained in:
parent
1f5768bc67
commit
cbc6ccb191
@ -876,16 +876,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||
variant_did,
|
||||
ctor,
|
||||
data.discr,
|
||||
self.root
|
||||
.tables
|
||||
.children
|
||||
.get(self, index)
|
||||
.expect("fields are not encoded for a variant")
|
||||
.decode(self)
|
||||
.map(|index| ty::FieldDef {
|
||||
did: self.local_def_id(index),
|
||||
name: self.item_name(index),
|
||||
vis: self.get_visibility(index),
|
||||
self.get_associated_item_or_field_def_ids(index)
|
||||
.map(|did| ty::FieldDef {
|
||||
did,
|
||||
name: self.item_name(did.index),
|
||||
vis: self.get_visibility(did.index),
|
||||
})
|
||||
.collect(),
|
||||
adt_kind,
|
||||
@ -910,7 +905,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||
let variants = if let ty::AdtKind::Enum = adt_kind {
|
||||
self.root
|
||||
.tables
|
||||
.children
|
||||
.module_children_non_reexports
|
||||
.get(self, item_id)
|
||||
.expect("variants are not encoded for an enum")
|
||||
.decode(self)
|
||||
@ -1022,11 +1017,9 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||
}
|
||||
} else {
|
||||
// Iterate over all children.
|
||||
for child_index in self.root.tables.children.get(self, id).unwrap().decode(self) {
|
||||
// FIXME: Do not encode RPITITs as a part of this list.
|
||||
if self.root.tables.opt_rpitit_info.get(self, child_index).is_none() {
|
||||
yield self.get_mod_child(child_index, sess);
|
||||
}
|
||||
let non_reexports = self.root.tables.module_children_non_reexports.get(self, id);
|
||||
for child_index in non_reexports.unwrap().decode(self) {
|
||||
yield self.get_mod_child(child_index, sess);
|
||||
}
|
||||
|
||||
let reexports = self.root.tables.module_children_reexports.get(self, id);
|
||||
@ -1058,17 +1051,16 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||
.map_or(false, |ident| ident.name == kw::SelfLower)
|
||||
}
|
||||
|
||||
fn get_associated_item_def_ids(
|
||||
fn get_associated_item_or_field_def_ids(
|
||||
self,
|
||||
id: DefIndex,
|
||||
sess: &'a Session,
|
||||
) -> impl Iterator<Item = DefId> + 'a {
|
||||
self.root
|
||||
.tables
|
||||
.children
|
||||
.associated_item_or_field_def_ids
|
||||
.get(self, id)
|
||||
.expect("associated items not encoded for an item")
|
||||
.decode((self, sess))
|
||||
.unwrap_or_else(|| self.missing("associated_item_or_field_def_ids", id))
|
||||
.decode(self)
|
||||
.map(move |child_index| self.local_def_id(child_index))
|
||||
}
|
||||
|
||||
|
@ -276,7 +276,7 @@ provide! { tcx, def_id, other, cdata,
|
||||
tcx.calculate_dtor(def_id, |_,_| Ok(()))
|
||||
}
|
||||
associated_item_def_ids => {
|
||||
tcx.arena.alloc_from_iter(cdata.get_associated_item_def_ids(def_id.index, tcx.sess))
|
||||
tcx.arena.alloc_from_iter(cdata.get_associated_item_or_field_def_ids(def_id.index))
|
||||
}
|
||||
associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) }
|
||||
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
|
||||
|
@ -1367,7 +1367,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
|
||||
if adt_def.is_enum() {
|
||||
let module_children = tcx.module_children_non_reexports(local_def_id);
|
||||
record_array!(self.tables.children[def_id] <-
|
||||
record_array!(self.tables.module_children_non_reexports[def_id] <-
|
||||
module_children.iter().map(|def_id| def_id.local_def_index));
|
||||
} else {
|
||||
// For non-enum, there is only one variant, and its def_id is the adt's.
|
||||
@ -1385,7 +1385,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
record!(self.tables.variant_data[variant.def_id] <- data);
|
||||
|
||||
self.tables.constness.set_some(variant.def_id.index, hir::Constness::Const);
|
||||
record_array!(self.tables.children[variant.def_id] <- variant.fields.iter().map(|f| {
|
||||
record_array!(self.tables.associated_item_or_field_def_ids[variant.def_id] <- variant.fields.iter().map(|f| {
|
||||
assert!(f.did.is_local());
|
||||
f.did.index
|
||||
}));
|
||||
@ -1415,7 +1415,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
record!(self.tables.expn_that_defined[def_id] <- tcx.expn_that_defined(local_def_id));
|
||||
} else {
|
||||
let non_reexports = tcx.module_children_non_reexports(local_def_id);
|
||||
record_array!(self.tables.children[def_id] <-
|
||||
record_array!(self.tables.module_children_non_reexports[def_id] <-
|
||||
non_reexports.iter().map(|def_id| def_id.local_def_index));
|
||||
|
||||
record_defaulted_array!(self.tables.module_children_reexports[def_id] <-
|
||||
@ -1617,7 +1617,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
debug!("EncodeContext::encode_info_for_item({:?})", def_id);
|
||||
|
||||
let record_associated_item_def_ids = |this: &mut Self, def_ids: &[DefId]| {
|
||||
record_array!(this.tables.children[def_id] <- def_ids.iter().map(|&def_id| {
|
||||
record_array!(this.tables.associated_item_or_field_def_ids[def_id] <- def_ids.iter().map(|&def_id| {
|
||||
assert!(def_id.is_local());
|
||||
def_id.index
|
||||
}))
|
||||
@ -1678,6 +1678,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
hir::ItemKind::Trait(..) => {
|
||||
record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
|
||||
|
||||
let module_children = tcx.module_children_non_reexports(item.owner_id.def_id);
|
||||
record_array!(self.tables.module_children_non_reexports[def_id] <-
|
||||
module_children.iter().map(|def_id| def_id.local_def_index));
|
||||
|
||||
let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
|
||||
record_associated_item_def_ids(self, associated_item_def_ids);
|
||||
for &item_def_id in associated_item_def_ids {
|
||||
|
@ -361,7 +361,8 @@ define_tables! {
|
||||
|
||||
- optional:
|
||||
attributes: Table<DefIndex, LazyArray<ast::Attribute>>,
|
||||
children: Table<DefIndex, LazyArray<DefIndex>>,
|
||||
module_children_non_reexports: Table<DefIndex, LazyArray<DefIndex>>,
|
||||
associated_item_or_field_def_ids: Table<DefIndex, LazyArray<DefIndex>>,
|
||||
opt_def_kind: Table<DefIndex, DefKind>,
|
||||
visibility: Table<DefIndex, LazyValue<ty::Visibility<DefIndex>>>,
|
||||
def_span: Table<DefIndex, LazyValue<Span>>,
|
||||
|
@ -670,9 +670,10 @@ rustc_queries! {
|
||||
desc { "computing the inferred outlives predicates for items in this crate" }
|
||||
}
|
||||
|
||||
/// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
|
||||
/// Maps from an impl/trait or struct/variant `DefId`
|
||||
/// to a list of the `DefId`s of its associated items or fields.
|
||||
query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
|
||||
desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
|
||||
desc { |tcx| "collecting associated items or fields of `{}`", tcx.def_path_str(key) }
|
||||
cache_on_disk_if { key.is_local() }
|
||||
separate_provide_extern
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user