diff options
| author | bors <bors@rust-lang.org> | 2022-09-14 02:39:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-09-14 02:39:51 +0000 |
| commit | a5b58addae4d629734ebbfc9c69f4e0653b99569 (patch) | |
| tree | e37ff624b1601fd747dc878ec10b9bf8521a1cc6 /compiler/rustc_query_impl/src | |
| parent | 88a192257ce110e7fb1732aa2b65e481f811db7a (diff) | |
| parent | 0a9d7dbca23bb05fab13c1dc75a87cdb2bf69ff5 (diff) | |
| download | rust-a5b58addae4d629734ebbfc9c69f4e0653b99569.tar.gz rust-a5b58addae4d629734ebbfc9c69f4e0653b99569.zip | |
Auto merge of #101307 - jyn514:simplify-storage, r=cjgillot
Simplify caching and storage for queries I highly recommend reviewing commit-by-commit; each individual commit is quite small but it can be hard to see looking at the overall diff that the behavior is the same. Each commit depends on the previous. r? `@cjgillot`
Diffstat (limited to 'compiler/rustc_query_impl/src')
| -rw-r--r-- | compiler/rustc_query_impl/src/lib.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_query_impl/src/plumbing.rs | 27 |
2 files changed, 26 insertions, 3 deletions
diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 26d397f70e0..c87d26b3950 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -17,7 +17,7 @@ extern crate rustc_middle; use rustc_data_structures::sync::AtomicU64; use rustc_middle::arena::Arena; -use rustc_middle::dep_graph::{self, DepKindStruct, SerializedDepNodeIndex}; +use rustc_middle::dep_graph::{self, DepKindStruct}; use rustc_middle::ty::query::{query_keys, query_storage, query_stored, query_values}; use rustc_middle::ty::query::{ExternProviders, Providers, QueryEngine}; use rustc_middle::ty::{self, TyCtxt}; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 96679281f07..6fb3c69b1f4 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -3,6 +3,7 @@ //! manage the caches, and so forth. use crate::keys::Key; +use crate::on_disk_cache::CacheDecoder; use crate::{on_disk_cache, Queries}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::{AtomicU64, Lock}; @@ -19,6 +20,7 @@ use rustc_query_system::query::{ QuerySideEffects, QueryStackFrame, }; use rustc_query_system::Value; +use rustc_serialize::Decodable; use std::any::Any; use std::num::NonZeroU64; use thin_vec::ThinVec; @@ -253,6 +255,18 @@ macro_rules! get_provider { }; } +macro_rules! should_ever_cache_on_disk { + ([]) => {{ + None + }}; + ([(cache) $($rest:tt)*]) => {{ + Some($crate::plumbing::try_load_from_disk::<Self::Value>) + }}; + ([$other:tt $($modifiers:tt)*]) => { + should_ever_cache_on_disk!([$($modifiers)*]) + }; +} + pub(crate) fn create_query_frame< 'tcx, K: Copy + Key + for<'a> HashStable<StableHashingContext<'a>>, @@ -313,6 +327,16 @@ where } } +pub(crate) fn try_load_from_disk<'tcx, V>( + tcx: QueryCtxt<'tcx>, + id: SerializedDepNodeIndex, +) -> Option<V> +where + V: for<'a> Decodable<CacheDecoder<'a, 'tcx>>, +{ + tcx.on_disk_cache().as_ref()?.try_load_query_result(*tcx, id) +} + fn force_from_dep_node<'tcx, Q>(tcx: TyCtxt<'tcx>, dep_node: DepNode) -> bool where Q: QueryDescription<QueryCtxt<'tcx>>, @@ -418,8 +442,7 @@ macro_rules! define_queries { hash_result: hash_result!([$($modifiers)*]), handle_cycle_error: handle_cycle_error!([$($modifiers)*]), compute, - cache_on_disk, - try_load_from_disk: Self::TRY_LOAD_FROM_DISK, + try_load_from_disk: if cache_on_disk { should_ever_cache_on_disk!([$($modifiers)*]) } else { None }, } } |
