Skip to main content

rustc_codegen_llvm/
type_of.rs

1use std::fmt::Write;
2
3use rustc_abi::Primitive::{self, Bool, Float, Int, Pointer};
4use rustc_abi::{Align, BackendRepr, FieldsShape, Scalar, Size, Variants};
5use rustc_codegen_ssa::traits::*;
6use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
7use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
8use rustc_middle::ty::{self, CoroutineArgsExt, Ty, TypeVisitableExt};
9use rustc_span::{DUMMY_SP, Span, bug};
10use tracing::debug;
11
12use crate::common::*;
13use crate::llvm::Type;
14
15fn uncached_llvm_type<'ll, 'tcx>(
16    cx: &CodegenCx<'ll, 'tcx>,
17    layout: TyAndLayout<'tcx>,
18    defer: &mut Option<(Type<'ll>, TyAndLayout<'tcx>)>,
19) -> Type<'ll> {
20    match layout.backend_repr {
21        BackendRepr::Scalar(_) => ::rustc_span::macros::bug_impl(None, format_args!("handled elsewhere"),
    Location::caller())bug!("handled elsewhere"),
22        BackendRepr::SimdVector { element, count } => {
23            let element = layout.scalar_llvm_type_at(cx, element);
24            return cx.type_vector(element, count.as_u64());
25        }
26        BackendRepr::SimdScalableVector { ref element, count, number_of_vectors } => {
27            let element = if element.is_bool() {
28                cx.type_i1()
29            } else {
30                layout.scalar_llvm_type_at(cx, *element)
31            };
32
33            let vector_type = cx.type_scalable_vector(element, count.as_u64());
34            return match number_of_vectors.0 {
35                1 => vector_type,
36                2 => cx.type_struct(&[vector_type; 2]),
37                3 => cx.type_struct(&[vector_type; 3]),
38                4 => cx.type_struct(&[vector_type; 4]),
39                5 => cx.type_struct(&[vector_type; 5]),
40                6 => cx.type_struct(&[vector_type; 6]),
41                7 => cx.type_struct(&[vector_type; 7]),
42                8 => cx.type_struct(&[vector_type; 8]),
43                _ => ::rustc_span::macros::bug_impl(None,
    format_args!("`#[rustc_scalable_vector]` tuple struct with too many fields"),
    Location::caller())bug!("`#[rustc_scalable_vector]` tuple struct with too many fields"),
44            };
45        }
46        BackendRepr::Memory { .. } | BackendRepr::ScalarPair { .. } => {}
47    }
48
49    let name = match layout.ty.kind() {
50        // FIXME(eddyb) producing readable type names for trait objects can result
51        // in problematically distinct types due to HRTB and subtyping (see #47638).
52        // ty::Dynamic(..) |
53        ty::Adt(..) | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Foreign(..) | ty::Coroutine(..) | ty::Str
54            // For performance reasons we use names only when emitting LLVM IR.
55            if !cx.sess().fewer_names() =>
56        {
57            let mut name = {
    let _guard = NoVisibleGuard::new();
    { let _guard = NoTrimmedGuard::new(); layout.ty.to_string() }
}with_no_visible_paths!(with_no_trimmed_paths!(layout.ty.to_string()));
58            if let (&ty::Adt(def, _), &Variants::Single { index }) =
59                (layout.ty.kind(), &layout.variants)
60            {
61                if def.is_enum() {
62                    (&mut name).write_fmt(format_args!("::{0}", def.variant(index).name))write!(&mut name, "::{}", def.variant(index).name).unwrap();
63                }
64            }
65            if let (&ty::Coroutine(_, _), &Variants::Single { index }) =
66                (layout.ty.kind(), &layout.variants)
67            {
68                (&mut name).write_fmt(format_args!("::{0}",
        ty::CoroutineArgs::variant_name(index)))write!(&mut name, "::{}", ty::CoroutineArgs::variant_name(index)).unwrap();
69            }
70            Some(name)
71        }
72        _ => None,
73    };
74
75    match layout.fields {
76        FieldsShape::Primitive | FieldsShape::Union(_) => {
77            let fill = cx.type_padding_filler(layout.size, layout.align);
78            match name {
79                None => cx.type_struct(&[fill]),
80                Some(ref name) => cx.type_named_struct(name, &[fill]),
81            }
82        }
83        FieldsShape::Array { count, .. } => {
84            let element_ty = layout.field(cx, 0);
85            if let BackendRepr::Scalar(scalar) = element_ty.backend_repr
86                && scalar.primitive() == Primitive::Float(rustc_abi::Float::X87F80)
87            {
88                cx.type_padding_filler(element_ty.size * count, element_ty.align)
89            } else {
90                cx.type_array(element_ty.llvm_type(cx), count)
91            }
92        }
93        FieldsShape::Arbitrary { .. } => match name {
94            None => {
95                let (llfields, packed) = struct_llfields(cx, layout);
96                if packed { cx.type_packed_struct(&llfields) } else { cx.type_struct(&llfields) }
97            }
98            Some(ref name) => {
99                let llty = cx.type_named_struct_deferred(name);
100                *defer = Some((llty, layout));
101                llty
102            }
103        },
104    }
105}
106
107fn struct_llfields<'ll, 'tcx>(
108    cx: &CodegenCx<'ll, 'tcx>,
109    layout: TyAndLayout<'tcx>,
110) -> (Vec<Type<'ll>>, bool) {
111    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/5989b83b125120725b75332ca63d15fe93c912dd/compiler/rustc_codegen_llvm/src/type_of.rs:111",
                        "rustc_codegen_llvm::type_of", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/5989b83b125120725b75332ca63d15fe93c912dd/compiler/rustc_codegen_llvm/src/type_of.rs"),
                        ::tracing_core::__macro_support::Option::Some(111u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_codegen_llvm::type_of"),
                        ::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!("struct_llfields: {0:#?}",
                                                    layout) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("struct_llfields: {:#?}", layout);
112    let field_count = layout.fields.count();
113
114    let mut packed = false;
115    let mut offset = Size::ZERO;
116    let mut prev_effective_align = layout.align;
117    let mut result: Vec<_> = Vec::with_capacity(1 + field_count * 2);
118    for i in layout.fields.index_by_increasing_offset() {
119        let target_offset = layout.fields.offset(i);
120        let field = layout.field(cx, i);
121        let effective_field_align =
122            layout.align.min(field.align).restrict_for_offset(target_offset);
123        packed |= effective_field_align < field.align;
124
125        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/5989b83b125120725b75332ca63d15fe93c912dd/compiler/rustc_codegen_llvm/src/type_of.rs:125",
                        "rustc_codegen_llvm::type_of", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/5989b83b125120725b75332ca63d15fe93c912dd/compiler/rustc_codegen_llvm/src/type_of.rs"),
                        ::tracing_core::__macro_support::Option::Some(125u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_codegen_llvm::type_of"),
                        ::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!("struct_llfields: {0}: {1:?} offset: {2:?} target_offset: {3:?} effective_field_align: {4}",
                                                    i, field, offset, target_offset,
                                                    effective_field_align.bytes()) as
                                            &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(
126            "struct_llfields: {}: {:?} offset: {:?} target_offset: {:?} \
127                effective_field_align: {}",
128            i,
129            field,
130            offset,
131            target_offset,
132            effective_field_align.bytes()
133        );
134        if !(target_offset >= offset) {
    ::core::panicking::panic("assertion failed: target_offset >= offset")
};assert!(target_offset >= offset);
135        let padding = target_offset - offset;
136        if padding != Size::ZERO {
137            let padding_align = prev_effective_align.min(effective_field_align);
138            {
    match (&(offset.align_to(padding_align) + padding), &target_offset) {
        (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!(offset.align_to(padding_align) + padding, target_offset);
139            result.push(cx.type_padding_filler(padding, padding_align));
140            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/5989b83b125120725b75332ca63d15fe93c912dd/compiler/rustc_codegen_llvm/src/type_of.rs:140",
                        "rustc_codegen_llvm::type_of", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/5989b83b125120725b75332ca63d15fe93c912dd/compiler/rustc_codegen_llvm/src/type_of.rs"),
                        ::tracing_core::__macro_support::Option::Some(140u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_codegen_llvm::type_of"),
                        ::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!("    padding before: {0:?}",
                                                    padding) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("    padding before: {:?}", padding);
141        }
142
143        if let BackendRepr::Scalar(scalar) = field.backend_repr
144            && scalar.primitive() == Primitive::Float(rustc_abi::Float::X87F80)
145        {
146            result.push(cx.type_padding_filler(field.size, field.align));
147        } else {
148            result.push(field.llvm_type(cx));
149        }
150
151        offset = target_offset + field.size;
152        prev_effective_align = effective_field_align;
153    }
154    if layout.is_sized() && field_count > 0 {
155        if offset > layout.size {
156            ::rustc_span::macros::bug_impl(None,
    format_args!("layout: {0:#?} stride: {1:?} offset: {2:?}", layout,
        layout.size, offset), Location::caller());bug!("layout: {:#?} stride: {:?} offset: {:?}", layout, layout.size, offset);
157        }
158        let padding = layout.size - offset;
159        if padding != Size::ZERO {
160            let padding_align = prev_effective_align;
161            {
    match (&(offset.align_to(padding_align) + padding), &layout.size) {
        (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!(offset.align_to(padding_align) + padding, layout.size);
162            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/5989b83b125120725b75332ca63d15fe93c912dd/compiler/rustc_codegen_llvm/src/type_of.rs:162",
                        "rustc_codegen_llvm::type_of", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/5989b83b125120725b75332ca63d15fe93c912dd/compiler/rustc_codegen_llvm/src/type_of.rs"),
                        ::tracing_core::__macro_support::Option::Some(162u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_codegen_llvm::type_of"),
                        ::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!("struct_llfields: pad_bytes: {0:?} offset: {1:?} stride: {2:?}",
                                                    padding, offset, layout.size) as
                                            &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(
163                "struct_llfields: pad_bytes: {:?} offset: {:?} stride: {:?}",
164                padding, offset, layout.size
165            );
166            result.push(cx.type_padding_filler(padding, padding_align));
167        }
168    } else {
169        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/5989b83b125120725b75332ca63d15fe93c912dd/compiler/rustc_codegen_llvm/src/type_of.rs:169",
                        "rustc_codegen_llvm::type_of", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/5989b83b125120725b75332ca63d15fe93c912dd/compiler/rustc_codegen_llvm/src/type_of.rs"),
                        ::tracing_core::__macro_support::Option::Some(169u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_codegen_llvm::type_of"),
                        ::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!("struct_llfields: offset: {0:?} stride: {1:?}",
                                                    offset, layout.size) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("struct_llfields: offset: {:?} stride: {:?}", offset, layout.size);
170    }
171    (result, packed)
172}
173
174impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
175    pub(crate) fn align_of(&self, ty: Ty<'tcx>) -> Align {
176        self.layout_of(ty).align
177    }
178
179    pub(crate) fn size_of(&self, ty: Ty<'tcx>) -> Size {
180        self.layout_of(ty).size
181    }
182
183    pub(crate) fn size_and_align_of(&self, ty: Ty<'tcx>) -> (Size, Align) {
184        self.spanned_size_and_align_of(ty, DUMMY_SP)
185    }
186
187    pub(crate) fn spanned_size_and_align_of(&self, ty: Ty<'tcx>, span: Span) -> (Size, Align) {
188        let layout = self.spanned_layout_of(ty, span);
189        (layout.size, layout.align)
190    }
191}
192
193pub(crate) trait LayoutLlvmExt<'tcx> {
194    fn llvm_type<'ll>(&self, cx: &CodegenCx<'ll, 'tcx>) -> Type<'ll>;
195    fn immediate_llvm_type<'ll>(&self, cx: &CodegenCx<'ll, 'tcx>) -> Type<'ll>;
196    fn scalar_llvm_type_at<'ll>(&self, cx: &CodegenCx<'ll, 'tcx>, scalar: Scalar) -> Type<'ll>;
197    fn scalar_pair_element_llvm_type<'ll>(
198        &self,
199        cx: &CodegenCx<'ll, 'tcx>,
200        index: usize,
201        immediate: bool,
202    ) -> Type<'ll>;
203}
204
205impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
206    /// Gets the LLVM type corresponding to a Rust type, i.e., `rustc_middle::ty::Ty`.
207    ///
208    /// For sized types, this is the in-memory type that is used for stores and loads.
209    /// The type used for immediates may be different, see [`Self::immediate_llvm_type`].
210    ///
211    /// Unsized types, however, are represented by a "minimal unit", e.g.
212    /// `[T]` becomes `T`, while `str` and `Trait` turn into `i8` - this
213    /// is useful for indexing slices, as `&[T]`'s data pointer is `T*`.
214    ///
215    /// If the type is an unsized struct, the regular layout is generated,
216    /// with the innermost trailing unsized field using the "minimal unit"
217    /// of that field's type - this is useful for taking the address of
218    /// that field and ensuring the struct has the right alignment.
219    fn llvm_type<'ll>(&self, cx: &CodegenCx<'ll, 'tcx>) -> Type<'ll> {
220        // This must produce the same result for `repr(transparent)` wrappers as for the inner type!
221        // In other words, this should generally not look at the type at all, but only at the
222        // layout.
223        if let BackendRepr::Scalar(scalar) = self.backend_repr {
224            // Use a different cache for scalars because pointers to DSTs
225            // can be either wide or thin (data pointers of wide pointers).
226            if let Some(&llty) = cx.scalar_lltypes.borrow().get(&self.ty) {
227                return llty;
228            }
229            let llty = self.scalar_llvm_type_at(cx, scalar);
230            cx.scalar_lltypes.borrow_mut().insert(self.ty, llty);
231            return llty;
232        }
233
234        // Check the cache.
235        let variant_index = match self.variants {
236            Variants::Single { index } => Some(index),
237            _ => None,
238        };
239        if let Some(llty) = cx.type_lowering.borrow().get(&(self.ty, variant_index)).copied() {
240            return llty;
241        }
242
243        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/5989b83b125120725b75332ca63d15fe93c912dd/compiler/rustc_codegen_llvm/src/type_of.rs:243",
                        "rustc_codegen_llvm::type_of", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/5989b83b125120725b75332ca63d15fe93c912dd/compiler/rustc_codegen_llvm/src/type_of.rs"),
                        ::tracing_core::__macro_support::Option::Some(243u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_codegen_llvm::type_of"),
                        ::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!("llvm_type({0:#?})",
                                                    self) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("llvm_type({:#?})", self);
244
245        if !!self.ty.has_escaping_bound_vars() {
    {
        ::core::panicking::panic_fmt(format_args!("{0:?} has escaping bound vars",
                self.ty));
    }
};assert!(!self.ty.has_escaping_bound_vars(), "{:?} has escaping bound vars", self.ty);
246
247        // Make sure lifetimes are erased, to avoid generating distinct LLVM
248        // types for Rust types that only differ in the choice of lifetimes.
249        let normal_ty = cx.tcx.erase_and_anonymize_regions(self.ty);
250
251        let mut defer = None;
252        let llty = if self.ty != normal_ty {
253            let mut layout = cx.layout_of(normal_ty);
254            if let Some(v) = variant_index {
255                layout = layout.for_variant(cx, v);
256            }
257            layout.llvm_type(cx)
258        } else {
259            uncached_llvm_type(cx, *self, &mut defer)
260        };
261        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/5989b83b125120725b75332ca63d15fe93c912dd/compiler/rustc_codegen_llvm/src/type_of.rs:261",
                        "rustc_codegen_llvm::type_of", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/5989b83b125120725b75332ca63d15fe93c912dd/compiler/rustc_codegen_llvm/src/type_of.rs"),
                        ::tracing_core::__macro_support::Option::Some(261u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_codegen_llvm::type_of"),
                        ::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!("--> mapped {0:#?} to llty={1:?}",
                                                    self, llty) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("--> mapped {:#?} to llty={:?}", self, llty);
262
263        cx.type_lowering.borrow_mut().insert((self.ty, variant_index), llty);
264
265        if let Some((llty, layout)) = defer {
266            let (llfields, packed) = struct_llfields(cx, layout);
267            if packed {
268                cx.set_struct_body_packed(llty, &llfields)
269            } else {
270                cx.set_struct_body(llty, &llfields)
271            }
272        }
273        llty
274    }
275
276    fn immediate_llvm_type<'ll>(&self, cx: &CodegenCx<'ll, 'tcx>) -> Type<'ll> {
277        match self.backend_repr {
278            BackendRepr::Scalar(scalar) => {
279                if scalar.is_bool() {
280                    return cx.type_i1();
281                }
282            }
283            BackendRepr::ScalarPair { .. } => {
284                // An immediate pair always contains just the two elements, without any padding
285                // filler, as it should never be stored to memory.
286                return cx.type_struct(&[
287                    self.scalar_pair_element_llvm_type(cx, 0, true),
288                    self.scalar_pair_element_llvm_type(cx, 1, true),
289                ]);
290            }
291            _ => {}
292        };
293        self.llvm_type(cx)
294    }
295
296    fn scalar_llvm_type_at<'ll>(&self, cx: &CodegenCx<'ll, 'tcx>, scalar: Scalar) -> Type<'ll> {
297        match scalar.primitive() {
298            Bool => cx.type_i8(),
299            Int(i, _) => cx.type_from_integer(i),
300            Float(f) => cx.type_from_float(f),
301            Pointer(address_space) => cx.type_ptr_ext(address_space),
302        }
303    }
304
305    fn scalar_pair_element_llvm_type<'ll>(
306        &self,
307        cx: &CodegenCx<'ll, 'tcx>,
308        index: usize,
309        immediate: bool,
310    ) -> Type<'ll> {
311        // This must produce the same result for `repr(transparent)` wrappers as for the inner type!
312        // In other words, this should generally not look at the type at all, but only at the
313        // layout.
314        let BackendRepr::ScalarPair { a, b, b_offset: _ } = self.backend_repr else {
315            ::rustc_span::macros::bug_impl(None,
    format_args!("TyAndLayout::scalar_pair_element_llty({0:?}): not applicable",
        self), Location::caller());bug!("TyAndLayout::scalar_pair_element_llty({:?}): not applicable", self);
316        };
317        let scalar = [a, b][index];
318
319        // Make sure to return the same type `immediate_llvm_type` would when
320        // dealing with an immediate pair. This means that `(bool, bool)` is
321        // effectively represented as `{i8, i8}` in memory and two `i1`s as an
322        // immediate, just like `bool` is typically `i8` in memory and only `i1`
323        // when immediate. We need to load/store `bool` as `i8` to avoid
324        // crippling LLVM optimizations or triggering other LLVM bugs with `i1`.
325        if immediate && scalar.is_bool() {
326            return cx.type_i1();
327        }
328
329        self.scalar_llvm_type_at(cx, scalar)
330    }
331}