Skip to content

Commit accadb2

Browse files
committed
Rollup merge of rust-lang#48181 - michaelwoerister:fix-incr-dir-finalization, r=nikomatsakis
incr.comp.: Run cache directory garbage collection before loading dep-graph. Prior to this PR, the incr. comp. cache directory would only be garbage collected after the final output artifacts were generated. However, compilation often aborts earlier and in the case of the RLS, which starts lots of compilation sessions, we might fill up the cache directory with chunk sessions. This PR makes the compiler do a garbage collection run before loading the dep-graph. cc @nrc rust-lang#48172 r? @nikomatsakis
2 parents dc9d93f + 580dd42 commit accadb2

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

src/librustc_driver/driver.rs

+9
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,15 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
660660
disambiguator,
661661
);
662662

663+
if sess.opts.incremental.is_some() {
664+
time(time_passes, "garbage collect incremental cache directory", || {
665+
if let Err(e) = rustc_incremental::garbage_collect_session_directories(sess) {
666+
warn!("Error while trying to garbage collect incremental \
667+
compilation cache directory: {}", e);
668+
}
669+
});
670+
}
671+
663672
// If necessary, compute the dependency graph (in the background).
664673
let future_dep_graph = if sess.opts.build_dep_graph() {
665674
Some(rustc_incremental::load_dep_graph(sess, time_passes))

src/librustc_incremental/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ pub use persist::in_incr_comp_dir;
4646
pub use persist::prepare_session_directory;
4747
pub use persist::finalize_session_directory;
4848
pub use persist::delete_workproduct_files;
49+
pub use persist::garbage_collect_session_directories;

src/librustc_incremental/persist/fs.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ fn timestamp_to_string(timestamp: SystemTime) -> String {
603603
}
604604

605605
fn string_to_timestamp(s: &str) -> Result<SystemTime, ()> {
606-
let micros_since_unix_epoch = u64::from_str_radix(s, 36);
606+
let micros_since_unix_epoch = u64::from_str_radix(s, INT_ENCODE_BASE as u32);
607607

608608
if micros_since_unix_epoch.is_err() {
609609
return Err(())
@@ -733,6 +733,20 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
733733
})
734734
.collect();
735735

736+
// Delete all session directories that don't have a lock file.
737+
for directory_name in session_directories {
738+
if !lock_file_to_session_dir.values().any(|dir| *dir == directory_name) {
739+
let path = crate_directory.join(directory_name);
740+
if let Err(err) = safe_remove_dir_all(&path) {
741+
sess.warn(&format!("Failed to garbage collect invalid incremental \
742+
compilation session directory `{}`: {}",
743+
path.display(),
744+
err));
745+
}
746+
}
747+
}
748+
749+
// Now garbage collect the valid session directories.
736750
let mut deletion_candidates = vec![];
737751
let mut definitely_delete = vec![];
738752

src/librustc_incremental/persist/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ mod save;
2020
mod work_product;
2121
mod file_format;
2222

23-
pub use self::fs::prepare_session_directory;
2423
pub use self::fs::finalize_session_directory;
24+
pub use self::fs::garbage_collect_session_directories;
2525
pub use self::fs::in_incr_comp_dir;
26+
pub use self::fs::prepare_session_directory;
2627
pub use self::load::dep_graph_tcx_init;
2728
pub use self::load::load_dep_graph;
2829
pub use self::load::load_query_result_cache;

0 commit comments

Comments
 (0)