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::{CguFields, CguKind};
32use rustc_hir::def_id::LOCAL_CRATE;
33use rustc_hir::{self as hir, find_attr};
34use rustc_middle::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 {
            #[allow(unused_imports)]
            use rustc_hir::attrs::AttributeKind::*;
            let i: &rustc_hir::Attribute = i;
            match i {
                rustc_hir::Attribute::Parsed(RustcCguTestAttr(e)) => {
                    break 'done Some(e);
                }
                rustc_hir::Attribute::Unparsed(..) =>
                    {}
                    #[deny(unreachable_patterns)]
                    _ => {}
            }
        }
        None
    }
}find_attr!(attrs,
92            RustcCguTestAttr(e) => e)
93        .into_flat_iter()
94        {
95            let (expected_reuse, comp_kind) = match cgu_fields {
96                CguFields::PartitionReused { .. } => (CguReuse::PreLto, ComparisonKind::AtLeast),
97                CguFields::PartitionCodegened { .. } => (CguReuse::No, ComparisonKind::Exact),
98                CguFields::ExpectedCguReuse { kind, .. } => match kind {
99                    CguKind::No => (CguReuse::No, ComparisonKind::Exact),
100                    CguKind::PreDashLto => (CguReuse::PreLto, ComparisonKind::Exact),
101                    CguKind::PostDashLto => (CguReuse::PostLto, ComparisonKind::Exact),
102                    CguKind::Any => (CguReuse::PreLto, ComparisonKind::AtLeast),
103                },
104            };
105            let (CguFields::ExpectedCguReuse { cfg, module, .. }
106            | CguFields::PartitionCodegened { cfg, module }
107            | CguFields::PartitionReused { cfg, module }) = cgu_fields;
108
109            if !self.tcx.sess.opts.unstable_opts.query_dep_graph {
110                self.tcx.dcx().emit_fatal(errors::MissingQueryDepGraph { span });
111            }
112
113            if !self.check_config(cfg) {
114                {
    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:114",
                        "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(114u32),
                        ::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");
115                return;
116            }
117
118            let user_path = module.as_str();
119            let crate_name = self.tcx.crate_name(LOCAL_CRATE);
120            let crate_name = crate_name.as_str();
121
122            if !user_path.starts_with(&crate_name) {
123                self.tcx.dcx().emit_fatal(errors::MalformedCguName { span, user_path, crate_name });
124            }
125
126            // Split of the "special suffix" if there is one.
127            let (user_path, cgu_special_suffix) = if let Some(index) = user_path.rfind('.') {
128                (&user_path[..index], Some(&user_path[index + 1..]))
129            } else {
130                (&user_path[..], None)
131            };
132
133            let mut iter = user_path.split('-');
134
135            // Remove the crate name
136            {
    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);
137
138            let cgu_path_components = iter.collect::<Vec<_>>();
139
140            let cgu_name_builder = &mut CodegenUnitNameBuilder::new(self.tcx);
141            let cgu_name = cgu_name_builder.build_cgu_name(
142                LOCAL_CRATE,
143                cgu_path_components,
144                cgu_special_suffix,
145            );
146
147            {
    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:147",
                        "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(147u32),
                        ::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}'");
148
149            if !self.available_cgus.contains(&cgu_name) {
150                let cgu_names: Vec<&str> =
151                    self.available_cgus.items().map(|cgu| cgu.as_str()).into_sorted_stable_ord();
152                self.tcx.dcx().emit_err(errors::NoModuleNamed {
153                    span,
154                    user_path,
155                    cgu_name,
156                    cgu_names: cgu_names.join(", "),
157                });
158            }
159
160            self.cgu_reuse_tracker.set_expectation(
161                cgu_name,
162                user_path,
163                span,
164                expected_reuse,
165                comp_kind,
166            );
167        }
168    }
169
170    /// Scan for a `cfg="foo"` attribute and check whether we have a
171    /// cfg flag called `foo`.
172    fn check_config(&self, value: Symbol) -> bool {
173        let config = &self.tcx.sess.config;
174        {
    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:174",
                        "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(174u32),
                        ::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);
175        if config.iter().any(|&(name, _)| name == value) {
176            {
    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:176",
                        "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(176u32),
                        ::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");
177            return true;
178        }
179        {
    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:179",
                        "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(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};
                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");
180        false
181    }
182}
183
184#[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)]
185pub enum CguReuse {
186    No,
187    PreLto,
188    PostLto,
189}
190
191impl fmt::Display for CguReuse {
192    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
193        match *self {
194            CguReuse::No => f.write_fmt(format_args!("No"))write!(f, "No"),
195            CguReuse::PreLto => f.write_fmt(format_args!("PreLto"))write!(f, "PreLto"),
196            CguReuse::PostLto => f.write_fmt(format_args!("PostLto"))write!(f, "PostLto"),
197        }
198    }
199}
200
201impl IntoDiagArg for CguReuse {
202    fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
203        DiagArgValue::Str(Cow::Owned(self.to_string()))
204    }
205}
206
207#[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)]
208pub enum ComparisonKind {
209    Exact,
210    AtLeast,
211}
212
213struct TrackerData {
214    actual_reuse: UnordMap<String, CguReuse>,
215    expected_reuse: UnordMap<String, (String, Span, CguReuse, ComparisonKind)>,
216}
217
218pub struct CguReuseTracker {
219    data: Option<TrackerData>,
220}
221
222impl CguReuseTracker {
223    fn new() -> CguReuseTracker {
224        let data =
225            TrackerData { actual_reuse: Default::default(), expected_reuse: Default::default() };
226
227        CguReuseTracker { data: Some(data) }
228    }
229
230    fn new_disabled() -> CguReuseTracker {
231        CguReuseTracker { data: None }
232    }
233
234    pub fn set_actual_reuse(&mut self, cgu_name: &str, kind: CguReuse) {
235        if let Some(data) = &mut self.data {
236            {
    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:236",
                        "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(236u32),
                        ::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:?})");
237
238            let prev_reuse = data.actual_reuse.insert(cgu_name.to_string(), kind);
239            if !prev_reuse.is_none() {
    ::core::panicking::panic("assertion failed: prev_reuse.is_none()")
};assert!(prev_reuse.is_none());
240        }
241    }
242
243    fn set_expectation(
244        &mut self,
245        cgu_name: Symbol,
246        cgu_user_name: &str,
247        error_span: Span,
248        expected_reuse: CguReuse,
249        comparison_kind: ComparisonKind,
250    ) {
251        if let Some(data) = &mut self.data {
252            {
    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:252",
                        "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(252u32),
                        ::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:?})");
253
254            data.expected_reuse.insert(
255                cgu_name.to_string(),
256                (cgu_user_name.to_string(), error_span, expected_reuse, comparison_kind),
257            );
258        }
259    }
260
261    fn check_expected_reuse(&self, sess: &Session) {
262        if let Some(ref data) = self.data {
263            let keys = data.expected_reuse.keys().into_sorted_stable_ord();
264            for cgu_name in keys {
265                let &(ref cgu_user_name, ref error_span, expected_reuse, comparison_kind) =
266                    data.expected_reuse.get(cgu_name).unwrap();
267
268                if let Some(&actual_reuse) = data.actual_reuse.get(cgu_name) {
269                    let (error, at_least) = match comparison_kind {
270                        ComparisonKind::Exact => (expected_reuse != actual_reuse, false),
271                        ComparisonKind::AtLeast => (actual_reuse < expected_reuse, true),
272                    };
273
274                    if error {
275                        let at_least = if at_least { 1 } else { 0 };
276                        sess.dcx().emit_err(errors::IncorrectCguReuseType {
277                            span: *error_span,
278                            cgu_user_name,
279                            actual_reuse,
280                            expected_reuse,
281                            at_least,
282                        });
283                    }
284                } else {
285                    sess.dcx().emit_fatal(errors::CguNotRecorded { cgu_user_name, cgu_name });
286                }
287            }
288        }
289    }
290}