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:
commit
442248d6bc
2 changed files with 20 additions and 44 deletions
|
@ -1104,42 +1104,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
let children = self.root.tables.children.get(self, id).unwrap_or_else(Lazy::empty);
|
let children = self.root.tables.children.get(self, id).unwrap_or_else(Lazy::empty);
|
||||||
|
|
||||||
for child_index in children.decode((self, sess)) {
|
for child_index in children.decode((self, sess)) {
|
||||||
// Get the item.
|
// FIXME: Merge with the logic below.
|
||||||
let child_kind = match self.maybe_kind(child_index) {
|
if let None | Some(EntryKind::ForeignMod | EntryKind::Impl(_)) =
|
||||||
Some(child_kind) => child_kind,
|
self.maybe_kind(child_index)
|
||||||
None => continue,
|
{
|
||||||
};
|
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,
|
|
||||||
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let def_key = self.def_key(child_index);
|
let def_key = self.def_key(child_index);
|
||||||
|
|
|
@ -1100,9 +1100,21 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
// Encode this here because we don't do it in encode_def_ids.
|
// 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));
|
record!(self.tables.expn_that_defined[def_id] <- tcx.expn_that_defined(local_def_id));
|
||||||
} else {
|
} else {
|
||||||
record!(self.tables.children[def_id] <- md.item_ids.iter().map(|item_id| {
|
let direct_children = md.item_ids.iter().map(|item_id| item_id.def_id.local_def_index);
|
||||||
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 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
record!(self.tables.kind[def_id] <- entry_kind);
|
record!(self.tables.kind[def_id] <- entry_kind);
|
||||||
// FIXME(eddyb) there should be a nicer way to do this.
|
// FIXME(eddyb) there should be a nicer way to do this.
|
||||||
match item.kind {
|
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] <-
|
hir::ItemKind::Enum(..) => record!(self.tables.children[def_id] <-
|
||||||
self.tcx.adt_def(def_id).variants.iter().map(|v| {
|
self.tcx.adt_def(def_id).variants.iter().map(|v| {
|
||||||
assert!(v.def_id.is_local());
|
assert!(v.def_id.is_local());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue