Skip to content

Commit 9900ea3

Browse files
committed
Cache more queries on disk.
1 parent 3a08bd7 commit 9900ea3

File tree

15 files changed

+104
-83
lines changed

15 files changed

+104
-83
lines changed

compiler/rustc_hir/src/hir.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@ pub struct FnSig<'hir> {
21292129
// The bodies for items are stored "out of line", in a separate
21302130
// hashmap in the `Crate`. Here we just record the hir-id of the item
21312131
// so it can fetched later.
2132-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)]
2132+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
21332133
pub struct TraitItemId {
21342134
pub def_id: LocalDefId,
21352135
}
@@ -2192,7 +2192,7 @@ pub enum TraitItemKind<'hir> {
21922192
// The bodies for items are stored "out of line", in a separate
21932193
// hashmap in the `Crate`. Here we just record the hir-id of the item
21942194
// so it can fetched later.
2195-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)]
2195+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
21962196
pub struct ImplItemId {
21972197
pub def_id: LocalDefId,
21982198
}
@@ -2787,7 +2787,7 @@ impl<'hir> VariantData<'hir> {
27872787
// The bodies for items are stored "out of line", in a separate
27882788
// hashmap in the `Crate`. Here we just record the hir-id of the item
27892789
// so it can fetched later.
2790-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, Hash, HashStable_Generic)]
2790+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Hash, HashStable_Generic)]
27912791
pub struct ItemId {
27922792
pub def_id: LocalDefId,
27932793
}
@@ -3034,7 +3034,7 @@ pub enum AssocItemKind {
30343034
// The bodies for items are stored "out of line", in a separate
30353035
// hashmap in the `Crate`. Here we just record the hir-id of the item
30363036
// so it can fetched later.
3037-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)]
3037+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
30383038
pub struct ForeignItemId {
30393039
pub def_id: LocalDefId,
30403040
}

compiler/rustc_index/src/vec.rs

-6
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ impl<S: Encoder, I: Idx, T: Encodable<S>> Encodable<S> for IndexVec<I, T> {
6565
}
6666
}
6767

68-
impl<S: Encoder, I: Idx, T: Encodable<S>> Encodable<S> for &IndexVec<I, T> {
69-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
70-
Encodable::encode(&self.raw, s)
71-
}
72-
}
73-
7468
impl<D: Decoder, I: Idx, T: Decodable<D>> Decodable<D> for IndexVec<I, T> {
7569
fn decode(d: &mut D) -> Self {
7670
IndexVec { raw: Decodable::decode(d), _marker: PhantomData }

compiler/rustc_metadata/src/rmeta/encoder.rs

-13
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use rustc_middle::middle::exported_symbols::{
2525
metadata_symbol_name, ExportedSymbol, SymbolExportInfo,
2626
};
2727
use rustc_middle::mir::interpret;
28-
use rustc_middle::thir;
2928
use rustc_middle::traits::specialization_graph;
3029
use rustc_middle::ty::codec::TyEncoder;
3130
use rustc_middle::ty::fast_reject::{self, SimplifiedType, TreatParams};
@@ -351,18 +350,6 @@ impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
351350
}
352351
}
353352

354-
impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for &'tcx [thir::abstract_const::Node<'tcx>] {
355-
fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) -> opaque::EncodeResult {
356-
(**self).encode(s)
357-
}
358-
}
359-
360-
impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for &'tcx [(ty::Predicate<'tcx>, Span)] {
361-
fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) -> opaque::EncodeResult {
362-
(**self).encode(s)
363-
}
364-
}
365-
366353
/// Helper trait to allow overloading `EncodeContext::lazy` for iterators.
367354
trait EncodeContentsForLazy<'a, 'tcx, T: ?Sized + LazyMeta> {
368355
fn encode_contents_for_lazy(self, ecx: &mut EncodeContext<'a, 'tcx>) -> T::Meta;

compiler/rustc_middle/src/arena.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ macro_rules! arena_types {
8282
[] upvars_mentioned: rustc_data_structures::fx::FxIndexMap<rustc_hir::HirId, rustc_hir::Upvar>,
8383
[] object_safety_violations: rustc_middle::traits::ObjectSafetyViolation,
8484
[] codegen_unit: rustc_middle::mir::mono::CodegenUnit<'tcx>,
85-
[] attribute: rustc_ast::Attribute,
85+
[decode] attribute: rustc_ast::Attribute,
8686
[] name_set: rustc_data_structures::fx::FxHashSet<rustc_span::symbol::Symbol>,
8787
[] hir_id_set: rustc_hir::HirIdSet,
8888

@@ -95,9 +95,6 @@ macro_rules! arena_types {
9595
// since we need to allocate this type on both the `rustc_hir` arena
9696
// (during lowering) and the `librustc_middle` arena (for decoding MIR)
9797
[decode] asm_template: rustc_ast::InlineAsmTemplatePiece,
98-
99-
// This is used to decode the &'tcx [Span] for InlineAsm's line_spans.
100-
[decode] span: rustc_span::Span,
10198
[decode] used_trait_imports: rustc_data_structures::fx::FxHashSet<rustc_hir::def_id::LocalDefId>,
10299
[decode] impl_source: rustc_middle::traits::ImplSource<'tcx, ()>,
103100

compiler/rustc_middle/src/hir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Owner<'tcx> {
3636

3737
/// Gather the LocalDefId for each item-like within a module, including items contained within
3838
/// bodies. The Ids are in visitor order. This is used to partition a pass between modules.
39-
#[derive(Debug, HashStable)]
39+
#[derive(Debug, HashStable, Encodable, Decodable)]
4040
pub struct ModuleItems {
4141
submodules: Box<[LocalDefId]>,
4242
items: Box<[ItemId]>,

compiler/rustc_middle/src/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub enum StabilityLevel {
2929
}
3030

3131
/// An entry in the `depr_map`.
32-
#[derive(Copy, Clone, HashStable, Debug)]
32+
#[derive(Copy, Clone, HashStable, Debug, Encodable, Decodable)]
3333
pub struct DeprecationEntry {
3434
/// The metadata of the attribute associated with this entry.
3535
pub attr: Deprecation,

compiler/rustc_middle/src/query/mod.rs

+37-2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ rustc_queries! {
5959
query hir_module_items(key: LocalDefId) -> rustc_middle::hir::ModuleItems {
6060
storage(ArenaCacheSelector<'tcx>)
6161
desc { |tcx| "HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
62+
cache_on_disk_if { true }
6263
}
6364

6465
/// Gives access to the HIR node for the HIR owner `key`.
@@ -128,6 +129,7 @@ rustc_queries! {
128129
/// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
129130
query const_param_default(param: DefId) -> ty::Const<'tcx> {
130131
desc { |tcx| "compute const default for a given parameter `{}`", tcx.def_path_str(param) }
132+
cache_on_disk_if { param.is_local() }
131133
separate_provide_extern
132134
}
133135

@@ -223,6 +225,7 @@ rustc_queries! {
223225
/// Bounds from the parent (e.g. with nested impl trait) are not included.
224226
query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
225227
desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
228+
cache_on_disk_if { key.is_local() }
226229
separate_provide_extern
227230
}
228231

@@ -508,13 +511,15 @@ rustc_queries! {
508511
/// Returns the predicates written explicitly by the user.
509512
query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
510513
desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
514+
cache_on_disk_if { key.is_local() }
511515
separate_provide_extern
512516
}
513517

514518
/// Returns the inferred outlives predicates (e.g., for `struct
515519
/// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
516520
query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
517521
desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
522+
cache_on_disk_if { key.is_local() }
518523
separate_provide_extern
519524
}
520525

@@ -526,6 +531,7 @@ rustc_queries! {
526531
/// additional acyclicity requirements).
527532
query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
528533
desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
534+
cache_on_disk_if { key.is_local() }
529535
separate_provide_extern
530536
}
531537

@@ -549,6 +555,7 @@ rustc_queries! {
549555
query trait_def(key: DefId) -> ty::TraitDef {
550556
desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
551557
storage(ArenaCacheSelector<'tcx>)
558+
cache_on_disk_if { key.is_local() }
552559
separate_provide_extern
553560
}
554561
query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
@@ -558,6 +565,7 @@ rustc_queries! {
558565
}
559566
query adt_destructor(key: DefId) -> Option<ty::Destructor> {
560567
desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
568+
cache_on_disk_if { key.is_local() }
561569
separate_provide_extern
562570
}
563571

@@ -587,11 +595,13 @@ rustc_queries! {
587595
/// `is_const_fn` function.
588596
query impl_constness(key: DefId) -> hir::Constness {
589597
desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
598+
cache_on_disk_if { key.is_local() }
590599
separate_provide_extern
591600
}
592601

593602
query asyncness(key: DefId) -> hir::IsAsync {
594603
desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
604+
cache_on_disk_if { key.is_local() }
595605
separate_provide_extern
596606
}
597607

@@ -609,12 +619,14 @@ rustc_queries! {
609619
/// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
610620
query is_foreign_item(key: DefId) -> bool {
611621
desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
622+
cache_on_disk_if { key.is_local() }
612623
separate_provide_extern
613624
}
614625

615626
/// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
616627
query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
617628
desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
629+
cache_on_disk_if { def_id.is_local() }
618630
separate_provide_extern
619631
}
620632

@@ -627,6 +639,7 @@ rustc_queries! {
627639
/// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
628640
query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
629641
desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
642+
cache_on_disk_if { def_id.is_local() }
630643
separate_provide_extern
631644
}
632645

@@ -639,13 +652,15 @@ rustc_queries! {
639652
/// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
640653
query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
641654
desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
655+
cache_on_disk_if { key.is_local() }
642656
separate_provide_extern
643657
}
644658

645659
/// Maps from a trait item to the trait item "descriptor".
646660
query associated_item(key: DefId) -> ty::AssocItem {
647661
desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
648662
storage(ArenaCacheSelector<'tcx>)
663+
cache_on_disk_if { key.is_local() }
649664
separate_provide_extern
650665
}
651666

@@ -685,10 +700,12 @@ rustc_queries! {
685700
/// Return `None` if this is an inherent impl.
686701
query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
687702
desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
703+
cache_on_disk_if { impl_id.is_local() }
688704
separate_provide_extern
689705
}
690706
query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
691707
desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
708+
cache_on_disk_if { impl_id.is_local() }
692709
separate_provide_extern
693710
}
694711

@@ -701,6 +718,7 @@ rustc_queries! {
701718
/// Methods in these implementations don't need to be exported.
702719
query inherent_impls(key: DefId) -> &'tcx [DefId] {
703720
desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
721+
cache_on_disk_if { key.is_local() }
704722
separate_provide_extern
705723
}
706724

@@ -745,6 +763,7 @@ rustc_queries! {
745763
/// Computes the signature of the function.
746764
query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
747765
desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
766+
cache_on_disk_if { key.is_local() }
748767
separate_provide_extern
749768
}
750769

@@ -820,6 +839,7 @@ rustc_queries! {
820839
/// Caches `CoerceUnsized` kinds for impls on custom types.
821840
query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo {
822841
desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
842+
cache_on_disk_if { key.is_local() }
823843
separate_provide_extern
824844
}
825845

@@ -1033,28 +1053,33 @@ rustc_queries! {
10331053

10341054
query opt_def_kind(def_id: DefId) -> Option<DefKind> {
10351055
desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1056+
cache_on_disk_if { def_id.is_local() }
10361057
separate_provide_extern
10371058
}
10381059

10391060
/// Gets the span for the definition.
10401061
query def_span(def_id: DefId) -> Span {
10411062
desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1063+
cache_on_disk_if { def_id.is_local() }
10421064
separate_provide_extern
10431065
}
10441066

10451067
/// Gets the span for the identifier of the definition.
10461068
query def_ident_span(def_id: DefId) -> Option<Span> {
10471069
desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1070+
cache_on_disk_if { def_id.is_local() }
10481071
separate_provide_extern
10491072
}
10501073

10511074
query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
10521075
desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1076+
cache_on_disk_if { def_id.is_local() }
10531077
separate_provide_extern
10541078
}
10551079

10561080
query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
10571081
desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1082+
cache_on_disk_if { def_id.is_local() }
10581083
separate_provide_extern
10591084
}
10601085

@@ -1064,6 +1089,7 @@ rustc_queries! {
10641089

10651090
query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
10661091
desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1092+
cache_on_disk_if { def_id.is_local() }
10671093
separate_provide_extern
10681094
}
10691095

@@ -1074,6 +1100,7 @@ rustc_queries! {
10741100

10751101
query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
10761102
desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1103+
cache_on_disk_if { def_id.is_local() }
10771104
separate_provide_extern
10781105
}
10791106

@@ -1090,33 +1117,39 @@ rustc_queries! {
10901117

10911118
query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
10921119
desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1120+
cache_on_disk_if { def_id.is_local() }
10931121
separate_provide_extern
10941122
}
10951123
/// Gets the rendered value of the specified constant or associated constant.
10961124
/// Used by rustdoc.
10971125
query rendered_const(def_id: DefId) -> String {
10981126
storage(ArenaCacheSelector<'tcx>)
10991127
desc { |tcx| "rendering constant intializer of `{}`", tcx.def_path_str(def_id) }
1128+
cache_on_disk_if { def_id.is_local() }
11001129
separate_provide_extern
11011130
}
11021131
query impl_parent(def_id: DefId) -> Option<DefId> {
11031132
desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1133+
cache_on_disk_if { def_id.is_local() }
11041134
separate_provide_extern
11051135
}
11061136

11071137
/// Given an `associated_item`, find the trait it belongs to.
11081138
/// Return `None` if the `DefId` is not an associated item.
11091139
query trait_of_item(associated_item: DefId) -> Option<DefId> {
11101140
desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(associated_item) }
1141+
cache_on_disk_if { associated_item.is_local() }
11111142
separate_provide_extern
11121143
}
11131144

11141145
query is_ctfe_mir_available(key: DefId) -> bool {
11151146
desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
1147+
cache_on_disk_if { key.is_local() }
11161148
separate_provide_extern
11171149
}
11181150
query is_mir_available(key: DefId) -> bool {
11191151
desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
1152+
cache_on_disk_if { key.is_local() }
11201153
separate_provide_extern
11211154
}
11221155

@@ -1358,6 +1391,7 @@ rustc_queries! {
13581391

13591392
query impl_defaultness(def_id: DefId) -> hir::Defaultness {
13601393
desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1394+
cache_on_disk_if { def_id.is_local() }
13611395
separate_provide_extern
13621396
}
13631397

@@ -1391,6 +1425,7 @@ rustc_queries! {
13911425
}
13921426
query is_reachable_non_generic(def_id: DefId) -> bool {
13931427
desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1428+
cache_on_disk_if { def_id.is_local() }
13941429
separate_provide_extern
13951430
}
13961431
query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
@@ -1705,9 +1740,9 @@ rustc_queries! {
17051740
/// - All names contained in `exported_symbols(cnum)` are guaranteed to
17061741
/// correspond to a publicly visible symbol in `cnum` machine code.
17071742
/// - The `exported_symbols` sets of different crates do not intersect.
1708-
query exported_symbols(_: CrateNum)
1709-
-> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
1743+
query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
17101744
desc { "exported_symbols" }
1745+
cache_on_disk_if { *cnum == LOCAL_CRATE }
17111746
separate_provide_extern
17121747
}
17131748

0 commit comments

Comments
 (0)