Skip to content

Commit 6a19a87

Browse files
committed
Auto merge of #124972 - matthiaskrgr:rollup-3fablim, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #124615 (coverage: Further simplify extraction of mapping info from MIR) - #124778 (Fix parse error message for meta items) - #124797 (Refactor float `Primitive`s to a separate `Float` type) - #124888 (Migrate `run-make/rustdoc-output-path` to rmake) - #124957 (Make `Ty::builtin_deref` just return a `Ty`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 66f8770 + 9a9ec90 commit 6a19a87

File tree

82 files changed

+467
-401
lines changed

Some content is hidden

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

82 files changed

+467
-401
lines changed

Diff for: compiler/rustc_abi/src/lib.rs

+38-12
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,41 @@ impl Integer {
926926
}
927927
}
928928

929+
/// Floating-point types.
930+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
931+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
932+
pub enum Float {
933+
F16,
934+
F32,
935+
F64,
936+
F128,
937+
}
938+
939+
impl Float {
940+
pub fn size(self) -> Size {
941+
use Float::*;
942+
943+
match self {
944+
F16 => Size::from_bits(16),
945+
F32 => Size::from_bits(32),
946+
F64 => Size::from_bits(64),
947+
F128 => Size::from_bits(128),
948+
}
949+
}
950+
951+
pub fn align<C: HasDataLayout>(self, cx: &C) -> AbiAndPrefAlign {
952+
use Float::*;
953+
let dl = cx.data_layout();
954+
955+
match self {
956+
F16 => dl.f16_align,
957+
F32 => dl.f32_align,
958+
F64 => dl.f64_align,
959+
F128 => dl.f128_align,
960+
}
961+
}
962+
}
963+
929964
/// Fundamental unit of memory access and layout.
930965
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
931966
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
@@ -938,10 +973,7 @@ pub enum Primitive {
938973
/// a negative integer passed by zero-extension will appear positive in
939974
/// the callee, and most operations on it will produce the wrong values.
940975
Int(Integer, bool),
941-
F16,
942-
F32,
943-
F64,
944-
F128,
976+
Float(Float),
945977
Pointer(AddressSpace),
946978
}
947979

@@ -952,10 +984,7 @@ impl Primitive {
952984

953985
match self {
954986
Int(i, _) => i.size(),
955-
F16 => Size::from_bits(16),
956-
F32 => Size::from_bits(32),
957-
F64 => Size::from_bits(64),
958-
F128 => Size::from_bits(128),
987+
Float(f) => f.size(),
959988
// FIXME(erikdesjardins): ignoring address space is technically wrong, pointers in
960989
// different address spaces can have different sizes
961990
// (but TargetDataLayout doesn't currently parse that part of the DL string)
@@ -969,10 +998,7 @@ impl Primitive {
969998

970999
match self {
9711000
Int(i, _) => i.align(dl),
972-
F16 => dl.f16_align,
973-
F32 => dl.f32_align,
974-
F64 => dl.f64_align,
975-
F128 => dl.f128_align,
1001+
Float(f) => f.align(dl),
9761002
// FIXME(erikdesjardins): ignoring address space is technically wrong, pointers in
9771003
// different address spaces can have different alignments
9781004
// (but TargetDataLayout doesn't currently parse that part of the DL string)

Diff for: compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1483,10 +1483,9 @@ fn suggest_ampmut<'tcx>(
14831483
} else {
14841484
// otherwise, suggest that the user annotates the binding; we provide the
14851485
// type of the local.
1486-
let ty_mut = decl_ty.builtin_deref(true).unwrap();
1487-
assert_eq!(ty_mut.mutbl, hir::Mutability::Not);
1486+
let ty = decl_ty.builtin_deref(true).unwrap();
14881487

1489-
(false, span, format!("{}mut {}", if decl_ty.is_ref() { "&" } else { "*" }, ty_mut.ty))
1488+
(false, span, format!("{}mut {}", if decl_ty.is_ref() { "&" } else { "*" }, ty))
14901489
}
14911490
}
14921491

Diff for: compiler/rustc_borrowck/src/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
400400
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
401401
let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity();
402402
let normalized_ty = self.cx.normalize(unnormalized_ty, locations);
403-
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap().ty;
403+
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap();
404404

405405
if let Err(terr) = self.cx.eq_types(
406406
literal_ty,
@@ -637,7 +637,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
637637
match pi {
638638
ProjectionElem::Deref => {
639639
let deref_ty = base_ty.builtin_deref(true);
640-
PlaceTy::from_ty(deref_ty.map(|t| t.ty).unwrap_or_else(|| {
640+
PlaceTy::from_ty(deref_ty.unwrap_or_else(|| {
641641
span_mirbug_and_err!(self, place, "deref of non-pointer {:?}", base_ty)
642642
}))
643643
}

Diff for: compiler/rustc_codegen_cranelift/src/base.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,8 @@ fn codegen_stmt<'tcx>(
670670
let to_ty = fx.monomorphize(to_ty);
671671

672672
fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
673-
ty.builtin_deref(true).is_some_and(
674-
|ty::TypeAndMut { ty: pointee_ty, mutbl: _ }| {
675-
has_ptr_meta(fx.tcx, pointee_ty)
676-
},
677-
)
673+
ty.builtin_deref(true)
674+
.is_some_and(|pointee_ty| has_ptr_meta(fx.tcx, pointee_ty))
678675
}
679676

680677
if is_fat_ptr(fx, from_ty) {

Diff for: compiler/rustc_codegen_cranelift/src/common.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::ty::layout::{
77
use rustc_middle::ty::TypeFoldable;
88
use rustc_span::source_map::Spanned;
99
use rustc_target::abi::call::FnAbi;
10-
use rustc_target::abi::{Integer, Primitive};
10+
use rustc_target::abi::{Float, Integer, Primitive};
1111
use rustc_target::spec::{HasTargetSpec, Target};
1212

1313
use crate::constant::ConstantCx;
@@ -32,10 +32,12 @@ pub(crate) fn scalar_to_clif_type(tcx: TyCtxt<'_>, scalar: Scalar) -> Type {
3232
Integer::I64 => types::I64,
3333
Integer::I128 => types::I128,
3434
},
35-
Primitive::F16 => unimplemented!("f16_f128"),
36-
Primitive::F32 => types::F32,
37-
Primitive::F64 => types::F64,
38-
Primitive::F128 => unimplemented!("f16_f128"),
35+
Primitive::Float(float) => match float {
36+
Float::F16 => unimplemented!("f16_f128"),
37+
Float::F32 => types::F32,
38+
Float::F64 => types::F64,
39+
Float::F128 => unimplemented!("f16_f128"),
40+
},
3941
// FIXME(erikdesjardins): handle non-default addrspace ptr sizes
4042
Primitive::Pointer(_) => pointer_ty(tcx),
4143
}

Diff for: compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
586586
intrinsic_args!(fx, args => (base, offset); intrinsic);
587587
let offset = offset.load_scalar(fx);
588588

589-
let pointee_ty = base.layout().ty.builtin_deref(true).unwrap().ty;
589+
let pointee_ty = base.layout().ty.builtin_deref(true).unwrap();
590590
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
591591
let ptr_diff = if pointee_size != 1 {
592592
fx.bcx.ins().imul_imm(offset, pointee_size as i64)
@@ -610,7 +610,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
610610
let val = val.load_scalar(fx);
611611
let count = count.load_scalar(fx);
612612

613-
let pointee_ty = dst.layout().ty.builtin_deref(true).unwrap().ty;
613+
let pointee_ty = dst.layout().ty.builtin_deref(true).unwrap();
614614
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
615615
let count = if pointee_size != 1 {
616616
fx.bcx.ins().imul_imm(count, pointee_size as i64)
@@ -715,7 +715,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
715715

716716
// Cranelift treats loads as volatile by default
717717
// FIXME correctly handle unaligned_volatile_load
718-
let inner_layout = fx.layout_of(ptr.layout().ty.builtin_deref(true).unwrap().ty);
718+
let inner_layout = fx.layout_of(ptr.layout().ty.builtin_deref(true).unwrap());
719719
let val = CValue::by_ref(Pointer::new(ptr.load_scalar(fx)), inner_layout);
720720
ret.write_cvalue(fx, val);
721721
}

Diff for: compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
974974
intrinsic_args!(fx, args => (ptr, offset); intrinsic);
975975

976976
let (lane_count, ptr_lane_ty) = ptr.layout().ty.simd_size_and_type(fx.tcx);
977-
let pointee_ty = ptr_lane_ty.builtin_deref(true).unwrap().ty;
977+
let pointee_ty = ptr_lane_ty.builtin_deref(true).unwrap();
978978
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
979979
let (ret_lane_count, ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
980980
let ret_lane_layout = fx.layout_of(ret_lane_ty);

Diff for: compiler/rustc_codegen_cranelift/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ mod prelude {
9595
pub(crate) use rustc_middle::mir::{self, *};
9696
pub(crate) use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
9797
pub(crate) use rustc_middle::ty::{
98-
self, FloatTy, Instance, InstanceDef, IntTy, ParamEnv, Ty, TyCtxt, TypeAndMut, UintTy,
98+
self, FloatTy, Instance, InstanceDef, IntTy, ParamEnv, Ty, TyCtxt, UintTy,
9999
};
100100
pub(crate) use rustc_span::Span;
101101
pub(crate) use rustc_target::abi::{Abi, FieldIdx, Scalar, Size, VariantIdx, FIRST_VARIANT};

Diff for: compiler/rustc_codegen_cranelift/src/num.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,8 @@ pub(crate) fn codegen_ptr_binop<'tcx>(
388388
in_lhs: CValue<'tcx>,
389389
in_rhs: CValue<'tcx>,
390390
) -> CValue<'tcx> {
391-
let is_thin_ptr = in_lhs
392-
.layout()
393-
.ty
394-
.builtin_deref(true)
395-
.map(|TypeAndMut { ty, mutbl: _ }| !has_ptr_meta(fx.tcx, ty))
396-
.unwrap_or(true);
391+
let is_thin_ptr =
392+
in_lhs.layout().ty.builtin_deref(true).map(|ty| !has_ptr_meta(fx.tcx, ty)).unwrap_or(true);
397393

398394
if is_thin_ptr {
399395
match bin_op {
@@ -404,7 +400,7 @@ pub(crate) fn codegen_ptr_binop<'tcx>(
404400
codegen_compare_bin_op(fx, bin_op, false, lhs, rhs)
405401
}
406402
BinOp::Offset => {
407-
let pointee_ty = in_lhs.layout().ty.builtin_deref(true).unwrap().ty;
403+
let pointee_ty = in_lhs.layout().ty.builtin_deref(true).unwrap();
408404
let (base, offset) = (in_lhs, in_rhs.load_scalar(fx));
409405
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
410406
let ptr_diff = fx.bcx.ins().imul_imm(offset, pointee_size as i64);

Diff for: compiler/rustc_codegen_cranelift/src/unsize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub(crate) fn coerce_unsized_into<'tcx>(
127127
let dst_ty = dst.layout().ty;
128128
let mut coerce_ptr = || {
129129
let (base, info) =
130-
if fx.layout_of(src.layout().ty.builtin_deref(true).unwrap().ty).is_unsized() {
130+
if fx.layout_of(src.layout().ty.builtin_deref(true).unwrap()).is_unsized() {
131131
let (old_base, old_info) = src.load_scalar_pair(fx);
132132
unsize_ptr(fx, old_base, src.layout(), dst.layout(), Some(old_info))
133133
} else {

Diff for: compiler/rustc_codegen_cranelift/src/value_and_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ impl<'tcx> CPlace<'tcx> {
819819
}
820820

821821
pub(crate) fn place_deref(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> CPlace<'tcx> {
822-
let inner_layout = fx.layout_of(self.layout().ty.builtin_deref(true).unwrap().ty);
822+
let inner_layout = fx.layout_of(self.layout().ty.builtin_deref(true).unwrap());
823823
if has_ptr_meta(fx.tcx, inner_layout.ty) {
824824
let (addr, extra) = self.to_cvalue(fx).load_scalar_pair(fx);
825825
CPlace::for_ptr_with_extra(Pointer::new(addr), extra, inner_layout)

Diff for: compiler/rustc_codegen_cranelift/src/vtable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
5959

6060
if let ty::Ref(_, ty, _) = arg.layout().ty.kind() {
6161
if ty.is_dyn_star() {
62-
let inner_layout = fx.layout_of(arg.layout().ty.builtin_deref(true).unwrap().ty);
62+
let inner_layout = fx.layout_of(arg.layout().ty.builtin_deref(true).unwrap());
6363
let dyn_star = CPlace::for_ptr(Pointer::new(arg.load_scalar(fx)), inner_layout);
6464
let ptr = dyn_star.place_field(fx, FieldIdx::ZERO).to_ptr();
6565
let vtable =

Diff for: compiler/rustc_codegen_gcc/src/type_of.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
88
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
99
use rustc_target::abi::call::{CastTarget, FnAbi, Reg};
1010
use rustc_target::abi::{
11-
self, Abi, Align, FieldsShape, Int, Integer, PointeeInfo, Pointer, Size, TyAbiInterface,
12-
Variants, F128, F16, F32, F64,
11+
self, Abi, Align, FieldsShape, Float, Int, Integer, PointeeInfo, Pointer, Size, TyAbiInterface,
12+
Variants,
1313
};
1414

1515
use crate::abi::{FnAbiGcc, FnAbiGccExt, GccType};
@@ -283,10 +283,7 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
283283
match scalar.primitive() {
284284
Int(i, true) => cx.type_from_integer(i),
285285
Int(i, false) => cx.type_from_unsigned_integer(i),
286-
F16 => cx.type_f16(),
287-
F32 => cx.type_f32(),
288-
F64 => cx.type_f64(),
289-
F128 => cx.type_f128(),
286+
Float(f) => cx.type_from_float(f),
290287
Pointer(address_space) => {
291288
// If we know the alignment, pick something better than i8.
292289
let pointee = if let Some(pointee) = self.pointee_info_at(cx, offset) {

Diff for: compiler/rustc_codegen_llvm/src/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
583583
let element_type_index = unsafe { llvm::LLVMRustGetElementTypeArgIndex(callsite) };
584584
if element_type_index >= 0 {
585585
let arg_ty = self.args[element_type_index as usize].layout.ty;
586-
let pointee_ty = arg_ty.builtin_deref(true).expect("Must be pointer argument").ty;
586+
let pointee_ty = arg_ty.builtin_deref(true).expect("Must be pointer argument");
587587
let element_type_attr = unsafe {
588588
llvm::LLVMRustCreateElementTypeAttr(bx.llcx, bx.layout_of(pointee_ty).llvm_type(bx))
589589
};

Diff for: compiler/rustc_codegen_llvm/src/asm.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,8 @@ fn llvm_asm_scalar_type<'ll>(cx: &CodegenCx<'ll, '_>, scalar: Scalar) -> &'ll Ty
904904
Primitive::Int(Integer::I16, _) => cx.type_i16(),
905905
Primitive::Int(Integer::I32, _) => cx.type_i32(),
906906
Primitive::Int(Integer::I64, _) => cx.type_i64(),
907-
Primitive::F32 => cx.type_f32(),
908-
Primitive::F64 => cx.type_f64(),
907+
Primitive::Float(Float::F32) => cx.type_f32(),
908+
Primitive::Float(Float::F64) => cx.type_f64(),
909909
// FIXME(erikdesjardins): handle non-default addrspace ptr sizes
910910
Primitive::Pointer(_) => cx.type_from_integer(dl.ptr_sized_integer()),
911911
_ => unreachable!(),
@@ -950,7 +950,7 @@ fn llvm_fixup_input<'ll, 'tcx>(
950950
bx.shuffle_vector(value, bx.const_undef(vec_ty), bx.const_vector(&indices))
951951
}
952952
(InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd), Abi::Scalar(s))
953-
if s.primitive() == Primitive::F64 =>
953+
if s.primitive() == Primitive::Float(Float::F64) =>
954954
{
955955
bx.bitcast(value, bx.cx.type_i64())
956956
}
@@ -986,8 +986,8 @@ fn llvm_fixup_input<'ll, 'tcx>(
986986
match s.primitive() {
987987
// MIPS only supports register-length arithmetics.
988988
Primitive::Int(Integer::I8 | Integer::I16, _) => bx.zext(value, bx.cx.type_i32()),
989-
Primitive::F32 => bx.bitcast(value, bx.cx.type_i32()),
990-
Primitive::F64 => bx.bitcast(value, bx.cx.type_i64()),
989+
Primitive::Float(Float::F32) => bx.bitcast(value, bx.cx.type_i32()),
990+
Primitive::Float(Float::F64) => bx.bitcast(value, bx.cx.type_i64()),
991991
_ => value,
992992
}
993993
}
@@ -1027,7 +1027,7 @@ fn llvm_fixup_output<'ll, 'tcx>(
10271027
bx.shuffle_vector(value, bx.const_undef(vec_ty), bx.const_vector(&indices))
10281028
}
10291029
(InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd), Abi::Scalar(s))
1030-
if s.primitive() == Primitive::F64 =>
1030+
if s.primitive() == Primitive::Float(Float::F64) =>
10311031
{
10321032
bx.bitcast(value, bx.cx.type_f64())
10331033
}
@@ -1064,8 +1064,8 @@ fn llvm_fixup_output<'ll, 'tcx>(
10641064
// MIPS only supports register-length arithmetics.
10651065
Primitive::Int(Integer::I8, _) => bx.trunc(value, bx.cx.type_i8()),
10661066
Primitive::Int(Integer::I16, _) => bx.trunc(value, bx.cx.type_i16()),
1067-
Primitive::F32 => bx.bitcast(value, bx.cx.type_f32()),
1068-
Primitive::F64 => bx.bitcast(value, bx.cx.type_f64()),
1067+
Primitive::Float(Float::F32) => bx.bitcast(value, bx.cx.type_f32()),
1068+
Primitive::Float(Float::F64) => bx.bitcast(value, bx.cx.type_f64()),
10691069
_ => value,
10701070
}
10711071
}
@@ -1100,7 +1100,7 @@ fn llvm_fixup_output_type<'ll, 'tcx>(
11001100
cx.type_vector(elem_ty, count * 2)
11011101
}
11021102
(InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd), Abi::Scalar(s))
1103-
if s.primitive() == Primitive::F64 =>
1103+
if s.primitive() == Primitive::Float(Float::F64) =>
11041104
{
11051105
cx.type_i64()
11061106
}
@@ -1136,8 +1136,8 @@ fn llvm_fixup_output_type<'ll, 'tcx>(
11361136
match s.primitive() {
11371137
// MIPS only supports register-length arithmetics.
11381138
Primitive::Int(Integer::I8 | Integer::I16, _) => cx.type_i32(),
1139-
Primitive::F32 => cx.type_i32(),
1140-
Primitive::F64 => cx.type_i64(),
1139+
Primitive::Float(Float::F32) => cx.type_i32(),
1140+
Primitive::Float(Float::F64) => cx.type_i64(),
11411141
_ => layout.llvm_type(cx),
11421142
}
11431143
}

Diff for: compiler/rustc_codegen_llvm/src/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
576576
}
577577
}
578578
}
579-
abi::F16 | abi::F32 | abi::F64 | abi::F128 => {}
579+
abi::Float(_) => {}
580580
}
581581
}
582582

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,7 @@ fn tag_base_type<'ll, 'tcx>(
122122
// Niche tags are always normalized to unsized integers of the correct size.
123123
match tag.primitive() {
124124
Primitive::Int(t, _) => t,
125-
Primitive::F16 => Integer::I16,
126-
Primitive::F32 => Integer::I32,
127-
Primitive::F64 => Integer::I64,
128-
Primitive::F128 => Integer::I128,
125+
Primitive::Float(f) => Integer::from_size(f.size()).unwrap(),
129126
// FIXME(erikdesjardins): handle non-default addrspace ptr sizes
130127
Primitive::Pointer(_) => {
131128
// If the niche is the NULL value of a reference, then `discr_enum_ty` will be

0 commit comments

Comments
 (0)