diff --git a/src/librustc/ty/maps/config.rs b/src/librustc/ty/maps/config.rs index 496284ad9c9f..2d0a3799178a 100644 --- a/src/librustc/ty/maps/config.rs +++ b/src/librustc/ty/maps/config.rs @@ -27,6 +27,7 @@ pub trait QueryConfig { pub(super) trait QueryDescription<'tcx>: QueryConfig { fn describe(tcx: TyCtxt, key: Self::Key) -> String; + #[inline] fn cache_on_disk(_: Self::Key) -> bool { false } @@ -34,7 +35,7 @@ pub(super) trait QueryDescription<'tcx>: QueryConfig { fn try_load_from_disk(_: TyCtxt<'_, 'tcx, 'tcx>, _: SerializedDepNodeIndex) -> Option { - bug!("QueryDescription::load_from_disk() called for unsupport query.") + bug!("QueryDescription::load_from_disk() called for an unsupported query.") } } @@ -166,6 +167,18 @@ impl<'tcx> QueryDescription<'tcx> for queries::symbol_name<'tcx> { fn describe(_tcx: TyCtxt, instance: ty::Instance<'tcx>) -> String { format!("computing the symbol for `{}`", instance) } + + #[inline] + fn cache_on_disk(_: Self::Key) -> bool { + true + } + + #[inline] + fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, + id: SerializedDepNodeIndex) + -> Option { + tcx.on_disk_query_result_cache.try_load_query_result(tcx, id) + } } impl<'tcx> QueryDescription<'tcx> for queries::describe_def<'tcx> { @@ -234,6 +247,18 @@ impl<'tcx> QueryDescription<'tcx> for queries::const_is_rvalue_promotable_to_sta format!("const checking if rvalue is promotable to static `{}`", tcx.item_path_str(def_id)) } + + #[inline] + fn cache_on_disk(_: Self::Key) -> bool { + true + } + + #[inline] + fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, + id: SerializedDepNodeIndex) + -> Option { + tcx.on_disk_query_result_cache.try_load_query_result(tcx, id) + } } impl<'tcx> QueryDescription<'tcx> for queries::rvalue_promotable_map<'tcx> { @@ -254,6 +279,18 @@ impl<'tcx> QueryDescription<'tcx> for queries::trans_fulfill_obligation<'tcx> { fn describe(tcx: TyCtxt, key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> String { format!("checking if `{}` fulfills its obligations", tcx.item_path_str(key.1.def_id())) } + + #[inline] + fn cache_on_disk(_: Self::Key) -> bool { + true + } + + #[inline] + fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, + id: SerializedDepNodeIndex) + -> Option { + tcx.on_disk_query_result_cache.try_load_query_result(tcx, id) + } } impl<'tcx> QueryDescription<'tcx> for queries::trait_impls_of<'tcx> { @@ -567,3 +604,42 @@ impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> { } } +impl<'tcx> QueryDescription<'tcx> for queries::optimized_mir<'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 mir: Option<::mir::Mir<'tcx>> = tcx.on_disk_query_result_cache + .try_load_query_result(tcx, id); + mir.map(|x| tcx.alloc_mir(x)) + } +} + +macro_rules! impl_disk_cacheable_query( + ($query_name:ident, |$key:tt| $cond:expr) => { + impl<'tcx> QueryDescription<'tcx> for queries::$query_name<'tcx> { + #[inline] + fn cache_on_disk($key: Self::Key) -> bool { + $cond + } + + #[inline] + fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, + id: SerializedDepNodeIndex) + -> Option { + tcx.on_disk_query_result_cache.try_load_query_result(tcx, id) + } + } + } +); + +impl_disk_cacheable_query!(unsafety_check_result, |def_id| def_id.is_local()); +impl_disk_cacheable_query!(borrowck, |def_id| def_id.is_local()); +impl_disk_cacheable_query!(mir_borrowck, |def_id| def_id.is_local()); +impl_disk_cacheable_query!(mir_const_qualif, |def_id| def_id.is_local()); +impl_disk_cacheable_query!(contains_extern_indicator, |_| true); +impl_disk_cacheable_query!(def_symbol_name, |_| true); diff --git a/src/librustc/ty/maps/on_disk_cache.rs b/src/librustc/ty/maps/on_disk_cache.rs index 8dc9b0877a01..079b518efd89 100644 --- a/src/librustc/ty/maps/on_disk_cache.rs +++ b/src/librustc/ty/maps/on_disk_cache.rs @@ -207,6 +207,16 @@ impl<'sess> OnDiskCache<'sess> { // 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)?; + encode_query_results::(tcx, enc, qri)?; + encode_query_results::(tcx, enc, qri)?; + encode_query_results::(tcx, enc, qri)?; } // Encode diagnostics diff --git a/src/librustc/ty/maps/plumbing.rs b/src/librustc/ty/maps/plumbing.rs index fdaa13e7fd16..ec6d190b8bde 100644 --- a/src/librustc/ty/maps/plumbing.rs +++ b/src/librustc/ty/maps/plumbing.rs @@ -974,4 +974,7 @@ impl_load_from_cache!( BorrowCheck => borrowck, MirBorrowCheck => mir_borrowck, MirConstQualif => mir_const_qualif, + SymbolName => def_symbol_name, + ConstIsRvaluePromotableToStatic => const_is_rvalue_promotable_to_static, + ContainsExternIndicator => contains_extern_indicator, );