Remoe has_ptr_meta in favor of tcx.type_has_metadata()
This commit is contained in:
parent
57767d6d99
commit
0f9c09fb3a
5 changed files with 17 additions and 25 deletions
|
|
@ -729,8 +729,10 @@ fn codegen_stmt<'tcx>(
|
|||
let to_ty = fx.monomorphize(to_ty);
|
||||
|
||||
fn is_wide_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
ty.builtin_deref(true)
|
||||
.is_some_and(|pointee_ty| has_ptr_meta(fx.tcx, pointee_ty))
|
||||
ty.builtin_deref(true).is_some_and(|pointee_ty| {
|
||||
fx.tcx
|
||||
.type_has_metadata(pointee_ty, ty::TypingEnv::fully_monomorphized())
|
||||
})
|
||||
}
|
||||
|
||||
if is_wide_ptr(fx, from_ty) {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ fn clif_type_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<types::Typ
|
|||
},
|
||||
ty::FnPtr(..) => pointer_ty(tcx),
|
||||
ty::RawPtr(pointee_ty, _) | ty::Ref(_, pointee_ty, _) => {
|
||||
if has_ptr_meta(tcx, *pointee_ty) {
|
||||
if tcx.type_has_metadata(*pointee_ty, ty::TypingEnv::fully_monomorphized()) {
|
||||
return None;
|
||||
} else {
|
||||
pointer_ty(tcx)
|
||||
|
|
@ -91,7 +91,7 @@ fn clif_pair_type_from_ty<'tcx>(
|
|||
(clif_type_from_ty(tcx, types[0])?, clif_type_from_ty(tcx, types[1])?)
|
||||
}
|
||||
ty::RawPtr(pointee_ty, _) | ty::Ref(_, pointee_ty, _) => {
|
||||
if has_ptr_meta(tcx, *pointee_ty) {
|
||||
if tcx.type_has_metadata(*pointee_ty, ty::TypingEnv::fully_monomorphized()) {
|
||||
(pointer_ty(tcx), pointer_ty(tcx))
|
||||
} else {
|
||||
return None;
|
||||
|
|
@ -101,20 +101,6 @@ fn clif_pair_type_from_ty<'tcx>(
|
|||
})
|
||||
}
|
||||
|
||||
/// Is a pointer to this type a wide ptr?
|
||||
pub(crate) fn has_ptr_meta<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
if ty.is_sized(tcx, ty::TypingEnv::fully_monomorphized()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let tail = tcx.struct_tail_for_codegen(ty, ty::TypingEnv::fully_monomorphized());
|
||||
match tail.kind() {
|
||||
ty::Foreign(..) => false,
|
||||
ty::Str | ty::Slice(..) | ty::Dynamic(..) => true,
|
||||
_ => bug!("unexpected unsized tail: {:?}", tail),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn codegen_icmp_imm(
|
||||
fx: &mut FunctionCx<'_, '_, '_>,
|
||||
intcc: IntCC,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
|
|||
use rustc_middle::ty::layout::LayoutOf;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
|
||||
use crate::{DebugContext, FullyMonomorphizedLayoutCx, has_ptr_meta};
|
||||
use crate::{DebugContext, FullyMonomorphizedLayoutCx};
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct TypeDebugContext<'tcx> {
|
||||
|
|
@ -129,7 +129,7 @@ impl DebugContext {
|
|||
|
||||
let name = type_names::compute_debuginfo_type_name(tcx, ptr_type, true);
|
||||
|
||||
if !has_ptr_meta(tcx, ptr_type) {
|
||||
if !tcx.type_has_metadata(ptr_type, ty::TypingEnv::fully_monomorphized()) {
|
||||
let pointer_type_id =
|
||||
self.dwarf.unit.add(self.dwarf.unit.root(), gimli::DW_TAG_pointer_type);
|
||||
let pointer_entry = self.dwarf.unit.get_mut(pointer_type_id);
|
||||
|
|
|
|||
|
|
@ -395,8 +395,12 @@ pub(crate) fn codegen_ptr_binop<'tcx>(
|
|||
in_lhs: CValue<'tcx>,
|
||||
in_rhs: CValue<'tcx>,
|
||||
) -> CValue<'tcx> {
|
||||
let is_thin_ptr =
|
||||
in_lhs.layout().ty.builtin_deref(true).map(|ty| !has_ptr_meta(fx.tcx, ty)).unwrap_or(true);
|
||||
let is_thin_ptr = in_lhs
|
||||
.layout()
|
||||
.ty
|
||||
.builtin_deref(true)
|
||||
.map(|ty| !fx.tcx.type_has_metadata(ty, ty::TypingEnv::fully_monomorphized()))
|
||||
.unwrap_or(true);
|
||||
|
||||
if is_thin_ptr {
|
||||
match bin_op {
|
||||
|
|
|
|||
|
|
@ -746,7 +746,7 @@ impl<'tcx> CPlace<'tcx> {
|
|||
};
|
||||
|
||||
let (field_ptr, field_layout) = codegen_field(fx, base, extra, layout, field);
|
||||
if has_ptr_meta(fx.tcx, field_layout.ty) {
|
||||
if fx.tcx.type_has_metadata(field_layout.ty, ty::TypingEnv::fully_monomorphized()) {
|
||||
CPlace::for_ptr_with_extra(field_ptr, extra.unwrap(), field_layout)
|
||||
} else {
|
||||
CPlace::for_ptr(field_ptr, field_layout)
|
||||
|
|
@ -832,7 +832,7 @@ impl<'tcx> CPlace<'tcx> {
|
|||
|
||||
pub(crate) fn place_deref(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> CPlace<'tcx> {
|
||||
let inner_layout = fx.layout_of(self.layout().ty.builtin_deref(true).unwrap());
|
||||
if has_ptr_meta(fx.tcx, inner_layout.ty) {
|
||||
if fx.tcx.type_has_metadata(inner_layout.ty, ty::TypingEnv::fully_monomorphized()) {
|
||||
let (addr, extra) = self.to_cvalue(fx).load_scalar_pair(fx);
|
||||
CPlace::for_ptr_with_extra(Pointer::new(addr), extra, inner_layout)
|
||||
} else {
|
||||
|
|
@ -845,7 +845,7 @@ impl<'tcx> CPlace<'tcx> {
|
|||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
) -> CValue<'tcx> {
|
||||
if has_ptr_meta(fx.tcx, self.layout().ty) {
|
||||
if fx.tcx.type_has_metadata(self.layout().ty, ty::TypingEnv::fully_monomorphized()) {
|
||||
let (ptr, extra) = self.to_ptr_unsized();
|
||||
CValue::by_val_pair(ptr.get_addr(fx), extra, layout)
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue