Skip to main content

rustc_codegen_ssa/
assert_module_sources.rs

1//! This pass is only used for UNIT TESTS related to incremental
2//! compilation. It tests whether a particular `.o` file will be re-used
3//! from a previous compilation or whether it must be regenerated.
4//!
5//! The user adds annotations to the crate of the following form:
6//!
7//! ```
8//! # #![feature(rustc_attrs)]
9//! # #![allow(internal_features)]
10//! #![rustc_partition_reused(module="spike", cfg="rpass2")]
11//! #![rustc_partition_codegened(module="spike-x", cfg="rpass2")]
12//! ```
13//!
14//! The first indicates (in the cfg `rpass2`) that `spike.o` will be
15//! reused, the second that `spike-x.o` will be recreated. If these
16//! annotations are inaccurate, errors are reported.
17//!
18//! The reason that we use `cfg=...` and not `#[cfg_attr]` is so that
19//! the HIR doesn't change as a result of the annotations, which might
20//! perturb the reuse results.
21//!
22//! `#![rustc_expected_cgu_reuse(module="spike", cfg="rpass2", kind="post-lto")]`
23//! allows for doing a more fine-grained check to see if pre- or post-lto data
24//! was re-used.
25
26use std::borrow::Cow;
27use std::fmt;
28
29use rustc_attr_ir::{CguFields, CguKind, find_attr};
30use rustc_data_structures::unord::{UnordMap, UnordSet};
31use rustc_errors::{DiagArgValue, IntoDiagArg};
32use rustc_hir::def_id::LOCAL_CRATE;
33use rustc_middle::mono::CodegenUnitNameBuilder;
34use rustc_middle::ty::TyCtxt;
35use rustc_session::Session;
36use rustc_span::{Span, Symbol};
37use tracing::debug;
38
39use crate::diagnostics;
40
41#[allow(missing_docs)]
42pub fn assert_module_sources(tcx: TyCtxt<'_>, set_reuse: &dyn Fn(&mut CguReuseTracker)) {
43    tcx.dep_graph.with_ignore(|| {
44        if tcx.sess.opts.incremental.is_none() {
45            return;
46        }
47
48        let available_cgus = tcx
49            .collect_and_partition_mono_items(())
50            .codegen_units
51            .iter()
52            .map(|cgu| cgu.name())
53            .collect();
54
55        let mut ams = AssertModuleSource {
56            tcx,
57            available_cgus,
58            cgu_reuse_tracker: if tcx.sess.opts.unstable_opts.query_dep_graph {
59                CguReuseTracker::new()
60            } else {
61                CguReuseTracker::new_disabled()
62            },
63        };
64
65        ams.check_attrs(tcx.hir_attrs(rustc_hir::CRATE_HIR_ID));
66
67        set_reuse(&mut ams.cgu_reuse_tracker);
68
69        if tcx.sess.opts.unstable_opts.print_mono_items
70            && let Some(data) = &ams.cgu_reuse_tracker.data
71        {
72            data.actual_reuse.items().all(|(cgu, reuse)| {
73                { ::std::io::_print(format_args!("CGU_REUSE {0} {1}\n", cgu, reuse)); };println!("CGU_REUSE {cgu} {reuse}");
74                true
75            });
76        }
77
78        ams.cgu_reuse_tracker.check_expected_reuse(tcx.sess);
79    });
80}
81
82struct AssertModuleSource<'tcx> {
83    tcx: TyCtxt<'tcx>,
84    available_cgus: UnordSet<Symbol>,
85    cgu_reuse_tracker: CguReuseTracker,
86}
87
88impl<'tcx> AssertModuleSource<'tcx> {
89    fn check_attrs(&mut self, attrs: &[rustc_attr_ir::Attribute]) {
90        for &(span, cgu_fields) in {
    'done:
        {
        for i in attrs {
            #[allow(unused_imports)]
            use ::rustc_attr_ir::AttributeKind::*;
            let i: &::rustc_attr_ir::Attribute = i;
            match i {
                ::rustc_attr_ir::Attribute::Parsed(RustcCguTestAttr(e)) => {
                    break 'done Some(e);
                }
                ::rustc_attr_ir::Attribute::Unparsed(..) =>
                    {}
                    #[deny(unreachable_patterns)]
                    _ => {}
            }
        }
        None
    }
}find_attr!(attrs,
91            RustcCguTestAttr(e) => e)
92        .into_flat_iter()
93        {
94            let (expected_reuse, comp_kind) = match cgu_fields {
95                CguFields::PartitionReused { .. } => (CguReuse::PreLto, ComparisonKind::AtLeast),
96                CguFields::PartitionCodegened { .. } => (CguReuse::No, ComparisonKind::Exact),
97                CguFields::ExpectedCguReuse { kind, .. } => match kind {
98                    CguKind::No => (CguReuse::No, ComparisonKind::Exact),
99                    CguKind::PreDashLto => (CguReuse::PreLto, ComparisonKind::Exact),
100                    CguKind::PostDashLto => (CguReuse::PostLto, ComparisonKind::Exact),
101                    CguKind::Any => (CguReuse::PreLto, ComparisonKind::AtLeast),
102                },
103            };
104            let (CguFields::ExpectedCguReuse { cfg, module, .. }
105            | CguFields::PartitionCodegened { cfg, module }
106            | CguFields::PartitionReused { cfg, module }) = cgu_fields;
107
108            if !self.tcx.sess.opts.unstable_opts.query_dep_graph {
109                self.tcx.dcx().emit_fatal(diagnostics::MissingQueryDepGraph { span });
110            }
111
112            if !self.check_config(cfg) {
113                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/4ebd258257737d5b7635c116fa7d281627a7e937/compiler/rustc_codegen_ssa/src/assert_module_sources.rs:113",
                        "rustc_codegen_ssa::assert_module_sources",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/4ebd258257737d5b7635c116fa7d281627a7e937/compiler/rustc_codegen_ssa/src/assert_module_sources.rs"),
                        ::tracing_core::__macro_support::Option::Some(113u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::assert_module_sources"),
                        ::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!("check_attr: config does not match, ignoring attr")
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("check_attr: config does not match, ignoring attr");
114                return;
115            }
116
117            let user_path = module.as_str();
118            let crate_name = self.tcx.crate_name(LOCAL_CRATE);
119            let crate_name = crate_name.as_str();
120
121            if !user_path.starts_with(&crate_name) {
122                self.tcx.dcx().emit_fatal(diagnostics::MalformedCguName {
123                    span,
124                    user_path,
125                    crate_name,
126                });
127            }
128
129            // Split of the "special suffix" if there is one.
130            let (user_path, cgu_special_suffix) = if let Some(index) = user_path.rfind('.') {
131                (&user_path[..index], Some(&user_path[index + 1..]))
132            } else {
133                (&user_path[..], None)
134            };
135
136            let mut iter = user_path.split('-');
137
138            // Remove the crate name
139            {
    match (&iter.next().unwrap(), &crate_name) {
        (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!(iter.next().unwrap(), crate_name);
140
141            let cgu_path_components = iter.collect::<Vec<_>>();
142
143            let cgu_name_builder = &mut CodegenUnitNameBuilder::new(self.tcx);
144            let cgu_name = cgu_name_builder.build_cgu_name(
145                LOCAL_CRATE,
146                cgu_path_components,
147                cgu_special_suffix,
148            );
149
150            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/4ebd258257737d5b7635c116fa7d281627a7e937/compiler/rustc_codegen_ssa/src/assert_module_sources.rs:150",
                        "rustc_codegen_ssa::assert_module_sources",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/4ebd258257737d5b7635c116fa7d281627a7e937/compiler/rustc_codegen_ssa/src/assert_module_sources.rs"),
                        ::tracing_core::__macro_support::Option::Some(150u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::assert_module_sources"),
                        ::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!("mapping \'{0}\' to cgu name \'{1}\'",
                                                    user_path, cgu_name) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("mapping '{user_path}' to cgu name '{cgu_name}'");
151
152            if !self.available_cgus.contains(&cgu_name) {
153                let cgu_names: Vec<&str> =
154                    self.available_cgus.items().map(|cgu| cgu.as_str()).into_sorted_stable_ord();
155                self.tcx.dcx().emit_err(diagnostics::NoModuleNamed {
156                    span,
157                    user_path,
158                    cgu_name,
159                    cgu_names: cgu_names.join(", "),
160                });
161            }
162
163            self.cgu_reuse_tracker.set_expectation(
164                cgu_name,
165                user_path,
166                span,
167                expected_reuse,
168                comp_kind,
169            );
170        }
171    }
172
173    /// Scan for a `cfg="foo"` attribute and check whether we have a
174    /// cfg flag called `foo`.
175    fn check_config(&self, value: Symbol) -> bool {
176        let config = &self.tcx.sess.config;
177        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/4ebd258257737d5b7635c116fa7d281627a7e937/compiler/rustc_codegen_ssa/src/assert_module_sources.rs:177",
                        "rustc_codegen_ssa::assert_module_sources",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/4ebd258257737d5b7635c116fa7d281627a7e937/compiler/rustc_codegen_ssa/src/assert_module_sources.rs"),
                        ::tracing_core::__macro_support::Option::Some(177u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::assert_module_sources"),
                        ::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!("check_config(config={0:?}, value={1:?})",
                                                    config, value) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("check_config(config={:?}, value={:?})", config, value);
178        if config.iter().any(|&(name, _)| name == value) {
179            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/4ebd258257737d5b7635c116fa7d281627a7e937/compiler/rustc_codegen_ssa/src/assert_module_sources.rs:179",
                        "rustc_codegen_ssa::assert_module_sources",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/4ebd258257737d5b7635c116fa7d281627a7e937/compiler/rustc_codegen_ssa/src/assert_module_sources.rs"),
                        ::tracing_core::__macro_support::Option::Some(179u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::assert_module_sources"),
                        ::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!("check_config: matched")
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("check_config: matched");
180            return true;
181        }
182        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/4ebd258257737d5b7635c116fa7d281627a7e937/compiler/rustc_codegen_ssa/src/assert_module_sources.rs:182",
                        "rustc_codegen_ssa::assert_module_sources",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/4ebd258257737d5b7635c116fa7d281627a7e937/compiler/rustc_codegen_ssa/src/assert_module_sources.rs"),
                        ::tracing_core::__macro_support::Option::Some(182u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::assert_module_sources"),
                        ::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!("check_config: no match found")
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("check_config: no match found");
183        false
184    }
185}
186
187#[derive(#[automatically_derived]
impl ::core::marker::Copy for CguReuse { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for CguReuse { }
#[automatically_derived]
impl ::core::clone::Clone for CguReuse {
    #[inline]
    fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for CguReuse {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                CguReuse::No => "No",
                CguReuse::PreLto => "PreLto",
                CguReuse::PostLto => "PostLto",
            })
    }
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for CguReuse { }
#[automatically_derived]
impl ::core::cmp::PartialEq for CguReuse {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
            ::core::intrinsics::discriminant_value(other)
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::PartialOrd for CguReuse {
    #[inline]
    fn partial_cmp(&self, other: &Self)
        -> ::core::option::Option<::core::cmp::Ordering> {
        ::core::cmp::PartialOrd::partial_cmp(&::core::intrinsics::discriminant_value(self),
            &::core::intrinsics::discriminant_value(other))
    }
}PartialOrd)]
188pub enum CguReuse {
189    No,
190    PreLto,
191    PostLto,
192}
193
194impl fmt::Display for CguReuse {
195    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
196        match *self {
197            CguReuse::No => f.write_fmt(format_args!("No"))write!(f, "No"),
198            CguReuse::PreLto => f.write_fmt(format_args!("PreLto"))write!(f, "PreLto"),
199            CguReuse::PostLto => f.write_fmt(format_args!("PostLto"))write!(f, "PostLto"),
200        }
201    }
202}
203
204impl IntoDiagArg for CguReuse {
205    fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
206        DiagArgValue::Str(Cow::Owned(self.to_string()))
207    }
208}
209
210#[derive(#[automatically_derived]
impl ::core::marker::Copy for ComparisonKind { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ComparisonKind { }
#[automatically_derived]
impl ::core::clone::Clone for ComparisonKind {
    #[inline]
    fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for ComparisonKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                ComparisonKind::Exact => "Exact",
                ComparisonKind::AtLeast => "AtLeast",
            })
    }
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for ComparisonKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ComparisonKind {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
            ::core::intrinsics::discriminant_value(other)
    }
}PartialEq)]
211pub enum ComparisonKind {
212    Exact,
213    AtLeast,
214}
215
216struct TrackerData {
217    actual_reuse: UnordMap<String, CguReuse>,
218    expected_reuse: UnordMap<String, (String, Span, CguReuse, ComparisonKind)>,
219}
220
221pub struct CguReuseTracker {
222    data: Option<TrackerData>,
223}
224
225impl CguReuseTracker {
226    fn new() -> CguReuseTracker {
227        let data =
228            TrackerData { actual_reuse: Default::default(), expected_reuse: Default::default() };
229
230        CguReuseTracker { data: Some(data) }
231    }
232
233    fn new_disabled() -> CguReuseTracker {
234        CguReuseTracker { data: None }
235    }
236
237    pub fn set_actual_reuse(&mut self, cgu_name: &str, kind: CguReuse) {
238        if let Some(data) = &mut self.data {
239            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/4ebd258257737d5b7635c116fa7d281627a7e937/compiler/rustc_codegen_ssa/src/assert_module_sources.rs:239",
                        "rustc_codegen_ssa::assert_module_sources",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/4ebd258257737d5b7635c116fa7d281627a7e937/compiler/rustc_codegen_ssa/src/assert_module_sources.rs"),
                        ::tracing_core::__macro_support::Option::Some(239u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::assert_module_sources"),
                        ::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!("set_actual_reuse({0:?}, {1:?})",
                                                    cgu_name, kind) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("set_actual_reuse({cgu_name:?}, {kind:?})");
240
241            let prev_reuse = data.actual_reuse.insert(cgu_name.to_string(), kind);
242            if !prev_reuse.is_none() {
    ::core::panicking::panic("assertion failed: prev_reuse.is_none()")
};assert!(prev_reuse.is_none());
243        }
244    }
245
246    fn set_expectation(
247        &mut self,
248        cgu_name: Symbol,
249        cgu_user_name: &str,
250        error_span: Span,
251        expected_reuse: CguReuse,
252        comparison_kind: ComparisonKind,
253    ) {
254        if let Some(data) = &mut self.data {
255            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/4ebd258257737d5b7635c116fa7d281627a7e937/compiler/rustc_codegen_ssa/src/assert_module_sources.rs:255",
                        "rustc_codegen_ssa::assert_module_sources",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/4ebd258257737d5b7635c116fa7d281627a7e937/compiler/rustc_codegen_ssa/src/assert_module_sources.rs"),
                        ::tracing_core::__macro_support::Option::Some(255u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::assert_module_sources"),
                        ::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!("set_expectation({0:?}, {1:?}, {2:?})",
                                                    cgu_name, expected_reuse, comparison_kind) as
                                            &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("set_expectation({cgu_name:?}, {expected_reuse:?}, {comparison_kind:?})");
256
257            data.expected_reuse.insert(
258                cgu_name.to_string(),
259                (cgu_user_name.to_string(), error_span, expected_reuse, comparison_kind),
260            );
261        }
262    }
263
264    fn check_expected_reuse(&self, sess: &Session) {
265        if let Some(ref data) = self.data {
266            let keys = data.expected_reuse.keys().into_sorted_stable_ord();
267            for cgu_name in keys {
268                let &(ref cgu_user_name, ref error_span, expected_reuse, comparison_kind) =
269                    data.expected_reuse.get(cgu_name).unwrap();
270
271                if let Some(&actual_reuse) = data.actual_reuse.get(cgu_name) {
272                    let (error, at_least) = match comparison_kind {
273                        ComparisonKind::Exact => (expected_reuse != actual_reuse, false),
274                        ComparisonKind::AtLeast => (actual_reuse < expected_reuse, true),
275                    };
276
277                    if error {
278                        let at_least = if at_least { 1 } else { 0 };
279                        sess.dcx().emit_err(diagnostics::IncorrectCguReuseType {
280                            span: *error_span,
281                            cgu_user_name,
282                            actual_reuse,
283                            expected_reuse,
284                            at_least,
285                        });
286                    }
287                } else {
288                    sess.dcx().emit_fatal(diagnostics::CguNotRecorded { cgu_user_name, cgu_name });
289                }
290            }
291        }
292    }
293}