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_macros::{Decodable, Encodable};
10use rustc_middle::dep_graph::{IncrCompSession, WorkProduct, WorkProductId};
11use rustc_session::Session;
12use tracing::debug;
13
14use crate::diagnostics;
15use crate::persist::fs::*;
16
17/// Copies a CGU work product to the incremental compilation directory, so next compilation can
18/// find and reuse it.
19///
20/// Panics when incr comp is disabled.
21pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
22    sess: &Session,
23    incr_comp_session: &mut IncrCompSession,
24    cgu_name: &str,
25    files: &[(&'static str, &Path)],
26) {
27    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_incremental/src/persist/work_product.rs:27",
                        "rustc_incremental::persist::work_product",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/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(&[{
                                            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);
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(incr_comp_session, &file_name);
34        match link_or_copy(path, &path_in_incr_dir, false /* allow_overwrite */) {
35            Ok(_) => {
36                let _ = saved_files.insert(ext.to_string(), file_name);
37            }
38            Err(err) => {
39                sess.dcx().emit_warn(diagnostics::CopyWorkProductToCache {
40                    from: path,
41                    to: &path_in_incr_dir,
42                    err,
43                });
44            }
45        }
46    }
47
48    let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_files };
49    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_incremental/src/persist/work_product.rs:49",
                        "rustc_incremental::persist::work_product",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_incremental/src/persist/work_product.rs"),
                        ::tracing_core::__macro_support::Option::Some(49u32),
                        ::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);
50    let work_product_id = WorkProductId::from_cgu_name(cgu_name);
51    incr_comp_session.new_work_products.insert(work_product_id, work_product);
52}
53
54#[derive(#[automatically_derived]impl ::core::fmt::Debug for SerializedWorkProduct {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "SerializedWorkProduct id work_product", &self.id,
            &&self.work_product)
    }
}Debug, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for SerializedWorkProduct {
            fn encode(&self, __encoder: &mut __E) {
                let SerializedWorkProduct {
                        id: ref __binding_0, work_product: ref __binding_1 } =
                    *self;
                ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                    __encoder);
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for SerializedWorkProduct {
            fn decode(__decoder: &mut __D) -> Self {
                SerializedWorkProduct {
                    id: ::rustc_serialize::Decodable::decode(__decoder),
                    work_product: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable)]
55pub(crate) struct SerializedWorkProduct {
56    /// node that produced the work-product
57    pub id: WorkProductId,
58
59    /// work-product data itself
60    pub work_product: WorkProduct,
61}