Skip to content

Commit 0f9c09f

Browse files
committed
Remoe has_ptr_meta in favor of tcx.type_has_metadata()
1 parent 57767d6 commit 0f9c09f

File tree

5 files changed

+17
-25
lines changed

5 files changed

+17
-25
lines changed

src/base.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,10 @@ fn codegen_stmt<'tcx>(
729729
let to_ty = fx.monomorphize(to_ty);
730730

731731
fn is_wide_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
732-
ty.builtin_deref(true)
733-
.is_some_and(|pointee_ty| has_ptr_meta(fx.tcx, pointee_ty))
732+
ty.builtin_deref(true).is_some_and(|pointee_ty| {
733+
fx.tcx
734+
.type_has_metadata(pointee_ty, ty::TypingEnv::fully_monomorphized())
735+
})
734736
}
735737

736738
if is_wide_ptr(fx, from_ty) {

src/common.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn clif_type_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<types::Typ
7171
},
7272
ty::FnPtr(..) => pointer_ty(tcx),
7373
ty::RawPtr(pointee_ty, _) | ty::Ref(_, pointee_ty, _) => {
74-
if has_ptr_meta(tcx, *pointee_ty) {
74+
if tcx.type_has_metadata(*pointee_ty, ty::TypingEnv::fully_monomorphized()) {
7575
return None;
7676
} else {
7777
pointer_ty(tcx)
@@ -91,7 +91,7 @@ fn clif_pair_type_from_ty<'tcx>(
9191
(clif_type_from_ty(tcx, types[0])?, clif_type_from_ty(tcx, types[1])?)
9292
}
9393
ty::RawPtr(pointee_ty, _) | ty::Ref(_, pointee_ty, _) => {
94-
if has_ptr_meta(tcx, *pointee_ty) {
94+
if tcx.type_has_metadata(*pointee_ty, ty::TypingEnv::fully_monomorphized()) {
9595
(pointer_ty(tcx), pointer_ty(tcx))
9696
} else {
9797
return None;
@@ -101,20 +101,6 @@ fn clif_pair_type_from_ty<'tcx>(
101101
})
102102
}
103103

104-
/// Is a pointer to this type a wide ptr?
105-
pub(crate) fn has_ptr_meta<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
106-
if ty.is_sized(tcx, ty::TypingEnv::fully_monomorphized()) {
107-
return false;
108-
}
109-
110-
let tail = tcx.struct_tail_for_codegen(ty, ty::TypingEnv::fully_monomorphized());
111-
match tail.kind() {
112-
ty::Foreign(..) => false,
113-
ty::Str | ty::Slice(..) | ty::Dynamic(..) => true,
114-
_ => bug!("unexpected unsized tail: {:?}", tail),
115-
}
116-
}
117-
118104
pub(crate) fn codegen_icmp_imm(
119105
fx: &mut FunctionCx<'_, '_, '_>,
120106
intcc: IntCC,

src/debuginfo/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
66
use rustc_middle::ty::layout::LayoutOf;
77
use rustc_middle::ty::{self, Ty, TyCtxt};
88

9-
use crate::{DebugContext, FullyMonomorphizedLayoutCx, has_ptr_meta};
9+
use crate::{DebugContext, FullyMonomorphizedLayoutCx};
1010

1111
#[derive(Default)]
1212
pub(crate) struct TypeDebugContext<'tcx> {
@@ -129,7 +129,7 @@ impl DebugContext {
129129

130130
let name = type_names::compute_debuginfo_type_name(tcx, ptr_type, true);
131131

132-
if !has_ptr_meta(tcx, ptr_type) {
132+
if !tcx.type_has_metadata(ptr_type, ty::TypingEnv::fully_monomorphized()) {
133133
let pointer_type_id =
134134
self.dwarf.unit.add(self.dwarf.unit.root(), gimli::DW_TAG_pointer_type);
135135
let pointer_entry = self.dwarf.unit.get_mut(pointer_type_id);

src/num.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,12 @@ pub(crate) fn codegen_ptr_binop<'tcx>(
395395
in_lhs: CValue<'tcx>,
396396
in_rhs: CValue<'tcx>,
397397
) -> CValue<'tcx> {
398-
let is_thin_ptr =
399-
in_lhs.layout().ty.builtin_deref(true).map(|ty| !has_ptr_meta(fx.tcx, ty)).unwrap_or(true);
398+
let is_thin_ptr = in_lhs
399+
.layout()
400+
.ty
401+
.builtin_deref(true)
402+
.map(|ty| !fx.tcx.type_has_metadata(ty, ty::TypingEnv::fully_monomorphized()))
403+
.unwrap_or(true);
400404

401405
if is_thin_ptr {
402406
match bin_op {

src/value_and_place.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ impl<'tcx> CPlace<'tcx> {
746746
};
747747

748748
let (field_ptr, field_layout) = codegen_field(fx, base, extra, layout, field);
749-
if has_ptr_meta(fx.tcx, field_layout.ty) {
749+
if fx.tcx.type_has_metadata(field_layout.ty, ty::TypingEnv::fully_monomorphized()) {
750750
CPlace::for_ptr_with_extra(field_ptr, extra.unwrap(), field_layout)
751751
} else {
752752
CPlace::for_ptr(field_ptr, field_layout)
@@ -832,7 +832,7 @@ impl<'tcx> CPlace<'tcx> {
832832

833833
pub(crate) fn place_deref(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> CPlace<'tcx> {
834834
let inner_layout = fx.layout_of(self.layout().ty.builtin_deref(true).unwrap());
835-
if has_ptr_meta(fx.tcx, inner_layout.ty) {
835+
if fx.tcx.type_has_metadata(inner_layout.ty, ty::TypingEnv::fully_monomorphized()) {
836836
let (addr, extra) = self.to_cvalue(fx).load_scalar_pair(fx);
837837
CPlace::for_ptr_with_extra(Pointer::new(addr), extra, inner_layout)
838838
} else {
@@ -845,7 +845,7 @@ impl<'tcx> CPlace<'tcx> {
845845
fx: &mut FunctionCx<'_, '_, 'tcx>,
846846
layout: TyAndLayout<'tcx>,
847847
) -> CValue<'tcx> {
848-
if has_ptr_meta(fx.tcx, self.layout().ty) {
848+
if fx.tcx.type_has_metadata(self.layout().ty, ty::TypingEnv::fully_monomorphized()) {
849849
let (ptr, extra) = self.to_ptr_unsized();
850850
CValue::by_val_pair(ptr.get_addr(fx), extra, layout)
851851
} else {

0 commit comments

Comments
 (0)