mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-19 18:34:08 +00:00
codegen_llvm/llvm_type: avoid matching on the Rust type
This commit is contained in:
parent
b60f7b51a2
commit
0fde82fb97
@ -3,7 +3,7 @@ use crate::context::TypeLowering;
|
|||||||
use crate::type_::Type;
|
use crate::type_::Type;
|
||||||
use rustc_codegen_ssa::traits::*;
|
use rustc_codegen_ssa::traits::*;
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
|
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
|
||||||
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
|
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
|
||||||
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
|
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
|
||||||
use rustc_target::abi::HasDataLayout;
|
use rustc_target::abi::HasDataLayout;
|
||||||
@ -215,20 +215,16 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
|
|||||||
/// of that field's type - this is useful for taking the address of
|
/// of that field's type - this is useful for taking the address of
|
||||||
/// that field and ensuring the struct has the right alignment.
|
/// that field and ensuring the struct has the right alignment.
|
||||||
fn llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type {
|
fn llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type {
|
||||||
|
// This must produce the same result for `repr(transparent)` wrappers as for the inner type!
|
||||||
|
// In other words, this should generally not look at the type at all, but only at the
|
||||||
|
// layout.
|
||||||
if let Abi::Scalar(scalar) = self.abi {
|
if let Abi::Scalar(scalar) = self.abi {
|
||||||
// Use a different cache for scalars because pointers to DSTs
|
// Use a different cache for scalars because pointers to DSTs
|
||||||
// can be either fat or thin (data pointers of fat pointers).
|
// can be either fat or thin (data pointers of fat pointers).
|
||||||
if let Some(&llty) = cx.scalar_lltypes.borrow().get(&self.ty) {
|
if let Some(&llty) = cx.scalar_lltypes.borrow().get(&self.ty) {
|
||||||
return llty;
|
return llty;
|
||||||
}
|
}
|
||||||
let llty = match *self.ty.kind() {
|
let llty = self.scalar_llvm_type_at(cx, scalar);
|
||||||
ty::Ref(..) | ty::RawPtr(_) => cx.type_ptr(),
|
|
||||||
ty::Adt(def, _) if def.is_box() => cx.type_ptr(),
|
|
||||||
ty::FnPtr(sig) => {
|
|
||||||
cx.fn_ptr_backend_type(cx.fn_abi_of_fn_ptr(sig, ty::List::empty()))
|
|
||||||
}
|
|
||||||
_ => self.scalar_llvm_type_at(cx, scalar),
|
|
||||||
};
|
|
||||||
cx.scalar_lltypes.borrow_mut().insert(self.ty, llty);
|
cx.scalar_lltypes.borrow_mut().insert(self.ty, llty);
|
||||||
return llty;
|
return llty;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user