about summary refs log tree commit diff
path: root/compiler/rustc_incremental/src
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2020-11-19 15:49:45 -0500
committerAaron Hill <aa1ronham@gmail.com>2020-11-19 15:50:55 -0500
commitd00ed018767f5ffb4d17971147fadeb860891f8d (patch)
tree5bd12b809f73fc7df149b8fe87b1d061224f9390 /compiler/rustc_incremental/src
parentfe982319aa0aa5bbfc2795791a753832292bd2ba (diff)
downloadrust-d00ed018767f5ffb4d17971147fadeb860891f8d.tar.gz
rust-d00ed018767f5ffb4d17971147fadeb860891f8d.zip
Only create `OnDiskCache` in incremental compilation mode
This lets us skip doing useless work when we're not in incremental
compilation mode.
Diffstat (limited to 'compiler/rustc_incremental/src')
-rw-r--r--compiler/rustc_incremental/src/persist/load.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/compiler/rustc_incremental/src/persist/load.rs b/compiler/rustc_incremental/src/persist/load.rs
index 578c045a2b4..201f381f889 100644
--- a/compiler/rustc_incremental/src/persist/load.rs
+++ b/compiler/rustc_incremental/src/persist/load.rs
@@ -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())),
     }
 }