From a084cd0ed2ec8f4c4706e843c3b4ed2e07ac3b7f Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Mon, 15 Jan 2018 16:38:04 +0100 Subject: [PATCH 1/3] incr.comp.: Cache type_of and some other queries. --- src/librustc/ty/maps/config.rs | 3 +++ src/librustc/ty/maps/on_disk_cache.rs | 6 ++++-- src/librustc/ty/maps/plumbing.rs | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/librustc/ty/maps/config.rs b/src/librustc/ty/maps/config.rs index 8dedcb24c2fb6..1dad74fb28e77 100644 --- a/src/librustc/ty/maps/config.rs +++ b/src/librustc/ty/maps/config.rs @@ -662,3 +662,6 @@ impl_disk_cacheable_query!(mir_const_qualif, |def_id| def_id.is_local()); impl_disk_cacheable_query!(check_match, |def_id| def_id.is_local()); impl_disk_cacheable_query!(contains_extern_indicator, |_| true); impl_disk_cacheable_query!(def_symbol_name, |_| true); +impl_disk_cacheable_query!(type_of, |def_id| def_id.is_local()); +impl_disk_cacheable_query!(predicates_of, |def_id| def_id.is_local()); +impl_disk_cacheable_query!(used_trait_imports, |def_id| def_id.is_local()); diff --git a/src/librustc/ty/maps/on_disk_cache.rs b/src/librustc/ty/maps/on_disk_cache.rs index 4e2421dad2161..a489bec5b27d0 100644 --- a/src/librustc/ty/maps/on_disk_cache.rs +++ b/src/librustc/ty/maps/on_disk_cache.rs @@ -204,8 +204,11 @@ impl<'sess> OnDiskCache<'sess> { let enc = &mut encoder; let qri = &mut query_result_index; - // Encode TypeckTables + encode_query_results::(tcx, enc, qri)?; + encode_query_results::(tcx, enc, qri)?; + encode_query_results::(tcx, enc, qri)?; encode_query_results::(tcx, enc, qri)?; + encode_query_results::(tcx, enc, qri)?; encode_query_results::(tcx, enc, qri)?; encode_query_results::(tcx, enc, qri)?; encode_query_results::(tcx, enc, qri)?; @@ -215,7 +218,6 @@ impl<'sess> OnDiskCache<'sess> { encode_query_results::(tcx, enc, qri)?; encode_query_results::(tcx, enc, qri)?; encode_query_results::(tcx, enc, qri)?; - encode_query_results::(tcx, enc, qri)?; encode_query_results::(tcx, enc, qri)?; } diff --git a/src/librustc/ty/maps/plumbing.rs b/src/librustc/ty/maps/plumbing.rs index d670ecc2691ae..a0db3c7bca8fa 100644 --- a/src/librustc/ty/maps/plumbing.rs +++ b/src/librustc/ty/maps/plumbing.rs @@ -982,4 +982,7 @@ impl_load_from_cache!( ConstIsRvaluePromotableToStatic => const_is_rvalue_promotable_to_static, ContainsExternIndicator => contains_extern_indicator, CheckMatch => check_match, + TypeOfItem => type_of, + PredicatesOfItem => predicates_of, + UsedTraitImports => used_trait_imports, ); From a5d7aae8cf7d989d13a0c7f019f42c9a514e1264 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 17 Jan 2018 16:23:50 +0100 Subject: [PATCH 2/3] Make ty::Generics::type_param_to_index use DefId instead of DefIndex as key. --- src/librustc/ty/mod.rs | 8 +++----- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/collect.rs | 11 ++++------- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 123432074761b..2c3454e7b5c7b 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -17,7 +17,7 @@ pub use self::fold::TypeFoldable; use hir::{map as hir_map, FreevarMap, TraitMap}; use hir::def::{Def, CtorKind, ExportMap}; -use hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use hir::map::DefPathData; use hir::svh::Svh; use ich::Fingerprint; @@ -39,7 +39,6 @@ use util::nodemap::{NodeSet, DefIdMap, FxHashMap, FxHashSet}; use serialize::{self, Encodable, Encoder}; use std::cell::RefCell; -use std::collections::BTreeMap; use std::cmp; use std::fmt; use std::hash::{Hash, Hasher}; @@ -758,9 +757,8 @@ pub struct Generics { pub regions: Vec, pub types: Vec, - /// Reverse map to each `TypeParameterDef`'s `index` field, from - /// `def_id.index` (`def_id.krate` is the same as the item's). - pub type_param_to_index: BTreeMap, + /// Reverse map to each `TypeParameterDef`'s `index` field + pub type_param_to_index: FxHashMap, pub has_self: bool, pub has_late_bound_regions: Option, diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 4616b4cf80c97..42bc3a25a8d3f 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -979,7 +979,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { let item_id = tcx.hir.get_parent_node(node_id); let item_def_id = tcx.hir.local_def_id(item_id); let generics = tcx.generics_of(item_def_id); - let index = generics.type_param_to_index[&tcx.hir.local_def_id(node_id).index]; + let index = generics.type_param_to_index[&tcx.hir.local_def_id(node_id)]; tcx.mk_param(index, tcx.hir.name(node_id)) } Def::SelfTy(_, Some(def_id)) => { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index cb8ce8d5ac331..6702ac2354d79 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1629,7 +1629,7 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> { let item_id = tcx.hir.ty_param_owner(node_id); let item_def_id = tcx.hir.local_def_id(item_id); let generics = tcx.generics_of(item_def_id); - let index = generics.type_param_to_index[&def_id.index]; + let index = generics.type_param_to_index[&def_id]; ty::GenericPredicates { parent: None, predicates: self.param_env.caller_bounds.iter().filter(|predicate| { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 5485045b70438..71ffb57ab48c7 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -40,8 +40,6 @@ use util::nodemap::FxHashMap; use rustc_const_math::ConstInt; -use std::collections::BTreeMap; - use syntax::{abi, ast}; use syntax::codemap::Spanned; use syntax::symbol::{Symbol, keywords}; @@ -240,7 +238,7 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let param_owner = tcx.hir.ty_param_owner(param_id); let param_owner_def_id = tcx.hir.local_def_id(param_owner); let generics = tcx.generics_of(param_owner_def_id); - let index = generics.type_param_to_index[&def_id.index]; + let index = generics.type_param_to_index[&def_id]; let ty = tcx.mk_param(index, tcx.hir.ty_param_name(param_id)); // Don't look for bounds where the type parameter isn't in scope. @@ -1024,10 +1022,9 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }); } - let mut type_param_to_index = BTreeMap::new(); - for param in &types { - type_param_to_index.insert(param.def_id.index, param.index); - } + let type_param_to_index = types.iter() + .map(|param| (param.def_id, param.index)) + .collect(); tcx.alloc_generics(ty::Generics { parent: parent_def_id, From 0a4f3473959411b5488b35cf4cc4379cae69a686 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 17 Jan 2018 16:39:29 +0100 Subject: [PATCH 3/3] incr.comp.: Cache generics_of query. --- src/librustc/ty/maps/config.rs | 19 +++++++++++++++++-- src/librustc/ty/maps/on_disk_cache.rs | 1 + src/librustc/ty/maps/plumbing.rs | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/librustc/ty/maps/config.rs b/src/librustc/ty/maps/config.rs index 1dad74fb28e77..5143654e91699 100644 --- a/src/librustc/ty/maps/config.rs +++ b/src/librustc/ty/maps/config.rs @@ -617,8 +617,8 @@ impl<'tcx> QueryDescription<'tcx> for queries::optimized_mir<'tcx> { } fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - id: SerializedDepNodeIndex) - -> Option { + id: SerializedDepNodeIndex) + -> Option { let mir: Option<::mir::Mir<'tcx>> = tcx.on_disk_query_result_cache .try_load_query_result(tcx, id); mir.map(|x| tcx.alloc_mir(x)) @@ -637,6 +637,21 @@ impl<'tcx> QueryDescription<'tcx> for queries::target_features_whitelist<'tcx> { } } +impl<'tcx> QueryDescription<'tcx> for queries::generics_of<'tcx> { + #[inline] + fn cache_on_disk(def_id: Self::Key) -> bool { + def_id.is_local() + } + + fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, + id: SerializedDepNodeIndex) + -> Option { + let generics: Option = tcx.on_disk_query_result_cache + .try_load_query_result(tcx, id); + generics.map(|x| tcx.alloc_generics(x)) + } +} + macro_rules! impl_disk_cacheable_query( ($query_name:ident, |$key:tt| $cond:expr) => { impl<'tcx> QueryDescription<'tcx> for queries::$query_name<'tcx> { diff --git a/src/librustc/ty/maps/on_disk_cache.rs b/src/librustc/ty/maps/on_disk_cache.rs index a489bec5b27d0..56ed0f9106f30 100644 --- a/src/librustc/ty/maps/on_disk_cache.rs +++ b/src/librustc/ty/maps/on_disk_cache.rs @@ -205,6 +205,7 @@ impl<'sess> OnDiskCache<'sess> { let qri = &mut query_result_index; encode_query_results::(tcx, enc, qri)?; + encode_query_results::(tcx, enc, qri)?; encode_query_results::(tcx, enc, qri)?; encode_query_results::(tcx, enc, qri)?; encode_query_results::(tcx, enc, qri)?; diff --git a/src/librustc/ty/maps/plumbing.rs b/src/librustc/ty/maps/plumbing.rs index a0db3c7bca8fa..3e1b490957ccf 100644 --- a/src/librustc/ty/maps/plumbing.rs +++ b/src/librustc/ty/maps/plumbing.rs @@ -983,6 +983,7 @@ impl_load_from_cache!( ContainsExternIndicator => contains_extern_indicator, CheckMatch => check_match, TypeOfItem => type_of, + GenericsOfItem => generics_of, PredicatesOfItem => predicates_of, UsedTraitImports => used_trait_imports, );