1//! This module manages how the incremental compilation cache is represented in
2//! the file system.
3//!
4//! Incremental compilation caches are managed according to a copy-on-write
5//! strategy: Once a complete, consistent cache version is finalized, it is
6//! never modified. Instead, when a subsequent compilation session is started,
7//! the compiler will allocate a new version of the cache that starts out as
8//! a copy of the previous version. Then only this new copy is modified and it
9//! will not be visible to other processes until it is finalized. This ensures
10//! that multiple compiler processes can be executed concurrently for the same
11//! crate without interfering with each other or blocking each other.
12//!
13//! More concretely this is implemented via the following protocol:
14//!
15//! 1. For a newly started compilation session, the compiler allocates a
16//! new `session` directory within the incremental compilation directory.
17//! This session directory will have a unique name that ends with the suffix
18//! "-working" and that contains a creation timestamp.
19//! 2. Next, the compiler looks for the newest finalized session directory,
20//! that is, a session directory from a previous compilation session that
21//! has been marked as valid and consistent. A session directory is
22//! considered finalized if the "-working" suffix in the directory name has
23//! been replaced by the SVH of the crate.
24//! 3. Once the compiler has found a valid, finalized session directory, it will
25//! hard-link/copy its contents into the new "-working" directory. If all
26//! goes well, it will have its own, private copy of the source directory and
27//! subsequently not have to worry about synchronizing with other compiler
28//! processes.
29//! 4. Now the compiler can do its normal compilation process, which involves
30//! reading and updating its private session directory.
31//! 5. When compilation finishes without errors, the private session directory
32//! will be in a state where it can be used as input for other compilation
33//! sessions. That is, it will contain a dependency graph and cache artifacts
34//! that are consistent with the state of the source code it was compiled
35//! from, with no need to change them ever again. At this point, the compiler
36//! finalizes and "publishes" its private session directory by renaming it
37//! from "s-{timestamp}-{random}-working" to "s-{timestamp}-{SVH}".
38//! 6. At this point the "old" session directory that we copied our data from
39//! at the beginning of the session has become obsolete because we have just
40//! published a more current version. Thus the compiler will delete it.
41//!
42//! ## Garbage Collection
43//!
44//! Naively following the above protocol might lead to old session directories
45//! piling up if a compiler instance crashes for some reason before its able to
46//! remove its private session directory. In order to avoid wasting disk space,
47//! the compiler also does some garbage collection each time it is started in
48//! incremental compilation mode. Specifically, it will scan the incremental
49//! compilation directory for private session directories that are not in use
50//! any more and will delete those. It will also delete any finalized session
51//! directories for a given crate except for the most recent one.
52//!
53//! ## Synchronization
54//!
55//! There is some synchronization needed in order for the compiler to be able to
56//! determine whether a given private session directory is not in use any more.
57//! This is done by creating a lock file for each session directory and
58//! locking it while the directory is still being used. Since file locks have
59//! operating system support, we can rely on the lock being released if the
60//! compiler process dies for some unexpected reason. Thus, when garbage
61//! collecting private session directories, the collecting process can determine
62//! whether the directory is still in use by trying to acquire a lock on the
63//! file. If locking the file fails, the original process must still be alive.
64//! If locking the file succeeds, we know that the owning process is not alive
65//! any more and we can safely delete the directory.
66//! There is still a small time window between the original process creating the
67//! lock file and actually locking it. In order to minimize the chance that
68//! another process tries to acquire the lock in just that instance, only
69//! session directories that are older than a few seconds are considered for
70//! garbage collection.
71//!
72//! Another case that has to be considered is what happens if one process
73//! deletes a finalized session directory that another process is currently
74//! trying to copy from. This case is also handled via the lock file. Before
75//! a process starts copying a finalized session directory, it will acquire a
76//! shared lock on the directory's lock file. Any garbage collecting process,
77//! on the other hand, will acquire an exclusive lock on the lock file.
78//! Thus, if a directory is being collected, any reader process will fail
79//! acquiring the shared lock and will leave the directory alone. Conversely,
80//! if a collecting process can't acquire the exclusive lock because the
81//! directory is currently being read from, it will leave collecting that
82//! directory to another process at a later point in time.
83//! The exact same scheme is also used when reading the metadata hashes file
84//! from an extern crate. When a crate is compiled, the hash values of its
85//! metadata are stored in a file in its session directory. When the
86//! compilation session of another crate imports the first crate's metadata,
87//! it also has to read in the accompanying metadata hashes. It thus will access
88//! the finalized session directory of all crates it links to and while doing
89//! so, it will also place a read lock on that the respective session directory
90//! so that it won't be deleted while the metadata hashes are loaded.
91//!
92//! ## Preconditions
93//!
94//! This system relies on two features being available in the file system in
95//! order to work really well: file locking and hard linking.
96//! If hard linking is not available (like on FAT) the data in the cache
97//! actually has to be copied at the beginning of each session.
98//! If file locking does not work reliably (like on NFS), some of the
99//! synchronization will go haywire.
100//! In both cases we recommend to locate the incremental compilation directory
101//! on a file system that supports these things.
102//! It might be a good idea though to try and detect whether we are on an
103//! unsupported file system and emit a warning in that case. This is not yet
104//! implemented.
105106use std::fsas std_fs;
107use std::io::{self, ErrorKind};
108use std::path::{Path, PathBuf};
109use std::time::{Duration, SystemTime, UNIX_EPOCH};
110111use rand::{RngCore, rng};
112use rustc_data_structures::base_n::{BaseNString, CASE_INSENSITIVE, ToBaseN};
113use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
114use rustc_data_structures::svh::Svh;
115use rustc_data_structures::unord::{UnordMap, UnordSet};
116use rustc_data_structures::{base_n, flock};
117use rustc_fs_util::{LinkOrCopy, link_or_copy, try_canonicalize};
118use rustc_session::{IncrCompSession, Session, StableCrateId};
119use rustc_span::{Symbol, bug};
120use tracing::debug;
121122use crate::diagnostics;
123124#[cfg(test)]
125mod tests;
126127const LOCK_FILE_EXT: &str = ".lock";
128const DEP_GRAPH_FILENAME: &str = "dep-graph.bin";
129const STAGING_DEP_GRAPH_FILENAME: &str = "dep-graph.part.bin";
130const WORK_PRODUCTS_FILENAME: &str = "work-products.bin";
131const QUERY_CACHE_FILENAME: &str = "query-cache.bin";
132133// We encode integers using the following base, so they are shorter than decimal
134// or hexadecimal numbers (we want short file and directory names). Since these
135// numbers will be used in file names, we choose an encoding that is not
136// case-sensitive (as opposed to base64, for example).
137const INT_ENCODE_BASE: usize = base_n::CASE_INSENSITIVE;
138139/// Returns the path to a session's dependency graph.
140pub(crate) fn dep_graph_path(incr_comp_session: &IncrCompSession) -> PathBuf {
141in_incr_comp_dir_sess(incr_comp_session, DEP_GRAPH_FILENAME)
142}
143144/// Returns the path to a session's staging dependency graph.
145///
146/// On the difference between dep-graph and staging dep-graph,
147/// see `build_dep_graph`.
148pub(crate) fn staging_dep_graph_path(incr_comp_session: &IncrCompSession) -> PathBuf {
149in_incr_comp_dir_sess(incr_comp_session, STAGING_DEP_GRAPH_FILENAME)
150}
151152pub(crate) fn work_products_path(incr_comp_session: &IncrCompSession) -> PathBuf {
153in_incr_comp_dir_sess(incr_comp_session, WORK_PRODUCTS_FILENAME)
154}
155156/// Returns the path to a session's query cache.
157pub(crate) fn query_cache_path(incr_comp_session: &IncrCompSession) -> PathBuf {
158in_incr_comp_dir_sess(incr_comp_session, QUERY_CACHE_FILENAME)
159}
160161/// Locks a given session directory.
162fn lock_file_path(session_dir: &Path) -> PathBuf {
163let crate_dir = session_dir.parent().unwrap();
164165let directory_name = session_dir166 .file_name()
167 .unwrap()
168 .to_str()
169 .expect("malformed session dir name: contains non-Unicode characters");
170171let dash_indices: Vec<_> = directory_name.match_indices('-').map(|(idx, _)| idx).collect();
172if dash_indices.len() != 3 {
173bug_impl(None,
format_args!("Encountered incremental compilation session directory with malformed name: {0}",
session_dir.display()), Location::caller())bug!(
174"Encountered incremental compilation session directory with \
175 malformed name: {}",
176 session_dir.display()
177 )178 }
179180crate_dir.join(&directory_name[0..dash_indices[2]]).with_extension(&LOCK_FILE_EXT[1..])
181}
182183/// Returns the path for a given filename within the incremental compilation directory
184/// in the current session.
185pub fn in_incr_comp_dir_sess(incr_comp_session: &IncrCompSession, file_name: &str) -> PathBuf {
186incr_comp_session.session_directory.join(file_name)
187}
188189/// Allocates the private session directory.
190///
191/// If the result of this function is `Ok`, we have a valid incremental
192/// compilation session directory. A valid session
193/// directory is one that contains a locked lock file. It may or may not contain
194/// a dep-graph and work products from a previous session.
195///
196/// This always attempts to load a dep-graph from the directory.
197/// If loading fails for some reason, we fallback to a disabled `DepGraph`.
198/// See [`rustc_interface::queries::dep_graph`].
199///
200/// If this function returns an error, it may leave behind an invalid session directory.
201/// The garbage collection will take care of it.
202///
203/// [`rustc_interface::queries::dep_graph`]: ../../rustc_interface/struct.Queries.html#structfield.dep_graph
204pub(crate) fn prepare_session_directory(
205 sess: &Session,
206 crate_name: Symbol,
207 stable_crate_id: StableCrateId,
208) -> IncrCompSession {
209if !sess.opts.incremental.is_some() {
::core::panicking::panic("assertion failed: sess.opts.incremental.is_some()")
};assert!(sess.opts.incremental.is_some());
210211let _timer = sess.timer("incr_comp_prepare_session_directory");
212213{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:213",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(213u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("prepare_session_directory")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("prepare_session_directory");
214215// {incr-comp-dir}/{crate-name-and-disambiguator}
216let crate_dir = crate_path(sess, crate_name, stable_crate_id);
217{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:217",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(217u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("crate-dir: {0}",
crate_dir.display()) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("crate-dir: {}", crate_dir.display());
218create_dir(sess, &crate_dir, "crate");
219220// Hack: canonicalize the path *after creating the directory*
221 // because, on windows, long paths can cause problems;
222 // canonicalization inserts this weird prefix that makes windows
223 // tolerate long paths.
224let crate_dir = match try_canonicalize(&crate_dir) {
225Ok(v) => v,
226Err(err) => {
227sess.dcx().emit_fatal(diagnostics::CanonicalizePath { path: crate_dir, err });
228 }
229 };
230231let mut source_directories_already_tried = FxHashSet::default();
232233loop {
234// Generate a session directory of the form:
235 //
236 // {incr-comp-dir}/{crate-name-and-disambiguator}/s-{timestamp}-{random}-working
237let session_dir = generate_session_dir_path(&crate_dir);
238{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:238",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(238u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("session-dir: {0}",
session_dir.display()) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("session-dir: {}", session_dir.display());
239240// Lock the new session directory. If this fails, return an
241 // error without retrying
242let (directory_lock, lock_file_path) = lock_directory(sess, &session_dir);
243244// Now that we have the lock, we can actually create the session
245 // directory
246create_dir(sess, &session_dir, "session");
247248// Find a suitable source directory to copy from. Ignore those that we
249 // have already tried before.
250let source_directory = find_source_directory(&crate_dir, &source_directories_already_tried);
251252let Some(source_directory) = source_directoryelse {
253// There's nowhere to copy from, we're done
254{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:254",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(254u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("no source directory found. Continuing with empty session directory.")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
255"no source directory found. Continuing with empty session \
256 directory."
257);
258259return IncrCompSession { session_directory: session_dir, _lock_file: directory_lock };
260 };
261262{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:262",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(262u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("attempting to copy data from source: {0}",
source_directory.display()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("attempting to copy data from source: {}", source_directory.display());
263264// Try copying over all files from the source directory
265if let Ok(allows_links) = copy_files(sess, &session_dir, &source_directory) {
266{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:266",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(266u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("successfully copied data from: {0}",
source_directory.display()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("successfully copied data from: {}", source_directory.display());
267268if !allows_links {
269sess.dcx().emit_warn(diagnostics::HardLinkFailed { path: &session_dir });
270 }
271272return IncrCompSession { session_directory: session_dir, _lock_file: directory_lock };
273 } else {
274{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:274",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(274u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("copying failed - trying next directory")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("copying failed - trying next directory");
275276// Something went wrong while trying to copy/link files from the
277 // source directory. Try again with a different one.
278source_directories_already_tried.insert(source_directory);
279280// Try to remove the session directory we just allocated. We don't
281 // know if there's any garbage in it from the failed copy action.
282if let Err(err) = std_fs::remove_dir_all(&session_dir) {
283sess.dcx().emit_warn(diagnostics::DeletePartial { path: &session_dir, err });
284 }
285286delete_session_dir_lock_file(sess, &lock_file_path);
287drop(directory_lock);
288 }
289 }
290}
291292/// This function finalizes and thus 'publishes' the session directory by
293/// renaming it to `s-{timestamp}-{svh}` and releasing the file lock.
294/// This must not be called if there have been any compilation errors.
295pub fn finalize_session_directory(
296 sess: &Session,
297 incr_comp_session: Option<IncrCompSession>,
298 svh: Option<Svh>,
299) {
300if !sess.dcx().has_errors_or_delayed_bugs().is_none() {
::core::panicking::panic("assertion failed: sess.dcx().has_errors_or_delayed_bugs().is_none()")
};assert!(sess.dcx().has_errors_or_delayed_bugs().is_none());
301302if sess.opts.incremental.is_none() {
303return;
304 }
305let incr_comp_session = incr_comp_session.unwrap();
306// The svh is always produced when incr. comp. is enabled.
307let svh = svh.unwrap();
308309let _timer = sess.timer("incr_comp_finalize_session_directory");
310311let incr_comp_session_dir = incr_comp_session.session_directory.clone();
312313{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:313",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(313u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("finalize_session_directory() - session directory: {0}",
incr_comp_session_dir.display()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("finalize_session_directory() - session directory: {}", incr_comp_session_dir.display());
314315let mut sub_dir_name = incr_comp_session_dir316 .file_name()
317 .unwrap()
318 .to_str()
319 .expect("malformed session dir name: contains non-Unicode characters")
320 .to_string();
321322// Keep the 's-{timestamp}-{random-number}' prefix, but replace "working" with the SVH of the crate
323sub_dir_name.truncate(sub_dir_name.len() - "working".len());
324// Double-check that we kept this: "s-{timestamp}-{random-number}-"
325if !sub_dir_name.ends_with('-') {
{ ::core::panicking::panic_fmt(format_args!("{0:?}", sub_dir_name)); }
};assert!(sub_dir_name.ends_with('-'), "{:?}", sub_dir_name);
326if !(sub_dir_name.as_bytes().iter().filter(|b| **b == b'-').count() == 3) {
::core::panicking::panic("assertion failed: sub_dir_name.as_bytes().iter().filter(|b| **b == b\'-\').count() == 3")
};assert!(sub_dir_name.as_bytes().iter().filter(|b| **b == b'-').count() == 3);
327328// Append the SVH
329sub_dir_name.push_str(&svh.as_u128().to_base_fixed_len(CASE_INSENSITIVE));
330331// Create the full path
332let new_path = incr_comp_session_dir.parent().unwrap().join(&*sub_dir_name);
333{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:333",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(333u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("finalize_session_directory() - new path: {0}",
new_path.display()) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("finalize_session_directory() - new path: {}", new_path.display());
334335match rename_path_with_retry(&*incr_comp_session_dir, &new_path, 3) {
336Ok(_) => {
337{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:337",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(337u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("finalize_session_directory() - directory renamed successfully")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("finalize_session_directory() - directory renamed successfully");
338 }
339Err(e) => {
340// Warn about the error. However, no need to abort compilation now.
341sess.dcx().emit_note(diagnostics::Finalize { path: &incr_comp_session_dir, err: e });
342343{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:343",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(343u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("finalize_session_directory() - error")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("finalize_session_directory() - error");
344 }
345 }
346347drop(incr_comp_session); // Unlock incr comp session dir
348349let _ = garbage_collect_session_directories(sess, &new_path);
350}
351352pub(crate) fn delete_all_session_dir_contents(
353 incr_comp_session: &IncrCompSession,
354) -> io::Result<()> {
355let sess_dir_iterator = incr_comp_session.session_directory.read_dir()?;
356for entry in sess_dir_iterator {
357let entry = entry?;
358 safe_remove_file(&entry.path())?
359}
360Ok(())
361}
362363fn copy_files(sess: &Session, target_dir: &Path, source_dir: &Path) -> Result<bool, ()> {
364// We acquire a shared lock on the lock file of the directory, so that
365 // nobody deletes it out from under us while we are reading from it.
366let lock_file_path = lock_file_path(source_dir);
367368// not exclusive
369let Ok(_lock) = flock::Lock::new(
370&lock_file_path,
371false, // don't wait,
372false, // don't create
373false,
374 ) else {
375// Could not acquire the lock, don't try to copy from here
376return Err(());
377 };
378379let Ok(source_dir_iterator) = source_dir.read_dir() else {
380return Err(());
381 };
382383let mut files_linked = 0;
384let mut files_copied = 0;
385386for entry in source_dir_iterator {
387match entry {
388Ok(entry) => {
389let file_name = entry.file_name();
390391let target_file_path = target_dir.join(file_name);
392let source_path = entry.path();
393394{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:394",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(394u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("copying into session dir: {0}",
source_path.display()) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("copying into session dir: {}", source_path.display());
395match link_or_copy(source_path, target_file_path) {
396Ok(LinkOrCopy::Link) => files_linked += 1,
397Ok(LinkOrCopy::Copy) => files_copied += 1,
398Err(_) => return Err(()),
399 }
400 }
401Err(_) => return Err(()),
402 }
403 }
404405if sess.opts.unstable_opts.incremental_info {
406{
::std::io::_eprint(format_args!("[incremental] session directory: {0} files hard-linked\n",
files_linked));
};eprintln!(
407"[incremental] session directory: \
408 {files_linked} files hard-linked"
409);
410{
::std::io::_eprint(format_args!("[incremental] session directory: {0} files copied\n",
files_copied));
};eprintln!(
411"[incremental] session directory: \
412 {files_copied} files copied"
413);
414 }
415416Ok(files_linked > 0 || files_copied == 0)
417}
418419/// Generates unique directory path of the form:
420/// {crate_dir}/s-{timestamp}-{random-number}-working
421fn generate_session_dir_path(crate_dir: &Path) -> PathBuf {
422let timestamp = timestamp_to_string(SystemTime::now());
423{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:423",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(423u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("generate_session_dir_path: timestamp = {0}",
timestamp) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("generate_session_dir_path: timestamp = {}", timestamp);
424let random_number = rng().next_u32();
425{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:425",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(425u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("generate_session_dir_path: random_number = {0}",
random_number) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("generate_session_dir_path: random_number = {}", random_number);
426427// Chop the first 3 characters off the timestamp. Those 3 bytes will be zero for a while.
428let (zeroes, timestamp) = timestamp.split_at(3);
429{
match (&zeroes, &"000") {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(zeroes, "000");
430let directory_name =
431::alloc::__export::must_use({
::alloc::fmt::format(format_args!("s-{0}-{1}-working", timestamp,
random_number.to_base_fixed_len(CASE_INSENSITIVE)))
})format!("s-{}-{}-working", timestamp, random_number.to_base_fixed_len(CASE_INSENSITIVE));
432{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:432",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(432u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("generate_session_dir_path: directory_name = {0}",
directory_name) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("generate_session_dir_path: directory_name = {}", directory_name);
433let directory_path = crate_dir.join(directory_name);
434{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:434",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(434u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("generate_session_dir_path: directory_path = {0}",
directory_path.display()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("generate_session_dir_path: directory_path = {}", directory_path.display());
435directory_path436}
437438fn create_dir(sess: &Session, path: &Path, dir_tag: &str) {
439match std_fs::create_dir_all(path) {
440Ok(()) => {
441{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:441",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(441u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("{0} directory created successfully",
dir_tag) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("{} directory created successfully", dir_tag);
442 }
443Err(err) => {
444sess.dcx().emit_fatal(diagnostics::CreateIncrCompDir { tag: dir_tag, path, err })
445 }
446 }
447}
448449/// Allocate the lock-file and lock it.
450fn lock_directory(sess: &Session, session_dir: &Path) -> (flock::Lock, PathBuf) {
451let lock_file_path = lock_file_path(session_dir);
452{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:452",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(452u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("lock_directory() - lock_file: {0}",
lock_file_path.display()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("lock_directory() - lock_file: {}", lock_file_path.display());
453454match flock::Lock::new(
455&lock_file_path,
456false, // don't wait
457true, // create the lock file
458true,
459 ) {
460// the lock should be exclusive
461Ok(lock) => (lock, lock_file_path),
462Err(lock_err) => {
463let is_unsupported_lock = flock::Lock::error_unsupported(&lock_err);
464sess.dcx().emit_fatal(diagnostics::CreateLock {
465lock_err,
466session_dir,
467is_unsupported_lock,
468 is_cargo: rustc_session::utils::was_invoked_from_cargo(),
469 });
470 }
471 }
472}
473474fn delete_session_dir_lock_file(sess: &Session, lock_file_path: &Path) {
475if let Err(err) = safe_remove_file(lock_file_path) {
476sess.dcx().emit_warn(diagnostics::DeleteLock { path: lock_file_path, err });
477 }
478}
479480/// Finds the most recent published session directory that is not in the
481/// ignore-list.
482fn find_source_directory(
483 crate_dir: &Path,
484 source_directories_already_tried: &FxHashSet<PathBuf>,
485) -> Option<PathBuf> {
486let iter = crate_dir487 .read_dir()
488 .unwrap() // FIXME
489.filter_map(|e| e.ok().map(|e| e.path()));
490491find_source_directory_in_iter(iter, source_directories_already_tried)
492}
493494fn find_source_directory_in_iter<I>(
495 iter: I,
496 source_directories_already_tried: &FxHashSet<PathBuf>,
497) -> Option<PathBuf>
498where
499I: Iterator<Item = PathBuf>,
500{
501let mut best_candidate = (UNIX_EPOCH, None);
502503for session_dir in iter {
504{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:504",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(504u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("find_source_directory_in_iter - inspecting `{0}`",
session_dir.display()) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("find_source_directory_in_iter - inspecting `{}`", session_dir.display());
505506let Some(directory_name) = session_dir.file_name().unwrap().to_str() else {
507{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:507",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(507u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("find_source_directory_in_iter - ignoring")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("find_source_directory_in_iter - ignoring");
508continue;
509 };
510511if source_directories_already_tried.contains(&session_dir)
512 || !is_session_directory(&directory_name)
513 || !is_finalized(&directory_name)
514 {
515{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:515",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(515u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("find_source_directory_in_iter - ignoring")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("find_source_directory_in_iter - ignoring");
516continue;
517 }
518519let timestamp = match extract_timestamp_from_session_dir(&directory_name) {
520Ok(timestamp) => timestamp,
521Err(e) => {
522{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:522",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(522u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("unexpected incr-comp session dir: {0}: {1}",
session_dir.display(), e) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("unexpected incr-comp session dir: {}: {}", session_dir.display(), e);
523continue;
524 }
525 };
526527if timestamp > best_candidate.0 {
528 best_candidate = (timestamp, Some(session_dir.clone()));
529 }
530 }
531532best_candidate.1
533}
534535fn is_finalized(directory_name: &str) -> bool {
536 !directory_name.ends_with("-working")
537}
538539fn is_session_directory(directory_name: &str) -> bool {
540directory_name.starts_with("s-") && !directory_name.ends_with(LOCK_FILE_EXT)
541}
542543fn is_session_directory_lock_file(file_name: &str) -> bool {
544file_name.starts_with("s-") && file_name.ends_with(LOCK_FILE_EXT)
545}
546547fn extract_timestamp_from_session_dir(directory_name: &str) -> Result<SystemTime, &'static str> {
548if !is_session_directory(directory_name) {
549return Err("not a directory");
550 }
551552let dash_indices: Vec<_> = directory_name.match_indices('-').map(|(idx, _)| idx).collect();
553if dash_indices.len() != 3 {
554return Err("not three dashes in name");
555 }
556557string_to_timestamp(&directory_name[dash_indices[0] + 1..dash_indices[1]])
558}
559560fn timestamp_to_string(timestamp: SystemTime) -> BaseNString {
561let duration = timestamp.duration_since(UNIX_EPOCH).unwrap();
562let micros: u64 = duration.as_micros().try_into().unwrap();
563micros.to_base_fixed_len(CASE_INSENSITIVE)
564}
565566fn string_to_timestamp(s: &str) -> Result<SystemTime, &'static str> {
567let micros_since_unix_epoch = match u64::from_str_radix(s, INT_ENCODE_BASEas u32) {
568Ok(micros) => micros,
569Err(_) => return Err("timestamp not an int"),
570 };
571572let duration = Duration::from_micros(micros_since_unix_epoch);
573Ok(UNIX_EPOCH + duration)
574}
575576fn crate_path(sess: &Session, crate_name: Symbol, stable_crate_id: StableCrateId) -> PathBuf {
577let incr_dir = sess.opts.incremental.as_ref().unwrap().clone();
578579let crate_name =
580::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}-{0}",
stable_crate_id.as_u64().to_base_fixed_len(CASE_INSENSITIVE),
crate_name))
})format!("{crate_name}-{}", stable_crate_id.as_u64().to_base_fixed_len(CASE_INSENSITIVE));
581incr_dir.join(crate_name)
582}
583584fn is_old_enough_to_be_collected(timestamp: SystemTime) -> bool {
585timestamp < SystemTime::now() - Duration::from_secs(10)
586}
587588/// Runs garbage collection for the current session.
589pub(crate) fn garbage_collect_session_directories(
590 sess: &Session,
591 session_directory: &Path,
592) -> io::Result<()> {
593{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:593",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(593u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("garbage_collect_session_directories() - begin")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("garbage_collect_session_directories() - begin");
594595{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:595",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(595u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("garbage_collect_session_directories() - session directory: {0}",
session_directory.display()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
596"garbage_collect_session_directories() - session directory: {}",
597 session_directory.display()
598 );
599600let crate_directory = session_directory.parent().unwrap();
601{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:601",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(601u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("garbage_collect_session_directories() - crate directory: {0}",
crate_directory.display()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
602"garbage_collect_session_directories() - crate directory: {}",
603 crate_directory.display()
604 );
605606// First do a pass over the crate directory, collecting lock files and
607 // session directories
608let mut session_directories = FxIndexSet::default();
609let mut lock_files = UnordSet::default();
610611for dir_entry in crate_directory.read_dir()? {
612let Ok(dir_entry) = dir_entry else {
613// Ignore any errors
614continue;
615 };
616617let entry_name = dir_entry.file_name();
618let Some(entry_name) = entry_name.to_str() else {
619continue;
620 };
621622if is_session_directory_lock_file(&entry_name) {
623 lock_files.insert(entry_name.to_string());
624 } else if is_session_directory(&entry_name) {
625 session_directories.insert(entry_name.to_string());
626 } else {
627// This is something we don't know, leave it alone
628}
629 }
630session_directories.sort();
631632// Now map from lock files to session directories
633let lock_file_to_session_dir: UnordMap<String, Option<String>> = lock_files634 .into_items()
635 .map(|lock_file_name| {
636if !lock_file_name.ends_with(LOCK_FILE_EXT) {
::core::panicking::panic("assertion failed: lock_file_name.ends_with(LOCK_FILE_EXT)")
};assert!(lock_file_name.ends_with(LOCK_FILE_EXT));
637let dir_prefix_end = lock_file_name.len() - LOCK_FILE_EXT.len();
638let session_dir = {
639let dir_prefix = &lock_file_name[0..dir_prefix_end];
640session_directories.iter().find(|dir_name| dir_name.starts_with(dir_prefix))
641 };
642 (lock_file_name, session_dir.map(String::clone))
643 })
644 .into();
645646// Delete all lock files, that don't have an associated directory. They must
647 // be some kind of leftover
648for (lock_file_name, directory_name) in
649lock_file_to_session_dir.items().into_sorted_stable_ord()
650 {
651if directory_name.is_none() {
652let Ok(timestamp) = extract_timestamp_from_session_dir(lock_file_name) else {
653{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:653",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(653u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("found lock-file with malformed timestamp: {0}",
crate_directory.join(&lock_file_name).display()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
654"found lock-file with malformed timestamp: {}",
655 crate_directory.join(&lock_file_name).display()
656 );
657// Ignore it
658continue;
659 };
660661let lock_file_path = crate_directory.join(&*lock_file_name);
662663if is_old_enough_to_be_collected(timestamp) {
664{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:664",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(664u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("garbage_collect_session_directories() - deleting garbage lock file: {0}",
lock_file_path.display()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
665"garbage_collect_session_directories() - deleting \
666 garbage lock file: {}",
667 lock_file_path.display()
668 );
669 delete_session_dir_lock_file(sess, &lock_file_path);
670 } else {
671{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:671",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(671u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("garbage_collect_session_directories() - lock file with no session dir not old enough to be collected: {0}",
lock_file_path.display()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
672"garbage_collect_session_directories() - lock file with \
673 no session dir not old enough to be collected: {}",
674 lock_file_path.display()
675 );
676 }
677 }
678 }
679680// Filter out `None` directories
681let lock_file_to_session_dir: UnordMap<String, String> = lock_file_to_session_dir682 .into_items()
683 .filter_map(|(lock_file_name, directory_name)| directory_name.map(|n| (lock_file_name, n)))
684 .into();
685686// Delete all session directories that don't have a lock file.
687for directory_name in session_directories {
688if !lock_file_to_session_dir.items().any(|(_, dir)| *dir == directory_name) {
689let path = crate_directory.join(directory_name);
690if let Err(err) = std_fs::remove_dir_all(&path) {
691 sess.dcx().emit_warn(diagnostics::InvalidGcFailed { path: &path, err });
692 }
693 }
694 }
695696let current_session_directory_name =
697session_directory.file_name().expect("session directory is not `..`");
698699// Now garbage collect the valid session directories.
700let deletion_candidates =
701lock_file_to_session_dir.items().filter_map(|(lock_file_name, directory_name)| {
702{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:702",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(702u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("garbage_collect_session_directories() - inspecting: {0}",
directory_name) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("garbage_collect_session_directories() - inspecting: {}", directory_name);
703704let Ok(timestamp) = extract_timestamp_from_session_dir(directory_name) else {
705{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:705",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(705u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("found session-dir with malformed timestamp: {0}",
crate_directory.join(directory_name).display()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
706"found session-dir with malformed timestamp: {}",
707 crate_directory.join(directory_name).display()
708 );
709// Ignore it
710return None;
711 };
712713if is_finalized(directory_name) {
714let lock_file_path = crate_directory.join(lock_file_name);
715match flock::Lock::new(
716&lock_file_path,
717false, // don't wait
718false, // don't create the lock-file
719true,
720 ) {
721// get an exclusive lock
722Ok(lock) => {
723{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:723",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(723u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("garbage_collect_session_directories() - successfully acquired lock")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
724"garbage_collect_session_directories() - \
725 successfully acquired lock"
726);
727{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:727",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(727u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("garbage_collect_session_directories() - adding deletion candidate: {0}",
directory_name) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
728"garbage_collect_session_directories() - adding \
729 deletion candidate: {}",
730 directory_name
731 );
732733// Note that we are holding on to the lock
734return Some((
735 (timestamp, crate_directory.join(directory_name)),
736Some(lock),
737 ));
738 }
739Err(_) => {
740{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:740",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(740u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("garbage_collect_session_directories() - not collecting, still in use")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
741"garbage_collect_session_directories() - \
742 not collecting, still in use"
743);
744 }
745 }
746 } else if is_old_enough_to_be_collected(timestamp) {
747if directory_name.as_str() == current_session_directory_name {
748// Skipping our own active directory is important for correctness.
749 //
750 // To summarize #147821: we will try to lock directories before deciding they can be
751 // garbage collected, but the ability of `flock::Lock` to detect a lock held *by the
752 // same process* varies across file locking APIs. Then, if our own session directory
753 // has become old enough to be eligible for GC, we are beholden to platform-specific
754 // details about detecting the our own lock on the session directory.
755 //
756 // POSIX `fcntl(F_SETLK)`-style file locks are maintained across a process. On
757 // systems where this is the mechanism for `flock::Lock`, there is no way to
758 // discover if an `flock::Lock` has been created in the same process on the same
759 // file. Attempting to set a lock on the lockfile again will succeed, even if the
760 // lock was set by another thread, on another file descriptor. Then we would
761 // garbage collect our own live directory, unable to tell it was locked perhaps by
762 // this same thread.
763 //
764 // It's not clear that `flock::Lock` can be fixed for this in general, and our own
765 // incremental session directory is the only one which this process may own, so skip
766 // it here and avoid the problem. We know it's not garbage anyway: we're using it.
767 // Once finalized, its lock is released. Include it in collection so we keep
768 // the newest completed session.
769return None;
770 }
771772// When cleaning out "-working" session directories, i.e.
773 // session directories that might still be in use by another
774 // compiler instance, we only look a directories that are
775 // at least ten seconds old. This is supposed to reduce the
776 // chance of deleting a directory in the time window where
777 // the process has allocated the directory but has not yet
778 // acquired the file-lock on it.
779780 // Try to acquire the directory lock. If we can't, it
781 // means that the owning process is still alive and we
782 // leave this directory alone.
783let lock_file_path = crate_directory.join(lock_file_name);
784match flock::Lock::new(
785&lock_file_path,
786false, // don't wait
787false, // don't create the lock-file
788true,
789 ) {
790// get an exclusive lock
791Ok(lock) => {
792{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:792",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(792u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("garbage_collect_session_directories() - successfully acquired lock")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
793"garbage_collect_session_directories() - \
794 successfully acquired lock"
795);
796797delete_old(sess, &crate_directory.join(directory_name));
798799// Let's make it explicit that the file lock is released at this point,
800 // or rather, that we held on to it until here
801drop(lock);
802 }
803Err(_) => {
804{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:804",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(804u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("garbage_collect_session_directories() - not collecting, still in use")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
805"garbage_collect_session_directories() - \
806 not collecting, still in use"
807);
808 }
809 }
810 } else {
811{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:811",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(811u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("garbage_collect_session_directories() - not finalized, not old enough")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
812"garbage_collect_session_directories() - not finalized, not \
813 old enough"
814);
815 }
816None817 });
818let deletion_candidates = deletion_candidates.into();
819820// Delete all but the most recent of the candidates
821all_except_most_recent(deletion_candidates).into_items().all(|(path, lock)| {
822if path.file_name() == Some(current_session_directory_name) {
823return true;
824 }
825826{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:826",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(826u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("garbage_collect_session_directories() - deleting `{0}`",
path.display()) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("garbage_collect_session_directories() - deleting `{}`", path.display());
827828if let Err(err) = std_fs::remove_dir_all(&path) {
829sess.dcx().emit_warn(diagnostics::FinalizedGcFailed { path: &path, err });
830 } else {
831delete_session_dir_lock_file(sess, &lock_file_path(&path));
832 }
833834// Let's make it explicit that the file lock is released at this point,
835 // or rather, that we held on to it until here
836drop(lock);
837true
838});
839840Ok(())
841}
842843fn delete_old(sess: &Session, path: &Path) {
844{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs:844",
"rustc_incremental::persist::fs", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_incremental/src/persist/fs.rs"),
::tracing_core::__macro_support::Option::Some(844u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::fs"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("garbage_collect_session_directories() - deleting `{0}`",
path.display()) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("garbage_collect_session_directories() - deleting `{}`", path.display());
845846if let Err(err) = std_fs::remove_dir_all(path) {
847sess.dcx().emit_warn(diagnostics::SessionGcFailed { path, err });
848 } else {
849delete_session_dir_lock_file(sess, &lock_file_path(path));
850 }
851}
852853fn all_except_most_recent(
854 deletion_candidates: UnordMap<(SystemTime, PathBuf), Option<flock::Lock>>,
855) -> UnordMap<PathBuf, Option<flock::Lock>> {
856let most_recent = deletion_candidates.items().map(|(&(timestamp, _), _)| timestamp).max();
857858if let Some(most_recent) = most_recent {
859deletion_candidates860 .into_items()
861 .filter(|&((timestamp, _), _)| timestamp != most_recent)
862 .map(|((_, path), lock)| (path, lock))
863 .collect()
864 } else {
865UnordMap::default()
866 }
867}
868869fn safe_remove_file(p: &Path) -> io::Result<()> {
870match std_fs::remove_file(p) {
871Err(err) if err.kind() == io::ErrorKind::NotFound => Ok(()),
872 result => result,
873 }
874}
875876// On Windows the compiler would sometimes fail to rename the session directory because
877// the OS thought something was still being accessed in it. So we retry a few times to give
878// the OS time to catch up.
879// See https://github.com/rust-lang/rust/issues/86929.
880fn rename_path_with_retry(from: &Path, to: &Path, mut retries_left: usize) -> std::io::Result<()> {
881loop {
882match std_fs::rename(from, to) {
883Ok(()) => return Ok(()),
884Err(e) => {
885if retries_left > 0 && e.kind() == ErrorKind::PermissionDenied {
886// Try again after a short waiting period.
887std::thread::sleep(Duration::from_millis(50));
888retries_left -= 1;
889 } else {
890return Err(e);
891 }
892 }
893 }
894 }
895}