1
Fork 0

Only create OnDiskCache in incremental compilation mode

This lets us skip doing useless work when we're not in incremental
compilation mode.
This commit is contained in:
Aaron Hill 2020-11-19 15:49:45 -05:00
parent fe982319aa
commit d00ed01876
No known key found for this signature in database
GPG key ID: B4087E510E98B164
6 changed files with 33 additions and 17 deletions

View file

@ -199,9 +199,14 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
}))
}
pub fn load_query_result_cache(sess: &Session) -> OnDiskCache<'_> {
/// Attempts to load the query result cache from disk
///
/// If we are not in incremental compilation mode, returns `None`.
/// Otherwise, tries to load the query result cache from disk,
/// creating an empty cache if it could not be loaded.
pub fn load_query_result_cache(sess: &Session) -> Option<OnDiskCache<'_>> {
if sess.opts.incremental.is_none() {
return OnDiskCache::new_empty(sess.source_map());
return None;
}
let _prof_timer = sess.prof.generic_activity("incr_comp_load_query_result_cache");
@ -211,7 +216,9 @@ pub fn load_query_result_cache(sess: &Session) -> OnDiskCache<'_> {
&query_cache_path(sess),
sess.is_nightly_build(),
) {
LoadResult::Ok { data: (bytes, start_pos) } => OnDiskCache::new(sess, bytes, start_pos),
_ => OnDiskCache::new_empty(sess.source_map()),
LoadResult::Ok { data: (bytes, start_pos) } => {
Some(OnDiskCache::new(sess, bytes, start_pos))
}
_ => Some(OnDiskCache::new_empty(sess.source_map())),
}
}