Auto merge of #92153 - petrochenkov:foreignchild, r=cjgillot

rustc_metadata: Merge items from `extern` blocks into their parent modules during metadata encoding rather than during metadata decoding
This commit is contained in:
bors 2021-12-28 13:47:22 +00:00
commit 442248d6bc
2 changed files with 20 additions and 44 deletions

View File

@ -1104,42 +1104,11 @@ fn each_child_of_item(&self, id: DefIndex, mut callback: impl FnMut(Export), ses
let children = self.root.tables.children.get(self, id).unwrap_or_else(Lazy::empty);
for child_index in children.decode((self, sess)) {
// Get the item.
let child_kind = match self.maybe_kind(child_index) {
Some(child_kind) => child_kind,
None => continue,
};
// Hand off the item to the callback.
match child_kind {
// FIXME(eddyb) Don't encode these in children.
EntryKind::ForeignMod => {
let child_children = self
.root
.tables
.children
.get(self, child_index)
.unwrap_or_else(Lazy::empty);
for child_index in child_children.decode((self, sess)) {
let kind = self.def_kind(child_index);
callback(Export {
res: Res::Def(kind, self.local_def_id(child_index)),
ident: self.item_ident(child_index, sess),
vis: self.get_visibility(child_index),
span: self
.root
.tables
.span
.get(self, child_index)
.unwrap()
.decode((self, sess)),
});
}
continue;
}
EntryKind::Impl(_) => continue,
_ => {}
// FIXME: Merge with the logic below.
if let None | Some(EntryKind::ForeignMod | EntryKind::Impl(_)) =
self.maybe_kind(child_index)
{
continue;
}
let def_key = self.def_key(child_index);

View File

@ -1100,9 +1100,21 @@ fn encode_info_for_mod(&mut self, local_def_id: LocalDefId, md: &hir::Mod<'_>) {
// Encode this here because we don't do it in encode_def_ids.
record!(self.tables.expn_that_defined[def_id] <- tcx.expn_that_defined(local_def_id));
} else {
record!(self.tables.children[def_id] <- md.item_ids.iter().map(|item_id| {
item_id.def_id.local_def_index
}));
let direct_children = md.item_ids.iter().map(|item_id| item_id.def_id.local_def_index);
// Foreign items are planted into their parent modules from name resolution point of view.
let tcx = self.tcx;
let foreign_item_children = md
.item_ids
.iter()
.filter_map(|item_id| match tcx.hir().item(*item_id).kind {
hir::ItemKind::ForeignMod { items, .. } => {
Some(items.iter().map(|fi_ref| fi_ref.id.def_id.local_def_index))
}
_ => None,
})
.flatten();
record!(self.tables.children[def_id] <- direct_children.chain(foreign_item_children));
}
}
@ -1503,11 +1515,6 @@ fn encode_info_for_item(&mut self, def_id: DefId, item: &'tcx hir::Item<'tcx>) {
record!(self.tables.kind[def_id] <- entry_kind);
// FIXME(eddyb) there should be a nicer way to do this.
match item.kind {
hir::ItemKind::ForeignMod { items, .. } => record!(self.tables.children[def_id] <-
items
.iter()
.map(|foreign_item| foreign_item.id.def_id.local_def_index)
),
hir::ItemKind::Enum(..) => record!(self.tables.children[def_id] <-
self.tcx.adt_def(def_id).variants.iter().map(|v| {
assert!(v.def_id.is_local());