Skip to content

Commit 49fd71b

Browse files
committed
[incremental] Don't panic if decoding the cache fails
If the cached data can't be loaded from disk, just issue a warning to the user so they know why compilation is taking longer than usual but don't fail the entire compilation since we can recover by ignorning the on disk cache. In the same way, if the disk cache can't be deserialized (because it has been corrupted for some reason), report the issue as a warning and continue without failing the compilation. `Decodable::decode()` tends to panic with various errors like "entered unreachable code" or "index out of range" if the input data is corrupted. Work around this by catching panics from the `decode()` calls when joining the thread and continuing without the cached data. Fixes #48847
1 parent 482a913 commit 49fd71b

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

src/librustc_driver/driver.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,9 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
901901
Some(future) => {
902902
let prev_graph = time(sess, "blocked while dep-graph loading finishes", || {
903903
future.open()
904-
.expect("Could not join with background dep_graph thread")
904+
.unwrap_or_else(|e| rustc_incremental::LoadResult::Error {
905+
message: format!("could not decode incremental cache: {:?}", e)
906+
})
905907
.open(sess)
906908
});
907909
DepGraph::new(prev_graph)

src/librustc_incremental/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub use assert_dep_graph::assert_dep_graph;
3939
pub use persist::dep_graph_tcx_init;
4040
pub use persist::load_dep_graph;
4141
pub use persist::load_query_result_cache;
42+
pub use persist::LoadResult;
4243
pub use persist::save_dep_graph;
4344
pub use persist::save_trans_partition;
4445
pub use persist::save_work_products;

src/librustc_incremental/persist/load.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ impl LoadResult<PreviousDepGraph> {
8989
pub fn open(self, sess: &Session) -> PreviousDepGraph {
9090
match self {
9191
LoadResult::Error { message } => {
92-
sess.fatal(&message) /* never returns */
92+
sess.warn(&message);
93+
PreviousDepGraph::new(SerializedDepGraph::new())
9394
},
9495
LoadResult::DataOutOfDate => {
9596
if let Err(err) = delete_all_session_dir_contents(sess) {

src/librustc_incremental/persist/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub use self::fs::prepare_session_directory;
2727
pub use self::load::dep_graph_tcx_init;
2828
pub use self::load::load_dep_graph;
2929
pub use self::load::load_query_result_cache;
30+
pub use self::load::LoadResult;
3031
pub use self::save::save_dep_graph;
3132
pub use self::save::save_work_products;
3233
pub use self::work_product::save_trans_partition;

0 commit comments

Comments
 (0)