Skip to content

Commit ba94a2a

Browse files
Rollup merge of #131202 - Urgau:wide-ptrs-compiler, r=jieyouxu
Use wide pointers consistenly across the compiler This PR replace every use of "fat pointer" for the more recent "wide pointer" terminology. Since some time T-lang as preferred the "wide pointer" terminology, as can be seen on [the last RFCs](https://github.com/search?q=repo%3Arust-lang%2Frfcs+%22wide+pointer%22&type=code), on some [lints](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#ambiguous-wide-pointer-comparisons), but also in [the reference](https://doc.rust-lang.org/stable/reference/expressions/operator-expr.html?highlight=wide%20pointer#pointer-to-pointer-cast). Currently we have a [mix of both](https://github.com/search?q=repo%3Arust-lang%2Frust+%22wide+pointer%22&type=code) (including in error messages), which isn't great, but with this PR no more. r? `@jieyouxu` (feel free to re-roll)
2 parents 2ceeeb1 + 018ba05 commit ba94a2a

File tree

41 files changed

+120
-120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+120
-120
lines changed

compiler/rustc_codegen_cranelift/example/std_example.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ fn main() {
168168

169169
foo(I64X2([0, 0]));
170170

171-
transmute_fat_pointer();
171+
transmute_wide_pointer();
172172

173173
rust_call_abi();
174174

@@ -192,7 +192,7 @@ type TwoPtrs = i64;
192192
#[cfg(target_pointer_width = "64")]
193193
type TwoPtrs = i128;
194194

195-
fn transmute_fat_pointer() -> TwoPtrs {
195+
fn transmute_wide_pointer() -> TwoPtrs {
196196
unsafe { transmute::<_, TwoPtrs>("true !") }
197197
}
198198

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -713,17 +713,17 @@ fn codegen_stmt<'tcx>(
713713
let from_ty = operand.layout().ty;
714714
let to_ty = fx.monomorphize(to_ty);
715715

716-
fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
716+
fn is_wide_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
717717
ty.builtin_deref(true)
718718
.is_some_and(|pointee_ty| has_ptr_meta(fx.tcx, pointee_ty))
719719
}
720720

721-
if is_fat_ptr(fx, from_ty) {
722-
if is_fat_ptr(fx, to_ty) {
723-
// fat-ptr -> fat-ptr
721+
if is_wide_ptr(fx, from_ty) {
722+
if is_wide_ptr(fx, to_ty) {
723+
// wide-ptr -> wide-ptr
724724
lval.write_cvalue(fx, operand.cast_pointer_to(dest_layout));
725725
} else {
726-
// fat-ptr -> thin-ptr
726+
// wide-ptr -> thin-ptr
727727
let (ptr, _extra) = operand.load_scalar_pair(fx);
728728
lval.write_cvalue(fx, CValue::by_val(ptr, dest_layout))
729729
}

compiler/rustc_codegen_cranelift/src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn clif_pair_type_from_ty<'tcx>(
101101
})
102102
}
103103

104-
/// Is a pointer to this type a fat ptr?
104+
/// Is a pointer to this type a wide ptr?
105105
pub(crate) fn has_ptr_meta<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
106106
if ty.is_sized(tcx, ParamEnv::reveal_all()) {
107107
return false;

compiler/rustc_codegen_cranelift/src/debuginfo/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl DebugContext {
139139

140140
pointer_type_id
141141
} else {
142-
// FIXME implement debuginfo for fat pointers
142+
// FIXME implement debuginfo for wide pointers
143143
self.placeholder_for_type(tcx, type_dbg, ptr_type)
144144
}
145145
}

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
478478
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
479479
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
480480
});
481-
require!(metadata.is_unit(), InvalidMonomorphization::CastFatPointer {
481+
require!(metadata.is_unit(), InvalidMonomorphization::CastWidePointer {
482482
span,
483483
name,
484484
ty: in_elem
@@ -493,7 +493,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
493493
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
494494
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
495495
});
496-
require!(metadata.is_unit(), InvalidMonomorphization::CastFatPointer {
496+
require!(metadata.is_unit(), InvalidMonomorphization::CastWidePointer {
497497
span,
498498
name,
499499
ty: out_elem

compiler/rustc_codegen_gcc/src/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
207207
// layout.
208208
if let Abi::Scalar(ref scalar) = self.abi {
209209
// Use a different cache for scalars because pointers to DSTs
210-
// can be either fat or thin (data pointers of fat pointers).
210+
// can be either wide or thin (data pointers of wide pointers).
211211
if let Some(&ty) = cx.scalar_types.borrow().get(&self.ty) {
212212
return ty;
213213
}

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_codegen_ssa::mir::place::{PlaceRef, PlaceValue};
77
use rustc_codegen_ssa::traits::*;
88
use rustc_middle::ty::Ty;
99
use rustc_middle::ty::layout::LayoutOf;
10-
pub(crate) use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};
10+
pub(crate) use rustc_middle::ty::layout::{WIDE_PTR_ADDR, WIDE_PTR_EXTRA};
1111
use rustc_middle::{bug, ty};
1212
use rustc_session::config;
1313
pub(crate) use rustc_target::abi::call::*;

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use super::utils::{
3434
};
3535
use crate::common::CodegenCx;
3636
use crate::debuginfo::metadata::type_map::build_type_with_children;
37-
use crate::debuginfo::utils::{FatPtrKind, fat_pointer_kind};
37+
use crate::debuginfo::utils::{WidePtrKind, wide_pointer_kind};
3838
use crate::llvm::debuginfo::{
3939
DIDescriptor, DIFile, DIFlags, DILexicalBlock, DIScope, DIType, DebugEmissionKind,
4040
DebugNameTableKind,
@@ -161,7 +161,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
161161
unique_type_id: UniqueTypeId<'tcx>,
162162
) -> DINodeCreationResult<'ll> {
163163
// The debuginfo generated by this function is only valid if `ptr_type` is really just
164-
// a (fat) pointer. Make sure it is not called for e.g. `Box<T, NonZSTAllocator>`.
164+
// a (wide) pointer. Make sure it is not called for e.g. `Box<T, NonZSTAllocator>`.
165165
assert_eq!(
166166
cx.size_and_align_of(ptr_type),
167167
cx.size_and_align_of(Ty::new_mut_ptr(cx.tcx, pointee_type))
@@ -174,7 +174,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
174174
let data_layout = &cx.tcx.data_layout;
175175
let ptr_type_debuginfo_name = compute_debuginfo_type_name(cx.tcx, ptr_type, true);
176176

177-
match fat_pointer_kind(cx, pointee_type) {
177+
match wide_pointer_kind(cx, pointee_type) {
178178
None => {
179179
// This is a thin pointer. Create a regular pointer type and give it the correct name.
180180
assert_eq!(
@@ -197,7 +197,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
197197

198198
DINodeCreationResult { di_node, already_stored_in_typemap: false }
199199
}
200-
Some(fat_pointer_kind) => {
200+
Some(wide_pointer_kind) => {
201201
type_map::build_type_with_children(
202202
cx,
203203
type_map::stub(
@@ -210,7 +210,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
210210
DIFlags::FlagZero,
211211
),
212212
|cx, owner| {
213-
// FIXME: If this fat pointer is a `Box` then we don't want to use its
213+
// FIXME: If this wide pointer is a `Box` then we don't want to use its
214214
// type layout and instead use the layout of the raw pointer inside
215215
// of it.
216216
// The proper way to handle this is to not treat Box as a pointer
@@ -227,16 +227,16 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
227227
};
228228

229229
let layout = cx.layout_of(layout_type);
230-
let addr_field = layout.field(cx, abi::FAT_PTR_ADDR);
231-
let extra_field = layout.field(cx, abi::FAT_PTR_EXTRA);
230+
let addr_field = layout.field(cx, abi::WIDE_PTR_ADDR);
231+
let extra_field = layout.field(cx, abi::WIDE_PTR_EXTRA);
232232

233-
let (addr_field_name, extra_field_name) = match fat_pointer_kind {
234-
FatPtrKind::Dyn => ("pointer", "vtable"),
235-
FatPtrKind::Slice => ("data_ptr", "length"),
233+
let (addr_field_name, extra_field_name) = match wide_pointer_kind {
234+
WidePtrKind::Dyn => ("pointer", "vtable"),
235+
WidePtrKind::Slice => ("data_ptr", "length"),
236236
};
237237

238-
assert_eq!(abi::FAT_PTR_ADDR, 0);
239-
assert_eq!(abi::FAT_PTR_EXTRA, 1);
238+
assert_eq!(abi::WIDE_PTR_ADDR, 0);
239+
assert_eq!(abi::WIDE_PTR_EXTRA, 1);
240240

241241
// The data pointer type is a regular, thin pointer, regardless of whether this
242242
// is a slice or a trait object.
@@ -258,7 +258,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
258258
owner,
259259
addr_field_name,
260260
(addr_field.size, addr_field.align.abi),
261-
layout.fields.offset(abi::FAT_PTR_ADDR),
261+
layout.fields.offset(abi::WIDE_PTR_ADDR),
262262
DIFlags::FlagZero,
263263
data_ptr_type_di_node,
264264
),
@@ -267,7 +267,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
267267
owner,
268268
extra_field_name,
269269
(extra_field.size, extra_field.align.abi),
270-
layout.fields.offset(abi::FAT_PTR_EXTRA),
270+
layout.fields.offset(abi::WIDE_PTR_EXTRA),
271271
DIFlags::FlagZero,
272272
type_di_node(cx, extra_field.ty),
273273
),
@@ -391,7 +391,7 @@ fn build_dyn_type_di_node<'ll, 'tcx>(
391391
///
392392
/// NOTE: We currently emit just emit the debuginfo for the element type here
393393
/// (i.e. `T` for slices and `u8` for `str`), so that we end up with
394-
/// `*const T` for the `data_ptr` field of the corresponding fat-pointer
394+
/// `*const T` for the `data_ptr` field of the corresponding wide-pointer
395395
/// debuginfo of `&[T]`.
396396
///
397397
/// It would be preferable and more accurate if we emitted a DIArray of T

compiler/rustc_codegen_llvm/src/debuginfo/utils.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,23 @@ pub(crate) fn get_namespace_for_item<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId
4949
}
5050

5151
#[derive(Debug, PartialEq, Eq)]
52-
pub(crate) enum FatPtrKind {
52+
pub(crate) enum WidePtrKind {
5353
Slice,
5454
Dyn,
5555
}
5656

5757
/// Determines if `pointee_ty` is slice-like or trait-object-like, i.e.
58-
/// if the second field of the fat pointer is a length or a vtable-pointer.
59-
/// If `pointee_ty` does not require a fat pointer (because it is Sized) then
58+
/// if the second field of the wide pointer is a length or a vtable-pointer.
59+
/// If `pointee_ty` does not require a wide pointer (because it is Sized) then
6060
/// the function returns `None`.
61-
pub(crate) fn fat_pointer_kind<'ll, 'tcx>(
61+
pub(crate) fn wide_pointer_kind<'ll, 'tcx>(
6262
cx: &CodegenCx<'ll, 'tcx>,
6363
pointee_ty: Ty<'tcx>,
64-
) -> Option<FatPtrKind> {
64+
) -> Option<WidePtrKind> {
6565
let pointee_tail_ty = cx.tcx.struct_tail_for_codegen(pointee_ty, cx.param_env());
6666
let layout = cx.layout_of(pointee_tail_ty);
6767
trace!(
68-
"fat_pointer_kind: {:?} has layout {:?} (is_unsized? {})",
68+
"wide_pointer_kind: {:?} has layout {:?} (is_unsized? {})",
6969
pointee_tail_ty,
7070
layout,
7171
layout.is_unsized()
@@ -76,8 +76,8 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>(
7676
}
7777

7878
match *pointee_tail_ty.kind() {
79-
ty::Str | ty::Slice(_) => Some(FatPtrKind::Slice),
80-
ty::Dynamic(..) => Some(FatPtrKind::Dyn),
79+
ty::Str | ty::Slice(_) => Some(WidePtrKind::Slice),
80+
ty::Dynamic(..) => Some(WidePtrKind::Dyn),
8181
ty::Foreign(_) => {
8282
// Assert that pointers to foreign types really are thin:
8383
assert_eq!(
@@ -90,7 +90,7 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>(
9090
// For all other pointee types we should already have returned None
9191
// at the beginning of the function.
9292
panic!(
93-
"fat_pointer_kind() - Encountered unexpected `pointee_tail_ty`: {pointee_tail_ty:?}"
93+
"wide_pointer_kind() - Encountered unexpected `pointee_tail_ty`: {pointee_tail_ty:?}"
9494
)
9595
}
9696
}

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,7 +2185,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
21852185
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
21862186
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
21872187
});
2188-
require!(metadata.is_unit(), InvalidMonomorphization::CastFatPointer {
2188+
require!(metadata.is_unit(), InvalidMonomorphization::CastWidePointer {
21892189
span,
21902190
name,
21912191
ty: in_elem
@@ -2200,7 +2200,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
22002200
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
22012201
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
22022202
});
2203-
require!(metadata.is_unit(), InvalidMonomorphization::CastFatPointer {
2203+
require!(metadata.is_unit(), InvalidMonomorphization::CastWidePointer {
22042204
span,
22052205
name,
22062206
ty: out_elem

0 commit comments

Comments
 (0)