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
5 changed files with 27 additions and 29 deletions
|
@ -876,16 +876,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
variant_did,
|
variant_did,
|
||||||
ctor,
|
ctor,
|
||||||
data.discr,
|
data.discr,
|
||||||
self.root
|
self.get_associated_item_or_field_def_ids(index)
|
||||||
.tables
|
.map(|did| ty::FieldDef {
|
||||||
.children
|
did,
|
||||||
.get(self, index)
|
name: self.item_name(did.index),
|
||||||
.expect("fields are not encoded for a variant")
|
vis: self.get_visibility(did.index),
|
||||||
.decode(self)
|
|
||||||
.map(|index| ty::FieldDef {
|
|
||||||
did: self.local_def_id(index),
|
|
||||||
name: self.item_name(index),
|
|
||||||
vis: self.get_visibility(index),
|
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
adt_kind,
|
adt_kind,
|
||||||
|
@ -910,7 +905,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
let variants = if let ty::AdtKind::Enum = adt_kind {
|
let variants = if let ty::AdtKind::Enum = adt_kind {
|
||||||
self.root
|
self.root
|
||||||
.tables
|
.tables
|
||||||
.children
|
.module_children_non_reexports
|
||||||
.get(self, item_id)
|
.get(self, item_id)
|
||||||
.expect("variants are not encoded for an enum")
|
.expect("variants are not encoded for an enum")
|
||||||
.decode(self)
|
.decode(self)
|
||||||
|
@ -1022,11 +1017,9 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Iterate over all children.
|
// Iterate over all children.
|
||||||
for child_index in self.root.tables.children.get(self, id).unwrap().decode(self) {
|
let non_reexports = self.root.tables.module_children_non_reexports.get(self, id);
|
||||||
// FIXME: Do not encode RPITITs as a part of this list.
|
for child_index in non_reexports.unwrap().decode(self) {
|
||||||
if self.root.tables.opt_rpitit_info.get(self, child_index).is_none() {
|
yield self.get_mod_child(child_index, sess);
|
||||||
yield self.get_mod_child(child_index, sess);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let reexports = self.root.tables.module_children_reexports.get(self, id);
|
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)
|
.map_or(false, |ident| ident.name == kw::SelfLower)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_associated_item_def_ids(
|
fn get_associated_item_or_field_def_ids(
|
||||||
self,
|
self,
|
||||||
id: DefIndex,
|
id: DefIndex,
|
||||||
sess: &'a Session,
|
|
||||||
) -> impl Iterator<Item = DefId> + 'a {
|
) -> impl Iterator<Item = DefId> + 'a {
|
||||||
self.root
|
self.root
|
||||||
.tables
|
.tables
|
||||||
.children
|
.associated_item_or_field_def_ids
|
||||||
.get(self, id)
|
.get(self, id)
|
||||||
.expect("associated items not encoded for an item")
|
.unwrap_or_else(|| self.missing("associated_item_or_field_def_ids", id))
|
||||||
.decode((self, sess))
|
.decode(self)
|
||||||
.map(move |child_index| self.local_def_id(child_index))
|
.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(()))
|
tcx.calculate_dtor(def_id, |_,_| Ok(()))
|
||||||
}
|
}
|
||||||
associated_item_def_ids => {
|
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) }
|
associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) }
|
||||||
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
|
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() {
|
if adt_def.is_enum() {
|
||||||
let module_children = tcx.module_children_non_reexports(local_def_id);
|
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));
|
module_children.iter().map(|def_id| def_id.local_def_index));
|
||||||
} else {
|
} else {
|
||||||
// For non-enum, there is only one variant, and its def_id is the adt's.
|
// 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);
|
record!(self.tables.variant_data[variant.def_id] <- data);
|
||||||
|
|
||||||
self.tables.constness.set_some(variant.def_id.index, hir::Constness::Const);
|
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());
|
assert!(f.did.is_local());
|
||||||
f.did.index
|
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));
|
record!(self.tables.expn_that_defined[def_id] <- tcx.expn_that_defined(local_def_id));
|
||||||
} else {
|
} else {
|
||||||
let non_reexports = tcx.module_children_non_reexports(local_def_id);
|
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));
|
non_reexports.iter().map(|def_id| def_id.local_def_index));
|
||||||
|
|
||||||
record_defaulted_array!(self.tables.module_children_reexports[def_id] <-
|
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);
|
debug!("EncodeContext::encode_info_for_item({:?})", def_id);
|
||||||
|
|
||||||
let record_associated_item_def_ids = |this: &mut Self, def_ids: &[DefId]| {
|
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());
|
assert!(def_id.is_local());
|
||||||
def_id.index
|
def_id.index
|
||||||
}))
|
}))
|
||||||
|
@ -1678,6 +1678,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
hir::ItemKind::Trait(..) => {
|
hir::ItemKind::Trait(..) => {
|
||||||
record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
|
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);
|
let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
|
||||||
record_associated_item_def_ids(self, associated_item_def_ids);
|
record_associated_item_def_ids(self, associated_item_def_ids);
|
||||||
for &item_def_id in associated_item_def_ids {
|
for &item_def_id in associated_item_def_ids {
|
||||||
|
|
|
@ -361,7 +361,8 @@ define_tables! {
|
||||||
|
|
||||||
- optional:
|
- optional:
|
||||||
attributes: Table<DefIndex, LazyArray<ast::Attribute>>,
|
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>,
|
opt_def_kind: Table<DefIndex, DefKind>,
|
||||||
visibility: Table<DefIndex, LazyValue<ty::Visibility<DefIndex>>>,
|
visibility: Table<DefIndex, LazyValue<ty::Visibility<DefIndex>>>,
|
||||||
def_span: Table<DefIndex, LazyValue<Span>>,
|
def_span: Table<DefIndex, LazyValue<Span>>,
|
||||||
|
|
|
@ -670,9 +670,10 @@ rustc_queries! {
|
||||||
desc { "computing the inferred outlives predicates for items in this crate" }
|
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] {
|
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() }
|
cache_on_disk_if { key.is_local() }
|
||||||
separate_provide_extern
|
separate_provide_extern
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue