Skip to content

Commit ff4a5fb

Browse files
authored
Rollup merge of #110333 - petrochenkov:notagain, r=compiler-errors
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.
2 parents 1151ea6 + cbc6ccb commit ff4a5fb

File tree

5 files changed

+27
-29
lines changed

5 files changed

+27
-29
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -876,16 +876,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
876876
variant_did,
877877
ctor,
878878
data.discr,
879-
self.root
880-
.tables
881-
.children
882-
.get(self, index)
883-
.expect("fields are not encoded for a variant")
884-
.decode(self)
885-
.map(|index| ty::FieldDef {
886-
did: self.local_def_id(index),
887-
name: self.item_name(index),
888-
vis: self.get_visibility(index),
879+
self.get_associated_item_or_field_def_ids(index)
880+
.map(|did| ty::FieldDef {
881+
did,
882+
name: self.item_name(did.index),
883+
vis: self.get_visibility(did.index),
889884
})
890885
.collect(),
891886
adt_kind,
@@ -910,7 +905,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
910905
let variants = if let ty::AdtKind::Enum = adt_kind {
911906
self.root
912907
.tables
913-
.children
908+
.module_children_non_reexports
914909
.get(self, item_id)
915910
.expect("variants are not encoded for an enum")
916911
.decode(self)
@@ -1022,11 +1017,9 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10221017
}
10231018
} else {
10241019
// Iterate over all children.
1025-
for child_index in self.root.tables.children.get(self, id).unwrap().decode(self) {
1026-
// FIXME: Do not encode RPITITs as a part of this list.
1027-
if self.root.tables.opt_rpitit_info.get(self, child_index).is_none() {
1028-
yield self.get_mod_child(child_index, sess);
1029-
}
1020+
let non_reexports = self.root.tables.module_children_non_reexports.get(self, id);
1021+
for child_index in non_reexports.unwrap().decode(self) {
1022+
yield self.get_mod_child(child_index, sess);
10301023
}
10311024

10321025
let reexports = self.root.tables.module_children_reexports.get(self, id);
@@ -1058,17 +1051,16 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10581051
.map_or(false, |ident| ident.name == kw::SelfLower)
10591052
}
10601053

1061-
fn get_associated_item_def_ids(
1054+
fn get_associated_item_or_field_def_ids(
10621055
self,
10631056
id: DefIndex,
1064-
sess: &'a Session,
10651057
) -> impl Iterator<Item = DefId> + 'a {
10661058
self.root
10671059
.tables
1068-
.children
1060+
.associated_item_or_field_def_ids
10691061
.get(self, id)
1070-
.expect("associated items not encoded for an item")
1071-
.decode((self, sess))
1062+
.unwrap_or_else(|| self.missing("associated_item_or_field_def_ids", id))
1063+
.decode(self)
10721064
.map(move |child_index| self.local_def_id(child_index))
10731065
}
10741066

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ provide! { tcx, def_id, other, cdata,
276276
tcx.calculate_dtor(def_id, |_,_| Ok(()))
277277
}
278278
associated_item_def_ids => {
279-
tcx.arena.alloc_from_iter(cdata.get_associated_item_def_ids(def_id.index, tcx.sess))
279+
tcx.arena.alloc_from_iter(cdata.get_associated_item_or_field_def_ids(def_id.index))
280280
}
281281
associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) }
282282
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13671367

13681368
if adt_def.is_enum() {
13691369
let module_children = tcx.module_children_non_reexports(local_def_id);
1370-
record_array!(self.tables.children[def_id] <-
1370+
record_array!(self.tables.module_children_non_reexports[def_id] <-
13711371
module_children.iter().map(|def_id| def_id.local_def_index));
13721372
} else {
13731373
// 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> {
13851385
record!(self.tables.variant_data[variant.def_id] <- data);
13861386

13871387
self.tables.constness.set_some(variant.def_id.index, hir::Constness::Const);
1388-
record_array!(self.tables.children[variant.def_id] <- variant.fields.iter().map(|f| {
1388+
record_array!(self.tables.associated_item_or_field_def_ids[variant.def_id] <- variant.fields.iter().map(|f| {
13891389
assert!(f.did.is_local());
13901390
f.did.index
13911391
}));
@@ -1415,7 +1415,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14151415
record!(self.tables.expn_that_defined[def_id] <- tcx.expn_that_defined(local_def_id));
14161416
} else {
14171417
let non_reexports = tcx.module_children_non_reexports(local_def_id);
1418-
record_array!(self.tables.children[def_id] <-
1418+
record_array!(self.tables.module_children_non_reexports[def_id] <-
14191419
non_reexports.iter().map(|def_id| def_id.local_def_index));
14201420

14211421
record_defaulted_array!(self.tables.module_children_reexports[def_id] <-
@@ -1617,7 +1617,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16171617
debug!("EncodeContext::encode_info_for_item({:?})", def_id);
16181618

16191619
let record_associated_item_def_ids = |this: &mut Self, def_ids: &[DefId]| {
1620-
record_array!(this.tables.children[def_id] <- def_ids.iter().map(|&def_id| {
1620+
record_array!(this.tables.associated_item_or_field_def_ids[def_id] <- def_ids.iter().map(|&def_id| {
16211621
assert!(def_id.is_local());
16221622
def_id.index
16231623
}))
@@ -1678,6 +1678,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16781678
hir::ItemKind::Trait(..) => {
16791679
record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
16801680

1681+
let module_children = tcx.module_children_non_reexports(item.owner_id.def_id);
1682+
record_array!(self.tables.module_children_non_reexports[def_id] <-
1683+
module_children.iter().map(|def_id| def_id.local_def_index));
1684+
16811685
let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
16821686
record_associated_item_def_ids(self, associated_item_def_ids);
16831687
for &item_def_id in associated_item_def_ids {

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ define_tables! {
361361

362362
- optional:
363363
attributes: Table<DefIndex, LazyArray<ast::Attribute>>,
364-
children: Table<DefIndex, LazyArray<DefIndex>>,
364+
module_children_non_reexports: Table<DefIndex, LazyArray<DefIndex>>,
365+
associated_item_or_field_def_ids: Table<DefIndex, LazyArray<DefIndex>>,
365366
opt_def_kind: Table<DefIndex, DefKind>,
366367
visibility: Table<DefIndex, LazyValue<ty::Visibility<DefIndex>>>,
367368
def_span: Table<DefIndex, LazyValue<Span>>,

compiler/rustc_middle/src/query/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,10 @@ rustc_queries! {
670670
desc { "computing the inferred outlives predicates for items in this crate" }
671671
}
672672

673-
/// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
673+
/// Maps from an impl/trait or struct/variant `DefId`
674+
/// to a list of the `DefId`s of its associated items or fields.
674675
query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
675-
desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
676+
desc { |tcx| "collecting associated items or fields of `{}`", tcx.def_path_str(key) }
676677
cache_on_disk_if { key.is_local() }
677678
separate_provide_extern
678679
}

0 commit comments

Comments
 (0)