From 9900ea352b1b7dbcbe290bbb62f436c91818c5d1 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 28 Mar 2022 19:53:01 +0200 Subject: [PATCH 1/2] Cache more queries on disk. --- compiler/rustc_hir/src/hir.rs | 8 ++-- compiler/rustc_index/src/vec.rs | 6 --- compiler/rustc_metadata/src/rmeta/encoder.rs | 13 ------ compiler/rustc_middle/src/arena.rs | 5 +- compiler/rustc_middle/src/hir/mod.rs | 2 +- compiler/rustc_middle/src/middle/stability.rs | 2 +- compiler/rustc_middle/src/query/mod.rs | 39 +++++++++++++++- compiler/rustc_middle/src/ty/assoc.rs | 6 +-- compiler/rustc_middle/src/ty/codec.rs | 46 +++++++++++-------- compiler/rustc_middle/src/ty/list.rs | 7 --- compiler/rustc_middle/src/ty/mod.rs | 4 +- compiler/rustc_query_impl/src/lib.rs | 2 +- .../rustc_query_impl/src/on_disk_cache.rs | 22 +++++++-- .../rustc_serialize/src/collection_impls.rs | 10 ---- compiler/rustc_serialize/src/serialize.rs | 15 +++--- 15 files changed, 104 insertions(+), 83 deletions(-) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 4d4d4a28499..c52fbaf0061 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -2129,7 +2129,7 @@ pub struct FnSig<'hir> { // The bodies for items are stored "out of line", in a separate // hashmap in the `Crate`. Here we just record the hir-id of the item // so it can fetched later. -#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)] pub struct TraitItemId { pub def_id: LocalDefId, } @@ -2192,7 +2192,7 @@ pub enum TraitItemKind<'hir> { // The bodies for items are stored "out of line", in a separate // hashmap in the `Crate`. Here we just record the hir-id of the item // so it can fetched later. -#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)] pub struct ImplItemId { pub def_id: LocalDefId, } @@ -2787,7 +2787,7 @@ impl<'hir> VariantData<'hir> { // The bodies for items are stored "out of line", in a separate // hashmap in the `Crate`. Here we just record the hir-id of the item // so it can fetched later. -#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, Hash, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Hash, HashStable_Generic)] pub struct ItemId { pub def_id: LocalDefId, } @@ -3034,7 +3034,7 @@ pub enum AssocItemKind { // The bodies for items are stored "out of line", in a separate // hashmap in the `Crate`. Here we just record the hir-id of the item // so it can fetched later. -#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)] pub struct ForeignItemId { pub def_id: LocalDefId, } diff --git a/compiler/rustc_index/src/vec.rs b/compiler/rustc_index/src/vec.rs index 4656994ac08..a8c611e18ff 100644 --- a/compiler/rustc_index/src/vec.rs +++ b/compiler/rustc_index/src/vec.rs @@ -65,12 +65,6 @@ impl> Encodable for IndexVec { } } -impl> Encodable for &IndexVec { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { - Encodable::encode(&self.raw, s) - } -} - impl> Decodable for IndexVec { fn decode(d: &mut D) -> Self { IndexVec { raw: Decodable::decode(d), _marker: PhantomData } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 81388a0bf58..7a017e2b77a 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -25,7 +25,6 @@ use rustc_middle::middle::exported_symbols::{ metadata_symbol_name, ExportedSymbol, SymbolExportInfo, }; use rustc_middle::mir::interpret; -use rustc_middle::thir; use rustc_middle::traits::specialization_graph; use rustc_middle::ty::codec::TyEncoder; use rustc_middle::ty::fast_reject::{self, SimplifiedType, TreatParams}; @@ -351,18 +350,6 @@ impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> { } } -impl<'a, 'tcx> Encodable> for &'tcx [thir::abstract_const::Node<'tcx>] { - fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) -> opaque::EncodeResult { - (**self).encode(s) - } -} - -impl<'a, 'tcx> Encodable> for &'tcx [(ty::Predicate<'tcx>, Span)] { - fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) -> opaque::EncodeResult { - (**self).encode(s) - } -} - /// Helper trait to allow overloading `EncodeContext::lazy` for iterators. trait EncodeContentsForLazy<'a, 'tcx, T: ?Sized + LazyMeta> { fn encode_contents_for_lazy(self, ecx: &mut EncodeContext<'a, 'tcx>) -> T::Meta; diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index 7c90cbb9092..def061aaea0 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -82,7 +82,7 @@ macro_rules! arena_types { [] upvars_mentioned: rustc_data_structures::fx::FxIndexMap, [] object_safety_violations: rustc_middle::traits::ObjectSafetyViolation, [] codegen_unit: rustc_middle::mir::mono::CodegenUnit<'tcx>, - [] attribute: rustc_ast::Attribute, + [decode] attribute: rustc_ast::Attribute, [] name_set: rustc_data_structures::fx::FxHashSet, [] hir_id_set: rustc_hir::HirIdSet, @@ -95,9 +95,6 @@ macro_rules! arena_types { // since we need to allocate this type on both the `rustc_hir` arena // (during lowering) and the `librustc_middle` arena (for decoding MIR) [decode] asm_template: rustc_ast::InlineAsmTemplatePiece, - - // This is used to decode the &'tcx [Span] for InlineAsm's line_spans. - [decode] span: rustc_span::Span, [decode] used_trait_imports: rustc_data_structures::fx::FxHashSet, [decode] impl_source: rustc_middle::traits::ImplSource<'tcx, ()>, diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index f18067145dd..b50f121eff2 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -36,7 +36,7 @@ impl<'a, 'tcx> HashStable> for Owner<'tcx> { /// Gather the LocalDefId for each item-like within a module, including items contained within /// bodies. The Ids are in visitor order. This is used to partition a pass between modules. -#[derive(Debug, HashStable)] +#[derive(Debug, HashStable, Encodable, Decodable)] pub struct ModuleItems { submodules: Box<[LocalDefId]>, items: Box<[ItemId]>, diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 6918046390e..8b11e35a7c3 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -29,7 +29,7 @@ pub enum StabilityLevel { } /// An entry in the `depr_map`. -#[derive(Copy, Clone, HashStable, Debug)] +#[derive(Copy, Clone, HashStable, Debug, Encodable, Decodable)] pub struct DeprecationEntry { /// The metadata of the attribute associated with this entry. pub attr: Deprecation, diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 0ef694a3c85..c6916697905 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -59,6 +59,7 @@ rustc_queries! { query hir_module_items(key: LocalDefId) -> rustc_middle::hir::ModuleItems { storage(ArenaCacheSelector<'tcx>) desc { |tcx| "HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) } + cache_on_disk_if { true } } /// Gives access to the HIR node for the HIR owner `key`. @@ -128,6 +129,7 @@ rustc_queries! { /// parameter. e.g. `fn example` called on `N` would return `3`. query const_param_default(param: DefId) -> ty::Const<'tcx> { desc { |tcx| "compute const default for a given parameter `{}`", tcx.def_path_str(param) } + cache_on_disk_if { param.is_local() } separate_provide_extern } @@ -223,6 +225,7 @@ rustc_queries! { /// Bounds from the parent (e.g. with nested impl trait) are not included. query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] { desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } separate_provide_extern } @@ -508,6 +511,7 @@ rustc_queries! { /// Returns the predicates written explicitly by the user. query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> { desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } separate_provide_extern } @@ -515,6 +519,7 @@ rustc_queries! { /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`). query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] { desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } separate_provide_extern } @@ -526,6 +531,7 @@ rustc_queries! { /// additional acyclicity requirements). query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> { desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } separate_provide_extern } @@ -549,6 +555,7 @@ rustc_queries! { query trait_def(key: DefId) -> ty::TraitDef { desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) } storage(ArenaCacheSelector<'tcx>) + cache_on_disk_if { key.is_local() } separate_provide_extern } query adt_def(key: DefId) -> ty::AdtDef<'tcx> { @@ -558,6 +565,7 @@ rustc_queries! { } query adt_destructor(key: DefId) -> Option { desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } separate_provide_extern } @@ -587,11 +595,13 @@ rustc_queries! { /// `is_const_fn` function. query impl_constness(key: DefId) -> hir::Constness { desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } separate_provide_extern } query asyncness(key: DefId) -> hir::IsAsync { desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } separate_provide_extern } @@ -609,12 +619,14 @@ rustc_queries! { /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`). query is_foreign_item(key: DefId) -> bool { desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } separate_provide_extern } /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator. query generator_kind(def_id: DefId) -> Option { desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) } + cache_on_disk_if { def_id.is_local() } separate_provide_extern } @@ -627,6 +639,7 @@ rustc_queries! { /// Maps from the `DefId` of a type or region parameter to its (inferred) variance. query variances_of(def_id: DefId) -> &'tcx [ty::Variance] { desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) } + cache_on_disk_if { def_id.is_local() } separate_provide_extern } @@ -639,6 +652,7 @@ rustc_queries! { /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items. query associated_item_def_ids(key: DefId) -> &'tcx [DefId] { desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } separate_provide_extern } @@ -646,6 +660,7 @@ rustc_queries! { query associated_item(key: DefId) -> ty::AssocItem { desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) } storage(ArenaCacheSelector<'tcx>) + cache_on_disk_if { key.is_local() } separate_provide_extern } @@ -685,10 +700,12 @@ rustc_queries! { /// Return `None` if this is an inherent impl. query impl_trait_ref(impl_id: DefId) -> Option> { desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) } + cache_on_disk_if { impl_id.is_local() } separate_provide_extern } query impl_polarity(impl_id: DefId) -> ty::ImplPolarity { desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) } + cache_on_disk_if { impl_id.is_local() } separate_provide_extern } @@ -701,6 +718,7 @@ rustc_queries! { /// Methods in these implementations don't need to be exported. query inherent_impls(key: DefId) -> &'tcx [DefId] { desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } separate_provide_extern } @@ -745,6 +763,7 @@ rustc_queries! { /// Computes the signature of the function. query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> { desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } separate_provide_extern } @@ -820,6 +839,7 @@ rustc_queries! { /// Caches `CoerceUnsized` kinds for impls on custom types. query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo { desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } separate_provide_extern } @@ -1033,28 +1053,33 @@ rustc_queries! { query opt_def_kind(def_id: DefId) -> Option { desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) } + cache_on_disk_if { def_id.is_local() } separate_provide_extern } /// Gets the span for the definition. query def_span(def_id: DefId) -> Span { desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) } + cache_on_disk_if { def_id.is_local() } separate_provide_extern } /// Gets the span for the identifier of the definition. query def_ident_span(def_id: DefId) -> Option { desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) } + cache_on_disk_if { def_id.is_local() } separate_provide_extern } query lookup_stability(def_id: DefId) -> Option { desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) } + cache_on_disk_if { def_id.is_local() } separate_provide_extern } query lookup_const_stability(def_id: DefId) -> Option { desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) } + cache_on_disk_if { def_id.is_local() } separate_provide_extern } @@ -1064,6 +1089,7 @@ rustc_queries! { query lookup_deprecation_entry(def_id: DefId) -> Option { desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) } + cache_on_disk_if { def_id.is_local() } separate_provide_extern } @@ -1074,6 +1100,7 @@ rustc_queries! { query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] { desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) } + cache_on_disk_if { def_id.is_local() } separate_provide_extern } @@ -1090,6 +1117,7 @@ rustc_queries! { query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] { desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) } + cache_on_disk_if { def_id.is_local() } separate_provide_extern } /// Gets the rendered value of the specified constant or associated constant. @@ -1097,10 +1125,12 @@ rustc_queries! { query rendered_const(def_id: DefId) -> String { storage(ArenaCacheSelector<'tcx>) desc { |tcx| "rendering constant intializer of `{}`", tcx.def_path_str(def_id) } + cache_on_disk_if { def_id.is_local() } separate_provide_extern } query impl_parent(def_id: DefId) -> Option { desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) } + cache_on_disk_if { def_id.is_local() } separate_provide_extern } @@ -1108,15 +1138,18 @@ rustc_queries! { /// Return `None` if the `DefId` is not an associated item. query trait_of_item(associated_item: DefId) -> Option { desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(associated_item) } + cache_on_disk_if { associated_item.is_local() } separate_provide_extern } query is_ctfe_mir_available(key: DefId) -> bool { desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } separate_provide_extern } query is_mir_available(key: DefId) -> bool { desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } separate_provide_extern } @@ -1358,6 +1391,7 @@ rustc_queries! { query impl_defaultness(def_id: DefId) -> hir::Defaultness { desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) } + cache_on_disk_if { def_id.is_local() } separate_provide_extern } @@ -1391,6 +1425,7 @@ rustc_queries! { } query is_reachable_non_generic(def_id: DefId) -> bool { desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) } + cache_on_disk_if { def_id.is_local() } separate_provide_extern } query is_unreachable_local_definition(def_id: LocalDefId) -> bool { @@ -1705,9 +1740,9 @@ rustc_queries! { /// - All names contained in `exported_symbols(cnum)` are guaranteed to /// correspond to a publicly visible symbol in `cnum` machine code. /// - The `exported_symbols` sets of different crates do not intersect. - query exported_symbols(_: CrateNum) - -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] { + query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] { desc { "exported_symbols" } + cache_on_disk_if { *cnum == LOCAL_CRATE } separate_provide_extern } diff --git a/compiler/rustc_middle/src/ty/assoc.rs b/compiler/rustc_middle/src/ty/assoc.rs index 49f846562a3..2c93af50667 100644 --- a/compiler/rustc_middle/src/ty/assoc.rs +++ b/compiler/rustc_middle/src/ty/assoc.rs @@ -9,7 +9,7 @@ use rustc_span::symbol::{Ident, Symbol}; use super::{TyCtxt, Visibility}; -#[derive(Clone, Copy, PartialEq, Eq, Debug, HashStable, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, HashStable, Hash, Encodable, Decodable)] pub enum AssocItemContainer { TraitContainer(DefId), ImplContainer(DefId), @@ -41,7 +41,7 @@ impl AssocItemContainer { } /// Information about an associated item -#[derive(Copy, Clone, Debug, PartialEq, HashStable, Eq, Hash)] +#[derive(Copy, Clone, Debug, PartialEq, HashStable, Eq, Hash, Encodable, Decodable)] pub struct AssocItem { pub def_id: DefId, pub name: Symbol, @@ -81,7 +81,7 @@ impl AssocItem { } } -#[derive(Copy, Clone, PartialEq, Debug, HashStable, Eq, Hash)] +#[derive(Copy, Clone, PartialEq, Debug, HashStable, Eq, Hash, Encodable, Decodable)] pub enum AssocKind { Const, Fn, diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 23c377651cc..2a5191008a9 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -168,25 +168,6 @@ impl<'tcx, E: TyEncoder<'tcx>> Encodable for AllocId { } } -macro_rules! encodable_via_deref { - ($($t:ty),+) => { - $(impl<'tcx, E: TyEncoder<'tcx>> Encodable for $t { - fn encode(&self, e: &mut E) -> Result<(), E::Error> { - (**self).encode(e) - } - })* - } -} - -encodable_via_deref! { - &'tcx ty::TypeckResults<'tcx>, - &'tcx traits::ImplSource<'tcx, ()>, - &'tcx mir::Body<'tcx>, - &'tcx mir::UnsafetyCheckResult, - &'tcx mir::BorrowCheckResult<'tcx>, - &'tcx mir::coverage::CodeRegion -} - pub trait TyDecoder<'tcx>: Decoder { const CLEAR_CROSS_CRATE: bool; @@ -466,6 +447,33 @@ macro_rules! impl_arena_allocatable_decoders { rustc_hir::arena_types!(impl_arena_allocatable_decoders); arena_types!(impl_arena_allocatable_decoders); +macro_rules! impl_arena_copy_decoder { + (<$tcx:tt> $($ty:ty,)*) => { + $(impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for $ty { + #[inline] + fn decode(decoder: &mut D) -> &'tcx Self { + decoder.tcx().arena.alloc(Decodable::decode(decoder)) + } + } + + impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [$ty] { + #[inline] + fn decode(decoder: &mut D) -> &'tcx Self { + decoder.tcx().arena.alloc_from_iter( as Decodable>::decode(decoder)) + } + })* + }; +} + +impl_arena_copy_decoder! {<'tcx> + Span, + rustc_span::symbol::Ident, + ty::Variance, + rustc_span::def_id::DefId, + rustc_span::def_id::LocalDefId, + (rustc_middle::middle::exported_symbols::ExportedSymbol<'tcx>, rustc_middle::middle::exported_symbols::SymbolExportInfo), +} + #[macro_export] macro_rules! implement_ty_decoder { ($DecoderName:ident <$($typaram:tt),*>) => { diff --git a/compiler/rustc_middle/src/ty/list.rs b/compiler/rustc_middle/src/ty/list.rs index 197dc9205b4..3c9e96df59a 100644 --- a/compiler/rustc_middle/src/ty/list.rs +++ b/compiler/rustc_middle/src/ty/list.rs @@ -122,13 +122,6 @@ impl> Encodable for List { } } -impl> Encodable for &List { - #[inline] - fn encode(&self, s: &mut S) -> Result<(), S::Error> { - (**self).encode(s) - } -} - impl PartialEq for List { #[inline] fn eq(&self, other: &List) -> bool { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index d847068b5bf..e21cdcb7303 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -228,7 +228,7 @@ impl fmt::Display for ImplPolarity { } } -#[derive(Clone, Debug, PartialEq, Eq, Copy, Hash, TyEncodable, TyDecodable, HashStable)] +#[derive(Clone, Debug, PartialEq, Eq, Copy, Hash, Encodable, Decodable, HashStable)] pub enum Visibility { /// Visible everywhere (including in other crates). Public, @@ -1629,7 +1629,7 @@ where } } -#[derive(Copy, Clone, Debug, HashStable)] +#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)] pub struct Destructor { /// The `DefId` of the destructor method pub did: DefId, diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 6ebff5388f4..2fa030f9b3f 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -21,7 +21,7 @@ use rustc_middle::dep_graph::{self, DepKindStruct, SerializedDepNodeIndex}; use rustc_middle::ty::query::{query_keys, query_storage, query_stored, query_values}; use rustc_middle::ty::query::{ExternProviders, Providers, QueryEngine}; use rustc_middle::ty::{self, TyCtxt}; -use rustc_span::def_id::LocalDefId; +use rustc_span::def_id::{LocalDefId, LOCAL_CRATE}; use rustc_span::Span; #[macro_use] diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index f2f895367ff..c4920408527 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -788,10 +788,24 @@ impl<'a, 'tcx> Decodable> for &'tcx [rustc_ast::InlineAsm } } -impl<'a, 'tcx> Decodable> for &'tcx [Span] { - fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self { - RefDecodable::decode(d) - } +macro_rules! impl_ref_decoder { + (<$tcx:tt> $($ty:ty,)*) => { + $(impl<'a, $tcx> Decodable> for &$tcx [$ty] { + fn decode(d: &mut CacheDecoder<'a, $tcx>) -> Self { + RefDecodable::decode(d) + } + })* + }; +} + +impl_ref_decoder! {<'tcx> + Span, + rustc_ast::Attribute, + rustc_span::symbol::Ident, + ty::Variance, + rustc_span::def_id::DefId, + rustc_span::def_id::LocalDefId, + (rustc_middle::middle::exported_symbols::ExportedSymbol<'tcx>, rustc_middle::middle::exported_symbols::SymbolExportInfo), } //- ENCODING ------------------------------------------------------------------- diff --git a/compiler/rustc_serialize/src/collection_impls.rs b/compiler/rustc_serialize/src/collection_impls.rs index dee6dc010fe..761e988360a 100644 --- a/compiler/rustc_serialize/src/collection_impls.rs +++ b/compiler/rustc_serialize/src/collection_impls.rs @@ -171,16 +171,6 @@ where } } -impl Encodable for &HashSet -where - T: Encodable + Eq, - S: BuildHasher, -{ - fn encode(&self, s: &mut E) -> Result<(), E::Error> { - (**self).encode(s) - } -} - impl Decodable for HashSet where T: Decodable + Hash + Eq, diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs index 7d6b8c760ff..36e575b2427 100644 --- a/compiler/rustc_serialize/src/serialize.rs +++ b/compiler/rustc_serialize/src/serialize.rs @@ -268,6 +268,15 @@ direct_serialize_impls! { char emit_char read_char } +impl Encodable for &T +where + T: Encodable, +{ + fn encode(&self, s: &mut S) -> Result<(), S::Error> { + (**self).encode(s) + } +} + impl Encodable for ! { fn encode(&self, _s: &mut S) -> Result<(), S::Error> { unreachable!() @@ -298,12 +307,6 @@ impl Encodable for str { } } -impl Encodable for &str { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_str(self) - } -} - impl Encodable for String { fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_str(&self[..]) From 29f3b3fe4914f3e5f1d1f484cd1bcfb7e677c433 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 29 Mar 2022 16:15:52 +0200 Subject: [PATCH 2/2] Do not cache item_attrs. --- compiler/rustc_middle/src/query/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index c6916697905..ddc2c599c8f 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1100,7 +1100,6 @@ rustc_queries! { query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] { desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) } - cache_on_disk_if { def_id.is_local() } separate_provide_extern }