Skip to content

Commit 4c448b8

Browse files
WIP: Cache more queries.
1 parent dbcbc37 commit 4c448b8

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

src/librustc/ty/maps/config.rs

+77-1
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ pub trait QueryConfig {
2727
pub(super) trait QueryDescription<'tcx>: QueryConfig {
2828
fn describe(tcx: TyCtxt, key: Self::Key) -> String;
2929

30+
#[inline]
3031
fn cache_on_disk(_: Self::Key) -> bool {
3132
false
3233
}
3334

3435
fn try_load_from_disk(_: TyCtxt<'_, 'tcx, 'tcx>,
3536
_: SerializedDepNodeIndex)
3637
-> Option<Self::Value> {
37-
bug!("QueryDescription::load_from_disk() called for unsupport query.")
38+
bug!("QueryDescription::load_from_disk() called for an unsupported query.")
3839
}
3940
}
4041

@@ -166,6 +167,18 @@ impl<'tcx> QueryDescription<'tcx> for queries::symbol_name<'tcx> {
166167
fn describe(_tcx: TyCtxt, instance: ty::Instance<'tcx>) -> String {
167168
format!("computing the symbol for `{}`", instance)
168169
}
170+
171+
#[inline]
172+
fn cache_on_disk(_: Self::Key) -> bool {
173+
true
174+
}
175+
176+
#[inline]
177+
fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
178+
id: SerializedDepNodeIndex)
179+
-> Option<Self::Value> {
180+
tcx.on_disk_query_result_cache.try_load_query_result(tcx, id)
181+
}
169182
}
170183

171184
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
234247
format!("const checking if rvalue is promotable to static `{}`",
235248
tcx.item_path_str(def_id))
236249
}
250+
251+
#[inline]
252+
fn cache_on_disk(_: Self::Key) -> bool {
253+
true
254+
}
255+
256+
#[inline]
257+
fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
258+
id: SerializedDepNodeIndex)
259+
-> Option<Self::Value> {
260+
tcx.on_disk_query_result_cache.try_load_query_result(tcx, id)
261+
}
237262
}
238263

239264
impl<'tcx> QueryDescription<'tcx> for queries::rvalue_promotable_map<'tcx> {
@@ -254,6 +279,18 @@ impl<'tcx> QueryDescription<'tcx> for queries::trans_fulfill_obligation<'tcx> {
254279
fn describe(tcx: TyCtxt, key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> String {
255280
format!("checking if `{}` fulfills its obligations", tcx.item_path_str(key.1.def_id()))
256281
}
282+
283+
#[inline]
284+
fn cache_on_disk(_: Self::Key) -> bool {
285+
true
286+
}
287+
288+
#[inline]
289+
fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
290+
id: SerializedDepNodeIndex)
291+
-> Option<Self::Value> {
292+
tcx.on_disk_query_result_cache.try_load_query_result(tcx, id)
293+
}
257294
}
258295

259296
impl<'tcx> QueryDescription<'tcx> for queries::trait_impls_of<'tcx> {
@@ -567,3 +604,42 @@ impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
567604
}
568605
}
569606

607+
impl<'tcx> QueryDescription<'tcx> for queries::optimized_mir<'tcx> {
608+
#[inline]
609+
fn cache_on_disk(def_id: Self::Key) -> bool {
610+
def_id.is_local()
611+
}
612+
613+
fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
614+
id: SerializedDepNodeIndex)
615+
-> Option<Self::Value> {
616+
let mir: Option<::mir::Mir<'tcx>> = tcx.on_disk_query_result_cache
617+
.try_load_query_result(tcx, id);
618+
mir.map(|x| tcx.alloc_mir(x))
619+
}
620+
}
621+
622+
macro_rules! impl_disk_cacheable_query(
623+
($query_name:ident, |$key:tt| $cond:expr) => {
624+
impl<'tcx> QueryDescription<'tcx> for queries::$query_name<'tcx> {
625+
#[inline]
626+
fn cache_on_disk($key: Self::Key) -> bool {
627+
$cond
628+
}
629+
630+
#[inline]
631+
fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
632+
id: SerializedDepNodeIndex)
633+
-> Option<Self::Value> {
634+
tcx.on_disk_query_result_cache.try_load_query_result(tcx, id)
635+
}
636+
}
637+
}
638+
);
639+
640+
impl_disk_cacheable_query!(unsafety_check_result, |def_id| def_id.is_local());
641+
impl_disk_cacheable_query!(borrowck, |def_id| def_id.is_local());
642+
impl_disk_cacheable_query!(mir_borrowck, |def_id| def_id.is_local());
643+
impl_disk_cacheable_query!(mir_const_qualif, |def_id| def_id.is_local());
644+
impl_disk_cacheable_query!(contains_extern_indicator, |_| true);
645+
impl_disk_cacheable_query!(def_symbol_name, |_| true);

src/librustc/ty/maps/on_disk_cache.rs

+10
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ impl<'sess> OnDiskCache<'sess> {
207207

208208
// Encode TypeckTables
209209
encode_query_results::<typeck_tables_of, _>(tcx, enc, qri)?;
210+
encode_query_results::<optimized_mir, _>(tcx, enc, qri)?;
211+
encode_query_results::<unsafety_check_result, _>(tcx, enc, qri)?;
212+
encode_query_results::<borrowck, _>(tcx, enc, qri)?;
213+
encode_query_results::<mir_borrowck, _>(tcx, enc, qri)?;
214+
encode_query_results::<mir_const_qualif, _>(tcx, enc, qri)?;
215+
encode_query_results::<def_symbol_name, _>(tcx, enc, qri)?;
216+
encode_query_results::<const_is_rvalue_promotable_to_static, _>(tcx, enc, qri)?;
217+
encode_query_results::<contains_extern_indicator, _>(tcx, enc, qri)?;
218+
encode_query_results::<symbol_name, _>(tcx, enc, qri)?;
219+
encode_query_results::<trans_fulfill_obligation, _>(tcx, enc, qri)?;
210220
}
211221

212222
// Encode diagnostics

src/librustc/ty/maps/plumbing.rs

+3
Original file line numberDiff line numberDiff line change
@@ -974,4 +974,7 @@ impl_load_from_cache!(
974974
BorrowCheck => borrowck,
975975
MirBorrowCheck => mir_borrowck,
976976
MirConstQualif => mir_const_qualif,
977+
SymbolName => def_symbol_name,
978+
ConstIsRvaluePromotableToStatic => const_is_rvalue_promotable_to_static,
979+
ContainsExternIndicator => contains_extern_indicator,
977980
);

0 commit comments

Comments
 (0)