Skip to content

Commit

Permalink
Rollup merge of rust-lang#62169 - Zoxc:store-query-results, r=eddyb
Browse files Browse the repository at this point in the history
Derive which queries to save using the proc macro

Based on rust-lang#62166.

r? @eddyb
  • Loading branch information
Mark-Simulacrum authored Jul 4, 2019
2 parents aa1e9be + b9344e3 commit 13fff3d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
5 changes: 0 additions & 5 deletions src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,6 @@ rustc_queries! {
"const-evaluating `{}`",
tcx.def_path_str(key.value.instance.def.def_id())
}
cache_on_disk_if(_, opt_result) {
// Only store results without errors
// FIXME: We never store these
opt_result.map_or(true, |r| r.is_ok())
}
}

/// Results of evaluating const items or constants embedded in
Expand Down
32 changes: 13 additions & 19 deletions src/librustc/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,28 +201,22 @@ impl<'sess> OnDiskCache<'sess> {
let mut query_result_index = EncodedQueryResultIndex::new();

time(tcx.sess, "encode query results", || {
use crate::ty::query::queries::*;
let enc = &mut encoder;
let qri = &mut query_result_index;

encode_query_results::<type_of<'_>, _>(tcx, enc, qri)?;
encode_query_results::<generics_of<'_>, _>(tcx, enc, qri)?;
encode_query_results::<predicates_of<'_>, _>(tcx, enc, qri)?;
encode_query_results::<used_trait_imports<'_>, _>(tcx, enc, qri)?;
encode_query_results::<typeck_tables_of<'_>, _>(tcx, enc, qri)?;
encode_query_results::<codegen_fulfill_obligation<'_>, _>(tcx, enc, qri)?;
encode_query_results::<optimized_mir<'_>, _>(tcx, enc, qri)?;
encode_query_results::<unsafety_check_result<'_>, _>(tcx, enc, qri)?;
encode_query_results::<borrowck<'_>, _>(tcx, enc, qri)?;
encode_query_results::<mir_borrowck<'_>, _>(tcx, enc, qri)?;
encode_query_results::<mir_const_qualif<'_>, _>(tcx, enc, qri)?;
encode_query_results::<const_is_rvalue_promotable_to_static<'_>, _>(tcx, enc, qri)?;
encode_query_results::<symbol_name<'_>, _>(tcx, enc, qri)?;
encode_query_results::<check_match<'_>, _>(tcx, enc, qri)?;
encode_query_results::<codegen_fn_attrs<'_>, _>(tcx, enc, qri)?;
encode_query_results::<specialization_graph_of<'_>, _>(tcx, enc, qri)?;
encode_query_results::<const_eval<'_>, _>(tcx, enc, qri)?;
// FIXME: Include const_eval_raw?
macro_rules! encode_queries {
($($query:ident,)*) => {
$(
encode_query_results::<ty::query::queries::$query<'_>, _>(
tcx,
enc,
qri
)?;
)*
}
}

rustc_cached_queries!(encode_queries!);

Ok(())
})?;
Expand Down
13 changes: 13 additions & 0 deletions src/librustc_macros/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
let mut dep_node_force_stream = quote! {};
let mut try_load_from_on_disk_cache_stream = quote! {};
let mut no_force_queries = Vec::new();
let mut cached_queries = quote! {};

for group in groups.0 {
let mut group_stream = quote! {};
Expand All @@ -427,6 +428,12 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
_ => quote! { #result_full },
};

if modifiers.cache.is_some() {
cached_queries.extend(quote! {
#name,
});
}

if modifiers.cache.is_some() && !modifiers.no_force {
try_load_from_on_disk_cache_stream.extend(quote! {
DepKind::#name => {
Expand Down Expand Up @@ -549,6 +556,12 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
}
}
}
macro_rules! rustc_cached_queries {
($($macro:tt)*) => {
$($macro)*(#cached_queries);
}
}

#query_description_stream

impl DepNode {
Expand Down

0 comments on commit 13fff3d

Please sign in to comment.