rustc_incremental/persist/
work_product.rs1use std::fs as std_fs;
6use std::path::{Path, PathBuf};
7
8use rustc_data_structures::unord::UnordMap;
9use rustc_fs_util::link_or_copy;
10use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
11use rustc_session::Session;
12use tracing::debug;
13
14use crate::diagnostics;
15use crate::persist::fs::*;
16
17pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
22 sess: &Session,
23 cgu_name: &str,
24 files: &[(&'static str, &Path)],
25 known_links: &[PathBuf],
26) -> (WorkProductId, WorkProduct) {
27 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_incremental/src/persist/work_product.rs:27",
"rustc_incremental::persist::work_product",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_incremental/src/persist/work_product.rs"),
::tracing_core::__macro_support::Option::Some(27u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::work_product"),
::tracing_core::field::FieldSet::new(&["cgu_name", "files"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&cgu_name)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&files) as
&dyn Value))])
});
} else { ; }
};debug!(?cgu_name, ?files);
28 if !sess.opts.incremental.is_some() {
::core::panicking::panic("assertion failed: sess.opts.incremental.is_some()")
};assert!(sess.opts.incremental.is_some());
29
30 let mut saved_files = UnordMap::default();
31 for (ext, path) in files {
32 let file_name = ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}.{1}", cgu_name, ext))
})format!("{cgu_name}.{ext}");
33 let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
34 if known_links.contains(&path_in_incr_dir) {
35 let _ = saved_files.insert(ext.to_string(), file_name);
36 continue;
37 }
38 match link_or_copy(path, &path_in_incr_dir) {
39 Ok(_) => {
40 let _ = saved_files.insert(ext.to_string(), file_name);
41 }
42 Err(err) => {
43 sess.dcx().emit_warn(diagnostics::CopyWorkProductToCache {
44 from: path,
45 to: &path_in_incr_dir,
46 err,
47 });
48 }
49 }
50 }
51
52 let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_files };
53 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_incremental/src/persist/work_product.rs:53",
"rustc_incremental::persist::work_product",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_incremental/src/persist/work_product.rs"),
::tracing_core::__macro_support::Option::Some(53u32),
::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::work_product"),
::tracing_core::field::FieldSet::new(&["work_product"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&work_product)
as &dyn Value))])
});
} else { ; }
};debug!(?work_product);
54 let work_product_id = WorkProductId::from_cgu_name(cgu_name);
55 (work_product_id, work_product)
56}
57
58pub(crate) fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
60 for (_, path) in work_product.saved_files.items().into_sorted_stable_ord() {
61 let path = in_incr_comp_dir_sess(sess, path);
62 if let Err(err) = std_fs::remove_file(&path) {
63 sess.dcx().emit_warn(diagnostics::DeleteWorkProduct { path: &path, err });
64 }
65 }
66}