diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index e77b3ee1d1e93..4036cb9ae95bf 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -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 { - 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 { self.root.tables.trait_item_def_id.get(self, id).map(|d| d.decode(self)) } - fn get_coerce_unsized_info(self, id: DefIndex) -> Option { - 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)) } diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 8427961165dff..430720ac2dba2 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -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) } @@ -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) } @@ -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) } @@ -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) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index c0bf2b60b9c8b..172ba90453693 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -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); diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 6dbab8b0a2783..924f194ce85c2 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -302,6 +302,12 @@ define_tables! { mir_for_ctfe: Table)>, promoted_mir: Table>)>, thir_abstract_const: Table])>, + impl_parent: Table, + impl_polarity: Table, + impl_constness: Table, + impl_defaultness: Table, + // FIXME(eddyb) perhaps compute this on the fly if cheap enough? + coerce_unsized_info: Table, trait_item_def_id: Table>, inherent_impls: Table>, @@ -344,7 +350,7 @@ enum EntryKind { Closure, Generator(hir::GeneratorKind), Trait(Lazy), - Impl(Lazy), + Impl, AssocFn(Lazy), AssocType(AssocContainer), AssocConst(AssocContainer, mir::ConstQualifs, Lazy), @@ -383,18 +389,6 @@ struct TraitData { must_implement_one_of: Option>, } -#[derive(TyEncodable, TyDecodable)] -struct ImplData { - polarity: ty::ImplPolarity, - constness: hir::Constness, - defaultness: hir::Defaultness, - parent_impl: Option, - - /// This is `Some` only for impls of `CoerceUnsized`. - // FIXME(eddyb) perhaps compute this on the fly if cheap enough? - coerce_unsized_info: Option, -} - /// 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".