mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
Rollup merge of #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 https://github.com/rust-lang/rust/issues/48172 r? @nikomatsakis
This commit is contained in:
commit
accadb2ce5
@ -660,6 +660,15 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
|
||||
disambiguator,
|
||||
);
|
||||
|
||||
if sess.opts.incremental.is_some() {
|
||||
time(time_passes, "garbage collect incremental cache directory", || {
|
||||
if let Err(e) = rustc_incremental::garbage_collect_session_directories(sess) {
|
||||
warn!("Error while trying to garbage collect incremental \
|
||||
compilation cache directory: {}", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// If necessary, compute the dependency graph (in the background).
|
||||
let future_dep_graph = if sess.opts.build_dep_graph() {
|
||||
Some(rustc_incremental::load_dep_graph(sess, time_passes))
|
||||
|
@ -46,3 +46,4 @@ pub use persist::in_incr_comp_dir;
|
||||
pub use persist::prepare_session_directory;
|
||||
pub use persist::finalize_session_directory;
|
||||
pub use persist::delete_workproduct_files;
|
||||
pub use persist::garbage_collect_session_directories;
|
||||
|
@ -603,7 +603,7 @@ fn timestamp_to_string(timestamp: SystemTime) -> String {
|
||||
}
|
||||
|
||||
fn string_to_timestamp(s: &str) -> Result<SystemTime, ()> {
|
||||
let micros_since_unix_epoch = u64::from_str_radix(s, 36);
|
||||
let micros_since_unix_epoch = u64::from_str_radix(s, INT_ENCODE_BASE as u32);
|
||||
|
||||
if micros_since_unix_epoch.is_err() {
|
||||
return Err(())
|
||||
@ -733,6 +733,20 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Delete all session directories that don't have a lock file.
|
||||
for directory_name in session_directories {
|
||||
if !lock_file_to_session_dir.values().any(|dir| *dir == directory_name) {
|
||||
let path = crate_directory.join(directory_name);
|
||||
if let Err(err) = safe_remove_dir_all(&path) {
|
||||
sess.warn(&format!("Failed to garbage collect invalid incremental \
|
||||
compilation session directory `{}`: {}",
|
||||
path.display(),
|
||||
err));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now garbage collect the valid session directories.
|
||||
let mut deletion_candidates = vec![];
|
||||
let mut definitely_delete = vec![];
|
||||
|
||||
|
@ -20,9 +20,10 @@ mod save;
|
||||
mod work_product;
|
||||
mod file_format;
|
||||
|
||||
pub use self::fs::prepare_session_directory;
|
||||
pub use self::fs::finalize_session_directory;
|
||||
pub use self::fs::garbage_collect_session_directories;
|
||||
pub use self::fs::in_incr_comp_dir;
|
||||
pub use self::fs::prepare_session_directory;
|
||||
pub use self::load::dep_graph_tcx_init;
|
||||
pub use self::load::load_dep_graph;
|
||||
pub use self::load::load_query_result_cache;
|
||||
|
Loading…
Reference in New Issue
Block a user