Skip to main content

rustc_incremental/persist/
work_product.rs

1//! Function for saving intermediate [work products].
2//!
3//! [work products]: WorkProduct
4
5use std::path::Path;
6
7use rustc_data_structures::unord::UnordMap;
8use rustc_fs_util::link_or_copy;
9use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
10use rustc_session::{IncrCompSession, Session};
11use tracing::debug;
12
13use crate::diagnostics;
14use crate::persist::fs::*;
15
16/// Copies a CGU work product to the incremental compilation directory, so next compilation can
17/// find and reuse it.
18///
19/// Panics when incr comp is disabled.
20pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
21    sess: &Session,
22    incr_comp_session: &IncrCompSession,
23    cgu_name: &str,
24    files: &[(&'static str, &Path)],
25) -> (WorkProductId, WorkProduct) {
26    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/5ceaf6608eb354c2f5bbb3b8d974caa367dac81c/compiler/rustc_incremental/src/persist/work_product.rs:26",
                        "rustc_incremental::persist::work_product",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/5ceaf6608eb354c2f5bbb3b8d974caa367dac81c/compiler/rustc_incremental/src/persist/work_product.rs"),
                        ::tracing_core::__macro_support::Option::Some(26u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::work_product"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("cgu_name")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("cgu_name");
                                            NAME.as_str()
                                        },
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("files")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("files");
                                            NAME.as_str()
                                        }], ::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(&::tracing::field::debug(&cgu_name)
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&files)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?cgu_name, ?files);
27    if !sess.opts.incremental.is_some() {
    ::core::panicking::panic("assertion failed: sess.opts.incremental.is_some()")
};assert!(sess.opts.incremental.is_some());
28
29    let mut saved_files = UnordMap::default();
30    for (ext, path) in files {
31        let file_name = ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0}.{1}", cgu_name, ext))
    })format!("{cgu_name}.{ext}");
32        let path_in_incr_dir = in_incr_comp_dir_sess(incr_comp_session, &file_name);
33        match link_or_copy(path, &path_in_incr_dir) {
34            Ok(_) => {
35                let _ = saved_files.insert(ext.to_string(), file_name);
36            }
37            Err(err) => {
38                sess.dcx().emit_warn(diagnostics::CopyWorkProductToCache {
39                    from: path,
40                    to: &path_in_incr_dir,
41                    err,
42                });
43            }
44        }
45    }
46
47    let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_files };
48    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/5ceaf6608eb354c2f5bbb3b8d974caa367dac81c/compiler/rustc_incremental/src/persist/work_product.rs:48",
                        "rustc_incremental::persist::work_product",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/5ceaf6608eb354c2f5bbb3b8d974caa367dac81c/compiler/rustc_incremental/src/persist/work_product.rs"),
                        ::tracing_core::__macro_support::Option::Some(48u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_incremental::persist::work_product"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("work_product")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("work_product");
                                            NAME.as_str()
                                        }], ::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(&::tracing::field::debug(&work_product)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?work_product);
49    let work_product_id = WorkProductId::from_cgu_name(cgu_name);
50    (work_product_id, work_product)
51}