Skip to content

Commit ab623f2

Browse files
committed
Merge branch 'cache-ty-collect' of https://github.com/michaelwoerister/rust into rollup
2 parents ad8b313 + 0a4f347 commit ab623f2

File tree

7 files changed

+38
-18
lines changed

7 files changed

+38
-18
lines changed

src/librustc/ty/maps/config.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,8 @@ impl<'tcx> QueryDescription<'tcx> for queries::optimized_mir<'tcx> {
617617
}
618618

619619
fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
620-
id: SerializedDepNodeIndex)
621-
-> Option<Self::Value> {
620+
id: SerializedDepNodeIndex)
621+
-> Option<Self::Value> {
622622
let mir: Option<::mir::Mir<'tcx>> = tcx.on_disk_query_result_cache
623623
.try_load_query_result(tcx, id);
624624
mir.map(|x| tcx.alloc_mir(x))
@@ -643,6 +643,21 @@ impl<'tcx> QueryDescription<'tcx> for queries::instance_def_size_estimate<'tcx>
643643
}
644644
}
645645

646+
impl<'tcx> QueryDescription<'tcx> for queries::generics_of<'tcx> {
647+
#[inline]
648+
fn cache_on_disk(def_id: Self::Key) -> bool {
649+
def_id.is_local()
650+
}
651+
652+
fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
653+
id: SerializedDepNodeIndex)
654+
-> Option<Self::Value> {
655+
let generics: Option<ty::Generics> = tcx.on_disk_query_result_cache
656+
.try_load_query_result(tcx, id);
657+
generics.map(|x| tcx.alloc_generics(x))
658+
}
659+
}
660+
646661
macro_rules! impl_disk_cacheable_query(
647662
($query_name:ident, |$key:tt| $cond:expr) => {
648663
impl<'tcx> QueryDescription<'tcx> for queries::$query_name<'tcx> {
@@ -668,3 +683,6 @@ impl_disk_cacheable_query!(mir_const_qualif, |def_id| def_id.is_local());
668683
impl_disk_cacheable_query!(check_match, |def_id| def_id.is_local());
669684
impl_disk_cacheable_query!(contains_extern_indicator, |_| true);
670685
impl_disk_cacheable_query!(def_symbol_name, |_| true);
686+
impl_disk_cacheable_query!(type_of, |def_id| def_id.is_local());
687+
impl_disk_cacheable_query!(predicates_of, |def_id| def_id.is_local());
688+
impl_disk_cacheable_query!(used_trait_imports, |def_id| def_id.is_local());

src/librustc/ty/maps/on_disk_cache.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,12 @@ impl<'sess> OnDiskCache<'sess> {
204204
let enc = &mut encoder;
205205
let qri = &mut query_result_index;
206206

207-
// Encode TypeckTables
207+
encode_query_results::<type_of, _>(tcx, enc, qri)?;
208+
encode_query_results::<generics_of, _>(tcx, enc, qri)?;
209+
encode_query_results::<predicates_of, _>(tcx, enc, qri)?;
210+
encode_query_results::<used_trait_imports, _>(tcx, enc, qri)?;
208211
encode_query_results::<typeck_tables_of, _>(tcx, enc, qri)?;
212+
encode_query_results::<trans_fulfill_obligation, _>(tcx, enc, qri)?;
209213
encode_query_results::<optimized_mir, _>(tcx, enc, qri)?;
210214
encode_query_results::<unsafety_check_result, _>(tcx, enc, qri)?;
211215
encode_query_results::<borrowck, _>(tcx, enc, qri)?;
@@ -215,7 +219,6 @@ impl<'sess> OnDiskCache<'sess> {
215219
encode_query_results::<const_is_rvalue_promotable_to_static, _>(tcx, enc, qri)?;
216220
encode_query_results::<contains_extern_indicator, _>(tcx, enc, qri)?;
217221
encode_query_results::<symbol_name, _>(tcx, enc, qri)?;
218-
encode_query_results::<trans_fulfill_obligation, _>(tcx, enc, qri)?;
219222
encode_query_results::<check_match, _>(tcx, enc, qri)?;
220223
}
221224

src/librustc/ty/maps/plumbing.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,4 +983,8 @@ impl_load_from_cache!(
983983
ConstIsRvaluePromotableToStatic => const_is_rvalue_promotable_to_static,
984984
ContainsExternIndicator => contains_extern_indicator,
985985
CheckMatch => check_match,
986+
TypeOfItem => type_of,
987+
GenericsOfItem => generics_of,
988+
PredicatesOfItem => predicates_of,
989+
UsedTraitImports => used_trait_imports,
986990
);

src/librustc/ty/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub use self::fold::TypeFoldable;
1717

1818
use hir::{map as hir_map, FreevarMap, TraitMap};
1919
use hir::def::{Def, CtorKind, ExportMap};
20-
use hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
20+
use hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
2121
use hir::map::DefPathData;
2222
use hir::svh::Svh;
2323
use ich::Fingerprint;
@@ -39,7 +39,6 @@ use util::nodemap::{NodeSet, DefIdMap, FxHashMap, FxHashSet};
3939

4040
use serialize::{self, Encodable, Encoder};
4141
use std::cell::RefCell;
42-
use std::collections::BTreeMap;
4342
use std::cmp;
4443
use std::cmp::Ordering;
4544
use std::fmt;
@@ -786,9 +785,8 @@ pub struct Generics {
786785
pub regions: Vec<RegionParameterDef>,
787786
pub types: Vec<TypeParameterDef>,
788787

789-
/// Reverse map to each `TypeParameterDef`'s `index` field, from
790-
/// `def_id.index` (`def_id.krate` is the same as the item's).
791-
pub type_param_to_index: BTreeMap<DefIndex, u32>,
788+
/// Reverse map to each `TypeParameterDef`'s `index` field
789+
pub type_param_to_index: FxHashMap<DefId, u32>,
792790

793791
pub has_self: bool,
794792
pub has_late_bound_regions: Option<Span>,

src/librustc_typeck/astconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
979979
let item_id = tcx.hir.get_parent_node(node_id);
980980
let item_def_id = tcx.hir.local_def_id(item_id);
981981
let generics = tcx.generics_of(item_def_id);
982-
let index = generics.type_param_to_index[&tcx.hir.local_def_id(node_id).index];
982+
let index = generics.type_param_to_index[&tcx.hir.local_def_id(node_id)];
983983
tcx.mk_param(index, tcx.hir.name(node_id))
984984
}
985985
Def::SelfTy(_, Some(def_id)) => {

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> {
16361636
let item_id = tcx.hir.ty_param_owner(node_id);
16371637
let item_def_id = tcx.hir.local_def_id(item_id);
16381638
let generics = tcx.generics_of(item_def_id);
1639-
let index = generics.type_param_to_index[&def_id.index];
1639+
let index = generics.type_param_to_index[&def_id];
16401640
ty::GenericPredicates {
16411641
parent: None,
16421642
predicates: self.param_env.caller_bounds.iter().filter(|predicate| {

src/librustc_typeck/collect.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ use util::nodemap::FxHashMap;
4040

4141
use rustc_const_math::ConstInt;
4242

43-
use std::collections::BTreeMap;
44-
4543
use syntax::{abi, ast};
4644
use syntax::codemap::Spanned;
4745
use syntax::symbol::{Symbol, keywords};
@@ -240,7 +238,7 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
240238
let param_owner = tcx.hir.ty_param_owner(param_id);
241239
let param_owner_def_id = tcx.hir.local_def_id(param_owner);
242240
let generics = tcx.generics_of(param_owner_def_id);
243-
let index = generics.type_param_to_index[&def_id.index];
241+
let index = generics.type_param_to_index[&def_id];
244242
let ty = tcx.mk_param(index, tcx.hir.ty_param_name(param_id));
245243

246244
// 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>,
10241022
});
10251023
}
10261024

1027-
let mut type_param_to_index = BTreeMap::new();
1028-
for param in &types {
1029-
type_param_to_index.insert(param.def_id.index, param.index);
1030-
}
1025+
let type_param_to_index = types.iter()
1026+
.map(|param| (param.def_id, param.index))
1027+
.collect();
10311028

10321029
tcx.alloc_generics(ty::Generics {
10331030
parent: parent_def_id,

0 commit comments

Comments
 (0)