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