Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #110648

Merged
merged 10 commits into from
Apr 21, 2023
34 changes: 13 additions & 21 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}));
Expand Down Expand Up @@ -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] <-
Expand Down Expand Up @@ -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
}))
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down