Skip to content

Commit

Permalink
Drop ImplData.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Feb 19, 2022
1 parent c7c306f commit 0b7ee3a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 76 deletions.
27 changes: 0 additions & 27 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Expand Up @@ -1014,37 +1014,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
self.root.tables.visibility.get(self, id).unwrap().decode(self)
}

fn get_impl_data(self, id: DefIndex) -> ImplData {
match self.kind(id) {
EntryKind::Impl(data) => data.decode(self),
_ => bug!(),
}
}

fn get_parent_impl(self, id: DefIndex) -> Option<DefId> {
self.get_impl_data(id).parent_impl
}

fn get_impl_polarity(self, id: DefIndex) -> ty::ImplPolarity {
self.get_impl_data(id).polarity
}

fn get_impl_defaultness(self, id: DefIndex) -> hir::Defaultness {
self.get_impl_data(id).defaultness
}

fn get_impl_constness(self, id: DefIndex) -> hir::Constness {
self.get_impl_data(id).constness
}

fn get_trait_item_def_id(self, id: DefIndex) -> Option<DefId> {
self.root.tables.trait_item_def_id.get(self, id).map(|d| d.decode(self))
}

fn get_coerce_unsized_info(self, id: DefIndex) -> Option<ty::adjustment::CoerceUnsizedInfo> {
self.get_impl_data(id).coerce_unsized_info
}

fn get_expn_that_defined(self, id: DefIndex, sess: &Session) -> ExpnId {
self.root.tables.expn_that_defined.get(self, id).unwrap().decode((self, sess))
}
Expand Down
14 changes: 5 additions & 9 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Expand Up @@ -131,6 +131,11 @@ provide! { <'tcx> tcx, def_id, other, cdata,
visibility => { table }
unused_generic_params => { table }
opt_def_kind => { table }
impl_parent => { table }
impl_polarity => { table }
impl_defaultness => { table }
impl_constness => { table }
coerce_unsized_info => { table }

trait_def => { cdata.get_trait_def(def_id.index, tcx.sess) }
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
Expand All @@ -140,12 +145,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
}
associated_item_def_ids => { cdata.get_associated_item_def_ids(tcx, def_id.index) }
associated_item => { cdata.get_associated_item(def_id.index) }
impl_polarity => { cdata.get_impl_polarity(def_id.index) }
coerce_unsized_info => {
cdata.get_coerce_unsized_info(def_id.index).unwrap_or_else(|| {
bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
})
}
mir_const_qualif => { cdata.mir_const_qualif(def_id.index) }
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
is_const_fn_raw => { cdata.is_const_fn_raw(def_id.index) }
Expand All @@ -156,7 +155,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
fn_arg_names => { cdata.get_fn_param_names(tcx, def_id.index) }
rendered_const => { cdata.get_rendered_const(def_id.index) }
impl_parent => { cdata.get_parent_impl(def_id.index) }
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
Expand All @@ -176,8 +174,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
}
is_no_builtins => { cdata.root.no_builtins }
symbol_mangling_version => { cdata.root.symbol_mangling_version }
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
impl_constness => { cdata.get_impl_constness(def_id.index) }
reachable_non_generics => {
let reachable_non_generics = tcx
.exported_symbols(cdata.cnum)
Expand Down
46 changes: 19 additions & 27 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Expand Up @@ -1468,39 +1468,31 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
)
}
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
record!(self.tables.impl_defaultness[def_id] <- defaultness);
record!(self.tables.impl_constness[def_id] <- constness);

let trait_ref = self.tcx.impl_trait_ref(def_id);
let polarity = self.tcx.impl_polarity(def_id);
let parent = if let Some(trait_ref) = trait_ref {
if let Some(trait_ref) = trait_ref {
let trait_def = self.tcx.trait_def(trait_ref.def_id);
trait_def.ancestors(self.tcx, def_id).ok().and_then(|mut an| {
an.nth(1).and_then(|node| match node {
specialization_graph::Node::Impl(parent) => Some(parent),
_ => None,
})
})
} else {
None
};
if let Some(mut an) = trait_def.ancestors(self.tcx, def_id).ok() {
if let Some(specialization_graph::Node::Impl(parent)) = an.nth(1) {
record!(self.tables.impl_parent[def_id] <- parent);
}
}

// if this is an impl of `CoerceUnsized`, create its
// "unsized info", else just store None
let coerce_unsized_info = trait_ref.and_then(|t| {
if Some(t.def_id) == self.tcx.lang_items().coerce_unsized_trait() {
Some(self.tcx.at(item.span).coerce_unsized_info(def_id))
} else {
None
// if this is an impl of `CoerceUnsized`, create its
// "unsized info", else just store None
if Some(trait_ref.def_id) == self.tcx.lang_items().coerce_unsized_trait() {
let coerce_unsized_info =
self.tcx.at(item.span).coerce_unsized_info(def_id);
record!(self.tables.coerce_unsized_info[def_id] <- coerce_unsized_info);
}
});
}

let data = ImplData {
polarity,
defaultness,
constness,
parent_impl: parent,
coerce_unsized_info,
};
let polarity = self.tcx.impl_polarity(def_id);
record!(self.tables.impl_polarity[def_id] <- polarity);

EntryKind::Impl(self.lazy(data))
EntryKind::Impl
}
hir::ItemKind::Trait(..) => {
let trait_def = self.tcx.trait_def(def_id);
Expand Down
20 changes: 7 additions & 13 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Expand Up @@ -302,6 +302,12 @@ define_tables! {
mir_for_ctfe: Table<DefIndex, Lazy!(mir::Body<'tcx>)>,
promoted_mir: Table<DefIndex, Lazy!(IndexVec<mir::Promoted, mir::Body<'tcx>>)>,
thir_abstract_const: Table<DefIndex, Lazy!(&'tcx [thir::abstract_const::Node<'tcx>])>,
impl_parent: Table<DefIndex, Lazy!(DefId)>,
impl_polarity: Table<DefIndex, Lazy!(ty::ImplPolarity)>,
impl_constness: Table<DefIndex, Lazy!(hir::Constness)>,
impl_defaultness: Table<DefIndex, Lazy!(hir::Defaultness)>,
// FIXME(eddyb) perhaps compute this on the fly if cheap enough?
coerce_unsized_info: Table<DefIndex, Lazy!(ty::adjustment::CoerceUnsizedInfo)>,

trait_item_def_id: Table<DefIndex, Lazy<DefId>>,
inherent_impls: Table<DefIndex, Lazy<[DefIndex]>>,
Expand Down Expand Up @@ -344,7 +350,7 @@ enum EntryKind {
Closure,
Generator(hir::GeneratorKind),
Trait(Lazy<TraitData>),
Impl(Lazy<ImplData>),
Impl,
AssocFn(Lazy<AssocFnData>),
AssocType(AssocContainer),
AssocConst(AssocContainer, mir::ConstQualifs, Lazy<RenderedConst>),
Expand Down Expand Up @@ -383,18 +389,6 @@ struct TraitData {
must_implement_one_of: Option<Box<[Ident]>>,
}

#[derive(TyEncodable, TyDecodable)]
struct ImplData {
polarity: ty::ImplPolarity,
constness: hir::Constness,
defaultness: hir::Defaultness,
parent_impl: Option<DefId>,

/// This is `Some` only for impls of `CoerceUnsized`.
// FIXME(eddyb) perhaps compute this on the fly if cheap enough?
coerce_unsized_info: Option<ty::adjustment::CoerceUnsizedInfo>,
}

/// Describes whether the container of an associated item
/// is a trait or an impl and whether, in a trait, it has
/// a default, or an in impl, whether it's marked "default".
Expand Down

0 comments on commit 0b7ee3a

Please sign in to comment.